Loading...
Searching...
No Matches
treeDataFace.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) 2019-2022 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::treeDataFace
29
30Description
31 Encapsulation of data for searching on faces.
32
33SourceFiles
34 treeDataFace.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_treeDataFace_H
39#define Foam_treeDataFace_H
40
41#include "face.H"
42#include "indexedOctree.H"
43#include "treeBoundBoxList.H"
44#include "bitSet.H"
45#include "primitiveMesh.H"
46#include "volumeType.H"
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
52
53// Forward Declarations
54class polyPatch;
56/*---------------------------------------------------------------------------*\
57 Class treeDataFace Declaration
58\*---------------------------------------------------------------------------*/
59
60class treeDataFace
61{
62 // Static Data
63
64 //- Tolerance on linear dimensions
65 static scalar tolSqr;
66
67
68 // Private Data
69
70 //- Reference to the mesh
71 const primitiveMesh& mesh_;
72
73 //- Subset of faces to work on
74 const labelList faceLabels_;
75
76 //- Inverse of faceLabels. For every mesh whether face is in faceLabels.
77 bitSet isTreeFace_;
78
79 //- Use subset of faces (faceLabels)
80 const bool useSubset_;
81
82 //- Whether to precalculate and store face bounding box
83 const bool cacheBb_;
84
85 //- Face bounding boxes (valid only if cacheBb_)
87
88
89 // Private Member Functions
90
91 //- True if specified mesh facei is being used
92 inline bool usesFace(const label facei) const;
93
94 //- Get face bounding box at specified index
95 inline treeBoundBox getBounds(const label index) const;
96
97 //- Initialise all member data
98 void update();
99
100public:
101
102
103 class findNearestOp
104 {
105 const indexedOctree<treeDataFace>& tree_;
106
107 public:
108
110
111 void operator()
112 (
113 const labelUList& indices,
114 const point& sample,
115
116 scalar& nearestDistSqr,
117 label& minIndex,
118 point& nearestPoint
119 ) const;
120
121 void operator()
122 (
123 const labelUList& indices,
124 const linePointRef& ln,
125
126 treeBoundBox& tightest,
127 label& minIndex,
128 point& linePoint,
129 point& nearestPoint
130 ) const;
131 };
132
133
134 class findIntersectOp
135 {
136 const indexedOctree<treeDataFace>& tree_;
137
138 public:
139
141
142 //- Calculate intersection of triangle with ray.
143 // Sets result accordingly
144 bool operator()
145 (
146 const label index,
147 const point& start,
148 const point& end,
149 point& intersectionPoint
150 ) const;
151 };
152
153
154 // Declare name of the class and its debug switch
155 ClassName("treeDataFace");
156
157
158 // Constructors (cachable versions)
159
160 //- Construct from mesh, using all faces
162 (
163 const bool cacheBb,
164 const primitiveMesh& mesh
165 );
166
167 //- Construct from mesh, using polyPatch faces
168 treeDataFace(const bool cacheBb, const polyPatch& patch);
169
170 //- Construct from mesh, using specified range of faces
172 (
173 const bool cacheBb,
174 const primitiveMesh& mesh,
175 const labelRange& range
176 );
177
178 //- Construct from mesh, copying subset of faces
180 (
181 const bool cacheBb,
182 const primitiveMesh& mesh,
184 );
185
186 //- Construct from mesh, moving subset of faces
188 (
189 const bool cacheBb,
190 const primitiveMesh& mesh,
192 );
193
194
195 // Constructors (non-caching)
196
197 //- Construct from mesh, using all faces
198 explicit treeDataFace(const primitiveMesh& mesh)
199 :
200 treeDataFace(false, mesh)
201 {}
202
203 //- Construct from mesh, using polyPatch faces
204 explicit treeDataFace(const polyPatch& patch)
205 :
206 treeDataFace(false, patch)
207 {}
208
209 //- Construct from mesh, using specified range of faces
210 treeDataFace(const primitiveMesh& mesh, const labelRange& range)
211 :
212 treeDataFace(false, mesh, range)
213 {}
214
215 //- Construct from mesh, copying subset of faces
216 treeDataFace(const primitiveMesh& mesh, const labelUList& faceLabels)
217 :
219 {}
220
221 //- Construct from mesh, moving subset of faces
222 treeDataFace(const primitiveMesh& mesh, labelList&& faceLabels)
223 :
224 treeDataFace(false, mesh, std::move(faceLabels))
225 {}
226
227
228 // Static Functions
229
230 //- Calculate and return bounding boxes for all mesh faces
232 (
233 const primitiveMesh& mesh
234 );
235
236 //- Calculate and return bounding boxes for specified range of faces
238 (
239 const primitiveMesh& mesh,
240 const labelRange& range
241 );
242
243 //- Calculate and return bounding boxes for specified mesh faces
245 (
246 const primitiveMesh& mesh,
247 const labelUList& faceIds
248 );
249
250 //- Return bounding box of specified range of faces
251 static treeBoundBox bounds
253 const primitiveMesh& mesh,
254 const labelRange& range
255 );
256
257 //- Return bounding box of specified mesh faces
258 static treeBoundBox bounds
259 (
261 const labelUList& faceIds
262 );
263
264
265 // Member Functions
266
267 //- Object dimension == 2 (face element)
268 int nDim() const noexcept { return 2; }
269
270 //- Return bounding box for the specified face indices
271 treeBoundBox bounds(const labelUList& indices) const;
272
273
274 // Access
275
276 //- Reference to the supporting mesh
277 const primitiveMesh& mesh() const noexcept { return mesh_; }
278
279 //- The subset of face ids to use
280 const labelList& faceLabels() const noexcept { return faceLabels_; }
281
282 //- Use a subset of faces
283 bool useSubset() const noexcept { return useSubset_; }
284
285 //- Is the effective face selection empty?
286 bool empty() const noexcept
287 {
288 return useSubset_ ? faceLabels_.empty() : !mesh_.nFaces();
289 }
290
291 //- The size of the face selection
292 label size() const noexcept
293 {
294 return useSubset_ ? faceLabels_.size() : mesh_.nFaces();
295 }
296
297 //- Map from shape index to original (non-subset) face label
298 label objectIndex(const label index) const
299 {
300 return useSubset_ && index >= 0 ? faceLabels_[index] : index;
301 }
302
303 //- Face at specified shape index
304 const face& operator[](const label index) const
305 {
306 return mesh_.faces()[objectIndex(index)];
307 }
308
309 //- Representative point (face centre) at shape index
310 const point& centre(const label index) const
311 {
312 return mesh_.faceCentres()[objectIndex(index)];
313 }
314
315 //- Representative point cloud for contained shapes.
316 //- One point per shape, corresponding to the face centres.
317 tmp<pointField> centres() const;
319
320 // Search
321
322 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
323 // Only makes sense for closed surfaces.
325 (
327 const point&
328 ) const;
329
330 //- Does (bb of) shape at index overlap searchBox
332 (
333 const label index,
334 const treeBoundBox& searchBox
335 ) const;
337 //- Does shape at index overlap sphere
338 bool overlaps
339 (
340 const label index,
341 const point& centre,
342 const scalar radiusSqr
343 ) const;
344
345 //- Calculates nearest (to sample) point in shape.
346 // Returns actual point and distance (squared)
347 void findNearest
348 (
349 const labelUList& indices,
350 const point& sample,
351
352 scalar& nearestDistSqr,
353 label& nearestIndex,
354 point& nearestPoint
355 ) const;
356};
357
358
359// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360
361} // End namespace Foam
363// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364
365
366#endif
367
368// ************************************************************************* //
scalar range
Minimal example by using system/controlDict.functions:
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
Non-pointer based hierarchical recursive searching.
A range or interval of labels defined by a start and a size.
Definition labelRange.H:66
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
Cell-face mesh analysis engine.
A class for managing temporary objects.
Definition tmp.H:75
Standard boundBox with extra functionality for use in octree.
findIntersectOp(const indexedOctree< treeDataFace > &tree)
findNearestOp(const indexedOctree< treeDataFace > &tree)
Encapsulation of data for searching on faces.
bool useSubset() const noexcept
Use a subset of faces.
tmp< pointField > centres() const
Representative point cloud for contained shapes. One point per shape, corresponding to the face centr...
const labelList & faceLabels() const noexcept
The subset of face ids to use.
void findNearest(const labelUList &indices, const point &sample, scalar &nearestDistSqr, label &nearestIndex, point &nearestPoint) const
Calculates nearest (to sample) point in shape.
bool empty() const noexcept
Is the effective face selection empty?
int nDim() const noexcept
Object dimension == 2 (face element).
treeDataFace(const primitiveMesh &mesh, const labelUList &faceLabels)
Construct from mesh, copying subset of faces.
static treeBoundBox bounds(const primitiveMesh &mesh, const labelRange &range)
Return bounding box of specified range of faces.
const point & centre(const label index) const
Representative point (face centre) at shape index.
label objectIndex(const label index) const
Map from shape index to original (non-subset) face label.
treeDataFace(const primitiveMesh &mesh, const labelRange &range)
Construct from mesh, using specified range of faces.
treeDataFace(const bool cacheBb, const primitiveMesh &mesh)
Construct from mesh, using all faces.
treeDataFace(const primitiveMesh &mesh, labelList &&faceLabels)
Construct from mesh, moving subset of faces.
treeDataFace(const polyPatch &patch)
Construct from mesh, using polyPatch faces.
ClassName("treeDataFace")
volumeType getVolumeType(const indexedOctree< treeDataFace > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
label size() const noexcept
The size of the face selection.
treeDataFace(const primitiveMesh &mesh)
Construct from mesh, using all faces.
static treeBoundBoxList boxes(const primitiveMesh &mesh)
Calculate and return bounding boxes for all mesh faces.
const primitiveMesh & mesh() const noexcept
Reference to the supporting mesh.
bool overlaps(const label index, const treeBoundBox &searchBox) const
Does (bb of) shape at index overlap searchBox.
const face & operator[](const label index) const
Face at specified shape index.
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition volumeType.H:56
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
mesh update()
dynamicFvMesh & mesh
Namespace for bounding specifications. At the moment, mostly for tables.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
List< treeBoundBox > treeBoundBoxList
A List of treeBoundBox.
line< point, const point & > linePointRef
A line using referred points.
Definition line.H:66
vector point
Point is a vector.
Definition point.H:37
const direction noexcept
Definition scalarImpl.H:265
UList< label > labelUList
A UList of labels.
Definition UList.H:75
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition POSIX.C:1239
Tree tree(triangles.begin(), triangles.end())