peel_outer_hull_layers.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <test_common.h>
  2. #include <iostream>
  3. #include <Eigen/Dense>
  4. #include <igl/copyleft/cgal/peel_outer_hull_layers.h>
  5. #include <igl/copyleft/cgal/remesh_self_intersections.h>
  6. #include <igl/copyleft/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_CASE("copyleft_cgal_peel_outer_hull_layers: TwoCubes", "[igl/copyleft/cgal]")
  12. {
  13. Eigen::MatrixXd V;
  14. Eigen::MatrixXi F;
  15. test_common::load_mesh("two-boxes-bad-self-union.ply", V, F);
  16. REQUIRE (V.rows() == 486);
  17. REQUIRE (F.rows() == 708);
  18. typedef CGAL::Exact_predicates_exact_constructions_kernel K;
  19. typedef K::FT Scalar;
  20. typedef Eigen::Matrix<Scalar,
  21. Eigen::Dynamic,
  22. Eigen::Dynamic> MatrixXe;
  23. MatrixXe Vs;
  24. Eigen::MatrixXi Fs, IF;
  25. Eigen::VectorXi J, IM;
  26. igl::copyleft::cgal::RemeshSelfIntersectionsParam param;
  27. igl::copyleft::cgal::remesh_self_intersections(V, F, param, Vs, Fs, IF, J, IM);
  28. std::for_each(Fs.data(),Fs.data()+Fs.size(),
  29. [&IM](int & a){ a=IM(a); });
  30. MatrixXe Vt;
  31. Eigen::MatrixXi Ft;
  32. igl::remove_unreferenced(Vs,Fs,Vt,Ft,IM);
  33. const size_t num_faces = Ft.rows();
  34. Eigen::VectorXi I, flipped;
  35. size_t num_peels = igl::copyleft::cgal::peel_outer_hull_layers(Vt, Ft, I, flipped);
  36. Eigen::MatrixXd vertices(Vt.rows(), Vt.cols());
  37. std::transform(Vt.data(), Vt.data() + Vt.rows() * Vt.cols(),
  38. vertices.data(), [](Scalar v) { return CGAL::to_double(v); });
  39. igl::writeOBJ("debug.obj", vertices, Ft);
  40. REQUIRE (I.rows() == num_faces);
  41. REQUIRE (I.minCoeff() == 0);
  42. REQUIRE (I.maxCoeff() == 1);
  43. }
  44. TEST_CASE("PeelOuterHullLayers: CubeWithFold", "[igl/copyleft/cgal]")
  45. {
  46. Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> V;
  47. Eigen::MatrixXi F;
  48. test_common::load_mesh("cube_with_fold.ply", V, F);
  49. typedef CGAL::Exact_predicates_exact_constructions_kernel K;
  50. typedef K::FT Scalar;
  51. typedef Eigen::Matrix<Scalar,
  52. Eigen::Dynamic,
  53. Eigen::Dynamic> MatrixXe;
  54. MatrixXe Vs;
  55. Eigen::MatrixXi Fs, IF;
  56. Eigen::VectorXi J, IM;
  57. igl::copyleft::cgal::RemeshSelfIntersectionsParam param;
  58. igl::copyleft::cgal::remesh_self_intersections(V, F, param, Vs, Fs, IF, J, IM);
  59. std::for_each(Fs.data(),Fs.data()+Fs.size(),
  60. [&IM](int & a){ a=IM(a); });
  61. MatrixXe Vt;
  62. Eigen::MatrixXi Ft;
  63. igl::remove_unreferenced(Vs,Fs,Vt,Ft,IM);
  64. Eigen::VectorXi I, flipped;
  65. size_t num_peels = igl::copyleft::cgal::peel_outer_hull_layers(Vt, Ft, I, flipped);
  66. }