unittests_basics.cc 60.3 KB
Newer Older
1
2
3
4
5
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>

#include <OpenVolumeMesh/Attribs/StatusAttrib.hh>
#include <OpenVolumeMesh/Attribs/NormalAttrib.hh>
6
#include <OpenVolumeMesh/Attribs/ColorAttrib.hh>
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

using namespace OpenVolumeMesh;

/*
 * ====================================================================
 * Define tests below
 * ====================================================================
 */

TEST_F(PolyhedralMeshBase, CreateSimpleMesh) {

  /*
   * Add vertices
   */

  VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, -1.0, -1.0));
  VertexHandle v1 = mesh_.add_vertex(Vec3d( 1.0, -1.0, -1.0));
  VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0,  1.0, -1.0));
  VertexHandle v3 = mesh_.add_vertex(Vec3d(-1.0,  1.0, -1.0));
  VertexHandle v4 = mesh_.add_vertex(Vec3d(-1.0, -1.0,  1.0));
  VertexHandle v5 = mesh_.add_vertex(Vec3d( 1.0, -1.0,  1.0));
  VertexHandle v6 = mesh_.add_vertex(Vec3d( 1.0,  1.0,  1.0));
  VertexHandle v7 = mesh_.add_vertex(Vec3d(-1.0,  1.0,  1.0));

  EXPECT_EQ(8u, mesh_.n_vertices()) << "The number of vertices is not correct!";

  /*
   * Add faces
   */

  std::vector<VertexHandle> fvertices;

  fvertices.push_back(v3);
  fvertices.push_back(v2);
  fvertices.push_back(v1);
  fvertices.push_back(v0);

  FaceHandle fh0 = mesh_.add_face(fvertices);

  fvertices.clear();

  fvertices.push_back(v4);
  fvertices.push_back(v5);
  fvertices.push_back(v6);
  fvertices.push_back(v7);

  FaceHandle fh1 = mesh_.add_face(fvertices);

  fvertices.clear();

  fvertices.push_back(v0);
  fvertices.push_back(v4);
  fvertices.push_back(v7);
  fvertices.push_back(v3);

  FaceHandle fh2 = mesh_.add_face(fvertices);

  fvertices.clear();

  fvertices.push_back(v1);
  fvertices.push_back(v2);
  fvertices.push_back(v6);
  fvertices.push_back(v5);

  FaceHandle fh3 = mesh_.add_face(fvertices);

  fvertices.clear();

  fvertices.push_back(v7);
  fvertices.push_back(v6);
  fvertices.push_back(v2);
  fvertices.push_back(v3);

  FaceHandle fh4 = mesh_.add_face(fvertices);

  fvertices.clear();

  fvertices.push_back(v0);
  fvertices.push_back(v1);
  fvertices.push_back(v5);
  fvertices.push_back(v4);

  FaceHandle fh5 = mesh_.add_face(fvertices);

  EXPECT_EQ(12u, mesh_.n_edges()) << "The number of edges is not correct!";
  EXPECT_EQ(6u, mesh_.n_faces())  << "The number of faces is not correct!";

  /*
   * Add cell
   */

  std::vector<HalfFaceHandle> chfaces;

  chfaces.push_back(mesh_.halfface_handle(fh0, 0));
  chfaces.push_back(mesh_.halfface_handle(fh1, 0));
  chfaces.push_back(mesh_.halfface_handle(fh2, 0));
  chfaces.push_back(mesh_.halfface_handle(fh3, 0));
  chfaces.push_back(mesh_.halfface_handle(fh4, 0));
  chfaces.push_back(mesh_.halfface_handle(fh5, 0));

  mesh_.add_cell(chfaces);

  EXPECT_EQ(1u, mesh_.n_cells())  << "The number of cells is not correct!";
}

//===========================================================================

