writePLY.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }