remove_duplicate_vertices.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "remove_duplicate_vertices.h"
  2. #include "round.h"
  3. #include "unique.h"
  4. #include "colon.h"
  5. #include "slice.h"
  6. #include <functional>
  7. template <
  8. typename DerivedV,
  9. typename DerivedSV,
  10. typename DerivedSVI,
  11. typename DerivedSVJ>
  12. IGL_INLINE void igl::remove_duplicate_vertices(
  13. const Eigen::PlainObjectBase<DerivedV>& V,
  14. const double epsilon,
  15. Eigen::PlainObjectBase<DerivedSV>& SV,
  16. Eigen::PlainObjectBase<DerivedSVI>& SVI,
  17. Eigen::PlainObjectBase<DerivedSVJ>& SVJ)
  18. {
  19. using namespace igl;
  20. if(epsilon > 0)
  21. {
  22. Eigen::PlainObjectBase<DerivedV> rV,rSV;
  23. round((V/(10.0*epsilon)).eval(),rV);
  24. unique_rows(rV,rSV,SVI,SVJ);
  25. slice(V,SVI,colon<int>(0,V.cols()-1),SV);
  26. }else
  27. {
  28. unique_rows(V,SV,SVI,SVJ);
  29. }
  30. }
  31. template <
  32. typename DerivedV,
  33. typename DerivedF,
  34. typename DerivedSV,
  35. typename DerivedSVI,
  36. typename DerivedSVJ,
  37. typename DerivedSF>
  38. IGL_INLINE void igl::remove_duplicate_vertices(
  39. const Eigen::PlainObjectBase<DerivedV>& V,
  40. const Eigen::PlainObjectBase<DerivedF>& F,
  41. const double epsilon,
  42. Eigen::PlainObjectBase<DerivedSV>& SV,
  43. Eigen::PlainObjectBase<DerivedSVI>& SVI,
  44. Eigen::PlainObjectBase<DerivedSVJ>& SVJ,
  45. Eigen::PlainObjectBase<DerivedSF>& SF)
  46. {
  47. using namespace Eigen;
  48. using namespace std;
  49. remove_duplicate_vertices(V,epsilon,SV,SVI,SVJ);
  50. // remap faces
  51. // #ifndef _WIN32
  52. // SF = F.unaryExpr(bind1st(mem_fun(
  53. // static_cast<VectorXi::Scalar&(VectorXi::*)(VectorXi::Index)>
  54. // (&VectorXi::operator())), &SVJ)).eval();
  55. // #else
  56. // Why doesn't the above compile on windows?
  57. // Daniele: it also does not compile with CLANG
  58. SF.resize(F.rows(),F.cols());
  59. for(int f = 0;f<F.rows();f++)
  60. {
  61. for(int c = 0;c<F.cols();c++)
  62. {
  63. SF(f,c) = SVJ(F(f,c));
  64. }
  65. }
  66. // #endif
  67. }
  68. #ifndef IGL_HEADER_ONLY
  69. // Explicit instanciation
  70. template void igl::remove_duplicate_vertices<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  71. #endif