Geogram Version 1.10.0-rc
A programming library of geometric algorithms
Loading...
Searching...
No Matches
triangle_intersection.h
Go to the documentation of this file.
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_TRIANGLE_INTERSECTION
41#define GEOGRAM_MESH_TRIANGLE_INTERSECTION
42
46#include <utility>
47
53namespace GEO {
54
65 T1_RGN_P0 = 0,
66 T1_RGN_P1 = 1,
67 T1_RGN_P2 = 2,
68
69 T2_RGN_P0 = 3,
70 T2_RGN_P1 = 4,
71 T2_RGN_P2 = 5,
72
73 T1_RGN_E0 = 6,
74 T1_RGN_E1 = 7,
75 T1_RGN_E2 = 8,
76
77 T2_RGN_E0 = 9,
78 T2_RGN_E1 = 10,
79 T2_RGN_E2 = 11,
80
81 T1_RGN_T = 12,
82 T2_RGN_T = 13,
83
84 T_RGN_NB = 14
85 };
86
87
93 inline bool is_in_T1(TriangleRegion R) {
94 return (R == T1_RGN_P0) ||
95 (R == T1_RGN_P1) ||
96 (R == T1_RGN_P2) ||
97 (R == T1_RGN_E0) ||
98 (R == T1_RGN_E1) ||
99 (R == T1_RGN_E2) ||
100 (R == T1_RGN_T ) ;
101 }
102
110
115 typedef std::pair<TriangleRegion, TriangleRegion> TriangleIsect;
116
117
127 public:
128 TriangleIsects() : size_(0) {
129 }
130
131 typedef TriangleIsect* iterator;
132 typedef const TriangleIsect* const_iterator;
133
134 iterator begin() {
135 return data_;
136 }
137
138 iterator end() {
139 return begin()+size_;
140 }
141
142 const_iterator begin() const {
143 return data_;
144 }
145
146 const_iterator end() const {
147 return begin()+size_;
148 }
149
150 void push_back(const TriangleIsect& I) {
151 geo_assert(size_ < capacity_);
152 data_[size_] = I;
153 ++size_;
154 }
155
156 void clear() {
157 size_ = 0;
158 }
159
160 index_t size() const {
161 return size_;
162 }
163
164 void resize(index_t new_size) {
165 geo_debug_assert(new_size <= capacity_);
166 size_ = new_size;
167 }
168
169 TriangleIsect& operator[](index_t i) {
170 geo_debug_assert(i<size());
171 return data_[i];
172 }
173
174 const TriangleIsect& operator[](index_t i) const {
175 geo_debug_assert(i<size());
176 return data_[i];
177 }
178
179 private:
188 static constexpr int capacity_ = 20;
189 index_t size_;
190 TriangleIsect data_[capacity_];
191 };
192
193
212 bool GEOGRAM_API triangles_intersections(
213 const vec3& p0, const vec3& p1, const vec3& p2,
214 const vec3& q0, const vec3& q1, const vec3& q2,
215 TriangleIsects& result
216 );
217
218
219 [[deprecated("use TriangleIsects instead of vector<TriangleIsect>")]]
220 inline bool triangles_intersections(
221 const vec3& p0, const vec3& p1, const vec3& p2,
222 const vec3& q0, const vec3& q1, const vec3& q2,
224 ) {
225 TriangleIsects result_;
226 bool r = triangles_intersections(p0,p1,p2,q0,q1,q2,result_);
227 result.clear();
228 for(TriangleIsect I : result_) {
229 result.push_back(I);
230 }
231 return r;
232 }
233
234
256 bool GEOGRAM_API triangles_intersections(
257 const vec3& p0, const vec3& p1, const vec3& p2,
258 const vec3& q0, const vec3& q1, const vec3& q2,
259 index_t p0_index,
260 index_t p1_index,
261 index_t p2_index,
262 index_t q0_index,
263 index_t q1_index,
264 index_t q2_index,
265 TriangleIsects& result
266 );
267
268
280 const vec3& p0, const vec3& p1, const vec3& p2,
281 const vec3& q0, const vec3& q1, const vec3& q2
282 );
283
289 std::string GEOGRAM_API region_to_string(TriangleRegion rgn);
290
299
306 void GEOGRAM_API get_triangle_vertices(
309 );
310
317 void GEOGRAM_API get_triangle_edges(
320 );
321
328 void GEOGRAM_API get_edge_vertices(
330 );
331
332
350 );
351
358 inline std::ostream& operator<<(
359 std::ostream& out, const TriangleIsect& I
360 ) {
361 return (
362 out << "("
363 << region_to_string(I.first) << ","
364 << region_to_string(I.second)
365 << ")"
366 );
367 }
368
375 inline std::ostream& operator<<(
376 std::ostream& out, TriangleIsects& II
377 ) {
378 for(const TriangleIsect& I : II) {
379 out << I << " ";
380 }
381 return out;
382 }
383
384 [[deprecated("use TriangleIsects instead of vector<TriangleIsect>")]]
385 inline std::ostream& operator<<(
386 std::ostream& out, const vector<TriangleIsect>& II
387 ) {
388 for(const TriangleIsect& I : II) {
389 out << I << " ";
390 }
391 return out;
392 }
393
394
395}
396
397#endif
#define geo_assert(x)
Verifies that a condition is met.
Definition assert.h:149
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:196
A small vector of TriangleIsect stored in an array with static size.
Vector with aligned memory allocation.
Definition memory.h:702
Common include file, providing basic definitions. Should be included before anything else by all head...
Geometric functions in 2d and 3d.
Types and functions for memory manipulation.
Global Vorpaline namespace.
Definition basic.h:55
coord_index_t region_dim(TriangleRegion r)
Gets the dimension of a triangle region.
TriangleRegion
Encodes the location of a point within a triangle.
TriangleRegion swap_T1_T2(TriangleRegion R)
Replaces T1 with T2 or T2 with T1 in a region code.
TriangleRegion regions_convex_hull(TriangleRegion R1, TriangleRegion R2)
Computes the convex hull of two regions.
std::pair< TriangleRegion, TriangleRegion > TriangleIsect
Encodes the symbolic representation of a triangle intersection, as a pair of TriangleRegion.
bool triangles_intersections(const vec3 &p0, const vec3 &p1, const vec3 &p2, const vec3 &q0, const vec3 &q1, const vec3 &q2, TriangleIsects &result)
Triangle-triangle intersection with symbolic information.
bool is_in_T1(TriangleRegion R)
Tests whether a region belongs to triangle T1.
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:330
void get_triangle_edges(TriangleRegion T, TriangleRegion &e0, TriangleRegion &e1, TriangleRegion &e2)
Gets the edges of a triangle.
void get_edge_vertices(TriangleRegion E, TriangleRegion &q0, TriangleRegion &q1)
Gets the vertices of an edge.
void get_triangle_vertices(TriangleRegion T, TriangleRegion &p0, TriangleRegion &p1, TriangleRegion &p2)
Gets the vertices of a triangle.
std::string region_to_string(TriangleRegion rgn)
Converts a triangle region code to a string.
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
Definition numeric.h:364