Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
geometry.h
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 H_HEXDOM_ALGO_GEOMETRY_H
41 #define H_HEXDOM_ALGO_GEOMETRY_H
42 
44 #include <exploragram/hexdom/basic.h>
45 #include <geogram/basic/geometry.h>
46 
47 namespace GEO {
48 
50  double w[6];
51  double tetvol;
52 
53  CoTan3D(vec3 P[4], double* anisotropy_as_xx_yy_zz_xy_yz_xz = nullptr);
54 
55  index_t org(index_t e);
56  index_t dest(index_t e);
57  double coeff(index_t e);
58 
59  void check_for_grad(vec3 P[4], vec3 grad);
60  };
61 
62  /*******************************************************************************/
63 
65  public:
66  TrglGradient(const vec3& p0, const vec3& p1, const vec3& p2);
67 
70 
71  void initialize(const vec3& p0, const vec3& p1, const vec3& p2);
72 
78  const vec3& vertex(index_t i) const;
79 
84  void basis(vec3& origin, vec3& X, vec3& Y, vec3& Z) const;
85 
92  double TX(index_t i) const;
93 
99  double TY(index_t i) const;
100  bool is_flat() const { return is_flat_; }
101 
102  vec3 gradient_3d(double value0, double value1, double value2) const;
103 
104  private:
105  double TX_[3];
106  double TY_[3];
107  vec3 vertex_[3];
108  bool is_flat_;
109  };
110 
111  /*******************************************************************************/
112 
113  struct Basis3d {
114  Basis3d(vec3 z) { // TODO DOCUMENT THIS!
115  v[2] = normalize(z);
116  if (std::fabs(v[2].z) < .8)
117  v[0] = cross(v[2], vec3(0, 0, 1));
118  else v[0] = cross(v[2], vec3(1, 0, 0));
119  v[0] = normalize(v[0]);
120  v[1] = cross(v[2], v[0]);
121  geo_assert(std::abs(v[1].length2() - 1) < .001);
122  }
123  vec2 project_xy(vec3 in){
124  return vec2(dot(in, v[0]), dot(in, v[1]));
125  }
126  vec3 un_project_xy(vec2 in){
127  return in[0] * v[0] + in[1] * v[1];
128  }
129  vec3 v[3];
130  };
131 
132  /*******************************************************************************/
133 
134  /* _____ _____ ____ _____ _ _ _
135  * | __ \ / ____| /\ |___ \| __ \ | | | | | |
136  * | |__) | | / \ __) | | | | ______ ______ _ __ ___ | |_ ___ ___ _ __ | |_ ___ _ __ ___ __| |
137  * | ___/| | / /\ \ |__ <| | | | |______|______| | '_ \ / _ \| __| / __/ _ \ '_ \| __/ _ \ '__/ _ \/ _` |
138  * | | | |____ / ____ \ ___) | |__| | | | | | (_) | |_ | (_| __/ | | | || __/ | | __/ (_| |
139  * |_| \_____/_/ \_\ |____/|_____/ |_| |_|\___/ \__| \___\___|_| |_|\__\___|_| \___|\__,_|
140  *
141  */
142 
144  public:
145  void begin_points();
146  void end_points();
147  void point(const vec3& p, double weight = 1.0);
148  vec3 axis[3];
149  double eigen_value[3];
150  private:
151  double M_[6];
152  int nb_points_;
153  double sum_weights_;
154  };
155 
156 
157  /*******************************************************************************/
158 
159 
160  /* Triangle/triangle intersection test routine,
161  * by Tomas Moller, 1997.
162  * See article "A Fast Triangle-Triangle Intersection Test",
163  * Journal of Graphics Tools, 2(2), 1997
164  *
165  * Updated June 1999: removed the divisions -- a little faster now!
166  * Updated October 1999: added {} to CROSS and SUB macros
167  *
168  * int NoDivTriTriIsect(double V0[3],double V1[3],double V2[3],
169  * double U0[3],double U1[3],double U2[3])
170  *
171  * parameters: vertices of triangle 1: V0,V1,V2
172  * vertices of triangle 2: U0,U1,U2
173  * result : returns 1 if the triangles intersect, otherwise 0
174  *
175  */
176  int EXPLORAGRAM_API NoDivTriTriIsect(
177  double V0[3], double V1[3], double V2[3],
178  double U0[3], double U1[3], double U2[3]
179  );
180 
181  /********************************************************/
182  /* AABB-triangle overlap test code */
183  /* by Tomas Akenine-Möller */
184  /* Function: int triBoxOverlap(float boxcenter[3], */
185  /* float boxhalfsize[3],float triverts[3][3]); */
186  /* History: */
187  /* 2001-03-05: released the code in its first version */
188  /* 2001-06-18: changed the order of the tests, faster */
189  /* */
190  /* Acknowledgement: Many thanks to Pierre Terdiman for */
191  /* suggestions and discussions on how to optimize code. */
192  /* Thanks to David Hunt for finding a ">="-bug! */
193  /********************************************************/
194  int EXPLORAGRAM_API triBoxOverlap(
195  float boxcenter[3], float boxhalfsize[3], float triverts[3][3]
196  );
197 
198  /*******************************************************************************/
199 
200 }
201 
202 #endif
#define geo_assert(x)
Verifies that a condition is met.
Definition: assert.h:149
double TX(index_t i) const
double TY(index_t i) const
void basis(vec3 &origin, vec3 &X, vec3 &Y, vec3 &Z) const
const vec3 & vertex(index_t i) const
#define EXPLORAGRAM_API
Linkage declaration for exploragram symbols.
Definition: defs.h:18
Included by all headers in exploragram.
Geometric functions in 2d and 3d.
Global Vorpaline namespace.
Definition: basic.h:55
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
Definition: geometry.h:65
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
void initialize(int flags=GEOGRAM_INSTALL_NONE)
Initialize Geogram.
vecng< 2, Numeric::float64 > vec2
Represents points and vectors in 2d.
Definition: geometry.h:59