OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

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