FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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