unittests_basics.cc 61.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

using namespace OpenVolumeMesh;
9
using namespace Geometry;
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 235

/*
 * ====================================================================
 * 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));

236
    FaceHandle fI = mesh_.add_face(halfedges, true);
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 325

    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));
326
    EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, mesh_.add_cell(halffaces, true));
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
}

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));

403
    EXPECT_NE(HexahedralMesh::InvalidCellHandle, mesh_.add_cell(chfaces, true));
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 479
}

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));

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

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

    generatePolyhedralMesh(mesh_);

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

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

    generatePolyhedralMesh(mesh_);

    // Add invalid cell
    std::vector<HalfFaceHandle> hfaces;
Max Lyon's avatar
Max Lyon committed
496 497 498
    hfaces.push_back(HalfFaceHandle(1)); hfaces.push_back(HalfFaceHandle(5));
    hfaces.push_back(HalfFaceHandle(7)); hfaces.push_back(HalfFaceHandle(9));
    hfaces.push_back(HalfFaceHandle(10)); hfaces.push_back(HalfFaceHandle(21));
499
    CellHandle i_cell = mesh_.add_cell(hfaces, true);
500 501 502

    EXPECT_EQ(PolyhedralMesh::InvalidCellHandle, i_cell);

Max Lyon's avatar
Max Lyon committed
503 504 505 506 507 508
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(HalfFaceHandle(1)));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(HalfFaceHandle(2)));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(HalfFaceHandle(5)));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(HalfFaceHandle(7)));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(HalfFaceHandle(9)));
    EXPECT_EQ(CellHandle(0), mesh_.incident_cell(HalfFaceHandle(10)));
509

Max Lyon's avatar
Max Lyon committed
510 511 512 513 514 515
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(HalfFaceHandle(3)));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(HalfFaceHandle(12)));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(HalfFaceHandle(15)));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(HalfFaceHandle(17)));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(HalfFaceHandle(19)));
    EXPECT_EQ(CellHandle(1), mesh_.incident_cell(HalfFaceHandle(20)));
516 517

    // Test adjacency function
Max Lyon's avatar
Max Lyon committed
518
    HalfFaceHandle ad_hf1 = mesh_.adjacent_halfface_in_cell(HalfFaceHandle(1), HalfEdgeHandle(3));
519 520 521
    // Should be halfface 5
    EXPECT_EQ(HalfFaceHandle(5), ad_hf1);

Max Lyon's avatar
Max Lyon committed
522
    HalfFaceHandle ad_hf2 = mesh_.adjacent_halfface_in_cell(HalfFaceHandle(1), HalfEdgeHandle(7));
523 524 525
    // Should be halfface 7
    EXPECT_EQ(HalfFaceHandle(7), ad_hf2);

Max Lyon's avatar
Max Lyon committed
526
    HalfFaceHandle ad_hf3 = mesh_.adjacent_halfface_in_cell(HalfFaceHandle(5), HalfEdgeHandle(24));
527 528 529
    // Should be invalid
    EXPECT_EQ(PolyhedralMesh::InvalidHalfFaceHandle, ad_hf3);

Max Lyon's avatar
Max Lyon committed
530
    HalfFaceHandle ad_hf4 = mesh_.adjacent_halfface_in_cell(HalfFaceHandle(12), HalfEdgeHandle(24));
531 532 533
    // Should be invalid
    EXPECT_EQ(HalfFaceHandle(20), ad_hf4);

Max Lyon's avatar
Max Lyon committed
534
    HalfFaceHandle ad_hf5 = mesh_.adjacent_halfface_in_cell(HalfFaceHandle(0), HalfEdgeHandle(0));
535 536 537 538 539 540 541 542 543 544 545 546 547
    // 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_);

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

    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();

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

562 563 564 565 566
    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]);

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

573 574 575 576 577 578 579 580 581 582
    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]);

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

589 590 591 592 593
    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]);

594 595
    // Should be positive y-axis
    n = normals[FaceHandle(5)];
596 597 598
    EXPECT_DOUBLE_EQ(-n_y[0], n[0]);
    EXPECT_DOUBLE_EQ(-n_y[1], n[1]);
    EXPECT_DOUBLE_EQ(-n_y[2], n[2]);
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
}

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
634
TEST_F(PolyhedralMeshBase, PolyhedralMeshColorTest) {
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 675

    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]);
}

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

    generatePolyhedralMesh(mesh_);

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

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 689
    }

    for(VertexIter v_it = mesh_.v_iter(); v_it.valid(); ++v_it) {
        Vec3d t;
690
        t = vp[v_it->idx()];
691 692 693 694 695 696
        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));
697 698
    vp[vh.idx()] = Vec3d(0.0);
    Vec3d p = vp[vh.idx()];
699 700 701 702 703 704
    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");

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

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

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

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

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

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

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

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

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

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);
}

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

    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));
    }
}

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 821
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) {
822
            EXPECT_GT(nihfs[i].count(*hf_it), 0u);
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 862
        }
    }
}

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) {
863
        EXPECT_GT(nhes0.count(*he_it), 0u);
864 865 866 867
    }

    for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes1.begin(),
            he_end = hes1.end(); he_it != he_end; ++he_it) {
868
        EXPECT_GT(nhes1.count(*he_it), 0u);
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 950
    }
}

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) {
951
            EXPECT_GT(nihfs[i].count(*hf_it), 0u);
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 1005
        }
    }
}

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) {
1006
        EXPECT_GT(nhes0.count(*he_it), 0u);
1007 1008 1009 1010
    }

    for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes1.begin(),
            he_end = hes1.end(); he_it != he_end; ++he_it) {
1011
        EXPECT_GT(nhes1.count(*he_it), 0u);
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 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
TEST_F(PolyhedralMeshBase, DeleteLastVertexTestBU) {

    generatePolyhedralMesh(mesh_);

    for(OpenVolumeMesh::HalfEdgeIter he_it = mesh_.halfedges_begin();
            he_it != mesh_.halfedges_end(); ++he_it) {

        const VertexHandle& fromVertex = mesh_.halfedge(*he_it).from_vertex();
        const VertexHandle& toVertex = mesh_.halfedge(*he_it).to_vertex();

        EXPECT_LE(fromVertex.idx(), 11);
        EXPECT_LE(toVertex.idx(), 11);
    }

    mesh_.delete_vertex(VertexHandle(11));

    for(OpenVolumeMesh::HalfEdgeIter he_it = mesh_.halfedges_begin();
            he_it != mesh_.halfedges_end(); ++he_it) {

        const VertexHandle& fromVertex = mesh_.halfedge(*he_it).from_vertex();
        const VertexHandle& toVertex = mesh_.halfedge(*he_it).to_vertex();

        EXPECT_LE(fromVertex.idx(), 10);
        EXPECT_LE(toVertex.idx(), 10);
    }
}

TEST_F(PolyhedralMeshBase, DeleteLastEdgeTestBU) {

    generatePolyhedralMesh(mesh_);

    for(OpenVolumeMesh::HalfFaceIter f_it = mesh_.halffaces_begin();
            f_it != mesh_.halffaces_end(); ++f_it) {

        std::vector<HalfEdgeHandle> hes = mesh_.halfface(*f_it).halfedges();
        for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin();
                he_it != hes.end(); ++he_it) {
            EXPECT_LE(he_it->idx(), 39);
        }
    }

    mesh_.delete_edge(EdgeHandle(19));

    for(OpenVolumeMesh::HalfFaceIter f_it = mesh_.halffaces_begin();
            f_it != mesh_.halffaces_end(); ++f_it) {

        std::vector<HalfEdgeHandle> hes = mesh_.halfface(*f_it).halfedges();
        for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin();
                he_it != hes.end(); ++he_it) {
            EXPECT_LE(he_it->idx(), 37);
        }
    }
}

TEST_F(PolyhedralMeshBase, DeleteLastFaceTestBU) {

    generatePolyhedralMesh(mesh_);

    for(OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
            c_it != mesh_.cells_end(); ++c_it) {

        std::vector<HalfFaceHandle> hfs = mesh_.cell(*c_it).halffaces();
        for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin();
                hf_it != hfs.end(); ++hf_it) {
            EXPECT_LE(hf_it->idx(), 21);
            EXPECT_LE(mesh_.opposite_halfface_handle(*hf_it).idx(), 21);
        }
    }

    mesh_.delete_face(FaceHandle(10));

    for(OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
            c_it != mesh_.cells_end(); ++c_it) {

        std::vector<HalfFaceHandle> hfs = mesh_.cell(*c_it).halffaces();
        for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin();
                hf_it != hfs.end(); ++hf_it) {
            EXPECT_LE(hf_it->idx(), 19);
            EXPECT_LE(mesh_.opposite_halfface_handle(*hf_it).idx(), 19);
        }
    }
}

TEST_F(PolyhedralMeshBase, DeleteLastVertexTestNoBU) {

    generatePolyhedralMesh(mesh_);

    mesh_.enable_bottom_up_incidences(false);

    for(OpenVolumeMesh::HalfEdgeIter he_it = mesh_.halfedges_begin();
            he_it != mesh_.halfedges_end(); ++he_it) {

        const VertexHandle& fromVertex = mesh_.halfedge(*he_it).from_vertex();
        const VertexHandle& toVertex = mesh_.halfedge(*he_it).to_vertex();

        EXPECT_LE(fromVertex.idx(), 11);
        EXPECT_LE(toVertex.idx(), 11);
    }

    mesh_.delete_vertex(VertexHandle(11));

    for(OpenVolumeMesh::HalfEdgeIter he_it = mesh_.halfedges_begin();
            he_it != mesh_.halfedges_end(); ++he_it) {

        const VertexHandle& fromVertex = mesh_.halfedge(*he_it).from_vertex();
        const VertexHandle& toVertex = mesh_.halfedge(*he_it).to_vertex();

        EXPECT_LE(fromVertex.idx(), 10);
        EXPECT_LE(toVertex.idx(), 10);
    }
}

TEST_F(PolyhedralMeshBase, DeleteLastEdgeTestNoBU) {

    generatePolyhedralMesh(mesh_);

    mesh_.enable_bottom_up_incidences(false);

    for(OpenVolumeMesh::HalfFaceIter f_it = mesh_.halffaces_begin();
            f_it != mesh_.halffaces_end(); ++f_it) {

        std::vector<HalfEdgeHandle> hes = mesh_.halfface(*f_it).halfedges();
        for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin();
                he_it != hes.end(); ++he_it) {
            EXPECT_LE(he_it->idx(), 39);
        }
    }

    mesh_.delete_edge(EdgeHandle(19));

    for(OpenVolumeMesh::HalfFaceIter f_it = mesh_.halffaces_begin();
            f_it != mesh_.halffaces_end(); ++f_it) {

        std::vector<HalfEdgeHandle> hes = mesh_.halfface(*f_it).halfedges();
        for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin();
                he_it != hes.end(); ++he_it) {
            EXPECT_LE(he_it->idx(), 37);
        }
    }
}

TEST_F(PolyhedralMeshBase, DeleteLastFaceTestNoBU) {

    generatePolyhedralMesh(mesh_);

    mesh_.enable_bottom_up_incidences(false);

    for(OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
            c_it != mesh_.cells_end(); ++c_it) {

        std::vector<HalfFaceHandle> hfs = mesh_.cell(*c_it).halffaces();
        for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin();
                hf_it != hfs.end(); ++hf_it) {
            EXPECT_LE(hf_it->idx(), 21);
            EXPECT_LE(mesh_.opposite_halfface_handle(*hf_it).idx(), 21);
        }
    }

    mesh_.delete_face(FaceHandle(10));

    for(OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
            c_it != mesh_.cells_end(); ++c_it) {

        std::vector<HalfFaceHandle> hfs = mesh_.cell(*c_it).halffaces();
        for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin();
                hf_it != hfs.end(); ++hf_it) {
            EXPECT_LE(hf_it->idx(), 19);
            EXPECT_LE(mesh_.opposite_halfface_handle(*hf_it).idx(), 19);
        }
    }
}

1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
/*
 * Hexahedral mesh tests
 */

