surfaceIntersection.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 Copyright (C) 2017 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::surfaceIntersection
29
30Description
31 Basic surface-surface intersection description. Constructed from two
32 surfaces it creates a description of the intersection.
33
34 The intersection information consists of the intersection line(s)
35 with new points, new edges between points (note that these edges and
36 points are on both surfaces) and various addressing from original
37 surface faces/edges to intersection and vice versa.
38
39 Gets either precalculated intersection information or calculates it
40 itself.
41 Algorithm works by intersecting all edges of one surface with the other
42 surface and storing a reference from both faces (one on surface1, one on
43 surface 2) to the vertex. If the reference re-occurs we have the second
44 hit of both faces and an edge is created between the retrieved vertex and
45 the new one.
46
47 Note: when doing intersecting itself uses 'tolerance' as a fraction of
48 current edge length to determine if intersection is a point-touching one
49 instead of an edge-piercing action.
50
51 Some constructors allow a dictionary of intersection controls:
52 \table
53 Property | Description | Type | Default value
54 tolerance | Edge-length tolerance | scalar | 1e-3
55 allowEdgeHits | Edge-end cuts another edge | bool | true
56 snap | Snap near end-points | bool | true
57 warnDegenerate | Number of warnings about degenerate edges | label | 0
58 intersectionMethod | Control for self intersection | (self,region,none)
59 \endtable
60
61SourceFiles
62 surfaceIntersection.C
63 surfaceIntersectionFuncs.C
64 surfaceIntersectionTemplates.C
65
66\*---------------------------------------------------------------------------*/
67
68#ifndef surfaceIntersection_H
69#define surfaceIntersection_H
70
71#include "DynamicList.H"
72#include "point.H"
73#include "edgeHashes.H"
74#include "edgeList.H"
75#include "labelPairHashes.H"
76#include "pointIndexHit.H"
77#include "typeInfo.H"
78#include "Enum.H"
79
80// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81
82namespace Foam
83{
84
85// Forward declaration of classes
86class triSurfaceSearch;
87class triSurface;
88class edgeIntersections;
89
90
91//- Key is non-commutative pair of labels. Value is commutative pair of labels
92typedef LabelPairMap<edge> labelPairEdgeLookup;
93
94//- Map from edge back to all parents (pairs of faces)
95typedef EdgeMap<labelPairHashSet> edgelabelPairHashLookup;
96
97
98/*---------------------------------------------------------------------------*\
99 Class surfaceIntersection Declaration
100\*---------------------------------------------------------------------------*/
101
102class surfaceIntersection
103{
104public:
105
106 //- Surface intersection types for classify, doCutEdges
108 {
109 FIRST,
110 SECOND,
111 SELF,
113 NONE
114 };
115
116 //- The user-selectable self-intersection enumeration names
117 static const Enum<intersectionType> selfIntersectionNames;
118
119
120private:
121
122 // Private data
124 //- Tolerance for intersections
125 scalar tolerance_;
126
127 //- Allow edge-ends to cut another edge.
128 bool allowEdgeHits_;
129
130 //- Snap cut points near edge ends (default: true)
131 bool snapToEnd_;
132
133 //- Maximum number of warnings about degenerate edges
134 label warnDegenerate_;
136 //- Newly introduced points.
137 pointField cutPoints_;
139 //- Newly introduced edges (are on both surfaces).
140 // Reference into cutPoints.
141 edgeList cutEdges_;
143 //- From face on surf1 and face on surf2 to intersection edge
144 labelPairEdgeLookup facePairToEdge_;
146 //- From face on surf1 and face on surf2 to intersection edgeId
147 // (label in cutEdges)
148 labelPairLookup facePairToEdgeId_;
149
150 //- Edges on surf1 that are cut.
151 // From edgeId on surf1 to location in cutPoint
152 labelListList surf1EdgeCuts_;
153
154 //- Edges on surf2 that are cut.
155 // From edgeId on surf2 to location in cutPoint
156 labelListList surf2EdgeCuts_;
157
158 //- Temporary storage to manage edge-edge self-intersections.
159 edgeHashSet edgeEdgeIntersection_;
160
161 //- Temporary storage to manage cuts/intersections from the edge ends
162 Map<label> snappedEnds_;
163
164 //- Temporary storage
165 EdgeMap<label> edgeToId_;
166
167
168 // Private Member Functions
169
170 //- Adjust intersection options according to the dictionary entries
171 void setOptions(const dictionary& dict);
172
173 //- Transfer contents of List<DynamicList<..>> to List<List<..>>
174 template<class T>
175 static void transfer(List<DynamicList<T>>&, List<List<T>>&);
176
177 //- Get minimum length of all edges connected to point
178 static scalar minEdgeLen(const triSurface& surf, const label pointi);
179
180 //- Get edge label of edge between face vertices fp and fp+1
181 static label getEdge
182 (
183 const triSurface& surf,
184 const label facei,
185 const label fp
186 );
187
188 //- Remove duplicates from ordered dynamic list. Returns map from old
189 // to new (-1 if element removed)
190 static void removeDuplicates(const labelList& map, labelList& labels);
191
192 // Remove all duplicate and degenerate elements. Return unique elements
193 // and map from old to new.
194 static edgeList filterEdges(const edgeList&, labelList& map);
195
196 //- Remove all duplicate elements.
197 static labelList filterLabels(const labelList& elems, labelList& map);
198
199 //- Debugging: Dump intersected edges to stream
200 void writeIntersectedEdges
201 (
202 const triSurface& surf,
203 const labelListList& edgeCutVerts,
204 Ostream& os
205 ) const;
206
207 //- Detect if point close to edge of end. Returns -1: not close.
208 // 0:close (within startTol) to start, 1:close (within endTol) to end
209 static label classify
210 (
211 const scalar startTol,
212 const scalar endTol,
213 const point& p,
214 const edge& e,
215 const UList<point>& points
216 );
217
218 //- Update reference between faceA and faceB.
219 // Updates facePairToEdge_ and facePairToEdgeId_ (on the second hit)
220 void storeIntersection
221 (
222 const enum intersectionType cutFrom,
223 const labelList& facesA,
224 const label faceB,
225 const UList<point>& allCutPoints,
226 const label cutPointId,
227 DynamicList<edge>& allCutEdges
228 );
229
230 //- Investigate pHit to whether is case of point hits point,
231 // point hits edge, point hits face or edge hits face.
232 void classifyHit
233 (
234 const triSurface& surf1,
235 const scalarField& surf1PointTol,
236 const triSurface& surf2,
237 const enum intersectionType cutFrom,
238 const label edgeI,
239 const pointIndexHit& pHit,
240
241 DynamicList<point>& allCutPoints,
242 DynamicList<edge>& allCutEdges,
243 List<DynamicList<label>>& surfEdgeCuts
244 );
245
246 //- Cut edges of surf1 with surface 2.
247 void doCutEdges
248 (
249 const triSurface& surf1,
250 const triSurfaceSearch& querySurf2,
251 const enum intersectionType cutFrom,
252
253 DynamicList<point>& allCutPoints,
254 DynamicList<edge>& allCutEdges,
255 List<DynamicList<label>>& surfEdgeCuts
256 );
257
258 //- Join disconnected intersection points
259 void joinDisconnected(DynamicList<edge>& allCutEdges);
260
261
262public:
263
264 // Public Data, Declarations
265
266 ClassName("surfaceIntersection");
267
268
269 // Constructors
270
271 //- Construct null
273
274 //- Construct from two surfaces.
275 // Does its own cutting. Has problems with degenerate cuts
277 (
278 const triSurfaceSearch& querySurf1,
279 const triSurfaceSearch& querySurf2,
281 );
282
283 //- Construct from self-intersections.
284 // Does its own cutting, but has problems with degenerate cuts
286 (
287 const triSurfaceSearch& querySurf1,
289 );
290
291 //- Construct from precalculated intersection information.
292 // Advantage: intersection information is guaranteed to have no
293 // degenerate cuts.
295 (
296 const triSurface& surf1,
297 const edgeIntersections& intersections1,
298 const triSurface& surf2,
299 const edgeIntersections& intersections2
300 );
301
302
303 // Member Functions
304
305 //- The list of cut points
306 const pointField& cutPoints() const;
307
308 //- The list of created edges
309 const edgeList& cutEdges() const;
310
311 //- Lookup of pairs of faces to created edges
312 const labelPairLookup& facePairToEdgeId() const;
313
314 //- Access either surf1EdgeCuts (isFirstSurface = true) or
315 // surf2EdgeCuts
316 const labelListList& edgeCuts(const bool isFirstSurf) const;
317
318 //- List of cut points on edges of surface1
319 const labelListList& surf1EdgeCuts() const;
320
321 //- List of cut points on edges of surface2
322 const labelListList& surf2EdgeCuts() const;
323
324
325 //- Geometric merge points (points within mergeDist) prior to
326 // automatically calling mergeEdges().
327 void mergePoints(const scalar mergeDist);
328
329 //- Merge duplicate edges
330 void mergeEdges();
331
332};
333
334
335// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
336
337} // End namespace Foam
338
339// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
340
341#ifdef NoRepository
343#endif
344
345// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
346
347#endif
348
349// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
Map from edge (expressed as its endpoints) to value. For easier forward declaration it is currently i...
Definition: EdgeMap.H:54
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
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
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:66
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Holder of intersections of edges of a surface with another surface. Optionally shuffles around points...
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
Basic surface-surface intersection description. Constructed from two surfaces it creates a descriptio...
const edgeList & cutEdges() const
The list of created edges.
void mergeEdges()
Merge duplicate edges.
const labelListList & surf2EdgeCuts() const
List of cut points on edges of surface2.
const labelListList & edgeCuts(const bool isFirstSurf) const
Access either surf1EdgeCuts (isFirstSurface = true) or.
intersectionType
Surface intersection types for classify, doCutEdges.
@ SELF_REGION
Self-intersection, region-wise only.
@ NONE
None = invalid (for input only)
void mergePoints(const scalar mergeDist)
Geometric merge points (points within mergeDist) prior to.
surfaceIntersection()
Construct null.
const labelListList & surf1EdgeCuts() const
List of cut points on edges of surface1.
const labelPairLookup & facePairToEdgeId() const
Lookup of pairs of faces to created edges.
const pointField & cutPoints() const
The list of cut points.
ClassName("surfaceIntersection")
static const Enum< intersectionType > selfIntersectionNames
The user-selectable self-intersection enumeration names.
Helper class to search on triSurface.
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
volScalarField & p
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
A HashTable to objects of type <T> with a labelPair key. The hashing is based on labelPair (FixedList...
Namespace for OpenFOAM.
EdgeMap< labelPairHashSet > edgelabelPairHashLookup
Map from edge back to all parents (pairs of faces)
LabelPairMap< edge > labelPairEdgeLookup
Key is non-commutative pair of labels. Value is commutative pair of labels.
dictionary dict
volScalarField & e
Definition: createFields.H:11