From 7a559a2bce1be5832b9e77d440a7e80bc9943a5d Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Mon, 9 Nov 2020 16:53:12 +0100 Subject: [PATCH] add unittest checking loading of properties of om version 2.1 --- .../TestFiles/cube_tri_with_properties_2_1.om | Bin 0 -> 24340 bytes src/Unittests/unittests_read_write_OM.cc | 190 ++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 src/Unittests/TestFiles/cube_tri_with_properties_2_1.om diff --git a/src/Unittests/TestFiles/cube_tri_with_properties_2_1.om b/src/Unittests/TestFiles/cube_tri_with_properties_2_1.om new file mode 100644 index 0000000000000000000000000000000000000000..26c4e1715db6d530afb27e91992ff60de2bf1232 GIT binary patch literal 24340 zcmeHPJ98Yz5uSS=4zB|s(X>R{>yt{QVo~ym)WdedL0}gXl@O>LgBGDj6-}Zj%4KI8 zIz;FYKf(XNTL=*%a$R(xLxm3g^~`*j-Qn)e9(W>P8C%uZ$K6g(&-C|o_v{`%`}FhO zp;BrMvJFu;luGYI{^|B|Ovzu9ytr**46=&9C? zPH(N(-cX%ZtNn}K%DCIvR^8QJXVM+LHt4RX-e$M^=3sSa(7V~`ztQgxI)k4K`fv4D zf7&1Xygf{M!%lnUXZ_(;Z}iLl==JXEyuY&E8N9yr)|>zCcZaREOw?-#mSid?2UK|9W^JW*2T%ziNEzGVOoA zvDW4Tls0el+pnKKdp?#S#N_ue@oSj$ZA|!y{c3GNaa>ZmTfbO1jc!Bf}at7CZU4nAqClQibB-jagHmQQBPb4wb7 z=W5eY%b3EZU5GI103xh9f(Wy&Lxf#Lw=nDuqy=e1PE^dZOLR9MrYz>^_wt^86CF~m zcBk9x4~8qF)wT7F&GFVYhP>U0d%SPTdVD6W6*ljQ_HyX?uW5TdL_p%MPu!kJc*mWG zh`8gfhsgNAT@MkW-1cJs;)wB98^r9hE$96JfCdsE$B+y%hbW+f=$Yb}2-?RnQS>() z6G^xu*WO8#^L?j`t4!s7gB!tA&!B2(aJ6cXwPCQeWzfa%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H4aV=QB{a_vwLV=iNL z66j$JrXI#(>S0W#9@|U&b?wkD>Y-iKGjZRe9@<4cw2OLZ7c`iSc2N)Qq8{2c(f0ey zMW}~%Q4j5+9@<4cw2OLZ7xmCC>Y-iKL%XPlc2SS*CH}hp(k|+`she=V_q&n`S)=I` zl0oJWNmyiESCW=Jh$Jp4M3R>u?#Y-lH?{l0id zVGCmjxjl>}VeCq@ZD!*3VQdLw8DmTs(->>Q*k)VzZ}2Lo=emD(WWrc|J$`mvnA=>Q z|1}BP9+xH;@~<>-Wu5uPG2A|b%pnSS$rvJe(G~H(|ZhP^6eEd-D&9Zoo=ZB+^ zq$GTD!JKUeZOC@r-tzvZOBdsrpO0CCb)k~k z{_z7=#q(SLgbU7pWIT1TU!+yN!68|&{F5npV{nmQxP|RC$$`BQHV00{Lke3}4jjuh zV>$6eTQya=aV$rP<;t;~ugWgw_T2k*9NS;68*!gFJ0@;Vd$_O4xx)3O(4JTh8?HZv z_9)k%s(Grii}r9I+C_V~ubQV=O%tnal-okPXb<;Q^K|Whb^xp9>FWAllN!PEmZ=eR zo9>dY5wu3$4>^WpPUhGv)B;i~g!MvLGlX@+5$?&?4tZUoN8}iiLFP`VE5W@YQwa6! z;dmcHJt>a!HA-HWLVF?_l0uH1WZ2Ik3ipbPAqhnEh-kBylpuo_h9hybn2qq)zfS z<#j1(3!)(@7}kQg1i1P7^8ao8nmk7+ d@xE)aGXKbN?EaDCj(Jm0Xq$^ee1-Lv`Y+%%a2Wsq literal 0 HcmV?d00001 diff --git a/src/Unittests/unittests_read_write_OM.cc b/src/Unittests/unittests_read_write_OM.cc index 35e4522d..4766b629 100644 --- a/src/Unittests/unittests_read_write_OM.cc +++ b/src/Unittests/unittests_read_write_OM.cc @@ -1,6 +1,7 @@ #include #include +#include namespace { @@ -1458,6 +1459,195 @@ TEST_F(OpenMeshReadWriteOM, LoadPolyMeshVersion_2_0) { } + +std::string get_type_string(OpenMesh::FaceHandle) { return "Face"; } +std::string get_type_string(OpenMesh::EdgeHandle) { return "Edge"; } +std::string get_type_string(OpenMesh::HalfedgeHandle) { return "Halfedge"; } +std::string get_type_string(OpenMesh::VertexHandle) { return "Vertex"; } + +std::string get_type_string(char) { return "char"; } +std::string get_type_string(double) { return "double"; } +std::string get_type_string(float) { return "float"; } +std::string get_type_string(int) { return "int"; } +std::string get_type_string(short) { return "short"; } +std::string get_type_string(unsigned char) { return "unsigned char"; } +std::string get_type_string(unsigned int) { return "unsigned int"; } +std::string get_type_string(unsigned short) { return "unsigned short"; } +std::string get_type_string(bool) { return "bool"; } + +template +std::string get_type_string(std::vector) { return "std::vector of " + get_type_string(T()); } + +template +std::string get_type_string(OpenMesh::VectorT) { return "OM vector of dimension " + std::to_string(Dim) + " of type " + get_type_string(T()); } + + +template +T get_value(int seed, T, int seed2 = 0) +{ + return (seed * 3 + seed2) % 20; +} + +template +std::vector get_value(int seed, const std::vector&) +{ + int size = get_value(seed, 3); + std::vector res(size); + for (int i = 0; i < size; ++i) + res[i] = get_value(seed, T(), i); + return res; +} + +template +OpenMesh::VectorT get_value(int seed, const OpenMesh::VectorT&) +{ + OpenMesh::VectorT res; + for (int i = 0; i < Dim; ++i) + res[i] = get_value(seed, T(), i); + return res; +} + +template +OpenMesh::Prop add_property(MeshT& _mesh) +{ + std::string name = get_type_string(HandleT()) + ": " + get_type_string(T()); + OpenMesh::Prop prop(_mesh, name.c_str()); + _mesh.property(prop.getRawProperty()).set_persistent(true); + for (auto e : _mesh.template elements()) + prop[e] = get_value(e.idx(), T()); + + return prop; +} + +template +void check_property(MeshT& _mesh) +{ + std::string name = get_type_string(HandleT()) + ": " + get_type_string(T()); + bool has_prop = OpenMesh::hasProperty(_mesh, name.c_str()); + EXPECT_TRUE(has_prop) << "Property " << name << " is not available"; + if (!has_prop) + return; + OpenMesh::Prop prop(_mesh, name.c_str()); + for (auto e : _mesh.template elements()) + EXPECT_EQ(prop[e], get_value(e.idx(), T())) << "For property " << name; +} + +template +void request_property(MeshT& _mesh) +{ + std::string name = get_type_string(HandleT()) + ": " + get_type_string(T()); + OpenMesh::Prop prop(_mesh, name.c_str()); +} + + +enum class PropertyAction +{ + Add, Check, Request +}; + + +template +void do_property(MeshT& _mesh, PropertyAction action) +{ + switch (action) + { + case PropertyAction::Add: + add_property(_mesh); + break; + case PropertyAction::Check: + check_property(_mesh); + break; + case PropertyAction::Request: + request_property(_mesh); + break; + } +} + + + +template +void do_all_property_types(MeshT& _mesh, PropertyAction action) +{ + // TODO: add support for commented out types + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); +// do_property (_mesh, action); +// do_property> (_mesh, action); +// do_property>(_mesh, action); +// do_property> (_mesh, action); +// do_property> (_mesh, action); +// do_property> (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); +// do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); +// do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); +// do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); +// do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); + do_property (_mesh, action); +} + +template +void do_all_properties(MeshT& _mesh, PropertyAction action) +{ + do_all_property_types (_mesh, action); + do_all_property_types (_mesh, action); + do_all_property_types(_mesh, action); + do_all_property_types (_mesh, action); +} + +template void add_all_properties(MeshT& _mesh) { do_all_properties(_mesh, PropertyAction::Add ); } +template void check_all_properties(MeshT& _mesh) { do_all_properties(_mesh, PropertyAction::Check ); } +template void request_all_properties(MeshT& _mesh) { do_all_properties(_mesh, PropertyAction::Request); } + +/* + * Load a triangle mesh from an om file of version 2.1 with properties + */ +TEST_F(OpenMeshReadWriteOM, LoadTriangleMeshWithPropertiesVersion_2_1) { + + mesh_.clear(); + + std::string file_name = "cube_tri_with_properties_2_1.om"; + + request_all_properties(mesh_); + bool ok = OpenMesh::IO::read_mesh(mesh_, file_name); + + ASSERT_TRUE(ok) << file_name; + + ASSERT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!"; + ASSERT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!"; + ASSERT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!"; + ASSERT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!"; + + check_all_properties(mesh_); +} + /* * Try to load mesh from om file with a version that is not yet supported */