Geogram  Version 1.9.1
A programming library of geometric algorithms
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 
43 #include <geogram/basic/common.h>
44 #include <geogram/basic/geometry.h>
45 #include <geogram/basic/memory.h>
46 #include <utility>
47 
53 namespace 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 
135  bool GEOGRAM_API triangles_intersections(
136  const vec3& p0, const vec3& p1, const vec3& p2,
137  const vec3& q0, const vec3& q1, const vec3& q2,
138  vector<TriangleIsect>& result
139  );
140 
141 
153  const vec3& p0, const vec3& p1, const vec3& p2,
154  const vec3& q0, const vec3& q1, const vec3& q2
155  );
156 
162  std::string GEOGRAM_API region_to_string(TriangleRegion rgn);
163 
172 
179  void GEOGRAM_API get_triangle_vertices(
180  TriangleRegion T,
182  );
183 
190  void GEOGRAM_API get_triangle_edges(
191  TriangleRegion T,
193  );
194 
201  void GEOGRAM_API get_edge_vertices(
203  );
204 
205 
223  );
224 
231  inline std::ostream& operator<<(
232  std::ostream& out, const TriangleIsect& I
233  ) {
234  return (
235  out << "("
236  << region_to_string(I.first) << ","
237  << region_to_string(I.second)
238  << ")"
239  );
240  }
241 
248  inline std::ostream& operator<<(
249  std::ostream& out, vector<TriangleIsect>& II
250  ) {
251  for(const TriangleIsect& I : II) {
252  out << I << " ";
253  }
254  return out;
255  }
256 }
257 
258 #endif
Vector with aligned memory allocation.
Definition: memory.h:635
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 is_in_T1(TriangleRegion R)
Tests whether a region belongs to triangle T1.
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:363
bool triangles_intersections(const vec3 &p0, const vec3 &p1, const vec3 &p2, const vec3 &q0, const vec3 &q1, const vec3 &q2, vector< TriangleIsect > &result)
Triangle-triangle intersection with symbolic information.