peal_outer_hull_layers.cpp 2.4 KB

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