From 7d092c7465692923092896f9b5ee105db3b2c83e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Thu, 1 Dec 2011 16:54:11 +0000 Subject: [PATCH] Tests for ply reader with and without normals, ascii mode git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@477 fdac6126-5c0c-442c-9429-916003d36597 --- .../TestFiles/cube-minimal-normals.ply | 26 +++++++++ src/Unittests/TestFiles/cube-minimal.ply | 23 ++++++++ src/Unittests/unittests_loading.hh | 53 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 src/Unittests/TestFiles/cube-minimal-normals.ply create mode 100644 src/Unittests/TestFiles/cube-minimal.ply diff --git a/src/Unittests/TestFiles/cube-minimal-normals.ply b/src/Unittests/TestFiles/cube-minimal-normals.ply new file mode 100644 index 00000000..c5519ec1 --- /dev/null +++ b/src/Unittests/TestFiles/cube-minimal-normals.ply @@ -0,0 +1,26 @@ +ply +format ascii 1.0 +element vertex 8 +property float32 x +property float32 y +property float32 z +property float32 nx +property float32 ny +property float32 nz +element face 6 +property list uint8 int32 vertex_indices +end_header +-1 -1 -1 0.0 0.0 1.0 +1 -1 -1 0.0 1.0 0.0 +1 1 -1 0.0 1.0 1.0 +-1 1 -1 1.0 0.0 0.0 +-1 -1 1 1.0 0.0 1.0 +1 -1 1 1.0 1.0 0.0 +1 1 1 1.0 1.0 1.0 +-1 1 1 1.0 1.0 2.0 +4 0 1 2 3 +4 5 4 7 6 +4 6 2 1 5 +4 3 7 4 0 +4 7 3 2 6 +4 5 1 0 4 diff --git a/src/Unittests/TestFiles/cube-minimal.ply b/src/Unittests/TestFiles/cube-minimal.ply new file mode 100644 index 00000000..3ec0f55e --- /dev/null +++ b/src/Unittests/TestFiles/cube-minimal.ply @@ -0,0 +1,23 @@ +ply +format ascii 1.0 +element vertex 8 +property float32 x +property float32 y +property float32 z +element face 6 +property list uint8 int32 vertex_indices +end_header +-1 -1 -1 +1 -1 -1 +1 1 -1 +-1 1 -1 +-1 -1 1 +1 -1 1 +1 1 1 +-1 1 1 +4 0 1 2 3 +4 5 4 7 6 +4 6 2 1 5 +4 3 7 4 0 +4 7 3 2 6 +4 5 1 0 4 diff --git a/src/Unittests/unittests_loading.hh b/src/Unittests/unittests_loading.hh index d5b0cb4c..27130a9a 100644 --- a/src/Unittests/unittests_loading.hh +++ b/src/Unittests/unittests_loading.hh @@ -174,9 +174,62 @@ TEST_F(OpenMeshLoader, LoadSimpleOBJWithVertexColorsAsVCLines) { } +/* + * Just load a ply + */ +TEST_F(OpenMeshLoader, LoadSimplePLY) { + + mesh_.clear(); + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal.ply"); + + EXPECT_TRUE(ok) << "Unable to load cube-minimal.ply"; + + EXPECT_EQ(8, mesh_.n_vertices()) << "The number of loaded vertices is not correct!"; + EXPECT_EQ(18, mesh_.n_edges()) << "The number of loaded edges is not correct!"; + EXPECT_EQ(12, mesh_.n_faces()) << "The number of loaded faces is not correct!"; + +} + + +/* + * Just load a ply with normals, ascii mode + */ +TEST_F(OpenMeshLoader, LoadSimplePLYWithNormals) { + + mesh_.clear(); + + mesh_.request_vertex_normals(); + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-normals.ply"); + EXPECT_TRUE(ok) << "Unable to load cube-minimal-normals.ply"; + + EXPECT_EQ(8, mesh_.n_vertices()) << "The number of loaded vertices is not correct!"; + EXPECT_EQ(18, mesh_.n_edges()) << "The number of loaded edges is not correct!"; + EXPECT_EQ(12, mesh_.n_faces()) << "The number of loaded faces is not correct!"; + EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) << "Wrong normal at vertex 0 component 0"; + EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[1] ) << "Wrong normal at vertex 0 component 1"; + EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(0))[2] ) << "Wrong normal at vertex 0 component 2"; + + EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(3))[0] ) << "Wrong normal at vertex 3 component 0"; + EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[1] ) << "Wrong normal at vertex 3 component 1"; + EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[2] ) << "Wrong normal at vertex 3 component 2"; + + EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[0] ) << "Wrong normal at vertex 4 component 0"; + EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[1] ) << "Wrong normal at vertex 4 component 1"; + EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[2] ) << "Wrong normal at vertex 4 component 2"; + + EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[0] ) << "Wrong normal at vertex 7 component 0"; + EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[1] ) << "Wrong normal at vertex 7 component 1"; + EXPECT_EQ(2, mesh_.normal(mesh_.vertex_handle(7))[2] ) << "Wrong normal at vertex 7 component 2"; + + mesh_.release_vertex_normals(); + +} + #endif // INCLUDE GUARD -- GitLab