Developer Documentation
unittests_basics.cc
1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3 
4 #include <OpenVolumeMesh/Attribs/StatusAttrib.hh>
5 #include <OpenVolumeMesh/Attribs/NormalAttrib.hh>
6 #include <OpenVolumeMesh/Attribs/ColorAttrib.hh>
7 
8 using namespace OpenVolumeMesh;
9 using namespace Geometry;
10 
11 /*
12  * ====================================================================
13  * Define tests below
14  * ====================================================================
15  */
16 
17 TEST_F(PolyhedralMeshBase, CreateSimpleMesh) {
18 
19  /*
20  * Add vertices
21  */
22 
23  VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, -1.0, -1.0));
24  VertexHandle v1 = mesh_.add_vertex(Vec3d( 1.0, -1.0, -1.0));
25  VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0, 1.0, -1.0));
26  VertexHandle v3 = mesh_.add_vertex(Vec3d(-1.0, 1.0, -1.0));
27  VertexHandle v4 = mesh_.add_vertex(Vec3d(-1.0, -1.0, 1.0));
28  VertexHandle v5 = mesh_.add_vertex(Vec3d( 1.0, -1.0, 1.0));
29  VertexHandle v6 = mesh_.add_vertex(Vec3d( 1.0, 1.0, 1.0));
30  VertexHandle v7 = mesh_.add_vertex(Vec3d(-1.0, 1.0, 1.0));
31 
32  EXPECT_EQ(8u, mesh_.n_vertices()) << "The number of vertices is not correct!";
33 
34  /*
35  * Add faces
36  */
37 
38  std::vector<VertexHandle> fvertices;
39 
40  fvertices.push_back(v3);
41  fvertices.push_back(v2);
42  fvertices.push_back(v1);
43  fvertices.push_back(v0);
44 
45  FaceHandle fh0 = mesh_.add_face(fvertices);
46 
47  fvertices.clear();
48 
49  fvertices.push_back(v4);
50  fvertices.push_back(v5);
51  fvertices.push_back(v6);
52  fvertices.push_back(v7);
53 
54  FaceHandle fh1 = mesh_.add_face(fvertices);
55 
56  fvertices.clear();
57 
58  fvertices.push_back(v0);
59  fvertices.push_back(v4);
60  fvertices.push_back(v7);
61  fvertices.push_back(v3);
62 
63  FaceHandle fh2 = mesh_.add_face(fvertices);
64 
65  fvertices.clear();
66 
67  fvertices.push_back(v1);
68  fvertices.push_back(v2);
69  fvertices.push_back(v6);
70  fvertices.push_back(v5);
71 
72  FaceHandle fh3 = mesh_.add_face(fvertices);
73 
74  fvertices.clear();
75 
76  fvertices.push_back(v7);
77  fvertices.push_back(v6);
78  fvertices.push_back(v2);
79  fvertices.push_back(v3);
80 
81  FaceHandle fh4 = mesh_.add_face(fvertices);
82 
83  fvertices.clear();
84 
85  fvertices.push_back(v0);
86  fvertices.push_back(v1);
87  fvertices.push_back(v5);
88  fvertices.push_back(v4);
89 
90  FaceHandle fh5 = mesh_.add_face(fvertices);
91 
92  EXPECT_EQ(12u, mesh_.n_edges()) << "The number of edges is not correct!";
93  EXPECT_EQ(6u, mesh_.n_faces()) << "The number of faces is not correct!";
94 
95  /*
96  * Add cell
97  */
98 
99  std::vector<HalfFaceHandle> chfaces;
100 
101  chfaces.push_back(mesh_.halfface_handle(fh0, 0));
102  chfaces.push_back(mesh_.halfface_handle(fh1, 0));
103  chfaces.push_back(mesh_.halfface_handle(fh2, 0));
104  chfaces.push_back(mesh_.halfface_handle(fh3, 0));
105  chfaces.push_back(mesh_.halfface_handle(fh4, 0));
106  chfaces.push_back(mesh_.halfface_handle(fh5, 0));
107 
108  mesh_.add_cell(chfaces);
109 
110  EXPECT_EQ(1u, mesh_.n_cells()) << "The number of cells is not correct!";
111 }
112 
113 //===========================================================================
114 
115 TEST_F(PolyhedralMeshBase, CreateSimpleMeshWithoutCells) {
116 
117  Vec3d p1(0.0, 0.0, 0.0);
118  Vec3d p2(1.0, 0.0, 0.0);
119  Vec3d p3(1.0, 1.0, 0.0);
120  Vec3d p4(0.0, 1.0, 0.0);
121 
122  Vec3d p5(0.0, 0.0, 1.0);
123  Vec3d p6(1.0, 0.0, 1.0);
124  Vec3d p7(1.0, 1.0, 1.0);
125  Vec3d p8(0.0, 1.0, 1.0);
126 
127  VertexHandle v1 = mesh_.add_vertex(p1);
128  VertexHandle v2 = mesh_.add_vertex(p2);
129  VertexHandle v3 = mesh_.add_vertex(p3);
130  VertexHandle v4 = mesh_.add_vertex(p4);
131 
132  VertexHandle v5 = mesh_.add_vertex(p5);
133  VertexHandle v6 = mesh_.add_vertex(p6);
134  VertexHandle v7 = mesh_.add_vertex(p7);
135  VertexHandle v8 = mesh_.add_vertex(p8);
136 
137  EXPECT_EQ(0, v1);
138  EXPECT_EQ(1, v2);
139  EXPECT_EQ(2, v3);
140  EXPECT_EQ(3, v4);
141  EXPECT_EQ(4, v5);
142  EXPECT_EQ(5, v6);
143  EXPECT_EQ(6, v7);
144  EXPECT_EQ(7, v8);
145 
146  EdgeHandle e1 = mesh_.add_edge(v1, v2);
147  EdgeHandle e2 = mesh_.add_edge(v2, v3);
148  EdgeHandle e3 = mesh_.add_edge(v3, v4);
149  EdgeHandle e4 = mesh_.add_edge(v4, v1);
150 
151  EdgeHandle e5 = mesh_.add_edge(v5, v6);
152  EdgeHandle e6 = mesh_.add_edge(v6, v7);
153  EdgeHandle e7 = mesh_.add_edge(v7, v8);
154  EdgeHandle e8 = mesh_.add_edge(v8, v5);
155 
156  EXPECT_EQ(0, e1);
157  EXPECT_EQ(1, e2);
158  EXPECT_EQ(2, e3);
159  EXPECT_EQ(3, e4);
160  EXPECT_EQ(4, e5);
161  EXPECT_EQ(5, e6);
162  EXPECT_EQ(6, e7);
163  EXPECT_EQ(7, e8);
164 
165  // Get halfedges
166  HalfEdgeHandle h1 = mesh_.halfedge_handle(e1, 0u);
167  HalfEdgeHandle h2 = mesh_.halfedge_handle(e2, 0u);
168  HalfEdgeHandle h3 = mesh_.halfedge_handle(e3, 0u);
169  HalfEdgeHandle h4 = mesh_.halfedge_handle(e4, 0u);
170 
171  HalfEdgeHandle h5 = mesh_.halfedge_handle(e5, 0u);
172  HalfEdgeHandle h6 = mesh_.halfedge_handle(e6, 0u);
173  HalfEdgeHandle h7 = mesh_.halfedge_handle(e7, 0u);
174  HalfEdgeHandle h8 = mesh_.halfedge_handle(e8, 0u);
175 
176  EXPECT_EQ(v1, mesh_.halfedge(h1).from_vertex());
177  EXPECT_EQ(v2, mesh_.halfedge(h1).to_vertex());
178  EXPECT_EQ(v2, mesh_.halfedge(h2).from_vertex());
179  EXPECT_EQ(v3, mesh_.halfedge(h2).to_vertex());
180  EXPECT_EQ(v3, mesh_.halfedge(h3).from_vertex());
181  EXPECT_EQ(v4, mesh_.halfedge(h3).to_vertex());
182  EXPECT_EQ(v4, mesh_.halfedge(h4).from_vertex());
183  EXPECT_EQ(v1, mesh_.halfedge(h4).to_vertex());
184 
185  EXPECT_EQ(v5, mesh_.halfedge(h5).from_vertex());
186  EXPECT_EQ(v6, mesh_.halfedge(h5).to_vertex());
187  EXPECT_EQ(v6, mesh_.halfedge(h6).from_vertex());
188  EXPECT_EQ(v7, mesh_.halfedge(h6).to_vertex());
189  EXPECT_EQ(v7, mesh_.halfedge(h7).from_vertex());
190  EXPECT_EQ(v8, mesh_.halfedge(h7).to_vertex());
191  EXPECT_EQ(v8, mesh_.halfedge(h8).from_vertex());
192  EXPECT_EQ(v5, mesh_.halfedge(h8).to_vertex());
193 
194  // Check opposite halfedges
195  EXPECT_EQ(v2, mesh_.opposite_halfedge(h1).from_vertex());
196  EXPECT_EQ(v1, mesh_.opposite_halfedge(h1).to_vertex());
197  EXPECT_EQ(v3, mesh_.opposite_halfedge(h2).from_vertex());
198  EXPECT_EQ(v2, mesh_.opposite_halfedge(h2).to_vertex());
199  EXPECT_EQ(v4, mesh_.opposite_halfedge(h3).from_vertex());
200  EXPECT_EQ(v3, mesh_.opposite_halfedge(h3).to_vertex());
201  EXPECT_EQ(v1, mesh_.opposite_halfedge(h4).from_vertex());
202  EXPECT_EQ(v4, mesh_.opposite_halfedge(h4).to_vertex());
203 
204  EXPECT_EQ(v6, mesh_.opposite_halfedge(h5).from_vertex());
205  EXPECT_EQ(v5, mesh_.opposite_halfedge(h5).to_vertex());
206  EXPECT_EQ(v7, mesh_.opposite_halfedge(h6).from_vertex());
207  EXPECT_EQ(v6, mesh_.opposite_halfedge(h6).to_vertex());
208  EXPECT_EQ(v8, mesh_.opposite_halfedge(h7).from_vertex());
209  EXPECT_EQ(v7, mesh_.opposite_halfedge(h7).to_vertex());
210  EXPECT_EQ(v5, mesh_.opposite_halfedge(h8).from_vertex());
211  EXPECT_EQ(v8, mesh_.opposite_halfedge(h8).to_vertex());
212 
213  // Add a face via vertices
214  std::vector<VertexHandle> vertices;
215  vertices.push_back(v2); vertices.push_back(v6);
216  vertices.push_back(v7); vertices.push_back(v3);
217  FaceHandle f1 = mesh_.add_face(vertices);
218 
219  EXPECT_EQ(0, f1);
220 
221  // Get halfedges of face
222  std::vector<HalfEdgeHandle> halfedges = mesh_.face(f1).halfedges();
223 
224  std::vector<HalfEdgeHandle>::iterator it = halfedges.begin();
225 
226  EXPECT_EQ(8, mesh_.edge_handle(*it)); ++it;
227  EXPECT_EQ(5, mesh_.edge_handle(*it)); ++it;
228  EXPECT_EQ(9, mesh_.edge_handle(*it)); ++it;
229  EXPECT_EQ(1, mesh_.edge_handle(*it));
230 
231  // Add invalid face
232  halfedges.clear();
233  halfedges.push_back(mesh_.halfedge_handle(e1, 0)); halfedges.push_back(mesh_.halfedge_handle(e2, 0));
234  halfedges.push_back(mesh_.halfedge_handle(e7, 0)); halfedges.push_back(mesh_.halfedge_handle(e4, 0));
235 
236  FaceHandle fI = mesh_.add_face(halfedges, true);
237 
238  EXPECT_EQ(PolyhedralMesh::InvalidFaceHandle, fI);
239 
240  // Now add valid face via edges
241  halfedges.clear();
242  halfedges.push_back(mesh_.halfedge_handle(e1, 0)); halfedges.push_back(mesh_.halfedge_handle(e2, 0));
243  halfedges.push_back(mesh_.halfedge_handle(e3, 0)); halfedges.push_back(mesh_.halfedge_handle(e4, 0));
244 
245  FaceHandle f2 = mesh_.add_face(halfedges);
246 
247  EXPECT_EQ(1, f2);
248 
249  // Get halfedges of face
250  halfedges = mesh_.face(f2).halfedges();
251  int handle = 0;
252  for(it = halfedges.begin(); it != halfedges.end(); ++it) {
253  EXPECT_EQ(handle, mesh_.edge_handle(*it)); handle++;
254  }
255 }
256 
257 TEST_F(PolyhedralMeshBase, TopologyCheckPass) {
258 
259  // Add eight vertices
260  VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, 0.0, 0.0));
261  VertexHandle v1 = mesh_.add_vertex(Vec3d( 0.0, 0.0, 1.0));
262  VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0, 0.0, 0.0));
263  VertexHandle v3 = mesh_.add_vertex(Vec3d( 0.0, 1.0, 0.0));
264 
265  std::vector<VertexHandle> vertices;
266 
267  // Add faces
268  vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v3);
269  FaceHandle f0 = mesh_.add_face(vertices);
270 
271  vertices.clear();
272  vertices.push_back(v1); vertices.push_back(v2);vertices.push_back(v3);
273  FaceHandle f1 = mesh_.add_face(vertices);
274 
275  vertices.clear();
276  vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v2);
277  FaceHandle f2 = mesh_.add_face(vertices);
278 
279  vertices.clear();
280  vertices.push_back(v0); vertices.push_back(v3);vertices.push_back(v2);
281  FaceHandle f3 = mesh_.add_face(vertices);
282 
283  std::vector<HalfFaceHandle> halffaces;
284 
285  // Add first tetrahedron
286  halffaces.push_back(mesh_.halfface_handle(f0, 1));
287  halffaces.push_back(mesh_.halfface_handle(f1, 1));
288  halffaces.push_back(mesh_.halfface_handle(f2, 0));
289  halffaces.push_back(mesh_.halfface_handle(f3, 1));
290  EXPECT_NE(PolyhedralMesh::InvalidCellHandle, mesh_.add_cell(halffaces));
291 }
292 
293 TEST_F(PolyhedralMeshBase, TopologyCheckFail) {
294 
295  // Add eight vertices
296  VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, 0.0, 0.0));
297  VertexHandle v1 = mesh_.add_vertex(Vec3d( 0.0, 0.0, 1.0));
298  VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0, 0.0, 0.0));
299  VertexHandle v3 = mesh_.add_vertex(Vec3d( 0.0, 1.0, 0.0));
300 
301  std::vector<VertexHandle> vertices;
302 
303  // Add faces
304  vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v3);
305  FaceHandle f0 = mesh_.add_face(vertices);
306 
307  vertices.clear();
308  vertices.push_back(v1); vertices.push_back(v2);vertices.push_back(v3);
309  FaceHandle f1 = mesh_.add_face(vertices);
310 
311  vertices.clear();
312  vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v2);
313  FaceHandle f2 = mesh_.add_face(vertices);
314 
315  vertices.clear();
316  vertices.push_back(v0); vertices.push_back(v3);vertices.push_back(v2);
317  FaceHandle f3 = mesh_.add_face(vertices);
318 
319  std::vector<HalfFaceHandle> halffaces;
320 
321  // Add first tetrahedron
322  halffaces.push_back(mesh_.halfface_handle(f0, 1));
323  halffaces.push_back(mesh_.halfface_handle(f1, 1));
324  halffaces.push_back(mesh_.halfface_handle(f2, 0));
325  halffaces.push_back(mesh_.halfface_handle(f3, 0));
326  EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, mesh_.add_cell(halffaces, true));
327 }
328 
329 TEST_F(HexahedralMeshBase, TopologyCheckPass) {
330 
331  VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, -1.0, -1.0));
332  VertexHandle v1 = mesh_.add_vertex(Vec3d( 1.0, -1.0, -1.0));
333  VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0, 1.0, -1.0));
334  VertexHandle v3 = mesh_.add_vertex(Vec3d(-1.0, 1.0, -1.0));
335  VertexHandle v4 = mesh_.add_vertex(Vec3d(-1.0, -1.0, 1.0));
336  VertexHandle v5 = mesh_.add_vertex(Vec3d( 1.0, -1.0, 1.0));
337  VertexHandle v6 = mesh_.add_vertex(Vec3d( 1.0, 1.0, 1.0));
338  VertexHandle v7 = mesh_.add_vertex(Vec3d(-1.0, 1.0, 1.0));
339 
340  std::vector<VertexHandle> fvertices;
341 
342  fvertices.push_back(v3);
343  fvertices.push_back(v2);
344  fvertices.push_back(v1);
345  fvertices.push_back(v0);
346 
347  FaceHandle fh0 = mesh_.add_face(fvertices);
348 
349  fvertices.clear();
350 
351  fvertices.push_back(v4);
352  fvertices.push_back(v5);
353  fvertices.push_back(v6);
354  fvertices.push_back(v7);
355 
356  FaceHandle fh1 = mesh_.add_face(fvertices);
357 
358  fvertices.clear();
359 
360  fvertices.push_back(v0);
361  fvertices.push_back(v4);
362  fvertices.push_back(v7);
363  fvertices.push_back(v3);
364 
365  FaceHandle fh2 = mesh_.add_face(fvertices);
366 
367  fvertices.clear();
368 
369  fvertices.push_back(v1);
370  fvertices.push_back(v2);
371  fvertices.push_back(v6);
372  fvertices.push_back(v5);
373 
374  FaceHandle fh3 = mesh_.add_face(fvertices);
375 
376  fvertices.clear();
377 
378  fvertices.push_back(v7);
379  fvertices.push_back(v6);
380  fvertices.push_back(v2);
381  fvertices.push_back(v3);
382 
383  FaceHandle fh4 = mesh_.add_face(fvertices);
384 
385  fvertices.clear();
386 
387  fvertices.push_back(v0);
388  fvertices.push_back(v1);
389  fvertices.push_back(v5);
390  fvertices.push_back(v4);
391 
392  FaceHandle fh5 = mesh_.add_face(fvertices);
393 
394  std::vector<HalfFaceHandle> chfaces;
395 
396  chfaces.push_back(mesh_.halfface_handle(fh0, 0));
397  chfaces.push_back(mesh_.halfface_handle(fh1, 0));
398  chfaces.push_back(mesh_.halfface_handle(fh2, 0));
399  chfaces.push_back(mesh_.halfface_handle(fh3, 0));
400  chfaces.push_back(mesh_.halfface_handle(fh4, 0));
401  chfaces.push_back(mesh_.halfface_handle(fh5, 0));
402 
403  EXPECT_NE(HexahedralMesh::InvalidCellHandle, mesh_.add_cell(chfaces, true));
404 }
405 
406 TEST_F(HexahedralMeshBase, TopologyCheckFail) {
407 
408  VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, -1.0, -1.0));
409  VertexHandle v1 = mesh_.add_vertex(Vec3d( 1.0, -1.0, -1.0));
410  VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0, 1.0, -1.0));
411  VertexHandle v3 = mesh_.add_vertex(Vec3d(-1.0, 1.0, -1.0));
412  VertexHandle v4 = mesh_.add_vertex(Vec3d(-1.0, -1.0, 1.0));
413  VertexHandle v5 = mesh_.add_vertex(Vec3d( 1.0, -1.0, 1.0));
414  VertexHandle v6 = mesh_.add_vertex(Vec3d( 1.0, 1.0, 1.0));
415  VertexHandle v7 = mesh_.add_vertex(Vec3d(-1.0, 1.0, 1.0));
416 
417  std::vector<VertexHandle> fvertices;
418 
419  fvertices.push_back(v3);
420  fvertices.push_back(v2);
421  fvertices.push_back(v1);
422  fvertices.push_back(v0);
423 
424  FaceHandle fh0 = mesh_.add_face(fvertices);
425 
426  fvertices.clear();
427 
428  fvertices.push_back(v4);
429  fvertices.push_back(v5);
430  fvertices.push_back(v6);
431  fvertices.push_back(v7);
432 
433  FaceHandle fh1 = mesh_.add_face(fvertices);
434 
435  fvertices.clear();
436 
437  fvertices.push_back(v0);
438  fvertices.push_back(v4);
439  fvertices.push_back(v7);
440  fvertices.push_back(v3);
441 
442  FaceHandle fh2 = mesh_.add_face(fvertices);
443 
444  fvertices.clear();
445 
446  fvertices.push_back(v1);
447  fvertices.push_back(v2);
448  fvertices.push_back(v6);
449  fvertices.push_back(v5);
450 
451  FaceHandle fh3 = mesh_.add_face(fvertices);
452 
453  fvertices.clear();
454 
455  fvertices.push_back(v7);
456  fvertices.push_back(v6);
457  fvertices.push_back(v2);
458  fvertices.push_back(v3);
459 
460  FaceHandle fh4 = mesh_.add_face(fvertices);
461 
462  fvertices.clear();
463 
464  fvertices.push_back(v0);
465  fvertices.push_back(v1);
466  fvertices.push_back(v5);
467  fvertices.push_back(v4);
468 
469  FaceHandle fh5 = mesh_.add_face(fvertices);
470 
471  std::vector<HalfFaceHandle> chfaces;
472 
473  chfaces.push_back(mesh_.halfface_handle(fh0, 0));
474  chfaces.push_back(mesh_.halfface_handle(fh1, 1));
475  chfaces.push_back(mesh_.halfface_handle(fh2, 0));
476  chfaces.push_back(mesh_.halfface_handle(fh3, 0));
477  chfaces.push_back(mesh_.halfface_handle(fh4, 0));
478  chfaces.push_back(mesh_.halfface_handle(fh5, 0));
479 
480  EXPECT_EQ(HexahedralMesh::InvalidCellHandle, mesh_.add_cell(chfaces, true));
481 }
482 
483 TEST_F(PolyhedralMeshBase, VolumeMeshGenus) {
484 
485  generatePolyhedralMesh(mesh_);
486 
487  EXPECT_EQ(0, mesh_.genus());
488 }
489 
490 TEST_F(PolyhedralMeshBase, VolumeMeshConnectivity) {
491 
492  generatePolyhedralMesh(mesh_);
493 
494  // Add invalid cell
495  std::vector<HalfFaceHandle> hfaces;
496  hfaces.push_back(1); hfaces.push_back(5);
497  hfaces.push_back(7); hfaces.push_back(9);
498  hfaces.push_back(10); hfaces.push_back(21);
499  CellHandle i_cell = mesh_.add_cell(hfaces, true);
500 
501  EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, i_cell);
502 
503  EXPECT_EQ(CellHandle(0), mesh_.incident_cell(1));
504  EXPECT_EQ(CellHandle(0), mesh_.incident_cell(2));
505  EXPECT_EQ(CellHandle(0), mesh_.incident_cell(5));
506  EXPECT_EQ(CellHandle(0), mesh_.incident_cell(7));
507  EXPECT_EQ(CellHandle(0), mesh_.incident_cell(9));
508  EXPECT_EQ(CellHandle(0), mesh_.incident_cell(10));
509 
510  EXPECT_EQ(CellHandle(1), mesh_.incident_cell(3));
511  EXPECT_EQ(CellHandle(1), mesh_.incident_cell(12));
512  EXPECT_EQ(CellHandle(1), mesh_.incident_cell(15));
513  EXPECT_EQ(CellHandle(1), mesh_.incident_cell(17));
514  EXPECT_EQ(CellHandle(1), mesh_.incident_cell(19));
515  EXPECT_EQ(CellHandle(1), mesh_.incident_cell(20));
516 
517  // Test adjacency function
518  HalfFaceHandle ad_hf1 = mesh_.adjacent_halfface_in_cell(1, 3);
519  // Should be halfface 5
520  EXPECT_EQ(HalfFaceHandle(5), ad_hf1);
521 
522  HalfFaceHandle ad_hf2 = mesh_.adjacent_halfface_in_cell(1, 7);
523  // Should be halfface 7
524  EXPECT_EQ(HalfFaceHandle(7), ad_hf2);
525 
526  HalfFaceHandle ad_hf3 = mesh_.adjacent_halfface_in_cell(5, 24);
527  // Should be invalid
528  EXPECT_EQ(PolyhedralMesh::InvalidHalfFaceHandle, ad_hf3);
529 
530  HalfFaceHandle ad_hf4 = mesh_.adjacent_halfface_in_cell(12, 24);
531  // Should be invalid
532  EXPECT_EQ(HalfFaceHandle(20), ad_hf4);
533 
534  HalfFaceHandle ad_hf5 = mesh_.adjacent_halfface_in_cell(0, 0);
535  // Should be invalid
536  EXPECT_EQ(PolyhedralMesh::InvalidHalfFaceHandle, ad_hf5);
537 
538  EXPECT_EQ(12u, mesh_.n_vertices());
539  EXPECT_EQ(20u, mesh_.n_edges());
540  EXPECT_EQ(2u, mesh_.n_cells());
541  EXPECT_EQ(11u, mesh_.n_faces());
542 }
543 
544 TEST_F(PolyhedralMeshBase, VolumeMeshNormals) {
545 
546  generatePolyhedralMesh(mesh_);
547 
549 
550  Vec3d n_x(1.0, 0.0, 0.0);
551  Vec3d n_y(0.0, 1.0, 0.0);
552  Vec3d n_z(0.0, 0.0, 1.0);
553 
554  normals.update_face_normals();
555 
556  // Should be positive z-axis
557  Vec3d& n = normals[FaceHandle(0)];
558  EXPECT_DOUBLE_EQ(n_z[0], n[0]);
559  EXPECT_DOUBLE_EQ(n_z[1], n[1]);
560  EXPECT_DOUBLE_EQ(n_z[2], n[2]);
561 
562  n = normals[HalfFaceHandle(1)];
563  EXPECT_DOUBLE_EQ(-n_z[0], n[0]);
564  EXPECT_DOUBLE_EQ(-n_z[1], n[1]);
565  EXPECT_DOUBLE_EQ(-n_z[2], n[2]);
566 
567  // Should be negative x-axis
568  n = normals[FaceHandle(2)];
569  EXPECT_DOUBLE_EQ(-n_x[0], n[0]);
570  EXPECT_DOUBLE_EQ(-n_x[1], n[1]);
571  EXPECT_DOUBLE_EQ(-n_x[2], n[2]);
572 
573  n = normals[HalfFaceHandle(4)];
574  EXPECT_DOUBLE_EQ(-n_x[0], n[0]);
575  EXPECT_DOUBLE_EQ(-n_x[1], n[1]);
576  EXPECT_DOUBLE_EQ(-n_x[2], n[2]);
577 
578  n = normals[HalfFaceHandle(5)];
579  EXPECT_DOUBLE_EQ(n_x[0], n[0]);
580  EXPECT_DOUBLE_EQ(n_x[1], n[1]);
581  EXPECT_DOUBLE_EQ(n_x[2], n[2]);
582 
583  // Should be negative y-axis
584  n = normals[FaceHandle(4)];
585  EXPECT_DOUBLE_EQ(-n_y[0], n[0]);
586  EXPECT_DOUBLE_EQ(-n_y[1], n[1]);
587  EXPECT_DOUBLE_EQ(-n_y[2], n[2]);
588 
589  n = normals[HalfFaceHandle(9)];
590  EXPECT_DOUBLE_EQ(n_y[0], n[0]);
591  EXPECT_DOUBLE_EQ(n_y[1], n[1]);
592  EXPECT_DOUBLE_EQ(n_y[2], n[2]);
593 
594  // Should be positive y-axis
595  n = normals[FaceHandle(5)];
596  EXPECT_DOUBLE_EQ(-n_y[0], n[0]);
597  EXPECT_DOUBLE_EQ(-n_y[1], n[1]);
598  EXPECT_DOUBLE_EQ(-n_y[2], n[2]);
599 }
600 
601 TEST_F(PolyhedralMeshBase, PolyhedralMeshStatusTest) {
602 
603  generatePolyhedralMesh(mesh_);
604 
605  // Request status
606  StatusAttrib status(mesh_);
607 
608  // Select a few faces
609  status[FaceHandle(1)].set_tagged(true);
610  status[FaceHandle(4)].set_tagged(true);
611 
612  status[HalfFaceHandle(21)].set_deleted(true);
613  status[HalfFaceHandle(0)].set_deleted(true);
614 
615  status[VertexHandle(3)].set_selected(true);
616  status[VertexHandle(8)].set_selected(true);
617 
618  EXPECT_TRUE(status[FaceHandle(1)].tagged());
619  EXPECT_TRUE(status[FaceHandle(4)].tagged());
620  EXPECT_FALSE(status[FaceHandle(7)].tagged());
621  EXPECT_FALSE(status[FaceHandle(2)].tagged());
622 
623  EXPECT_TRUE(status[HalfFaceHandle(21)].deleted());
624  EXPECT_TRUE(status[HalfFaceHandle(0)].deleted());
625  EXPECT_FALSE(status[HalfFaceHandle(13)].deleted());
626  EXPECT_FALSE(status[HalfFaceHandle(20)].deleted());
627 
628  EXPECT_TRUE(status[VertexHandle(3)].selected());
629  EXPECT_TRUE(status[VertexHandle(8)].selected());
630  EXPECT_FALSE(status[VertexHandle(1)].selected());
631  EXPECT_FALSE(status[VertexHandle(9)].selected());
632 }
633 
634 TEST_F(PolyhedralMeshBase, PolyhedralMeshColorTest) {
635 
636  generatePolyhedralMesh(mesh_);
637 
639 
640  // Request colors
641  ColorAttrib<Vec4f> colors(mesh_);
642 
643  colors[VertexHandle(7)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
644  colors[EdgeHandle(6)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
645  colors[HalfEdgeHandle(5)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
646  colors[FaceHandle(4)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
647  colors[HalfFaceHandle(3)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
648  colors[CellHandle(1)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
649 
650  EXPECT_FLOAT_EQ(1.0f, colors[VertexHandle(7)][0]);
651  EXPECT_FLOAT_EQ(1.0f, colors[VertexHandle(7)][1]);
652  EXPECT_FLOAT_EQ(0.0f, colors[VertexHandle(7)][2]);
653  EXPECT_FLOAT_EQ(1.0f, colors[VertexHandle(7)][3]);
654  EXPECT_FLOAT_EQ(1.0f, colors[EdgeHandle(6)][0]);
655  EXPECT_FLOAT_EQ(1.0f, colors[EdgeHandle(6)][1]);
656  EXPECT_FLOAT_EQ(0.0f, colors[EdgeHandle(6)][2]);
657  EXPECT_FLOAT_EQ(1.0f, colors[EdgeHandle(6)][3]);
658  EXPECT_FLOAT_EQ(1.0f, colors[HalfEdgeHandle(5)][0]);
659  EXPECT_FLOAT_EQ(1.0f, colors[HalfEdgeHandle(5)][1]);
660  EXPECT_FLOAT_EQ(0.0f, colors[HalfEdgeHandle(5)][2]);
661  EXPECT_FLOAT_EQ(1.0f, colors[HalfEdgeHandle(5)][3]);
662  EXPECT_FLOAT_EQ(1.0f, colors[FaceHandle(4)][0]);
663  EXPECT_FLOAT_EQ(1.0f, colors[FaceHandle(4)][1]);
664  EXPECT_FLOAT_EQ(0.0f, colors[FaceHandle(4)][2]);
665  EXPECT_FLOAT_EQ(1.0f, colors[FaceHandle(4)][3]);
666  EXPECT_FLOAT_EQ(1.0f, colors[HalfFaceHandle(3)][0]);
667  EXPECT_FLOAT_EQ(1.0f, colors[HalfFaceHandle(3)][1]);
668  EXPECT_FLOAT_EQ(0.0f, colors[HalfFaceHandle(3)][2]);
669  EXPECT_FLOAT_EQ(1.0f, colors[HalfFaceHandle(3)][3]);
670  EXPECT_FLOAT_EQ(1.0f, colors[CellHandle(1)][0]);
671  EXPECT_FLOAT_EQ(1.0f, colors[CellHandle(1)][1]);
672  EXPECT_FLOAT_EQ(0.0f, colors[CellHandle(1)][2]);
673  EXPECT_FLOAT_EQ(1.0f, colors[CellHandle(1)][3]);
674 }
675 
676 TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {
677 
678  generatePolyhedralMesh(mesh_);
679 
680  VertexPropertyT<Vec3d> vp = mesh_.request_vertex_property<Vec3d>("VProp");
681 
682  EXPECT_TRUE(mesh_.vertex_property_exists<Vec3d>("VProp"));
683 
684  for(VertexIter v_it = mesh_.v_iter(); v_it.valid(); ++v_it) {
685  vp[v_it->idx()] = Vec3d(1.0, 0.0, 0.0);
686  }
687 
688  for(VertexIter v_it = mesh_.v_iter(); v_it.valid(); ++v_it) {
689  Vec3d t;
690  t = vp[v_it->idx()];
691  EXPECT_DOUBLE_EQ(1.0, t[0]);
692  EXPECT_DOUBLE_EQ(0.0, t[1]);
693  EXPECT_DOUBLE_EQ(0.0, t[2]);
694  }
695 
696  VertexHandle vh = mesh_.add_vertex(Vec3d(3.0,3.0,3.0));
697  vp[vh.idx()] = Vec3d(0.0);
698  Vec3d p = vp[vh.idx()];
699  EXPECT_DOUBLE_EQ(0.0, p[0]);
700  EXPECT_DOUBLE_EQ(0.0, p[1]);
701  EXPECT_DOUBLE_EQ(0.0, p[2]);
702 
703  EdgePropertyT<unsigned int> ep = mesh_.request_edge_property<unsigned int>("EProp");
704 
705  EXPECT_TRUE(mesh_.edge_property_exists<unsigned int>("EProp"));
706 
707  unsigned int i = 0;
708  for(EdgeIter e_it = mesh_.e_iter(); e_it.valid(); ++e_it) {
709  ep[e_it->idx()] = i++;
710  }
711 
712  i = 0;
713  for(EdgeIter e_it = mesh_.e_iter(); e_it.valid(); ++e_it) {
714  EXPECT_EQ(i++, ep[e_it->idx()]);
715  }
716 
717  HalfFacePropertyT<bool> hfp = mesh_.request_halfface_property<bool>("HFProp");
718 
719  EXPECT_TRUE(mesh_.halfface_property_exists<bool>("HFProp"));
720 
721  bool b = false;
722  for(HalfFaceIter hf_it = mesh_.hf_iter(); hf_it.valid(); ++hf_it) {
723  hfp[hf_it->idx()] = b;
724  b = !b;
725  }
726 
727  b = false;
728  for(HalfFaceIter hf_it = mesh_.hf_iter(); hf_it.valid(); ++hf_it) {
729  EXPECT_EQ(b, hfp[hf_it->idx()]);
730  b = !b;
731  }
732 
733  // Request halfface properties
734  CellPropertyT<std::string> cp = mesh_.request_cell_property<std::string>("CProp");
735 
736  EXPECT_TRUE(mesh_.cell_property_exists<std::string>("CProp"));
737 
738  for(CellIter c_it = mesh_.c_iter(); c_it.valid(); ++c_it) {
739  cp[c_it->idx()] = std::string("MyTestString");
740  }
741 
742  for(CellIter c_it = mesh_.c_iter(); c_it.valid(); ++c_it) {
743  EXPECT_EQ(std::string("MyTestString"), cp[c_it->idx()]);
744  }
745 
746  EXPECT_FALSE(mesh_.halfedge_property_exists<unsigned char>("HEProp"));
747  EXPECT_FALSE(mesh_.vertex_property_exists<size_t>(""));
748 }
749 
750 TEST_F(PolyhedralMeshBase, STLCompliance) {
751 
752  generatePolyhedralMesh(mesh_);
753 
754  Print p;
755  p.mute(true);
756  //std::cerr << "Vertices:" << std::endl;
757  std::for_each(mesh_.vertices_begin(), mesh_.vertices_end(), p);
758  //std::cerr << "Edges:" << std::endl;
759  std::for_each(mesh_.edges_begin(), mesh_.edges_end(), p);
760  //std::cerr << "HalfEdges:" << std::endl;
761  std::for_each(mesh_.halfedges_begin(), mesh_.halfedges_end(), p);
762  //std::cerr << "Faces:" << std::endl;
763  std::for_each(mesh_.faces_begin(), mesh_.faces_end(), p);
764  //std::cerr << "HalfFaces:" << std::endl;
765  std::for_each(mesh_.halffaces_begin(), mesh_.halffaces_end(), p);
766  //std::cerr << "Cells:" << std::endl;
767  std::for_each(mesh_.cells_begin(), mesh_.cells_end(), p);
768 }
769 
770 TEST_F(PolyhedralMeshBase, DeleteCellBUTest1) {
771 
772  generatePolyhedralMesh(mesh_);
773 
774  std::vector<HalfFaceHandle> hfs = mesh_.cell(CellHandle(0)).halffaces();
775 
776  mesh_.delete_cell(CellHandle(0));
777 
778  for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
779  hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
780  EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, mesh_.incident_cell(*hf_it));
781  }
782 }
783 
784 TEST_F(PolyhedralMeshBase, DeleteFaceBUTest1) {
785 
786  generatePolyhedralMesh(mesh_);
787 
788  std::vector<HalfEdgeHandle> hes = mesh_.face(FaceHandle(0)).halfedges();
789 
790  std::vector<HalfFaceHandle> ihfs[4];
791 
792  for(size_t i = 0; i < 4; ++i) {
793  for(HalfEdgeHalfFaceIter hehf_it = mesh_.hehf_iter(hes[i]); hehf_it.valid(); ++hehf_it) {
794 
795  HalfFaceHandle hfh = *hehf_it;
796 
797  if(mesh_.face_handle(hfh) == FaceHandle(0)) continue;
798 
799  hfh.idx((hfh.idx() > mesh_.halfface_handle(FaceHandle(0), 1) ? hfh.idx() - 2 : hfh.idx()));
800 
801  ihfs[i].push_back(hfh);
802  }
803  }
804 
805  mesh_.delete_face(FaceHandle(0));
806 
807  std::set<HalfFaceHandle> nihfs[4];
808  for(size_t i = 0; i < 4; ++i) {
809  for(HalfEdgeHalfFaceIter hehf_it = mesh_.hehf_iter(hes[i]); hehf_it.valid(); ++hehf_it) {
810  nihfs[i].insert(*hehf_it);
811  }
812  }
813 
814  EXPECT_EQ(ihfs[0].size(), nihfs[0].size());
815  EXPECT_EQ(ihfs[1].size(), nihfs[1].size());
816  EXPECT_EQ(ihfs[2].size(), nihfs[2].size());
817  EXPECT_EQ(ihfs[3].size(), nihfs[3].size());
818 
819  for(size_t i = 0; i < 4; ++i) {
820  for(std::vector<HalfFaceHandle>::const_iterator hf_it = ihfs[i].begin(),
821  hf_end = ihfs[i].end(); hf_it != hf_end; ++hf_it) {
822  EXPECT_GT(nihfs[i].count(*hf_it), 0u);
823  }
824  }
825 }
826 
827 TEST_F(PolyhedralMeshBase, DeleteEdgeBUTest1) {
828 
829  generatePolyhedralMesh(mesh_);
830 
831  VertexHandle vh0 = mesh_.edge(EdgeHandle(0)).from_vertex();
832  VertexHandle vh1 = mesh_.edge(EdgeHandle(0)).to_vertex();
833 
834  std::vector<HalfEdgeHandle> hes0;
835  for(VertexOHalfEdgeIter voh_it = mesh_.voh_iter(vh0); voh_it.valid(); ++voh_it) {
836  if(mesh_.edge_handle(*voh_it) == EdgeHandle(0)) continue;
837  hes0.push_back(HalfEdgeHandle(voh_it->idx() > mesh_.halfedge_handle(EdgeHandle(0), 1) ? voh_it->idx() - 2 : voh_it->idx()));
838  }
839 
840  std::vector<HalfEdgeHandle> hes1;
841  for(VertexOHalfEdgeIter voh_it = mesh_.voh_iter(vh1); voh_it.valid(); ++voh_it) {
842  if(mesh_.edge_handle(*voh_it) == EdgeHandle(0)) continue;
843  hes1.push_back(HalfEdgeHandle(voh_it->idx() > mesh_.halfedge_handle(EdgeHandle(0), 1) ? voh_it->idx() - 2 : voh_it->idx()));
844  }
845 
846  mesh_.delete_edge(EdgeHandle(0));
847 
848  std::set<HalfEdgeHandle> nhes0;
849  for(VertexOHalfEdgeIter voh_it = mesh_.voh_iter(vh0); voh_it.valid(); ++voh_it) {
850  nhes0.insert(*voh_it);
851  }
852 
853  std::set<HalfEdgeHandle> nhes1;
854  for(VertexOHalfEdgeIter voh_it = mesh_.voh_iter(vh1); voh_it.valid(); ++voh_it) {
855  nhes1.insert(*voh_it);
856  }
857 
858  EXPECT_EQ(hes0.size(), nhes0.size());
859  EXPECT_EQ(hes1.size(), nhes1.size());
860 
861  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes0.begin(),
862  he_end = hes0.end(); he_it != he_end; ++he_it) {
863  EXPECT_GT(nhes0.count(*he_it), 0u);
864  }
865 
866  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes1.begin(),
867  he_end = hes1.end(); he_it != he_end; ++he_it) {
868  EXPECT_GT(nhes1.count(*he_it), 0u);
869  }
870 }
871 
872 TEST_F(PolyhedralMeshBase, DeleteCellBUTest1noBU) {
873 
874  generatePolyhedralMesh(mesh_);
875 
876  mesh_.enable_bottom_up_incidences(false);
877 
878  std::vector<HalfFaceHandle> hfs = mesh_.cell(CellHandle(0)).halffaces();
879 
880  mesh_.delete_cell(CellHandle(0));
881 
882  for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
883  hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
884  EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, mesh_.incident_cell(*hf_it));
885  }
886 }
887 
888 TEST_F(PolyhedralMeshBase, DeleteFaceBUTest1noBU) {
889 
890  generatePolyhedralMesh(mesh_);
891 
892  mesh_.enable_bottom_up_incidences(false);
893 
894  std::vector<HalfEdgeHandle> hes = mesh_.face(FaceHandle(0)).halfedges();
895 
896  std::vector<HalfFaceHandle> ihfs[4];
897 
898  for(size_t i = 0; i < 4; ++i) {
899  for(HalfFaceIter hf_it = mesh_.halffaces_begin(), hf_end = mesh_.halffaces_end(); hf_it != hf_end; ++hf_it) {
900 
901  std::vector<HalfEdgeHandle> t_hes = mesh_.halfface(*hf_it).halfedges();
902  bool found = false;
903  for(std::vector<HalfEdgeHandle>::const_iterator the_it = t_hes.begin(),
904  the_end = t_hes.end(); the_it != the_end; ++the_it) {
905  if(std::find(hes.begin(), hes.end(), *the_it) != hes.end()) {
906  found = true;
907  break;
908  }
909  }
910  if(!found) continue;
911 
912  HalfFaceHandle hfh = *hf_it;
913 
914  if(mesh_.face_handle(hfh) == FaceHandle(0)) continue;
915 
916  hfh.idx((hfh.idx() > mesh_.halfface_handle(FaceHandle(0), 1) ? hfh.idx() - 2 : hfh.idx()));
917 
918  ihfs[i].push_back(hfh);
919  }
920  }
921 
922  mesh_.delete_face(FaceHandle(0));
923 
924  std::set<HalfFaceHandle> nihfs[4];
925  for(size_t i = 0; i < 4; ++i) {
926  for(HalfFaceIter hf_it = mesh_.halffaces_begin(), hf_end = mesh_.halffaces_end(); hf_it != hf_end; ++hf_it) {
927 
928  std::vector<HalfEdgeHandle> t_hes = mesh_.halfface(*hf_it).halfedges();
929  bool found = false;
930  for(std::vector<HalfEdgeHandle>::const_iterator the_it = t_hes.begin(),
931  the_end = t_hes.end(); the_it != the_end; ++the_it) {
932  if(std::find(hes.begin(), hes.end(), *the_it) != hes.end()) {
933  found = true;
934  break;
935  }
936  }
937  if(!found) continue;
938 
939  nihfs[i].insert(*hf_it);
940  }
941  }
942 
943  EXPECT_EQ(ihfs[0].size(), nihfs[0].size());
944  EXPECT_EQ(ihfs[1].size(), nihfs[1].size());
945  EXPECT_EQ(ihfs[2].size(), nihfs[2].size());
946  EXPECT_EQ(ihfs[3].size(), nihfs[3].size());
947 
948  for(size_t i = 0; i < 4; ++i) {
949  for(std::vector<HalfFaceHandle>::const_iterator hf_it = ihfs[i].begin(),
950  hf_end = ihfs[i].end(); hf_it != hf_end; ++hf_it) {
951  EXPECT_GT(nihfs[i].count(*hf_it), 0u);
952  }
953  }
954 }
955 
956 TEST_F(PolyhedralMeshBase, DeleteEdgeBUTest1noBU) {
957 
958  generatePolyhedralMesh(mesh_);
959 
960  mesh_.enable_bottom_up_incidences(false);
961 
962  VertexHandle vh0 = mesh_.edge(EdgeHandle(0)).from_vertex();
963  VertexHandle vh1 = mesh_.edge(EdgeHandle(0)).to_vertex();
964 
965  std::vector<HalfEdgeHandle> hes0;
966  for(HalfEdgeIter he_it = mesh_.halfedges_begin(), he_end = mesh_.halfedges_end(); he_it != he_end; ++he_it) {
967 
968  if(mesh_.halfedge(*he_it).from_vertex() == vh0) {
969 
970  if(mesh_.edge_handle(*he_it) == EdgeHandle(0)) continue;
971  hes0.push_back(HalfEdgeHandle(he_it->idx() > mesh_.halfedge_handle(EdgeHandle(0), 1) ? he_it->idx() - 2 : he_it->idx()));
972  }
973  }
974 
975  std::vector<HalfEdgeHandle> hes1;
976  for(HalfEdgeIter he_it = mesh_.halfedges_begin(), he_end = mesh_.halfedges_end(); he_it != he_end; ++he_it) {
977 
978  if(mesh_.halfedge(*he_it).from_vertex() == vh1) {
979 
980  if(mesh_.edge_handle(*he_it) == EdgeHandle(0)) continue;
981  hes1.push_back(HalfEdgeHandle(he_it->idx() > mesh_.halfedge_handle(EdgeHandle(0), 1) ? he_it->idx() - 2 : he_it->idx()));
982  }
983  }
984 
985  mesh_.delete_edge(EdgeHandle(0));
986 
987  std::set<HalfEdgeHandle> nhes0;
988  for(HalfEdgeIter he_it = mesh_.halfedges_begin(), he_end = mesh_.halfedges_end(); he_it != he_end; ++he_it) {
989  if(mesh_.halfedge(*he_it).from_vertex() == vh0) {
990  nhes0.insert(*he_it);
991  }
992  }
993 
994  std::set<HalfEdgeHandle> nhes1;
995  for(HalfEdgeIter he_it = mesh_.halfedges_begin(), he_end = mesh_.halfedges_end(); he_it != he_end; ++he_it) {
996  if(mesh_.halfedge(*he_it).from_vertex() == vh1) {
997  nhes1.insert(*he_it);
998  }
999  }
1000 
1001  EXPECT_EQ(hes0.size(), nhes0.size());
1002  EXPECT_EQ(hes1.size(), nhes1.size());
1003 
1004  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes0.begin(),
1005  he_end = hes0.end(); he_it != he_end; ++he_it) {
1006  EXPECT_GT(nhes0.count(*he_it), 0u);
1007  }
1008 
1009  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes1.begin(),
1010  he_end = hes1.end(); he_it != he_end; ++he_it) {
1011  EXPECT_GT(nhes1.count(*he_it), 0u);
1012  }
1013 }
1014 
1015 TEST_F(PolyhedralMeshBase, DeleteLastVertexTestBU) {
1016 
1017  generatePolyhedralMesh(mesh_);
1018 
1019  for(OpenVolumeMesh::HalfEdgeIter he_it = mesh_.halfedges_begin();
1020  he_it != mesh_.halfedges_end(); ++he_it) {
1021 
1022  const VertexHandle& fromVertex = mesh_.halfedge(*he_it).from_vertex();
1023  const VertexHandle& toVertex = mesh_.halfedge(*he_it).to_vertex();
1024 
1025  EXPECT_LE(fromVertex.idx(), 11);
1026  EXPECT_LE(toVertex.idx(), 11);
1027  }
1028 
1029  mesh_.delete_vertex(VertexHandle(11));
1030 
1031  for(OpenVolumeMesh::HalfEdgeIter he_it = mesh_.halfedges_begin();
1032  he_it != mesh_.halfedges_end(); ++he_it) {
1033 
1034  const VertexHandle& fromVertex = mesh_.halfedge(*he_it).from_vertex();
1035  const VertexHandle& toVertex = mesh_.halfedge(*he_it).to_vertex();
1036 
1037  EXPECT_LE(fromVertex.idx(), 10);
1038  EXPECT_LE(toVertex.idx(), 10);
1039  }
1040 }
1041 
1042 TEST_F(PolyhedralMeshBase, DeleteLastEdgeTestBU) {
1043 
1044  generatePolyhedralMesh(mesh_);
1045 
1046  for(OpenVolumeMesh::HalfFaceIter f_it = mesh_.halffaces_begin();
1047  f_it != mesh_.halffaces_end(); ++f_it) {
1048 
1049  std::vector<HalfEdgeHandle> hes = mesh_.halfface(*f_it).halfedges();
1050  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin();
1051  he_it != hes.end(); ++he_it) {
1052  EXPECT_LE(he_it->idx(), 39);
1053  }
1054  }
1055 
1056  mesh_.delete_edge(EdgeHandle(19));
1057 
1058  for(OpenVolumeMesh::HalfFaceIter f_it = mesh_.halffaces_begin();
1059  f_it != mesh_.halffaces_end(); ++f_it) {
1060 
1061  std::vector<HalfEdgeHandle> hes = mesh_.halfface(*f_it).halfedges();
1062  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin();
1063  he_it != hes.end(); ++he_it) {
1064  EXPECT_LE(he_it->idx(), 37);
1065  }
1066  }
1067 }
1068 
1069 TEST_F(PolyhedralMeshBase, DeleteLastFaceTestBU) {
1070 
1071  generatePolyhedralMesh(mesh_);
1072 
1073  for(OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
1074  c_it != mesh_.cells_end(); ++c_it) {
1075 
1076  std::vector<HalfFaceHandle> hfs = mesh_.cell(*c_it).halffaces();
1077  for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin();
1078  hf_it != hfs.end(); ++hf_it) {
1079  EXPECT_LE(hf_it->idx(), 21);
1080  EXPECT_LE(mesh_.opposite_halfface_handle(*hf_it).idx(), 21);
1081  }
1082  }
1083 
1084  mesh_.delete_face(FaceHandle(10));
1085 
1086  for(OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
1087  c_it != mesh_.cells_end(); ++c_it) {
1088 
1089  std::vector<HalfFaceHandle> hfs = mesh_.cell(*c_it).halffaces();
1090  for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin();
1091  hf_it != hfs.end(); ++hf_it) {
1092  EXPECT_LE(hf_it->idx(), 19);
1093  EXPECT_LE(mesh_.opposite_halfface_handle(*hf_it).idx(), 19);
1094  }
1095  }
1096 }
1097 
1098 TEST_F(PolyhedralMeshBase, DeleteLastVertexTestNoBU) {
1099 
1100  generatePolyhedralMesh(mesh_);
1101 
1102  mesh_.enable_bottom_up_incidences(false);
1103 
1104  for(OpenVolumeMesh::HalfEdgeIter he_it = mesh_.halfedges_begin();
1105  he_it != mesh_.halfedges_end(); ++he_it) {
1106 
1107  const VertexHandle& fromVertex = mesh_.halfedge(*he_it).from_vertex();
1108  const VertexHandle& toVertex = mesh_.halfedge(*he_it).to_vertex();
1109 
1110  EXPECT_LE(fromVertex.idx(), 11);
1111  EXPECT_LE(toVertex.idx(), 11);
1112  }
1113 
1114  mesh_.delete_vertex(VertexHandle(11));
1115 
1116  for(OpenVolumeMesh::HalfEdgeIter he_it = mesh_.halfedges_begin();
1117  he_it != mesh_.halfedges_end(); ++he_it) {
1118 
1119  const VertexHandle& fromVertex = mesh_.halfedge(*he_it).from_vertex();
1120  const VertexHandle& toVertex = mesh_.halfedge(*he_it).to_vertex();
1121 
1122  EXPECT_LE(fromVertex.idx(), 10);
1123  EXPECT_LE(toVertex.idx(), 10);
1124  }
1125 }
1126 
1127 TEST_F(PolyhedralMeshBase, DeleteLastEdgeTestNoBU) {
1128 
1129  generatePolyhedralMesh(mesh_);
1130 
1131  mesh_.enable_bottom_up_incidences(false);
1132 
1133  for(OpenVolumeMesh::HalfFaceIter f_it = mesh_.halffaces_begin();
1134  f_it != mesh_.halffaces_end(); ++f_it) {
1135 
1136  std::vector<HalfEdgeHandle> hes = mesh_.halfface(*f_it).halfedges();
1137  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin();
1138  he_it != hes.end(); ++he_it) {
1139  EXPECT_LE(he_it->idx(), 39);
1140  }
1141  }
1142 
1143  mesh_.delete_edge(EdgeHandle(19));
1144 
1145  for(OpenVolumeMesh::HalfFaceIter f_it = mesh_.halffaces_begin();
1146  f_it != mesh_.halffaces_end(); ++f_it) {
1147 
1148  std::vector<HalfEdgeHandle> hes = mesh_.halfface(*f_it).halfedges();
1149  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin();
1150  he_it != hes.end(); ++he_it) {
1151  EXPECT_LE(he_it->idx(), 37);
1152  }
1153  }
1154 }
1155 
1156 TEST_F(PolyhedralMeshBase, DeleteLastFaceTestNoBU) {
1157 
1158  generatePolyhedralMesh(mesh_);
1159 
1160  mesh_.enable_bottom_up_incidences(false);
1161 
1162  for(OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
1163  c_it != mesh_.cells_end(); ++c_it) {
1164 
1165  std::vector<HalfFaceHandle> hfs = mesh_.cell(*c_it).halffaces();
1166  for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin();
1167  hf_it != hfs.end(); ++hf_it) {
1168  EXPECT_LE(hf_it->idx(), 21);
1169  EXPECT_LE(mesh_.opposite_halfface_handle(*hf_it).idx(), 21);
1170  }
1171  }
1172 
1173  mesh_.delete_face(FaceHandle(10));
1174 
1175  for(OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
1176  c_it != mesh_.cells_end(); ++c_it) {
1177 
1178  std::vector<HalfFaceHandle> hfs = mesh_.cell(*c_it).halffaces();
1179  for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin();
1180  hf_it != hfs.end(); ++hf_it) {
1181  EXPECT_LE(hf_it->idx(), 19);
1182  EXPECT_LE(mesh_.opposite_halfface_handle(*hf_it).idx(), 19);
1183  }
1184  }
1185 }
1186 
1187 /*
1188  * Hexahedral mesh tests
1189  */
1190 
1191 TEST_F(HexahedralMeshBase, SimpleHexMeshNavigation) {
1192 
1193  generateHexahedralMesh(mesh_);
1194 
1195  EXPECT_EQ(12u, mesh_.n_vertices());
1196  EXPECT_EQ(20u, mesh_.n_edges());
1197  EXPECT_EQ(11u, mesh_.n_faces());
1198  EXPECT_EQ(2u, mesh_.n_cells());
1199 
1200  EXPECT_EQ(1, mesh_.xfront_halfface(CellHandle(0)));
1201  EXPECT_EQ(2, mesh_.xback_halfface(CellHandle(0)));
1202  EXPECT_EQ(5, mesh_.yfront_halfface(CellHandle(0)));
1203  EXPECT_EQ(6, mesh_.yback_halfface(CellHandle(0)));
1204  EXPECT_EQ(8, mesh_.zfront_halfface(CellHandle(0)));
1205  EXPECT_EQ(11, mesh_.zback_halfface(CellHandle(0)));
1206 
1207  EXPECT_EQ(12, mesh_.opposite_halfface_handle_in_cell(
1208  HalfFaceHandle(3), CellHandle(1)));
1209 
1210  EXPECT_EQ(HalfFaceHandle(20), mesh_.adjacent_halfface_on_sheet(
1211  HalfFaceHandle(9), HalfEdgeHandle(12)));
1212  EXPECT_EQ(HalfFaceHandle(21), mesh_.adjacent_halfface_on_sheet(
1213  HalfFaceHandle(8), HalfEdgeHandle(12)));
1214 
1215  HexahedralMesh::CellSheetCellIter csc_it = mesh_.csc_iter(0, HexahedralMesh::YF);
1216  EXPECT_EQ(CellHandle(1), *csc_it);
1217 
1218  HexahedralMesh::HalfFaceSheetHalfFaceIter hfshf_it = mesh_.hfshf_iter(5);
1219  EXPECT_EQ(HalfFaceHandle(15), *hfshf_it);
1220  hfshf_it = mesh_.hfshf_iter(6);
1221  EXPECT_EQ(HalfFaceHandle(16), *hfshf_it);
1222 }
1223 
1224 TEST_F(HexahedralMeshBase, BottomUpIncidenceUpdate1) {
1225 
1226  generateHexahedralMesh(mesh_);
1227 
1228  EXPECT_EQ(12u, mesh_.n_vertices());
1229  EXPECT_EQ(20u, mesh_.n_edges());
1230  EXPECT_EQ(11u, mesh_.n_faces());
1231  EXPECT_EQ(2u, mesh_.n_cells());
1232 
1233  mesh_.delete_vertex(VertexHandle(0));
1234 
1235  EXPECT_EQ(11u, mesh_.n_vertices());
1236  EXPECT_EQ(17u, mesh_.n_edges());
1237  EXPECT_EQ(8u, mesh_.n_faces());
1238  EXPECT_EQ(1u, mesh_.n_cells());
1239 
1240  HexVertexIter hv_it = mesh_.hv_iter(CellHandle(0));
1241 
1242  EXPECT_EQ(3, hv_it->idx()); ++hv_it;
1243  EXPECT_EQ(4, hv_it->idx()); ++hv_it;
1244  EXPECT_EQ(5, hv_it->idx()); ++hv_it;
1245  EXPECT_EQ(6, hv_it->idx()); ++hv_it;
1246  EXPECT_EQ(7, hv_it->idx()); ++hv_it;
1247  EXPECT_EQ(10, hv_it->idx()); ++hv_it;
1248  EXPECT_EQ(9, hv_it->idx()); ++hv_it;
1249  EXPECT_EQ(8, hv_it->idx());
1250 }
1251 
1252 TEST_F(HexahedralMeshBase, GarbageCollectionTest1) {
1253 
1254  generateHexahedralMesh(mesh_);
1255 
1256  EXPECT_EQ(12u, mesh_.n_vertices());
1257  EXPECT_EQ(20u, mesh_.n_edges());
1258  EXPECT_EQ(11u, mesh_.n_faces());
1259  EXPECT_EQ(2u, mesh_.n_cells());
1260 
1261  StatusAttrib status(mesh_);
1262 
1263  HexVertexIter hv_it = mesh_.hv_iter(CellHandle(1));
1264 
1265  EXPECT_EQ(4, hv_it->idx()); ++hv_it;
1266  EXPECT_EQ(5, hv_it->idx()); ++hv_it;
1267  EXPECT_EQ(6, hv_it->idx()); ++hv_it;
1268  EXPECT_EQ(7, hv_it->idx()); ++hv_it;
1269  EXPECT_EQ(8, hv_it->idx()); ++hv_it;
1270  EXPECT_EQ(11, hv_it->idx()); ++hv_it;
1271  EXPECT_EQ(10, hv_it->idx()); ++hv_it;
1272  EXPECT_EQ(9, hv_it->idx());
1273 
1274  status[VertexHandle(0)].set_deleted(true);
1275 
1276  status.garbage_collection(false);
1277 
1278  EXPECT_EQ(1u, mesh_.n_cells());
1279  EXPECT_EQ(11u, mesh_.n_vertices());
1280  EXPECT_EQ(17u, mesh_.n_edges());
1281  EXPECT_EQ(8u, mesh_.n_faces());
1282 
1283  hv_it = mesh_.hv_iter(CellHandle(0));
1284 
1285  EXPECT_EQ(3, hv_it->idx()); ++hv_it;
1286  EXPECT_EQ(4, hv_it->idx()); ++hv_it;
1287  EXPECT_EQ(5, hv_it->idx()); ++hv_it;
1288  EXPECT_EQ(6, hv_it->idx()); ++hv_it;
1289  EXPECT_EQ(7, hv_it->idx()); ++hv_it;
1290  EXPECT_EQ(10, hv_it->idx()); ++hv_it;
1291  EXPECT_EQ(9, hv_it->idx()); ++hv_it;
1292  EXPECT_EQ(8, hv_it->idx());
1293 
1294  status.garbage_collection(true);
1295 
1296  EXPECT_EQ(1u, mesh_.n_cells());
1297  EXPECT_EQ(8u, mesh_.n_vertices());
1298  EXPECT_EQ(12u, mesh_.n_edges());
1299  EXPECT_EQ(6u, mesh_.n_faces());
1300 
1301  hv_it = mesh_.hv_iter(CellHandle(0));
1302 
1303  EXPECT_EQ(0, hv_it->idx()); ++hv_it;
1304  EXPECT_EQ(1, hv_it->idx()); ++hv_it;
1305  EXPECT_EQ(2, hv_it->idx()); ++hv_it;
1306  EXPECT_EQ(3, hv_it->idx()); ++hv_it;
1307  EXPECT_EQ(4, hv_it->idx()); ++hv_it;
1308  EXPECT_EQ(7, hv_it->idx()); ++hv_it;
1309  EXPECT_EQ(6, hv_it->idx()); ++hv_it;
1310  EXPECT_EQ(5, hv_it->idx());
1311 }
1312 
1313 TEST_F(HexahedralMeshBase, GarbageCollectionTest2) {
1314 
1315  generateHexahedralMesh(mesh_);
1316 
1317  StatusAttrib status(mesh_);
1318 
1319  status[VertexHandle(0)].set_deleted(true);
1320 
1321  status.garbage_collection(false);
1322 
1323  status.garbage_collection(false);
1324 
1325  EXPECT_EQ(1u, mesh_.n_cells());
1326  EXPECT_EQ(11u, mesh_.n_vertices());
1327  EXPECT_EQ(17u, mesh_.n_edges());
1328  EXPECT_EQ(8u, mesh_.n_faces());
1329 }
1330 
1331 TEST_F(HexahedralMeshBase, GarbageCollectionTest3) {
1332 
1333  generateHexahedralMesh(mesh_);
1334 
1335  StatusAttrib status(mesh_);
1336 
1337  status[EdgeHandle(0)].set_deleted(true);
1338 
1339  status.garbage_collection(false);
1340 
1341  EXPECT_EQ(1u, mesh_.n_cells());
1342  EXPECT_EQ(12u, mesh_.n_vertices());
1343  EXPECT_EQ(19u, mesh_.n_edges());
1344  EXPECT_EQ(9u, mesh_.n_faces());
1345 }
1346 
1347 TEST_F(HexahedralMeshBase, GarbageCollectionTest4) {
1348 
1349  generateHexahedralMesh(mesh_);
1350 
1351  StatusAttrib status(mesh_);
1352 
1353  status[EdgeHandle(5)].set_deleted(true);
1354 
1355  status.garbage_collection(false);
1356 
1357  EXPECT_EQ(0u, mesh_.n_cells());
1358  EXPECT_EQ(12u, mesh_.n_vertices());
1359  EXPECT_EQ(19u, mesh_.n_edges());
1360  EXPECT_EQ(8u, mesh_.n_faces());
1361 }
1362 
1363 TEST_F(HexahedralMeshBase, GarbageCollectionTest5) {
1364 
1365  generateHexahedralMesh(mesh_);
1366 
1367  StatusAttrib status(mesh_);
1368 
1369  status[EdgeHandle(0)].set_deleted(true);
1370  status[EdgeHandle(1)].set_deleted(true);
1371  status[EdgeHandle(2)].set_deleted(true);
1372 
1373  status.garbage_collection(true);
1374 
1375  EXPECT_EQ(1u, mesh_.n_cells());
1376  EXPECT_EQ(8u, mesh_.n_vertices());
1377  EXPECT_EQ(12u, mesh_.n_edges());
1378  EXPECT_EQ(6u, mesh_.n_faces());
1379 }
1380 
1381 TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness1) {
1382 
1383  generateHexahedralMesh(mesh_);
1384 
1385  StatusAttrib status(mesh_);
1386 
1387  status[VertexHandle(0)].set_deleted(true);
1388 
1389  status.garbage_collection(true);
1390 
1391  EXPECT_EQ(1u, mesh_.n_cells());
1392  EXPECT_EQ(6u, mesh_.n_faces());
1393  EXPECT_EQ(12u, mesh_.n_edges());
1394  EXPECT_EQ(8u, mesh_.n_vertices());
1395 }
1396 
1397 TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness2) {
1398 
1399  generateHexahedralMesh(mesh_);
1400 
1401  StatusAttrib status(mesh_);
1402 
1403  status[EdgeHandle(0)].set_deleted(true);
1404 
1405  status.garbage_collection(true);
1406 
1407  EXPECT_EQ(1u, mesh_.n_cells());
1408  EXPECT_EQ(6u, mesh_.n_faces());
1409  EXPECT_EQ(12u, mesh_.n_edges());
1410  EXPECT_EQ(8u, mesh_.n_vertices());
1411 }
1412 
1413 TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness3) {
1414 
1415  generateHexahedralMesh(mesh_);
1416 
1417  StatusAttrib status(mesh_);
1418 
1419  status[FaceHandle(0)].set_deleted(true);
1420 
1421  status.garbage_collection(true);
1422 
1423  EXPECT_EQ(1u, mesh_.n_cells());
1424  EXPECT_EQ(6u, mesh_.n_faces());
1425  EXPECT_EQ(12u, mesh_.n_edges());
1426  EXPECT_EQ(8u, mesh_.n_vertices());
1427 }
1428 
1429 TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness4) {
1430 
1431  generateHexahedralMesh(mesh_);
1432 
1433  StatusAttrib status(mesh_);
1434 
1435  status[CellHandle(0)].set_deleted(true);
1436 
1437  status.garbage_collection(true);
1438 
1439  EXPECT_EQ(1u, mesh_.n_cells());
1440  EXPECT_EQ(6u, mesh_.n_faces());
1441  EXPECT_EQ(12u, mesh_.n_edges());
1442  EXPECT_EQ(8u, mesh_.n_vertices());
1443 }
1444 
1445 TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness5) {
1446 
1447  generateHexahedralMesh(mesh_);
1448 
1449  StatusAttrib status(mesh_);
1450 
1451  status[EdgeHandle(5)].set_deleted(true);
1452 
1453  status.garbage_collection(false);
1454 
1455  EXPECT_EQ(0u, mesh_.n_cells());
1456  EXPECT_EQ(8u, mesh_.n_faces());
1457  EXPECT_EQ(19u, mesh_.n_edges());
1458  EXPECT_EQ(12u, mesh_.n_vertices());
1459 
1460  status.garbage_collection(true);
1461 
1462  EXPECT_EQ(0u, mesh_.n_cells());
1463  EXPECT_EQ(0u, mesh_.n_faces());
1464  EXPECT_EQ(0u, mesh_.n_edges());
1465  EXPECT_EQ(0u, mesh_.n_vertices());
1466 }
1467 
1468 TEST_F(HexahedralMeshBase, GarbageCollectionTestTrackVertexHandles) {
1469 
1470  generateHexahedralMesh(mesh_);
1471 
1472  EXPECT_EQ(12u, mesh_.n_vertices());
1473  EXPECT_EQ(20u, mesh_.n_edges());
1474  EXPECT_EQ(11u, mesh_.n_faces());
1475  EXPECT_EQ(2u, mesh_.n_cells());
1476 
1477  StatusAttrib status(mesh_);
1478 
1479  status[VertexHandle(0)].set_deleted(true);
1480 
1481  std::vector<VertexHandle> vhs;
1482  std::vector<VertexHandle*> track_vhs;
1483  std::vector<HalfEdgeHandle*> hh_empty;
1484  std::vector<HalfFaceHandle*> hfh_empty;
1485  std::vector<CellHandle*> ch_empty;
1486 
1487  OpenVolumeMesh::VertexIter v_it = mesh_.vertices_begin();
1488  for (; v_it != mesh_.vertices_end(); ++v_it)
1489  vhs.push_back(*v_it);
1490 
1491  for (std::vector<VertexHandle>::iterator it = vhs.begin(); it != vhs.end(); ++it)
1492  track_vhs.push_back(&(*it));
1493 
1494  status.garbage_collection(track_vhs, hh_empty, hfh_empty, ch_empty, false);
1495 
1496  EXPECT_EQ(vhs[0], -1);
1497  EXPECT_EQ(vhs[11], 10);
1498 
1499  EXPECT_EQ(1u, mesh_.n_cells());
1500  EXPECT_EQ(11u, mesh_.n_vertices());
1501  EXPECT_EQ(17u, mesh_.n_edges());
1502  EXPECT_EQ(8u, mesh_.n_faces());
1503 }
1504 
1505 TEST_F(HexahedralMeshBase, GarbageCollectionTestTrackHalfedgeHandles) {
1506 
1507  generateHexahedralMesh(mesh_);
1508 
1509  StatusAttrib status(mesh_);
1510 
1511  status[EdgeHandle(5)].set_deleted(true);
1512 
1513  std::vector<HalfEdgeHandle> hhs;
1514  std::vector<VertexHandle*> vh_empty;
1515  std::vector<HalfEdgeHandle*> track_hh;
1516  std::vector<HalfFaceHandle*> hfh_empty;
1517  std::vector<CellHandle*> ch_empty;
1518 
1519  OpenVolumeMesh::HalfEdgeIter hh_it = mesh_.halfedges_begin();
1520  for (; hh_it != mesh_.halfedges_end(); ++hh_it)
1521  hhs.push_back(*hh_it);
1522 
1523  for (std::vector<HalfEdgeHandle>::iterator it = hhs.begin(); it != hhs.end(); ++it)
1524  track_hh.push_back(&(*it));
1525 
1526  status.garbage_collection(vh_empty, track_hh, hfh_empty, ch_empty, false);
1527 
1528  EXPECT_EQ(hhs[9], 9);
1529  EXPECT_EQ(hhs[10], -1);
1530  EXPECT_EQ(hhs[11], -1);
1531  EXPECT_EQ(hhs[12], 10);
1532  EXPECT_EQ(hhs[39], 37);
1533 
1534  EXPECT_EQ(0u, mesh_.n_cells());
1535  EXPECT_EQ(8u, mesh_.n_faces());
1536  EXPECT_EQ(19u, mesh_.n_edges());
1537  EXPECT_EQ(12u, mesh_.n_vertices());
1538 
1539  status.garbage_collection(vh_empty, track_hh, hfh_empty, ch_empty, true);
1540 
1541  for (std::vector<HalfEdgeHandle>::iterator it = hhs.begin(); it != hhs.end(); ++it)
1542  EXPECT_EQ(it->idx(), -1);
1543 
1544  EXPECT_EQ(0u, mesh_.n_cells());
1545  EXPECT_EQ(0u, mesh_.n_faces());
1546  EXPECT_EQ(0u, mesh_.n_edges());
1547  EXPECT_EQ(0u, mesh_.n_vertices());
1548 }
1549 
1550 TEST_F(HexahedralMeshBase, GarbageCollectionTestTrackHalffaceHandles) {
1551 
1552  generateHexahedralMesh(mesh_);
1553 
1554  StatusAttrib status(mesh_);
1555 
1556  status[FaceHandle(0)].set_deleted(true);
1557 
1558  std::vector<HalfFaceHandle> hfhs;
1559  std::vector<VertexHandle*> vh_empty;
1560  std::vector<HalfEdgeHandle*> hh_empty;
1561  std::vector<HalfFaceHandle*> track_hfh;
1562  std::vector<CellHandle*> ch_empty;
1563 
1564  OpenVolumeMesh::HalfFaceIter hfh_it = mesh_.halffaces_begin();
1565  for (; hfh_it != mesh_.halffaces_end(); ++hfh_it)
1566  hfhs.push_back(*hfh_it);
1567 
1568  for (std::vector<HalfFaceHandle>::iterator it = hfhs.begin(); it != hfhs.end(); ++it)
1569  track_hfh.push_back(&(*it));
1570 
1571  status.garbage_collection(vh_empty, hh_empty, track_hfh, ch_empty, true);
1572 
1573  EXPECT_EQ(hfhs[0], -1);
1574  EXPECT_EQ(hfhs[1], -1);
1575  EXPECT_EQ(hfhs[2], 0);
1576  EXPECT_EQ(hfhs[3], 1);
1577  EXPECT_EQ(hfhs[21], 11);
1578 
1579 
1580  EXPECT_EQ(1u, mesh_.n_cells());
1581  EXPECT_EQ(6u, mesh_.n_faces());
1582  EXPECT_EQ(12u, mesh_.n_edges());
1583  EXPECT_EQ(8u, mesh_.n_vertices());
1584 }
1585 
1586 TEST_F(HexahedralMeshBase, GarbageCollectionTestTrackCellHandles) {
1587 
1588  generateHexahedralMesh(mesh_);
1589 
1590  StatusAttrib status(mesh_);
1591 
1592  status[CellHandle(0)].set_deleted(true);
1593 
1594  std::vector<CellHandle> chs;
1595  std::vector<VertexHandle*> vh_empty;
1596  std::vector<HalfEdgeHandle*> hh_empty;
1597  std::vector<HalfFaceHandle*> hfh_empty;
1598  std::vector<CellHandle*> track_ch;
1599 
1600  OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
1601  for (; c_it != mesh_.cells_end(); ++c_it)
1602  chs.push_back(*c_it);
1603 
1604  for (std::vector<CellHandle>::iterator it = chs.begin(); it != chs.end(); ++it)
1605  track_ch.push_back(&(*it));
1606 
1607  status.garbage_collection(vh_empty, hh_empty, hfh_empty, track_ch, true);
1608 
1609  EXPECT_EQ(chs[0], -1);
1610  EXPECT_EQ(chs[1], 0);
1611 
1612  EXPECT_EQ(1u, mesh_.n_cells());
1613  EXPECT_EQ(6u, mesh_.n_faces());
1614  EXPECT_EQ(12u, mesh_.n_edges());
1615  EXPECT_EQ(8u, mesh_.n_vertices());
1616 }
1617 
1618 TEST_F(HexahedralMeshBase, GarbageCollectionTestProps1) {
1619 
1620  generateHexahedralMesh(mesh_);
1621 
1622  StatusAttrib status(mesh_);
1623 
1624  FacePropertyT<int> fprop = mesh_.request_face_property<int>("FProp");
1625 
1626  FaceHandle fh0(0);
1627  FaceHandle fh1(1);
1628  FaceHandle fh2(2);
1629  FaceHandle fh3(3);
1630  FaceHandle fh4(4);
1631  FaceHandle fh5(5);
1632  FaceHandle fh6(6);
1633  FaceHandle fh7(7);
1634  FaceHandle fh8(8);
1635  FaceHandle fh9(9);
1636  FaceHandle fh10(10);
1637 
1638  fprop[fh0] = 11;
1639  fprop[fh1] = 10;
1640  fprop[fh2] = 9;
1641  fprop[fh3] = 8;
1642  fprop[fh4] = 7;
1643  fprop[fh5] = 6;
1644  fprop[fh6] = 5;
1645  fprop[fh7] = 4;
1646  fprop[fh8] = 3;
1647  fprop[fh9] = 2;
1648  fprop[fh10] = 1;
1649 
1650  status[VertexHandle(0)].set_deleted(true);
1651 
1652  status.garbage_collection(false);
1653 
1654  EXPECT_EQ(1u, mesh_.n_cells());
1655  EXPECT_EQ(11u, mesh_.n_vertices());
1656  EXPECT_EQ(17u, mesh_.n_edges());
1657  EXPECT_EQ(8u, mesh_.n_faces());
1658 
1659  std::set<int> fprops_i;
1660  for(FaceIter f_it = mesh_.f_iter(); f_it.valid(); ++f_it) {
1661  fprops_i.insert(fprop[f_it->idx()]);
1662  }
1663 
1664  EXPECT_EQ(0u, fprops_i.count(11));
1665  EXPECT_EQ(1u, fprops_i.count(10));
1666  EXPECT_EQ(1u, fprops_i.count(9));
1667  EXPECT_EQ(0u, fprops_i.count(8));
1668  EXPECT_EQ(0u, fprops_i.count(7));
1669  EXPECT_EQ(1u, fprops_i.count(6));
1670  EXPECT_EQ(1u, fprops_i.count(5));
1671  EXPECT_EQ(1u, fprops_i.count(4));
1672  EXPECT_EQ(1u, fprops_i.count(3));
1673  EXPECT_EQ(1u, fprops_i.count(2));
1674  EXPECT_EQ(1u, fprops_i.count(1));
1675 }
1676 
1677 TEST_F(HexahedralMeshBase, GarbageCollectionTestProps2) {
1678 
1679  generateHexahedralMesh(mesh_);
1680 
1681  StatusAttrib status(mesh_);
1682 
1683  FacePropertyT<int> fprop = mesh_.request_face_property<int>("FProp");
1684 
1685  FaceHandle fh0(0);
1686  FaceHandle fh1(1);
1687  FaceHandle fh2(2);
1688  FaceHandle fh3(3);
1689  FaceHandle fh4(4);
1690  FaceHandle fh5(5);
1691  FaceHandle fh6(6);
1692  FaceHandle fh7(7);
1693  FaceHandle fh8(8);
1694  FaceHandle fh9(9);
1695  FaceHandle fh10(10);
1696 
1697  fprop[fh0] = 11;
1698  fprop[fh1] = 10;
1699  fprop[fh2] = 9;
1700  fprop[fh3] = 8;
1701  fprop[fh4] = 7;
1702  fprop[fh5] = 6;
1703  fprop[fh6] = 5;
1704  fprop[fh7] = 4;
1705  fprop[fh8] = 3;
1706  fprop[fh9] = 2;
1707  fprop[fh10] = 1;
1708 
1709  status[FaceHandle(0)].set_deleted(true);
1710 
1711  status.garbage_collection(false);
1712 
1713  EXPECT_EQ(1u, mesh_.n_cells());
1714  EXPECT_EQ(12u, mesh_.n_vertices());
1715  EXPECT_EQ(20u, mesh_.n_edges());
1716  EXPECT_EQ(10u, mesh_.n_faces());
1717 
1718  std::set<int> fprops_i;
1719  for(FaceIter f_it = mesh_.f_iter(); f_it.valid(); ++f_it) {
1720  fprops_i.insert(fprop[f_it->idx()]);
1721  }
1722 
1723  EXPECT_EQ(0u, fprops_i.count(11));
1724  EXPECT_EQ(1u, fprops_i.count(10));
1725  EXPECT_EQ(1u, fprops_i.count(9));
1726  EXPECT_EQ(1u, fprops_i.count(8));
1727  EXPECT_EQ(1u, fprops_i.count(7));
1728  EXPECT_EQ(1u, fprops_i.count(6));
1729  EXPECT_EQ(1u, fprops_i.count(5));
1730  EXPECT_EQ(1u, fprops_i.count(4));
1731  EXPECT_EQ(1u, fprops_i.count(3));
1732  EXPECT_EQ(1u, fprops_i.count(2));
1733  EXPECT_EQ(1u, fprops_i.count(1));
1734 }
1735 
1736 TEST_F(HexahedralMeshBase, HalfEdgeFetchFunction1) {
1737 
1738  generateHexahedralMesh(mesh_);
1739 
1740  VertexHandle v0(0);
1741  VertexHandle v1(1);
1742 
1743  VertexHandle v2(2);
1744  VertexHandle v3(3);
1745 
1746  VertexHandle v5(5);
1747  VertexHandle v6(6);
1748  VertexHandle v7(7);
1749 
1750  HalfEdgeHandle he0 = mesh_.halfedge(v0, v1);
1751  HalfEdgeHandle he5 = mesh_.halfedge(v3, v2);
1752  HalfEdgeHandle he10 = mesh_.halfedge(v5, v6);
1753  HalfEdgeHandle heInv = mesh_.halfedge(v5, v7);
1754 
1755  EXPECT_EQ(HalfEdgeHandle(0), he0);
1756  EXPECT_EQ(HalfEdgeHandle(5), he5);
1757  EXPECT_EQ(HalfEdgeHandle(10), he10);
1758  EXPECT_EQ(HexahedralMesh::InvalidHalfEdgeHandle, heInv);
1759 }
1760 
1761 TEST_F(HexahedralMeshBase, HalfFaceFetchFunction1) {
1762 
1763  generateHexahedralMesh(mesh_);
1764 
1765  HalfEdgeHandle he0(0);
1766  HalfEdgeHandle he2(2);
1767  HalfEdgeHandle he4(4);
1768 
1769  std::vector<HalfEdgeHandle> hes;
1770  hes.push_back(he0); hes.push_back(he2);
1771 
1772  HalfFaceHandle hf0_0 = mesh_.halfface(hes);
1773  hes.clear();
1774  hes.push_back(he0); hes.push_back(he4);
1775  HalfFaceHandle hf0_1 = mesh_.halfface(hes);
1776 
1777  HalfEdgeHandle he16(16);
1778  HalfEdgeHandle he18(18);
1779 
1780  hes.clear();
1781  hes.push_back(he16); hes.push_back(he18);
1782  HalfFaceHandle hf4_0 = mesh_.halfface(hes);
1783 
1784  hes.clear();
1785  hes.push_back(he0); hes.push_back(he18);
1786  HalfFaceHandle hfInv = mesh_.halfface(hes);
1787 
1788  HalfEdgeHandle he17(17);
1789  HalfEdgeHandle he19(19);
1790 
1791  hes.clear();
1792  hes.push_back(he17); hes.push_back(he19);
1793  HalfFaceHandle hf5_0 = mesh_.halfface(hes);
1794 
1795  EXPECT_EQ(HalfFaceHandle(0), hf0_0);
1796  EXPECT_EQ(HalfFaceHandle(0), hf0_1);
1797  EXPECT_EQ(HalfFaceHandle(4), hf4_0);
1798  EXPECT_EQ(HalfFaceHandle(5), hf5_0);
1799  EXPECT_EQ(HexahedralMesh::InvalidHalfFaceHandle, hfInv);
1800 }
1801 
1802 TEST_F(HexahedralMeshBase, HalfFaceFetchFunction2) {
1803 
1804  generateHexahedralMesh(mesh_);
1805 
1806  VertexHandle v0(0);
1807  VertexHandle v1(1);
1808  VertexHandle v2(2);
1809  VertexHandle v3(3);
1810  VertexHandle v4(4);
1811  VertexHandle v5(5);
1812  VertexHandle v6(6);
1813  VertexHandle v7(7);
1814 
1815  std::vector<VertexHandle> vs;
1816  vs.push_back(v0); vs.push_back(v1); vs.push_back(v2);
1817  HalfFaceHandle hf0 = mesh_.halfface(vs); vs.clear();
1818 
1819  vs.push_back(v2); vs.push_back(v1); vs.push_back(v0);
1820  HalfFaceHandle hf1 = mesh_.halfface(vs); vs.clear();
1821 
1822  vs.push_back(v2); vs.push_back(v1); vs.push_back(v5);
1823  HalfFaceHandle hf4 = mesh_.halfface(vs); vs.clear();
1824 
1825  vs.push_back(v6); vs.push_back(v5); vs.push_back(v4);
1826  HalfFaceHandle hf3 = mesh_.halfface(vs); vs.clear();
1827 
1828  vs.push_back(v4); vs.push_back(v5); vs.push_back(v6);
1829  HalfFaceHandle hf2 = mesh_.halfface(vs); vs.clear();
1830 
1831  vs.push_back(v0); vs.push_back(v1); vs.push_back(v4);
1832  HalfFaceHandle hfInv0 = mesh_.halfface(vs); vs.clear();
1833 
1834  vs.push_back(v0); vs.push_back(v1); vs.push_back(v6);
1835  HalfFaceHandle hfInv1 = mesh_.halfface(vs); vs.clear();
1836 
1837  EXPECT_EQ(HalfFaceHandle(0), hf0);
1838  EXPECT_EQ(HalfFaceHandle(1), hf1);
1839  EXPECT_EQ(HalfFaceHandle(4), hf4);
1840  EXPECT_EQ(HalfFaceHandle(3), hf3);
1841  EXPECT_EQ(HalfFaceHandle(2), hf2);
1842  EXPECT_EQ(HexahedralMesh::InvalidHalfFaceHandle, hfInv0);
1843  EXPECT_EQ(HexahedralMesh::InvalidHalfFaceHandle, hfInv1);
1844 }
1845 
1846 TEST_F(HexahedralMeshBase, AddCellViaVerticesFunction1) {
1847 
1848  generateHexahedralMesh(mesh_);
1849 
1850  StatusAttrib status(mesh_);
1851 
1852  status[FaceHandle(0)].set_deleted(true);
1853 
1854  status.garbage_collection(false);
1855 
1856  EXPECT_EQ(1u, mesh_.n_cells());
1857  EXPECT_EQ(10u, mesh_.n_faces());
1858  EXPECT_EQ(20u, mesh_.n_edges());
1859  EXPECT_EQ(12u, mesh_.n_vertices());
1860 
1861  std::vector<VertexHandle> vs;
1862  vs.push_back(VertexHandle(0));
1863  vs.push_back(VertexHandle(1));
1864  vs.push_back(VertexHandle(2));
1865  vs.push_back(VertexHandle(3));
1866  vs.push_back(VertexHandle(4));
1867  vs.push_back(VertexHandle(7));
1868  vs.push_back(VertexHandle(6));
1869  vs.push_back(VertexHandle(5));
1870 
1871  CellHandle ch = mesh_.add_cell(vs);
1872 
1873  EXPECT_NE(HexahedralMesh::InvalidCellHandle, ch);
1874 
1875  EXPECT_EQ(2u, mesh_.n_cells());
1876  EXPECT_EQ(11u, mesh_.n_faces());
1877  EXPECT_EQ(20u, mesh_.n_edges());
1878  EXPECT_EQ(12u, mesh_.n_vertices());
1879 }
1880 
1881 TEST_F(HexahedralMeshBase, AddCellViaVerticesFunction2) {
1882 
1883  generateHexahedralMesh(mesh_);
1884 
1885  StatusAttrib status(mesh_);
1886 
1887  status[FaceHandle(0)].set_deleted(true);
1888 
1889  status.garbage_collection(true);
1890 
1891  EXPECT_EQ(1u, mesh_.n_cells());
1892  EXPECT_EQ(6u, mesh_.n_faces());
1893  EXPECT_EQ(12u, mesh_.n_edges());
1894  EXPECT_EQ(8u, mesh_.n_vertices());
1895 
1896  VertexHandle v0 = mesh_.add_vertex(Vec3d(0.0, 0.0, 0.0));
1897  VertexHandle v1 = mesh_.add_vertex(Vec3d(1.0, 0.0, 0.0));
1898  VertexHandle v2 = mesh_.add_vertex(Vec3d(1.0, 1.0, 0.0));
1899  VertexHandle v3 = mesh_.add_vertex(Vec3d(0.0, 1.0, 0.0));
1900 
1901  std::vector<VertexHandle> vs;
1902  vs.push_back(v0);
1903  vs.push_back(v1);
1904  vs.push_back(v2);
1905  vs.push_back(v3);
1906  vs.push_back(VertexHandle(0));
1907  vs.push_back(VertexHandle(3));
1908  vs.push_back(VertexHandle(2));
1909  vs.push_back(VertexHandle(1));
1910 
1911  CellHandle ch = mesh_.add_cell(vs);
1912 
1913  EXPECT_NE(HexahedralMesh::InvalidCellHandle, ch);
1914 
1915  EXPECT_EQ(2u, mesh_.n_cells());
1916  EXPECT_EQ(11u, mesh_.n_faces());
1917  EXPECT_EQ(20u, mesh_.n_edges());
1918  EXPECT_EQ(12u, mesh_.n_vertices());
1919 }
1920 
1921 //===========================================================================
1922 
1923 TEST_F(PolyhedralMeshBase, SwapVertices) {
1924 
1925  generatePolyhedralMesh(mesh_);
1926 
1927  Vec3d p1(0.0, 0.0, 0.0);
1928  Vec3d p2(1.0, 0.0, 0.0);
1929  Vec3d p3(1.0, 1.0, 0.0);
1930  Vec3d p4(0.0, 1.0, 0.0);
1931 
1932  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(0))[0], p1[0]);
1933  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(0))[1], p1[1]);
1934  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(0))[2], p1[2]);
1935 
1936  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(1))[0], p2[0]);
1937  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(1))[1], p2[1]);
1938  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(1))[2], p2[2]);
1939 
1940  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(2))[0], p3[0]);
1941  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(2))[1], p3[1]);
1942  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(2))[2], p3[2]);
1943 
1944  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(3))[0], p4[0]);
1945  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(3))[1], p4[1]);
1946  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(3))[2], p4[2]);
1947 
1948  EXPECT_EQ(12u, mesh_.n_vertices());
1949 
1950  Vec3d p1n(1.0, 1.0, 1.0);
1951  Vec3d p2n(0.0, 1.0, 2.0);
1952  Vec3d p3n(0.0, 0.0, 3.0);
1953  Vec3d p4n(1.0, 0.0, 4.0);
1954 
1955  /*
1956  * Old coordinates
1957  */
1958  Vec3d p5(0.0, 0.0, 1.0);
1959  Vec3d p6(1.0, 0.0, 1.0);
1960  Vec3d p7(1.0, 1.0, 1.0);
1961  Vec3d p8(0.0, 1.0, 1.0);
1962 
1963  Vec3d p9(0.0, 0.0, 2.0);
1964  Vec3d p10(1.0, 0.0, 2.0);
1965  Vec3d p11(1.0, 1.0, 2.0);
1966  Vec3d p12(0.0, 1.0, 2.0);
1967 
1968  std::vector<Vec3d> new_vertices;
1969 
1970  new_vertices.push_back(p1n);
1971  new_vertices.push_back(p2n);
1972  new_vertices.push_back(p3n);
1973  new_vertices.push_back(p4n);
1974 
1975  new_vertices.push_back(p5);
1976  new_vertices.push_back(p6);
1977  new_vertices.push_back(p7);
1978  new_vertices.push_back(p8);
1979  new_vertices.push_back(p9);
1980  new_vertices.push_back(p10);
1981  new_vertices.push_back(p11);
1982  new_vertices.push_back(p12);
1983 
1984  mesh_.swap_vertices(new_vertices);
1985 
1986  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(0))[0], p1n[0]);
1987  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(0))[1], p1n[1]);
1988  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(0))[2], p1n[2]);
1989 
1990  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(1))[0], p2n[0]);
1991  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(1))[1], p2n[1]);
1992  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(1))[2], p2n[2]);
1993 
1994  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(2))[0], p3n[0]);
1995  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(2))[1], p3n[1]);
1996  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(2))[2], p3n[2]);
1997 
1998  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(3))[0], p4n[0]);
1999  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(3))[1], p4n[1]);
2000  EXPECT_DOUBLE_EQ(mesh_.vertex(VertexHandle(3))[2], p4n[2]);
2001 
2002  EXPECT_EQ(12u, mesh_.n_vertices());
2003 }
2004 
2005 void testDeferredDelete(PolyhedralMesh &mesh) {
2006  mesh.add_vertex(Vec3d(1,0,0));
2007  mesh.add_vertex(Vec3d(0,1,0));
2008  mesh.delete_vertex(VertexHandle(0));
2009  mesh.collect_garbage();
2010  EXPECT_DOUBLE_EQ(mesh.vertex(VertexHandle(0))[1], 1);
2011 }
2012 
2013 TEST_F(PolyhedralMeshBase, DeferredDelete) {
2014  mesh_.enable_deferred_deletion(true);
2015  mesh_.enable_fast_deletion(false);
2016  testDeferredDelete(mesh_);
2017 }
2018 TEST_F(PolyhedralMeshBase, DeferredFastDelete) {
2019  mesh_.enable_deferred_deletion(true);
2020  mesh_.enable_fast_deletion(true);
2021  testDeferredDelete(mesh_);
2022 }
2023 
const VecT & vertex(const VertexHandle &_vh) const
Get point _vh&#39;s coordinates.
Property classes for the different entity types.
Iterate over all vertices of a hexahedron in a specific order.
virtual VertexHandle add_vertex()
Override of empty add_vertex function.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236