faceTriangulation.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Class
25  Foam::faceTriangulation
26 
27 Description
28  Triangulation of faces. Handles concave polygons as well
29  (inefficiently)
30 
31  Works by trying to subdivide the face at the vertex with 'flattest'
32  internal angle (i.e. closest to 180 deg).
33 
34  Based on routine 'Diagonal' in
35  \verbatim
36  "Efficient Triangulation of Simple Polygons"
37  Godfried Toussaint, McGill University.
38  \endverbatim
39 
40  After construction is the list of triangles the face is decomposed into.
41  (Or empty list if no valid triangulation could be found).
42 
43 
44 SourceFiles
45  faceTriangulation.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef faceTriangulation_H
50 #define faceTriangulation_H
51 
52 #include "triFaceList.H"
53 #include "pointField.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward declaration of classes
61 
62 /*---------------------------------------------------------------------------*\
63  Class faceTriangulation Declaration
64 \*---------------------------------------------------------------------------*/
65 
67 :
68  public triFaceList
69 {
70  // Static Data
71 
72  //- Relative tolerance on edge.
73  static const scalar edgeRelTol;
74 
75 
76  // Static Member Functions
77 
78  //- Edge to the right of face vertex i
79  static label right(const label size, label i);
80 
81  //- Edge to the left of face vertex i
82  static label left(const label size, label i);
83 
84  //- Calculate normalized edge vectors
85  static tmp<vectorField> calcEdges(const face&, const pointField&);
86 
87  //- Calculates half angle components of angle from e0 to e1
88  // in plane given by normal.
89  static void calcHalfAngle
90  (
91  const vector& normal,
92  const vector& e0,
93  const vector& e1,
94  scalar& cosHalfAngle,
95  scalar& sinHalfAngle
96  );
97 
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
101  (
102  const vector& normal,
103  const point& rayOrigin,
104  const vector& rayDir,
105  const point& p1,
106  const point& p2,
107  scalar& posOnEdge
108  );
109 
110  // Return true if triangle given its three points
111  // (anticlockwise ordered) contains point
112  static bool triangleContainsPoint
113  (
114  const vector& n,
115  const point& p0,
116  const point& p1,
117  const point& p2,
118  const point& pt
119  );
120 
121  //- Starting from startIndex find diagonal. Return in index1, index2.
122  // Index1 always startIndex except when convex polygon
123  static void findDiagonal
124  (
125  const pointField& points,
126  const face& f,
127  const vectorField& edges,
128  const vector& normal,
129  const label startIndex,
130  label& index1,
131  label& index2
132  );
133 
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
139  (
140  const face& f,
141  const vectorField& edges,
142  const vector& normal
143  );
144 
145 
146  // Private Member Functions
147 
148  //- Split face f into triangles. Handles all simple (convex & concave)
149  // polygons. Returns false if could not produce valid split.
150  bool split
151  (
152  const bool fallBack,
153  const pointField& points,
154  const face& f,
155  const vector& normal,
156  label& triI
157  );
158 
159 public:
160 
161  // Constructors
162 
163  //- Construct null
165 
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.
171  (
172  const pointField& points,
173  const face& f,
174  const bool fallBack = false
175  );
176 
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.
182  (
183  const pointField& points,
184  const face& f,
185  const vector& n,
186  const bool fallBack = false
187  );
188 
189  //- Construct from Istream
191 };
192 
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 } // End namespace Foam
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 #endif
201 
202 // ************************************************************************* //
const pointField & points
labelList f(nPoints)
faceTriangulation()
Construct null.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Namespace for OpenFOAM.
label n
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Triangulation of faces. Handles concave polygons as well (inefficiently)
A normal distribution model.
label size() const
Return the number of elements in the UList.
Definition: ListI.H:83
A class for managing temporary objects.
Definition: PtrList.H:118