remove_duplicate_vertices.cpp 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "remove_duplicate_vertices.h"
  9. #include "round.h"
  10. #include "unique.h"
  11. #include "colon.h"
  12. #include "slice.h"
  13. #include <functional>
  14. template <
  15. typename DerivedV,
  16. typename DerivedSV,
  17. typename DerivedSVI,
  18. typename DerivedSVJ>
  19. IGL_INLINE void igl::remove_duplicate_vertices(
  20. const Eigen::PlainObjectBase<DerivedV>& V,
  21. const double epsilon,
  22. Eigen::PlainObjectBase<DerivedSV>& SV,
  23. Eigen::PlainObjectBase<DerivedSVI>& SVI,
  24. Eigen::PlainObjectBase<DerivedSVJ>& SVJ)
  25. {
  26. if(epsilon > 0)
  27. {
  28. DerivedV rV,rSV;
  29. round((V/(10.0*epsilon)).eval(),rV);
  30. unique_rows(rV,rSV,SVI,SVJ);
  31. slice(V,SVI,colon<int>(0,V.cols()-1),SV);
  32. }else
  33. {
  34. unique_rows(V,SV,SVI,SVJ);
  35. }
  36. }
  37. template <
  38. typename DerivedV,
  39. typename DerivedF,
  40. typename DerivedSV,
  41. typename DerivedSVI,
  42. typename DerivedSVJ,
  43. typename DerivedSF>
  44. IGL_INLINE void igl::remove_duplicate_vertices(
  45. const Eigen::PlainObjectBase<DerivedV>& V,
  46. const Eigen::PlainObjectBase<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. {
  53. using namespace Eigen;
  54. using namespace std;
  55. remove_duplicate_vertices(V,epsilon,SV,SVI,SVJ);
  56. // remap faces
  57. // #ifndef _WIN32
  58. // SF = F.unaryExpr(bind1st(mem_fun(
  59. // static_cast<VectorXi::Scalar&(VectorXi::*)(VectorXi::Index)>
  60. // (&VectorXi::operator())), &SVJ)).eval();
  61. // #else
  62. // Why doesn't the above compile on windows?
  63. // Daniele: it also does not compile with CLANG
  64. SF.resize(F.rows(),F.cols());
  65. for(int f = 0;f<F.rows();f++)
  66. {
  67. for(int c = 0;c<F.cols();c++)
  68. {
  69. SF(f,c) = SVJ(F(f,c));
  70. }
  71. }
  72. // #endif
  73. }
  74. #ifdef IGL_STATIC_LIBRARY
  75. // Explicit instanciation
  76. 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> >&);
  77. template void igl::remove_duplicate_vertices<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, 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, 3, 0, -1, 3> >&);
  78. 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> >&);
  79. #endif