peel_outer_hull_layers.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <test_common.h>
  2. #include <iostream>
  3. #include <Eigen/Dense>
  4. #include <igl/cgal/peel_outer_hull_layers.h>
  5. #include <igl/cgal/remesh_self_intersections.h>
  6. #include <igl/cgal/RemeshSelfIntersectionsParam.h>
  7. #include <igl/per_face_normals.h>
  8. #include <igl/remove_unreferenced.h>
  9. #include <igl/writeOBJ.h>
  10. #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
  11. TEST(PeelOuterHullLayers, TwoCubes) {
  12. Eigen::MatrixXd V;
  13. Eigen::MatrixXi F;
  14. test_common::load_mesh("two-boxes-bad-self-union.ply", V, F);
  15. ASSERT_EQ(486, V.rows());
  16. ASSERT_EQ(708, F.rows());
  17. typedef CGAL::Exact_predicates_exact_constructions_kernel K;
  18. typedef K::FT Scalar;
  19. typedef Eigen::Matrix<Scalar,
  20. Eigen::Dynamic,
  21. Eigen::Dynamic> MatrixXe;
  22. MatrixXe Vs;
  23. Eigen::MatrixXi Fs, IF;
  24. Eigen::VectorXi J, IM;
  25. igl::cgal::RemeshSelfIntersectionsParam param;
  26. igl::cgal::remesh_self_intersections(V, F, param, Vs, Fs, IF, J, IM);
  27. std::for_each(Fs.data(),Fs.data()+Fs.size(),
  28. [&IM](int & a){ a=IM(a); });
  29. MatrixXe Vt;
  30. Eigen::MatrixXi Ft;
  31. igl::remove_unreferenced(Vs,Fs,Vt,Ft,IM);
  32. const size_t num_faces = Ft.rows();
  33. Eigen::VectorXi I, flipped;
  34. size_t num_peels = igl::cgal::peel_outer_hull_layers(Vt, Ft, I, flipped);
  35. Eigen::MatrixXd vertices(Vt.rows(), Vt.cols());
  36. std::transform(Vt.data(), Vt.data() + Vt.rows() * Vt.cols(),
  37. vertices.data(), [](Scalar v) { return CGAL::to_double(v); });
  38. igl::writeOBJ("debug.obj", vertices, Ft);
  39. ASSERT_EQ(num_faces, I.rows());
  40. ASSERT_EQ(0, I.minCoeff());
  41. ASSERT_EQ(1, I.maxCoeff());
  42. }