1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 Foam::intersectedSurface
28 Given triSurface and intersection creates the intersected
29 (properly triangulated) surface.
30 (note: intersection is the list of points and edges 'shared'
34 - from the intersection get the points created on the edges of the surface
35 - split the edges of the surface
36 - construct a new edgeList with (in this order) the edges from the
37 intersection ('cuts', i.e. the edges shared with the other surface)
38 and the (split) edges from the original triangles (from 0 ..
40 - construct face-edge addressing for above edges
41 - for each face do a right-handed walk to reconstruct faces (splitFace)
42 - retriangulate resulting faces (might be non-convex so use
43 faceTriangulation which does proper bisection)
45 The resulting surface will have the points from the surface first
46 in the point list (0 .. nSurfacePoints-1)
48 Note: problematic are the cut-edges which are completely inside a face.
49 These will not be visited by a edge-point-edge walk. These are handled by
50 resplitFace which first connects the 'floating' edges to triangle edges
51 with two extra edges and then tries the splitting again. Seems to work
52 (mostly). Will probably fail for boundary edge (edge with only face).
54 Note: points are compact, i.e. points().size() == localPoints().size()
55 (though points() probably not localPoints())
60 \*---------------------------------------------------------------------------*/
62 #ifndef intersectedSurface_H
63 #define intersectedSurface_H
65 #include "triSurface.H"
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 // Forward declaration of classes
75 class surfaceIntersection;
78 /*---------------------------------------------------------------------------*\
79 Class intersectedSurface Declaration
80 \*---------------------------------------------------------------------------*/
82 class intersectedSurface
88 static const label UNVISITED;
89 static const label STARTTOEND;
90 static const label ENDTOSTART;
91 static const label BOTH;
97 //- Edges which are part of intersection
98 labelList intersectionEdges_;
100 //- From new to original faces
103 //- What are surface points: 0 .. nSurfacePoints_-1
104 label nSurfacePoints_;
107 // Static Member Functions
109 //- Debug:Dump edges to stream. Mantains vertex numbering
112 const pointField& points,
113 const edgeList& edges,
117 //- Debug:Dump selected edges to stream. Mantains vertex numbering
120 const pointField& points,
121 const edgeList& edges,
122 const labelList& faceEdges,
126 //- Debug:Dump selected edges to stream. Renumbers vertices to
128 static void writeLocalOBJ
130 const pointField& points,
131 const edgeList& edges,
132 const labelList& faceEdges,
136 //- Debug:Write whole pointField and face to stream
139 const pointField& points,
144 //- Debug:Print visited status
145 static void printVisit
147 const edgeList& edges,
148 const labelList& edgeLabels,
149 const Map<label>& visited
153 //- Check if the two vertices that f0 and f1 share are in the same
154 // order on both faces.
155 static bool sameEdgeOrder
157 const labelledTri& fA,
158 const labelledTri& fB
161 //- Increment data for key. (start from 0 if not found)
169 //- Calculate point-edge addressing for single face only.
170 static Map<DynamicList<label> > calcPointEdgeAddressing
176 //- Choose edge out of candidates (facePointEdges) according to
177 // angle with previous edge.
178 static label nextEdge
180 const edgeSurface& eSurf,
181 const Map<label>& visited,
183 const vector& n, // original triangle normal
184 const Map<DynamicList<label> >& facePointEdges,
185 const label prevEdgeI,
186 const label prevVertI
189 //- Walk path along edges in face. Used by splitFace.
192 const edgeSurface& eSurf,
195 const Map<DynamicList<label> >& facePointEdges,
197 const label startEdgeI,
198 const label startVertI,
203 //- For resplitFace: find nearest (to pt) fully visited point. Return
204 // point and distance.
205 static void findNearestVisited
207 const edgeSurface& eSurf,
209 const Map<DynamicList<label> >& facePointEdges,
210 const Map<label>& pointVisited,
212 const label excludeFaceI,
219 //- Fallback for if splitFace fails to connect all.
220 static faceList resplitFace
222 const triSurface& surf,
224 const Map<DynamicList<label> >& facePointEdges,
225 const Map<label>& visited,
229 //- Main face splitting routine. Gets overall points and edges and
230 // owners and face-local edgeLabels. Returns list of faces.
231 static faceList splitFace
233 const triSurface& surf,
239 // Private Member Functions
244 ClassName("intersectedSurface");
250 intersectedSurface();
252 //- Construct from surface
253 intersectedSurface(const triSurface& surf);
255 //- Construct from surface and intersection. isFirstSurface is needed
256 // to determine which side of face pairs stored in the intersection
257 // to address. Should be in the same order as how the intersection was
261 const triSurface& surf,
262 const bool isFirstSurface,
263 const surfaceIntersection& inter
268 //- Labels of edges in *this which originate from 'cuts'
269 const labelList& intersectionEdges() const
271 return intersectionEdges_;
275 const labelList& faceMap() const
280 //- Number of points from original surface
281 label nSurfacePoints() const
283 return nSurfacePoints_;
286 //- Is point coming from original surface?
287 bool isSurfacePoint(const label pointI) const
289 return pointI < nSurfacePoints_;
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 } // End namespace Foam
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
302 // ************************************************************************* //