cut_mesh.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include <test_common.h>
  2. #include <igl/cut_mesh.h>
  3. #include <igl/vertex_components.h>
  4. #include <igl/edges.h>
  5. TEST_CASE("cut_mesh: seperate mesh", "[igl]") {
  6. Eigen::MatrixXd V(9,3);
  7. V << 0,0,0,
  8. 0,1,0,
  9. 0,2,0,
  10. 1,2,0,
  11. 2,2,0,
  12. 2,1,0,
  13. 2,0,0,
  14. 1,0,0,
  15. 1,1,0;
  16. Eigen::MatrixXi F(8,3);
  17. F << 0,1,8,
  18. 1,2,8,
  19. 2,3,8,
  20. 3,4,8,
  21. 4,5,8,
  22. 5,6,8,
  23. 6,7,8,
  24. 7,0,8;
  25. Eigen::MatrixXi C(8,3);
  26. C << 0,1,1,
  27. 0,1,1,
  28. 0,0,1,
  29. 0,0,0,
  30. 0,0,0,
  31. 0,0,0,
  32. 0,0,0,
  33. 0,1,0;
  34. Eigen::VectorXi I;
  35. igl::cut_mesh(V,F,C,I);
  36. Eigen::VectorXi count;
  37. igl::vertex_components(F, count);
  38. REQUIRE(count.maxCoeff() == 2);
  39. }
  40. TEST_CASE("cut_mesh: single edge", "[igl]") {
  41. Eigen::MatrixXd V(9,3);
  42. V << 0,0,0,
  43. 0,1,0,
  44. 0,2,0,
  45. 1,2,0,
  46. 2,2,0,
  47. 2,1,0,
  48. 2,0,0,
  49. 1,0,0,
  50. 1,1,0;
  51. Eigen::MatrixXi F(8,3);
  52. F << 0,1,8,
  53. 1,2,8,
  54. 2,3,8,
  55. 3,4,8,
  56. 4,5,8,
  57. 5,6,8,
  58. 6,7,8,
  59. 7,0,8;
  60. Eigen::MatrixXi C(8,3);
  61. C << 0,1,0,
  62. 0,0,1,
  63. 0,0,0,
  64. 0,0,0,
  65. 0,0,0,
  66. 0,0,0,
  67. 0,0,0,
  68. 0,0,0;
  69. Eigen::VectorXi I;
  70. igl::cut_mesh(V,F,C,I);
  71. Eigen::VectorXi count;
  72. igl::vertex_components(F, count);
  73. REQUIRE(0 == count.maxCoeff());
  74. Eigen::MatrixXi E;
  75. igl::edges(F, E);
  76. const auto euler = V.rows() - E.rows() + F.rows();
  77. REQUIRE ( 1 == euler );
  78. }
  79. TEST_CASE("cut_mesh: two triangles", "[igl]") {
  80. Eigen::MatrixXd V(4,3);
  81. V << 0,0,0,
  82. 0,1,0,
  83. 1,0,0,
  84. 1,1,0;
  85. Eigen::MatrixXi F(2,3);
  86. F << 0,1,2,
  87. 2,1,3;
  88. // Only mark one side of the internal edge to cut. This should still work.
  89. Eigen::MatrixXi C(2,3);
  90. C << 0,0,0,
  91. 1,0,0;
  92. Eigen::MatrixXd VCut;
  93. Eigen::MatrixXi FCut;
  94. igl::cut_mesh(V,F,C,VCut,FCut);
  95. REQUIRE( VCut.rows() == 6 );
  96. }