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

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