TEST_F(HexahedralMeshBase, SimpleHexMeshNavigation) {

    generateHexahedralMesh(mesh_);

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

    EXPECT_EQ(1,  mesh_.xfront_halfface(CellHandle(0)));
    EXPECT_EQ(2, mesh_.xback_halfface(CellHandle(0)));
    EXPECT_EQ(5,  mesh_.yfront_halfface(CellHandle(0)));
    EXPECT_EQ(6,  mesh_.yback_halfface(CellHandle(0)));
    EXPECT_EQ(8,  mesh_.zfront_halfface(CellHandle(0)));
    EXPECT_EQ(11,  mesh_.zback_halfface(CellHandle(0)));

    EXPECT_EQ(12, mesh_.opposite_halfface_handle_in_cell(
            HalfFaceHandle(3), CellHandle(1)));

    EXPECT_EQ(HalfFaceHandle(20), mesh_.adjacent_halfface_on_sheet(
            HalfFaceHandle(9), HalfEdgeHandle(12)));
    EXPECT_EQ(HalfFaceHandle(21), mesh_.adjacent_halfface_on_sheet(
            HalfFaceHandle(8), HalfEdgeHandle(12)));

Max Lyon's avatar
Max Lyon committed
1215
    HexahedralMesh::CellSheetCellIter csc_it = mesh_.csc_iter(CellHandle(0), HexahedralMesh::YF);
1216 1217
    EXPECT_EQ(CellHandle(1), *csc_it);

Max Lyon's avatar
Max Lyon committed
1218
    HexahedralMesh::HalfFaceSheetHalfFaceIter hfshf_it = mesh_.hfshf_iter(HalfFaceHandle(5));
1219
    EXPECT_EQ(HalfFaceHandle(15), *hfshf_it);
Max Lyon's avatar
Max Lyon committed
1220
    hfshf_it = mesh_.hfshf_iter(HalfFaceHandle(6));
1221 1222 1223
    EXPECT_EQ(HalfFaceHandle(16), *hfshf_it);
}

