1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 cfMesh is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
28 Geometry queries useful for mesh generation
32 \*---------------------------------------------------------------------------*/
34 #ifndef helperFunctionsGeometryQueries_H
35 #define helperFunctionsGeometryQueries_H
43 #include "tetrahedron.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 /*---------------------------------------------------------------------------*\
55 Namespace help functions Declaration
56 \*---------------------------------------------------------------------------*/
60 //- check if a list has nan entries
61 template<class ListType>
62 bool isnan(const ListType&);
64 //- check if a list has inf entries
65 template<class ListType>
66 bool isinf(const ListType&);
68 //- check if the faces share a convex edge
69 template<class Face1, class Face2>
70 inline bool isSharedEdgeConvex
72 const pointField& points,
77 //- angle between the two faces in radians
78 template<class Face1, class Face2>
79 inline scalar angleBetweenFaces
81 const pointField& points,
86 // merge faces which are in the same patch
87 // This is need to merge the triagles which are generated for cells
88 // cut by more than on boundary regions
89 inline faceList mergePatchFaces
91 const List< DynList<label> >& pfcs,
92 const pointField& polyPoints
95 //- check if the point p belongs to the edge e
96 inline bool vertexOnLine
103 //- check if the point p belongs to the plane
104 inline bool vertexInPlane(const point& p, const plane& pl);
106 //- find the vertex on the line of the edge nearest to the point p
107 inline point nearestPointOnTheEdge
109 const point& edgePoint0,
110 const point& edgePoint1,
114 //- find the vertex on the edge nearest to the point p
115 inline point nearestPointOnTheEdgeExact
117 const point& edgePoint0,
118 const point& edgePoint1,
122 //- find and return the distance between the edge and the point p
123 inline scalar distanceOfPointFromTheEdge
125 const point& edgePoint0,
126 const point& edgePoint1,
130 //- find the nearest points on the edge and the line
131 inline bool nearestEdgePointToTheLine
133 const point& edgePoint0,
134 const point& edgePoint1,
137 point& nearestOnEdge,
141 //- check if the edge intersects the plane
142 inline bool planeIntersectsEdge
150 //- check if a vertex lies inside the tetrahedron
151 inline bool pointInTetrahedron
154 const tetrahedron<point, point>& tet
157 //- check if a line intersects the triangle, and return the intersection
158 inline bool triLineIntersection
160 const triangle<point, point>& tria,
161 const point& lineStart,
162 const point& lineEnd,
166 //- check if a line intersects the triangle and return the intersection
167 inline bool triLineIntersection
176 //- check if the line intersects the bounding box
177 inline bool boundBoxLineIntersection
184 //- check if the line and the face intersect
185 inline bool lineFaceIntersection
190 const pointField& fp,
194 //- check if the surface triangle and the face intersect
195 inline bool doFaceAndTriangleIntersect
197 const triSurf& surface,
200 const pointField& facePoints
203 //- find the nearest point on the triangle to the given point
204 inline point nearestPointOnTheTriangle
206 const triangle<point, point>& tri,
210 //- find the nearest vertex on the surface triangle to the given point
211 inline point nearestPointOnTheTriangle
218 //- find the minimiser point from a point and the given planes
219 //- returns true if the minimizer exists
220 inline bool findMinimizerPoint
222 const DynList<point>& origins,
223 const DynList<vector>& normals,
227 //- check the existence of overlap between the two edges
228 inline bool doEdgesOverlap
234 FixedList<point, 2>& overlappingPart,
235 const scalar distTol = -1.0,
236 const scalar cosTol = Foam::cos(5.0*(M_PI/180.0)) // cosine tolerance
239 //- check the existence of overlap between the two triangles
240 inline bool doTrianglesOverlap
242 const triangle<point, point>& tri0,
243 const triangle<point, point>& tri1,
244 DynList<point>& overlappingPolygon,
245 const scalar distTol = -1.0,
246 const scalar cosTol = Foam::cos(5.0*(M_PI/180.0)) // cosine tolerance
249 //- check the existence of intersection between the two triangles
250 inline bool doTrianglesIntersect
252 const triangle<point, point> &tri0,
253 const triangle<point, point> &tri1,
254 const scalar distTol = -1.0
257 inline bool doTrianglesIntersect
259 const triangle<point, point>& tri0,
260 const triangle<point, point>& tri1,
261 DynList<point>& intersectionPoints,
262 const scalar distTol = -1.0
265 //- check if the point is inside or outside the face
266 inline bool pointInsideFace
271 const pointField& fp,
272 const scalar distTol = SMALL
275 //- check if the point is inside or outside the face
276 inline bool pointInsideFace
280 const pointField& fp,
281 const scalar distTol = SMALL
284 //- check if the face is convex. Concave points are flagged false
285 inline bool isFaceConvexAndOk
288 const pointField& fp,
289 DynList<bool>& OkPoints
292 //- check if the vertex is on the positive side of the face plane
293 inline bool isVertexVisible(const point& p, const plane& pl);
295 //- find number of face groups within a given range
296 inline label numberOfFaceGroups
298 const labelHashSet& containedElements,
301 const triSurf& surface
304 //- find the number of edge groups within the given range
305 inline label numberOfEdgeGroups
307 const labelHashSet& containedEdges,
310 const triSurf& surface
313 } // End namespace help
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 } // End namespace Foam
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 #include "helperFunctionsGeometryQueriesI.H"
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 // ************************************************************************* //