remove_duplicate_vertices.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #define __STR2__(x) #x
  58. #define __STR1__(x) __STR2__(x)
  59. #define __LOC__ __FILE__ "("__STR1__(__LINE__)") : Warning Msg: "
  60. #pragma message(__LOC__"Using untested Windows-only code")
  61. // This needs to be tested.
  62. SF.resize(F.rows(),F.cols());
  63. for(int f = 0;f<SF.size();f++)
  64. {
  65. SF(f) = SVJ(f);
  66. }
  67. #endif
  68. }
  69. #ifndef IGL_HEADER_ONLY
  70. // Explicit instanciation
  71. 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> >&);
  72. #endif