OpenFOAM logo
Open Source CFD Toolkit

faceTriangulation.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     faceTriangulation
00027 
00028 Description
00029     Triangulation of faces. Handles concave polygons as well
00030     (ineffeciently)
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 
00036     "Efficient Triangulation of Simple Polygons"
00037     Godfried Toussaint, McGill University.
00038 
00039     After construction is the list of triangles the face is decomposed into.
00040     (Or empty list if no valid triangulation could be found).
00041 
00042 
00043 SourceFiles
00044     faceTriangulation.C
00045 
00046 \*---------------------------------------------------------------------------*/
00047 
00048 #ifndef faceTriangulation_H
00049 #define faceTriangulation_H
00050 
00051 #include "triFaceList.H"
00052 #include "pointField.H"
00053 
00054 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00055 
00056 namespace Foam
00057 {
00058 
00059 // Class forward declarations
00060 
00061 /*---------------------------------------------------------------------------*\
00062                            Class faceTriangulation Declaration
00063 \*---------------------------------------------------------------------------*/
00064 
00065 class faceTriangulation
00066 :
00067     public triFaceList
00068 {
00069     // Static Data
00070 
00071         //- Relative tolerance on edge.
00072         static const scalar edgeRelTol;
00073 
00074 
00075     // Static Member Functions
00076 
00077         //- Edge to the right of face vertex i
00078         static label right(const label size, label i);
00079 
00080         //- Edge to the left of face vertex i
00081         static label left(const label size, label i);
00082 
00083         //- Calculate normalized edge vectors
00084         static tmp<vectorField> calcEdges(const face&, const pointField&);
00085 
00086         //- Calculates half angle components of angle from e0 to e1
00087         //  in plane given by normal.
00088         static void calcHalfAngle
00089         (
00090             const vector& normal,
00091             const vector& e0,
00092             const vector& e1,
00093             scalar& cosHalfAngle,
00094             scalar& sinHalfAngle
00095         );
00096 
00097         //- Calculate intersection point between edge p1-p2 and ray (in 2D).
00098         // Return true and intersection point if intersection between p1 and p2.
00099         static pointHit rayEdgeIntersect
00100         (
00101             const vector& normal, 
00102             const point& rayOrigin,
00103             const vector& rayDir,
00104             const point& p1,
00105             const point& p2,
00106             scalar& posOnEdge
00107         );
00108 
00109         // Return true if triangle given its three points
00110         // (anticlockwise ordered) contains point
00111         static bool triangleContainsPoint
00112         (
00113             const vector& n,
00114             const point& p0,
00115             const point& p1,
00116             const point& p2,
00117             const point& pt
00118         );
00119 
00120         //- Starting from startIndex find diagonal. Return in index1, index2.
00121         //  Index1 always startIndex except when convex polygon
00122         static void findDiagonal
00123         (
00124             const pointField& points,
00125             const face& f,
00126             const vectorField& edges,
00127             const vector& normal,
00128             const label startIndex,
00129             label& index1,
00130             label& index2
00131         );
00132 
00133         //- Find label of vertex to start splitting from. This will be the
00134         //  vertex with edge angle:
00135         //     1] flattest concave angle
00136         //     2] flattest convex angle if no concave angles.
00137         static label findStart
00138         (
00139             const face& f,
00140             const vectorField& edges,
00141             const vector& normal
00142         );
00143 
00144 
00145     // Private Member Functions
00146 
00147         //- Split face f into triangles. Handles all simple (convex & concave)
00148         //  polygons. Returns false if could not produce valid split.
00149         bool split
00150         (
00151             const bool fallBack,
00152             const pointField& points,
00153             const face& f,
00154             const vector& normal,
00155             label& triI
00156         );
00157 
00158 public:
00159 
00160     // Constructors
00161 
00162         //- Construct null
00163         faceTriangulation();
00164 
00165         //- Construct from face and points. Decomposition based on average
00166         //  normal. After construction *this is size 0 or holds the triangles.
00167         //  If fallBack and triangulation fails does naive triangulation
00168         //  and never returns 0 size.
00169         faceTriangulation
00170         (
00171             const pointField& points,
00172             const face& f,
00173             const bool fallBack = false
00174         );
00175 
00176         //- Construct from face and points and user supplied (unit) normal.
00177         //  After construction *this is size 0 or holds the triangles.
00178         //  If fallBack and triangulation fails does naive triangulation
00179         //  and never returns 0 size.
00180         faceTriangulation
00181         (
00182             const pointField& points,
00183             const face& f,
00184             const vector& n,
00185             const bool fallBack = false
00186         );
00187 
00188         //- Construct from Istream
00189         faceTriangulation(Istream&);
00190 };
00191 
00192 
00193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00194 
00195 } // End namespace Foam
00196 
00197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00198 
00199 #endif
00200 
00201 // ************************************************************************* //
For further information go to www.openfoam.org