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]);
96 #if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 102 OpenMesh::VPropHandleT<bool>,
Mesh> pm_v_bool(mesh_,
"pm_v_bool2");
103 pm_v_bool.set_range(mesh_.vertices(),
false);
104 for (
int i = 0; i < 4; ++i)
105 ASSERT_FALSE(pm_v_bool[vhandle[i]]);
106 pm_v_bool.set_range(mesh_.vertices(),
true);
107 for (
int i = 0; i < 4; ++i)
108 ASSERT_TRUE(pm_v_bool[vhandle[i]]);
111 OpenMesh::EPropHandleT<bool>,
Mesh> pm_e_bool(mesh_,
"pm_e_bool2");
112 pm_e_bool.set_range(mesh_.edges(),
false);
113 for (Mesh::EdgeIter e_it = mesh_.edges_begin(), f_end = mesh_.edges_end();
114 e_it != f_end; ++e_it)
115 ASSERT_FALSE(pm_e_bool[*e_it]);
116 pm_e_bool.set_range(mesh_.edges(),
true);
117 for (Mesh::EdgeIter e_it = mesh_.edges_begin(), f_end = mesh_.edges_end();
118 e_it != f_end; ++e_it)
119 ASSERT_TRUE(pm_e_bool[*e_it]);
122 OpenMesh::FPropHandleT<bool>,
Mesh> pm_f_bool(mesh_,
"pm_f_bool2");
123 pm_f_bool.set_range(mesh_.faces(),
false);
124 for (Mesh::FaceIter f_it = mesh_.faces_begin(), f_end = mesh_.faces_end();
125 f_it != f_end; ++f_it)
126 ASSERT_FALSE(pm_f_bool[*f_it]);
127 pm_f_bool.set_range(mesh_.faces(),
true);
128 for (Mesh::FaceIter f_it = mesh_.faces_begin(), f_end = mesh_.faces_end();
129 f_it != f_end; ++f_it)
130 ASSERT_TRUE(pm_f_bool[*f_it]);
140 #if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 142 template<
typename PropHandle,
typename Mesh>
143 bool has_property(
const Mesh& _mesh,
const std::string& _name) {
144 auto dummy_handle = PropHandle{};
145 return _mesh.get_property_handle(dummy_handle, _name);
151 TEST_F(OpenMeshPropertyManager, cpp11_temp_property) {
153 const auto prop_name =
"pm_v_test_property";
154 ASSERT_FALSE(has_property<handle_type>(mesh_, prop_name));
157 auto vprop = OpenMesh::makePropertyManagerFromNew<handle_type>(mesh_, prop_name);
158 static_cast<void>(vprop);
159 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
162 ASSERT_FALSE(has_property<handle_type>(mesh_, prop_name));
169 TEST_F(OpenMeshPropertyManager, cpp11_temp_property_shadowing) {
170 auto vh = mesh_.add_vertex({0,0,0});
173 const auto prop_name =
"pm_v_test_property";
175 auto outer_prop = OpenMesh::makePropertyManagerFromNew<handle_type>(mesh_, prop_name);
176 outer_prop[vh] = 100;
177 ASSERT_EQ(100, outer_prop[vh]);
181 auto inner_prop = OpenMesh::makePropertyManagerFromNew<handle_type>(mesh_, prop_name);
182 inner_prop[vh] = 200;
183 ASSERT_EQ(200, inner_prop[vh]);
188 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
189 ASSERT_EQ(100, outer_prop[vh]);
199 TEST_F(OpenMeshPropertyManager, cpp11_persistent_and_non_owning_properties) {
200 auto vh = mesh_.add_vertex({0,0,0});
203 const auto prop_name =
"pm_v_test_property";
205 ASSERT_FALSE(has_property<handle_type>(mesh_, prop_name));
208 auto prop = OpenMesh::makePropertyManagerFromExistingOrNew<handle_type>(mesh_, prop_name);
213 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
217 auto prop = OpenMesh::makePropertyManagerFromExistingOrNew<handle_type>(mesh_, prop_name);
218 ASSERT_EQ(100, prop[vh]);
223 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
227 auto prop = OpenMesh::makePropertyManagerFromExisting<handle_type>(mesh_, prop_name);
228 ASSERT_EQ(200, prop[vh]);
231 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
235 ASSERT_THROW(OpenMesh::makePropertyManagerFromExisting<handle_type>(mesh_,
"wrong_property_name"), std::runtime_error);
238 ASSERT_TRUE(has_property<handle_type>(mesh_, prop_name));
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Kernel::Point Point
Coordinate type.