|
1 | 1 | #include <npe.h>
|
2 | 2 |
|
3 |
| -#include <igl/remove_duplicate_vertices.h> |
| 3 | +#include <igl/round.h> |
| 4 | +#include <igl/unique_rows.h> |
| 5 | +#include <igl/colon.h> |
4 | 6 |
|
5 | 7 | #include "common/common.h"
|
6 | 8 |
|
| 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 | + |
7 | 90 | const char* remove_duplicate_points_doc = R"igl_Qu8mg5v7(
|
8 | 91 | Removes duplicated points from a point cloud where two points are considered the same if their distance is below
|
9 | 92 | some threshold
|
@@ -35,7 +118,7 @@ npe_begin_code()
|
35 | 118 | Eigen::Matrix<int32_t, Eigen::Dynamic, 1> svj;
|
36 | 119 | Eigen::Matrix<int32_t, Eigen::Dynamic, 1> svi;
|
37 | 120 |
|
38 |
| - igl::remove_duplicate_vertices(x_copy, epsilon, x_out, svi, svj); |
| 121 | + remove_duplicate_vertices(x_copy, epsilon, x_out, svi, svj); |
39 | 122 |
|
40 | 123 | if (return_index) {
|
41 | 124 | return pybind11::cast(std::make_tuple(npe::move(x_out), npe::move(svi), npe::move(svj)));
|
@@ -82,7 +165,7 @@ npe_begin_code()
|
82 | 165 | Eigen::Matrix<int32_t, Eigen::Dynamic, 1> svi;
|
83 | 166 | Eigen::Matrix<int32_t, Eigen::Dynamic, 1> svj;
|
84 | 167 |
|
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); |
86 | 169 |
|
87 | 170 | if (return_index) {
|
88 | 171 | return pybind11::cast(std::make_tuple(npe::move(v_out), npe::move(f_out), npe::move(svi), npe::move(svj)));
|
|
0 commit comments