readPLY.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #include <test_common.h>
  2. #include <igl/readPLY.h>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6. TEST_CASE("readPLY: cube_with_fold.ply", "[igl]")
  7. {
  8. Eigen::MatrixXd V;
  9. Eigen::MatrixXi F;
  10. REQUIRE (igl::readPLY(test_common::data_path("cube_with_fold.ply"), V, F));
  11. REQUIRE (V.rows() == 26);
  12. REQUIRE (V.cols() == 3);
  13. REQUIRE (F.rows() == 48);
  14. REQUIRE (F.cols() == 3);
  15. }
  16. TEST_CASE("readPLY: bunny.ply", "[igl]")
  17. {
  18. std::ifstream f(test_common::data_path("bunny.ply"));
  19. REQUIRE (f.good());
  20. f.close();
  21. Eigen::MatrixXd V,N,UV,VD,FD,ED;
  22. std::vector<std::string> Vheader,Fheader,Eheader,comments;
  23. Eigen::MatrixXi F,E;
  24. REQUIRE (igl::readPLY(test_common::data_path("bunny.ply"), V, F, E, N, UV, VD,Vheader, FD,Fheader, ED,Eheader,comments));
  25. REQUIRE (V.rows() == 35947);
  26. REQUIRE (V.cols() == 3);
  27. REQUIRE (F.rows() == 69451);
  28. REQUIRE (F.cols() == 3);
  29. // no edge data
  30. REQUIRE (E.rows() == 0);
  31. REQUIRE (E.cols() == 0);
  32. // no normals or texture coordinates
  33. REQUIRE (N.rows() == 0);
  34. REQUIRE (N.cols() == 0);
  35. REQUIRE (UV.rows() == 0);
  36. REQUIRE (UV.cols() == 0);
  37. // this bunny have additonal data
  38. REQUIRE (VD.rows() == 35947);
  39. REQUIRE (VD.cols() == 2);
  40. REQUIRE (Vheader.size() == 2);
  41. REQUIRE (Vheader[0] == "confidence" );
  42. REQUIRE (Vheader[1] == "intensity" );
  43. // no Face data or edge data
  44. REQUIRE (FD.rows() == 0);
  45. REQUIRE (FD.cols() == 0);
  46. REQUIRE (Fheader.size() == 0);
  47. REQUIRE (ED.rows() == 0);
  48. REQUIRE (ED.cols() == 0);
  49. REQUIRE (Eheader.size() == 0);
  50. // there are comments
  51. REQUIRE (comments.size() == 2);
  52. }
  53. TEST_CASE("readPLY: mesh_error.ply", "[igl]")
  54. {
  55. // test on a non-existent file
  56. std::ifstream f(test_common::data_path("mesh_error.ply"));
  57. REQUIRE (f.good() == false);
  58. f.close();
  59. Eigen::MatrixXd V;
  60. Eigen::MatrixXi F;
  61. REQUIRE (igl::readPLY(test_common::data_path("mesh_error.ply"), V, F) == false);
  62. REQUIRE (V.rows() == 0);
  63. REQUIRE (F.rows() == 0);
  64. }
  65. TEST_CASE("readPLY: quad_cube.ply", "[igl]")
  66. {
  67. // small qube from blender
  68. const char *ply_quad_cube=
  69. "ply\n"
  70. "format ascii 1.0\n"
  71. "comment Created by Blender 2.81 (sub 16) - www.blender.org, source file: ''\n"
  72. "element vertex 24\n"
  73. "property float x\n"
  74. "property float y\n"
  75. "property float z\n"
  76. "property float nx\n"
  77. "property float ny\n"
  78. "property float nz\n"
  79. "property float s\n"
  80. "property float t\n"
  81. "element face 6\n"
  82. "property list uchar uint vertex_indices\n"
  83. "property uchar red\n"
  84. "property uchar green\n"
  85. "property uchar blue\n"
  86. "property uchar alpha\n"
  87. "end_header\n"
  88. "1.000000 1.000000 1.000000 0.000000 -0.000000 1.000000 0.625000 0.500000\n"
  89. "-1.000000 1.000000 1.000000 0.000000 -0.000000 1.000000 0.875000 0.500000\n"
  90. "-1.000000 -1.000000 1.000000 0.000000 -0.000000 1.000000 0.875000 0.750000\n"
  91. "1.000000 -1.000000 1.000000 0.000000 -0.000000 1.000000 0.625000 0.750000\n"
  92. "1.000000 -1.000000 -1.000000 0.000000 -1.000000 0.000000 0.375000 0.750000\n"
  93. "1.000000 -1.000000 1.000000 0.000000 -1.000000 0.000000 0.625000 0.750000\n"
  94. "-1.000000 -1.000000 1.000000 0.000000 -1.000000 0.000000 0.625000 1.000000\n"
  95. "-1.000000 -1.000000 -1.000000 0.000000 -1.000000 0.000000 0.375000 1.000000\n"
  96. "-1.000000 -1.000000 -1.000000 -1.000000 -0.000000 0.000000 0.375000 0.000000\n"
  97. "-1.000000 -1.000000 1.000000 -1.000000 -0.000000 0.000000 0.625000 0.000000\n"
  98. "-1.000000 1.000000 1.000000 -1.000000 -0.000000 0.000000 0.625000 0.250000\n"
  99. "-1.000000 1.000000 -1.000000 -1.000000 -0.000000 0.000000 0.375000 0.250000\n"
  100. "-1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 0.125000 0.500000\n"
  101. "1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 0.375000 0.500000\n"
  102. "1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 0.375000 0.750000\n"
  103. "-1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 0.125000 0.750000\n"
  104. "1.000000 1.000000 -1.000000 1.000000 -0.000000 0.000000 0.375000 0.500000\n"
  105. "1.000000 1.000000 1.000000 1.000000 -0.000000 0.000000 0.625000 0.500000\n"
  106. "1.000000 -1.000000 1.000000 1.000000 -0.000000 0.000000 0.625000 0.750000\n"
  107. "1.000000 -1.000000 -1.000000 1.000000 -0.000000 0.000000 0.375000 0.750000\n"
  108. "-1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000 0.375000 0.250000\n"
  109. "-1.000000 1.000000 1.000000 0.000000 1.000000 0.000000 0.625000 0.250000\n"
  110. "1.000000 1.000000 1.000000 0.000000 1.000000 0.000000 0.625000 0.500000\n"
  111. "1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000 0.375000 0.500000\n"
  112. "4 0 1 2 3 0 0 255 255\n"
  113. "4 4 5 6 7 0 0 255 255\n"
  114. "4 8 9 10 11 0 0 255 255\n"
  115. "4 12 13 14 15 0 0 255 255\n"
  116. "4 16 17 18 19 0 0 255 255\n"
  117. "4 20 21 22 23 0 0 255 255\n";
  118. std::ofstream f("quad_cube.ply");
  119. f.write(ply_quad_cube,strlen(ply_quad_cube));
  120. f.close();
  121. Eigen::MatrixXd V;
  122. Eigen::MatrixXi F;
  123. REQUIRE (igl::readPLY("quad_cube.ply", V, F));
  124. REQUIRE (V.rows() == 24);
  125. REQUIRE (V.cols() == 3);
  126. REQUIRE (F.rows() == 6);
  127. REQUIRE (F.cols() == 4);
  128. Eigen::MatrixXd N,UV,VD,FD,ED;
  129. Eigen::MatrixXi E;
  130. std::vector<std::string> headerV;
  131. std::vector<std::string> headerF, headerE, comments;
  132. REQUIRE (igl::readPLY("quad_cube.ply", V, F, E, N, UV,
  133. VD, headerV,
  134. FD, headerF,
  135. ED, headerE,
  136. comments));
  137. REQUIRE (V.rows() == 24);
  138. REQUIRE (V.cols() == 3);
  139. REQUIRE (F.rows() == 6);
  140. REQUIRE (F.cols() == 4);
  141. REQUIRE (E.rows() == 0);
  142. REQUIRE (E.cols() == 0);
  143. REQUIRE (N.rows() == 24);
  144. REQUIRE (N.cols() == 3);
  145. REQUIRE (UV.rows() == 24);
  146. REQUIRE (UV.cols() == 2);
  147. REQUIRE (VD.rows() == 0);
  148. REQUIRE (VD.cols() == 0);
  149. REQUIRE (headerV.empty());
  150. REQUIRE (FD.rows() == 6);
  151. REQUIRE (FD.cols() == 4);
  152. REQUIRE (headerF.size() == 4);
  153. REQUIRE (headerF[0] == "red");
  154. REQUIRE (headerF[1] == "green");
  155. REQUIRE (headerF[2] == "blue");
  156. REQUIRE (headerF[3] == "alpha");
  157. REQUIRE (ED.rows() == 0);
  158. REQUIRE (ED.cols() == 0);
  159. REQUIRE (headerE.size() == 0);
  160. }