TEST_F(PolyhedralMeshBase, CreateSimpleMeshWithoutCells) {

    Vec3d p1(0.0, 0.0, 0.0);
    Vec3d p2(1.0, 0.0, 0.0);
    Vec3d p3(1.0, 1.0, 0.0);
    Vec3d p4(0.0, 1.0, 0.0);

    Vec3d p5(0.0, 0.0, 1.0);
    Vec3d p6(1.0, 0.0, 1.0);
    Vec3d p7(1.0, 1.0, 1.0);
    Vec3d p8(0.0, 1.0, 1.0);

    VertexHandle v1 = mesh_.add_vertex(p1);
    VertexHandle v2 = mesh_.add_vertex(p2);
    VertexHandle v3 = mesh_.add_vertex(p3);
    VertexHandle v4 = mesh_.add_vertex(p4);

    VertexHandle v5 = mesh_.add_vertex(p5);
    VertexHandle v6 = mesh_.add_vertex(p6);
    VertexHandle v7 = mesh_.add_vertex(p7);
    VertexHandle v8 = mesh_.add_vertex(p8);

    EXPECT_EQ(0, v1);
    EXPECT_EQ(1, v2);
    EXPECT_EQ(2, v3);
    EXPECT_EQ(3, v4);
    EXPECT_EQ(4, v5);
    EXPECT_EQ(5, v6);
    EXPECT_EQ(6, v7);
    EXPECT_EQ(7, v8);

    EdgeHandle e1 = mesh_.add_edge(v1, v2);
    EdgeHandle e2 = mesh_.add_edge(v2, v3);
    EdgeHandle e3 = mesh_.add_edge(v3, v4);
    EdgeHandle e4 = mesh_.add_edge(v4, v1);

    EdgeHandle e5 = mesh_.add_edge(v5, v6);
    EdgeHandle e6 = mesh_.add_edge(v6, v7);
    EdgeHandle e7 = mesh_.add_edge(v7, v8);
    EdgeHandle e8 = mesh_.add_edge(v8, v5);

    EXPECT_EQ(0, e1);
    EXPECT_EQ(1, e2);
    EXPECT_EQ(2, e3);
    EXPECT_EQ(3, e4);
    EXPECT_EQ(4, e5);
    EXPECT_EQ(5, e6);
    EXPECT_EQ(6, e7);
    EXPECT_EQ(7, e8);

    // Get halfedges
    HalfEdgeHandle h1 = mesh_.halfedge_handle(e1, 0u);
    HalfEdgeHandle h2 = mesh_.halfedge_handle(e2, 0u);
    HalfEdgeHandle h3 = mesh_.halfedge_handle(e3, 0u);
    HalfEdgeHandle h4 = mesh_.halfedge_handle(e4, 0u);

    HalfEdgeHandle h5 = mesh_.halfedge_handle(e5, 0u);
    HalfEdgeHandle h6 = mesh_.halfedge_handle(e6, 0u);
    HalfEdgeHandle h7 = mesh_.halfedge_handle(e7, 0u);
    HalfEdgeHandle h8 = mesh_.halfedge_handle(e8, 0u);

    EXPECT_EQ(v1, mesh_.halfedge(h1).from_vertex());
    EXPECT_EQ(v2, mesh_.halfedge(h1).to_vertex());
    EXPECT_EQ(v2, mesh_.halfedge(h2).from_vertex());
    EXPECT_EQ(v3, mesh_.halfedge(h2).to_vertex());
    EXPECT_EQ(v3, mesh_.halfedge(h3).from_vertex());
    EXPECT_EQ(v4, mesh_.halfedge(h3).to_vertex());
    EXPECT_EQ(v4, mesh_.halfedge(h4).from_vertex());
    EXPECT_EQ(v1, mesh_.halfedge(h4).to_vertex());

    EXPECT_EQ(v5, mesh_.halfedge(h5).from_vertex());
    EXPECT_EQ(v6, mesh_.halfedge(h5).to_vertex());
    EXPECT_EQ(v6, mesh_.halfedge(h6).from_vertex());
    EXPECT_EQ(v7, mesh_.halfedge(h6).to_vertex());
    EXPECT_EQ(v7, mesh_.halfedge(h7).from_vertex());
    EXPECT_EQ(v8, mesh_.halfedge(h7).to_vertex());
    EXPECT_EQ(v8, mesh_.halfedge(h8).from_vertex());
    EXPECT_EQ(v5, mesh_.halfedge(h8).to_vertex());

    // Check opposite halfedges
    EXPECT_EQ(v2, mesh_.opposite_halfedge(h1).from_vertex());
    EXPECT_EQ(v1, mesh_.opposite_halfedge(h1).to_vertex());
    EXPECT_EQ(v3, mesh_.opposite_halfedge(h2).from_vertex());
    EXPECT_EQ(v2, mesh_.opposite_halfedge(h2).to_vertex());
    EXPECT_EQ(v4, mesh_.opposite_halfedge(h3).from_vertex());
    EXPECT_EQ(v3, mesh_.opposite_halfedge(h3).to_vertex());
    EXPECT_EQ(v1, mesh_.opposite_halfedge(h4).from_vertex());
    EXPECT_EQ(v4, mesh_.opposite_halfedge(h4).to_vertex());

    EXPECT_EQ(v6, mesh_.opposite_halfedge(h5).from_vertex());
    EXPECT_EQ(v5, mesh_.opposite_halfedge(h5).to_vertex());
    EXPECT_EQ(v7, mesh_.opposite_halfedge(h6).from_vertex());
    EXPECT_EQ(v6, mesh_.opposite_halfedge(h6).to_vertex());
    EXPECT_EQ(v8, mesh_.opposite_halfedge(h7).from_vertex());
    EXPECT_EQ(v7, mesh_.opposite_halfedge(h7).to_vertex());
    EXPECT_EQ(v5, mesh_.opposite_halfedge(h8).from_vertex());
    EXPECT_EQ(v8, mesh_.opposite_halfedge(h8).to_vertex());

    // Add a face via vertices
    std::vector<VertexHandle> vertices;
    vertices.push_back(v2); vertices.push_back(v6);
    vertices.push_back(v7); vertices.push_back(v3);
    FaceHandle f1 = mesh_.add_face(vertices);

    EXPECT_EQ(0, f1);

    // Get halfedges of face
    std::vector<HalfEdgeHandle> halfedges = mesh_.face(f1).halfedges();

    std::vector<HalfEdgeHandle>::iterator it = halfedges.begin();

    EXPECT_EQ(8, mesh_.edge_handle(*it)); ++it;
    EXPECT_EQ(5, mesh_.edge_handle(*it)); ++it;
    EXPECT_EQ(9, mesh_.edge_handle(*it)); ++it;
    EXPECT_EQ(1, mesh_.edge_handle(*it));

    // Add invalid face
    halfedges.clear();
    halfedges.push_back(mesh_.halfedge_handle(e1, 0)); halfedges.push_back(mesh_.halfedge_handle(e2, 0));
    halfedges.push_back(mesh_.halfedge_handle(e7, 0)); halfedges.push_back(mesh_.halfedge_handle(e4, 0));

235
    FaceHandle fI = mesh_.add_face(halfedges, true);
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

    EXPECT_EQ(PolyhedralMesh::InvalidFaceHandle, fI);

    // Now add valid face via edges
    halfedges.clear();
    halfedges.push_back(mesh_.halfedge_handle(e1, 0)); halfedges.push_back(mesh_.halfedge_handle(e2, 0));
    halfedges.push_back(mesh_.halfedge_handle(e3, 0)); halfedges.push_back(mesh_.halfedge_handle(e4, 0));

    FaceHandle f2 = mesh_.add_face(halfedges);

    EXPECT_EQ(1, f2);

    // Get halfedges of face
    halfedges = mesh_.face(f2).halfedges();
    int handle = 0;
    for(it = halfedges.begin(); it != halfedges.end(); ++it) {
        EXPECT_EQ(handle, mesh_.edge_handle(*it)); handle++;
    }
}

