unittests_trimesh_iterators.cc 24.7 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3 4 5
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>

#include <iostream>

6 7
namespace {

Jan Möbius's avatar
Jan Möbius committed
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
class OpenMeshIterators : public OpenMeshBase {

    protected:

        // This function is called before each test is run
        virtual void SetUp() {
        }

        // This function is called after all tests are through
        virtual void TearDown() {

            // Do some final stuff with the member data here...
        }

    // Member already defined in OpenMeshBase
    //Mesh mesh_;  
};

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

/*
 * Small VertexIterator Test
 */
TEST_F(OpenMeshIterators, VertexIter) {

37
  mesh_.clear();
Jan Möbius's avatar
Jan Möbius committed
38

39 40
  // Add some vertices
  Mesh::VertexHandle vhandle[4];
Jan Möbius's avatar
Jan Möbius committed
41

42 43 44 45
  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
Jan Möbius's avatar
Jan Möbius committed
46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  // Add two faces
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[0]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  mesh_.add_face(face_vhandles);

  // Test setup:
  //  1 === 2
  //  |   / |    
  //  |  /  |
  //  | /   |
  //  0 === 3

69 70
  Mesh::VertexIter v_it  = mesh_.vertices_begin(); 
  Mesh::VertexIter v_end = mesh_.vertices_end(); 
71

72
  EXPECT_EQ(0, v_it->idx()) << "Index wrong for vertex iterator vertices_begin()";
73
  ++v_it;
74
  EXPECT_EQ(1, v_it->idx()) << "Index wrong in vertex iterator";
75
  ++v_it;
76
  EXPECT_EQ(2, v_it->idx()) << "Index wrong in vertex iterator";
77
  ++v_it;
78
  EXPECT_EQ(3, v_it->idx()) << "Index wrong in vertex iterator";
79
  ++v_it;
80
  EXPECT_EQ(4, v_it->idx()) << "Index wrong in vertex iterator";
81 82

  // Check end iterator
83
  EXPECT_EQ(4, v_end->idx()) << "Index wrong in vertex iterator for vertices_end()";    
Jan Möbius's avatar
Jan Möbius committed
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

  // Second iterator test to start at a specific position

}

/*
 * Small VertexIterator Test to check if we can start iterating at a specific handle
 */
TEST_F(OpenMeshIterators, VertexIterStartPosition) {

  mesh_.clear();

  // Add some vertices
  Mesh::VertexHandle vhandle[4];

  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));

  // Add two faces
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[0]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  mesh_.add_face(face_vhandles);

  // Test setup:
  //  1 === 2
  //  |   / |
  //  |  /  |
  //  | /   |
  //  0 === 3

  Mesh::VertexIter v_it  = Mesh::VertexIter(mesh_,mesh_.vertex_handle(2));
  Mesh::VertexIter v_end = mesh_.vertices_end();

130
  EXPECT_EQ(2, v_it->idx()) << "Index wrong in vertex iterator";
131
  ++v_it;
132
  EXPECT_EQ(3, v_it->idx()) << "Index wrong in vertex iterator";
133
  ++v_it;
134
  EXPECT_EQ(4, v_it->idx()) << "Index wrong in vertex iterator";
135 136

  // Check end iterator
137
  EXPECT_EQ(4, v_end->idx()) << "Index wrong in vertex iterator for vertices_end()";
138 139


Jan Möbius's avatar
Jan Möbius committed
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

/*
 * Small VertexIterator Test to check if we can continue from the end after adding vertices
 */