1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
TEST_F(HexahedralMeshBase, BottomUpIncidenceUpdate1) {

    generateHexahedralMesh(mesh_);

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

    mesh_.delete_vertex(VertexHandle(0));

    EXPECT_EQ(11u, mesh_.n_vertices());
    EXPECT_EQ(17u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_faces());
    EXPECT_EQ(1u, mesh_.n_cells());

    HexVertexIter hv_it = mesh_.hv_iter(CellHandle(0));

    EXPECT_EQ(3, hv_it->idx()); ++hv_it;
    EXPECT_EQ(4, hv_it->idx()); ++hv_it;
    EXPECT_EQ(5, hv_it->idx()); ++hv_it;
    EXPECT_EQ(6, hv_it->idx()); ++hv_it;
    EXPECT_EQ(7, hv_it->idx()); ++hv_it;
    EXPECT_EQ(10, hv_it->idx()); ++hv_it;
    EXPECT_EQ(9, hv_it->idx()); ++hv_it;
    EXPECT_EQ(8, hv_it->idx());
}

1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
TEST_F(HexahedralMeshBase, GarbageCollectionTest1) {

    generateHexahedralMesh(mesh_);

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

    StatusAttrib status(mesh_);

1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
    HexVertexIter hv_it = mesh_.hv_iter(CellHandle(1));

    EXPECT_EQ(4, hv_it->idx()); ++hv_it;
    EXPECT_EQ(5, hv_it->idx()); ++hv_it;
    EXPECT_EQ(6, hv_it->idx()); ++hv_it;
    EXPECT_EQ(7, hv_it->idx()); ++hv_it;
    EXPECT_EQ(8, hv_it->idx()); ++hv_it;
    EXPECT_EQ(11, hv_it->idx()); ++hv_it;
    EXPECT_EQ(10, hv_it->idx()); ++hv_it;
    EXPECT_EQ(9, hv_it->idx());

1274 1275 1276 1277 1278 1279 1280 1281 1282
    status[VertexHandle(0)].set_deleted(true);

    status.garbage_collection(false);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(11u, mesh_.n_vertices());
    EXPECT_EQ(17u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_faces());

1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
    hv_it = mesh_.hv_iter(CellHandle(0));

    EXPECT_EQ(3, hv_it->idx()); ++hv_it;
    EXPECT_EQ(4, hv_it->idx()); ++hv_it;
    EXPECT_EQ(5, hv_it->idx()); ++hv_it;
    EXPECT_EQ(6, hv_it->idx()); ++hv_it;
    EXPECT_EQ(7, hv_it->idx()); ++hv_it;
    EXPECT_EQ(10, hv_it->idx()); ++hv_it;
    EXPECT_EQ(9, hv_it->idx()); ++hv_it;
    EXPECT_EQ(8, hv_it->idx());

1294 1295 1296 1297 1298 1299
    status.garbage_collection(true);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(8u, mesh_.n_vertices());
    EXPECT_EQ(12u, mesh_.n_edges());
    EXPECT_EQ(6u, mesh_.n_faces());
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310

    hv_it = mesh_.hv_iter(CellHandle(0));

    EXPECT_EQ(0, hv_it->idx()); ++hv_it;
    EXPECT_EQ(1, hv_it->idx()); ++hv_it;
    EXPECT_EQ(2, hv_it->idx()); ++hv_it;
    EXPECT_EQ(3, hv_it->idx()); ++hv_it;
    EXPECT_EQ(4, hv_it->idx()); ++hv_it;
    EXPECT_EQ(7, hv_it->idx()); ++hv_it;
    EXPECT_EQ(6, hv_it->idx()); ++hv_it;
    EXPECT_EQ(5, hv_it->idx());
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
}

