| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2000-2022 Inria | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions are met: | ||
| 7 | * | ||
| 8 | * * Redistributions of source code must retain the above copyright notice, | ||
| 9 | * this list of conditions and the following disclaimer. | ||
| 10 | * * Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | * this list of conditions and the following disclaimer in the documentation | ||
| 12 | * and/or other materials provided with the distribution. | ||
| 13 | * * Neither the name of the ALICE Project-Team nor the names of its | ||
| 14 | * contributors may be used to endorse or promote products derived from this | ||
| 15 | * software without specific prior written permission. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | * | ||
| 29 | * Contact: Bruno Levy | ||
| 30 | * | ||
| 31 | * https://www.inria.fr/fr/bruno-levy | ||
| 32 | * | ||
| 33 | * Inria, | ||
| 34 | * Domaine de Voluceau, | ||
| 35 | * 78150 Le Chesnay - Rocquencourt | ||
| 36 | * FRANCE | ||
| 37 | * | ||
| 38 | */ | ||
| 39 | |||
| 40 | #include <exploragram/hexdom/cavity.h> | ||
| 41 | #include <exploragram/hexdom/hex.h> | ||
| 42 | #include <exploragram/hexdom/PGP.h> | ||
| 43 | #include <exploragram/hexdom/basic.h> | ||
| 44 | #include <exploragram/hexdom/extra_connectivity.h> | ||
| 45 | #include <geogram/numerics/matrix_util.h> | ||
| 46 | #include <geogram/basic/permutation.h> | ||
| 47 | #include <algorithm> | ||
| 48 | #include <geogram/mesh/triangle_intersection.h> | ||
| 49 | #include <geogram/mesh/mesh_tetrahedralize.h> | ||
| 50 | #include <geogram/delaunay/delaunay.h> | ||
| 51 | |||
| 52 | #include <geogram/points/nn_search.h> | ||
| 53 | #include <geogram/points/colocate.h> | ||
| 54 | #include <queue> | ||
| 55 | |||
| 56 | #include <exploragram/hexdom/mesh_inspector.h> | ||
| 57 | #include <exploragram/hexdom/intersect_tools.h> | ||
| 58 | #include <exploragram/hexdom/polygon.h> | ||
| 59 | |||
| 60 | namespace GEO { | ||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | ✗ | void merge_hex_boundary_and_quadtri(Mesh* hex, Mesh* quad) { | |
| 68 | ✗ | if (hex->cells.nb() == 0) return; | |
| 69 | ✗ | double eps = 1e-3*get_cell_average_edge_size(hex); | |
| 70 | |||
| 71 | // add hex surface to quadt | ||
| 72 | ✗ | index_t off_v = quad->vertices.create_vertices(hex->vertices.nb()); | |
| 73 | ✗ | FOR(v, hex->vertices.nb()) X(quad)[off_v + v] = X(hex)[v]; | |
| 74 | |||
| 75 | ✗ | index_t off_f = quad->facets.create_facets(hex->facets.nb(), 4); | |
| 76 | ✗ | FOR(f, hex->facets.nb()) FOR(fc, 4) | |
| 77 | ✗ | quad->facets.set_vertex(off_f + f, (3 - fc), off_v + hex->facets.vertex(f, fc)); | |
| 78 | |||
| 79 | |||
| 80 | // merge vertices from hex faces to quatri vertices | ||
| 81 | |||
| 82 | { | ||
| 83 | ✗ | vector<index_t> to_kill(quad->vertices.nb(), 0); | |
| 84 | ✗ | vector<index_t> old2new(quad->vertices.nb()); | |
| 85 | ✗ | FOR(v, quad->vertices.nb()) old2new[v] = v; | |
| 86 | |||
| 87 | ✗ | NearestNeighborSearch_var NN = NearestNeighborSearch::create(3); | |
| 88 | ✗ | NN->set_points(off_v, quad->vertices.point_ptr(0)); | |
| 89 | |||
| 90 | ✗ | for (index_t v = off_v; v < quad->vertices.nb(); v++) { | |
| 91 | ✗ | index_t nearest = NN->get_nearest_neighbor(X(quad)[v].data()); | |
| 92 | ✗ | if ((X(quad)[v] - X(quad)[nearest]).length2() == 0) { | |
| 93 | ✗ | old2new[v] = nearest; | |
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | ✗ | FOR(f, quad->facets.nb()) FOR(fv, quad->facets.nb_vertices(f)) | |
| 98 | ✗ | quad->facets.set_vertex(f, fv, old2new[quad->facets.vertex(f, fv)]); | |
| 99 | ✗ | FOR(v, quad->vertices.nb()) if (old2new[v] != v) to_kill[v] = NOT_AN_ID; | |
| 100 | ✗ | quad->vertices.delete_elements(to_kill); | |
| 101 | ✗ | } | |
| 102 | |||
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | // remove useless quads | ||
| 107 | ✗ | vector<vec3> f_bary(quad->facets.nb(), vec3(0, 0, 0)); | |
| 108 | |||
| 109 | ✗ | FOR(f, quad->facets.nb()) FOR(fc, quad->facets.nb_vertices(f)) | |
| 110 | ✗ | f_bary[f] = f_bary[f] + (1. / quad->facets.nb_vertices(f))*quad->vertices.point(quad->facets.vertex(f, fc)); | |
| 111 | |||
| 112 | ✗ | vector<index_t> bary_old2new(quad->facets.nb()); | |
| 113 | ✗ | Geom::colocate((double*)(f_bary.data()), 3, quad->facets.nb(), bary_old2new, eps); | |
| 114 | |||
| 115 | ✗ | vector<index_t> to_kill(quad->facets.nb(), 0); | |
| 116 | ✗ | FOR(f, quad->facets.nb()) if (bary_old2new[f] != f) { | |
| 117 | ✗ | if (quad->facets.nb_vertices(f) != 4) continue; | |
| 118 | ✗ | if (quad->facets.nb_vertices(bary_old2new[f]) != 4) continue; | |
| 119 | |||
| 120 | ✗ | bool have_same_vertices = true; | |
| 121 | ✗ | FOR(fv1, quad->facets.nb_vertices(f)) { | |
| 122 | ✗ | bool isin = false; | |
| 123 | ✗ | FOR(fv2, quad->facets.nb_vertices(bary_old2new[f])) { | |
| 124 | ✗ | isin = isin || quad->facets.vertex(f, fv1) == quad->facets.vertex(bary_old2new[f], fv2); | |
| 125 | } | ||
| 126 | ✗ | have_same_vertices = have_same_vertices && isin; | |
| 127 | } | ||
| 128 | ✗ | if (!have_same_vertices) continue; | |
| 129 | ✗ | to_kill[f] = true; | |
| 130 | ✗ | to_kill[bary_old2new[f]] = true; | |
| 131 | } | ||
| 132 | ✗ | quad->facets.delete_elements(to_kill); | |
| 133 | ✗ | create_non_manifold_facet_adjacence(quad); | |
| 134 | |||
| 135 | |||
| 136 | ✗ | } | |
| 137 | |||
| 138 | |||
| 139 | } | ||
| 140 |