25# ifndef __BITPIT_CG_BASE_HPP__
26# define __BITPIT_CG_BASE_HPP__
33# include "bitpit_common.hpp"
40typedef std::array<double,3> array3D ;
47const double DEFAULT_DISTANCE_TOLERANCE = 1.e-12;
48const double DEFAULT_COPLANARITY_TOLERANCE = 1.e-12;
55 std::array<int,2>{ {0,2} },
56 std::array<int,2>{ {1,3} },
57 std::array<int,2>{ {0,1} },
58 std::array<int,2>{ {2,3} },
59 std::array<int,2>{ {4,6} },
60 std::array<int,2>{ {5,7} },
61 std::array<int,2>{ {4,5} },
62 std::array<int,2>{ {6,7} },
63 std::array<int,2>{ {0,4} },
64 std::array<int,2>{ {1,5} },
65 std::array<int,2>{ {2,6} },
66 std::array<int,2>{ {3,7} }
75 std::array<int,4>{ {0,2,6,4} },
76 std::array<int,4>{ {1,3,7,5} },
77 std::array<int,4>{ {0,4,5,1} },
78 std::array<int,4>{ {2,6,7,3} },
79 std::array<int,4>{ {0,1,3,2} },
80 std::array<int,4>{ {4,5,7,6} }
88bool validLine( array3D
const &, array3D
const & );
89bool validPlane( array3D
const &, array3D
const & );
90bool validTriangle( array3D
const &, array3D
const &, array3D
const & );
112array3D
rotatePoint(
const array3D &P,
const array3D &n0,
const array3D &n1,
double angle );
114array3D
projectPointLine( array3D
const &, array3D
const &, array3D
const & );
117array3D
projectPointSegment( array3D
const &, array3D
const &, array3D
const &, std::array<double,2> & );
119array3D
projectPointTriangle( array3D
const &, array3D
const &, array3D
const &, array3D
const & );
120array3D
projectPointTriangle( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D & );
121array3D
projectPointTriangle( array3D
const &P, array3D
const &Q0, array3D
const &Q1, array3D
const &Q2,
double *lambda );
124array3D
projectPointPolygon( array3D
const &, std::vector<array3D>
const &, std::vector<double> & );
125array3D
projectPointPolygon( array3D
const &, std::size_t, array3D
const *, std::vector<double> & );
127array3D
projectPointCone( array3D
const &, array3D
const &, array3D
const &,
double );
128std::vector<array3D>
projectCloudTriangle( std::vector<array3D>
const &, array3D
const &, array3D
const &, array3D
const &, std::vector<array3D> &);
133double distancePointLine( array3D
const &, array3D
const &, array3D
const &, array3D & ) ;
134double distancePointPlane( array3D
const &, array3D
const &, array3D
const &, array3D & ) ;
137double distancePointSegment( array3D
const &, array3D
const &, array3D
const &, std::array<double,2> & );
140double distancePointTriangle( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D &);
146double distancePointPolygon( array3D
const &, std::vector<array3D>
const &, std::vector<double> & );
147double distancePointPolygon( array3D
const &, std::size_t, array3D
const *, std::vector<double> & );
150double distancePointCone( array3D
const &, array3D
const &, array3D
const &,
double );
152std::vector<double>
distanceCloudTriangle( std::vector<array3D>
const &, array3D
const &, array3D
const &, array3D
const &);
153std::vector<double>
distanceCloudTriangle( std::vector<array3D>
const &, array3D
const &, array3D
const &, array3D
const &, std::vector<array3D> & );
155std::vector<double>
distanceCloudPolygon( std::vector<array3D>
const &, std::vector<array3D>
const &, std::vector<array3D> &, std::vector<int> & );
156std::vector<double>
distanceCloudPolygon( std::vector<array3D>
const &, std::size_t, array3D
const *, std::vector<array3D> &, std::vector<int> & );
157std::vector<double>
distanceCloudPolygon( std::vector<array3D>
const &, std::vector<array3D>
const &);
158std::vector<double>
distanceCloudPolygon( std::vector<array3D>
const &, std::size_t, array3D
const *);
159std::vector<double>
distanceCloudPolygon( std::vector<array3D>
const &, std::vector<array3D>
const &, std::vector<std::vector<double>> &);
160std::vector<double>
distanceCloudPolygon( std::vector<array3D>
const &, std::size_t, array3D
const *, std::vector<std::vector<double>> &);
162double distanceLineLine(array3D
const &, array3D
const &, array3D
const &, array3D
const &);
163double distanceLineLine(array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D &, array3D &);
167 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
169 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
171 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
172bool intersectPointBox( array3D
const &, array3D
const &, array3D
const &,
int dim=3,
173 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
175bool intersectLineLine( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D &,
176 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
177bool intersectLinePlane( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D &,
178 const double coplanarityTolerance = DEFAULT_COPLANARITY_TOLERANCE) ;
179bool intersectLineTriangle( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D
const &,
180 array3D &,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
181bool intersectLinePolygon( array3D
const &, array3D
const &, std::vector<array3D>
const &, array3D &,
182 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
183bool intersectLinePolygon( array3D
const &, array3D
const &, std::size_t, array3D
const *, array3D &,
184 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
187 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
188bool intersectSegmentPlane( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D &,
189 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
191 array3D &,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
193 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
195 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
197bool intersectSegmentBox( array3D
const &, array3D
const &, array3D
const &, array3D
const &,
int dim = 3,
198 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
199bool intersectSegmentBox( array3D
const &, array3D
const &, array3D
const &, array3D
const &,
bool,
bool,
200 std::vector<array3D> &,
int dim=3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
201bool intersectSegmentBox( array3D
const &, array3D
const &, array3D
const &, array3D
const &,
bool,
bool,
202 std::vector<array3D> &, std::vector<int> &,
int dim=3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
204bool intersectPlanePlane( array3D
const &, array3D
const &, array3D
const &, array3D
const &,
205 array3D &, array3D &,
const double coplanarityTolerance = DEFAULT_COPLANARITY_TOLERANCE) ;
206bool intersectPlaneBox( array3D
const &, array3D
const &, array3D
const &, array3D
const &,
int dim=3,
207 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
208bool intersectPlaneBox( array3D
const &, array3D
const &, array3D
const &, array3D
const &,
209 std::vector<array3D> &,
int dim=3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
211bool intersectBoxBox( array3D
const &, array3D
const &, array3D
const &, array3D
const &,
int dim = 3,
212 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
213bool intersectBoxBox( array3D
const &, array3D
const &, array3D
const &, array3D
const &,
214 array3D &, array3D &,
int dim = 3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
217bool intersectBoxTriangle( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D
const &,
218 int dim=3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
219bool intersectBoxTriangle( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D
const &,
220 bool,
bool,
bool, std::vector<array3D> &,
int dim=3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
221bool intersectBoxTriangle( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D
const &,
222 bool,
bool,
bool, std::vector<array3D> &, std::vector<int> &,
int dim=3,
223 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE) ;
226bool intersectBoxPolygon( array3D
const &, array3D
const &, std::vector<array3D>
const &,
int dim=3,
227 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
228bool intersectBoxPolygon( array3D
const &, array3D
const &, std::size_t, array3D
const *,
int dim=3,
229 const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
230bool intersectBoxPolygon( array3D
const &, array3D
const &, std::vector<array3D>
const &,
bool,
bool,
bool,
231 std::vector<array3D> &,
int dim=3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
232bool intersectBoxPolygon( array3D
const &, array3D
const &, std::size_t, array3D
const *,
bool,
bool,
bool,
233 std::vector<array3D> &,
int dim=3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
234bool intersectBoxPolygon( array3D
const &, array3D
const &, std::vector<array3D>
const &,
bool,
bool,
bool,
235 std::vector<array3D> &, std::vector<int> &,
int dim=3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
236bool intersectBoxPolygon( array3D
const &, array3D
const &, std::size_t, array3D
const *,
bool,
bool,
bool,
237 std::vector<array3D> &, std::vector<int> &,
int dim=3,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
239bool intersectBoxCircle( array3D
const &A0, array3D
const &A1, array3D
const ¢re,
double radius,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
241bool intersectBoxSphere( array3D
const &A0, array3D
const &A1, array3D
const ¢re,
double radius,
const double distanceTolerance = DEFAULT_DISTANCE_TOLERANCE);
244void computeAABBTriangle( array3D
const &, array3D
const &, array3D
const &, array3D &, array3D & ) ;
248void unionAABB( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D &, array3D & );
249void intersectionAABB( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D &, array3D & );
250void subtractionAABB( array3D
const &, array3D
const &, array3D
const &, array3D
const &, array3D &, array3D & );
251void unionAABB( std::vector<array3D>
const &, std::vector<array3D>
const &, array3D &, array3D & );
253array3D
rotateVector( array3D
const &, array3D
const &,
double);
254double areaTriangle( array3D
const &, array3D
const &, array3D
const &);
256void vertexOfSegment(
int, array3D
const &, array3D
const &, array3D &);
258void vertexOfTriangle(
int, array3D
const &, array3D
const &, array3D
const &, array3D &);
259void edgeOfTriangle(
int, array3D
const &, array3D
const &, array3D
const &, array3D &, array3D &);
261void vertexOfBox(
int, array3D
const &, array3D
const &, array3D &);
262void edgeOfBox(
int, array3D
const &, array3D
const &, array3D &, array3D &);
263void faceOfBox(
int, array3D
const &, array3D
const &, array3D &, array3D &, array3D &, array3D & );
269void edgeOfPolygon(
int, std::vector<array3D>
const &, array3D &, array3D &);
270void edgeOfPolygon(
int, std::size_t, array3D
const *, array3D &, array3D &);
278namespace CGAlgorithms {
282 std::vector<std::array<double,3>> &,
283 std::vector<std::vector<int>> &,
284 std::vector<std::vector<std::vector<int>>> &,
285 std::vector<double> &,
294 std::vector<std::array<double,3>> &,
295 std::vector<std::vector<int>> &,
296 std::vector<std::vector<std::vector<int>>> &,
297 std::vector<double> &,
303 std::vector<std::array<double,3>> &,
304 std::vector<std::vector<int>> &,
305 std::vector<std::vector<std::vector<int>>> &,
306 std::vector<double> &,
315 std::vector<std::array<double,3>> &,
316 std::vector<std::vector<int>> &,
317 std::vector<double> &,
323 std::vector<std::array<double,3>> &,
324 std::vector<std::vector<int>> &,
325 std::vector<std::vector<int>> &,
326 std::vector<double> &,
334 std::vector<std::array<double,3>> &,
335 std::vector<std::vector<int>> &,
336 std::vector<std::vector<int>> &,
337 std::vector<double> &,
void edgeOfPolygon(int, std::vector< array3D > const &, array3D &, array3D &)
std::vector< double > distanceCloudTriangle(std::vector< array3D > const &, array3D const &, array3D const &, array3D const &)
double distancePointLine(array3D const &, array3D const &, array3D const &, array3D &)
double distancePointCone(array3D const &, array3D const &, array3D const &, double)
array3D projectPointLine(array3D const &, array3D const &, array3D const &)
void edgeOfTriangle(int, array3D const &, array3D const &, array3D const &, array3D &, array3D &)
const std::array< std::array< int, 2 >, 12 > boxEdgeVertexConnectivity
bool intersectPlaneBox(array3D const &, array3D const &, array3D const &, array3D const &, int dim=3, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
void unionAABB(array3D const &, array3D const &, array3D const &, array3D const &, array3D &, array3D &)
bool intersectPointTriangle(array3D const &, array3D const &, array3D const &, array3D const &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectBoxBox(array3D const &, array3D const &, array3D const &, array3D const &, int dim=3, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
array3D projectPointTriangle(array3D const &, array3D const &, array3D const &, array3D const &)
array3D rotateVector(array3D const &, array3D const &, double)
array3D projectPointSegment(array3D const &, array3D const &, array3D const &)
double distancePointPlane(array3D const &, array3D const &, array3D const &, array3D &)
bool intersectBoxTriangle(array3D const &, array3D const &, array3D const &, array3D const &, array3D const &, int dim=3, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
int convertBarycentricToFlagSegment(std::array< double, 2 > const &, double tolerance=DEFAULT_DISTANCE_TOLERANCE)
void computeAABBTriangle(array3D const &, array3D const &, array3D const &, array3D &, array3D &)
bool validBarycentric(double const *, int)
void intersectionAABB(array3D const &, array3D const &, array3D const &, array3D const &, array3D &, array3D &)
double distanceLineLine(array3D const &, array3D const &, array3D const &, array3D const &)
array3D reconstructPointFromBarycentricTriangle(array3D const &, array3D const &, array3D const &, std::array< double, 3 > const &)
array3D reconstructPointFromBarycentricSegment(array3D const &, array3D const &, std::array< double, 2 > const &)
const std::array< std::array< int, 4 >, 6 > boxFaceVertexConnectivity
std::vector< double > distanceCloudPolygon(std::vector< array3D > const &, std::vector< array3D > const &, std::vector< array3D > &, std::vector< int > &)
void vertexOfSegment(int, array3D const &, array3D const &, array3D &)
void vertexOfTriangle(int, array3D const &, array3D const &, array3D const &, array3D &)
int convertBarycentricToFlagPolygon(std::vector< double > const &, double tolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectSegmentPlane(array3D const &, array3D const &, array3D const &, array3D const &, array3D &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectLineTriangle(array3D const &, array3D const &, array3D const &, array3D const &, array3D const &, array3D &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectSegmentSegment(array3D const &, array3D const &, array3D const &, array3D const &, array3D &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
double distancePointTriangle(array3D const &, array3D const &, array3D const &, array3D const &)
bool intersectPointLine(array3D const &, array3D const &, array3D const &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
int polygonEdgesCount(std::vector< array3D > const &)
int polygonSubtriangleCount(std::vector< array3D > const &)
bool intersectBoxSphere(array3D const &A0, array3D const &A1, array3D const ¢re, double radius, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
int convertBarycentricToFlagTriangle(std::array< double, 3 > const &, double tolerance=DEFAULT_DISTANCE_TOLERANCE)
double areaTriangle(array3D const &, array3D const &, array3D const &)
array3D projectPointPlane(array3D const &, array3D const &, array3D const &)
void subtriangleOfPolygon(int, std::vector< array3D > const &, array3D &, array3D &, array3D &)
bool intersectSegmentBox(array3D const &, array3D const &, array3D const &, array3D const &, int dim=3, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectPlanePlane(array3D const &, array3D const &, array3D const &, array3D const &, array3D &, array3D &, const double coplanarityTolerance=DEFAULT_COPLANARITY_TOLERANCE)
void computeGeneralizedBarycentric(array3D const &, std::vector< array3D > const &, std::vector< double > &)
double distancePointSegment(array3D const &, array3D const &, array3D const &)
bool intersectLinePlane(array3D const &, array3D const &, array3D const &, array3D const &, array3D &, const double coplanarityTolerance=DEFAULT_COPLANARITY_TOLERANCE)
bool validPlane(array3D const &, array3D const &)
array3D rotatePoint(const array3D &P, const array3D &n0, const array3D &n1, double angle)
double distancePointPolygon(array3D const &, std::vector< array3D > const &, array3D &, int &)
bool validLine(array3D const &, array3D const &)
void computeAABBPolygon(std::vector< array3D > const &, array3D &, array3D &)
bool validTriangle(array3D const &, array3D const &, array3D const &)
array3D reconstructPointFromBarycentricPolygon(std::vector< array3D > const &, std::vector< double > const &)
bool intersectSegmentTriangle(array3D const &, array3D const &, array3D const &, array3D const &, array3D const &, array3D &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
array3D restrictPointTriangle(array3D const &, array3D const &, array3D const &, array3D &)
bool intersectBoxPolygon(array3D const &, array3D const &, std::vector< array3D > const &, int dim=3, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
void faceOfBox(int, array3D const &, array3D const &, array3D &, array3D &, array3D &, array3D &)
std::vector< array3D > projectCloudTriangle(std::vector< array3D > const &, array3D const &, array3D const &, array3D const &, std::vector< array3D > &)
array3D projectPointCone(array3D const &, array3D const &, array3D const &, double)
void vertexOfBox(int, array3D const &, array3D const &, array3D &)
void edgeOfBox(int, array3D const &, array3D const &, array3D &, array3D &)
void subtractionAABB(array3D const &, array3D const &, array3D const &, array3D const &, array3D &, array3D &)
array3D projectPointPolygon(array3D const &, std::vector< array3D > const &)
bool validSegment(array3D const &, array3D const &)
void computeAABBSegment(array3D const &, array3D const &, array3D &, array3D &)
bool intersectPointBox(array3D const &, array3D const &, array3D const &, int dim=3, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectPointSegment(array3D const &, array3D const &, array3D const &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectLineLine(array3D const &, array3D const &, array3D const &, array3D const &, array3D &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectBoxCircle(array3D const &A0, array3D const &A1, array3D const ¢re, double radius, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectLinePolygon(array3D const &, array3D const &, std::vector< array3D > const &, array3D &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)
bool intersectSegmentPolygon(array3D const &, array3D const &, std::vector< array3D > const &, array3D &, const double distanceTolerance=DEFAULT_DISTANCE_TOLERANCE)