diff --git a/src/Unittests/TestFiles/cube-minimal-texCoords.ply b/src/Unittests/TestFiles/cube-minimal-texCoords.ply new file mode 100644 index 00000000..a344928b --- /dev/null +++ b/src/Unittests/TestFiles/cube-minimal-texCoords.ply @@ -0,0 +1,35 @@ +ply +format ascii 1.0 +comment ================================= +comment Exported via OpenFlipper 1.4 +comment www.openflipper.org +comment ================================= +element vertex 8 +property float x +property float y +property float z +property int32 u +property int32 v +element face 12 +property list uchar int32 vertex_index +end_header +0 0 0 10 10 +0 0 1 12 12 +0 1 0 6 6 +0 1 1 12 12 +1 0 0 9 9 +1 0 1 11 11 +1 1 0 7 7 +1 1 1 12 12 +3 0 6 4 +3 0 2 6 +3 0 3 2 +3 0 1 3 +3 2 7 6 +3 2 3 7 +3 4 6 7 +3 4 7 5 +3 0 4 5 +3 0 5 1 +3 1 5 7 +3 1 7 3 diff --git a/src/Unittests/TestFiles/cube-minimal-vertexColors.ply b/src/Unittests/TestFiles/cube-minimal-vertexColors.ply new file mode 100644 index 00000000..e591a883 --- /dev/null +++ b/src/Unittests/TestFiles/cube-minimal-vertexColors.ply @@ -0,0 +1,36 @@ +ply +format ascii 1.0 +comment ================================= +comment Exported via OpenFlipper 1.4 +comment www.openflipper.org +comment ================================= +element vertex 8 +property float x +property float y +property float z +property uchar red +property uchar green +property uchar blue +element face 12 +property list uchar int32 vertex_index +end_header +0 0 0 255 0 0 +0 0 1 255 0 0 +0 1 0 255 0 0 +0 1 1 255 0 0 +1 0 0 0 0 255 +1 0 1 0 0 255 +1 1 0 0 0 255 +1 1 1 0 0 255 +3 0 6 4 +3 0 2 6 +3 0 3 2 +3 0 1 3 +3 2 7 6 +3 2 3 7 +3 4 6 7 +3 4 7 5 +3 0 4 5 +3 0 5 1 +3 1 5 7 +3 1 7 3 diff --git a/src/Unittests/unittests_loading.hh b/src/Unittests/unittests_loading.hh index 46db12cd..1136ce45 100644 --- a/src/Unittests/unittests_loading.hh +++ b/src/Unittests/unittests_loading.hh @@ -374,6 +374,116 @@ TEST_F(OpenMeshLoader, LoadSimplePLY) { } +/* + * Just load a ply file and set vertex color option before loading + */ +TEST_F(OpenMeshLoader, LoadSimplePLYForceVertexColorsAlthoughNotAvailable) { + + mesh_.clear(); + + mesh_.request_vertex_colors(); + + std::string file_name = "cube-minimal.ply"; + + OpenMesh::IO::Options options; + options += OpenMesh::IO::Options::VertexColor; + + bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options); + + EXPECT_TRUE(ok) << file_name; + + EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!"; + EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!"; + EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!"; + EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!"; + + EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!"; + EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!"; + EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!"; +} + +/* + * Just load a ply file of a cube with vertex colors + */ +TEST_F(OpenMeshLoader, LoadSimplePLYWithVertexColors) { + + mesh_.clear(); + + mesh_.request_vertex_colors(); + + OpenMesh::IO::Options options; + options += OpenMesh::IO::Options::VertexColor; + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.ply",options); + + EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.ply"; + + EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!"; + EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!"; + EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!"; + + EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0"; + EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1"; + EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2"; + + EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0"; + EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1"; + EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2"; + + EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0"; + EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1"; + EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2"; + + EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0"; + EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1"; + EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2"; + + EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!"; + EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!"; + EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!"; + + mesh_.release_vertex_colors(); +} + +/* + * Just load a ply file of a cube with vertex texCoords + */ +TEST_F(OpenMeshLoader, LoadSimplePLYWithTexCoords) { + + mesh_.clear(); + + mesh_.request_vertex_texcoords2D(); + + OpenMesh::IO::Options options; + options += OpenMesh::IO::Options::VertexTexCoord; + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-texCoords.ply",options); + + EXPECT_TRUE(ok) << "Unable to load cube-minimal-texCoords.ply"; + + EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!"; + EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!"; + EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!"; + + EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0"; + EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1"; + + EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) << "Wrong vertex color at vertex 2 component 0"; + EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) << "Wrong vertex color at vertex 2 component 1"; + + EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0"; + EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1"; + + EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0"; + EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1"; + + + EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!"; + EXPECT_TRUE(options.vertex_has_texcoord()) << "Wrong user options are returned!"; + EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!"; + + mesh_.release_vertex_texcoords2D(); +} /* * Just load a ply with normals, ascii mode