peal_outer_hull_layers.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <vector>
  2. #include "peal_outer_hull_layers.h"
  3. #include "outer_hull.h"
  4. #include <vector>
  5. using namespace std;
  6. template <
  7. typename DerivedV,
  8. typename DerivedF,
  9. typename Derivedodd,
  10. typename Derivedflip>
  11. IGL_INLINE void igl::peal_outer_hull_layers(
  12. const Eigen::PlainObjectBase<DerivedV > & V,
  13. const Eigen::PlainObjectBase<DerivedF > & F,
  14. Eigen::PlainObjectBase<Derivedodd > & odd,
  15. Eigen::PlainObjectBase<Derivedflip > & flip)
  16. {
  17. using namespace Eigen;
  18. using namespace std;
  19. typedef typename DerivedF::Index Index;
  20. typedef Matrix<typename DerivedF::Scalar,Dynamic,DerivedF::ColsAtCompileTime> MatrixXF;
  21. typedef Matrix<Index,Dynamic,1> MatrixXI;
  22. typedef Matrix<typename Derivedflip::Scalar,Dynamic,Derivedflip::ColsAtCompileTime> MatrixXflip;
  23. const Index m = F.rows();
  24. // keep track of iteration parity and whether flipped in hull
  25. MatrixXF Fr = F;
  26. odd.resize(m,1);
  27. flip.resize(m,1);
  28. // Keep track of index map
  29. MatrixXI IM = MatrixXI::LinSpaced(m,0,m-1);
  30. // This is O(n * layers)
  31. bool odd_iter = true;
  32. MatrixXI P(m,1);
  33. Index iter = 0;
  34. while(Fr.size() > 0)
  35. {
  36. assert(Fr.rows() == IM.rows());
  37. // Compute outer hull of current Fr
  38. MatrixXF Fo;
  39. MatrixXI Jo;
  40. MatrixXflip flipr;
  41. outer_hull(V,Fr,Fo,Jo,flipr);
  42. assert(Fo.rows() == Jo.rows());
  43. // all faces in Fo of Fr
  44. vector<bool> in_outer(Fr.rows(),false);
  45. for(Index g = 0;g<Jo.rows();g++)
  46. {
  47. odd(IM(Jo(g))) = odd_iter;
  48. P(IM(Jo(g))) = iter;
  49. in_outer[Jo(g)] = true;
  50. flip(IM(Jo(g))) = flipr(Jo(g));
  51. }
  52. // Fr = Fr - Fo
  53. // update IM
  54. MatrixXF prev_Fr = Fr;
  55. MatrixXI prev_IM = IM;
  56. Fr.resize(prev_Fr.rows() - Fo.rows(),F.cols());
  57. IM.resize(Fr.rows());
  58. {
  59. Index g = 0;
  60. for(Index f = 0;f<prev_Fr.rows();f++)
  61. {
  62. if(!in_outer[f])
  63. {
  64. Fr.row(g) = prev_Fr.row(f);
  65. IM(g) = prev_IM(f);
  66. g++;
  67. }
  68. }
  69. }
  70. odd_iter = !odd_iter;
  71. iter++;
  72. }
  73. }
  74. #ifdef IGL_STATIC_LIBRARY
  75. // Explicit template specialization
  76. template void igl::peal_outer_hull_layers<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<bool, -1, 1, 0, -1, 1>, Eigen::Matrix<bool, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<bool, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<bool, -1, 1, 0, -1, 1> >&);
  77. #endif