1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
12 virtual void SetUp() {
18 virtual void TearDown() {
36 TEST_F(OpenMeshReadWriteOM, LoadSimpleOMForceVertexColorsAlthoughNotAvailable) {
40 mesh_.request_vertex_colors();
42 std::string file_name =
"cube-minimal.om";
49 EXPECT_TRUE(ok) << file_name;
51 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
52 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
53 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
54 EXPECT_EQ(36u , mesh_.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
56 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
57 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
58 EXPECT_FALSE(options.vertex_has_color()) <<
"Wrong user options are returned!";
64 TEST_F(OpenMeshReadWriteOM, LoadSimpleOMWithTexCoords) {
68 mesh_.request_vertex_texcoords2D();
75 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-texCoords.om";
77 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
78 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
79 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
81 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
82 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
84 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) <<
"Wrong vertex color at vertex 2 component 0";
85 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) <<
"Wrong vertex color at vertex 2 component 1";
87 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
88 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
90 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
91 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
94 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
95 EXPECT_TRUE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
96 EXPECT_FALSE(options.vertex_has_color()) <<
"Wrong user options are returned!";
98 mesh_.release_vertex_texcoords2D();
104 TEST_F(OpenMeshReadWriteOM, LoadSimpleOMWithVertexColors) {
108 mesh_.request_vertex_colors();
115 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-vertexColors.om";
117 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
118 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
119 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
121 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
122 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
123 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
125 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
126 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
127 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
129 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
130 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
131 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
133 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
134 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
135 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
137 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
138 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
139 EXPECT_TRUE(options.vertex_has_color()) <<
"Wrong user options are returned!";
141 mesh_.release_vertex_colors();
147 TEST_F(OpenMeshReadWriteOM, WriteTriangle) {
152 const std::string filename =
"triangle-minimal.om";
158 mesh.add_face(v1,v2,v3);
162 EXPECT_TRUE(ok) <<
"Unable to write " << filename;
169 EXPECT_TRUE(ok) <<
"Unable to read " << filename;
172 EXPECT_EQ(3u , mesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
173 EXPECT_EQ(3u , mesh.n_edges()) <<
"The number of loaded edges is not correct!";
174 EXPECT_EQ(1u , mesh.n_faces()) <<
"The number of loaded faces is not correct!";
176 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , mesh.point(v1)) <<
"Wrong coordinates at vertex 0";
177 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , mesh.point(v2)) <<
"Wrong coordinates at vertex 1";
178 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , mesh.point(v3)) <<
"Wrong coordinates at vertex 2";
181 remove(filename.c_str());
188 TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexIntegerColor) {
192 mesh.request_vertex_colors();
198 const std::string filename =
"triangle-minimal-ColorsPerVertex.om";
204 mesh.add_face(v1,v2,v3);
210 mesh.set_color(v1,c1);
211 mesh.set_color(v2,c2);
212 mesh.set_color(v3,c3);
216 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
218 mesh.release_vertex_colors();
222 cmpMesh.request_vertex_colors();
224 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
226 EXPECT_TRUE(cmpMesh.has_vertex_colors()) <<
"Loaded mesh has no vertex colors.";
229 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
230 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
231 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
233 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
234 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
235 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
237 EXPECT_EQ(c1 , cmpMesh.color(v1)) <<
"Wrong colors at vertex 0";
238 EXPECT_EQ(c2 , cmpMesh.color(v2)) <<
"Wrong colors at vertex 1";
239 EXPECT_EQ(c3 , cmpMesh.color(v3)) <<
"Wrong colors at vertex 2";
242 cmpMesh.release_vertex_colors();
243 remove(filename.c_str());
250 TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexBoolProperty) {
254 const std::string filename =
"triangle-minimal-VBProp.om";
260 mesh.add_face(v1,v2,v3);
263 mesh.add_property(prop,
"VBProp");
264 mesh.property(prop).set_persistent(
true);
266 mesh.property(prop,v1) =
true;
267 mesh.property(prop,v2) =
false;
268 mesh.property(prop,v3) =
true;
272 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
278 cmpMesh.add_property(prop,
"VBProp");
279 cmpMesh.property(prop).set_persistent(
true);
282 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
285 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
286 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
287 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
289 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
290 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
291 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
293 EXPECT_TRUE(cmpMesh.property(prop,v1)) <<
"Wrong Property value at vertex 0";
294 EXPECT_FALSE(cmpMesh.property(prop,v2)) <<
"Wrong Property value at vertex 1";
295 EXPECT_TRUE(cmpMesh.property(prop,v3)) <<
"Wrong Property value at vertex 2";
298 remove(filename.c_str());
305 TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexBoolPropertySpaceEquivalent) {
309 const std::string filename =
"triangle-minimal-VBProp-pattern-test.om";
315 mesh.add_face(v1,v2,v3);
320 mesh.add_face(v4,v5,v6);
327 mesh.add_property(prop,
"VBProp");
328 mesh.property(prop).set_persistent(
true);
331 mesh.property(prop,v1) =
false;
332 mesh.property(prop,v2) =
false;
333 mesh.property(prop,v3) =
false;
334 mesh.property(prop,v4) =
false;
335 mesh.property(prop,v5) =
false;
336 mesh.property(prop,v6) =
true;
337 mesh.property(prop,v7) =
false;
338 mesh.property(prop,v8) =
false;
339 mesh.property(prop,v9) =
true;
343 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
348 cmpMesh.add_property(prop,
"VBProp");
349 cmpMesh.property(prop).set_persistent(
true);
352 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
355 EXPECT_EQ(9u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
356 EXPECT_EQ(6u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
357 EXPECT_EQ(2u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
359 EXPECT_FALSE(cmpMesh.property(prop,v1)) <<
"Wrong Property value at vertex 0";
360 EXPECT_FALSE(cmpMesh.property(prop,v2)) <<
"Wrong Property value at vertex 1";
361 EXPECT_FALSE(cmpMesh.property(prop,v3)) <<
"Wrong Property value at vertex 2";
362 EXPECT_FALSE(cmpMesh.property(prop,v4)) <<
"Wrong Property value at vertex 3";
363 EXPECT_FALSE(cmpMesh.property(prop,v5)) <<
"Wrong Property value at vertex 4";
364 EXPECT_TRUE(cmpMesh.property(prop,v6)) <<
"Wrong Property value at vertex 5";
365 EXPECT_FALSE(cmpMesh.property(prop,v7)) <<
"Wrong Property value at vertex 6";
366 EXPECT_FALSE(cmpMesh.property(prop,v8)) <<
"Wrong Property value at vertex 7";
367 EXPECT_TRUE(cmpMesh.property(prop,v9)) <<
"Wrong Property value at vertex 8";
370 remove(filename.c_str());
377 TEST_F(OpenMeshReadWriteOM, WriteTriangleTwoVertexBoolProperty) {
381 const std::string filename =
"triangle-minimal-VBProp.om";
387 mesh.add_face(v1,v2,v3);
390 mesh.add_property(prop,
"VBProp");
391 mesh.property(prop).set_persistent(
true);
393 mesh.property(prop,v1) =
true;
394 mesh.property(prop,v2) =
false;
395 mesh.property(prop,v3) =
true;
398 mesh.add_property(prop2,
"VBProp2");
399 mesh.property(prop2).set_persistent(
true);
401 mesh.property(prop2,v1) =
false;
402 mesh.property(prop2,v2) =
false;
403 mesh.property(prop2,v3) =
false;
407 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
412 cmpMesh.add_property(prop,
"VBProp");
413 cmpMesh.property(prop).set_persistent(
true);
415 cmpMesh.add_property(prop2,
"VBProp2");
416 cmpMesh.property(prop2).set_persistent(
true);
419 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
422 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
423 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
424 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
426 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
427 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
428 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
430 EXPECT_TRUE(cmpMesh.property(prop,v1)) <<
"Wrong Property value at vertex 0";
431 EXPECT_FALSE(cmpMesh.property(prop,v2)) <<
"Wrong Property value at vertex 1";
432 EXPECT_TRUE(cmpMesh.property(prop,v3)) <<
"Wrong Property value at vertex 2";
434 EXPECT_FALSE(cmpMesh.property(prop2,v1)) <<
"Wrong second Property value at vertex 0";
435 EXPECT_FALSE(cmpMesh.property(prop2,v2)) <<
"Wrong second Property value at vertex 1";
436 EXPECT_FALSE(cmpMesh.property(prop2,v3)) <<
"Wrong second Property value at vertex 2";
439 remove(filename.c_str());
446 TEST_F(OpenMeshReadWriteOM, WriteTriangleEdgeIntProperty) {
450 const std::string propName =
"EIProp";
451 const std::string filename = std::string(
"triangle-minimal-")+propName+
".om";
457 mesh.add_face(v1,v2,v3);
460 mesh.add_property(prop,propName);
461 mesh.property(prop).set_persistent(
true);
463 Mesh::EdgeHandle e1 = Mesh::EdgeHandle(0);
464 Mesh::EdgeHandle e2 = Mesh::EdgeHandle(1);
465 Mesh::EdgeHandle e3 = Mesh::EdgeHandle(2);
471 mesh.property(prop,e1) = va1ue1;
472 mesh.property(prop,e2) = value2;
473 mesh.property(prop,e3) = value3;
477 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
482 cmpMesh.add_property(prop,propName);
483 cmpMesh.property(prop).set_persistent(
true);
486 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
489 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
490 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
491 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
493 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
494 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
495 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
497 EXPECT_EQ(va1ue1 , cmpMesh.property(prop,e1)) <<
"Wrong property at edge 0";
498 EXPECT_EQ(value2 , cmpMesh.property(prop,e2)) <<
"Wrong property at edge 1";
499 EXPECT_EQ(value3 , cmpMesh.property(prop,e3)) <<
"Wrong property at edge 2";
502 remove(filename.c_str());
509 TEST_F(OpenMeshReadWriteOM, WriteTriangleFaceDoubleProperty) {
513 const std::string propName =
"FDProp";
514 const std::string filename = std::string(
"triangle-minimal-")+propName+
".om";
520 mesh.add_face(v1,v2,v3);
523 mesh.add_property(prop,propName);
524 mesh.property(prop).set_persistent(
true);
526 Mesh::FaceHandle f1 = Mesh::FaceHandle(0);
530 mesh.property(prop,f1) = va1ue1;
534 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
539 cmpMesh.add_property(prop,propName);
540 cmpMesh.property(prop).set_persistent(
true);
543 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
546 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
547 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
548 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
550 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
551 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
552 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
554 EXPECT_EQ(va1ue1 , cmpMesh.property(prop,f1)) <<
"Wrong property at edge 0";
557 remove(filename.c_str());
564 TEST_F(OpenMeshReadWriteOM, WriteTriangleFaceFloatProperty) {
566 const std::string propName =
"FFProp";
567 const std::string filename = std::string(
"triangle-minimal-")+propName+
".om";
574 mesh.add_face(v1,v2,v3);
577 mesh.add_property(prop,propName);
578 mesh.property(prop).set_persistent(
true);
580 Mesh::FaceHandle f1 = Mesh::FaceHandle(0);
584 mesh.property(prop,f1) = va1ue1;
588 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
593 cmpMesh.add_property(prop,propName);
594 cmpMesh.property(prop).set_persistent(
true);
597 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
600 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
601 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
602 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
604 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
605 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
606 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
608 EXPECT_EQ(va1ue1 , cmpMesh.property(prop,f1)) <<
"Wrong property at edge 0";
611 remove(filename.c_str());
618 TEST_F(OpenMeshReadWriteOM, ReadBigMeshWithCustomProperty) {
648 mesh.add_property(faceProp,
"DFProp");
649 mesh.property(faceProp).set_persistent(
true);
651 mesh.add_property(vertexProp,
"IVProp");
652 mesh.property(vertexProp).set_persistent(
true);
655 EXPECT_TRUE(ok) <<
"Unable to read cube1_customProps.om";
658 EXPECT_EQ(7526u , mesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
659 EXPECT_EQ(22572u, mesh.n_edges()) <<
"The number of loaded edges is not correct!";
660 EXPECT_EQ(15048u, mesh.n_faces()) <<
"The number of loaded faces is not correct!";
663 for (Mesh::FaceIter fIter = mesh.faces_begin(); fIter != mesh.faces_end() && !wrong; ++fIter)
664 wrong = (0.3 != mesh.property(faceProp,*fIter));
665 EXPECT_FALSE(wrong) <<
"min one face has wrong face property";
668 for (Mesh::VertexIter vIter = mesh.vertices_begin(); vIter != mesh.vertices_end() && !wrong; ++vIter)
669 wrong = (vIter->idx() != mesh.property(vertexProp,*vIter));
670 EXPECT_FALSE(wrong) <<
"min one vertex has worng vertex property";
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Kernel::Color Color
Color type.
Kernel::Point Point
Coordinate type.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Has (r) / store (w) texture coordinates.
Set options for reader/writer modules.
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files) ...
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
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.