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

triSurface.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::triSurface
00027 
00028 Description
00029     Triangulated surface description with patch information.
00030 
00031 SourceFiles
00032     triSurface.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef triSurface_H
00037 #define triSurface_H
00038 
00039 #include "PrimitivePatch.H"
00040 #include "pointField.H"
00041 #include "labelledTri.H"
00042 #include "boolList.H"
00043 #include "geometricSurfacePatchList.H"
00044 #include "surfacePatchList.H"
00045 #include "triFaceList.H"
00046 
00047 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00048 
00049 namespace Foam
00050 {
00051 
00052 class Time;
00053 class IFstream;
00054 
00055 /*---------------------------------------------------------------------------*\
00056                            Class triSurface Declaration
00057 \*---------------------------------------------------------------------------*/
00058 
00059 class triSurface
00060 :
00061     public PrimitivePatch<labelledTri, ::Foam::List, pointField, point>
00062 {
00063     // Private typedefs
00064 
00065     //- Typedefs for convenience
00066         typedef labelledTri Face;
00067         typedef PrimitivePatch
00068         <
00069             labelledTri,
00070             ::Foam::List,
00071             pointField,
00072             point
00073         >
00074         ParentType;
00075 
00076 
00077     // Private data
00078 
00079         //- The number of bytes in the STL header
00080         static const int STLheaderSize = 80;
00081 
00082         //- Patch information (face ordering nFaces/startFace only used
00083         //  during reading and writing)
00084         geometricSurfacePatchList patches_;
00085 
00086 
00087     // Demand driven private data.
00088 
00089         //- Edge-face addressing (sorted)
00090         mutable labelListList* sortedEdgeFacesPtr_;
00091 
00092         //- Label of face that 'owns' edge (i.e. e.vec() is righthanded walk
00093         //  along face)
00094         mutable labelList* edgeOwnerPtr_;
00095 
00096 
00097     // Private member functions
00098 
00099         //- Calculate sorted edgeFaces
00100         void calcSortedEdgeFaces() const;
00101 
00102         //- Calculate owner
00103         void calcEdgeOwner() const;
00104 
00105         //- Sort faces according to region. Returns patch list
00106         //  and sets faceMap to index of labelledTri inside *this.
00107         surfacePatchList calcPatches(labelList& faceMap) const;
00108 
00109         //- Sets default values for patches
00110         void setDefaultPatches();
00111 
00112         //- Function to stitch the triangles by removing duplicate points.
00113         //  Returns true if any points merged
00114         bool stitchTriangles
00115         (
00116             const pointField& rawPoints,
00117             const scalar tol = SMALL,
00118             const bool verbose = false
00119         );
00120 
00121         //- Read in Foam format
00122         bool read(Istream&);
00123 
00124         //- Generic read routine. Chooses reader based on extension.
00125         bool read(const fileName&, const word& ext, const bool check = true);
00126 
00127         bool readSTL(const fileName&);
00128         bool readSTLASCII(const fileName&);
00129         bool readSTLBINARY(const fileName&);
00130         bool readGTS(const fileName&);
00131         bool readOBJ(const fileName&);
00132         bool readOFF(const fileName&);
00133         bool readTRI(const fileName&);
00134         bool readAC(const fileName&);
00135         bool readNAS(const fileName&);
00136 
00137         //- Generic write routine. Chooses writer based on extension.
00138         void write(const fileName&, const word& ext, const bool sort) const;
00139 
00140         //- Write to Ostream in ASCII STL format.
00141         //  Each region becomes 'solid' 'endsolid' block.
00142         void writeSTLASCII(Ostream&) const;
00143 
00144         //- Write to std::ostream in BINARY STL format
00145         void writeSTLBINARY(std::ostream&) const;
00146 
00147         //- Write to Ostream in GTS (Gnu Tri Surface library)
00148         //  format.
00149         void writeGTS(const bool writeSorted, Ostream&) const;
00150 
00151         //- Write to Ostream in OBJ (Lightwave) format.
00152         //  writeSorted=true: sort faces acc. to region and write as single
00153         //  group. =false: write in normal order.
00154         void writeOBJ(const bool writeSorted, Ostream&) const;
00155 
00156         //- Write to Ostream in OFF (Geomview) format.
00157         //  writeSorted=true: sort faces acc. to region and write as single
00158         //  group. =false: write in normal order.
00159         void writeOFF(const bool writeSorted, Ostream&) const;
00160 
00161         //- Write to VTK legacy format.
00162         void writeVTK(const bool writeSorted, Ostream&) const;
00163 
00164         //- Write to Ostream in TRI (AC3D) format
00165         //  Ac3d .tri format (unmerged triangle format)
00166         void writeTRI(const bool writeSorted, Ostream&) const;
00167 
00168         //- Write to Ostream in SMESH (tetgen) format
00169         void writeSMESH(const bool writeSorted, Ostream&) const;
00170 
00171         //- Write to Ostream in AC3D format. Always sorted by patch.
00172         void writeAC(Ostream&) const;
00173 
00174         //- For DX writing.
00175         void writeDX(const bool, Ostream&) const;
00176         void writeDXGeometry(const bool, Ostream&) const;
00177         void writeDXTrailer(Ostream&) const;
00178 
00179     // Static private functions
00180 
00181         //- Convert faces to labelledTri. All get same region.
00182         static List<labelledTri> convertToTri
00183         (
00184             const faceList&,
00185             const label defaultRegion = 0
00186         );
00187 
00188         //- Convert triFaces to labelledTri. All get same region.
00189         static List<labelledTri> convertToTri
00190         (
00191             const triFaceList&,
00192             const label defaultRegion = 0
00193         );
00194 
00195         //- helper function to print triangle info
00196         static void printTriangle
00197         (
00198             Ostream&,
00199             const Foam::string& pre,
00200             const labelledTri&,
00201             const pointField&
00202         );
00203 
00204         //- read non-comment line
00205         static string getLineNoComment(IFstream&);
00206 
00207 protected:
00208 
00209     // Protected Member Functions
00210 
00211         //- Non-const access to global points
00212         pointField& storedPoints()
00213         {
00214             return const_cast<pointField&>(ParentType::points());
00215         }
00216 
00217         //- Non-const access to the faces
00218         List<Face>& storedFaces()
00219         {
00220             return static_cast<List<Face>&>(*this);
00221         }
00222 
00223 public:
00224 
00225     // Public typedefs
00226 
00227         //- Placeholder only, but do not remove - it is needed for GeoMesh
00228         typedef bool BoundaryMesh;
00229 
00230 
00231         //- Runtime type information
00232         ClassName("triSurface");
00233 
00234 
00235     // Static
00236 
00237         //- Name of triSurface directory to use.
00238         static fileName triSurfInstance(const Time&);
00239 
00240 
00241     // Constructors
00242 
00243         //- Construct null
00244         triSurface();
00245 
00246         //- Construct from triangles, patches, points.
00247         triSurface
00248         (
00249             const List<labelledTri>&,
00250             const geometricSurfacePatchList&,
00251             const pointField&
00252         );
00253 
00254         //- Construct from triangles, patches, points. Reuse storage.
00255         triSurface
00256         (
00257             List<labelledTri>&,
00258             const geometricSurfacePatchList&,
00259             pointField&,
00260             const bool reUse
00261         );
00262 
00263         //- Construct from triangles, points. Set patchnames to default.
00264         triSurface(const List<labelledTri>&, const pointField&);
00265 
00266         //- Construct from triangles, points. Set region to 0 and default
00267         //  patchName.
00268         triSurface(const triFaceList&, const pointField&);
00269 
00270         //- Construct from file name (uses extension to determine type)
00271         triSurface(const fileName&);
00272 
00273         //- Construct from Istream
00274         triSurface(Istream&);
00275 
00276         //- Construct from objectRegistry
00277         triSurface(const Time& d);
00278 
00279         //- Construct as copy
00280         triSurface(const triSurface&);
00281 
00282 
00283 
00284     // Destructor
00285 
00286         ~triSurface();
00287 
00288         void clearOut();
00289 
00290         void clearTopology();
00291 
00292         void clearPatchMeshAddr();
00293 
00294 
00295     // Member Functions
00296 
00297         // Access
00298 
00299             const geometricSurfacePatchList& patches() const
00300             {
00301                 return patches_;
00302             }
00303 
00304             geometricSurfacePatchList& patches()
00305             {
00306                 return patches_;
00307             }
00308 
00309             //- Return edge-face addressing sorted (for edges with more than
00310             //  2 faces) according to the angle around the edge.
00311             //  Orientation is anticlockwise looking from
00312             //  edge.vec(localPoints())
00313             const labelListList& sortedEdgeFaces() const;
00314 
00315             //- If 2 face neighbours: label of face where ordering of edge
00316             //  is consistent with righthand walk.
00317             //  If 1 neighbour: label of only face.
00318             //  If >2 neighbours: undetermined.
00319             const labelList& edgeOwner() const;
00320 
00321         // Edit
00322 
00323             //- Move points
00324             virtual void movePoints(const pointField&);
00325 
00326             //- Scale points. A non-positive factor is ignored
00327             virtual void scalePoints(const scalar&);
00328 
00329             //- Check/remove duplicate/degenerate triangles
00330             void checkTriangles(const bool verbose);
00331 
00332             //- Check triply (or more) connected edges.
00333             void checkEdges(const bool verbose);
00334 
00335             //- Remove non-valid triangles
00336             void cleanup(const bool verbose);
00337 
00338             //- Fill faceZone with currentZone for every face reachable
00339             //  from faceI without crossing edge marked in borderEdge.
00340             //  Note: faceZone has to be sized nFaces before calling this fun.
00341             void markZone
00342             (
00343                 const boolList& borderEdge,
00344                 const label faceI,
00345                 const label currentZone,
00346                 labelList& faceZone
00347             ) const;
00348 
00349             //- (size and) fills faceZone with zone of face. Zone is area
00350             //  reachable by edge crossing without crossing borderEdge
00351             //  (bool for every edge in surface). Returns number of zones.
00352             label markZones
00353             (
00354                 const boolList& borderEdge,
00355                 labelList& faceZone
00356             ) const;
00357 
00358             //- 'Create' sub mesh, including only faces for which
00359             //  boolList entry is true
00360             //  Sets: pointMap: from new to old localPoints
00361             //        faceMap: new to old faces
00362             void subsetMeshMap
00363             (
00364                 const boolList& include,
00365                 labelList& pointMap,
00366                 labelList& faceMap
00367             ) const;
00368 
00369             //- Return new surface. Returns pointMap, faceMap from
00370             //  subsetMeshMap
00371             triSurface subsetMesh
00372             (
00373                 const boolList& include,
00374                 labelList& pointMap,
00375                 labelList& faceMap
00376             ) const;
00377 
00378         // Write
00379 
00380             //- Write to Ostream in simple FOAM format
00381             void write(Ostream&) const;
00382 
00383             //- Generic write routine. Chooses writer based on extension.
00384             void write(const fileName&, const bool sortByRegion = false) const;
00385 
00386             //- Write to database
00387             void write(const Time&) const;
00388 
00389             //- Write to Ostream in OpenDX format
00390             void writeDX(const scalarField&, Ostream&) const;
00391             void writeDX(const vectorField&, Ostream&) const;
00392 
00393             //- Write some statistics
00394             void writeStats(Ostream&) const;
00395 
00396 
00397     // Member operators
00398 
00399         void operator=(const triSurface&);
00400 
00401 
00402     // Ostream Operator
00403 
00404         friend Ostream& operator<<(Ostream&, const triSurface&);
00405 };
00406 
00407 
00408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00409 
00410 } // End namespace Foam
00411 
00412 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00413 
00414 #endif
00415 
00416 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd