1 #include <gtest/gtest.h> 2 #include <Unittests/unittests_common.hh> 13 virtual void SetUp() {
19 virtual void TearDown() {
38 TEST_F(OpenMeshReadWriteOFF, LoadSimpleOFFFile) {
46 EXPECT_EQ(7526u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
47 EXPECT_EQ(22572u, mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
48 EXPECT_EQ(15048u, mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
52 TEST_F(OpenMeshReadWriteOFF, WriteAndReadVertexColorsToAndFromOFFFile) {
56 mesh_.request_vertex_colors();
67 for (Mesh::VertexIter vit = mesh_.vertices_begin(), vitend = mesh_.vertices_end(); vit != vitend; ++vit)
68 mesh_.set_color(*vit, testColor);
72 for (Mesh::VertexIter vit = mesh_.vertices_begin(), vitend = mesh_.vertices_end(); vit != vitend; ++vit) {
74 if ( color[0] != testColor[0] || color[1] != testColor[1] || color[2] != testColor[2] )
78 EXPECT_EQ(0, count) <<
"Vertices have the wrong color!";
88 for (Mesh::VertexIter vit = mesh_.vertices_begin(), vitend = mesh_.vertices_end(); vit != vitend; ++vit) {
90 if ( color[0] != testColor[0] || color[1] != testColor[1] || color[2] != testColor[2] )
94 EXPECT_EQ(0, count) <<
"Vertices should have the same color after writing and reading the OFF file!";
96 mesh_.release_vertex_colors();
99 TEST_F(OpenMeshReadWriteOFF, WriteAndReadFloatVertexColorsToAndFromOFFFile) {
103 mesh_.request_vertex_colors();
109 EXPECT_TRUE(ok) <<
"meshlab.ply could not be read!";
117 EXPECT_TRUE(ok) <<
"cube_floating.off could not be written!";
120 EXPECT_TRUE(ok) <<
"cube_floating.off could not be read!";
122 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
123 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
124 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
126 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
127 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
128 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
130 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
131 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
132 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
134 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
135 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
136 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
138 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
139 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
140 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
142 EXPECT_FALSE(opt.vertex_has_normal()) <<
"Wrong user opt are returned!";
143 EXPECT_FALSE(opt.vertex_has_texcoord()) <<
"Wrong user opt are returned!";
144 EXPECT_TRUE(opt.vertex_has_color()) <<
"Wrong user opt are returned!";
145 EXPECT_TRUE(opt.color_is_float()) <<
"Wrong user opt are returned!";
147 mesh_.release_vertex_colors();
150 TEST_F(OpenMeshReadWriteOFF, WriteAndReadBinaryFloatVertexColorsToAndFromOFFFile) {
154 mesh_.request_vertex_colors();
160 EXPECT_TRUE(ok) <<
"meshlab.ply could not be read!";
169 EXPECT_TRUE(ok) <<
"cube_floating_binary.off could not be written!";
176 EXPECT_TRUE(ok) <<
"cube_floating_binary.off could not be read!";
178 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
179 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
180 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
182 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
183 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
184 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
186 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
187 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
188 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
190 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
191 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
192 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
194 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
195 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
196 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
198 EXPECT_FALSE(opt.vertex_has_normal()) <<
"Wrong user opt are returned!";
199 EXPECT_FALSE(opt.vertex_has_texcoord()) <<
"Wrong user opt are returned!";
200 EXPECT_FALSE(opt.face_has_color()) <<
"Wrong user opt are returned!";
201 EXPECT_TRUE(opt.vertex_has_color()) <<
"Wrong user opt are returned!";
202 EXPECT_TRUE(opt.color_is_float()) <<
"Wrong user opt are returned!";
203 EXPECT_TRUE(opt.is_binary()) <<
"Wrong user opt are returned!";
205 mesh_.release_vertex_colors();
Kernel::Color Color
Color type.
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files) ...
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Set options for reader/writer modules.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Kernel::Point Point
Coordinate type.
Has (r) / store (w) vertex colors.
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.