OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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