TEST_F(OpenMeshIterators, VertexIterContinueAfterEnd) {

  mesh_.clear();

  // Add some vertices
  Mesh::VertexHandle vhandle[4];

  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));

  // Add two faces
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[0]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  mesh_.add_face(face_vhandles);

  // Test setup:
  //  1 === 2
  //  |   / |
  //  |  /  |
  //  | /   |
  //  0 === 3



  // Add a double vertex property
  OpenMesh::VPropHandleT<int> intHandle;
  EXPECT_FALSE( mesh_.get_property_handle(intHandle,"intProp") );
  mesh_.add_property(intHandle,"intProp");

  // Initialize existing properties:
  int i = 0;
  for (Mesh::VertexIter v_it = mesh_.vertices_begin(); v_it !=  mesh_.vertices_end()  ; ++ v_it) {
    mesh_.property(intHandle,*v_it) = i;
    ++i;
  }

  // Check property
  EXPECT_TRUE(mesh_.get_property_handle(intHandle,"intProp"));

  // Remember old end iterator
  Mesh::VertexIter old_end = mesh_.vertices_end();

  // Set properties to perform test
  for ( unsigned int j = 0 ; j < 4 ; ++j ) {
    OpenMesh::VertexHandle vh = mesh_.add_vertex(Mesh::Point(1, 0, 0));
    mesh_.property(intHandle,vh) = i;
    ++i;
  }

  // Reset to first expected value
  i = 4;

  for ( Mesh::VertexIter test = old_end ; test != mesh_.vertices_end() ; ++test ) {
    EXPECT_EQ( mesh_.property(intHandle,*test) , i);
    ++i;
  }

}

Jan Möbius's avatar
Jan Möbius committed
217 218 219 220 221
/*
 * Small EdgeIterator Test
 */
TEST_F(OpenMeshIterators, EdgeIter) {

222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
  mesh_.clear();

  // Add some vertices
  Mesh::VertexHandle vhandle[4];

  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));

  // Add two faces
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[0]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  mesh_.add_face(face_vhandles);

  // Test setup:
  //  1 === 2
  //  |   / |    
  //  |  /  |
  //  | /   |
  //  0 === 3

Jan Möbius's avatar
Jan Möbius committed
254

255 256 257
  Mesh::EdgeIter e_it  = mesh_.edges_begin(); 
  Mesh::EdgeIter e_end = mesh_.edges_end(); 
  
258 259
  EXPECT_EQ(0, e_it->idx()) << "Wrong start index in edge iterator";
  EXPECT_EQ(5, e_end->idx()) << "Wrong end index in edge iterator";
Jan Möbius's avatar
Jan Möbius committed
260

261 262 263 264
  EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() )   << "1: Wrong to vertex handle of halfedge 0";
  EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) << "1: Wrong from vertex handle of halfedge 0";
  EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() )   << "1: Wrong to vertex handle of halfedge 1";
  EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) << "1: Wrong from vertex handle of halfedge 1";
Jan Möbius's avatar
Jan Möbius committed
265

266
  ++e_it;
267
  EXPECT_EQ(1, e_it->idx()) << "Wrong index in edge iterator";
Jan Möbius's avatar
Jan Möbius committed
268

269 270 271 272
  EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() )   << "2: Wrong to vertex handle of halfedge 0";
  EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) << "2: Wrong from vertex handle of halfedge 0";
  EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() )   << "2: Wrong to vertex handle of halfedge 1";
  EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) << "2: Wrong from vertex handle of halfedge 1";
Jan Möbius's avatar
Jan Möbius committed
273 274


275
  ++e_it;
276
  EXPECT_EQ(2, e_it->idx()) << "Wrong index in edge iterator";
Jan Möbius's avatar
Jan Möbius committed
277

278 279 280 281
  EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() )   << "3: Wrong to vertex handle of halfedge 0";
  EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) << "3: Wrong from vertex handle of halfedge 0";
  EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() )   << "3: Wrong to vertex handle of halfedge 1";
  EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) << "3: Wrong from vertex handle of halfedge 1";
Jan Möbius's avatar
Jan Möbius committed
282 283


284
  ++e_it;
285
  EXPECT_EQ(3, e_it->idx()) << "Wrong index in edge iterator";
Jan Möbius's avatar
Jan Möbius committed
286

287 288 289 290
  EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() )   << "4: Wrong to vertex handle of halfedge 0";
  EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) << "4: Wrong from vertex handle of halfedge 0";
  EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() )   << "4: Wrong to vertex handle of halfedge 1";
  EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) << "4: Wrong from vertex handle of halfedge 1";
