00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::faceTriangulation 00026 00027 Description 00028 Triangulation of faces. Handles concave polygons as well 00029 (inefficiently) 00030 00031 Works by trying to subdivide the face at the vertex with 'flattest' 00032 internal angle (i.e. closest to 180 deg). 00033 00034 Based on routine 'Diagonal' in 00035 @verbatim 00036 "Efficient Triangulation of Simple Polygons" 00037 Godfried Toussaint, McGill University. 00038 @endverbatim 00039 00040 After construction is the list of triangles the face is decomposed into. 00041 (Or empty list if no valid triangulation could be found). 00042 00043 00044 SourceFiles 00045 faceTriangulation.C 00046 00047 \*---------------------------------------------------------------------------*/ 00048 00049 #ifndef faceTriangulation_H 00050 #define faceTriangulation_H 00051 00052 #include <OpenFOAM/triFaceList.H> 00053 #include <OpenFOAM/pointField.H> 00054 00055 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00056 00057 namespace Foam 00058 { 00059 00060 // Forward declaration of classes 00061 00062 /*---------------------------------------------------------------------------*\ 00063 Class faceTriangulation Declaration 00064 \*---------------------------------------------------------------------------*/ 00065 00066 class faceTriangulation 00067 : 00068 public triFaceList 00069 { 00070 // Static Data 00071 00072 //- Relative tolerance on edge. 00073 static const scalar edgeRelTol; 00074 00075 00076 // Static Member Functions 00077 00078 //- Edge to the right of face vertex i 00079 static label right(const label size, label i); 00080 00081 //- Edge to the left of face vertex i 00082 static label left(const label size, label i); 00083 00084 //- Calculate normalized edge vectors 00085 static tmp<vectorField> calcEdges(const face&, const pointField&); 00086 00087 //- Calculates half angle components of angle from e0 to e1 00088 // in plane given by normal. 00089 static void calcHalfAngle 00090 ( 00091 const vector& normal, 00092 const vector& e0, 00093 const vector& e1, 00094 scalar& cosHalfAngle, 00095 scalar& sinHalfAngle 00096 ); 00097 00098 //- Calculate intersection point between edge p1-p2 and ray (in 2D). 00099 // Return true and intersection point if intersection between p1 and p2. 00100 static pointHit rayEdgeIntersect 00101 ( 00102 const vector& normal, 00103 const point& rayOrigin, 00104 const vector& rayDir, 00105 const point& p1, 00106 const point& p2, 00107 scalar& posOnEdge 00108 ); 00109 00110 // Return true if triangle given its three points 00111 // (anticlockwise ordered) contains point 00112 static bool triangleContainsPoint 00113 ( 00114 const vector& n, 00115 const point& p0, 00116 const point& p1, 00117 const point& p2, 00118 const point& pt 00119 ); 00120 00121 //- Starting from startIndex find diagonal. Return in index1, index2. 00122 // Index1 always startIndex except when convex polygon 00123 static void findDiagonal 00124 ( 00125 const pointField& points, 00126 const face& f, 00127 const vectorField& edges, 00128 const vector& normal, 00129 const label startIndex, 00130 label& index1, 00131 label& index2 00132 ); 00133 00134 //- Find label of vertex to start splitting from. This will be the 00135 // vertex with edge angle: 00136 // 1] flattest concave angle 00137 // 2] flattest convex angle if no concave angles. 00138 static label findStart 00139 ( 00140 const face& f, 00141 const vectorField& edges, 00142 const vector& normal 00143 ); 00144 00145 00146 // Private Member Functions 00147 00148 //- Split face f into triangles. Handles all simple (convex & concave) 00149 // polygons. Returns false if could not produce valid split. 00150 bool split 00151 ( 00152 const bool fallBack, 00153 const pointField& points, 00154 const face& f, 00155 const vector& normal, 00156 label& triI 00157 ); 00158 00159 public: 00160 00161 // Constructors 00162 00163 //- Construct null 00164 faceTriangulation(); 00165 00166 //- Construct from face and points. Decomposition based on average 00167 // normal. After construction *this is size 0 or holds the triangles. 00168 // If fallBack and triangulation fails does naive triangulation 00169 // and never returns 0 size. 00170 faceTriangulation 00171 ( 00172 const pointField& points, 00173 const face& f, 00174 const bool fallBack = false 00175 ); 00176 00177 //- Construct from face and points and user supplied (unit) normal. 00178 // After construction *this is size 0 or holds the triangles. 00179 // If fallBack and triangulation fails does naive triangulation 00180 // and never returns 0 size. 00181 faceTriangulation 00182 ( 00183 const pointField& points, 00184 const face& f, 00185 const vector& n, 00186 const bool fallBack = false 00187 ); 00188 00189 //- Construct from Istream 00190 faceTriangulation(Istream&); 00191 }; 00192 00193 00194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00195 00196 } // End namespace Foam 00197 00198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00199 00200 #endif 00201 00202 // ************************ vim: set sw=4 sts=4 et: ************************ //