intersectedSurface.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::intersectedSurface
28
29Description
30 Given triSurface and intersection creates the intersected
31 (properly triangulated) surface.
32 (note: intersection is the list of points and edges 'shared'
33 by two surfaces)
34
35 Algorithm:
36 - from the intersection get the points created on the edges of the surface
37 - split the edges of the surface
38 - construct a new edgeList with (in this order) the edges from the
39 intersection ('cuts', i.e. the edges shared with the other surface)
40 and the (split) edges from the original triangles (from 0 ..
41 nSurfaceEdges)
42 - construct face-edge addressing for above edges
43 - for each face do a right-handed walk to reconstruct faces (splitFace)
44 - retriangulate resulting faces (might be non-convex so use
45 faceTriangulation which does proper bisection)
46
47 The resulting surface will have the points from the surface first
48 in the point list (0 .. nSurfacePoints-1)
49
50 Note: problematic are the cut-edges which are completely inside a face.
51 These will not be visited by a edge-point-edge walk. These are handled by
52 resplitFace which first connects the 'floating' edges to triangle edges
53 with two extra edges and then tries the splitting again. Seems to work
54 (mostly). Will probably fail for boundary edge (edge with only face).
55
56 Note: points are compact, i.e. points().size() == localPoints().size()
57 (though points() probably not localPoints())
58
59SourceFiles
60 intersectedSurface.C
61
62\*---------------------------------------------------------------------------*/
63
64#ifndef intersectedSurface_H
65#define intersectedSurface_H
66
67#include "triSurface.H"
68#include "Map.H"
69#include "typeInfo.H"
70
71// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72
73namespace Foam
74{
75
76// Forward declaration of classes
77class surfaceIntersection;
78class edgeSurface;
79
80/*---------------------------------------------------------------------------*\
81 Class intersectedSurface Declaration
82\*---------------------------------------------------------------------------*/
85:
86 public triSurface
87{
88public:
90 static const label UNVISITED;
91 static const label STARTTOEND;
92 static const label ENDTOSTART;
93 static const label BOTH;
94
95private:
96
97 // Private data
98
99 //- Edges which are part of intersection
100 labelList intersectionEdges_;
101
102 //- From new to original faces
103 labelList faceMap_;
104
105 //- What are surface points: 0 .. nSurfacePoints_-1
106 label nSurfacePoints_;
107
108
109 // Static Member Functions
110
111 //- Debug:Dump edges to stream. Maintains vertex numbering
112 static void writeOBJ
113 (
114 const pointField& points,
115 const edgeList& edges,
116 Ostream& os
117 );
118
119 //- Debug:Dump selected edges to stream. Maintains vertex numbering
120 static void writeOBJ
121 (
122 const pointField& points,
123 const edgeList& edges,
124 const labelList& faceEdges,
125 Ostream& os
126 );
127
128 //- Debug:Dump selected edges to stream. Renumbers vertices to
129 // local ordering.
130 static void writeLocalOBJ
131 (
132 const pointField& points,
133 const edgeList& edges,
134 const labelList& faceEdges,
135 const fileName&
136 );
137
138 //- Debug:Write whole pointField and face to stream
139 static void writeOBJ
140 (
141 const pointField& points,
142 const face& f,
143 Ostream& os
144 );
145
146 //- Debug:Print visited status
147 static void printVisit
148 (
149 const edgeList& edges,
150 const labelList& edgeLabels,
151 const Map<label>& visited
152 );
153
154
155 //- Check if the two vertices that f0 and f1 share are in the same
156 // order on both faces.
157 static bool sameEdgeOrder
158 (
159 const labelledTri& fA,
160 const labelledTri& fB
161 );
162
163 //- Increment data for key. (start from 0 if not found)
164 static void incCount
165 (
166 Map<label>& visited,
167 const label key,
168 const label offset
169 );
170
171 //- Calculate point-edge addressing for single face only.
172 static Map<DynamicList<label>> calcPointEdgeAddressing
173 (
174 const edgeSurface&,
175 const label facei
176 );
177
178 //- Choose edge out of candidates (facePointEdges) according to
179 // angle with previous edge.
180 static label nextEdge
181 (
182 const edgeSurface& eSurf,
183 const Map<label>& visited,
184 const label facei,
185 const vector& n, // original triangle normal
186 const Map<DynamicList<label>>& facePointEdges,
187 const label prevEdgeI,
188 const label prevVertI
189 );
190
191 //- Walk path along edges in face. Used by splitFace.
192 static face walkFace
193 (
194 const edgeSurface& eSurf,
195 const label facei,
196 const vector& n,
197 const Map<DynamicList<label>>& facePointEdges,
198
199 const label startEdgeI,
200 const label startVertI,
201
202 Map<label>& visited
203 );
204
205 //- For resplitFace: find nearest (to pt) fully visited point. Return
206 // point and distance.
207 static void findNearestVisited
208 (
209 const edgeSurface& eSurf,
210 const label facei,
211 const Map<DynamicList<label>>& facePointEdges,
212 const Map<label>& pointVisited,
213 const point& pt,
214 const label excludeFacei,
215
216 label& minVertI,
217 scalar& minDist
218 );
219
220
221 //- Fallback for if splitFace fails to connect all.
222 static faceList resplitFace
223 (
224 const triSurface& surf,
225 const label facei,
226 const Map<DynamicList<label>>& facePointEdges,
227 const Map<label>& visited,
228 edgeSurface& eSurf
229 );
230
231 //- Main face splitting routine. Gets overall points and edges and
232 // owners and face-local edgeLabels. Returns list of faces.
233 static faceList splitFace
234 (
235 const triSurface& surf,
236 const label facei,
237 edgeSurface& eSurf
238 );
239
240
241 // Private Member Functions
242
243
244public:
246 ClassName("intersectedSurface");
247
248
249 // Constructors
250
251 //- Construct null
253
254 //- Construct from surface
255 intersectedSurface(const triSurface& surf);
256
257 //- Construct from surface and intersection. isFirstSurface is needed
258 // to determine which side of face pairs stored in the intersection
259 // to address. Should be in the same order as how the intersection was
260 // constructed.
262 (
263 const triSurface& surf,
264 const bool isFirstSurface,
265 const surfaceIntersection& inter
266 );
267
268 // Member Functions
269
270 //- Labels of edges in *this which originate from 'cuts'
271 const labelList& intersectionEdges() const
272 {
273 return intersectionEdges_;
274 }
275
276 //- New to old
277 const labelList& faceMap() const
278 {
279 return faceMap_;
280 }
281
282 //- Number of points from original surface
283 label nSurfacePoints() const
284 {
285 return nSurfacePoints_;
286 }
287
288 //- Is point coming from original surface?
289 bool isSurfacePoint(const label pointi) const
290 {
291 return pointi < nSurfacePoints_;
292 }
293};
294
295
296// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297
298} // End namespace Foam
299
300// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301
302#endif
303
304// ************************************************************************* //
label n
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
const Field< point_type > & points() const noexcept
Return reference to global points.
const labelListList & faceEdges() const
Return face-edge addressing.
Description of surface in form of 'cloud of edges'.
Definition: edgeSurface.H:76
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
A class for handling file names.
Definition: fileName.H:76
Given triSurface and intersection creates the intersected (properly triangulated) surface....
const labelList & faceMap() const
New to old.
intersectedSurface()
Construct null.
bool isSurfacePoint(const label pointi) const
Is point coming from original surface?
static const label ENDTOSTART
const labelList & intersectionEdges() const
Labels of edges in *this which originate from 'cuts'.
label nSurfacePoints() const
Number of points from original surface.
static const label UNVISITED
ClassName("intersectedSurface")
static const label STARTTOEND
A triFace with additional (region) index.
Definition: labelledTri.H:60
Basic surface-surface intersection description. Constructed from two surfaces it creates a descriptio...
Triangulated surface description with patch information.
Definition: triSurface.H:79
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:67
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
labelList f(nPoints)