TEST_F(PolyhedralMeshBase, TopologyCheckPass) {

    // Add eight vertices
    VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, 0.0, 0.0));
    VertexHandle v1 = mesh_.add_vertex(Vec3d( 0.0, 0.0, 1.0));
    VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0, 0.0, 0.0));
    VertexHandle v3 = mesh_.add_vertex(Vec3d( 0.0, 1.0, 0.0));

    std::vector<VertexHandle> vertices;

    // Add faces
    vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v3);
    FaceHandle f0 = mesh_.add_face(vertices);

    vertices.clear();
    vertices.push_back(v1); vertices.push_back(v2);vertices.push_back(v3);
    FaceHandle f1 = mesh_.add_face(vertices);

    vertices.clear();
    vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v2);
    FaceHandle f2 = mesh_.add_face(vertices);

    vertices.clear();
    vertices.push_back(v0); vertices.push_back(v3);vertices.push_back(v2);
    FaceHandle f3 = mesh_.add_face(vertices);

    std::vector<HalfFaceHandle> halffaces;

    // Add first tetrahedron
    halffaces.push_back(mesh_.halfface_handle(f0, 1));
    halffaces.push_back(mesh_.halfface_handle(f1, 1));
    halffaces.push_back(mesh_.halfface_handle(f2, 0));
    halffaces.push_back(mesh_.halfface_handle(f3, 1));
    EXPECT_NE(PolyhedralMesh::InvalidCellHandle, mesh_.add_cell(halffaces));
}

TEST_F(PolyhedralMeshBase, TopologyCheckFail) {

    // Add eight vertices
    VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, 0.0, 0.0));
    VertexHandle v1 = mesh_.add_vertex(Vec3d( 0.0, 0.0, 1.0));
    VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0, 0.0, 0.0));
    VertexHandle v3 = mesh_.add_vertex(Vec3d( 0.0, 1.0, 0.0));

    std::vector<VertexHandle> vertices;

    // Add faces
    vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v3);
    FaceHandle f0 = mesh_.add_face(vertices);

    vertices.clear();
    vertices.push_back(v1); vertices.push_back(v2);vertices.push_back(v3);
    FaceHandle f1 = mesh_.add_face(vertices);

    vertices.clear();
    vertices.push_back(v0); vertices.push_back(v1);vertices.push_back(v2);
    FaceHandle f2 = mesh_.add_face(vertices);

    vertices.clear();
    vertices.push_back(v0); vertices.push_back(v3);vertices.push_back(v2);
    FaceHandle f3 = mesh_.add_face(vertices);

    std::vector<HalfFaceHandle> halffaces;

    // Add first tetrahedron
    halffaces.push_back(mesh_.halfface_handle(f0, 1));
    halffaces.push_back(mesh_.halfface_handle(f1, 1));
    halffaces.push_back(mesh_.halfface_handle(f2, 0));
    halffaces.push_back(mesh_.halfface_handle(f3, 0));
325
    EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, mesh_.add_cell(halffaces, true));
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
}

TEST_F(HexahedralMeshBase, TopologyCheckPass) {

    VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, -1.0, -1.0));
    VertexHandle v1 = mesh_.add_vertex(Vec3d( 1.0, -1.0, -1.0));
    VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0,  1.0, -1.0));
    VertexHandle v3 = mesh_.add_vertex(Vec3d(-1.0,  1.0, -1.0));
    VertexHandle v4 = mesh_.add_vertex(Vec3d(-1.0, -1.0,  1.0));
    VertexHandle v5 = mesh_.add_vertex(Vec3d( 1.0, -1.0,  1.0));
    VertexHandle v6 = mesh_.add_vertex(Vec3d( 1.0,  1.0,  1.0));
    VertexHandle v7 = mesh_.add_vertex(Vec3d(-1.0,  1.0,  1.0));

    std::vector<VertexHandle> fvertices;

    fvertices.push_back(v3);
    fvertices.push_back(v2);
    fvertices.push_back(v1);
    fvertices.push_back(v0);

    FaceHandle fh0 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v4);
    fvertices.push_back(v5);
    fvertices.push_back(v6);
    fvertices.push_back(v7);

    FaceHandle fh1 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v0);
    fvertices.push_back(v4);
    fvertices.push_back(v7);
    fvertices.push_back(v3);

    FaceHandle fh2 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v1);
    fvertices.push_back(v2);
    fvertices.push_back(v6);
    fvertices.push_back(v5);

    FaceHandle fh3 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v7);
    fvertices.push_back(v6);
    fvertices.push_back(v2);
    fvertices.push_back(v3);

    FaceHandle fh4 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v0);
    fvertices.push_back(v1);
    fvertices.push_back(v5);
    fvertices.push_back(v4);

    FaceHandle fh5 = mesh_.add_face(fvertices);

    std::vector<HalfFaceHandle> chfaces;

    chfaces.push_back(mesh_.halfface_handle(fh0, 0));
    chfaces.push_back(mesh_.halfface_handle(fh1, 0));
    chfaces.push_back(mesh_.halfface_handle(fh2, 0));
    chfaces.push_back(mesh_.halfface_handle(fh3, 0));
    chfaces.push_back(mesh_.halfface_handle(fh4, 0));
    chfaces.push_back(mesh_.halfface_handle(fh5, 0));

