readMESH.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <test_common.h>
  2. #include <catch2/catch.hpp>
  3. #include <igl/readMESH.h>
  4. #include <fstream>
  5. TEST_CASE("readMESH: single-tet","[igl]")
  6. {
  7. std::ofstream("test.mesh")<< R"(MeshVersionFormatted 1
  8. Dimension 3
  9. Vertices
  10. 4
  11. 0 0 0 0
  12. 0 0 1 0
  13. 0 1 0 0
  14. 1 0 0 0
  15. Triangles
  16. 0
  17. Tetrahedra
  18. 1
  19. 1 2 3 4 0
  20. End
  21. )";
  22. Eigen::MatrixXd V;
  23. Eigen::MatrixXi T,F;
  24. igl::readMESH("test.mesh",V,T,F);
  25. REQUIRE(V.rows() == 4);
  26. REQUIRE(T.rows() == 1);
  27. REQUIRE(T(0,0) == 0);
  28. REQUIRE(F.rows() == 0);
  29. }
  30. TEST_CASE("readMESH: no-triangles-line","[igl]")
  31. {
  32. std::ofstream("test.mesh")<< R"(MeshVersionFormatted 1
  33. Dimension 3
  34. Vertices
  35. 4
  36. 0 0 0 0
  37. 0 0 1 0
  38. 0 1 0 0
  39. 1 0 0 0
  40. Tetrahedra
  41. 1
  42. 1 2 3 4 0
  43. )";
  44. Eigen::MatrixXd V;
  45. Eigen::MatrixXi T,F;
  46. igl::readMESH("test.mesh",V,T,F);
  47. REQUIRE(V.rows() == 4);
  48. REQUIRE(T.rows() == 1);
  49. REQUIRE(T(0,0) == 0);
  50. REQUIRE(F.rows() == 0);
  51. }
  52. TEST_CASE("readMESH: mesh-version-formatted-2","[igl]")
  53. {
  54. std::ofstream("test.mesh")<< R"(MeshVersionFormatted 2
  55. Dimension 3
  56. Vertices
  57. 4
  58. 0 0 0 0
  59. 0 0 1 0
  60. 0 1 0 0
  61. 1 0 0 0
  62. Triangles
  63. 0
  64. Tetrahedra
  65. 1
  66. 1 2 3 4 0
  67. End
  68. )";
  69. Eigen::MatrixXd V;
  70. Eigen::MatrixXi T,F;
  71. igl::readMESH("test.mesh",V,T,F);
  72. REQUIRE(V.rows() == 4);
  73. REQUIRE(T.rows() == 1);
  74. REQUIRE(T(0,0) == 0);
  75. REQUIRE(F.rows() == 0);
  76. }