1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3 #include <OpenMesh/Core/Utils/PropertyManager.hh>
14 virtual void SetUp() {
18 virtual void TearDown() {
36 TEST_F(OpenMeshPropertyManager, set_range_bool) {
49 std::vector<Mesh::VertexHandle> face_vhandles;
51 face_vhandles.push_back(vhandle[0]);
52 face_vhandles.push_back(vhandle[1]);
53 face_vhandles.push_back(vhandle[2]);
54 mesh_.add_face(face_vhandles);
56 face_vhandles.clear();
58 face_vhandles.push_back(vhandle[0]);
59 face_vhandles.push_back(vhandle[2]);
60 face_vhandles.push_back(vhandle[3]);
61 mesh_.add_face(face_vhandles);
65 pm_v_bool.set_range(mesh_.vertices_begin(), mesh_.vertices_end(),
false);
66 for (
int i = 0; i < 4; ++i)
67 ASSERT_FALSE(pm_v_bool[vhandle[i]]);
68 pm_v_bool.set_range(mesh_.vertices_begin(), mesh_.vertices_end(),
true);
69 for (
int i = 0; i < 4; ++i)
70 ASSERT_TRUE(pm_v_bool[vhandle[i]]);
74 pm_e_bool.set_range(mesh_.edges_begin(), mesh_.edges_end(),
false);
75 for (Mesh::EdgeIter e_it = mesh_.edges_begin(), f_end = mesh_.edges_end();
76 e_it != f_end; ++e_it)
77 ASSERT_FALSE(pm_e_bool[*e_it]);
78 pm_e_bool.set_range(mesh_.edges_begin(), mesh_.edges_end(),
true);
79 for (Mesh::EdgeIter e_it = mesh_.edges_begin(), f_end = mesh_.edges_end();
80 e_it != f_end; ++e_it)
81 ASSERT_TRUE(pm_e_bool[*e_it]);
85 pm_f_bool.set_range(mesh_.faces_begin(), mesh_.faces_end(),
false);
86 for (Mesh::FaceIter f_it = mesh_.faces_begin(), f_end = mesh_.faces_end();
87 f_it != f_end; ++f_it)
88 ASSERT_FALSE(pm_f_bool[*f_it]);
89 pm_f_bool.set_range(mesh_.faces_begin(), mesh_.faces_end(),
true);
90 for (Mesh::FaceIter f_it = mesh_.faces_begin(), f_end = mesh_.faces_end();
91 f_it != f_end; ++f_it)
92 ASSERT_TRUE(pm_f_bool[*f_it]);
100 #if _MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
102 template<
typename PropHandle,
typename Mesh>
103 bool has_property(
const Mesh& _mesh,
const std::string& _name) {
104 auto dummy_handle = PropHandle{};
105 return _mesh.get_property_handle(dummy_handle, _name);
111 TEST_F(OpenMeshPropertyManager, cpp11_temp_property) {
113 const auto prop_name =
"pm_v_test_property";
114 ASSERT_FALSE(has_property<handle_type>(mesh_, prop_name));
117 auto vprop = OpenMesh::makePropertyManagerFromNew<handle_type>(mesh_, prop_name);
118 static_cast<void>(vprop);
119 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
122 ASSERT_FALSE(has_property<handle_type>(mesh_, prop_name));
129 TEST_F(OpenMeshPropertyManager, cpp11_temp_property_shadowing) {
130 auto vh = mesh_.add_vertex({0,0,0});
133 const auto prop_name =
"pm_v_test_property";
135 auto outer_prop = OpenMesh::makePropertyManagerFromNew<handle_type>(mesh_, prop_name);
136 outer_prop[vh] = 100;
137 ASSERT_EQ(100, outer_prop[vh]);
141 auto inner_prop = OpenMesh::makePropertyManagerFromNew<handle_type>(mesh_, prop_name);
142 inner_prop[vh] = 200;
143 ASSERT_EQ(200, inner_prop[vh]);
148 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
149 ASSERT_EQ(100, outer_prop[vh]);
159 TEST_F(OpenMeshPropertyManager, cpp11_persistent_and_non_owning_properties) {
160 auto vh = mesh_.add_vertex({0,0,0});
163 const auto prop_name =
"pm_v_test_property";
165 ASSERT_FALSE(has_property<handle_type>(mesh_, prop_name));
168 auto prop = OpenMesh::makePropertyManagerFromExistingOrNew<handle_type>(mesh_, prop_name);
173 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
177 auto prop = OpenMesh::makePropertyManagerFromExistingOrNew<handle_type>(mesh_, prop_name);
178 ASSERT_EQ(100, prop[vh]);
183 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
187 auto prop = OpenMesh::makePropertyManagerFromExisting<handle_type>(mesh_, prop_name);
188 ASSERT_EQ(200, prop[vh]);
191 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
195 ASSERT_THROW(OpenMesh::makePropertyManagerFromExisting<handle_type>(mesh_,
"wrong_property_name"), std::runtime_error);
198 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
Kernel::Point Point
Coordinate type.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.