2 #include <gtest/gtest.h> 3 #include <Unittests/unittests_common.hh> 14 virtual void SetUp() {
20 virtual void TearDown() {
38 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJ) {
44 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal.obj";
46 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
47 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
48 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
54 TEST_F(OpenMeshReadWriteOBJ, LoadDegeneratedOBJ) {
60 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-degenerated.obj";
62 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
63 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
64 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
70 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJCheckHalfEdgeAndVertexNormals) {
74 mesh_.request_halfedge_normals();
75 mesh_.request_vertex_normals();
80 std::string file_name =
"cube-minimal.obj";
84 EXPECT_TRUE(ok) << file_name;
86 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
87 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
88 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
89 EXPECT_EQ(36u , mesh_.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
93 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex normal at vertex 0 component 0";
94 EXPECT_EQ(-1, mesh_.normal(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex normal at vertex 0 component 1";
95 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex normal at vertex 0 component 2";
97 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex normal at vertex 3 component 0";
98 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex normal at vertex 3 component 1";
99 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex normal at vertex 3 component 2";
101 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex normal at vertex 4 component 0";
102 EXPECT_EQ(-1, mesh_.normal(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex normal at vertex 4 component 1";
103 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex normal at vertex 4 component 2";
105 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex normal at vertex 7 component 0";
106 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex normal at vertex 7 component 1";
107 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex normal at vertex 7 component 2";
111 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(0))[0] ) <<
"Wrong halfedge normal at halfedge 0 component 0";
112 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(0))[1] ) <<
"Wrong halfedge normal at halfedge 0 component 1";
113 EXPECT_EQ(-1, mesh_.normal(mesh_.halfedge_handle(0))[2] ) <<
"Wrong halfedge normal at halfedge 0 component 2";
115 EXPECT_EQ(-1, mesh_.normal(mesh_.halfedge_handle(10))[0] ) <<
"Wrong halfedge normal at halfedge 10 component 0";
116 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(10))[1] ) <<
"Wrong halfedge normal at halfedge 10 component 1";
117 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(10))[2] ) <<
"Wrong halfedge normal at halfedge 10 component 2";
119 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(19))[0] ) <<
"Wrong halfedge normal at halfedge 19 component 0";
120 EXPECT_EQ(1, mesh_.normal(mesh_.halfedge_handle(19))[1] ) <<
"Wrong halfedge normal at halfedge 19 component 1";
121 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(19))[2] ) <<
"Wrong halfedge normal at halfedge 19 component 2";
123 EXPECT_EQ(1, mesh_.normal(mesh_.halfedge_handle(24))[0] ) <<
"Wrong halfedge normal at halfedge 24 component 0";
124 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(24))[1] ) <<
"Wrong halfedge normal at halfedge 24 component 1";
125 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(24))[2] ) <<
"Wrong halfedge normal at halfedge 24 component 2";
127 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(30))[0] ) <<
"Wrong halfedge normal at halfedge 30 component 0";
128 EXPECT_EQ(-1, mesh_.normal(mesh_.halfedge_handle(30))[1] ) <<
"Wrong halfedge normal at halfedge 30 component 1";
129 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(30))[2] ) <<
"Wrong halfedge normal at halfedge 30 component 2";
131 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(35))[0] ) <<
"Wrong halfedge normal at halfedge 35 component 0";
132 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(35))[1] ) <<
"Wrong halfedge normal at halfedge 35 component 1";
133 EXPECT_EQ(1, mesh_.normal(mesh_.halfedge_handle(35))[2] ) <<
"Wrong halfedge normal at halfedge 35 component 2";
135 mesh_.release_vertex_normals();
136 mesh_.release_halfedge_normals();
143 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJForceVertexColorsAlthoughNotAvailable) {
147 mesh_.request_vertex_colors();
149 std::string file_name =
"cube-minimal.obj";
156 EXPECT_TRUE(ok) << file_name;
158 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
159 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
160 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
161 EXPECT_EQ(36u , mesh_.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
169 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJCheckTexCoords) {
173 mesh_.request_halfedge_texcoords2D();
178 std::string file_name =
"cube-minimal-texCoords.obj";
182 EXPECT_TRUE(ok) << file_name;
184 EXPECT_EQ(1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[0] ) <<
"Wrong texCoord at halfedge 0 component 0";
185 EXPECT_EQ(1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[1] ) <<
"Wrong texCoord at halfedge 0 component 1";
187 EXPECT_EQ(3, mesh_.texcoord2D(mesh_.halfedge_handle(10))[0] ) <<
"Wrong texCoord at halfedge 1 component 0";
188 EXPECT_EQ(3, mesh_.texcoord2D(mesh_.halfedge_handle(10))[1] ) <<
"Wrong texCoord at halfedge 1 component 1";
190 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.halfedge_handle(19))[0] ) <<
"Wrong texCoord at halfedge 4 component 0";
191 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.halfedge_handle(19))[1] ) <<
"Wrong texCoord at halfedge 4 component 1";
193 EXPECT_EQ(7, mesh_.texcoord2D(mesh_.halfedge_handle(24))[0] ) <<
"Wrong texCoord at halfedge 7 component 0";
194 EXPECT_EQ(7, mesh_.texcoord2D(mesh_.halfedge_handle(24))[1] ) <<
"Wrong texCoord at halfedge 7 component 1";
196 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.halfedge_handle(30))[0] ) <<
"Wrong texCoord at halfedge 9 component 0";
197 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.halfedge_handle(30))[1] ) <<
"Wrong texCoord at halfedge 9 component 1";
199 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.halfedge_handle(35))[0] ) <<
"Wrong texCoord at halfedge 11 component 0";
200 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.halfedge_handle(35))[1] ) <<
"Wrong texCoord at halfedge 11 component 1";
202 mesh_.release_halfedge_texcoords2D();
208 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJCheckTexCoords3d) {
212 mesh_.request_halfedge_texcoords3D();
217 std::string file_name =
"cube-minimal-texCoords3d.obj";
221 EXPECT_TRUE(ok) << file_name;
223 EXPECT_EQ(1, mesh_.texcoord3D(mesh_.halfedge_handle(0))[0] ) <<
"Wrong texCoord at halfedge 0 component 0";
224 EXPECT_EQ(1, mesh_.texcoord3D(mesh_.halfedge_handle(0))[1] ) <<
"Wrong texCoord at halfedge 0 component 1";
225 EXPECT_EQ(1, mesh_.texcoord3D(mesh_.halfedge_handle(0))[2] ) <<
"Wrong texCoord at halfedge 0 component 2";
227 EXPECT_EQ(3, mesh_.texcoord3D(mesh_.halfedge_handle(10))[0] ) <<
"Wrong texCoord at halfedge 1 component 0";
228 EXPECT_EQ(3, mesh_.texcoord3D(mesh_.halfedge_handle(10))[1] ) <<
"Wrong texCoord at halfedge 1 component 1";
229 EXPECT_EQ(3, mesh_.texcoord3D(mesh_.halfedge_handle(10))[2] ) <<
"Wrong texCoord at halfedge 1 component 2";
231 EXPECT_EQ(6, mesh_.texcoord3D(mesh_.halfedge_handle(19))[0] ) <<
"Wrong texCoord at halfedge 4 component 0";
232 EXPECT_EQ(6, mesh_.texcoord3D(mesh_.halfedge_handle(19))[1] ) <<
"Wrong texCoord at halfedge 4 component 1";
233 EXPECT_EQ(6, mesh_.texcoord3D(mesh_.halfedge_handle(19))[2] ) <<
"Wrong texCoord at halfedge 4 component 2";
235 EXPECT_EQ(7, mesh_.texcoord3D(mesh_.halfedge_handle(24))[0] ) <<
"Wrong texCoord at halfedge 7 component 0";
236 EXPECT_EQ(7, mesh_.texcoord3D(mesh_.halfedge_handle(24))[1] ) <<
"Wrong texCoord at halfedge 7 component 1";
237 EXPECT_EQ(7, mesh_.texcoord3D(mesh_.halfedge_handle(24))[2] ) <<
"Wrong texCoord at halfedge 7 component 2";
239 EXPECT_EQ(9, mesh_.texcoord3D(mesh_.halfedge_handle(30))[0] ) <<
"Wrong texCoord at halfedge 9 component 0";
240 EXPECT_EQ(9, mesh_.texcoord3D(mesh_.halfedge_handle(30))[1] ) <<
"Wrong texCoord at halfedge 9 component 1";
241 EXPECT_EQ(9, mesh_.texcoord3D(mesh_.halfedge_handle(30))[2] ) <<
"Wrong texCoord at halfedge 9 component 2";
243 EXPECT_EQ(12, mesh_.texcoord3D(mesh_.halfedge_handle(35))[0] ) <<
"Wrong texCoord at halfedge 11 component 0";
244 EXPECT_EQ(12, mesh_.texcoord3D(mesh_.halfedge_handle(35))[1] ) <<
"Wrong texCoord at halfedge 11 component 1";
245 EXPECT_EQ(12, mesh_.texcoord3D(mesh_.halfedge_handle(35))[2] ) <<
"Wrong texCoord at halfedge 11 component 2";
247 mesh_.request_halfedge_texcoords3D();
253 TEST_F(OpenMeshReadWriteOBJ, LoadObjWithMaterial) {
257 mesh_.request_face_colors();
262 std::string file_name =
"square_material.obj";
266 EXPECT_TRUE(ok) << file_name;
270 EXPECT_TRUE(fh.
is_valid()) <<
"fh should be valid";
272 EXPECT_EQ(128, mesh_.color(fh)[0] ) <<
"Wrong vertex color at vertex 0 component 0";
273 EXPECT_EQ(128, mesh_.color(fh)[1] ) <<
"Wrong vertex color at vertex 0 component 1";
274 EXPECT_EQ(128, mesh_.color(fh)[2] ) <<
"Wrong vertex color at vertex 0 component 2";
276 mesh_.release_face_colors();
279 TEST_F(OpenMeshReadWriteOBJ, LoadObjWithTexture) {
283 mesh_.request_face_colors();
284 mesh_.request_face_texture_index();
289 std::string file_name =
"square_material_texture.obj";
293 EXPECT_TRUE(ok) << file_name;
297 mesh_.get_property_handle(property,
"TextureMapping");
298 EXPECT_EQ(mesh_.property(property).size(), 1u) <<
"More than one texture defined";
299 std::map< int, std::string >::iterator tex = mesh_.property(property).find(1);
300 EXPECT_TRUE(tex != mesh_.property(property).end()) <<
"Could not find texture with id 1";
301 EXPECT_TRUE((mesh_.property(property)[1] == std::string(
"square_material_texture.jpg"))) <<
"Wrong texture name";
305 EXPECT_TRUE(fh.
is_valid()) <<
"fh should be valid";
306 EXPECT_EQ(mesh_.property(mesh_.face_texture_index_pph(),fh),1) <<
"Face texture index is not set correctly";
308 mesh_.release_face_colors();
309 mesh_.release_face_texture_index();
315 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJWithVertexColorsAfterVertices) {
319 mesh_.request_vertex_colors();
326 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-vertex-colors-after-vertex-definition.obj";
328 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
329 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
330 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
332 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
333 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
334 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
336 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
337 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
338 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
340 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
341 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
342 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
344 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
345 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
346 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
348 mesh_.release_vertex_colors();
354 TEST_F(OpenMeshReadWriteOBJ, LoadSimpleOBJWithVertexColorsAsVCLines) {
358 mesh_.request_vertex_colors();
365 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-vertex-colors-as-vc-lines.obj";
367 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
368 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
369 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
371 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
372 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
373 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
375 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
376 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
377 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
379 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
380 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
381 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
383 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
384 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
385 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
387 mesh_.release_vertex_colors();
394 TEST_F(OpenMeshReadWriteOBJ, ReadWriteReadSimpleOBJ) {
397 mesh_.request_vertex_normals();
403 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal.obj";
407 const char* filename =
"cube-minimal_openmeshOutputTestfile.obj";
410 mesh_.release_vertex_normals();
411 ASSERT_TRUE(ok) <<
"Unable to write obj mesh";
414 mesh2.request_vertex_normals();
421 ASSERT_TRUE(ok) <<
"Unable to read written mesh";
423 EXPECT_EQ(8u , mesh2.n_vertices()) <<
"The number of loaded vertices is not correct!";
424 EXPECT_EQ(18u , mesh2.n_edges()) <<
"The number of loaded edges is not correct!";
425 EXPECT_EQ(12u , mesh2.n_faces()) <<
"The number of loaded faces is not correct!";
429 EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(0))[0] ) <<
"Wrong vertex normal at vertex 0 component 0";
430 EXPECT_EQ(-1, mesh2.normal(mesh2.vertex_handle(0))[1] ) <<
"Wrong vertex normal at vertex 0 component 1";
431 EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(0))[2] ) <<
"Wrong vertex normal at vertex 0 component 2";
433 EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(3))[0] ) <<
"Wrong vertex normal at vertex 3 component 0";
434 EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(3))[1] ) <<
"Wrong vertex normal at vertex 3 component 1";
435 EXPECT_EQ(1, mesh2.normal(mesh2.vertex_handle(3))[2] ) <<
"Wrong vertex normal at vertex 3 component 2";
437 EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(4))[0] ) <<
"Wrong vertex normal at vertex 4 component 0";
438 EXPECT_EQ(-1, mesh2.normal(mesh2.vertex_handle(4))[1] ) <<
"Wrong vertex normal at vertex 4 component 1";
439 EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(4))[2] ) <<
"Wrong vertex normal at vertex 4 component 2";
441 EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(7))[0] ) <<
"Wrong vertex normal at vertex 7 component 0";
442 EXPECT_EQ(0, mesh2.normal(mesh2.vertex_handle(7))[1] ) <<
"Wrong vertex normal at vertex 7 component 1";
443 EXPECT_EQ(1, mesh2.normal(mesh2.vertex_handle(7))[2] ) <<
"Wrong vertex normal at vertex 7 component 2";
Has (r) / store (w) vertex normals.
void clear(void)
Clear all bits.
bool is_valid() const
The handle is valid iff the index is not equal to -1.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Set options for reader/writer modules.
Handle for a face entity.
Has (r) / store (w) face texture coordinates.
Has (r) / store (w) face colors.
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.