TEST_F(HexahedralMeshBase, GarbageCollectionTest2) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[VertexHandle(0)].set_deleted(true);

    status.garbage_collection(false);

    status.garbage_collection(false);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(11u, mesh_.n_vertices());
    EXPECT_EQ(17u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_faces());
}

TEST_F(HexahedralMeshBase, GarbageCollectionTest3) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[EdgeHandle(0)].set_deleted(true);

    status.garbage_collection(false);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(12u, mesh_.n_vertices());
    EXPECT_EQ(19u, mesh_.n_edges());
    EXPECT_EQ(9u, mesh_.n_faces());
}

TEST_F(HexahedralMeshBase, GarbageCollectionTest4) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[EdgeHandle(5)].set_deleted(true);

    status.garbage_collection(false);

    EXPECT_EQ(0u, mesh_.n_cells());
    EXPECT_EQ(12u, mesh_.n_vertices());
    EXPECT_EQ(19u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_faces());
}

1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
TEST_F(HexahedralMeshBase, GarbageCollectionTest5) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[EdgeHandle(0)].set_deleted(true);
    status[EdgeHandle(1)].set_deleted(true);
    status[EdgeHandle(2)].set_deleted(true);

    status.garbage_collection(true);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(8u, mesh_.n_vertices());
    EXPECT_EQ(12u, mesh_.n_edges());
    EXPECT_EQ(6u, mesh_.n_faces());
}

