peal_outer_hull_layers.cpp 2.5 KB

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