1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM 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 OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Foam::faceTriangulation
29 Triangulation of faces. Handles concave polygons as well
32 Works by trying to subdivide the face at the vertex with 'flattest'
33 internal angle (i.e. closest to 180 deg).
35 Based on routine 'Diagonal' in
37 "Efficient Triangulation of Simple Polygons"
38 Godfried Toussaint, McGill University.
41 After construction is the list of triangles the face is decomposed into.
42 (Or empty list if no valid triangulation could be found).
48 \*---------------------------------------------------------------------------*/
50 #ifndef faceTriangulation_H
51 #define faceTriangulation_H
53 #include "triFaceList.H"
54 #include "pointField.H"
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 // Forward declaration of classes
63 /*---------------------------------------------------------------------------*\
64 Class faceTriangulation Declaration
65 \*---------------------------------------------------------------------------*/
67 class faceTriangulation
73 //- Relative tolerance on edge.
74 static const scalar edgeRelTol;
77 // Static Member Functions
79 //- Edge to the right of face vertex i
80 static label right(const label size, label i);
82 //- Edge to the left of face vertex i
83 static label left(const label size, label i);
85 //- Calculate normalized edge vectors
86 static tmp<vectorField> calcEdges(const face&, const pointField&);
88 //- Calculates half angle components of angle from e0 to e1
89 // in plane given by normal.
90 static void calcHalfAngle
99 //- Calculate intersection point between edge p1-p2 and ray (in 2D).
100 // Return true and intersection point if intersection between p1 and p2.
101 static pointHit rayEdgeIntersect
103 const vector& normal,
104 const point& rayOrigin,
105 const vector& rayDir,
111 // Return true if triangle given its three points
112 // (anticlockwise ordered) contains point
113 static bool triangleContainsPoint
122 //- Starting from startIndex find diagonal. Return in index1, index2.
123 // Index1 always startIndex except when convex polygon
124 static void findDiagonal
126 const pointField& points,
128 const vectorField& edges,
129 const vector& normal,
130 const label startIndex,
135 //- Find label of vertex to start splitting from. This will be the
136 // vertex with edge angle:
137 // 1] flattest concave angle
138 // 2] flattest convex angle if no concave angles.
139 static label findStart
142 const vectorField& edges,
147 // Private Member Functions
149 //- Split face f into triangles. Handles all simple (convex & concave)
150 // polygons. Returns false if could not produce valid split.
154 const pointField& points,
156 const vector& normal,
167 //- Construct from face and points. Decomposition based on average
168 // normal. After construction *this is size 0 or holds the triangles.
169 // If fallBack and triangulation fails does naive triangulation
170 // and never returns 0 size.
173 const pointField& points,
175 const bool fallBack = false
178 //- Construct from face and points and user supplied (unit) normal.
179 // After construction *this is size 0 or holds the triangles.
180 // If fallBack and triangulation fails does naive triangulation
181 // and never returns 0 size.
184 const pointField& points,
187 const bool fallBack = false
190 //- Construct from Istream
191 faceTriangulation(Istream&);
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 } // End namespace Foam
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 // ************************************************************************* //