Jan Möbius's avatar
Jan Möbius committed
291 292


293
  ++e_it;
294
  EXPECT_EQ(4, e_it->idx()) << "Wrong index in edge iterator";
Jan Möbius's avatar
Jan Möbius committed
295

296 297 298 299
  EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() )   << "5: Wrong to vertex handle of halfedge 0";
  EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) << "5: Wrong from vertex handle of halfedge 0";
  EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() )   << "5: Wrong to vertex handle of halfedge 1";
  EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) << "5: Wrong from vertex handle of halfedge 1";
Jan Möbius's avatar
Jan Möbius committed
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 325 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 402 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
/* Adds a cube to a trimesh and runs over all halfedges
 */
TEST_F(OpenMeshIterators, HalfedgeIterSkipping) {

  mesh_.clear();

  // Add some vertices
  Mesh::VertexHandle vhandle[8];
  vhandle[0] = mesh_.add_vertex(Mesh::Point(-1, -1,  1));
  vhandle[1] = mesh_.add_vertex(Mesh::Point( 1, -1,  1));
  vhandle[2] = mesh_.add_vertex(Mesh::Point( 1,  1,  1));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(-1,  1,  1));
  vhandle[4] = mesh_.add_vertex(Mesh::Point(-1, -1, -1));
  vhandle[5] = mesh_.add_vertex(Mesh::Point( 1, -1, -1));
  vhandle[6] = mesh_.add_vertex(Mesh::Point( 1,  1, -1));
  vhandle[7] = mesh_.add_vertex(Mesh::Point(-1,  1, -1));

  // Add six faces to form a cube
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[3]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[3]);
  mesh_.add_face(face_vhandles);

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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[7]);
  face_vhandles.push_back(vhandle[6]);
  face_vhandles.push_back(vhandle[5]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[7]);
  face_vhandles.push_back(vhandle[5]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[4]);
  face_vhandles.push_back(vhandle[5]);
  mesh_.add_face(face_vhandles);

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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[5]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[5]);
  face_vhandles.push_back(vhandle[6]);
  mesh_.add_face(face_vhandles);


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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[6]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[6]);
  face_vhandles.push_back(vhandle[7]);
  mesh_.add_face(face_vhandles);

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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[7]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[7]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);


  // Test setup:
  //
  //
  //    3 ======== 2
  //   /          /|
  //  /          / |      z
  // 0 ======== 1  |      |
  // |          |  |      |   y
  // |  7       |  6      |  /
  // |          | /       | /
  // |          |/        |/
  // 4 ======== 5         -------> x
  //

  // Check setup
  EXPECT_EQ(18u, mesh_.n_edges() )     << "Wrong number of Edges";
  EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
  EXPECT_EQ(8u, mesh_.n_vertices() )   << "Wrong number of vertices";
  EXPECT_EQ(12u, mesh_.n_faces() )     << "Wrong number of faces";

  mesh_.request_face_status();
  mesh_.request_vertex_status();
  mesh_.request_halfedge_status();

  // Get second edge
  Mesh::EdgeHandle eh = mesh_.edge_handle(2);

  // Delete one edge
  mesh_.delete_edge(eh);

  // Check setup ( No garbage collection, so nothing should change!)
  EXPECT_EQ(18u, mesh_.n_edges() )     << "Wrong number of Edges after delete";
  EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after delete";
  EXPECT_EQ(8u, mesh_.n_vertices() )   << "Wrong number of vertices after delete";
  EXPECT_EQ(12u, mesh_.n_faces() )     << "Wrong number of faces after delete";

  Mesh::HalfedgeIter he_it  = mesh_.halfedges_sbegin();
  Mesh::HalfedgeIter he_end = mesh_.halfedges_end();

447 448
  EXPECT_EQ(0,  he_it->idx()) << "Wrong start index in halfedge iterator";
  EXPECT_EQ(36, he_end->idx()) << "Wrong end index in halfedge iterator";