1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness1) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[VertexHandle(0)].set_deleted(true);

    status.garbage_collection(true);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(6u, mesh_.n_faces());
    EXPECT_EQ(12u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_vertices());
}

TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness2) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[EdgeHandle(0)].set_deleted(true);

    status.garbage_collection(true);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(6u, mesh_.n_faces());
    EXPECT_EQ(12u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_vertices());
}

TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness3) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[FaceHandle(0)].set_deleted(true);

    status.garbage_collection(true);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(6u, mesh_.n_faces());
    EXPECT_EQ(12u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_vertices());
}

TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness4) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[CellHandle(0)].set_deleted(true);

    status.garbage_collection(true);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(6u, mesh_.n_faces());
    EXPECT_EQ(12u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_vertices());
}

TEST_F(HexahedralMeshBase, GarbageCollectionTestManifoldness5) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[EdgeHandle(5)].set_deleted(true);

    status.garbage_collection(false);

    EXPECT_EQ(0u, mesh_.n_cells());
    EXPECT_EQ(8u, mesh_.n_faces());
    EXPECT_EQ(19u, mesh_.n_edges());
    EXPECT_EQ(12u, mesh_.n_vertices());

    status.garbage_collection(true);

    EXPECT_EQ(0u, mesh_.n_cells());
    EXPECT_EQ(0u, mesh_.n_faces());
    EXPECT_EQ(0u, mesh_.n_edges());
    EXPECT_EQ(0u, mesh_.n_vertices());
}

