writePLY.cpp 5.0 KB

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