449 450 451 452 453 454 455 456 457 458 459


  // =====================================================
  // Check skipping iterator
  // =====================================================
  bool ok_4 = true;
  bool ok_5 = true;

  unsigned int count = 0;

  while (he_it != he_end) {
460
    if ( he_it->idx() ==  4 )
461 462
      ok_4 = false;

463
    if ( he_it->idx() ==  5 )
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
      ok_5 = false;

    ++he_it;
    ++count;
  }

  EXPECT_EQ(34u,count) << "Skipping iterator count error";
  EXPECT_TRUE( ok_4 )  << "Skipping iterator hit deleted halfedge 4";
  EXPECT_TRUE( ok_5 )  << "Skipping iterator hit deleted halfedge 5";

  // =====================================================
  // Check non skipping iterator
  // =====================================================
  he_it  = mesh_.halfedges_begin();

  count = 0;
  ok_4 = false;
  ok_5 = false;

  while (he_it != he_end) {
484
    if ( he_it->idx() ==  4 )
485 486
      ok_4 = true;

487
    if ( he_it->idx() ==  5 )
488 489 490 491 492 493 494 495 496 497 498 499
      ok_5 = true;


    ++he_it;
    ++count;
  }

  EXPECT_EQ(36u,count) << "Non-skipping iterator count error";
  EXPECT_TRUE( ok_4 )  << "Non-skipping iterator missed deleted halfedge 4";
  EXPECT_TRUE( ok_5 )  << "Non-skipping iterator missed  deleted halfedge 5";
}

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 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 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 633 634 635 636 637 638 639
/* Adds a cube to a trimesh and runs over all halfedges
 */
TEST_F(OpenMeshIterators, HalfedgeIterSkippingLowLevel) {

  mesh_.clear();

  // Add some vertices
  Mesh::VertexHandle vhandle[8];
  vhandle[0] = mesh_.add_vertex(Mesh::Point(-1, -1,  1));
  vhandle[1] = mesh_.add_vertex(Mesh::Point( 1, -1,  1));
  vhandle[2] = mesh_.add_vertex(Mesh::Point( 1,  1,  1));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(-1,  1,  1));
  vhandle[4] = mesh_.add_vertex(Mesh::Point(-1, -1, -1));
  vhandle[5] = mesh_.add_vertex(Mesh::Point( 1, -1, -1));
  vhandle[6] = mesh_.add_vertex(Mesh::Point( 1,  1, -1));
  vhandle[7] = mesh_.add_vertex(Mesh::Point(-1,  1, -1));

  // Add six faces to form a cube
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[3]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[3]);
  mesh_.add_face(face_vhandles);

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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[7]);
  face_vhandles.push_back(vhandle[6]);
  face_vhandles.push_back(vhandle[5]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[7]);
  face_vhandles.push_back(vhandle[5]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[4]);
  face_vhandles.push_back(vhandle[5]);
  mesh_.add_face(face_vhandles);

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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[5]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[5]);
  face_vhandles.push_back(vhandle[6]);
  mesh_.add_face(face_vhandles);


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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[6]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[6]);
  face_vhandles.push_back(vhandle[7]);
  mesh_.add_face(face_vhandles);

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

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[7]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[7]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);


  // Test setup:
  //
  //
  //    3 ======== 2
  //   /          /|
  //  /          / |      z
  // 0 ======== 1  |      |
  // |          |  |      |   y
  // |  7       |  6      |  /
  // |          | /       | /
  // |          |/        |/
  // 4 ======== 5         -------> x
  //

  // Check setup
  EXPECT_EQ(18u, mesh_.n_edges() )     << "Wrong number of Edges";
  EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
  EXPECT_EQ(8u, mesh_.n_vertices() )   << "Wrong number of vertices";
  EXPECT_EQ(12u, mesh_.n_faces() )     << "Wrong number of faces";

  mesh_.request_face_status();
  mesh_.request_vertex_status();
  mesh_.request_halfedge_status();

  // Get second edge
  Mesh::EdgeHandle eh = mesh_.edge_handle(2);

  // Check setup ( No garbage collection, so nothing should change!)
  EXPECT_EQ(18u, mesh_.n_edges() )     << "Wrong number of Edges after delete";
  EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after delete";
  EXPECT_EQ(8u, mesh_.n_vertices() )   << "Wrong number of vertices after delete";
  EXPECT_EQ(12u, mesh_.n_faces() )     << "Wrong number of faces after delete";

  Mesh::HalfedgeIter he_it  = mesh_.halfedges_sbegin();
  Mesh::HalfedgeIter he_end = mesh_.halfedges_end();

