| 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 | #ifndef GEOGRAM_MESH_MESH_TETRAHEDRALIZE | ||
| 41 | #define GEOGRAM_MESH_MESH_TETRAHEDRALIZE | ||
| 42 | |||
| 43 | #include <geogram/basic/common.h> | ||
| 44 | |||
| 45 | /** | ||
| 46 | * \file geogram/mesh/mesh_tetrahedralize.h | ||
| 47 | * \brief Functions for filling a surface mesh with tetrahedra. | ||
| 48 | */ | ||
| 49 | |||
| 50 | namespace GEO { | ||
| 51 | |||
| 52 | class Mesh; | ||
| 53 | |||
| 54 | /** | ||
| 55 | * \brief Parameters for mesh_tetrahedralize() | ||
| 56 | */ | ||
| 57 | struct MeshTetrahedralizeParameters { | ||
| 58 | /** | ||
| 59 | * \brief Tentatively fix mesh before tetrahedralization | ||
| 60 | * \details Merges duplicated vertices, fills small holes, | ||
| 61 | * removes intersections and extracts external boundary. | ||
| 62 | */ | ||
| 63 | bool preprocess = false; | ||
| 64 | /** | ||
| 65 | * \brief merge coplanar facets | ||
| 66 | */ | ||
| 67 | bool preprocess_merge_coplanar_facets = false; | ||
| 68 | /** | ||
| 69 | * \brief Maximum distance for merging vertices if preprocess is set | ||
| 70 | * \details In percent of bounding box diagonal | ||
| 71 | */ | ||
| 72 | double preprocess_merge_vertices_epsilon = 0.001; | ||
| 73 | /** | ||
| 74 | * \brief Maximum area for filling a hole if preprocess is set | ||
| 75 | * \details In percent of total surface mesh area | ||
| 76 | */ | ||
| 77 | double preprocess_fill_hole_max_area = 0.01; | ||
| 78 | /** | ||
| 79 | * \brief Inserts additional vertices to improve mesh quality | ||
| 80 | */ | ||
| 81 | bool refine = true; | ||
| 82 | /** | ||
| 83 | * \brief Desired mesh quality | ||
| 84 | * \details it is typically in [1.0, 2.0], it specifies | ||
| 85 | * the desired quality of mesh elements (1.0 means maximum | ||
| 86 | * quality, and generates a higher number of elements). | ||
| 87 | */ | ||
| 88 | double refine_quality = 2.0; | ||
| 89 | /** | ||
| 90 | * \brief keep internal boundaries and what is inside | ||
| 91 | * \details If set, then all internal regions are kept, and | ||
| 92 | * a region cell attribute is created, else only tetrahedra in the | ||
| 93 | * outermost region are kept. | ||
| 94 | */ | ||
| 95 | bool keep_regions = false; | ||
| 96 | /** | ||
| 97 | * \brief display status messages | ||
| 98 | */ | ||
| 99 | bool verbose = true; | ||
| 100 | }; | ||
| 101 | |||
| 102 | /** | ||
| 103 | * \brief Fills a closed surface mesh with tetrahedra. | ||
| 104 | * \details A constrained Delaunay triangulation algorithm | ||
| 105 | * needs to be interfaced (e.g., compiling with tetgen support). | ||
| 106 | * \param [in,out] M a reference to the input surface mesh. On exit, | ||
| 107 | * the (optionally pre-processed) same surface mesh filled with | ||
| 108 | * tetrahedra | ||
| 109 | * \param [in] params a reference to a MeshTetrahedralizeParameters | ||
| 110 | * \retval true if the mesh was successfuly tetrahedralized | ||
| 111 | * \retval false otherwise | ||
| 112 | * \note needs a constrained Delaunay algorithm to work (geogram needs | ||
| 113 | * to be compiled with mg-tetra or tetgen). | ||
| 114 | */ | ||
| 115 | bool GEOGRAM_API mesh_tetrahedralize( | ||
| 116 | Mesh& M, const MeshTetrahedralizeParameters& params | ||
| 117 | ); | ||
| 118 | |||
| 119 | /** | ||
| 120 | * \brief Fills a closed surface mesh with tetrahedra. | ||
| 121 | * \details A constrained Delaunay triangulation algorithm | ||
| 122 | * needs to be interfaced (e.g., compiling with tetgen support). | ||
| 123 | * \param [in,out] M a reference to a mesh | ||
| 124 | * \param [in] preprocess if true, the surface mesh is preprocessed | ||
| 125 | * to fix some defects (small gaps and intersections). If preprocess | ||
| 126 | * is set and borders are detected after preprocessing, then the function | ||
| 127 | * returns false. If preprocess is set to false, then the caller is | ||
| 128 | * supposed to provide a correct set of input constraints (that may have | ||
| 129 | * dangling borders / internal constraints). | ||
| 130 | * \param [in] refine if true, inserts additional vertices to improve | ||
| 131 | * the quality of the mesh elements | ||
| 132 | * \param[in] quality typically in [1.0, 2.0], specifies | ||
| 133 | * the desired quality of mesh elements (1.0 means maximum | ||
| 134 | * quality, and generates a higher number of elements). | ||
| 135 | * \param[in] keep_regions if set, then all internal regions are kept, and | ||
| 136 | * a region cell attribute is created, else only tetrahedra in the | ||
| 137 | * outermost region are kept. | ||
| 138 | * \param[in] eps threshold for merging verties if preprocess is set, in | ||
| 139 | * percentage of bounding box diagonal. Use 0 to merge strictly colocated | ||
| 140 | * vertices | ||
| 141 | * \retval true if the mesh was successfuly tetrahedralized | ||
| 142 | * \retval false otherwise | ||
| 143 | * \note needs a constrained Delaunay algorithm to work (geogram needs | ||
| 144 | * to be compiled with mg-tetra or tetgen). | ||
| 145 | */ | ||
| 146 | inline bool GEOGRAM_API mesh_tetrahedralize( | ||
| 147 | Mesh& M, bool preprocess=true, bool refine=false, double quality=2.0, | ||
| 148 | bool keep_regions=false, double eps = 0.001 | ||
| 149 | ) { | ||
| 150 | 1 | MeshTetrahedralizeParameters params; | |
| 151 | 1 | params.preprocess = preprocess; | |
| 152 | 1 | params.preprocess_merge_vertices_epsilon = eps; | |
| 153 | 1 | params.refine = refine; | |
| 154 | 1 | params.refine_quality = quality; | |
| 155 | params.keep_regions = keep_regions; | ||
| 156 |
1/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
1 | return mesh_tetrahedralize(M, params); |
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | #endif | ||
| 161 |