writePLY.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include <test_common.h>
  2. #include <igl/readPLY.h>
  3. #include <igl/writePLY.h>
  4. #include <igl/edges.h>
  5. #include <fstream>
  6. #include <string>
  7. #include <vector>
  8. TEST_CASE("writePLY: bunny.ply", "[igl]")
  9. {
  10. std::ifstream f(test_common::data_path("bunny.ply"));
  11. REQUIRE (f.good());
  12. f.close();
  13. Eigen::MatrixXd V1,N1,UV1,VD1,FD1,ED1;
  14. std::vector<std::string> Vheader1,Fheader1,Eheader1,comments1;
  15. Eigen::MatrixXi F1,E1;
  16. // load test data first
  17. REQUIRE (igl::readPLY(test_common::data_path("bunny.ply"), V1, F1, E1, N1, UV1, VD1,Vheader1, FD1,Fheader1, ED1,Eheader1,comments1));
  18. // add more data
  19. Vheader1.push_back("dummy_data");
  20. Eigen::VectorXd dummy_data(V1.rows());
  21. for(size_t i=0;i<V1.rows();++i)
  22. dummy_data(i)=(double)i;
  23. Eigen::MatrixXd VD2(V1.rows(),VD1.cols()+1);
  24. VD2<<VD1,dummy_data;
  25. Fheader1.push_back("face_data");
  26. Eigen::VectorXd face_data(F1.rows());
  27. for(size_t i=0;i<F1.rows();++i)
  28. face_data(i)=(double)i;
  29. // there is no face data in the input file
  30. Eigen::MatrixXd FD2(F1.rows(),FD1.cols()+1);
  31. FD2<<face_data;
  32. //input file have no edge data
  33. REQUIRE (E1.rows() == 0);
  34. REQUIRE (E1.cols() == 0);
  35. REQUIRE (ED1.rows() == 0);
  36. REQUIRE (Eheader1.empty());
  37. Eigen::MatrixXi E2;
  38. std::vector<std::string> Eheader2;
  39. //generate edges
  40. igl::edges(F1,E2);
  41. //generate edge data
  42. Eheader2.push_back("edge_data");
  43. Eigen::VectorXd edge_data(E2.rows());
  44. for(size_t i=0;i<E2.rows();++i)
  45. edge_data(i)=(double)i;
  46. // there is no edge data in the input file
  47. Eigen::MatrixXd ED2(E2.rows(),1);
  48. ED2<<edge_data;
  49. // test that saving preserves all the data, including new data column
  50. REQUIRE (igl::writePLY("writePLY_test_bunny.ply", V1, F1, E2, N1, UV1, VD2, Vheader1, FD2,Fheader1, ED2, Eheader2, comments1, igl::FileEncoding::Binary));
  51. Eigen::MatrixXd V,N,UV,VD,FD,ED;
  52. Eigen::MatrixXi F,E;
  53. std::vector<std::string> Vheader,Fheader,Eheader,comments;
  54. // test that saving preserves all the data
  55. REQUIRE (igl::readPLY("writePLY_test_bunny.ply", V, F, E, N, UV, VD,Vheader, FD,Fheader, ED,Eheader, comments));
  56. REQUIRE (V.rows() == 35947);
  57. REQUIRE (V.cols() == 3);
  58. REQUIRE (F.rows() == 69451);
  59. REQUIRE (F.cols() == 3);
  60. // generated edges
  61. REQUIRE (E.rows() == E2.rows());
  62. REQUIRE (E.cols() == E2.cols());
  63. // no normals or texture coordinates
  64. REQUIRE (N.rows() == 0);
  65. REQUIRE (N.cols() == 0);
  66. REQUIRE (UV.rows() == 0);
  67. REQUIRE (UV.cols() == 0);
  68. // this bunny have additional data
  69. REQUIRE (VD.rows() == 35947);
  70. REQUIRE (VD.cols() == 3);
  71. // the dummy column contents check
  72. for(size_t i=0;i<V.rows();++i)
  73. REQUIRE (VD(i,2) == (double)i);
  74. REQUIRE (Vheader.size() == 3);
  75. REQUIRE (Vheader[0] == "confidence" );
  76. REQUIRE (Vheader[1] == "intensity" );
  77. REQUIRE (Vheader[2] == "dummy_data" );
  78. // Face datashould have only one column
  79. REQUIRE (Fheader.size() == 1);
  80. REQUIRE (Fheader[0] == "face_data" );
  81. REQUIRE (FD.rows() == F.rows());
  82. REQUIRE (FD.cols() == 1);
  83. // the dummy column contents check
  84. for(size_t i=0;i<F.rows();++i)
  85. REQUIRE (FD(i,0) == (double)i);
  86. // Edge data should have only one column
  87. REQUIRE (Eheader.size() == 1);
  88. REQUIRE (Eheader[0] == "edge_data" );
  89. REQUIRE (ED.rows() == E.rows());
  90. REQUIRE (ED.cols() == 1);
  91. // the dummy column contents check
  92. for(size_t i=0;i<E.rows();++i)
  93. REQUIRE (ED(i,0) == (double)i);
  94. // there are comments
  95. REQUIRE (comments.size() == 2);
  96. }
  97. TEST_CASE("writePLY: bunny.ply float", "[igl]")
  98. {
  99. std::ifstream f(test_common::data_path("bunny.ply"));
  100. REQUIRE (f.good());
  101. f.close();
  102. Eigen::MatrixXf V1,N1,UV1,VD1,FD1,ED1;
  103. std::vector<std::string> Vheader1,Fheader1,Eheader1,comments1;
  104. Eigen::MatrixXi F1,E1;
  105. // load test data first
  106. REQUIRE (igl::readPLY(test_common::data_path("bunny.ply"), V1, F1, E1, N1, UV1, VD1,Vheader1, FD1,Fheader1, ED1,Eheader1,comments1));
  107. // add more data
  108. Vheader1.push_back("dummy_data");
  109. Eigen::VectorXf dummy_data(V1.rows());
  110. for(size_t i=0;i<V1.rows();++i)
  111. dummy_data(i)=(double)i;
  112. Eigen::MatrixXf VD2(V1.rows(),VD1.cols()+1);
  113. VD2<<VD1,dummy_data;
  114. // test that saving preserves all the data, including new data column
  115. REQUIRE (igl::writePLY("writePLY_test_bunny_float.ply", V1, F1, E1, N1, UV1, VD2, Vheader1, FD1,Fheader1, ED1, Eheader1, comments1, igl::FileEncoding::Binary));
  116. Eigen::MatrixXf V,N,UV,VD,FD,ED;
  117. Eigen::MatrixXi F,E;
  118. std::vector<std::string> Vheader,Fheader,Eheader,comments;
  119. // test that saving preserves all the data
  120. REQUIRE (igl::readPLY("writePLY_test_bunny_float.ply", V, F, E, N, UV, VD,Vheader, FD,Fheader, ED,Eheader, comments));
  121. REQUIRE (V.rows() == 35947);
  122. REQUIRE (V.cols() == 3);
  123. REQUIRE (F.rows() == 69451);
  124. REQUIRE (F.cols() == 3);
  125. // no edge data
  126. REQUIRE (E.rows() == 0);
  127. REQUIRE (E.cols() == 0);
  128. // no normals or texture coordinates
  129. REQUIRE (N.rows() == 0);
  130. REQUIRE (N.cols() == 0);
  131. REQUIRE (UV.rows() == 0);
  132. REQUIRE (UV.cols() == 0);
  133. // this bunny have additonal data
  134. REQUIRE (VD.rows() == 35947);
  135. REQUIRE (VD.cols() == 3);
  136. // the dummy column contents check
  137. for(size_t i=0;i<V.rows();++i)
  138. REQUIRE (VD(i,2) == (double)i);
  139. REQUIRE (Vheader.size() == 3);
  140. REQUIRE (Vheader[0] == "confidence" );
  141. REQUIRE (Vheader[1] == "intensity" );
  142. REQUIRE (Vheader[2] == "dummy_data" );
  143. // no Face data or edge data
  144. REQUIRE (FD.rows() == 0);
  145. REQUIRE (FD.cols() == 0);
  146. REQUIRE (Fheader.size() == 0);
  147. REQUIRE (ED.rows() == 0);
  148. REQUIRE (ED.cols() == 0);
  149. REQUIRE (Eheader.size() == 0);
  150. // there are comments
  151. REQUIRE (comments.size() == 2);
  152. }