640 641
  EXPECT_EQ(0,  he_it->idx()) << "Wrong start index in halfedge iterator";
  EXPECT_EQ(36, he_end->idx()) << "Wrong end index in halfedge iterator";
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658

  // =====================================================
  // Try to add low level edge with invalid incidents and
  // check skipping iterator
  // =====================================================

  // Add a low level edge without handles
  Mesh::EdgeHandle eh_test = mesh_.edge_handle(mesh_.new_edge(Mesh::VertexHandle(),Mesh::VertexHandle()));

  he_it  = mesh_.halfedges_sbegin();
  he_end = mesh_.halfedges_end();

  unsigned int count = 0;
  bool found_36 = false;
  bool found_37 = false;

  while (he_it != he_end) {
659
    if ( he_it->idx() ==  36 )
660 661
      found_36 = true;

662
    if ( he_it->idx() ==  37 )
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
      found_37 = true;

    ++he_it;
    ++count;
  }

  EXPECT_EQ(38u,count) << "Skipping iterator count error";
  EXPECT_TRUE( found_36 )  << "Skipping iterator missed halfedge 36";
  EXPECT_TRUE( found_37 )  << "Skipping iterator missed halfedge 37";

  // =====================================================
  // Try to delete one edge with valid incidents and
  // check skipping iterator
  // =====================================================

  // delete one edge and recheck (Halfedges 4 and 5)
  mesh_.delete_edge(eh);

  he_it  = mesh_.halfedges_sbegin();
  he_end = mesh_.halfedges_end();

  count = 0;
  bool found_4  = false;
  bool found_5  = false;
  found_36 = false;
  found_37 = false;

  while (he_it != he_end) {

692
    if ( he_it->idx() ==  4 )
693 694
      found_4 = true;

695
    if ( he_it->idx() ==  5 )
696 697
      found_5 = true;

698
    if ( he_it->idx() ==  36 )
699 700
      found_36 = true;

701
    if ( he_it->idx() ==  37 )
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
      found_37 = true;

    ++he_it;
    ++count;
  }

  EXPECT_EQ(36u,count) << "Deleted valid: Skipping iterator count error";
  EXPECT_FALSE( found_4 )  << "Deleted valid: Skipping iterator hit deleted halfedge 4";
  EXPECT_FALSE( found_5 )  << "Deleted valid: Skipping iterator hit  deleted halfedge 5";
  EXPECT_TRUE( found_36 )  << "Deleted valid: Skipping iterator missed halfedge 36";
  EXPECT_TRUE( found_37 )  << "Deleted valid: Skipping iterator missed halfedge 37";

  // =====================================================
  // Try to delete one edge with invalid incidents and
  // check skipping iterator
  // =====================================================

  // delete one edge and recheck (Halfedges 4 and 5)
  mesh_.delete_edge(eh_test);

  he_it  = mesh_.halfedges_sbegin();
  he_end = mesh_.halfedges_end();

  count = 0;
  found_4  = false;
  found_5  = false;
  found_36 = false;
  found_37 = false;

  while (he_it != he_end) {

733
    if ( he_it->idx() ==  4 )
734 735
      found_4 = true;

736
    if ( he_it->idx() ==  5 )
737 738
      found_5 = true;

739
    if ( he_it->idx() ==  36 )
740 741
      found_36 = true;

742
    if ( he_it->idx() ==  37 )
743 744 745 746 747 748 749 750 751 752 753 754 755 756
      found_37 = true;

    ++he_it;
    ++count;
  }

  EXPECT_EQ(34u,count) << "Deleted invalid: Skipping iterator count error";
  EXPECT_FALSE( found_4 )  << "Deleted invalid: Skipping iterator hit deleted halfedge 4";
  EXPECT_FALSE( found_5 )  << "Deleted invalid: Skipping iterator hit deleted halfedge 5";
  EXPECT_FALSE( found_36 ) << "Deleted invalid: Skipping iterator hit deleted halfedge 36";
  EXPECT_FALSE( found_37 ) << "Deleted invalid: Skipping iterator hit deleted halfedge 37";

}

