writePLY.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. // test that saving preserves all the data, including new data column
  25. REQUIRE (igl::writePLY("test_bunny.ply", V1, F1, E1, N1, UV1, VD2, Vheader1, FD1,Fheader1, ED1, Eheader1, comments1, true));
  26. Eigen::MatrixXd V,N,UV,VD,FD,ED;
  27. Eigen::MatrixXi F,E;
  28. std::vector<std::string> Vheader,Fheader,Eheader,comments;
  29. // test that saving preserves all the data
  30. REQUIRE (igl::readPLY("test_bunny.ply", V, F, E, N, UV, VD,Vheader, FD,Fheader, ED,Eheader, comments));
  31. REQUIRE (V.rows() == 35947);
  32. REQUIRE (V.cols() == 3);
  33. REQUIRE (F.rows() == 69451);
  34. REQUIRE (F.cols() == 3);
  35. // no edge data
  36. REQUIRE (E.rows() == 0);
  37. REQUIRE (E.cols() == 0);
  38. // no normals or texture coordinates
  39. REQUIRE (N.rows() == 0);
  40. REQUIRE (N.cols() == 0);
  41. REQUIRE (UV.rows() == 0);
  42. REQUIRE (UV.cols() == 0);
  43. // this bunny have additonal data
  44. REQUIRE (VD.rows() == 35947);
  45. REQUIRE (VD.cols() == 3);
  46. // the dummy column contents check
  47. for(size_t i=0;i<V.rows();++i)
  48. REQUIRE (VD(i,2) == (double)i);
  49. REQUIRE (Vheader.size() == 3);
  50. REQUIRE (Vheader[0] == "confidence" );
  51. REQUIRE (Vheader[1] == "intensity" );
  52. REQUIRE (Vheader[2] == "dummy_data" );
  53. // no Face data or edge data
  54. REQUIRE (FD.rows() == 0);
  55. REQUIRE (FD.cols() == 0);
  56. REQUIRE (Fheader.size() == 0);
  57. REQUIRE (ED.rows() == 0);
  58. REQUIRE (ED.cols() == 0);
  59. REQUIRE (Eheader.size() == 0);
  60. // there are comments
  61. REQUIRE (comments.size() == 2);
  62. }
  63. TEST_CASE("writePLY: bunny.ply float", "[igl]")
  64. {
  65. std::ifstream f(test_common::data_path("bunny.ply"));
  66. REQUIRE (f.good());
  67. f.close();
  68. Eigen::MatrixXf V1,N1,UV1,VD1,FD1,ED1;
  69. std::vector<std::string> Vheader1,Fheader1,Eheader1,comments1;
  70. Eigen::MatrixXi F1,E1;
  71. // load test data first
  72. REQUIRE (igl::readPLY(test_common::data_path("bunny.ply"), V1, F1, E1, N1, UV1, VD1,Vheader1, FD1,Fheader1, ED1,Eheader1,comments1));
  73. // add more data
  74. Vheader1.push_back("dummy_data");
  75. Eigen::VectorXf dummy_data(V1.rows());
  76. for(size_t i=0;i<V1.rows();++i)
  77. dummy_data(i)=(double)i;
  78. Eigen::MatrixXf VD2(V1.rows(),VD1.cols()+1);
  79. VD2<<VD1,dummy_data;
  80. // test that saving preserves all the data, including new data column
  81. REQUIRE (igl::writePLY("test_bunny.ply", V1, F1, E1, N1, UV1, VD2, Vheader1, FD1,Fheader1, ED1, Eheader1, comments1, true));
  82. Eigen::MatrixXf V,N,UV,VD,FD,ED;
  83. Eigen::MatrixXi F,E;
  84. std::vector<std::string> Vheader,Fheader,Eheader,comments;
  85. // test that saving preserves all the data
  86. REQUIRE (igl::readPLY("test_bunny.ply", V, F, E, N, UV, VD,Vheader, FD,Fheader, ED,Eheader, comments));
  87. REQUIRE (V.rows() == 35947);
  88. REQUIRE (V.cols() == 3);
  89. REQUIRE (F.rows() == 69451);
  90. REQUIRE (F.cols() == 3);
  91. // no edge data
  92. REQUIRE (E.rows() == 0);
  93. REQUIRE (E.cols() == 0);
  94. // no normals or texture coordinates
  95. REQUIRE (N.rows() == 0);
  96. REQUIRE (N.cols() == 0);
  97. REQUIRE (UV.rows() == 0);
  98. REQUIRE (UV.cols() == 0);
  99. // this bunny have additonal data
  100. REQUIRE (VD.rows() == 35947);
  101. REQUIRE (VD.cols() == 3);
  102. // the dummy column contents check
  103. for(size_t i=0;i<V.rows();++i)
  104. REQUIRE (VD(i,2) == (double)i);
  105. REQUIRE (Vheader.size() == 3);
  106. REQUIRE (Vheader[0] == "confidence" );
  107. REQUIRE (Vheader[1] == "intensity" );
  108. REQUIRE (Vheader[2] == "dummy_data" );
  109. // no Face data or edge data
  110. REQUIRE (FD.rows() == 0);
  111. REQUIRE (FD.cols() == 0);
  112. REQUIRE (Fheader.size() == 0);
  113. REQUIRE (ED.rows() == 0);
  114. REQUIRE (ED.cols() == 0);
  115. REQUIRE (Eheader.size() == 0);
  116. // there are comments
  117. REQUIRE (comments.size() == 2);
  118. }