402
    EXPECT_NE(HexahedralMesh::InvalidCellHandle, mesh_.add_cell(chfaces, true));
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
}

TEST_F(HexahedralMeshBase, TopologyCheckFail) {

    VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, -1.0, -1.0));
    VertexHandle v1 = mesh_.add_vertex(Vec3d( 1.0, -1.0, -1.0));
    VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0,  1.0, -1.0));
    VertexHandle v3 = mesh_.add_vertex(Vec3d(-1.0,  1.0, -1.0));
    VertexHandle v4 = mesh_.add_vertex(Vec3d(-1.0, -1.0,  1.0));
    VertexHandle v5 = mesh_.add_vertex(Vec3d( 1.0, -1.0,  1.0));
    VertexHandle v6 = mesh_.add_vertex(Vec3d( 1.0,  1.0,  1.0));
    VertexHandle v7 = mesh_.add_vertex(Vec3d(-1.0,  1.0,  1.0));

    std::vector<VertexHandle> fvertices;

    fvertices.push_back(v3);
    fvertices.push_back(v2);
    fvertices.push_back(v1);
    fvertices.push_back(v0);

    FaceHandle fh0 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v4);
    fvertices.push_back(v5);
    fvertices.push_back(v6);
    fvertices.push_back(v7);

    FaceHandle fh1 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v0);
    fvertices.push_back(v4);
    fvertices.push_back(v7);
    fvertices.push_back(v3);

    FaceHandle fh2 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v1);
    fvertices.push_back(v2);
    fvertices.push_back(v6);
    fvertices.push_back(v5);

    FaceHandle fh3 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v7);
    fvertices.push_back(v6);
    fvertices.push_back(v2);
    fvertices.push_back(v3);

    FaceHandle fh4 = mesh_.add_face(fvertices);

    fvertices.clear();

    fvertices.push_back(v0);
    fvertices.push_back(v1);
    fvertices.push_back(v5);
    fvertices.push_back(v4);

    FaceHandle fh5 = mesh_.add_face(fvertices);

    std::vector<HalfFaceHandle> chfaces;

    chfaces.push_back(mesh_.halfface_handle(fh0, 0));
    chfaces.push_back(mesh_.halfface_handle(fh1, 1));
    chfaces.push_back(mesh_.halfface_handle(fh2, 0));
    chfaces.push_back(mesh_.halfface_handle(fh3, 0));
    chfaces.push_back(mesh_.halfface_handle(fh4, 0));
    chfaces.push_back(mesh_.halfface_handle(fh5, 0));

479
    EXPECT_EQ(HexahedralMesh::InvalidCellHandle, mesh_.add_cell(chfaces, true));
480
481
}

482
483
484
485
486
487
488
TEST_F(PolyhedralMeshBase, VolumeMeshGenus) {

    generatePolyhedralMesh(mesh_);

    EXPECT_EQ(0, mesh_.genus());
}

489
490
491
492
493
494
495
496
497
TEST_F(PolyhedralMeshBase, VolumeMeshConnectivity) {

    generatePolyhedralMesh(mesh_);

    // Add invalid cell
    std::vector<HalfFaceHandle> hfaces;
    hfaces.push_back(1); hfaces.push_back(5);
    hfaces.push_back(7); hfaces.push_back(9);
    hfaces.push_back(10); hfaces.push_back(21);
498
    CellHandle i_cell = mesh_.add_cell(hfaces, true);
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546

    EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, i_cell);

    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(1));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(2));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(5));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(7));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(9));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(10));

    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(3));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(12));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(15));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(17));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(19));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(20));

    // Test adjacency function
    HalfFaceHandle ad_hf1 = mesh_.adjacent_halfface_in_cell(1, 3);
    // Should be halfface 5
    EXPECT_EQ(HalfFaceHandle(5), ad_hf1);

    HalfFaceHandle ad_hf2 = mesh_.adjacent_halfface_in_cell(1, 7);
    // Should be halfface 7
    EXPECT_EQ(HalfFaceHandle(7), ad_hf2);

    HalfFaceHandle ad_hf3 = mesh_.adjacent_halfface_in_cell(5, 24);
    // Should be invalid
    EXPECT_EQ(PolyhedralMesh::InvalidHalfFaceHandle, ad_hf3);

    HalfFaceHandle ad_hf4 = mesh_.adjacent_halfface_in_cell(12, 24);
    // Should be invalid
    EXPECT_EQ(HalfFaceHandle(20), ad_hf4);

    HalfFaceHandle ad_hf5 = mesh_.adjacent_halfface_in_cell(0, 0);
    // Should be invalid
    EXPECT_EQ(PolyhedralMesh::InvalidHalfFaceHandle, ad_hf5);

    EXPECT_EQ(12u, mesh_.n_vertices());
    EXPECT_EQ(20u, mesh_.n_edges());
    EXPECT_EQ(2u,  mesh_.n_cells());
    EXPECT_EQ(11u, mesh_.n_faces());
}

