libsurf
Programmer's Documentation

guige.h (r6227/r6201)
1 
2 /* Interface definition for Guigue/Devillers' triangle-triangle
3  * intersections routines (Journal of Graphics Tools)
4  *
5  * This file is in the public domain
6  */
7 
8 #ifndef SURF_GUIGE_H
9 #define SURF_GUIGE_H
10 
11 #ifdef __cplusplus
12 extern "C"
13 {
14 #endif
15 
16 // Guige
17 
18 int tri_tri_overlap_test_3d(const double p1[3], const double q1[3], const double r1[3],
19  const double p2[3], const double q2[3], const double r2[3]);
20 
21 
22 int coplanar_tri_tri3d(const double p1[3], const double q1[3], const double r1[3],
23  const double p2[3], const double q2[3], const double r2[3],
24  const double N1[3], const double N2[3]);
25 
26 
27 int tri_tri_overlap_test_2d(const double p1[2], const double q1[2], const double r1[2],
28  const double p2[2], const double q2[2], const double r2[2]);
29 
30 
31 int tri_tri_intersection_test_3d(const double p1[3], const double q1[3], const double r1[3],
32  const double p2[3], const double q2[3], const double r2[3],
33  int * coplanar,
34  double source[3], double target[3]);
35 
36 #ifdef __cplusplus
37 } // end extern "C"
38 
39 #include <iostream>
40 #include <genua/triface.h>
41 #include <genua/trimesh.h>
42 
43 // Moeller
44 
45 int tri_tri_intersect(const double V0[3],const double V1[3],const double V2[3],
46  const double U0[3],const double U1[3],const double U2[3]);
47 
48 int tri_tri_intersect_with_isectline(double V0[3], double V1[3], double V2[3],
49  double U0[3], double U1[3], double U2[3],
50  int *coplanar, double isectpt1[3],
51  double isectpt2[3]);
52 
53 int tri_tri_intersect(const float V0[3],const float V1[3],const float V2[3],
54  const float U0[3],const float U1[3],const float U2[3]);
55 
56 int tri_tri_intersect_with_isectline(float V0[3], float V1[3], float V2[3],
57  float U0[3], float U1[3], float U2[3],
58  int *coplanar, float isectpt1[3],
59  float isectpt2[3]);
60 
61 
62 inline bool guige_overlap(const TriFace & f1, const TriFace & f2)
63 {
64  const uint *v1( f1.vertices() );
65  const TriMesh & m1( *(f1.mesh()) );
66  const Vct3 & p1( m1.vertex(v1[0]) );
67  const Vct3 & q1( m1.vertex(v1[1]) );
68  const Vct3 & r1( m1.vertex(v1[2]) );
69 
70  const uint *v2( f2.vertices() );
71  const TriMesh & m2( *(f2.mesh()) );
72  const Vct3 & p2( m2.vertex(v2[0]) );
73  const Vct3 & q2( m2.vertex(v2[1]) );
74  const Vct3 & r2( m2.vertex(v2[2]) );
75 
76  int r = tri_tri_overlap_test_3d(p1.pointer(), q1.pointer(), r1.pointer(),
77  p2.pointer(), q2.pointer(), r2.pointer());
78  return (r != 0);
79 }
80 
81 inline bool guige_intersect(const TriFace & f1, const TriFace & f2,
82  Vct3 & isrc, Vct3 & itrg)
83 {
84  const uint *v1( f1.vertices() );
85  const TriMesh & m1( *(f1.mesh()) );
86  const Vct3 & p1( m1.vertex(v1[0]) );
87  const Vct3 & q1( m1.vertex(v1[1]) );
88  const Vct3 & r1( m1.vertex(v1[2]) );
89 
90  const uint *v2( f2.vertices() );
91  const TriMesh & m2( *(f2.mesh()) );
92  const Vct3 & p2( m2.vertex(v2[0]) );
93  const Vct3 & q2( m2.vertex(v2[1]) );
94  const Vct3 & r2( m2.vertex(v2[2]) );
95 
96  int coplanar(0);
97  int r = tri_tri_intersection_test_3d(p1.pointer(), q1.pointer(), r1.pointer(),
98  p2.pointer(), q2.pointer(), r2.pointer(),
99  &coplanar,
100  isrc.pointer(), itrg.pointer());
101 
102  return (r != 0 and coplanar != 1);
103 }
104 
105 inline bool moeller_intersect(const Vct3 a[], const Vct3 b[])
106 {
107  int r = tri_tri_intersect(a[0].pointer(), a[1].pointer(), a[2].pointer(),
108  b[0].pointer(), b[1].pointer(), b[2].pointer());
109  return (r != 0);
110 }
111 
112 inline bool moeller_intersect(const TriFace & f1, const TriFace & f2,
113  Vct3 & isrc, Vct3 & itrg)
114 {
115  const uint *v1( f1.vertices() );
116  const TriMesh & m1( *(f1.mesh()) );
117  Vct3 p1( m1.vertex(v1[0]) );
118  Vct3 q1( m1.vertex(v1[1]) );
119  Vct3 r1( m1.vertex(v1[2]) );
120 
121  const uint *v2( f2.vertices() );
122  const TriMesh & m2( *(f2.mesh()) );
123  Vct3 p2( m2.vertex(v2[0]) );
124  Vct3 q2( m2.vertex(v2[1]) );
125  Vct3 r2( m2.vertex(v2[2]) );
126 
127  int coplanar(0);
128  int r = tri_tri_intersect_with_isectline(p1.pointer(), q1.pointer(), r1.pointer(),
129  p2.pointer(), q2.pointer(), r2.pointer(),
130  &coplanar, isrc.pointer(), itrg.pointer());
131 
132  return (r != 0 and coplanar != 1);
133 }
134 
135 #endif
136 
137 #endif
const uint * vertices() const
const TriMesh * mesh() const
Generated on Mon Jan 24 2022 03:03:16 for libsurf by   doxygen 1.8.5