Skip to content

Commit 1968f81

Browse files
committed
dedup mesh vertices removes degenerate faces
1 parent dee37e4 commit 1968f81

File tree

1 file changed

+86
-3
lines changed

1 file changed

+86
-3
lines changed

src/remove_duplicates.cpp

+86-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,92 @@
11
#include <npe.h>
22

3-
#include <igl/remove_duplicate_vertices.h>
3+
#include <igl/round.h>
4+
#include <igl/unique_rows.h>
5+
#include <igl/colon.h>
46

57
#include "common/common.h"
68

9+
namespace {
10+
11+
template <
12+
typename DerivedV,
13+
typename DerivedSV,
14+
typename DerivedSVI,
15+
typename DerivedSVJ>
16+
inline void remove_duplicate_vertices(
17+
const Eigen::MatrixBase<DerivedV>& V,
18+
const double epsilon,
19+
Eigen::PlainObjectBase<DerivedSV>& SV,
20+
Eigen::PlainObjectBase<DerivedSVI>& SVI,
21+
Eigen::PlainObjectBase<DerivedSVJ>& SVJ) {
22+
23+
static_assert(
24+
(DerivedSVI::RowsAtCompileTime == 1 || DerivedSVI::ColsAtCompileTime == 1) &&
25+
(DerivedSVJ::RowsAtCompileTime == 1 || DerivedSVJ::ColsAtCompileTime == 1),
26+
"SVI and SVJ need to have RowsAtCompileTime == 1 or ColsAtCompileTime == 1");
27+
if(epsilon > 0) {
28+
DerivedV rV,rSV;
29+
igl::round((V/(epsilon)).eval(),rV);
30+
igl::unique_rows(rV,rSV,SVI,SVJ);
31+
SV = V(SVI.derived(),Eigen::all);
32+
} else {
33+
igl::unique_rows(V,SV,SVI,SVJ);
34+
}
35+
}
36+
37+
template <
38+
typename DerivedV,
39+
typename DerivedF,
40+
typename DerivedSV,
41+
typename DerivedSVI,
42+
typename DerivedSVJ,
43+
typename DerivedSF>
44+
inline void remove_duplicate_vertices(
45+
const Eigen::MatrixBase<DerivedV>& V,
46+
const Eigen::MatrixBase<DerivedF>& F,
47+
const double epsilon,
48+
Eigen::PlainObjectBase<DerivedSV>& SV,
49+
Eigen::PlainObjectBase<DerivedSVI>& SVI,
50+
Eigen::PlainObjectBase<DerivedSVJ>& SVJ,
51+
Eigen::PlainObjectBase<DerivedSF>& SF) {
52+
// SVI and SVJ need to have RowsAtCompileTime == 1 or ColsAtCompileTime == 1
53+
static_assert(
54+
(DerivedSVI::RowsAtCompileTime == 1 || DerivedSVI::ColsAtCompileTime == 1) &&
55+
(DerivedSVJ::RowsAtCompileTime == 1 || DerivedSVJ::ColsAtCompileTime == 1),
56+
"SVI and SVJ need to have RowsAtCompileTime == 1 or ColsAtCompileTime == 1");
57+
using namespace Eigen;
58+
using namespace std;
59+
remove_duplicate_vertices(V,epsilon,SV,SVI,SVJ);
60+
SF.resizeLike(F);
61+
int64_t fcount = 0;
62+
for(int f = 0; f < F.rows(); f++) {
63+
bool is_degen = false;
64+
for(int c = 0; c < F.cols(); c++) {
65+
for (int c2 = c + 1; c2 < F.cols(); c2++) {
66+
if (SVJ(F(f,c)) == SVJ(F(f,c2))) {
67+
is_degen = true;
68+
break;
69+
}
70+
}
71+
if (is_degen) {
72+
break;
73+
}
74+
SF(fcount,c) = SVJ(F(f,c));
75+
}
76+
if (!is_degen) {
77+
fcount++;
78+
}
79+
}
80+
SF.conservativeResize(fcount, F.cols());
81+
}
82+
83+
84+
}
85+
86+
87+
88+
89+
790
const char* remove_duplicate_points_doc = R"igl_Qu8mg5v7(
891
Removes duplicated points from a point cloud where two points are considered the same if their distance is below
992
some threshold
@@ -35,7 +118,7 @@ npe_begin_code()
35118
Eigen::Matrix<int32_t, Eigen::Dynamic, 1> svj;
36119
Eigen::Matrix<int32_t, Eigen::Dynamic, 1> svi;
37120

38-
igl::remove_duplicate_vertices(x_copy, epsilon, x_out, svi, svj);
121+
remove_duplicate_vertices(x_copy, epsilon, x_out, svi, svj);
39122

40123
if (return_index) {
41124
return pybind11::cast(std::make_tuple(npe::move(x_out), npe::move(svi), npe::move(svj)));
@@ -82,7 +165,7 @@ npe_begin_code()
82165
Eigen::Matrix<int32_t, Eigen::Dynamic, 1> svi;
83166
Eigen::Matrix<int32_t, Eigen::Dynamic, 1> svj;
84167
85-
igl::remove_duplicate_vertices(v_copy, f_copy, epsilon, v_out, svi, svj, f_out);
168+
remove_duplicate_vertices(v_copy, f_copy, epsilon, v_out, svi, svj, f_out);
86169
87170
if (return_index) {
88171
return pybind11::cast(std::make_tuple(npe::move(v_out), npe::move(f_out), npe::move(svi), npe::move(svj)));

0 commit comments

Comments
 (0)