OpenFOAM logo
Open Source CFD Toolkit

triSurfaceTools.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     triSurfaceTools
00027 
00028 Description
00029 
00030 SourceFiles
00031     triSurfaceTools.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef triSurfaceTools_H
00036 #define triSurfaceTools_H
00037 
00038 #include "label.H"
00039 #include "labelList.H"
00040 #include "boolList.H"
00041 #include "point.H"
00042 #include "pointField.H"
00043 #include "HashTable.H"
00044 #include "DynamicList.H"
00045 #include "labelHashSet.H"
00046 #include "FixedList.H"
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050 namespace Foam
00051 {
00052 
00053 // Class forward declarations
00054 class triSurface;
00055 class edge;
00056 class labelledTri;
00057 class polyBoundaryMesh;
00058 
00059 /*---------------------------------------------------------------------------*\
00060                            Class triSurfaceTools Declaration
00061 \*---------------------------------------------------------------------------*/
00062 
00063 namespace triSurfaceTools
00064 {
00065     //- Write pointField to OBJ format file
00066     void writeOBJ
00067     (
00068         const fileName& fName,
00069         const pointField& pts
00070     );
00071 
00072     //- Write vertex subset to OBJ format file
00073     void writeOBJ
00074     (
00075         const triSurface& surf,
00076         const fileName& fName,
00077         const boolList& markedVerts
00078     );
00079 
00080     //- Get all triangles using edge endpoint
00081     void getVertexTriangles
00082     (
00083         const triSurface& surf,
00084         const label edgeI,
00085         labelList& edgeTris
00086     );
00087 
00088     //- Get all vertices (local numbering) connected to vertices of edge
00089     labelList getVertexVertices
00090     (
00091         const triSurface& surf,
00092         const edge& e
00093     );
00094 
00095     //- Get all edges of triangle in face ordering (elem 0 is edge between
00096     //  f[0] .. f[1], elem1 between f[1]..f[2] etc)
00097     FixedList<label, 3> sortedFaceEdges
00098     (
00099         const triSurface& surf,
00100         const label faceI
00101     );
00102 
00103     //- Order vertices consistent with face
00104     void orderVertices
00105     (
00106         const labelledTri& f,
00107         const label v1,
00108         const label v2,
00109         label& vA,
00110         label& vB
00111     );
00112 
00113     //- Get face connected to edge not faceI
00114     label otherFace
00115     (
00116         const triSurface& surf,
00117         const label faceI,
00118         const label edgeI
00119     );
00120 
00121     //- Get the two edges on faceI counterclockwise after edgeI
00122     void otherEdges
00123     (
00124         const triSurface& surf,
00125         const label faceI,
00126         const label edgeI,
00127         label& e1,
00128         label& e2
00129     );
00130 
00131     //- Get the two vertices (local numbering) on faceI counterclockwise vertI
00132     void otherVertices
00133     (
00134         const triSurface& surf,
00135         const label faceI,
00136         const label vertI,
00137         label& vert1I,
00138         label& vert2I
00139     );
00140 
00141     //- Get edge opposite vertex (local numbering)
00142     label oppositeEdge
00143     (
00144         const triSurface& surf,
00145         const label faceI,
00146         const label vertI
00147     );
00148 
00149     //- Get vertex (local numbering) opposite edge
00150     label oppositeVertex
00151     (
00152         const triSurface& surf,
00153         const label faceI,
00154         const label edgeI
00155     );
00156 
00157     //- Returns edge label connecting v1, v2 (local numbering)
00158     label getEdge
00159     (
00160         const triSurface& surf,
00161         const label vert1I,
00162         const label vert2I
00163     );
00164 
00165     //- Return index of triangle (or -1) using all three edges
00166     label getTriangle
00167     (
00168         const triSurface& surf,
00169         const label e0I,
00170         const label e1I,
00171         const label e2I
00172     );
00173 
00174     //- Returns element in edgeIndices with minimum length
00175     label minEdge
00176     (
00177         const triSurface& surf,
00178         const labelList& edgeIndices
00179     );
00180 
00181     //- Returns element in edgeIndices with minimum length
00182     label maxEdge
00183     (
00184         const triSurface& surf,
00185         const labelList& edgeIndices
00186     );
00187 
00188     scalar faceCosAngle
00189     (
00190         const point& pStart,
00191         const point& pEnd,
00192         const point& pLeft,
00193         const point& pRight
00194     );
00195 
00196     //- Estimate angle of vec in coordinate system (e0, e1, e0^e1).
00197     //  Is guaranteed to return increasing number but is not correct
00198     //  angle. Used for sorting angles.
00199     //  All input vectors need to be normalized.
00200     scalar pseudoAngle
00201     (
00202         const vector& e0,
00203         const vector& e1,
00204         const vector& vec
00205     );
00206 
00207 
00208     //- faces to collapse because of edge collapse
00209     labelHashSet getCollapsedFaces
00210     (
00211         const triSurface& surf,
00212         label edgeI
00213     );
00214 
00215     // Return value of faceUsed for faces using vertI (local numbering).
00216     // Used internally.
00217     label vertexUsesFace
00218     (
00219         const triSurface& surf,
00220         const labelHashSet& faceUsed,
00221         const label vertI
00222     );
00223 
00224     // Get new connections between faces (because of edge collapse) in form of
00225     // tables:
00226     //  - given edge get other edge
00227     //  - given edge get other face
00228     // A face using point v1 on edge will get connected to a face using point v2
00229     // if they share a common vertex (but not a common edge since then the
00230     // triangles collapse to nothing)
00231     void getMergedEdges
00232     (
00233         const triSurface& surf,
00234         const label edgeI,
00235         const labelHashSet& collapsedFaces,
00236         HashTable<label, label, Hash<label> >& edgeToEdge,
00237         HashTable<label, label, Hash<label> >& edgeToFace
00238     );
00239 
00240     //- Calculates (cos of) angle across edgeI of faceI,
00241     //  taking into account updated addressing (resulting from edge collapse)
00242     scalar edgeCosAngle
00243     (
00244         const triSurface& surf,
00245         const label v1,
00246         const point& pt,
00247         const labelHashSet& collapsedFaces,
00248         const HashTable<label, label, Hash<label> >& edgeToEdge,
00249         const HashTable<label, label, Hash<label> >& edgeToFace,
00250         const label faceI,
00251         const label edgeI
00252     );
00253 
00254     //- Calculate minimum (cos of) edge angle using addressing from collapsing
00255     //  edge to v1 at pt. Returns 1 if v1 is on edge without neighbours
00256     //  (and hence no edge angle can be defined)
00257     scalar collapseMinCosAngle
00258     (
00259         const triSurface& surf,
00260         const label v1,
00261         const point& pt,
00262         const labelHashSet& collapsedFaces,
00263         const HashTable<label, label, Hash<label> >& edgeToEdge,
00264         const HashTable<label, label, Hash<label> >& edgeToFace
00265     );
00266 
00267     //- Like collapseMinCosAngle but return true for value < minCos 
00268     bool collapseCreatesFold
00269     (
00270         const triSurface& surf,
00271         const label v1,
00272         const point& pt,
00273         const labelHashSet& collapsedFaces,
00274         const HashTable<label, label, Hash<label> >& edgeToEdge,
00275         const HashTable<label, label, Hash<label> >& edgeToFace,
00276         const scalar minCos
00277     );
00278 
00279 //    //- Checks if edge collapse creates triangles on top of each other
00280 //    bool collapseCreatesDuplicates
00281 //    (
00282 //        const triSurface& surf,
00283 //        const label edgeI,
00284 //        const HashTable<bool, label, Hash<label> >& collapsedFaces
00285 //    );
00286 
00287     //- Face collapse status.
00288     //  anyEdge: any edge can be collapsed
00289     //  noEdge: no edge can be collapsed
00290     //  collapsed: already collapsed
00291     //  >0: edge label that can be collapsed
00292     static const label ANYEDGE = -1;
00293     static const label NOEDGE = -2;
00294     static const label COLLAPSED = -3;
00295 
00296     void protectNeighbours
00297     (
00298         const triSurface& surf,
00299         const label vertI,
00300         labelList& faceStatus
00301     );
00302 
00303     //- Create new triSurface by collapsing edges to edge mids.
00304     triSurface collapseEdges
00305     (
00306         const triSurface& surf,
00307         const labelList& collapsableEdges
00308     );
00309 
00310     //- Create new triSurface by collapsing edges to specified
00311     //  positions. faceStatus allows
00312     //  explicit control over which faces need to be protected (see above).
00313     //  faceStatus gets updated to protect collapsing already collapsed faces.
00314     triSurface collapseEdges
00315     (
00316         const triSurface& surf,
00317         const labelList& collapsableEdges,
00318         const pointField& edgeMids,
00319         labelList& faceStatus
00320     );
00321 
00322     enum refineType
00323     {
00324         NONE,
00325         RED,
00326         GREEN
00327     };
00328 
00329     void calcRefineStatus
00330     (
00331         const triSurface& surf,
00332         const label faceI,
00333         labelList& refine
00334     );
00335 
00336     void greenRefine
00337     (
00338         const triSurface& surf,
00339         const label faceI,
00340         const label edgeI,
00341         const label newPointI,
00342         DynamicList<labelledTri>& newFaces
00343     );
00344 
00345     //- Refine edges by splitting to opposite vertex
00346     triSurface greenRefine
00347     (
00348         const triSurface& surf,
00349         const labelList& refineEdges
00350     );
00351 
00352     triSurface doRefine
00353     (
00354         const triSurface& surf,
00355         const labelList& refineStatus
00356     );
00357 
00358     //- Refine face by splitting all edges. Neighbouring face is greenRefine'd.
00359     triSurface redGreenRefine
00360     (
00361         const triSurface& surf,
00362         const labelList& refineFaces
00363     );
00364 
00365     //- Merge points within distance
00366     triSurface mergePoints
00367     (
00368         const triSurface& surf,
00369         const scalar mergeTol
00370     );
00371 
00372     //- Triangle (unit) normal. If nearest point to triangle on edge use edge
00373     //  normal (calculated on the fly); if on vertex use vertex normal.
00374     //  Uses planarTol.
00375     vector surfaceNormal
00376     (
00377         const triSurface& surf,
00378         const label nearestFaceI,
00379         const point& nearestPt
00380     );
00381 
00382     //- Simple triangulation of (selected patches of) boundaryMesh. Needs
00383     //  polyMesh (or polyBoundaryMesh) since only at this level are the
00384     //  triangles on neighbouring patches connected.
00385     triSurface triangulate
00386     (
00387         const polyBoundaryMesh& mBesh,
00388         const labelHashSet& includePatches,
00389         const bool verbose = false
00390     );
00391 
00392     //- Face-centre triangulation of (selected patches of) boundaryMesh. Needs
00393     //  polyMesh (or polyBoundaryMesh) since only at this level are the
00394     //  triangles on neighbouring patches connected.
00395     triSurface triangulateFaceCentre
00396     (
00397         const polyBoundaryMesh& mBesh,
00398         const labelHashSet& includePatches,
00399         const bool verbose = false
00400     );
00401 }
00402 
00403 
00404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00405 
00406 } // End namespace Foam
00407 
00408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00409 
00410 #endif
00411 
00412 // ************************************************************************* //
For further information go to www.openfoam.org