TEST_F(PolyhedralMeshBase, VolumeMeshNormals) {

    generatePolyhedralMesh(mesh_);

547
    NormalAttrib<GeometricPolyhedralMeshV3d> normals(mesh_);
548
549
550
551
552
553
554

    Vec3d n_x(1.0, 0.0, 0.0);
    Vec3d n_y(0.0, 1.0, 0.0);
    Vec3d n_z(0.0, 0.0, 1.0);

    normals.update_face_normals();

555
    // Should be positive z-axis
556
    Vec3d& n = normals[FaceHandle(0)];
557
558
559
    EXPECT_DOUBLE_EQ(n_z[0], n[0]);
    EXPECT_DOUBLE_EQ(n_z[1], n[1]);
    EXPECT_DOUBLE_EQ(n_z[2], n[2]);
560

561
562
563
564
565
    n = normals[HalfFaceHandle(1)];
    EXPECT_DOUBLE_EQ(-n_z[0], n[0]);
    EXPECT_DOUBLE_EQ(-n_z[1], n[1]);
    EXPECT_DOUBLE_EQ(-n_z[2], n[2]);

566
    // Should be negative x-axis
567
    n = normals[FaceHandle(2)];
568
569
570
    EXPECT_DOUBLE_EQ(-n_x[0], n[0]);
    EXPECT_DOUBLE_EQ(-n_x[1], n[1]);
    EXPECT_DOUBLE_EQ(-n_x[2], n[2]);
571

572
573
574
575
576
577
578
579
580
581
    n = normals[HalfFaceHandle(4)];
    EXPECT_DOUBLE_EQ(-n_x[0], n[0]);
    EXPECT_DOUBLE_EQ(-n_x[1], n[1]);
    EXPECT_DOUBLE_EQ(-n_x[2], n[2]);

    n = normals[HalfFaceHandle(5)];
    EXPECT_DOUBLE_EQ(n_x[0], n[0]);
    EXPECT_DOUBLE_EQ(n_x[1], n[1]);
    EXPECT_DOUBLE_EQ(n_x[2], n[2]);

582
    // Should be negative y-axis
583
    n = normals[FaceHandle(4)];
584
585
586
    EXPECT_DOUBLE_EQ(-n_y[0], n[0]);
    EXPECT_DOUBLE_EQ(-n_y[1], n[1]);
    EXPECT_DOUBLE_EQ(-n_y[2], n[2]);
587

588
589
590
591
592
    n = normals[HalfFaceHandle(9)];
    EXPECT_DOUBLE_EQ(n_y[0], n[0]);
    EXPECT_DOUBLE_EQ(n_y[1], n[1]);
    EXPECT_DOUBLE_EQ(n_y[2], n[2]);

593
594
    // Should be positive y-axis
    n = normals[FaceHandle(5)];
595
596
597
    EXPECT_DOUBLE_EQ(-n_y[0], n[0]);
    EXPECT_DOUBLE_EQ(-n_y[1], n[1]);
    EXPECT_DOUBLE_EQ(-n_y[2], n[2]);
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
}

TEST_F(PolyhedralMeshBase, PolyhedralMeshStatusTest) {

    generatePolyhedralMesh(mesh_);

    // Request status
    StatusAttrib status(mesh_);

    // Select a few faces
    status[FaceHandle(1)].set_tagged(true);
    status[FaceHandle(4)].set_tagged(true);

    status[HalfFaceHandle(21)].set_deleted(true);
    status[HalfFaceHandle(0)].set_deleted(true);

    status[VertexHandle(3)].set_selected(true);
    status[VertexHandle(8)].set_selected(true);

    EXPECT_TRUE(status[FaceHandle(1)].tagged());
    EXPECT_TRUE(status[FaceHandle(4)].tagged());
    EXPECT_FALSE(status[FaceHandle(7)].tagged());
    EXPECT_FALSE(status[FaceHandle(2)].tagged());

    EXPECT_TRUE(status[HalfFaceHandle(21)].deleted());
    EXPECT_TRUE(status[HalfFaceHandle(0)].deleted());
    EXPECT_FALSE(status[HalfFaceHandle(13)].deleted());
    EXPECT_FALSE(status[HalfFaceHandle(20)].deleted());

    EXPECT_TRUE(status[VertexHandle(3)].selected());
    EXPECT_TRUE(status[VertexHandle(8)].selected());
    EXPECT_FALSE(status[VertexHandle(1)].selected());
    EXPECT_FALSE(status[VertexHandle(9)].selected());
}

