remove_duplicate_vertices.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. SF.resize(F.rows(),F.cols());
  58. for(int f = 0;f<F.rows();f++)
  59. {
  60. for(int c = 0;c<F.cols();c++)
  61. {
  62. SF(f,c) = SVJ(F(f,c));
  63. }
  64. }
  65. #endif
  66. }
  67. #ifndef IGL_HEADER_ONLY
  68. // Explicit instanciation
  69. 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> >&);
  70. #endif