From 740d23ed36e1a9caa232b6531a30df81ff93ccc8 Mon Sep 17 00:00:00 2001 From: Isaak Lim Date: Mon, 25 Feb 2013 13:30:56 +0000 Subject: [PATCH] - read_mesh now throws a compile error if an Options::Flag enum is passed as an argument instead of an Options object - added a unit test for writing and reading vertex colors to and from an OFF file. The default color type Vec3uc from DefaultTraits in Traits.hh is used. refs #1404 git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@809 fdac6126-5c0c-442c-9429-916003d36597 --- src/OpenMesh/Core/IO/MeshIO.hh | 14 +++++----- src/Unittests/unittests_loading.hh | 45 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/OpenMesh/Core/IO/MeshIO.hh b/src/OpenMesh/Core/IO/MeshIO.hh index 21a0d0dc..4fb47ed8 100644 --- a/src/OpenMesh/Core/IO/MeshIO.hh +++ b/src/OpenMesh/Core/IO/MeshIO.hh @@ -89,19 +89,16 @@ namespace IO { @param _mesh The target mesh that will be filled with the read data @param _filename fill to load - @param _clear Clear the target data before filling it (allows to - load multiple files into one Mesh) @return Successful? */ template bool read_mesh(Mesh& _mesh, - const std::string& _filename, - bool _clear = true) + const std::string& _filename) { Options opt; - return read_mesh(_mesh, _filename, opt, _clear); + return read_mesh(_mesh, _filename, opt, true); } @@ -116,9 +113,12 @@ read_mesh(Mesh& _mesh, @param _mesh The target mesh that will be filled with the read data @param _filename fill to load @param _opt Reader options (e.g. skip loading of normals ... depends - on the reader capabilities) + on the reader capabilities). Note that simply passing an + Options::Flag enum is not sufficient. @param _clear Clear the target data before filling it (allows to - load multiple files into one Mesh) + load multiple files into one Mesh). If you only want to read a mesh + without clearing set _clear to false. Providing a default Options + object is sufficient in this case. @return Successful? */ diff --git a/src/Unittests/unittests_loading.hh b/src/Unittests/unittests_loading.hh index 7c0c2257..166a2a68 100644 --- a/src/Unittests/unittests_loading.hh +++ b/src/Unittests/unittests_loading.hh @@ -49,6 +49,51 @@ TEST_F(OpenMeshLoader, LoadSimpleOFFFile) { } +TEST_F(OpenMeshLoader, WriteAndReadVertexColorsToAndFromOFFFile) { + + mesh_.clear(); + + mesh_.request_vertex_colors(); + + mesh_.add_vertex( Mesh::Point(0,0,1) ); + mesh_.add_vertex( Mesh::Point(0,1,0) ); + mesh_.add_vertex( Mesh::Point(0,1,1) ); + mesh_.add_vertex( Mesh::Point(1,0,1) ); + + // using the default color type Vec3uc from DefaultTraits in Traits.hh + Mesh::Color testColor(255, 128, 64); + + // setting colors (different from black) + for (Mesh::VertexIter vit = mesh_.vertices_begin(), vitend = mesh_.vertices_end(); vit != vitend; ++vit) + mesh_.set_color(vit, testColor); + + // check if the colors are correctly setted + int count = 0; + for (Mesh::VertexIter vit = mesh_.vertices_begin(), vitend = mesh_.vertices_end(); vit != vitend; ++vit) { + Mesh::Color color = mesh_.color(vit); + if ( color[0] != testColor[0] || color[1] != testColor[1] || color[2] != testColor[2] ) + ++ count; + } + + EXPECT_EQ(0, count) << "Vertices have the wrong color!"; + + // write the mesh_ + OpenMesh::IO::Options opt(OpenMesh::IO::Options::VertexColor); + OpenMesh::IO::write_mesh(mesh_, "temp.off", opt); + OpenMesh::IO::read_mesh(mesh_, "temp.off", opt); + + // check if vertices still have the same color + count = 0; + for (Mesh::VertexIter vit = mesh_.vertices_begin(), vitend = mesh_.vertices_end(); vit != vitend; ++vit) { + Mesh::Color color = mesh_.color(vit); + if ( color[0] != testColor[0] || color[1] != testColor[1] || color[2] != testColor[2] ) + ++ count; + } + + EXPECT_EQ(0, count) << "Vertices should have the same color after writing and reading the OFF file!"; + + mesh_.release_vertex_colors(); +} /* * Just load a simple mesh file in stla format and count whether