Mike Kremer's avatar
Mike Kremer committed
633
TEST_F(PolyhedralMeshBase, PolyhedralMeshColorTest) {
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674

    generatePolyhedralMesh(mesh_);

    typedef OpenVolumeMesh::Geometry::Vec4f Vec4f;

    // Request colors
    ColorAttrib<Vec4f> colors(mesh_);

    colors[VertexHandle(7)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
    colors[EdgeHandle(6)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
    colors[HalfEdgeHandle(5)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
    colors[FaceHandle(4)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
    colors[HalfFaceHandle(3)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);
    colors[CellHandle(1)] = Vec4f(1.0f, 1.0f, 0.0f, 1.0f);

    EXPECT_FLOAT_EQ(1.0f, colors[VertexHandle(7)][0]);
    EXPECT_FLOAT_EQ(1.0f, colors[VertexHandle(7)][1]);
    EXPECT_FLOAT_EQ(0.0f, colors[VertexHandle(7)][2]);
    EXPECT_FLOAT_EQ(1.0f, colors[VertexHandle(7)][3]);
    EXPECT_FLOAT_EQ(1.0f, colors[EdgeHandle(6)][0]);
    EXPECT_FLOAT_EQ(1.0f, colors[EdgeHandle(6)][1]);
    EXPECT_FLOAT_EQ(0.0f, colors[EdgeHandle(6)][2]);
    EXPECT_FLOAT_EQ(1.0f, colors[EdgeHandle(6)][3]);
    EXPECT_FLOAT_EQ(1.0f, colors[HalfEdgeHandle(5)][0]);
    EXPECT_FLOAT_EQ(1.0f, colors[HalfEdgeHandle(5)][1]);
    EXPECT_FLOAT_EQ(0.0f, colors[HalfEdgeHandle(5)][2]);
    EXPECT_FLOAT_EQ(1.0f, colors[HalfEdgeHandle(5)][3]);
    EXPECT_FLOAT_EQ(1.0f, colors[FaceHandle(4)][0]);
    EXPECT_FLOAT_EQ(1.0f, colors[FaceHandle(4)][1]);
    EXPECT_FLOAT_EQ(0.0f, colors[FaceHandle(4)][2]);
    EXPECT_FLOAT_EQ(1.0f, colors[FaceHandle(4)][3]);
    EXPECT_FLOAT_EQ(1.0f, colors[HalfFaceHandle(3)][0]);
    EXPECT_FLOAT_EQ(1.0f, colors[HalfFaceHandle(3)][1]);
    EXPECT_FLOAT_EQ(0.0f, colors[HalfFaceHandle(3)][2]);
    EXPECT_FLOAT_EQ(1.0f, colors[HalfFaceHandle(3)][3]);
    EXPECT_FLOAT_EQ(1.0f, colors[CellHandle(1)][0]);
    EXPECT_FLOAT_EQ(1.0f, colors[CellHandle(1)][1]);
    EXPECT_FLOAT_EQ(0.0f, colors[CellHandle(1)][2]);
    EXPECT_FLOAT_EQ(1.0f, colors[CellHandle(1)][3]);
}

675
676
677
678
679
680
TEST_F(PolyhedralMeshBase, PolyhedralMeshProperties) {

    generatePolyhedralMesh(mesh_);

    VertexPropertyT<Vec3d> vp = mesh_.request_vertex_property<Vec3d>("VProp");

681
    EXPECT_TRUE(mesh_.vertex_property_exists<Vec3d>("VProp"));
682

683
    for(VertexIter v_it = mesh_.v_iter(); v_it.valid(); ++v_it) {
684
        vp[v_it->idx()] = Vec3d(1.0, 0.0, 0.0);
685
686
687
688
    }

    for(VertexIter v_it = mesh_.v_iter(); v_it.valid(); ++v_it) {
        Vec3d t;
689
        t = vp[v_it->idx()];
690
691
692
693
694
695
        EXPECT_DOUBLE_EQ(1.0, t[0]);
        EXPECT_DOUBLE_EQ(0.0, t[1]);
        EXPECT_DOUBLE_EQ(0.0, t[2]);
    }

    VertexHandle vh = mesh_.add_vertex(Vec3d(3.0,3.0,3.0));
696
697
    vp[vh.idx()] = Vec3d(0.0);
    Vec3d p = vp[vh.idx()];
698
699
700
701
702
703
    EXPECT_DOUBLE_EQ(0.0, p[0]);
    EXPECT_DOUBLE_EQ(0.0, p[1]);
    EXPECT_DOUBLE_EQ(0.0, p[2]);

    EdgePropertyT<unsigned int> ep = mesh_.request_edge_property<unsigned int>("EProp");

704
    EXPECT_TRUE(mesh_.edge_property_exists<unsigned int>("EProp"));
705

706
707
    unsigned int i = 0;
    for(EdgeIter e_it = mesh_.e_iter(); e_it.valid(); ++e_it) {
708
        ep[e_it->idx()] = i++;
709
710
711
712
    }

    i = 0;
    for(EdgeIter e_it = mesh_.e_iter(); e_it.valid(); ++e_it) {
713
        EXPECT_EQ(i++, ep[e_it->idx()]);
714
715
716
717
    }

    HalfFacePropertyT<bool> hfp = mesh_.request_halfface_property<bool>("HFProp");

718
    EXPECT_TRUE(mesh_.halfface_property_exists<bool>("HFProp"));
719

720
721
    bool b = false;
    for(HalfFaceIter hf_it = mesh_.hf_iter(); hf_it.valid(); ++hf_it) {
722
        hfp[hf_it->idx()] = b;
723
724
725
726
727
        b = !b;
    }

    b = false;
    for(HalfFaceIter hf_it = mesh_.hf_iter(); hf_it.valid(); ++hf_it) {
728
        EXPECT_EQ(b, hfp[hf_it->idx()]);
729
730
731
732
733
734
        b = !b;
    }

    // Request halfface properties
    CellPropertyT<std::string> cp = mesh_.request_cell_property<std::string>("CProp");

735
    EXPECT_TRUE(mesh_.cell_property_exists<std::string>("CProp"));
736

737
    for(CellIter c_it = mesh_.c_iter(); c_it.valid(); ++c_it) {
738
        cp[c_it->idx()] = std::string("MyTestString");
739
740
741
    }

    for(CellIter c_it = mesh_.c_iter(); c_it.valid(); ++c_it) {
742
        EXPECT_EQ(std::string("MyTestString"), cp[c_it->idx()]);
743
    }
744

745
746
    EXPECT_FALSE(mesh_.halfedge_property_exists<unsigned char>("HEProp"));
    EXPECT_FALSE(mesh_.vertex_property_exists<size_t>(""));
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
}

TEST_F(PolyhedralMeshBase, STLCompliance) {

    generatePolyhedralMesh(mesh_);

    Print p;
    p.mute(true);
    //std::cerr << "Vertices:" << std::endl;
    std::for_each(mesh_.vertices_begin(), mesh_.vertices_end(), p);
    //std::cerr << "Edges:" << std::endl;
    std::for_each(mesh_.edges_begin(), mesh_.edges_end(), p);
    //std::cerr << "HalfEdges:" << std::endl;
    std::for_each(mesh_.halfedges_begin(), mesh_.halfedges_end(), p);
    //std::cerr << "Faces:" << std::endl;
    std::for_each(mesh_.faces_begin(), mesh_.faces_end(), p);
    //std::cerr << "HalfFaces:" << std::endl;
    std::for_each(mesh_.halffaces_begin(), mesh_.halffaces_end(), p);
    //std::cerr << "Cells:" << std::endl;
    std::for_each(mesh_.cells_begin(), mesh_.cells_end(), p);
}

769
TEST_F(PolyhedralMeshBase, DeleteCellBUTest1) {
Mike Kremer's avatar
Mike Kremer committed
770
771
772
773
774
775
776
777
778
779
780
781
782

    generatePolyhedralMesh(mesh_);

    std::vector<HalfFaceHandle> hfs = mesh_.cell(CellHandle(0)).halffaces();

    mesh_.delete_cell(CellHandle(0));

    for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
            hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
        EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, mesh_.incident_cell(*hf_it));
    }
}

783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
TEST_F(PolyhedralMeshBase, DeleteFaceBUTest1) {

    generatePolyhedralMesh(mesh_);

    std::vector<HalfEdgeHandle> hes = mesh_.face(FaceHandle(0)).halfedges();

    std::vector<HalfFaceHandle> ihfs[4];

    for(size_t i = 0; i < 4; ++i) {
        for(HalfEdgeHalfFaceIter hehf_it = mesh_.hehf_iter(hes[i]); hehf_it.valid(); ++hehf_it) {

            HalfFaceHandle hfh = *hehf_it;

            if(mesh_.face_handle(hfh) == FaceHandle(0)) continue;

            hfh.idx((hfh.idx() > mesh_.halfface_handle(FaceHandle(0), 1) ? hfh.idx() - 2 : hfh.idx()));

            ihfs[i].push_back(hfh);
        }
    }

    mesh_.delete_face(FaceHandle(0));

    std::set<HalfFaceHandle> nihfs[4];
    for(size_t i = 0; i < 4; ++i) {
        for(HalfEdgeHalfFaceIter hehf_it = mesh_.hehf_iter(hes[i]); hehf_it.valid(); ++hehf_it) {
            nihfs[i].insert(*hehf_it);
        }
    }

    EXPECT_EQ(ihfs[0].size(), nihfs[0].size());
    EXPECT_EQ(ihfs[1].size(), nihfs[1].size());
    EXPECT_EQ(ihfs[2].size(), nihfs[2].size());
    EXPECT_EQ(ihfs[3].size(), nihfs[3].size());

    for(size_t i = 0; i < 4; ++i) {
        for(std::vector<HalfFaceHandle>::const_iterator hf_it = ihfs[i].begin(),
                hf_end = ihfs[i].end(); hf_it != hf_end; ++hf_it) {
821
            EXPECT_GT(nihfs[i].count(*hf_it), 0u);
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
        }
    }
}

TEST_F(PolyhedralMeshBase, DeleteEdgeBUTest1) {

    generatePolyhedralMesh(mesh_);

    VertexHandle vh0 = mesh_.edge(EdgeHandle(0)).from_vertex();
    VertexHandle vh1 = mesh_.edge(EdgeHandle(0)).to_vertex();

    std::vector<HalfEdgeHandle> hes0;
    for(VertexOHalfEdgeIter voh_it = mesh_.voh_iter(vh0); voh_it.valid(); ++voh_it) {
        if(mesh_.edge_handle(*voh_it) == EdgeHandle(0)) continue;
        hes0.push_back(HalfEdgeHandle(voh_it->idx() > mesh_.halfedge_handle(EdgeHandle(0), 1) ? voh_it->idx() - 2 : voh_it->idx()));
    }

    std::vector<HalfEdgeHandle> hes1;
    for(VertexOHalfEdgeIter voh_it = mesh_.voh_iter(vh1); voh_it.valid(); ++voh_it) {
        if(mesh_.edge_handle(*voh_it) == EdgeHandle(0)) continue;
        hes1.push_back(HalfEdgeHandle(voh_it->idx() > mesh_.halfedge_handle(EdgeHandle(0), 1) ? voh_it->idx() - 2 : voh_it->idx()));
    }

    mesh_.delete_edge(EdgeHandle(0));

    std::set<HalfEdgeHandle> nhes0;
    for(VertexOHalfEdgeIter voh_it = mesh_.voh_iter(vh0); voh_it.valid(); ++voh_it) {
        nhes0.insert(*voh_it);
    }

    std::set<HalfEdgeHandle> nhes1;
    for(VertexOHalfEdgeIter voh_it = mesh_.voh_iter(vh1); voh_it.valid(); ++voh_it) {
        nhes1.insert(*voh_it);
    }

    EXPECT_EQ(hes0.size(), nhes0.size());
    EXPECT_EQ(hes1.size(), nhes1.size());

    for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes0.begin(),
            he_end = hes0.end(); he_it != he_end; ++he_it) {
862
        EXPECT_GT(nhes0.count(*he_it), 0u);
863
864
865
866
    }

    for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes1.begin(),
            he_end = hes1.end(); he_it != he_end; ++he_it) {
867
        EXPECT_GT(nhes1.count(*he_it), 0u);
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
    }
}

