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 | Copyright (C) 2011-2016 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 (might be non-convex so use
43  faceTriangulation which does proper bisection)
44 
45  The resulting surface will have the points from the surface first
46  in the point list (0 .. nSurfacePoints-1)
47 
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).
53 
54  Note: points are compact, i.e. points().size() == localPoints().size()
55  (though points() probably not localPoints())
56 
57 SourceFiles
58  intersectedSurface.C
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #ifndef intersectedSurface_H
63 #define intersectedSurface_H
64 
65 #include "triSurface.H"
66 #include "Map.H"
67 #include "typeInfo.H"
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 
74 // Forward declaration of classes
75 class surfaceIntersection;
76 class edgeSurface;
77 
78 /*---------------------------------------------------------------------------*\
79  Class intersectedSurface Declaration
80 \*---------------------------------------------------------------------------*/
81 
83 :
84  public triSurface
85 {
86 public:
87 
88  static const label UNVISITED;
89  static const label STARTTOEND;
90  static const label ENDTOSTART;
91  static const label BOTH;
92 
93 private:
94 
95  // Private data
96 
97  //- Edges which are part of intersection
98  labelList intersectionEdges_;
99 
100  //- From new to original faces
101  labelList faceMap_;
102 
103  //- What are surface points: 0 .. nSurfacePoints_-1
104  label nSurfacePoints_;
105 
106 
107  // Static Member Functions
108 
109  //- Debug:Dump edges to stream. Mantains vertex numbering
110  static void writeOBJ
111  (
112  const pointField& points,
113  const edgeList& edges,
114  Ostream& os
115  );
116 
117  //- Debug:Dump selected edges to stream. Mantains vertex numbering
118  static void writeOBJ
119  (
120  const pointField& points,
121  const edgeList& edges,
122  const labelList& faceEdges,
123  Ostream& os
124  );
125 
126  //- Debug:Dump selected edges to stream. Renumbers vertices to
127  // local ordering.
128  static void writeLocalOBJ
129  (
130  const pointField& points,
131  const edgeList& edges,
132  const labelList& faceEdges,
133  const fileName&
134  );
135 
136  //- Debug:Write whole pointField and face to stream
137  static void writeOBJ
138  (
139  const pointField& points,
140  const face& f,
141  Ostream& os
142  );
143 
144  //- Debug:Print visited status
145  static void printVisit
146  (
147  const edgeList& edges,
148  const labelList& edgeLabels,
149  const Map<label>& visited
150  );
151 
152 
153  //- Check if the two vertices that f0 and f1 share are in the same
154  // order on both faces.
155  static bool sameEdgeOrder
156  (
157  const labelledTri& fA,
158  const labelledTri& fB
159  );
160 
161  //- Increment data for key. (start from 0 if not found)
162  static void incCount
163  (
164  Map<label>& visited,
165  const label key,
166  const label offset
167  );
168 
169  //- Calculate point-edge addressing for single face only.
170  static Map<DynamicList<label>> calcPointEdgeAddressing
171  (
172  const edgeSurface&,
173  const label facei
174  );
175 
176  //- Choose edge out of candidates (facePointEdges) according to
177  // angle with previous edge.
178  static label nextEdge
179  (
180  const edgeSurface& eSurf,
181  const Map<label>& visited,
182  const label facei,
183  const vector& n, // original triangle normal
184  const Map<DynamicList<label>>& facePointEdges,
185  const label prevEdgeI,
186  const label prevVertI
187  );
188 
189  //- Walk path along edges in face. Used by splitFace.
190  static face walkFace
191  (
192  const edgeSurface& eSurf,
193  const label facei,
194  const vector& n,
195  const Map<DynamicList<label>>& facePointEdges,
196 
197  const label startEdgeI,
198  const label startVertI,
199 
200  Map<label>& visited
201  );
202 
203  //- For resplitFace: find nearest (to pt) fully visited point. Return
204  // point and distance.
205  static void findNearestVisited
206  (
207  const edgeSurface& eSurf,
208  const label facei,
209  const Map<DynamicList<label>>& facePointEdges,
210  const Map<label>& pointVisited,
211  const point& pt,
212  const label excludeFacei,
213 
214  label& minVertI,
215  scalar& minDist
216  );
217 
218 
219  //- Fallback for if splitFace fails to connect all.
220  static faceList resplitFace
221  (
222  const triSurface& surf,
223  const label facei,
224  const Map<DynamicList<label>>& facePointEdges,
225  const Map<label>& visited,
226  edgeSurface& eSurf
227  );
228 
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
232  (
233  const triSurface& surf,
234  const label facei,
235  edgeSurface& eSurf
236  );
237 
238 
239  // Private Member Functions
240 
241 
242 public:
243 
244  ClassName("intersectedSurface");
245 
246 
247  // Constructors
248 
249  //- Construct null
251 
252  //- Construct from surface
253  intersectedSurface(const triSurface& surf);
254 
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
258  // constructed.
260  (
261  const triSurface& surf,
262  const bool isFirstSurface,
263  const surfaceIntersection& inter
264  );
265 
266  // Member Functions
267 
268  //- Labels of edges in *this which originate from 'cuts'
269  const labelList& intersectionEdges() const
270  {
271  return intersectionEdges_;
272  }
273 
274  //- New to old
275  const labelList& faceMap() const
276  {
277  return faceMap_;
278  }
279 
280  //- Number of points from original surface
281  label nSurfacePoints() const
282  {
283  return nSurfacePoints_;
284  }
285 
286  //- Is point coming from original surface?
287  bool isSurfacePoint(const label pointi) const
288  {
289  return pointi < nSurfacePoints_;
290  }
291 };
292 
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 } // End namespace Foam
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 
300 #endif
301 
302 // ************************************************************************* //
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:69
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.
ClassName("intersectedSurface")
const labelList & intersectionEdges() const
Labels of edges in *this which originate from &#39;cuts&#39;.
const Field< point > & 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:53
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:65
static const label ENDTOSTART
Namespace for OpenFOAM.
label nSurfacePoints() const
Number of points from original surface.