757
/*
758
 * Test with a mesh with one deleted face
759
 */
760
TEST_F(OpenMeshIterators, FaceIterEmptyMeshOneDeletedFace) {
761 762 763

  mesh_.clear();

764 765 766 767
  // request delete_face capability
  mesh_.request_vertex_status();
  mesh_.request_edge_status();
  mesh_.request_face_status();
768 769

  // Add some vertices
770
  Mesh::VertexHandle vhandle[4];
771

772 773 774
  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
775 776 777 778 779 780 781

  // Add two faces
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[0]);
782
  Mesh::FaceHandle fh = mesh_.add_face(face_vhandles);
783

784 785 786
  // Delete face but keep vertices
  bool const is_delete_isolated_vertex = false;
  mesh_.delete_face(fh, is_delete_isolated_vertex);
787

788 789 790 791 792 793
  // Test setup (Face deleted but vertices kept.
  //  1 === 2
  //  |   /
  //  |  /
  //  | /
  //  0
794

795 796
  Mesh::FaceIter f_it  = mesh_.faces_begin();
  Mesh::FaceIter f_end = mesh_.faces_end();
797

798
  EXPECT_EQ(0, f_it->idx()) << "Wrong start index in FaceIterator";
799

800
  EXPECT_EQ(1, f_end->idx()) << "Wrong end index in FaceIterator";
801

802
  ++f_it;
803
  EXPECT_EQ(1, f_it->idx()) << "Wrong end index in FaceIterator after one step";
804
  EXPECT_TRUE(f_it == f_end ) << "Iterator not at end for FaceIterator after one step";
805

806 807
  Mesh::ConstFaceIter cf_it  = mesh_.faces_begin();
  Mesh::ConstFaceIter cf_end = mesh_.faces_end();
808

809
  EXPECT_EQ(0, cf_it->idx()) << "Wrong start index in ConstFaceIterator";
810

811
  EXPECT_EQ(1, cf_end->idx()) << "Wrong end index in ConstFaceIterator";
812

813
  ++cf_it;
814
  EXPECT_EQ(1, cf_it->idx()) << "Wrong end index in ConstFaceIterator after one step";
815
  EXPECT_TRUE(cf_it == cf_end ) << "Iterator not at end for ConstFaceIterator after one step";
816 817


818 819 820
  // Same with skipping iterators:
  f_it  = mesh_.faces_sbegin();
  f_end = mesh_.faces_end();
821

822
  EXPECT_EQ(1, f_it->idx()) << "Wrong start index in FaceIterator with skipping";
823

824
  EXPECT_EQ(1, f_end->idx()) << "Wrong end index in FaceIterator with skipping";
825

826
  EXPECT_TRUE(f_it == f_end ) << "Iterator not at end for FaceIterator with skipping";
827

828 829 830
  // Same with skipping iterators:
  cf_it  = mesh_.faces_sbegin();
  cf_end = mesh_.faces_end();
831

832
  EXPECT_EQ(1, cf_it->idx()) << "Wrong start index in ConstFaceIterator with skipping";
833

834
  EXPECT_EQ(1, cf_end->idx()) << "Wrong end index in ConstFaceIterator with skipping";
835

836
  EXPECT_TRUE(cf_it == cf_end ) << "Iterator not at end for ConstFaceIterator with skipping";
837

838

839 840 841
  mesh_.release_vertex_status();
  mesh_.release_edge_status();
  mesh_.release_face_status();
842 843

}
844
}