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);
66 pm_v_bool.set_range(mesh_.vertices_begin(), mesh_.vertices_end(),
false);
67 for (
int i = 0; i < 4; ++i)
68 ASSERT_FALSE(pm_v_bool[vhandle[i]]);
69 pm_v_bool.set_range(mesh_.vertices_begin(), mesh_.vertices_end(),
true);
70 for (
int i = 0; i < 4; ++i)
71 ASSERT_TRUE(pm_v_bool[vhandle[i]]);
75 pm_e_bool.set_range(mesh_.edges_begin(), mesh_.edges_end(),
false);
76 for (Mesh::EdgeIter e_it = mesh_.edges_begin(), f_end = mesh_.edges_end();
77 e_it != f_end; ++e_it)
78 ASSERT_FALSE(pm_e_bool[*e_it]);
79 pm_e_bool.set_range(mesh_.edges_begin(), mesh_.edges_end(),
true);
80 for (Mesh::EdgeIter e_it = mesh_.edges_begin(), f_end = mesh_.edges_end();
81 e_it != f_end; ++e_it)
82 ASSERT_TRUE(pm_e_bool[*e_it]);
86 pm_f_bool.set_range(mesh_.faces_begin(), mesh_.faces_end(),
false);
87 for (Mesh::FaceIter f_it = mesh_.faces_begin(), f_end = mesh_.faces_end();
88 f_it != f_end; ++f_it)
89 ASSERT_FALSE(pm_f_bool[*f_it]);
90 pm_f_bool.set_range(mesh_.faces_begin(), mesh_.faces_end(),
true);
91 for (Mesh::FaceIter f_it = mesh_.faces_begin(), f_end = mesh_.faces_end();
92 f_it != f_end; ++f_it)
93 ASSERT_TRUE(pm_f_bool[*f_it]);
101 OpenMesh::VPropHandleT<bool>,
Mesh> pm_v_bool(mesh_,
"pm_v_bool2");
102 pm_v_bool.set_range(mesh_.vertices(),
false);
103 for (
int i = 0; i < 4; ++i)
104 ASSERT_FALSE(pm_v_bool[vhandle[i]]);
105 pm_v_bool.set_range(mesh_.vertices(),
true);
106 for (
int i = 0; i < 4; ++i)
107 ASSERT_TRUE(pm_v_bool[vhandle[i]]);
110 OpenMesh::EPropHandleT<bool>,
Mesh> pm_e_bool(mesh_,
"pm_e_bool2");
111 pm_e_bool.set_range(mesh_.edges(),
false);
112 for (Mesh::EdgeIter e_it = mesh_.edges_begin(), f_end = mesh_.edges_end();
113 e_it != f_end; ++e_it)
114 ASSERT_FALSE(pm_e_bool[*e_it]);
115 pm_e_bool.set_range(mesh_.edges(),
true);
116 for (Mesh::EdgeIter e_it = mesh_.edges_begin(), f_end = mesh_.edges_end();
117 e_it != f_end; ++e_it)
118 ASSERT_TRUE(pm_e_bool[*e_it]);
121 OpenMesh::FPropHandleT<bool>,
Mesh> pm_f_bool(mesh_,
"pm_f_bool2");
122 pm_f_bool.set_range(mesh_.faces(),
false);
123 for (Mesh::FaceIter f_it = mesh_.faces_begin(), f_end = mesh_.faces_end();
124 f_it != f_end; ++f_it)
125 ASSERT_FALSE(pm_f_bool[*f_it]);
126 pm_f_bool.set_range(mesh_.faces(),
true);
127 for (Mesh::FaceIter f_it = mesh_.faces_begin(), f_end = mesh_.faces_end();
128 f_it != f_end; ++f_it)
129 ASSERT_TRUE(pm_f_bool[*f_it]);
139 template<
typename PropHandle,
typename Mesh>
140 bool has_property(
const Mesh& _mesh,
const std::string& _name) {
141 auto dummy_handle = PropHandle{};
142 return _mesh.get_property_handle(dummy_handle, _name);
148 TEST_F(OpenMeshPropertyManager, cpp11_temp_property) {
150 const auto prop_name =
"pm_v_test_property";
151 ASSERT_FALSE(has_property<handle_type>(mesh_, prop_name));
154 auto vprop = OpenMesh::makeTemporaryProperty<OpenMesh::VertexHandle, int>(mesh_, prop_name);
155 static_cast<void>(vprop);
156 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
159 ASSERT_FALSE(has_property<handle_type>(mesh_, prop_name));
166 TEST_F(OpenMeshPropertyManager, cpp11_temp_property_shadowing) {
167 auto vh = mesh_.add_vertex({0,0,0});
170 const auto prop_name =
"pm_v_test_property";
172 auto outer_prop = OpenMesh::makeTemporaryProperty<OpenMesh::VertexHandle, int>(mesh_, prop_name);
173 outer_prop[vh] = 100;
174 ASSERT_EQ(100, outer_prop[vh]);
178 auto inner_prop = OpenMesh::makeTemporaryProperty<OpenMesh::VertexHandle, int>(mesh_, prop_name);
179 inner_prop[vh] = 200;
180 ASSERT_EQ(200, inner_prop[vh]);
185 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
186 ASSERT_EQ(100, outer_prop[vh]);
196 TEST_F(OpenMeshPropertyManager, cpp11_persistent_and_non_owning_properties) {
197 auto vh = mesh_.add_vertex({0,0,0});
200 const auto prop_name =
"pm_v_test_property";
202 ASSERT_FALSE(has_property<handle_type>(mesh_, prop_name));
205 auto prop = OpenMesh::getOrMakeProperty<OpenMesh::VertexHandle, int>(mesh_, prop_name);
210 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
214 auto prop = OpenMesh::getOrMakeProperty<OpenMesh::VertexHandle, int>(mesh_, prop_name);
215 ASSERT_EQ(100, prop[vh]);
220 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
224 auto prop = OpenMesh::getProperty<OpenMesh::VertexHandle, int>(mesh_, prop_name);
225 ASSERT_EQ(200, prop[vh]);
228 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
232 auto code_that_throws = [&](){
233 OpenMesh::getProperty<OpenMesh::VertexHandle, int>(mesh_,
"wrong_prop_name");
235 ASSERT_THROW(code_that_throws(), std::runtime_error);
238 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.