1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487
TEST_F(HexahedralMeshBase, GarbageCollectionTestTrackVertexHandles) {

    generateHexahedralMesh(mesh_);

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

    StatusAttrib status(mesh_);

    status[VertexHandle(0)].set_deleted(true);

    std::vector<VertexHandle> vhs;
    std::vector<VertexHandle*> track_vhs;
    std::vector<HalfEdgeHandle*> hh_empty;
    std::vector<HalfFaceHandle*> hfh_empty;
    std::vector<CellHandle*> ch_empty;

    OpenVolumeMesh::VertexIter v_it = mesh_.vertices_begin();
1488
    for (; v_it != mesh_.vertices_end(); ++v_it)
1489 1490 1491 1492 1493 1494 1495 1496
        vhs.push_back(*v_it);

    for (std::vector<VertexHandle>::iterator it = vhs.begin(); it != vhs.end(); ++it)
        track_vhs.push_back(&(*it));

    status.garbage_collection(track_vhs, hh_empty, hfh_empty, ch_empty, false);

    EXPECT_EQ(vhs[0], -1);
1497
    EXPECT_EQ(vhs[11], 10);
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(11u, mesh_.n_vertices());
    EXPECT_EQ(17u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_faces());
}

TEST_F(HexahedralMeshBase, GarbageCollectionTestTrackHalfedgeHandles) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[EdgeHandle(5)].set_deleted(true);

    std::vector<HalfEdgeHandle> hhs;
    std::vector<VertexHandle*> vh_empty;
    std::vector<HalfEdgeHandle*> track_hh;
    std::vector<HalfFaceHandle*> hfh_empty;
    std::vector<CellHandle*> ch_empty;

    OpenVolumeMesh::HalfEdgeIter hh_it = mesh_.halfedges_begin();
1520
    for (; hh_it != mesh_.halfedges_end(); ++hh_it)
1521 1522 1523 1524 1525 1526 1527
        hhs.push_back(*hh_it);

    for (std::vector<HalfEdgeHandle>::iterator it = hhs.begin(); it != hhs.end(); ++it)
        track_hh.push_back(&(*it));

    status.garbage_collection(vh_empty, track_hh, hfh_empty, ch_empty, false);

1528
    EXPECT_EQ(hhs[9], 9);
1529 1530
    EXPECT_EQ(hhs[10], -1);
    EXPECT_EQ(hhs[11], -1);
1531 1532
    EXPECT_EQ(hhs[12], 10);
    EXPECT_EQ(hhs[39], 37);
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564

    EXPECT_EQ(0u, mesh_.n_cells());
    EXPECT_EQ(8u, mesh_.n_faces());
    EXPECT_EQ(19u, mesh_.n_edges());
    EXPECT_EQ(12u, mesh_.n_vertices());

    status.garbage_collection(vh_empty, track_hh, hfh_empty, ch_empty, true);

    for (std::vector<HalfEdgeHandle>::iterator it = hhs.begin(); it != hhs.end(); ++it)
        EXPECT_EQ(it->idx(), -1);

    EXPECT_EQ(0u, mesh_.n_cells());
    EXPECT_EQ(0u, mesh_.n_faces());
    EXPECT_EQ(0u, mesh_.n_edges());
    EXPECT_EQ(0u, mesh_.n_vertices());
}

