peel_outer_hull_layers.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. Eigen::MatrixXd V;
  13. Eigen::MatrixXi F;
  14. test_common::load_mesh("two-boxes-bad-self-union.ply", V, F);
  15. REQUIRE (V.rows() == 486);
  16. REQUIRE (F.rows() == 708);
  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::copyleft::cgal::RemeshSelfIntersectionsParam param;
  26. igl::copyleft::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::copyleft::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. REQUIRE (I.rows() == num_faces);
  40. REQUIRE (I.minCoeff() == 0);
  41. REQUIRE (I.maxCoeff() == 1);
  42. }
  43. TEST_CASE("PeelOuterHullLayers: CubeWithFold", "[igl/copyleft/cgal]")
  44. Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> V;
  45. Eigen::MatrixXi F;
  46. test_common::load_mesh("cube_with_fold.ply", V, F);
  47. typedef CGAL::Exact_predicates_exact_constructions_kernel K;
  48. typedef K::FT Scalar;
  49. typedef Eigen::Matrix<Scalar,
  50. Eigen::Dynamic,
  51. Eigen::Dynamic> MatrixXe;
  52. MatrixXe Vs;
  53. Eigen::MatrixXi Fs, IF;
  54. Eigen::VectorXi J, IM;
  55. igl::copyleft::cgal::RemeshSelfIntersectionsParam param;
  56. igl::copyleft::cgal::remesh_self_intersections(V, F, param, Vs, Fs, IF, J, IM);
  57. std::for_each(Fs.data(),Fs.data()+Fs.size(),
  58. [&IM](int & a){ a=IM(a); });
  59. MatrixXe Vt;
  60. Eigen::MatrixXi Ft;
  61. igl::remove_unreferenced(Vs,Fs,Vt,Ft,IM);
  62. Eigen::VectorXi I, flipped;
  63. size_t num_peels = igl::copyleft::cgal::peel_outer_hull_layers(Vt, Ft, I, flipped);
  64. }