| 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 | #ifdef GEOGRAM_WITH_TRIANGLE | ||
| 41 | |||
| 42 | |||
| 43 | #include <geogram/delaunay/delaunay_triangle.h> | ||
| 44 | #include <geogram/mesh/mesh.h> | ||
| 45 | #include <geogram/bibliography/bibliography.h> | ||
| 46 | |||
| 47 | namespace { | ||
| 48 | |||
| 49 | /** | ||
| 50 | * \brief Initializes a triangulateio. | ||
| 51 | * \param[in] tri a pointer to the triangulateio | ||
| 52 | * structure to be initialized | ||
| 53 | */ | ||
| 54 | 2 | void init_triangulateio(struct triangulateio* tri) { | |
| 55 | 2 | memset(tri, 0, sizeof(struct triangulateio)); | |
| 56 | 2 | } | |
| 57 | |||
| 58 | /** | ||
| 59 | * \brief Deallocates the memory used by a triangulateio. | ||
| 60 | * \details Only the memory used by the triangulateio is freed, | ||
| 61 | * not the triangulateio struct. | ||
| 62 | * \param[in] tri a pointer to the triangulateio | ||
| 63 | */ | ||
| 64 | 2 | void free_triangulateio(struct triangulateio* tri) { | |
| 65 | 2 | free(tri->pointlist); | |
| 66 | 2 | free(tri->pointattributelist); | |
| 67 | 2 | free(tri->pointmarkerlist); | |
| 68 | 2 | free(tri->trianglelist); | |
| 69 | 2 | free(tri->triangleattributelist); | |
| 70 | 2 | free(tri->trianglearealist); | |
| 71 | 2 | free(tri->neighborlist); | |
| 72 | 2 | free(tri->segmentlist); | |
| 73 | 2 | free(tri->segmentmarkerlist); | |
| 74 | 2 | free(tri->holelist); | |
| 75 | 2 | free(tri->regionlist); | |
| 76 | 2 | free(tri->edgelist); | |
| 77 | 2 | free(tri->edgemarkerlist); | |
| 78 | 2 | free(tri->normlist); | |
| 79 | 2 | memset(tri, 0, sizeof(struct triangulateio)); | |
| 80 | 2 | } | |
| 81 | |||
| 82 | } | ||
| 83 | |||
| 84 | namespace GEO { | ||
| 85 | |||
| 86 | 1 | DelaunayTriangle::DelaunayTriangle( | |
| 87 | coord_index_t dimension | ||
| 88 | 1 | ) : Delaunay(2) { | |
| 89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if(dimension != 2) { |
| 90 | ✗ | throw InvalidDimension(dimension, "DelaunayTriangle", "2"); | |
| 91 | } | ||
| 92 | 1 | init_triangulateio(&triangle_in_); | |
| 93 | 1 | init_triangulateio(&triangle_out_); | |
| 94 | |||
| 95 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | geo_cite("DBLP:conf/wacg/Shewchuk96"); |
| 96 | 1 | } | |
| 97 | |||
| 98 | ✗ | bool DelaunayTriangle::supports_constraints() const { | |
| 99 | ✗ | return true; | |
| 100 | } | ||
| 101 | |||
| 102 | 1 | void DelaunayTriangle::set_vertices( | |
| 103 | index_t nb_vertices, const double* vertices | ||
| 104 | ) { | ||
| 105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if(constraints_ != nullptr) { |
| 106 | ✗ | set_vertices_constrained(nb_vertices, vertices); | |
| 107 | } else { | ||
| 108 | 1 | set_vertices_unconstrained(nb_vertices, vertices); | |
| 109 | } | ||
| 110 | 1 | } | |
| 111 | |||
| 112 | 1 | void DelaunayTriangle::set_vertices_unconstrained( | |
| 113 | index_t nb_vertices, const double* vertices | ||
| 114 | ) { | ||
| 115 | 1 | Delaunay::set_vertices(nb_vertices, vertices); | |
| 116 | 1 | free_triangulateio(&triangle_out_); | |
| 117 | 1 | triangle_in_.numberofpoints = int(nb_vertices); | |
| 118 | 1 | triangle_in_.pointlist = const_cast<double*>(vertices); | |
| 119 | // Q: quiet | ||
| 120 | // z: numbering starts from 0 | ||
| 121 | // n: output neighbors | ||
| 122 | 1 | triangulate( | |
| 123 | const_cast<char*>("Qzn"), &triangle_in_, &triangle_out_, nullptr | ||
| 124 | ); | ||
| 125 | 1 | set_arrays( | |
| 126 | 1 | index_t(triangle_out_.numberoftriangles), | |
| 127 | 1 | reinterpret_cast<index_t*>(triangle_out_.trianglelist), | |
| 128 | 1 | reinterpret_cast<index_t*>(triangle_out_.neighborlist) | |
| 129 | ); | ||
| 130 | 1 | } | |
| 131 | |||
| 132 | ✗ | void DelaunayTriangle::set_vertices_constrained( | |
| 133 | index_t nb_vertices, const double* vertices | ||
| 134 | ) { | ||
| 135 | // For now, everything is taken from the constraints | ||
| 136 | ✗ | geo_assert(nb_vertices == 0); | |
| 137 | ✗ | geo_assert(vertices == nullptr); | |
| 138 | |||
| 139 | ✗ | nb_vertices = constraints_->vertices.nb(); | |
| 140 | ✗ | vertices = constraints_->vertices.point_ptr(0); | |
| 141 | |||
| 142 | ✗ | free_triangulateio(&triangle_out_); | |
| 143 | |||
| 144 | ✗ | triangle_in_.numberofpoints = int(nb_vertices); | |
| 145 | ✗ | triangle_in_.pointlist = const_cast<double*>(vertices); | |
| 146 | ✗ | triangle_in_.numberofsegments = int(constraints_->edges.nb()); | |
| 147 | ✗ | triangle_in_.segmentlist = reinterpret_cast<int*>(const_cast<index_t*>( | |
| 148 | ✗ | constraints_->edges.vertex_index_ptr(0) | |
| 149 | )); | ||
| 150 | |||
| 151 | // Q: quiet | ||
| 152 | // z: numbering starts from 0 | ||
| 153 | // n: output neighbors | ||
| 154 | // p: Planar Straight Line Graph | ||
| 155 | ✗ | triangulate( | |
| 156 | const_cast<char*>("Qznp"), &triangle_in_, &triangle_out_, nullptr | ||
| 157 | ); | ||
| 158 | |||
| 159 | ✗ | Delaunay::set_vertices( | |
| 160 | ✗ | index_t(triangle_out_.numberofpoints), | |
| 161 | ✗ | triangle_out_.pointlist | |
| 162 | ); | ||
| 163 | |||
| 164 | ✗ | set_arrays( | |
| 165 | ✗ | index_t(triangle_out_.numberoftriangles), | |
| 166 | ✗ | reinterpret_cast<index_t*>(triangle_out_.trianglelist), | |
| 167 | ✗ | reinterpret_cast<index_t*>(triangle_out_.neighborlist) | |
| 168 | ); | ||
| 169 | |||
| 170 | ✗ | if(triangle_out_.numberofpoints != triangle_in_.numberofpoints) { | |
| 171 | ✗ | std::cerr << "Triangle: created " | |
| 172 | ✗ | << triangle_out_.numberofpoints - | |
| 173 | ✗ | triangle_in_.numberofpoints | |
| 174 | ✗ | << " points" | |
| 175 | ✗ | << std::endl; | |
| 176 | } | ||
| 177 | ✗ | } | |
| 178 | |||
| 179 | 4 | DelaunayTriangle::~DelaunayTriangle() { | |
| 180 | 2 | free_triangulateio(&triangle_out_); | |
| 181 | 4 | } | |
| 182 | |||
| 183 | |||
| 184 | } | ||
| 185 | |||
| 186 | #endif | ||
| 187 |