Developer Documentation
Loading...
Searching...
No Matches
unittests_convert_meshes.cc
1
2#include <gtest/gtest.h>
3#include <Unittests/unittests_common.hh>
4#include <OpenMesh/Core/Utils/PropertyManager.hh>
5
6namespace {
7
8class OpenMeshConvertTriangleMeshToPoly : public OpenMeshBase {
9
10 protected:
11
12 // This function is called before each test is run
13 virtual void SetUp() {
14 mesh_.clear();
15
16 // Add some vertices
17 Mesh::VertexHandle vhandle[4];
18
19 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
20 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
21 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
22 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
23
24 // Add two faces
25 std::vector<Mesh::VertexHandle> face_vhandles;
26
27 face_vhandles.push_back(vhandle[2]);
28 face_vhandles.push_back(vhandle[1]);
29 face_vhandles.push_back(vhandle[0]);
30 mesh_.add_face(face_vhandles);
31
32 face_vhandles.clear();
33
34 face_vhandles.push_back(vhandle[2]);
35 face_vhandles.push_back(vhandle[0]);
36 face_vhandles.push_back(vhandle[3]);
37 mesh_.add_face(face_vhandles);
38
39 // Test setup:
40 // 1 === 2
41 // | / |
42 // | / |
43 // | / |
44 // 0 === 3
45 }
46
47 // This function is called after all tests are through
48 virtual void TearDown() {
49
50 // Do some final stuff with the member data here...
51 }
52
53 // Member already defined in OpenMeshBase
54 //Mesh mesh_;
55};
56
57class OpenMeshConvertPolyMeshToTriangle : public OpenMeshBasePoly {
58
59 protected:
60
61 // This function is called before each test is run
62 virtual void SetUp() {
63 mesh_.clear();
64
65 // Add some vertices
66 Mesh::VertexHandle vhandle[4];
67
68 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
69 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
70 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
71 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
72
73 // Add two faces
74 std::vector<Mesh::VertexHandle> face_vhandles;
75
76 face_vhandles.push_back(vhandle[2]);
77 face_vhandles.push_back(vhandle[1]);
78 face_vhandles.push_back(vhandle[0]);
79 face_vhandles.push_back(vhandle[3]);
80 mesh_.add_face(face_vhandles);
81
82 // Test setup:
83 // 1 --- 2
84 // | |
85 // | |
86 // | |
87 // 0 --- 3
88 }
89
90 // This function is called after all tests are through
91 virtual void TearDown() {
92
93 // Do some final stuff with the member data here...
94 }
95
96 // Member already defined in OpenMeshBase
97 //Mesh mesh_;
98};
99
100/*
101 * ====================================================================
102 * Define tests below
103 * ====================================================================
104 */
105
106/* Checks the converted mesh #faces and #vertices behaviour of adding
107 * vertices and faces to a trimesh after the conversion.
108 */
109TEST_F(OpenMeshConvertTriangleMeshToPoly, VertexFaceCheck) {
110
111 EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices in TriMesh";
112 EXPECT_EQ(2u, mesh_.n_faces() ) << "Wrong number of faces in TriMesh";
113
114 //convert triMesh to PolyMesh
115 PolyMesh p = static_cast<PolyMesh>(mesh_);
116
117 // Check setup
118 EXPECT_EQ(4u, p.n_vertices() ) << "Wrong number of vertices in PolyMesh";
119 EXPECT_EQ(2u, p.n_faces() ) << "Wrong number of faces in PolyMesh";
120
121 //add vertex to original mesh
122 Mesh::VertexHandle vhand = mesh_.add_vertex(Mesh::Point(1, 1, 1));
123
124 EXPECT_EQ(5u, mesh_.n_vertices() ) << "Wrong number of vertices in TriMesh";
125 EXPECT_EQ(4u, p.n_vertices() ) << "Wrong number of vertices in PolyMesh";
126
127 Mesh::VertexIter it = mesh_.vertices_begin();
128 //add face to original mesh
129 mesh_.add_face(vhand,(*it),(*++it));
130
131 EXPECT_EQ(3u, mesh_.n_faces() ) << "Wrong number of faces in TriMesh";
132 EXPECT_EQ(2u, p.n_faces() ) << "Wrong number of faces in PolyMesh";
133}
134
135/* Creates a double property and checks if it works after conversion
136 */
137TEST_F(OpenMeshConvertTriangleMeshToPoly, VertexPropertyCheckDouble) {
138
139 // Add a double vertex property
141
142 EXPECT_FALSE( mesh_.get_property_handle(doubleHandle,"doubleProp") );
143
144 mesh_.add_property(doubleHandle,"doubleProp");
145
146 // Fill property
147 double index = 0.0;
148
149 for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) {
150 mesh_.property(doubleHandle,*v_it) = index;
151 index += 1.0;
152 }
153
154 EXPECT_TRUE(mesh_.get_property_handle(doubleHandle,"doubleProp"));
155
156 //convert triMesh to PolyMesh
157 PolyMesh p = static_cast<PolyMesh>(mesh_);
158
159 EXPECT_TRUE(p.get_property_handle(doubleHandle,"doubleProp"));
160
161 // Check if it is ok.
162 Mesh::VertexIter v_it = p.vertices_begin();
163 EXPECT_EQ( p.property(doubleHandle,*v_it) , 0.0 ) << "Invalid double value for vertex 0";
164 ++v_it;
165
166 EXPECT_EQ( p.property(doubleHandle,*v_it) , 1.0 ) << "Invalid double value for vertex 1";
167 ++v_it;
168
169 EXPECT_EQ( p.property(doubleHandle,*v_it) , 2.0 ) << "Invalid double value for vertex 2";
170 ++v_it;
171
172 EXPECT_EQ( p.property(doubleHandle,*v_it) , 3.0 ) << "Invalid double value for vertex 3";
173
174 //check if deletion in the original mesh affects the converted one.
175 mesh_.get_property_handle(doubleHandle,"doubleProp");
176 mesh_.remove_property(doubleHandle);
177 EXPECT_FALSE(mesh_.get_property_handle(doubleHandle,"doubleProp"));
178 EXPECT_TRUE(p.get_property_handle(doubleHandle,"doubleProp"));
179
180}
181
182/* Checks the converted mesh #faces and #vertices behaviour of adding
183 * vertices and faces to a trimesh after the conversion.
184 */
185TEST_F(OpenMeshConvertPolyMeshToTriangle, VertexFaceCheck) {
186
187 EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices in PolyMesh";
188 EXPECT_EQ(1u, mesh_.n_faces() ) << "Wrong number of faces in PolyMesh";
189
190 //convert PolyMesh to TriMesh
191 Mesh p = static_cast<Mesh>(mesh_);
192
193 // Check setup
194 EXPECT_EQ(4u, p.n_vertices() ) << "Wrong number of vertices in TriMesh";
195 EXPECT_EQ(2u, p.n_faces() ) << "Wrong number of faces in TriMesh";
196
197 //add vertex to original mesh
198 Mesh::VertexHandle vhand = mesh_.add_vertex(Mesh::Point(1, 1, 1));
199
200 EXPECT_EQ(5u, mesh_.n_vertices() ) << "Wrong number of vertices in PolyMesh";
201 EXPECT_EQ(4u, p.n_vertices() ) << "Wrong number of vertices in TriMesh";
202
203 Mesh::VertexIter it = mesh_.vertices_begin();
204
205
206 //add face to original mesh
207 Mesh::VertexHandle vhand1 = *it;
208 Mesh::VertexHandle vhand2 = (*++it);
209 mesh_.add_face(vhand,vhand1,vhand2);
210
211 EXPECT_EQ(2u, mesh_.n_faces() ) << "Wrong number of faces in PolyMesh";
212 EXPECT_EQ(2u, p.n_faces() ) << "Wrong number of faces in TriMesh";
213}
214
215/* Creates a double property and checks if it works after conversion
216 */
217TEST_F(OpenMeshConvertPolyMeshToTriangle, VertexPropertyCheckDouble) {
218
219 // Add a double vertex property
221
222 EXPECT_FALSE( mesh_.get_property_handle(doubleHandle,"doubleProp") );
223
224 mesh_.add_property(doubleHandle,"doubleProp");
225
226 // Fill property
227 double index = 0.0;
228
229 for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) {
230 mesh_.property(doubleHandle,*v_it) = index;
231 index += 1.0;
232 }
233
234 EXPECT_TRUE(mesh_.get_property_handle(doubleHandle,"doubleProp"));
235
236 //convert triMesh to PolyMesh
237 Mesh p = static_cast<Mesh>(mesh_);
238
239 EXPECT_TRUE(p.get_property_handle(doubleHandle,"doubleProp"));
240
241 // Check if it is ok.
242 Mesh::VertexIter v_it = p.vertices_begin();
243 EXPECT_EQ( p.property(doubleHandle,*v_it) , 0.0 ) << "Invalid double value for vertex 0";
244 ++v_it;
245
246 EXPECT_EQ( p.property(doubleHandle,*v_it) , 1.0 ) << "Invalid double value for vertex 1";
247 ++v_it;
248
249 EXPECT_EQ( p.property(doubleHandle,*v_it) , 2.0 ) << "Invalid double value for vertex 2";
250 ++v_it;
251
252 EXPECT_EQ( p.property(doubleHandle,*v_it) , 3.0 ) << "Invalid double value for vertex 3";
253
254 //check if deletion in the original mesh affects the converted one.
255 mesh_.get_property_handle(doubleHandle,"doubleProp");
256 mesh_.remove_property(doubleHandle);
257 EXPECT_FALSE(mesh_.get_property_handle(doubleHandle,"doubleProp"));
258 EXPECT_TRUE(p.get_property_handle(doubleHandle,"doubleProp"));
259
260}
261
262/* Creates a double property and checks if it works after conversion
263 * especially if edge properties are preserved after triangulation
264 */
265TEST_F(OpenMeshConvertPolyMeshToTriangle, EdgePropertyCheckDouble) {
266
267 // Add a double vertex property
269
270 EXPECT_FALSE( mesh_.get_property_handle(doubleHandle,"doubleProp") );
271
272 mesh_.add_property(doubleHandle,"doubleProp");
273
274 // Fill property
275 double index = 0.0;
276
277 for ( Mesh::EdgeIter v_it = mesh_.edges_begin() ; v_it != mesh_.edges_end(); ++v_it ) {
278 mesh_.property(doubleHandle,*v_it) = index;
279 index += 1.0;
280 }
281
282 EXPECT_TRUE(mesh_.get_property_handle(doubleHandle,"doubleProp"));
283
284 //convert triMesh to PolyMesh
285 Mesh p = static_cast<Mesh>(mesh_);
286
287 EXPECT_TRUE(p.get_property_handle(doubleHandle,"doubleProp"));
288
289 // Check if it is ok.
290 Mesh::EdgeIter v_it = p.edges_begin();
291
292 EXPECT_EQ( p.property(doubleHandle,*v_it) , 0.0 ) << "Invalid double value for vertex 0";
293 ++v_it;
294
295 EXPECT_EQ( p.property(doubleHandle,*v_it) , 1.0 ) << "Invalid double value for vertex 1";
296 ++v_it;
297
298 EXPECT_EQ( p.property(doubleHandle,*v_it) , 2.0 ) << "Invalid double value for vertex 2";
299 ++v_it;
300
301 EXPECT_EQ( p.property(doubleHandle,*v_it) , 3.0 ) << "Invalid double value for vertex 3";
302 ++v_it;
303
304 EXPECT_FALSE( p.is_boundary(*v_it)) << "Invalid Edge after triangulation";
305
306 //check if deletion in the original mesh affects the converted one.
307 mesh_.get_property_handle(doubleHandle,"doubleProp");
308 mesh_.remove_property(doubleHandle);
309 EXPECT_FALSE(mesh_.get_property_handle(doubleHandle,"doubleProp"));
310 EXPECT_TRUE(p.get_property_handle(doubleHandle,"doubleProp"));
311
312}
313
314}
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition PolyMeshT.hh:136
SmartVertexHandle add_vertex(const Point _p)
Definition PolyMeshT.hh:255
Kernel::EdgeIter EdgeIter
Scalar type.
Definition PolyMeshT.hh:145
Kernel::Point Point
Coordinate type.
Definition PolyMeshT.hh:112
Kernel::VertexIter VertexIter
Scalar type.
Definition PolyMeshT.hh:143