OpenFOAM logo
Open Source CFD Toolkit

intersectedSurface.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-2005 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     intersectedSurface
00027 
00028 Description
00029     Given triSurface and intersection creates the intersected
00030     (properly triangulated) surface.
00031     (note: intersection is the list of points and edges 'shared'
00032     by two surfaces)
00033 
00034     Algorithm:
00035     - from the intersection get the points created on the edges of the surface
00036     - split the edges of the surface
00037     - construct a new edgeList with (in this order) the edges from the
00038       intersection ('cuts', i.e. the edges shared with the other surface)
00039       and the (split) edges from the original triangles (from 0 .. 
00040       nSurfaceEdges)
00041     - construct face-edge addressing for above edges
00042     - for each face do a right-handed walk to reconstruct faces (splitFace)
00043     - retriangulate resulting faces (might be non-convex so use
00044       faceTriangulation which does proper bisection)
00045 
00046     The resulting surface will have the points from the surface first
00047     in the point list (0 .. nSurfacePoints-1)
00048 
00049     Note: problematic are the cut-edges which are completely inside a face.
00050     These will not be visited by a edge-point-edge walk. These are handled by
00051     resplitFace which first connects the 'floating' edges to triangle edges
00052     with two extra edges and then tries the splitting again. Seems to work
00053     (mostly). Will probably fail for boundary edge (edge with only face).
00054 
00055     Note: points are compact, i.e. points().size() == localPoints().size()
00056     (though points() probably not localPoints())
00057 
00058 SourceFiles
00059     intersectedSurface.C
00060 
00061 \*---------------------------------------------------------------------------*/
00062 
00063 #ifndef intersectedSurface_H
00064 #define intersectedSurface_H
00065 
00066 #include "triSurface.H"
00067 #include "Map.H"
00068 #include "typeInfo.H"
00069 
00070 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00071 
00072 namespace Foam
00073 {
00074 
00075 // Class forward declarations
00076 class surfaceIntersection;
00077 class edgeSurface;
00078 
00079 /*---------------------------------------------------------------------------*\
00080                            Class intersectedSurface Declaration
00081 \*---------------------------------------------------------------------------*/
00082 
00083 class intersectedSurface
00084 :
00085     public triSurface
00086 {
00087 public:
00088 
00089         static const label UNVISITED;
00090         static const label STARTTOEND;
00091         static const label ENDTOSTART;
00092         static const label BOTH;
00093 
00094 private:
00095 
00096     // Private data
00097 
00098         //- Edges which are part of intersection
00099         labelList intersectionEdges_;
00100 
00101         //- From new to original faces
00102         labelList faceMap_;
00103 
00104         //- What are surface points: 0 .. nSurfacePoints_-1
00105         label nSurfacePoints_;
00106 
00107 
00108     // Static Member Functions
00109 
00110         //- Debug:Dump edges to stream. Mantains vertex numbering
00111         static void writeOBJ
00112         (
00113             const pointField& points,
00114             const edgeList& edges,
00115             Ostream& os
00116         );
00117 
00118         //- Debug:Dump selected edges to stream. Mantains vertex numbering
00119         static void writeOBJ
00120         (
00121             const pointField& points,
00122             const edgeList& edges,
00123             const labelList& faceEdges,
00124             Ostream& os
00125         );
00126 
00127         //- Debug:Dump selected edges to stream. Renumbers vertices to local ordering.
00128         static void writeLocalOBJ
00129         (
00130             const pointField& points,
00131             const edgeList& edges,
00132             const labelList& faceEdges,
00133             const fileName&
00134         );
00135 
00136         //- Debug:Write whole pointField and face to stream
00137         static void writeOBJ
00138         (
00139             const pointField& points,
00140             const face& f,
00141             Ostream& os
00142         );
00143 
00144         //- Debug:Print visited status
00145         static void printVisit
00146         (
00147             const edgeList& edges,
00148             const labelList& edgeLabels,
00149             const Map<label>& visited
00150         );
00151 
00152 
00153         //- Check if the two vertices that f0 and f1 share are in the same
00154         //  order on both faces.
00155         static bool sameEdgeOrder
00156         (
00157             const labelledTri& fA,
00158             const labelledTri& fB
00159         );
00160 
00161         //- Increment data for key. (start from 0 if not found)
00162         static void incCount
00163         (
00164             Map<label>& visited,
00165             const label key,
00166             const label offset
00167         );
00168 
00169         //- Calculate point-edge addressing for single face only.
00170         static Map<DynamicList<label> > calcPointEdgeAddressing
00171         (
00172             const edgeSurface&,
00173             const label faceI
00174         );
00175 
00176         //- Choose edge out of candidates (facePointEdges) according to
00177         //  angle with previous edge.
00178         static label nextEdge
00179         (
00180             const edgeSurface& eSurf,
00181             const Map<label>& visited,
00182             const label faceI,
00183             const vector& n,                // original triangle normal
00184             const Map<DynamicList<label> >& facePointEdges,
00185             const label prevEdgeI,
00186             const label prevVertI
00187         );
00188 
00189         //- Walk path along edges in face. Used by splitFace.
00190         static face walkFace
00191         (
00192             const edgeSurface& eSurf,
00193             const label faceI,
00194             const vector& n,
00195             const Map<DynamicList<label> >& facePointEdges,
00196 
00197             const label startEdgeI,
00198             const label startVertI,
00199 
00200             Map<label>& visited
00201         );
00202 
00203         //- For resplitFace: find nearest (to pt) fully visited point. Return
00204         //  point and distance.
00205         static void findNearestVisited
00206         (
00207             const edgeSurface& eSurf,
00208             const label faceI,
00209             const Map<DynamicList<label> >& facePointEdges,
00210             const Map<label>& pointVisited,
00211             const point& pt,
00212             const label excludeFaceI,
00213 
00214             label& minVertI,
00215             scalar& minDist
00216         );
00217 
00218 
00219         //- Fallback for if splitFace fails to connect all.
00220         static faceList resplitFace
00221         (
00222             const triSurface& surf,
00223             const label faceI,
00224             const Map<DynamicList<label> >& facePointEdges,
00225             const Map<label>& visited,
00226             edgeSurface& eSurf
00227         );
00228 
00229         //- Main face splitting routine. Gets overall points and edges and
00230         //  owners and face-local edgeLabels. Returns list of faces.
00231         static faceList splitFace
00232         (
00233             const triSurface& surf,
00234             const label faceI,
00235             edgeSurface& eSurf
00236         );
00237 
00238 
00239     // Private Member Functions
00240 
00241 
00242 public:
00243 
00244     ClassName("intersectedSurface");
00245 
00246 
00247     // Constructors
00248 
00249         //- Construct null
00250         intersectedSurface();
00251 
00252         //- Construct from surface
00253         intersectedSurface(const triSurface& surf);
00254 
00255         //- Construct from surface and intersection. isFirstSurface is needed
00256         //  to determine which side of face pairs stored in the intersection
00257         //  to address. Should be in the same order as how the intersection was
00258         //  constructed.
00259         intersectedSurface
00260         (
00261             const triSurface& surf,
00262             const bool isFirstSurface,
00263             const surfaceIntersection& inter
00264         );
00265 
00266     // Member Functions
00267 
00268         //- Labels of edges in *this which originate from 'cuts'
00269         const labelList& intersectionEdges() const
00270         {
00271             return intersectionEdges_;
00272         }
00273 
00274         //- New to old
00275         const labelList& faceMap() const
00276         {
00277             return faceMap_;
00278         }
00279 
00280         //- Number of points from original surface
00281         label nSurfacePoints() const
00282         {
00283             return nSurfacePoints_;
00284         }
00285 
00286         //- Is point coming from original surface?
00287         bool isSurfacePoint(const label pointI) const
00288         {
00289             return pointI < nSurfacePoints_;
00290         }
00291 };
00292 
00293 
00294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00295 
00296 } // End namespace Foam
00297 
00298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00299 
00300 #endif
00301 
00302 // ************************************************************************* //
For further information go to www.openfoam.org