booleanSurface.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-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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::booleanSurface
26 
27 Description
28  Surface-surface intersection. Given two surfaces construct combined surface.
29 
30  Called 'boolean' since the volume of resulting surface will encompass
31  the volumes of the original surface according to some boolean operation:
32  - all which is in surface1 AND in surface2 (intersection)
33  - all which is in surface1 AND NOT in surface2 (surface1 minus surface2)
34  - all which is in surface1 OR in surface2 (union)
35 
36  Algorithm:
37  -# find edge-surface intersection. Class 'surfaceIntersection'.
38  -# combine intersection with both surfaces. Class 'intersectedSurface'.
39  -# subset surfaces upto intersection. The 'side' of the surface to
40  include is based on the faces that can be reached from a
41  user-supplied face index.
42  -# merge surfaces. Only the points on the intersection are shared.
43 
44 SourceFiles
45  booleanSurface.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef booleanSurface_H
50 #define booleanSurface_H
51 
52 #include "triSurface.H"
53 #include "surfaceIntersection.H"
54 #include "typeInfo.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward declaration of classes
62 class triSurfaceSearch;
63 class intersectedSurface;
64 
65 /*---------------------------------------------------------------------------*\
66  Class booleanSurface Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class booleanSurface
70 :
71  public triSurface
72 {
73  // Data types
74 
75  //- Enumeration listing the status of a face (visible/invisible from
76  // outside)
77  enum sideStat
78  {
81  INSIDE
82  };
83 
84 
85  // Private data
86 
87  //- From new to old face + surface:
88  // >0 : to face on surface1
89  // <0 : to face on surface2. Negate and offset by one to get
90  // face2 (e.g. face2I = -faceMap[]-1)
92 
93 
94  // Private Member Functions
95 
96  //- Check whether subset of faces (from markZones) reaches up to
97  // the intersection.
98  static void checkIncluded
99  (
100  const intersectedSurface& surf,
101  const labelList& faceZone,
102  const label includedFace
103  );
104 
105  //- Get label in elems of elem.
106  static label index(const labelList& elems, const label elem);
107 
108  //- Find index of edge e in subset edgeLabels.
109  static label findEdge
110  (
111  const edgeList& edges,
112  const labelList& edgeLabels,
113  const edge& e
114  );
115 
116  //- Get index of face in zoneI whose faceCentre is nearest farAwayPoint
117  static label findNearest
118  (
119  const triSurface& surf,
120  const labelList& faceZone,
121  const label zoneI
122  );
123 
124  //- Generate combined patchList (returned). Sets patchMap to map from
125  // surf region numbers into combined patchList
127  (
128  const triSurface& surf1,
129  const triSurface& surf2,
130  labelList& patchMap2
131  );
132 
133  //- On edgeI, coming from face prevFace, determines visibility/side of
134  // all the other faces using the edge.
135  static void propagateEdgeSide
136  (
137  const triSurface& surf,
138  const label prevVert0,
139  const label prevFaceI,
140  const label prevState,
141  const label edgeI,
142  labelList& side
143  );
144 
145  //- Given in/outside status of face determines status for all
146  // neighbouring faces.
147  static void propagateSide
148  (
149  const triSurface& surf,
150  const label prevState,
151  const label faceI,
152  labelList& side
153  );
154 
155 
156 public:
157 
158  ClassName("booleanSurface");
159 
160 
161  // Data types
162 
163  //- Enumeration listing the possible volume operator types
164  enum booleanOpType
165  {
166  UNION, // Union of volumes
167  INTERSECTION, // Intersection of volumes
168  DIFFERENCE, // Difference of volumes
169  ALL // Special: does not subset combined
170  // surface. (Produces multiply connected surface)
171  };
172 
173  // Static data
174 
176 
177 
178 
179  // Constructors
180 
181  //- Construct null
182  booleanSurface();
183 
184  //- Construct from surfaces and face labels to keep.
185  // Walks from provided seed faces without crossing intersection line
186  // to determine faces to keep.
188  (
189  const triSurface& surf1,
190  const triSurface& surf2,
191  const surfaceIntersection& inter,
192  const label includeFace1,
193  const label includeFace2
194  );
195 
196  //- Construct from surfaces and operation. Surfaces need to be closed
197  // for this to make any sense since uses inside/outside to determine
198  // which part of combined surface to include.
200  (
201  const triSurface& surf1,
202  const triSurface& surf2,
203  const surfaceIntersection& inter,
204  const label booleanOp
205  );
206 
207 
208  // Member Functions
209 
210  //- New to old face map. >0: surface 1 face label. <0: surface 2. Negate
211  // and subtract 1 to get face label on surface 2.
212  const labelList& faceMap() const
213  {
214  return faceMap_;
215  }
216 
217  bool from1(const label faceI) const
218  {
219  return faceMap_[faceI] >= 0;
220  }
221 
222  bool surf1Face(const label faceI) const
223  {
224  if (!from1(faceI))
225  {
227  << "face " << faceI << " not from surface 1"
228  << abort(FatalError);
229  }
230  return faceMap_[faceI];
231  }
232 
233  bool surf2Face(const label faceI) const
234  {
235  if (from1(faceI))
236  {
238  << "face " << faceI << " not from surface 2"
239  << abort(FatalError);
240  }
241  return -faceMap_[faceI]-1;
242  }
243 };
244 
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 } // End namespace Foam
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 #endif
253 
254 // ************************************************************************* //
Foam::booleanSurface::propagateEdgeSide
static void propagateEdgeSide(const triSurface &surf, const label prevVert0, const label prevFaceI, const label prevState, const label edgeI, labelList &side)
On edgeI, coming from face prevFace, determines visibility/side of.
Definition: booleanSurface.C:197
typeInfo.H
Foam::PrimitivePatch< labelledTri, List, pointField, point >::edges
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
Definition: PrimitivePatchTemplate.C:212
Foam::booleanSurface::from1
bool from1(const label faceI) const
Definition: booleanSurface.H:216
Foam::booleanSurface::ClassName
ClassName("booleanSurface")
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::booleanSurface::UNION
@ UNION
Definition: booleanSurface.H:165
Foam::booleanSurface::ALL
@ ALL
Definition: booleanSurface.H:168
Foam::booleanSurface::mergePatches
static geometricSurfacePatchList mergePatches(const triSurface &surf1, const triSurface &surf2, labelList &patchMap2)
Generate combined patchList (returned). Sets patchMap to map from.
Definition: booleanSurface.C:141
Foam::booleanSurface::booleanOpType
booleanOpType
Enumeration listing the possible volume operator types.
Definition: booleanSurface.H:163
surfaceIntersection.H
Foam::booleanSurface::INTERSECTION
@ INTERSECTION
Definition: booleanSurface.H:166
Foam::label
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
Foam::intersectedSurface
Given triSurface and intersection creates the intersected (properly triangulated) surface....
Definition: intersectedSurface.H:81
Foam::surfaceIntersection
Basic surface-surface intersection description. Constructed from two surfaces it creates a descriptio...
Definition: surfaceIntersection.H:80
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::booleanSurface::index
static label index(const labelList &elems, const label elem)
Get label in elems of elem.
Definition: booleanSurface.C:100
Foam::booleanSurface
Surface-surface intersection. Given two surfaces construct combined surface.
Definition: booleanSurface.H:68
Foam::booleanSurface::faceMap
const labelList & faceMap() const
New to old face map. >0: surface 1 face label. <0: surface 2. Negate.
Definition: booleanSurface.H:211
Foam::FatalError
error FatalError
Foam::booleanSurface::findNearest
static label findNearest(const triSurface &surf, const labelList &faceZone, const label zoneI)
Get index of face in zoneI whose faceCentre is nearest farAwayPoint.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::booleanSurface::DIFFERENCE
@ DIFFERENCE
Definition: booleanSurface.H:167
Foam::booleanSurface::propagateSide
static void propagateSide(const triSurface &surf, const label prevState, const label faceI, labelList &side)
Given in/outside status of face determines status for all.
Definition: booleanSurface.C:324
Foam::booleanSurface::booleanOpTypeNames
static const NamedEnum< booleanOpType, 4 > booleanOpTypeNames
Definition: booleanSurface.H:174
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::booleanSurface::UNVISITED
@ UNVISITED
Definition: booleanSurface.H:78
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::booleanSurface::INSIDE
@ INSIDE
Definition: booleanSurface.H:80
Foam::booleanSurface::faceMap_
labelList faceMap_
From new to old face + surface:
Definition: booleanSurface.H:90
Foam::booleanSurface::checkIncluded
static void checkIncluded(const intersectedSurface &surf, const labelList &faceZone, const label includedFace)
Check whether subset of faces (from markZones) reaches up to.
Definition: booleanSurface.C:63
Foam::booleanSurface::surf1Face
bool surf1Face(const label faceI) const
Definition: booleanSurface.H:221
Foam::booleanSurface::booleanSurface
booleanSurface()
Construct null.
Definition: booleanSurface.C:388
Foam::booleanSurface::OUTSIDE
@ OUTSIDE
Definition: booleanSurface.H:79
Foam::booleanSurface::sideStat
sideStat
Enumeration listing the status of a face (visible/invisible from.
Definition: booleanSurface.H:76
Foam::booleanSurface::surf2Face
bool surf2Face(const label faceI) const
Definition: booleanSurface.H:232
Foam::NamedEnum< booleanOpType, 4 >
Foam::booleanSurface::findEdge
static label findEdge(const edgeList &edges, const labelList &edgeLabels, const edge &e)
Find index of edge e in subset edgeLabels.
Definition: booleanSurface.C:117