TEST_F(PolyhedralMeshBase, DeleteCellBUTest1noBU) {

    generatePolyhedralMesh(mesh_);

    mesh_.enable_bottom_up_incidences(false);

    std::vector<HalfFaceHandle> hfs = mesh_.cell(CellHandle(0)).halffaces();

    mesh_.delete_cell(CellHandle(0));

    for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
            hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
        EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, mesh_.incident_cell(*hf_it));
    }
}

TEST_F(PolyhedralMeshBase, DeleteFaceBUTest1noBU) {

    generatePolyhedralMesh(mesh_);

    mesh_.enable_bottom_up_incidences(false);

    std::vector<HalfEdgeHandle> hes = mesh_.face(FaceHandle(0)).halfedges();

    std::vector<HalfFaceHandle> ihfs[4];

    for(size_t i = 0; i < 4; ++i) {
        for(HalfFaceIter hf_it = mesh_.halffaces_begin(), hf_end = mesh_.halffaces_end(); hf_it != hf_end; ++hf_it) {

            std::vector<HalfEdgeHandle> t_hes = mesh_.halfface(*hf_it).halfedges();
            bool found = false;
            for(std::vector<HalfEdgeHandle>::const_iterator the_it = t_hes.begin(),
                    the_end = t_hes.end(); the_it != the_end; ++the_it) {
                if(std::find(hes.begin(), hes.end(), *the_it) != hes.end()) {
                    found = true;
                    break;
                }
            }
            if(!found) continue;

            HalfFaceHandle hfh = *hf_it;

            if(mesh_.face_handle(hfh) == FaceHandle(0)) continue;

            hfh.idx((hfh.idx() > mesh_.halfface_handle(FaceHandle(0), 1) ? hfh.idx() - 2 : hfh.idx()));

            ihfs[i].push_back(hfh);
        }
    }

    mesh_.delete_face(FaceHandle(0));

    std::set<HalfFaceHandle> nihfs[4];
    for(size_t i = 0; i < 4; ++i) {
        for(HalfFaceIter hf_it = mesh_.halffaces_begin(), hf_end = mesh_.halffaces_end(); hf_it != hf_end; ++hf_it) {

            std::vector<HalfEdgeHandle> t_hes = mesh_.halfface(*hf_it).halfedges();
            bool found = false;
            for(std::vector<HalfEdgeHandle>::const_iterator the_it = t_hes.begin(),
                    the_end = t_hes.end(); the_it != the_end; ++the_it) {
                if(std::find(hes.begin(), hes.end(), *the_it) != hes.end()) {
                    found = true;
                    break;
                }
            }
            if(!found) continue;

            nihfs[i].insert(*hf_it);
        }
    }

    EXPECT_EQ(ihfs[0].size(), nihfs[0].size());
    EXPECT_EQ(ihfs[1].size(), nihfs[1].size());
    EXPECT_EQ(ihfs[2].size(), nihfs[2].size());
    EXPECT_EQ(ihfs[3].size(), nihfs[3].size());

    for(size_t i = 0; i < 4; ++i) {
        for(std::vector<HalfFaceHandle>::const_iterator hf_it = ihfs[i].begin(),
                hf_end = ihfs[i].end(); hf_it != hf_end; ++hf_it) {
950
            EXPECT_GT(nihfs[i].count(*hf_it), 0u);
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
        }
    }
}

