Fixes a bug in writePLY introduced in dfda6de04e (#1867)
Addes a test to make sure it works as expected
This commit is contained in:
@@ -147,7 +147,7 @@ bool writePLY(
|
||||
_ed.resize(ED.size());
|
||||
Eigen::Map<Eigen::Matrix<EDScalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > >( &_ed[0], ED.rows(), ED.cols() ) = ED;
|
||||
|
||||
file.add_properties_to_element("face", FDheader,
|
||||
file.add_properties_to_element("edge", EDheader,
|
||||
tynyply_type<EDScalar>(), ED.rows(), reinterpret_cast<uint8_t*>( &_ed[0] ), tinyply::Type::INVALID, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <test_common.h>
|
||||
#include <igl/readPLY.h>
|
||||
#include <igl/writePLY.h>
|
||||
#include <igl/edges.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -31,12 +32,37 @@ TEST_CASE("writePLY: bunny.ply", "[igl]")
|
||||
Eigen::VectorXd face_data(F1.rows());
|
||||
for(size_t i=0;i<F1.rows();++i)
|
||||
face_data(i)=(double)i;
|
||||
Eigen::MatrixXd FD2(F1.rows(),FD1.cols()+1);
|
||||
|
||||
|
||||
|
||||
// there is no face data in the input file
|
||||
Eigen::MatrixXd FD2(F1.rows(),FD1.cols()+1);
|
||||
FD2<<face_data;
|
||||
|
||||
//input file have no edge data
|
||||
REQUIRE (E1.rows() == 0);
|
||||
REQUIRE (E1.cols() == 0);
|
||||
REQUIRE (ED1.rows() == 0);
|
||||
REQUIRE (Eheader1.empty());
|
||||
|
||||
Eigen::MatrixXi E2;
|
||||
std::vector<std::string> Eheader2;
|
||||
|
||||
//generate edges
|
||||
igl::edges(F1,E2);
|
||||
|
||||
//generate edge data
|
||||
Eheader2.push_back("edge_data");
|
||||
Eigen::VectorXd edge_data(E2.rows());
|
||||
for(size_t i=0;i<E2.rows();++i)
|
||||
edge_data(i)=(double)i;
|
||||
|
||||
// there is no edge data in the input file
|
||||
Eigen::MatrixXd ED2(E2.rows(),1);
|
||||
ED2<<edge_data;
|
||||
|
||||
// test that saving preserves all the data, including new data column
|
||||
REQUIRE (igl::writePLY("writePLY_test_bunny.ply", V1, F1, E1, N1, UV1, VD2, Vheader1, FD2,Fheader1, ED1, Eheader1, comments1, igl::FileEncoding::Binary));
|
||||
REQUIRE (igl::writePLY("writePLY_test_bunny.ply", V1, F1, E2, N1, UV1, VD2, Vheader1, FD2,Fheader1, ED2, Eheader2, comments1, igl::FileEncoding::Binary));
|
||||
|
||||
Eigen::MatrixXd V,N,UV,VD,FD,ED;
|
||||
Eigen::MatrixXi F,E;
|
||||
@@ -49,9 +75,10 @@ TEST_CASE("writePLY: bunny.ply", "[igl]")
|
||||
REQUIRE (V.cols() == 3);
|
||||
REQUIRE (F.rows() == 69451);
|
||||
REQUIRE (F.cols() == 3);
|
||||
// no edge data
|
||||
REQUIRE (E.rows() == 0);
|
||||
REQUIRE (E.cols() == 0);
|
||||
|
||||
// generated edges
|
||||
REQUIRE (E.rows() == E2.rows());
|
||||
REQUIRE (E.cols() == E2.cols());
|
||||
|
||||
// no normals or texture coordinates
|
||||
REQUIRE (N.rows() == 0);
|
||||
@@ -72,7 +99,7 @@ TEST_CASE("writePLY: bunny.ply", "[igl]")
|
||||
REQUIRE (Vheader[1] == "intensity" );
|
||||
REQUIRE (Vheader[2] == "dummy_data" );
|
||||
|
||||
// Face should have only one column
|
||||
// Face datashould have only one column
|
||||
REQUIRE (Fheader.size() == 1);
|
||||
REQUIRE (Fheader[0] == "face_data" );
|
||||
REQUIRE (FD.rows() == F.rows());
|
||||
@@ -82,9 +109,16 @@ TEST_CASE("writePLY: bunny.ply", "[igl]")
|
||||
for(size_t i=0;i<F.rows();++i)
|
||||
REQUIRE (FD(i,0) == (double)i);
|
||||
|
||||
REQUIRE (ED.rows() == 0);
|
||||
REQUIRE (ED.cols() == 0);
|
||||
REQUIRE (Eheader.size() == 0);
|
||||
// Edge data should have only one column
|
||||
REQUIRE (Eheader.size() == 1);
|
||||
REQUIRE (Eheader[0] == "edge_data" );
|
||||
REQUIRE (ED.rows() == E.rows());
|
||||
REQUIRE (ED.cols() == 1);
|
||||
|
||||
// the dummy column contents check
|
||||
for(size_t i=0;i<E.rows();++i)
|
||||
REQUIRE (ED(i,0) == (double)i);
|
||||
|
||||
|
||||
// there are comments
|
||||
REQUIRE (comments.size() == 2);
|
||||
|
||||
Reference in New Issue
Block a user