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