1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
25 Foam::faceTriangulation
28 Triangulation of faces. Handles concave polygons as well
31 Works by trying to subdivide the face at the vertex with 'flattest'
32 internal angle (i.e. closest to 180 deg).
34 Based on routine 'Diagonal' in
36 "Efficient Triangulation of Simple Polygons"
37 Godfried Toussaint, McGill University.
40 After construction is the list of triangles the face is decomposed into.
41 (Or empty list if no valid triangulation could be found).
47 \*---------------------------------------------------------------------------*/
49 #ifndef faceTriangulation_H
50 #define faceTriangulation_H
52 #include "triFaceList.H"
53 #include "pointField.H"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 // Forward declaration of classes
62 /*---------------------------------------------------------------------------*\
63 Class faceTriangulation Declaration
64 \*---------------------------------------------------------------------------*/
66 class faceTriangulation
72 //- Relative tolerance on edge.
73 static const scalar edgeRelTol;
76 // Static Member Functions
78 //- Edge to the right of face vertex i
79 static label right(const label size, label i);
81 //- Edge to the left of face vertex i
82 static label left(const label size, label i);
84 //- Calculate normalized edge vectors
85 static tmp<vectorField> calcEdges(const face&, const pointField&);
87 //- Calculates half angle components of angle from e0 to e1
88 // in plane given by normal.
89 static void calcHalfAngle
98 //- Calculate intersection point between edge p1-p2 and ray (in 2D).
99 // Return true and intersection point if intersection between p1 and p2.
100 static pointHit rayEdgeIntersect
102 const vector& normal,
103 const point& rayOrigin,
104 const vector& rayDir,
110 // Return true if triangle given its three points
111 // (anticlockwise ordered) contains point
112 static bool triangleContainsPoint
121 //- Starting from startIndex find diagonal. Return in index1, index2.
122 // Index1 always startIndex except when convex polygon
123 static void findDiagonal
125 const pointField& points,
127 const vectorField& edges,
128 const vector& normal,
129 const label startIndex,
134 //- Find label of vertex to start splitting from. This will be the
135 // vertex with edge angle:
136 // 1] flattest concave angle
137 // 2] flattest convex angle if no concave angles.
138 static label findStart
141 const vectorField& edges,
146 // Private Member Functions
148 //- Split face f into triangles. Handles all simple (convex & concave)
149 // polygons. Returns false if could not produce valid split.
153 const pointField& points,
155 const vector& normal,
166 //- Construct from face and points. Decomposition based on average
167 // normal. After construction *this is size 0 or holds the triangles.
168 // If fallBack and triangulation fails does naive triangulation
169 // and never returns 0 size.
172 const pointField& points,
174 const bool fallBack = false
177 //- Construct from face and points and user supplied (unit) normal.
178 // After construction *this is size 0 or holds the triangles.
179 // If fallBack and triangulation fails does naive triangulation
180 // and never returns 0 size.
183 const pointField& points,
186 const bool fallBack = false
189 //- Construct from Istream
190 faceTriangulation(Istream&);
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 } // End namespace Foam
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 // ************************************************************************* //