TEST_F(HexahedralMeshBase, GarbageCollectionTestTrackHalffaceHandles) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[FaceHandle(0)].set_deleted(true);

    std::vector<HalfFaceHandle> hfhs;
    std::vector<VertexHandle*> vh_empty;
    std::vector<HalfEdgeHandle*> hh_empty;
    std::vector<HalfFaceHandle*> track_hfh;
    std::vector<CellHandle*> ch_empty;

    OpenVolumeMesh::HalfFaceIter hfh_it = mesh_.halffaces_begin();
1565
    for (; hfh_it != mesh_.halffaces_end(); ++hfh_it)
1566 1567 1568 1569 1570 1571 1572 1573 1574
        hfhs.push_back(*hfh_it);

    for (std::vector<HalfFaceHandle>::iterator it = hfhs.begin(); it != hfhs.end(); ++it)
        track_hfh.push_back(&(*it));

    status.garbage_collection(vh_empty, hh_empty, track_hfh, ch_empty, true);

    EXPECT_EQ(hfhs[0], -1);
    EXPECT_EQ(hfhs[1], -1);
1575 1576 1577
    EXPECT_EQ(hfhs[2], 0);
    EXPECT_EQ(hfhs[3], 1);
    EXPECT_EQ(hfhs[21], 11);
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600


    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(6u, mesh_.n_faces());
    EXPECT_EQ(12u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_vertices());
}

TEST_F(HexahedralMeshBase, GarbageCollectionTestTrackCellHandles) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    status[CellHandle(0)].set_deleted(true);

    std::vector<CellHandle> chs;
    std::vector<VertexHandle*> vh_empty;
    std::vector<HalfEdgeHandle*> hh_empty;
    std::vector<HalfFaceHandle*> hfh_empty;
    std::vector<CellHandle*> track_ch;

    OpenVolumeMesh::CellIter c_it = mesh_.cells_begin();
1601
    for (; c_it != mesh_.cells_end(); ++c_it)
1602 1603 1604 1605 1606 1607 1608 1609
        chs.push_back(*c_it);

    for (std::vector<CellHandle>::iterator it = chs.begin(); it != chs.end(); ++it)
        track_ch.push_back(&(*it));

    status.garbage_collection(vh_empty, hh_empty, hfh_empty, track_ch, true);

    EXPECT_EQ(chs[0], -1);
1610
    EXPECT_EQ(chs[1], 0);
1611 1612 1613 1614 1615 1616 1617

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(6u, mesh_.n_faces());
    EXPECT_EQ(12u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_vertices());
}

1618 1619 1620 1621 1622 1623 1624 1625
TEST_F(HexahedralMeshBase, GarbageCollectionTestProps1) {

    generateHexahedralMesh(mesh_);

    StatusAttrib status(mesh_);

    FacePropertyT<int> fprop = mesh_.request_face_property<int>("FProp");

1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648
    FaceHandle fh0(0);
    FaceHandle fh1(1);
    FaceHandle fh2(2);
    FaceHandle fh3(3);
    FaceHandle fh4(4);
    FaceHandle fh5(5);
    FaceHandle fh6(6);
    FaceHandle fh7(7);
    FaceHandle fh8(8);
    FaceHandle fh9(9);
    FaceHandle fh10(10);

    fprop[fh0] = 11;
    fprop[fh1] = 10;
    fprop[fh2] = 9;
    fprop[fh3] = 8;
    fprop[fh4] = 7;
    fprop[fh5] = 6;
    fprop[fh6] = 5;
    fprop[fh7] = 4;
    fprop[fh8] = 3;
    fprop[fh9] = 2;
    fprop[fh10] = 1;
1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660

    status[VertexHandle(0)].set_deleted(true);

    status.garbage_collection(false);

    EXPECT_EQ(1u, mesh_.n_cells());
    EXPECT_EQ(11u, mesh_.n_vertices());
    EXPECT_EQ(17u, mesh_.n_edges());
    EXPECT_EQ(8u, mesh_.n_faces());

    std::set<int> fprops_i;
    for(FaceIter f_it = mesh_.f_iter(); f_it.valid(); ++f_it) {
1661
        fprops_i.insert(fprop[f_it->idx()]);
1662 1663
    }

Mike Kremer's avatar