TEST_F(PolyhedralMeshBase, DeleteEdgeBUTest1noBU) {

    generatePolyhedralMesh(mesh_);

    mesh_.enable_bottom_up_incidences(false);

    VertexHandle vh0 = mesh_.edge(EdgeHandle(0)).from_vertex();
    VertexHandle vh1 = mesh_.edge(EdgeHandle(0)).to_vertex();

    std::vector<HalfEdgeHandle> hes0;
    for(HalfEdgeIter he_it = mesh_.halfedges_begin(), he_end = mesh_.halfedges_end(); he_it != he_end; ++he_it) {

        if(mesh_.halfedge(*he_it).from_vertex() == vh0) {

            if(mesh_.edge_handle(*he_it) == EdgeHandle(0)) continue;
            hes0.push_back(HalfEdgeHandle(he_it->idx() > mesh_.halfedge_handle(EdgeHandle(0), 1) ? he_it->idx() - 2 : he_it->idx()));
        }
    }

    std::vector<HalfEdgeHandle> hes1;
    for(HalfEdgeIter he_it = mesh_.halfedges_begin(), he_end = mesh_.halfedges_end(); he_it != he_end; ++he_it) {

        if(mesh_.halfedge(*he_it).from_vertex() == vh1) {

            if(mesh_.edge_handle(*he_it) == EdgeHandle(0)) continue;
            hes1.push_back(HalfEdgeHandle(he_it->idx() > mesh_.halfedge_handle(EdgeHandle(0), 1) ? he_it->idx() - 2 : he_it->idx()));
        }
    }

    mesh_.delete_edge(EdgeHandle(0));

    std::set<HalfEdgeHandle> nhes0;
    for(HalfEdgeIter he_it = mesh_.halfedges_begin(), he_end = mesh_.halfedges_end(); he_it != he_end; ++he_it) {
        if(mesh_.halfedge(*he_it).from_vertex() == vh0) {
            nhes0.insert(*he_it);
        }
    }

    std::set<HalfEdgeHandle> nhes1;
    for(HalfEdgeIter he_it = mesh_.halfedges_begin(), he_end = mesh_.halfedges_end(); he_it != he_end; ++he_it) {
        if(mesh_.halfedge(*he_it).from_vertex() == vh1) {
            nhes1.insert(*he_it);
        }
    }

    EXPECT_EQ(hes0.size(), nhes0.size());
    EXPECT_EQ(hes1.size(), nhes1.size());

    for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes0.begin(),
            he_end = hes0.end(); he_it != he_end; ++he_it) {
1005
        EXPECT_GT(nhes0.count(*he_it), 0u);
1006
1007
1008
1009
    }

    for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes1.begin(),
            he_end = hes1.end(); he_it != he_end; ++he_it) {
1010
        EXPECT_GT(nhes1.count(*he_it), 0u);
1011
1012
1013
    }
}

1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100