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

isoSurfaceCell.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::isoSurfaceCell
00027 
00028 Description
00029     A surface formed by the iso value.
00030     After "Polygonising A Scalar Field Using Tetrahedrons", Paul Bourke
00031     and
00032     "Regularised Marching Tetrahedra: improved iso-surface extraction",
00033     G.M. Treece, R.W. Prager and A.H. Gee.
00034 
00035     See isoSurface. This is a variant which does tetrahedrisation from
00036     triangulation of face to cell centre instead of edge of face to two
00037     neighbouring cell centres. This gives much lower quality triangles
00038     but they are local to a cell.
00039 
00040 SourceFiles
00041     isoSurfaceCell.C
00042 
00043 \*---------------------------------------------------------------------------*/
00044 
00045 #ifndef isoSurfaceCell_H
00046 #define isoSurfaceCell_H
00047 
00048 #include "triSurface.H"
00049 #include "labelPair.H"
00050 #include "pointIndexHit.H"
00051 #include "PackedBoolList.H"
00052 
00053 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00054 
00055 namespace Foam
00056 {
00057 
00058 class polyMesh;
00059 
00060 /*---------------------------------------------------------------------------*\
00061                        Class isoSurfaceCell Declaration
00062 \*---------------------------------------------------------------------------*/
00063 
00064 class isoSurfaceCell
00065 :
00066     public triSurface
00067 {
00068     // Private data
00069 
00070         enum segmentCutType
00071         {
00072             NEARFIRST,      // intersection close to e.first()
00073             NEARSECOND,     //  ,,                   e.second()
00074             NOTNEAR         // no intersection
00075         };
00076 
00077         enum cellCutType
00078         {
00079             NOTCUT,     // not cut
00080             SPHERE,     // all edges to cell centre cut
00081             CUT         // normal cut
00082         };
00083 
00084 
00085         //- Reference to mesh
00086         const polyMesh& mesh_;
00087 
00088         //- isoSurfaceCell value
00089         const scalar iso_;
00090 
00091         //- When to merge points
00092         const scalar mergeDistance_;
00093 
00094         //- Whether cell might be cut
00095         List<cellCutType> cellCutType_;
00096 
00097         //- Estimated number of cut cells
00098         label nCutCells_;
00099 
00100         //- For every triangle the original cell in mesh
00101         labelList meshCells_;
00102 
00103         //- For every unmerged triangle point the point in the triSurface
00104         labelList triPointMergeMap_;
00105 
00106 
00107     // Private Member Functions
00108 
00109         //- Get location of iso value as fraction inbetween s0,s1
00110         scalar isoFraction
00111         (
00112             const scalar s0,
00113             const scalar s1
00114         ) const;
00115 
00116         //List<triFace> triangulate(const face& f) const;
00117 
00118         //- Determine whether cell is cut
00119         cellCutType calcCutType
00120         (
00121             const PackedBoolList&,
00122             const scalarField& cellValues,
00123             const scalarField& pointValues,
00124             const label
00125         ) const;
00126 
00127         void calcCutTypes
00128         (
00129             const PackedBoolList&,
00130             const scalarField& cellValues,
00131             const scalarField& pointValues
00132         );
00133 
00134         static labelPair findCommonPoints
00135         (
00136             const labelledTri&,
00137             const labelledTri&
00138         );
00139 
00140         static point calcCentre(const triSurface&);
00141 
00142         static pointIndexHit collapseSurface
00143         (
00144             pointField& localPoints,
00145             DynamicList<labelledTri, 64>& localTris
00146         );
00147 
00148         //- Determine per cc whether all near cuts can be snapped to single
00149         //  point.
00150         void calcSnappedCc
00151         (
00152             const PackedBoolList& isTet,
00153             const scalarField& cVals,
00154             const scalarField& pVals,
00155             DynamicList<point>& triPoints,
00156             labelList& snappedCc
00157         ) const;
00158 
00159         //- Generate triangles for face connected to pointI
00160         void genPointTris
00161         (
00162             const scalarField& cellValues,
00163             const scalarField& pointValues,
00164             const label pointI,
00165             const face& f,
00166             const label cellI,
00167             DynamicList<point, 64>& localTriPoints
00168         ) const;
00169 
00170         //- Generate triangles for tet connected to pointI
00171         void genPointTris
00172         (
00173             const scalarField& pointValues,
00174             const label pointI,
00175             const label cellI,
00176             DynamicList<point, 64>& localTriPoints
00177         ) const;
00178 
00179         //- Determine per point whether all near cuts can be snapped to single
00180         //  point.
00181         void calcSnappedPoint
00182         (
00183             const PackedBoolList& isBoundaryPoint,
00184             const PackedBoolList& isTet,
00185             const scalarField& cVals,
00186             const scalarField& pVals,
00187             DynamicList<point>& triPoints,
00188             labelList& snappedPoint
00189         ) const;
00190 
00191         //- Generate single point by interpolation or snapping
00192         template<class Type>
00193         Type generatePoint
00194         (
00195             const DynamicList<Type>& snappedPoints,
00196             const scalar s0,
00197             const Type& p0,
00198             const label p0Index,
00199             const scalar s1,
00200             const Type& p1,
00201             const label p1Index
00202         ) const;
00203 
00204         template<class Type>
00205         void generateTriPoints
00206         (
00207             const DynamicList<Type>& snapped,
00208             const scalar s0,
00209             const Type& p0,
00210             const label p0Index,
00211             const scalar s1,
00212             const Type& p1,
00213             const label p1Index,
00214             const scalar s2,
00215             const Type& p2,
00216             const label p2Index,
00217             const scalar s3,
00218             const Type& p3,
00219             const label p3Index,
00220             DynamicList<Type>& points
00221         ) const;
00222 
00223         template<class Type>
00224         void generateTriPoints
00225         (
00226             const scalarField& cVals,
00227             const scalarField& pVals,
00228 
00229             const Field<Type>& cCoords,
00230             const Field<Type>& pCoords,
00231 
00232             const DynamicList<Type>& snappedPoints,
00233             const labelList& snappedCc,
00234             const labelList& snappedPoint,
00235 
00236             DynamicList<Type>& triPoints,
00237             DynamicList<label>& triMeshCells
00238         ) const;
00239 
00240         triSurface stitchTriPoints
00241         (
00242             const bool checkDuplicates,
00243             const List<point>& triPoints,
00244             labelList& triPointReverseMap,  // unmerged to merged point
00245             labelList& triMap               // merged to unmerged triangle
00246         ) const;
00247 
00248         //- Check single triangle for (topological) validity
00249         static bool validTri(const triSurface&, const label);
00250 
00251         //- Determine edge-face addressing
00252         void calcAddressing
00253         (
00254             const triSurface& surf,
00255             List<FixedList<label, 3> >& faceEdges,
00256             labelList& edgeFace0,
00257             labelList& edgeFace1,
00258             Map<labelList>& edgeFacesRest
00259         ) const;
00260 
00261         //- Determine orientation
00262         static void walkOrientation
00263         (
00264             const triSurface& surf,
00265             const List<FixedList<label, 3> >& faceEdges,
00266             const labelList& edgeFace0,
00267             const labelList& edgeFace1,
00268             const label seedTriI,
00269             labelList& flipState
00270         );
00271 
00272         //- Orient surface
00273         static void orientSurface
00274         (
00275             triSurface&,
00276             const List<FixedList<label, 3> >& faceEdges,
00277             const labelList& edgeFace0,
00278             const labelList& edgeFace1,
00279             const Map<labelList>& edgeFacesRest
00280         );
00281 
00282         //- Is triangle (given by 3 edges) not fully connected?
00283         static bool danglingTriangle
00284         (
00285             const FixedList<label, 3>& fEdges,
00286             const labelList& edgeFace1
00287         );
00288 
00289         //- Mark all non-fully connected triangles
00290         static label markDanglingTriangles
00291         (
00292             const List<FixedList<label, 3> >& faceEdges,
00293             const labelList& edgeFace0,
00294             const labelList& edgeFace1,
00295             const Map<labelList>& edgeFacesRest,
00296             boolList& keepTriangles
00297         );
00298 
00299         static triSurface subsetMesh
00300         (
00301             const triSurface& s,
00302             const labelList& newToOldFaces,
00303             labelList& oldToNewPoints,
00304             labelList& newToOldPoints
00305         );
00306 
00307         //- Combine all triangles inside a cell into a minimal triangulation
00308         void combineCellTriangles();
00309 
00310 public:
00311 
00312     //- Runtime type information
00313     TypeName("isoSurfaceCell");
00314 
00315 
00316     // Constructors
00317 
00318         //- Construct from dictionary
00319         isoSurfaceCell
00320         (
00321             const polyMesh& mesh,
00322             const scalarField& cellValues,
00323             const scalarField& pointValues,
00324             const scalar iso,
00325             const bool regularise,
00326             const scalar mergeTol = 1E-6    // fraction of bounding box
00327         );
00328 
00329 
00330     // Member Functions
00331 
00332         //- For every face original cell in mesh
00333         const labelList& meshCells() const
00334         {
00335             return meshCells_;
00336         }
00337 
00338         //- For every unmerged triangle point the point in the triSurface
00339         const labelList triPointMergeMap() const
00340         {
00341             return triPointMergeMap_;
00342         }
00343 
00344 
00345         //- Interpolates cCoords,pCoords. Takes the original fields
00346         //  used to create the iso surface.
00347         template <class Type>
00348         tmp<Field<Type> > interpolate
00349         (
00350             const scalarField& cVals,
00351             const scalarField& pVals,
00352             const Field<Type>& cCoords,
00353             const Field<Type>& pCoords
00354         ) const;
00355 };
00356 
00357 
00358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00359 
00360 } // End namespace Foam
00361 
00362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00363 
00364 #ifdef NoRepository
00365 #   include "isoSurfaceCellTemplates.C"
00366 #endif
00367 
00368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00369 
00370 #endif
00371 
00372 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd