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