remove_duplicate_vertices.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. using namespace igl;
  27. if(epsilon > 0)
  28. {
  29. Eigen::PlainObjectBase<DerivedV> rV,rSV;
  30. round((V/(10.0*epsilon)).eval(),rV);
  31. unique_rows(rV,rSV,SVI,SVJ);
  32. slice(V,SVI,colon<int>(0,V.cols()-1),SV);
  33. }else
  34. {
  35. unique_rows(V,SV,SVI,SVJ);
  36. }
  37. }
  38. template <
  39. typename DerivedV,
  40. typename DerivedF,
  41. typename DerivedSV,
  42. typename DerivedSVI,
  43. typename DerivedSVJ,
  44. typename DerivedSF>
  45. IGL_INLINE void igl::remove_duplicate_vertices(
  46. const Eigen::PlainObjectBase<DerivedV>& V,
  47. const Eigen::PlainObjectBase<DerivedF>& F,
  48. const double epsilon,
  49. Eigen::PlainObjectBase<DerivedSV>& SV,
  50. Eigen::PlainObjectBase<DerivedSVI>& SVI,
  51. Eigen::PlainObjectBase<DerivedSVJ>& SVJ,
  52. Eigen::PlainObjectBase<DerivedSF>& SF)
  53. {
  54. using namespace Eigen;
  55. using namespace std;
  56. remove_duplicate_vertices(V,epsilon,SV,SVI,SVJ);
  57. // remap faces
  58. // #ifndef _WIN32
  59. // SF = F.unaryExpr(bind1st(mem_fun(
  60. // static_cast<VectorXi::Scalar&(VectorXi::*)(VectorXi::Index)>
  61. // (&VectorXi::operator())), &SVJ)).eval();
  62. // #else
  63. // Why doesn't the above compile on windows?
  64. // Daniele: it also does not compile with CLANG
  65. SF.resize(F.rows(),F.cols());
  66. for(int f = 0;f<F.rows();f++)
  67. {
  68. for(int c = 0;c<F.cols();c++)
  69. {
  70. SF(f,c) = SVJ(F(f,c));
  71. }
  72. }
  73. // #endif
  74. }
  75. #ifndef IGL_HEADER_ONLY
  76. // Explicit instanciation
  77. 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> >&);
  78. #endif