1#include <gtest/gtest.h>
2#include <Unittests/unittests_common.hh>
4#include <OpenMesh/Core/Utils/PropertyManager.hh>
5#include <OpenMesh/Core/Utils/PropertyCreator.hh>
17 return ival == _other.ival &&
18 dval == _other.dval &&
19 bval == _other.bval &&
20 vec4fval == _other.vec4fval;
43 return "RegisteredDataType";
45 static size_t store(std::ostream& _os,
const value_type& _v,
bool _swap=
false)
48 bytes = IO::store( _os, _v.ival, _swap );
49 bytes += IO::store( _os, _v.dval, _swap );
50 bytes += IO::store( _os, _v.bval, _swap );
51 bytes += IO::store( _os, _v.vec4fval, _swap );
52 return _os.good() ? bytes : 0;
57 bytes = IO::restore( _is, _v.ival, _swap );
58 bytes += IO::restore( _is, _v.dval, _swap );
59 bytes += IO::restore( _is, _v.bval, _swap );
60 bytes += IO::restore( _is, _v.vec4fval, _swap );
61 return _is.good() ? bytes : 0;
74 virtual void SetUp() {
80 virtual void TearDown() {
98TEST_F(OpenMeshReadWriteOM, LoadSimpleOMForceVertexColorsAlthoughNotAvailable) {
102 mesh_.request_vertex_colors();
104 std::string file_name =
"cube-minimal.om";
111 EXPECT_TRUE(ok) << file_name;
113 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
114 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
115 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
116 EXPECT_EQ(36u , mesh_.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
118 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
119 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
120 EXPECT_FALSE(options.vertex_has_color()) <<
"Wrong user options are returned!";
126TEST_F(OpenMeshReadWriteOM, LoadSimpleOMWithTexCoords) {
130 mesh_.request_vertex_texcoords2D();
137 ASSERT_TRUE(ok) <<
"Unable to load cube-minimal-texCoords.om";
139 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
140 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
141 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
143 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
144 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
146 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) <<
"Wrong vertex color at vertex 2 component 0";
147 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) <<
"Wrong vertex color at vertex 2 component 1";
149 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
150 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
152 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
153 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
156 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
157 EXPECT_TRUE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
158 EXPECT_FALSE(options.vertex_has_color()) <<
"Wrong user options are returned!";
160 mesh_.release_vertex_texcoords2D();
166TEST_F(OpenMeshReadWriteOM, LoadSimpleOMWithVertexColors) {
170 mesh_.request_vertex_colors();
177 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-vertexColors.om";
179 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
180 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
181 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
183#ifdef TEST_DOUBLE_TRAITS
184 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
185 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
186 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
188 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
189 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
190 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
192 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
193 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
194 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
196 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
197 EXPECT_FLOAT_EQ(0.0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
198 EXPECT_FLOAT_EQ(1.0, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
200 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
201 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
202 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
204 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
205 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
206 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
208 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
209 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
210 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
212 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
213 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
214 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
217 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
218 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
219 EXPECT_TRUE(options.vertex_has_color()) <<
"Wrong user options are returned!";
221 mesh_.release_vertex_colors();
227TEST_F(OpenMeshReadWriteOM, WriteTriangle) {
232 const std::string filename =
"triangle-minimal.om";
238 mesh.add_face(v1,v2,v3);
242 EXPECT_TRUE(ok) <<
"Unable to write " << filename;
249 EXPECT_TRUE(ok) <<
"Unable to read " << filename;
252 EXPECT_EQ(3u , mesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
253 EXPECT_EQ(3u , mesh.n_edges()) <<
"The number of loaded edges is not correct!";
254 EXPECT_EQ(1u , mesh.n_faces()) <<
"The number of loaded faces is not correct!";
256 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , mesh.point(v1)) <<
"Wrong coordinates at vertex 0";
257 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , mesh.point(v2)) <<
"Wrong coordinates at vertex 1";
258 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , mesh.point(v3)) <<
"Wrong coordinates at vertex 2";
261 remove(filename.c_str());
268TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexIntegerColor) {
272 mesh.request_vertex_colors();
278 const std::string filename =
"triangle-minimal-ColorsPerVertex.om";
284 mesh.add_face(v1,v2,v3);
286#ifdef TEST_DOUBLE_TRAITS
296 mesh.set_color(v1,c1);
297 mesh.set_color(v2,c2);
298 mesh.set_color(v3,c3);
302 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
304 mesh.release_vertex_colors();
308 cmpMesh.request_vertex_colors();
310 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
312 EXPECT_TRUE(cmpMesh.has_vertex_colors()) <<
"Loaded mesh has no vertex colors.";
315 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
316 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
317 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
319 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
320 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
321 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
323#ifdef TEST_DOUBLE_TRAITS
326 for (
size_t i = 0; i < c1.size(); ++i)
328 EXPECT_FLOAT_EQ(c1[i] , cmpMesh.color(v1)[i]) <<
"Wrong colors at coordinate " << i <<
" of vertex 0";
329 EXPECT_FLOAT_EQ(c2[i] , cmpMesh.color(v2)[i]) <<
"Wrong colors at coordinate " << i <<
" of vertex 1";
330 EXPECT_FLOAT_EQ(c3[i] , cmpMesh.color(v3)[i]) <<
"Wrong colors at coordinate " << i <<
" of vertex 2";
333 EXPECT_EQ(c1 , cmpMesh.color(v1)) <<
"Wrong colors at vertex 0";
334 EXPECT_EQ(c2 , cmpMesh.color(v2)) <<
"Wrong colors at vertex 1";
335 EXPECT_EQ(c3 , cmpMesh.color(v3)) <<
"Wrong colors at vertex 2";
339 cmpMesh.release_vertex_colors();
340 remove(filename.c_str());
347TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexBoolProperty) {
351 const std::string filename =
"triangle-minimal-VBProp.om";
357 mesh.add_face(v1,v2,v3);
360 mesh.add_property(prop,
"VBProp");
361 mesh.property(prop).set_persistent(
true);
363 mesh.property(prop,v1) =
true;
364 mesh.property(prop,v2) =
false;
365 mesh.property(prop,v3) =
true;
371 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
377 cmpMesh.add_property(prop,
"VBProp");
378 cmpMesh.property(prop).set_persistent(
true);
381 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
384 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
385 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
386 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
388 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
389 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
390 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
392 EXPECT_TRUE(cmpMesh.property(prop,v1)) <<
"Wrong Property value at vertex 0";
393 EXPECT_FALSE(cmpMesh.property(prop,v2)) <<
"Wrong Property value at vertex 1";
394 EXPECT_TRUE(cmpMesh.property(prop,v3)) <<
"Wrong Property value at vertex 2";
397 remove(filename.c_str());
404TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexBoolPropertySpaceEquivalent) {
408 const std::string filename =
"triangle-minimal-VBProp-pattern-test.om";
414 mesh.add_face(v1,v2,v3);
419 mesh.add_face(v4,v5,v6);
426 mesh.add_property(prop,
"VBProp");
427 mesh.property(prop).set_persistent(
true);
430 mesh.property(prop,v1) =
false;
431 mesh.property(prop,v2) =
false;
432 mesh.property(prop,v3) =
false;
433 mesh.property(prop,v4) =
false;
434 mesh.property(prop,v5) =
false;
435 mesh.property(prop,v6) =
true;
436 mesh.property(prop,v7) =
false;
437 mesh.property(prop,v8) =
false;
438 mesh.property(prop,v9) =
true;
444 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
449 cmpMesh.add_property(prop,
"VBProp");
450 cmpMesh.property(prop).set_persistent(
true);
453 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
456 EXPECT_EQ(9u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
457 EXPECT_EQ(6u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
458 EXPECT_EQ(2u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
460 EXPECT_FALSE(cmpMesh.property(prop,v1)) <<
"Wrong Property value at vertex 0";
461 EXPECT_FALSE(cmpMesh.property(prop,v2)) <<
"Wrong Property value at vertex 1";
462 EXPECT_FALSE(cmpMesh.property(prop,v3)) <<
"Wrong Property value at vertex 2";
463 EXPECT_FALSE(cmpMesh.property(prop,v4)) <<
"Wrong Property value at vertex 3";
464 EXPECT_FALSE(cmpMesh.property(prop,v5)) <<
"Wrong Property value at vertex 4";
465 EXPECT_TRUE(cmpMesh.property(prop,v6)) <<
"Wrong Property value at vertex 5";
466 EXPECT_FALSE(cmpMesh.property(prop,v7)) <<
"Wrong Property value at vertex 6";
467 EXPECT_FALSE(cmpMesh.property(prop,v8)) <<
"Wrong Property value at vertex 7";
468 EXPECT_TRUE(cmpMesh.property(prop,v9)) <<
"Wrong Property value at vertex 8";
471 remove(filename.c_str());
478TEST_F(OpenMeshReadWriteOM, WriteTriangleTwoVertexBoolProperty) {
482 const std::string filename =
"triangle-minimal-VBProp.om";
488 mesh.add_face(v1,v2,v3);
491 mesh.add_property(prop,
"VBProp");
492 mesh.property(prop).set_persistent(
true);
494 mesh.property(prop,v1) =
true;
495 mesh.property(prop,v2) =
false;
496 mesh.property(prop,v3) =
true;
499 mesh.add_property(prop2,
"VBProp2");
500 mesh.property(prop2).set_persistent(
true);
502 mesh.property(prop2,v1) =
false;
503 mesh.property(prop2,v2) =
false;
504 mesh.property(prop2,v3) =
false;
510 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
515 cmpMesh.add_property(prop,
"VBProp");
516 cmpMesh.property(prop).set_persistent(
true);
518 cmpMesh.add_property(prop2,
"VBProp2");
519 cmpMesh.property(prop2).set_persistent(
true);
522 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
525 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
526 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
527 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
529 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
530 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
531 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
533 EXPECT_TRUE(cmpMesh.property(prop,v1)) <<
"Wrong Property value at vertex 0";
534 EXPECT_FALSE(cmpMesh.property(prop,v2)) <<
"Wrong Property value at vertex 1";
535 EXPECT_TRUE(cmpMesh.property(prop,v3)) <<
"Wrong Property value at vertex 2";
537 EXPECT_FALSE(cmpMesh.property(prop2,v1)) <<
"Wrong second Property value at vertex 0";
538 EXPECT_FALSE(cmpMesh.property(prop2,v2)) <<
"Wrong second Property value at vertex 1";
539 EXPECT_FALSE(cmpMesh.property(prop2,v3)) <<
"Wrong second Property value at vertex 2";
542 remove(filename.c_str());
549TEST_F(OpenMeshReadWriteOM, WriteTriangleEdgeIntProperty) {
553 const std::string propName =
"EIProp";
554 const std::string filename = std::string(
"triangle-minimal-")+propName+
".om";
560 mesh.add_face(v1,v2,v3);
563 mesh.add_property(prop,propName);
564 mesh.property(prop).set_persistent(
true);
574 mesh.property(prop,e1) = value1;
575 mesh.property(prop,e2) = value2;
576 mesh.property(prop,e3) = value3;
582 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
587 cmpMesh.add_property(prop,propName);
588 cmpMesh.property(prop).set_persistent(
true);
591 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
594 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
595 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
596 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
598 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
599 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
600 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
602 EXPECT_EQ(value1 , cmpMesh.property(prop,e1)) <<
"Wrong property at edge 0";
603 EXPECT_EQ(value2 , cmpMesh.property(prop,e2)) <<
"Wrong property at edge 1";
604 EXPECT_EQ(value3 , cmpMesh.property(prop,e3)) <<
"Wrong property at edge 2";
607 remove(filename.c_str());
614TEST_F(OpenMeshReadWriteOM, WriteSplitTriangleEdgeIntProperty) {
618 const std::string propName =
"EIProp";
619 const std::string filename = std::string(
"triangle-minimal-")+propName+
".om";
625 auto fh0 = mesh.add_face(v1,v2,v3);
632 mesh.add_property(prop,propName);
633 mesh.property(prop).set_persistent(
true);
649 mesh.property(prop,e1) = value1;
650 mesh.property(prop,e2) = value2;
651 mesh.property(prop,e3) = value3;
652 mesh.property(prop,e4) = value4;
653 mesh.property(prop,e5) = value5;
654 mesh.property(prop,e6) = value6;
660 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
665 cmpMesh.add_property(prop,propName);
666 cmpMesh.property(prop).set_persistent(
true);
669 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
672 EXPECT_EQ(4u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
673 EXPECT_EQ(6u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
674 EXPECT_EQ(3u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
676 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
677 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
678 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
680#ifdef TEST_DOUBLE_TRAITS
682 EXPECT_FLOAT_EQ(c[0] , cmpMesh.point(v4)[0]) <<
"Wrong coordinate 0 at vertex 4";
683 EXPECT_FLOAT_EQ(c[1] , cmpMesh.point(v4)[1]) <<
"Wrong coordinate 1 at vertex 4";
684 EXPECT_FLOAT_EQ(c[2] , cmpMesh.point(v4)[2]) <<
"Wrong coordinate 2 at vertex 4";
686 EXPECT_EQ(c , cmpMesh.point(v4)) <<
"Wrong coordinates at vertex 4";
689 EXPECT_EQ(value1 , cmpMesh.property(prop,e1)) <<
"Wrong property at edge 0";
690 EXPECT_EQ(value2 , cmpMesh.property(prop,e2)) <<
"Wrong property at edge 1";
691 EXPECT_EQ(value3 , cmpMesh.property(prop,e3)) <<
"Wrong property at edge 2";
692 EXPECT_EQ(value4 , cmpMesh.property(prop,e4)) <<
"Wrong property at edge 3";
693 EXPECT_EQ(value5 , cmpMesh.property(prop,e5)) <<
"Wrong property at edge 4";
694 EXPECT_EQ(value6 , cmpMesh.property(prop,e6)) <<
"Wrong property at edge 5";
698 for (
auto eh : mesh.edges())
700 auto heh = mesh.halfedge_handle(eh, 0);
701 auto from_vh = mesh.from_vertex_handle(heh);
702 auto to_vh = mesh.to_vertex_handle(heh);
705 auto cmpHeh = cmpMesh.find_halfedge(from_vh, to_vh);
706 auto cmpEh = cmpMesh.edge_handle(cmpHeh);
708 EXPECT_EQ(mesh.property(prop, eh), cmpMesh.property(prop, cmpEh)) <<
"Wrong property at input edge " << eh.idx()
709 <<
" corresponding to edge " << cmpEh.idx() <<
" in the loaded Mesh";
715 remove(filename.c_str());
722TEST_F(OpenMeshReadWriteOM, WriteSplitTriangleStatusProperties) {
726 mesh.request_vertex_status();
727 mesh.request_edge_status();
728 mesh.request_halfedge_status();
729 mesh.request_face_status();
731 const std::string filename = std::string(
"triangle-minimal-status.om");
737 auto fh0 = mesh.add_face(v0,v1,v2);
742 mesh.delete_vertex(v0);
743 mesh.status(v1).set_selected(
true);
744 mesh.status(v2).set_feature(
true);
745 mesh.status(v3).set_tagged(
true);
746 mesh.status(v2).set_tagged2(
true);
748 std::vector<bool> vertex_deleted;
749 std::vector<bool> vertex_selected;
750 std::vector<bool> vertex_feature;
751 std::vector<bool> vertex_tagged;
752 std::vector<bool> vertex_tagged2;
754 for (
auto vh : mesh.all_vertices())
756 vertex_deleted.push_back(mesh.status(vh).deleted());
757 vertex_selected.push_back(mesh.status(vh).selected());
758 vertex_feature.push_back(mesh.status(vh).feature());
759 vertex_tagged.push_back(mesh.status(vh).tagged());
760 vertex_tagged2.push_back(mesh.status(vh).tagged2());
768 mesh.status(e1).set_selected(
true);
769 mesh.status(e2).set_feature(
true);
770 mesh.status(e3).set_tagged(
true);
771 mesh.status(e4).set_tagged2(
true);
773 std::vector<bool> edge_deleted;
774 std::vector<bool> edge_selected;
775 std::vector<bool> edge_feature;
776 std::vector<bool> edge_tagged;
777 std::vector<bool> edge_tagged2;
779 for (
auto eh : mesh.all_edges())
781 edge_deleted.push_back(mesh.status(eh).deleted());
782 edge_selected.push_back(mesh.status(eh).selected());
783 edge_feature.push_back(mesh.status(eh).feature());
784 edge_tagged.push_back(mesh.status(eh).tagged());
785 edge_tagged2.push_back(mesh.status(eh).tagged2());
794 mesh.status(he1).set_selected(
true);
795 mesh.status(he2).set_feature(
true);
796 mesh.status(he3).set_tagged(
true);
797 mesh.status(he4).set_tagged2(
true);
799 std::vector<bool> halfedge_deleted;
800 std::vector<bool> halfedge_selected;
801 std::vector<bool> halfedge_feature;
802 std::vector<bool> halfedge_tagged;
803 std::vector<bool> halfedge_tagged2;
805 for (
auto heh : mesh.all_halfedges())
807 halfedge_deleted.push_back(mesh.status(heh).deleted());
808 halfedge_selected.push_back(mesh.status(heh).selected());
809 halfedge_feature.push_back(mesh.status(heh).feature());
810 halfedge_tagged.push_back(mesh.status(heh).tagged());
811 halfedge_tagged2.push_back(mesh.status(heh).tagged2());
819 mesh.status(f1).set_selected(
true);
820 mesh.status(f2).set_feature(
true);
821 mesh.status(f3).set_tagged(
true);
822 mesh.status(f4).set_tagged2(
true);
824 std::vector<bool> face_deleted;
825 std::vector<bool> face_selected;
826 std::vector<bool> face_feature;
827 std::vector<bool> face_tagged;
828 std::vector<bool> face_tagged2;
830 for (
auto fh : mesh.all_faces())
832 face_deleted.push_back(mesh.status(fh).deleted());
833 face_selected.push_back(mesh.status(fh).selected());
834 face_feature.push_back(mesh.status(fh).feature());
835 face_tagged.push_back(mesh.status(fh).tagged());
836 face_tagged2.push_back(mesh.status(fh).tagged2());
842 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
847 cmpMesh.request_vertex_status();
848 cmpMesh.request_edge_status();
849 cmpMesh.request_halfedge_status();
850 cmpMesh.request_face_status();
853 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
856 EXPECT_EQ(4u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
857 EXPECT_EQ(6u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
858 EXPECT_EQ(3u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
860 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v0)) <<
"Wrong coordinates at vertex 0";
861 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 1";
862 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 2";
864#ifdef TEST_DOUBLE_TRAITS
866 EXPECT_FLOAT_EQ(c[0] , cmpMesh.point(v3)[0]) <<
"Wrong coordinate 0 at vertex 3";
867 EXPECT_FLOAT_EQ(c[1] , cmpMesh.point(v3)[1]) <<
"Wrong coordinate 1 at vertex 3";
868 EXPECT_FLOAT_EQ(c[2] , cmpMesh.point(v3)[2]) <<
"Wrong coordinate 2 at vertex 3";
870 EXPECT_EQ(c , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 3";
873 for (
auto vh : cmpMesh.all_vertices())
875 EXPECT_EQ(cmpMesh.status(vh).deleted(), vertex_deleted [vh.idx()]) <<
"Wrong deleted status at vertex " << vh.idx();
876 EXPECT_EQ(cmpMesh.status(vh).selected(), vertex_selected[vh.idx()]) <<
"Wrong selected status at vertex " << vh.idx();
877 EXPECT_EQ(cmpMesh.status(vh).feature(), vertex_feature [vh.idx()]) <<
"Wrong feature status at vertex " << vh.idx();
878 EXPECT_EQ(cmpMesh.status(vh).tagged(), vertex_tagged [vh.idx()]) <<
"Wrong tagged status at vertex " << vh.idx();
879 EXPECT_EQ(cmpMesh.status(vh).tagged2(), vertex_tagged2 [vh.idx()]) <<
"Wrong tagged2 status at vertex " << vh.idx();
882 for (
auto eh : cmpMesh.all_edges())
884 EXPECT_EQ(cmpMesh.status(eh).deleted(), edge_deleted [eh.idx()]) <<
"Wrong deleted status at edge " << eh.idx();
885 EXPECT_EQ(cmpMesh.status(eh).selected(), edge_selected[eh.idx()]) <<
"Wrong selected status at edge " << eh.idx();
886 EXPECT_EQ(cmpMesh.status(eh).feature(), edge_feature [eh.idx()]) <<
"Wrong feature status at edge " << eh.idx();
887 EXPECT_EQ(cmpMesh.status(eh).tagged(), edge_tagged [eh.idx()]) <<
"Wrong tagged status at edge " << eh.idx();
888 EXPECT_EQ(cmpMesh.status(eh).tagged2(), edge_tagged2 [eh.idx()]) <<
"Wrong tagged2 status at edge " << eh.idx();
891 for (
auto heh : cmpMesh.all_halfedges())
893 EXPECT_EQ(cmpMesh.status(heh).deleted(), halfedge_deleted [heh.idx()]) <<
"Wrong deleted status at halfedge " << heh.idx();
894 EXPECT_EQ(cmpMesh.status(heh).selected(), halfedge_selected[heh.idx()]) <<
"Wrong selected status at halfedge " << heh.idx();
895 EXPECT_EQ(cmpMesh.status(heh).feature(), halfedge_feature [heh.idx()]) <<
"Wrong feature status at halfedge " << heh.idx();
896 EXPECT_EQ(cmpMesh.status(heh).tagged(), halfedge_tagged [heh.idx()]) <<
"Wrong tagged status at halfedge " << heh.idx();
897 EXPECT_EQ(cmpMesh.status(heh).tagged2(), halfedge_tagged2 [heh.idx()]) <<
"Wrong tagged2 status at halfedge " << heh.idx();
900 for (
auto fh : cmpMesh.all_faces())
902 EXPECT_EQ(cmpMesh.status(fh).deleted(), face_deleted [fh.idx()]) <<
"Wrong deleted status at face " << fh.idx();
903 EXPECT_EQ(cmpMesh.status(fh).selected(), face_selected[fh.idx()]) <<
"Wrong selected status at face " << fh.idx();
904 EXPECT_EQ(cmpMesh.status(fh).feature(), face_feature [fh.idx()]) <<
"Wrong feature status at face " << fh.idx();
905 EXPECT_EQ(cmpMesh.status(fh).tagged(), face_tagged [fh.idx()]) <<
"Wrong tagged status at face " << fh.idx();
906 EXPECT_EQ(cmpMesh.status(fh).tagged2(), face_tagged2 [fh.idx()]) <<
"Wrong tagged2 status at face " << fh.idx();
911 remove(filename.c_str());
917TEST_F(OpenMeshReadWriteOM, WriteTriangleFaceDoubleProperty) {
921 const std::string propName =
"FDProp";
922 const std::string filename = std::string(
"triangle-minimal-")+propName+
".om";
928 mesh.add_face(v1,v2,v3);
931 mesh.add_property(prop,propName);
932 mesh.property(prop).set_persistent(
true);
938 mesh.property(prop,f1) = va1ue1;
944 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
949 cmpMesh.add_property(prop,propName);
950 cmpMesh.property(prop).set_persistent(
true);
953 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
956 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
957 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
958 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
960 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
961 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
962 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
964 EXPECT_EQ(va1ue1 , cmpMesh.property(prop,f1)) <<
"Wrong property at edge 0";
967 remove(filename.c_str());
974TEST_F(OpenMeshReadWriteOM, WriteTriangleFaceFloatProperty) {
976 const std::string propName =
"FFProp";
977 const std::string filename = std::string(
"triangle-minimal-")+propName+
".om";
984 mesh.add_face(v1,v2,v3);
987 mesh.add_property(prop,propName);
988 mesh.property(prop).set_persistent(
true);
994 mesh.property(prop,f1) = va1ue1;
1000 EXPECT_TRUE(ok) <<
"Unable to write "<<filename;
1005 cmpMesh.add_property(prop,propName);
1006 cmpMesh.property(prop).set_persistent(
true);
1009 EXPECT_TRUE(ok) <<
"Unable to read "<<filename;
1012 EXPECT_EQ(3u , cmpMesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
1013 EXPECT_EQ(3u , cmpMesh.n_edges()) <<
"The number of loaded edges is not correct!";
1014 EXPECT_EQ(1u , cmpMesh.n_faces()) <<
"The number of loaded faces is not correct!";
1016 EXPECT_EQ(
Mesh::Point(1.0,0.0,0.0) , cmpMesh.point(v1)) <<
"Wrong coordinates at vertex 0";
1017 EXPECT_EQ(
Mesh::Point(0.0,1.0,0.0) , cmpMesh.point(v2)) <<
"Wrong coordinates at vertex 1";
1018 EXPECT_EQ(
Mesh::Point(0.0,0.0,1.0) , cmpMesh.point(v3)) <<
"Wrong coordinates at vertex 2";
1020 EXPECT_EQ(va1ue1 , cmpMesh.property(prop,f1)) <<
"Wrong property at edge 0";
1023 remove(filename.c_str());
1030TEST_F(OpenMeshReadWriteOM, ReadBigMeshWithCustomProperty) {
1060 mesh.add_property(faceProp,
"DFProp");
1061 mesh.property(faceProp).set_persistent(
true);
1063 mesh.add_property(vertexProp,
"IVProp");
1064 mesh.property(vertexProp).set_persistent(
true);
1068 EXPECT_TRUE(ok) <<
"Unable to read cube1_customProps.om";
1071 EXPECT_EQ(7526u , mesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
1072 EXPECT_EQ(22572u, mesh.n_edges()) <<
"The number of loaded edges is not correct!";
1073 EXPECT_EQ(15048u, mesh.n_faces()) <<
"The number of loaded faces is not correct!";
1076 for (
Mesh::FaceIter fIter = mesh.faces_begin(); fIter != mesh.faces_end() && !wrong; ++fIter)
1077 wrong = (0.3 != mesh.property(faceProp,*fIter));
1078 EXPECT_FALSE(wrong) <<
"min one face has wrong face property";
1081 for (
Mesh::VertexIter vIter = mesh.vertices_begin(); vIter != mesh.vertices_end() && !wrong; ++vIter)
1082 wrong = (vIter->idx() != mesh.property(vertexProp,*vIter));
1083 EXPECT_FALSE(wrong) <<
"min one vertex has wrong vertex property";
1090TEST_F(OpenMeshReadWriteOM, WriteReadStatusPropertyVertexOnly) {
1097 mesh.add_face(vh0, vh1, vh2);
1099 mesh.request_vertex_status();
1101 mesh.status(vh0).set_selected(
true);
1102 mesh.status(vh1).set_feature(
true);
1103 mesh.status(vh2).set_tagged(
true);
1104 mesh.status(vh0).set_locked(
true);
1105 mesh.status(vh1).set_deleted(
true);
1106 mesh.status(vh2).set_hidden(
true);
1107 mesh.status(vh0).set_fixed_nonmanifold(
true);
1110 std::string filename_without_status =
"no_vertex_status_test.om";
1111 std::string filename_with_status =
"vertex_status_test.om";
1122 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though they should not have been loaded";
1123 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1124 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though file should not have a stored status";
1125 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1133 EXPECT_TRUE (loaded_mesh.has_vertex_status()) <<
"Mesh has no vertex status even though they should have been loaded";
1134 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1135 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though file should not have a stored status";
1136 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1138 if (loaded_mesh.has_vertex_status())
1140 for (
auto vh : mesh.vertices())
1142 EXPECT_EQ(mesh.status(vh).bits(), loaded_mesh.status(vh).bits());
1150 loaded_mesh.request_vertex_status();
1153 EXPECT_TRUE (loaded_mesh.has_vertex_status()) <<
"Mesh vertex status was removed by reading";
1154 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1155 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though file should not have a stored status";
1156 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1158 for (
auto vh : loaded_mesh.vertices())
1160 EXPECT_EQ(loaded_mesh.status(vh).bits(), 0u) <<
"Vertex status was modified even though it should not have been loaded";
1169 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though file should not have a stored status";
1170 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1171 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though they file should not have a stored status";
1172 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though they file should not have a stored status";
1180TEST_F(OpenMeshReadWriteOM, WriteReadStatusPropertyHalfedgeOnly) {
1187 mesh.add_face(vh0, vh1, vh2);
1189 mesh.request_halfedge_status();
1198 mesh.status(heh0).set_selected(
true);
1199 mesh.status(heh1).set_feature(
true);
1200 mesh.status(heh2).set_tagged(
true);
1201 mesh.status(heh3).set_locked(
true);
1202 mesh.status(heh4).set_deleted(
true);
1203 mesh.status(heh5).set_hidden(
true);
1204 mesh.status(heh0).set_fixed_nonmanifold(
true);
1206 std::string filename_without_status =
"no_halfedge_status_test.om";
1207 std::string filename_with_status =
"edge_halfstatus_test.om";
1218 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though they should not have been loaded";
1219 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1220 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though file should not have a stored status";
1221 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1229 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though they should have been loaded";
1230 EXPECT_TRUE(loaded_mesh.has_halfedge_status()) <<
"Mesh has no halfedge status even though file should not have a stored status";
1231 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though file should not have a stored status";
1232 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1234 if (loaded_mesh.has_halfedge_status())
1236 for (
auto heh : mesh.halfedges())
1238 EXPECT_EQ(mesh.status(heh).bits(), loaded_mesh.status(heh).bits());
1246 loaded_mesh.request_halfedge_status();
1249 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though file should not have a stored status";
1250 EXPECT_TRUE (loaded_mesh.has_halfedge_status()) <<
"Mesh halfedge status was removed by reading";
1251 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though file should not have a stored status";
1252 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1254 for (
auto heh : loaded_mesh.halfedges())
1256 EXPECT_EQ(loaded_mesh.status(heh).bits(), 0u) <<
"Edge status was modified even though it should not have been loaded";
1265 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though file should not have a stored status";
1266 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1267 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though they file should not have a stored status";
1268 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though they file should not have a stored status";
1276TEST_F(OpenMeshReadWriteOM, WriteReadStatusPropertyEdgeOnly) {
1283 mesh.add_face(vh0, vh1, vh2);
1285 mesh.request_edge_status();
1291 mesh.status(eh0).set_selected(
true);
1292 mesh.status(eh1).set_feature(
true);
1293 mesh.status(eh2).set_tagged(
true);
1294 mesh.status(eh0).set_locked(
true);
1295 mesh.status(eh1).set_deleted(
true);
1296 mesh.status(eh2).set_hidden(
true);
1297 mesh.status(eh0).set_fixed_nonmanifold(
true);
1299 std::string filename_without_status =
"no_edge_status_test.om";
1300 std::string filename_with_status =
"edge_status_test.om";
1311 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though they should not have been loaded";
1312 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1313 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though file should not have a stored status";
1314 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1322 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though they should have been loaded";
1323 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1324 EXPECT_TRUE(loaded_mesh.has_edge_status()) <<
"Mesh has no edge status even though file should not have a stored status";
1325 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1327 if (loaded_mesh.has_edge_status())
1329 for (
auto eh : mesh.edges())
1331 EXPECT_EQ(mesh.status(eh).bits(), loaded_mesh.status(eh).bits());
1339 loaded_mesh.request_edge_status();
1342 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though file should not have a stored status";
1343 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1344 EXPECT_TRUE (loaded_mesh.has_edge_status()) <<
"Mesh edge status was removed by reading";
1345 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1347 for (
auto eh : loaded_mesh.edges())
1349 EXPECT_EQ(loaded_mesh.status(eh).bits(), 0u) <<
"Edge status was modified even though it should not have been loaded";
1358 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though file should not have a stored status";
1359 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1360 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though they file should not have a stored status";
1361 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though they file should not have a stored status";
1369TEST_F(OpenMeshReadWriteOM, WriteReadStatusPropertyFaceOnly) {
1377 auto fh0 = mesh.add_face(vh0, vh1, vh2);
1378 auto fh1 = mesh.add_face(vh2, vh1, vh3);
1380 mesh.request_face_status();
1382 mesh.status(fh0).set_selected(
true);
1383 mesh.status(fh1).set_feature(
true);
1384 mesh.status(fh0).set_tagged(
true);
1385 mesh.status(fh1).set_locked(
true);
1386 mesh.status(fh0).set_deleted(
true);
1387 mesh.status(fh1).set_hidden(
true);
1388 mesh.status(fh0).set_fixed_nonmanifold(
true);
1390 std::string filename_without_status =
"no_face_status_test.om";
1391 std::string filename_with_status =
"face_status_test.om";
1402 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though they should not have been loaded";
1403 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1404 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though file should not have a stored status";
1405 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though file should not have a stored status";
1413 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though they should have been loaded";
1414 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1415 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though file should not have a stored status";
1416 EXPECT_TRUE(loaded_mesh.has_face_status()) <<
"Mesh has no face status even though file should not have a stored status";
1418 if (loaded_mesh.has_face_status())
1420 for (
auto fh : mesh.faces())
1422 EXPECT_EQ(mesh.status(fh).bits(), loaded_mesh.status(fh).bits());
1430 loaded_mesh.request_face_status();
1433 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though file should not have a stored status";
1434 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1435 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edgestatus even though file should not have a stored status";
1436 EXPECT_TRUE (loaded_mesh.has_face_status()) <<
"Mesh face status was removed by reading";
1438 for (
auto fh : loaded_mesh.faces())
1440 EXPECT_EQ(loaded_mesh.status(fh).bits(), 0u) <<
"Edge status was modified even though it should not have been loaded";
1449 EXPECT_FALSE(loaded_mesh.has_vertex_status()) <<
"Mesh has vertex status even though file should not have a stored status";
1450 EXPECT_FALSE(loaded_mesh.has_halfedge_status()) <<
"Mesh has halfedge status even though file should not have a stored status";
1451 EXPECT_FALSE(loaded_mesh.has_edge_status()) <<
"Mesh has edge status even though they file should not have a stored status";
1452 EXPECT_FALSE(loaded_mesh.has_face_status()) <<
"Mesh has face status even though they file should not have a stored status";
1460TEST_F(OpenMeshReadWriteOM, LoadTriangleMeshVersion_1_2) {
1464 std::string file_name =
"cube_tri_version_1_2.om";
1468 EXPECT_TRUE(ok) << file_name;
1470 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
1471 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
1472 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
1473 EXPECT_EQ(36u , mesh_.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
1480TEST_F(OpenMeshReadWriteOM, LoadPolyMeshVersion_1_2) {
1484 std::string file_name =
"cube_poly_version_1_2.om";
1488 EXPECT_TRUE(ok) << file_name;
1490 EXPECT_EQ(8u , mesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
1491 EXPECT_EQ(12u , mesh.n_edges()) <<
"The number of loaded edges is not correct!";
1492 EXPECT_EQ(6u , mesh.n_faces()) <<
"The number of loaded faces is not correct!";
1493 EXPECT_EQ(24u , mesh.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
1500TEST_F(OpenMeshReadWriteOM, LoadTriangleMeshVersion_2_0) {
1504 std::string file_name =
"cube_tri_version_2_0.om";
1508 EXPECT_TRUE(ok) << file_name;
1510 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
1511 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
1512 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
1513 EXPECT_EQ(36u , mesh_.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
1520TEST_F(OpenMeshReadWriteOM, LoadPolyMeshVersion_2_0) {
1524 std::string file_name =
"cube_poly_version_2_0.om";
1528 EXPECT_TRUE(ok) << file_name;
1530 EXPECT_EQ(8u , mesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
1531 EXPECT_EQ(12u , mesh.n_edges()) <<
"The number of loaded edges is not correct!";
1532 EXPECT_EQ(6u , mesh.n_faces()) <<
"The number of loaded faces is not correct!";
1533 EXPECT_EQ(24u , mesh.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
1543std::string get_type_string(
char) {
return "char"; }
1544std::string get_type_string(
signed char) {
return "signed char"; }
1545std::string get_type_string(
double) {
return "double"; }
1546std::string get_type_string(
float) {
return "float"; }
1547std::string get_type_string(
int) {
return "int"; }
1548std::string get_type_string(
short) {
return "short"; }
1549std::string get_type_string(
unsigned char) {
return "unsigned char"; }
1550std::string get_type_string(
unsigned int) {
return "unsigned int"; }
1551std::string get_type_string(
unsigned short) {
return "unsigned short"; }
1552std::string get_type_string(
bool) {
return "bool"; }
1553std::string get_type_string(std::string) {
return "string"; }
1556template <
typename T>
1557std::string get_type_string(std::vector<T>) {
return "std::vector of " + get_type_string(T()); }
1559template <
typename T,
int Dim>
1560std::string get_type_string(
OpenMesh::VectorT<T, Dim>) {
return "OM vector of dimension " + std::to_string(Dim) +
" of type " + get_type_string(T()); }
1562template <
typename T>
1563T get_value(
int seed, T,
int seed2 = 0)
1565 return (seed * 3 + seed2) % 20;
1568std::string get_value(
int seed, std::string,
int seed2 = 0)
1570 return std::to_string((seed * 3 + seed2) % 20);
1573template <
typename T>
1574std::vector<T> get_value(
int seed,
const std::vector<T>&,
int _offset = 0)
1576 int size = get_value(seed, 3);
1577 std::vector<T> res(size);
1578 for (
int i = 0; i < size; ++i)
1579 res[i] = get_value(seed, T(), i + _offset);
1583template <
typename T,
int Dim>
1587 for (
int i = 0; i < Dim; ++i)
1588 res[i] = get_value(seed, T(), i);
1592template <
typename MeshT,
typename HandleT,
typename T>
1595 std::string name = get_type_string(HandleT()) +
": " + get_type_string(T());
1597 _mesh.property(prop.getRawProperty()).set_persistent(
true);
1598 for (
auto e : _mesh.template elements<HandleT>())
1599 prop[e] = get_value(e.idx(), T());
1604template <
typename MeshT,
typename HandleT,
typename T>
1605void check_property(
MeshT& _mesh)
1607 std::string name = get_type_string(HandleT()) +
": " + get_type_string(T());
1608 bool has_prop = OpenMesh::hasProperty<HandleT, T>(_mesh, name.c_str());
1609 EXPECT_TRUE(has_prop) <<
"Property " << name <<
" is not available";
1613 for (
auto e : _mesh.template elements<HandleT>())
1614 EXPECT_EQ(prop[e], get_value(e.idx(), T())) <<
"For property " << name;
1617template <
typename MeshT,
typename HandleT,
typename T>
1618void request_property(
MeshT& _mesh)
1620 std::string name = get_type_string(HandleT()) +
": " + get_type_string(T());
1625enum class PropertyAction
1631template <
typename MeshT,
typename HandleT,
typename T>
1632void do_property(
MeshT& _mesh, PropertyAction action)
1636 case PropertyAction::Add:
1637 add_property<MeshT, HandleT, T>(_mesh);
1639 case PropertyAction::Check:
1640 check_property<MeshT, HandleT, T>(_mesh);
1642 case PropertyAction::Request:
1643 request_property<MeshT, HandleT, T>(_mesh);
1649template <
typename MeshT,
typename HandleT,
int Dim>
1650void do_all_property_types_vec(
MeshT& _mesh, PropertyAction action)
1652 do_property<MeshT, HandleT, OpenMesh::VectorT<signed char , Dim>>(_mesh, action);
1653 do_property<MeshT, HandleT, OpenMesh::VectorT<double , Dim>>(_mesh, action);
1654 do_property<MeshT, HandleT, OpenMesh::VectorT<float , Dim>>(_mesh, action);
1655 do_property<MeshT, HandleT, OpenMesh::VectorT<int , Dim>>(_mesh, action);
1656 do_property<MeshT, HandleT, OpenMesh::VectorT<short , Dim>>(_mesh, action);
1657 do_property<MeshT, HandleT, OpenMesh::VectorT<unsigned char , Dim>>(_mesh, action);
1658 do_property<MeshT, HandleT, OpenMesh::VectorT<unsigned int , Dim>>(_mesh, action);
1659 do_property<MeshT, HandleT, OpenMesh::VectorT<unsigned short, Dim>>(_mesh, action);
1663template <
typename MeshT,
typename HandleT>
1664void do_all_property_types_vec_all_dim(
MeshT& _mesh, PropertyAction action)
1666 do_all_property_types_vec<MeshT, HandleT, 1>(_mesh, action);
1667 do_all_property_types_vec<MeshT, HandleT, 2>(_mesh, action);
1668 do_all_property_types_vec<MeshT, HandleT, 3>(_mesh, action);
1669 do_all_property_types_vec<MeshT, HandleT, 4>(_mesh, action);
1673template <
typename MeshT,
typename HandleT>
1674void do_all_property_types(
MeshT& _mesh, PropertyAction action,
int version)
1676 do_property<MeshT, HandleT, int> (_mesh, action);
1677 do_property<MeshT, HandleT, double> (_mesh, action);
1678 do_property<MeshT, HandleT, float> (_mesh, action);
1679 do_property<MeshT, HandleT, char> (_mesh, action);
1680 do_property<MeshT, HandleT, bool> (_mesh, action);
1681 do_property<MeshT, HandleT, std::string> (_mesh, action);
1682 do_property<MeshT, HandleT, RegisteredDataType> (_mesh, action);
1686 do_property<MeshT, HandleT, std::vector<int>> (_mesh, action);
1687 do_property<MeshT, HandleT, std::vector<double>> (_mesh, action);
1688 do_property<MeshT, HandleT, std::vector<float>> (_mesh, action);
1689 do_property<MeshT, HandleT, std::vector<char>> (_mesh, action);
1690 do_property<MeshT, HandleT, std::vector<bool>> (_mesh, action);
1691 do_property<MeshT, HandleT, std::vector<std::string>> (_mesh, action);
1692 do_property<MeshT, HandleT, std::vector<RegisteredDataType>> (_mesh, action);
1694 do_property<MeshT, HandleT, std::vector<std::vector<int>>> (_mesh, action);
1695 do_property<MeshT, HandleT, std::vector<std::vector<double>>> (_mesh, action);
1696 do_property<MeshT, HandleT, std::vector<std::vector<float>>> (_mesh, action);
1697 do_property<MeshT, HandleT, std::vector<std::vector<char>>> (_mesh, action);
1698 do_property<MeshT, HandleT, std::vector<std::vector<bool>>> (_mesh, action);
1699 do_property<MeshT, HandleT, std::vector<std::vector<std::string>>> (_mesh, action);
1700 do_property<MeshT, HandleT, std::vector<std::vector<RegisteredDataType>>> (_mesh, action);
1702 do_property<MeshT, HandleT, std::vector<std::vector<std::vector<int>>>> (_mesh, action);
1703 do_property<MeshT, HandleT, std::vector<std::vector<std::vector<double>>>> (_mesh, action);
1704 do_property<MeshT, HandleT, std::vector<std::vector<std::vector<float>>>> (_mesh, action);
1705 do_property<MeshT, HandleT, std::vector<std::vector<std::vector<char>>>> (_mesh, action);
1706 do_property<MeshT, HandleT, std::vector<std::vector<std::vector<bool>>>> (_mesh, action);
1707 do_property<MeshT, HandleT, std::vector<std::vector<std::vector<std::string>>>> (_mesh, action);
1708 do_property<MeshT, HandleT, std::vector<std::vector<std::vector<RegisteredDataType>>>> (_mesh, action);
1711 do_all_property_types_vec_all_dim<MeshT, HandleT>(_mesh, action);
1715template <
typename MeshT>
1716void do_all_properties(
MeshT& _mesh, PropertyAction action,
int version)
1718 do_all_property_types<MeshT,OpenMesh::FaceHandle> (_mesh, action, version);
1719 do_all_property_types<MeshT,OpenMesh::EdgeHandle> (_mesh, action, version);
1720 do_all_property_types<MeshT,OpenMesh::HalfedgeHandle>(_mesh, action, version);
1721 do_all_property_types<MeshT,OpenMesh::VertexHandle> (_mesh, action, version);
1724template <
typename MeshT>
void add_all_properties(
MeshT& _mesh,
int version) { do_all_properties(_mesh, PropertyAction::Add , version); }
1725template <
typename MeshT>
void check_all_properties(
MeshT& _mesh,
int version) { do_all_properties(_mesh, PropertyAction::Check , version); }
1726template <
typename MeshT>
void request_all_properties(
MeshT& _mesh,
int version) { do_all_properties(_mesh, PropertyAction::Request, version); }
1731TEST_F(OpenMeshReadWriteOM, LoadTriangleMeshWithPropertiesVersion_2_1) {
1736 std::string file_name =
"cube_tri_with_properties_2_1.om";
1738 request_all_properties(mesh_, version);
1741 ASSERT_TRUE(ok) << file_name;
1743 ASSERT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
1744 ASSERT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
1745 ASSERT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
1746 ASSERT_EQ(36u , mesh_.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
1748 check_all_properties(mesh_, version);
1754TEST_F(OpenMeshReadWriteOM, LoadTriangleMeshWithPropertiesCurrentVersion) {
1762 std::string file_name =
"cube_tri_version_2_0.om";
1766 ASSERT_TRUE(ok) << file_name;
1767 ASSERT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
1768 ASSERT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
1769 ASSERT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
1770 ASSERT_EQ(36u , mesh_.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
1772 add_all_properties(mesh_, version);
1773 mesh_.request_halfedge_texcoords2D();
1775 std::string file_name_2_2 =
"cube_tri_with_properties_2_2.om";
1784 check_all_properties(new_mesh, version);
1785 EXPECT_TRUE(new_mesh.has_halfedge_texcoords2D());
1791TEST_F(OpenMeshReadWriteOM, LoadTriMeshVersion_7_5) {
1795 std::string file_name =
"cube_tri_version_7_5.om";
1799 EXPECT_FALSE(ok) << file_name;
1806TEST_F(OpenMeshReadWriteOM, WriteAndLoadDoubles) {
1810 DoublePolyMesh mesh;
1811 mesh.request_vertex_normals();
1812 mesh.request_face_normals();
1814 std::vector<OpenMesh::VertexHandle> vertices;
1815 for (
int i = 0; i < 3; ++i)
1817 vertices.push_back(mesh.
add_vertex(DoublePolyMesh::Point(1.0/3.0, std::numeric_limits<double>::min(), std::numeric_limits<double>::max())));
1818 mesh.set_normal(vertices.back(), DoublePolyMesh::Normal(1.0/3.0, std::numeric_limits<double>::min(), std::numeric_limits<double>::max()));
1820 auto fh = mesh.add_face(vertices);
1821 mesh.set_normal(fh, DoublePolyMesh::Normal(1.0/3.0, std::numeric_limits<double>::min(), std::numeric_limits<double>::max()));
1823 std::string file_name =
"doubles.om";
1828 DoublePolyMesh mesh2;
1829 mesh2.request_vertex_normals();
1830 mesh2.request_face_normals();
1842TEST_F(OpenMeshReadWriteOM, PropertyFromString)
1845 std::string int_prop_name =
"my int prop";
1846 OpenMesh::create_property_from_string<OpenMesh::VertexHandle>(mesh_,
"int32_t", int_prop_name);
1847 bool has_int_prop = OpenMesh::hasProperty<OpenMesh::VertexHandle, int>(mesh_, int_prop_name.c_str());
1848 EXPECT_TRUE(has_int_prop);
1852 std::string double_prop_name =
"my double prop";
1853 OpenMesh::create_property_from_string<OpenMesh::VertexHandle>(mesh_,
"double", double_prop_name);
1854 bool has_double_prop = OpenMesh::hasProperty<OpenMesh::VertexHandle, double>(mesh_, double_prop_name.c_str());
1855 EXPECT_TRUE(has_double_prop);
1859 std::string vec_float_prop_name =
"my vector of floats prop";
1860 OpenMesh::create_property_from_string<OpenMesh::VertexHandle>(mesh_,
"std::vector<float>", vec_float_prop_name);
1861 bool has_vec_float_prop = OpenMesh::hasProperty<OpenMesh::VertexHandle, std::vector<float>>(mesh_, vec_float_prop_name.c_str());
1862 EXPECT_TRUE(has_vec_float_prop);
1866 std::string MyData_prop_name =
"my MyData prop";
1867 OpenMesh::create_property_from_string<OpenMesh::VertexHandle>(mesh_,
"RegisteredDataType", MyData_prop_name);
1868 bool has_myData_prop = OpenMesh::hasProperty<OpenMesh::VertexHandle, RegisteredDataType>(mesh_, MyData_prop_name.c_str());
1869 EXPECT_TRUE(has_myData_prop);
1877TEST_F(OpenMeshReadWriteOM, WriteAndLoadBoolCheckSpaces) {
1881 DoublePolyMesh mesh;
1884 mesh.add_property(prop,
"VBProp");
1885 mesh.property(prop).set_persistent(
true);
1890 std::vector<OpenMesh::VertexHandle> vertices;
1891 for (
unsigned int i = 0; i < 8; ++i)
1893 vertices.push_back(mesh.
add_vertex(DoublePolyMesh::Point(0.0, 0.0, 0.0)));
1896 mesh.property(prop,vertices[i]) =
true;
1898 mesh.property(prop,vertices[i]) =
false;
1901 std::string file_name =
"bool-space-test.om";
1911 DoublePolyMesh mesh2;
1913 mesh2.add_property(prop2,
"VBProp");
1914 mesh2.property(prop2).set_persistent(
true);
1919 for (
unsigned int i = 0; i < 8; ++i)
1922 EXPECT_TRUE( mesh.property(prop,mesh2.vertex_handle((i)) ) );
1924 EXPECT_FALSE(mesh.property(prop,mesh2.vertex_handle((i))));
1931OM_REGISTER_PROPERTY_TYPE(std::vector<std::string>)
1932OM_REGISTER_PROPERTY_TYPE(std::vector<float>)
1933OM_REGISTER_PROPERTY_TYPE(std::vector<RegisteredDataType>)
1934OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<int>>)
1935OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<
double>>)
1936OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<
float>>)
1937OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<
char>>)
1938OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<
bool>>)
1939OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<std::
string>>)
1941OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<std::vector<
int>>>)
1942OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<std::vector<
double>>>)
1943OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<std::vector<
float>>>)
1944OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<std::vector<
char>>>)
1945OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<std::vector<
bool>>>)
1946OM_REGISTER_PROPERTY_TYPE(std::vector<std::vector<std::vector<std::
string>>>)
Set options for reader/writer modules.
@ ColorFloat
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files)
@ FaceNormal
Has (r) / store (w) face normals.
@ FaceTexCoord
Has (r) / store (w) face texture coordinates.
@ Default
By default write persistent custom properties.
@ Status
Has (r) / store (w) status properties.
@ VertexNormal
Has (r) / store (w) vertex normals.
@ VertexTexCoord
Has (r) / store (w) texture coordinates.
@ VertexColor
Has (r) / store (w) vertex colors.
@ Custom
Has (r) / store (w) custom properties marked persistent (currently PLY only supports reading and only...
void calc_face_centroid(FaceHandle _fh, Point &_pt) const
calculates the average of the vertices defining _fh
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Kernel::EdgeHandle EdgeHandle
Scalar type.
Kernel::FaceIter FaceIter
Scalar type.
SmartVertexHandle add_vertex(const Point _p)
Kernel::FaceHandle FaceHandle
Scalar type.
Kernel::HalfedgeHandle HalfedgeHandle
Scalar type.
Kernel::Point Point
Coordinate type.
Kernel::Color Color
Color type.
Kernel::VertexIter VertexIter
Scalar type.
SmartVertexHandle split(EdgeHandle _eh, const Point &_p)
Edge split (= 2-to-4 split)
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.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Handle for a edge entity.
Handle for a face entity.
Handle for a halfedge entity.
static size_t restore(std::istream &, value_type &, bool=false, bool=true)
Restore a value of T and return the number of bytes read.
static const bool is_streamable
Can we store T? Set this to true in your specialization.
static std::string type_identifier(void)
A string that identifies the type of T.
static size_t size_of(void)
What's the size of T? If it depends on the actual value (e.g. for vectors) return UnknownSize.
Handle for a vertex entity.