Loading...
Searching...
No Matches
treeDataEdge.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-2015 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::treeDataEdge
29
30Description
31 Holds data for octree to work on an edges subset.
32
33SourceFiles
34 treeDataEdge.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_treeDataEdge_H
39#define Foam_treeDataEdge_H
40
41#include "treeBoundBoxList.H"
42#include "labelRange.H"
43#include "line.H"
44#include "volumeType.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
50
51// Forward Declarations
52template<class Type> class indexedOctree;
54/*---------------------------------------------------------------------------*\
55 Class treeDataEdge Declaration
56\*---------------------------------------------------------------------------*/
57
58class treeDataEdge
59{
60 // Private Data
61
62 //- Reference to the underlying support points
63 const pointField& points_;
64
65 //- Reference to edgeList
66 const edgeList& edges_;
67
68 //- Subset of edges to work on
69 const labelList edgeLabels_;
70
71 //- Use subset of edges (edgeLabels)
72 const bool useSubset_;
73
74 //- Whether to precalculate and store edge bounding box
75 const bool cacheBb_;
76
77 //- Edge bounding boxes (valid only if cacheBb_)
79
80
81 // Private Member Functions
82
83 //- Initialise all member data
84 void update();
85
86
87public:
88
89
90 //- Forward to treeDataEdge findNearest operations
91 class findNearestOp
92 {
93 const indexedOctree<treeDataEdge>& tree_;
94
95 public:
96
98
99 void operator()
100 (
101 const labelUList& indices,
102 const point& sample,
103
104 scalar& nearestDistSqr,
105 label& minIndex,
106 point& nearestPoint
107 ) const;
108
109 void operator()
110 (
111 const labelUList& indices,
112 const linePointRef& ln,
113
114 treeBoundBox& tightest,
115 label& minIndex,
116 point& linePoint,
117 point& nearestPoint
118 ) const;
119 };
120
121
122 //- Forward to treeDataEdge findIntersect operations
123 class findIntersectOp
124 {
125 public:
126
128
129 //- Calculate intersection of triangle with ray. Sets result
130 // accordingly
131 bool operator()
132 (
133 const label index,
134 const point& start,
135 const point& end,
136 point& intersectionPoint
137 ) const;
138 };
139
140
141 // Declare name of the class and its debug switch
142 ClassNameNoDebug("treeDataEdge");
143
144
145 // Constructors (cachable versions)
146
147 //- Construct from all edges.
148 // \note Holds references to edges and points!
150 (
151 const bool cacheBb,
152 const edgeList& edges,
153 const pointField& points
154 );
155
156 //- Construct from range of edges.
157 // \note Holds references to edges and points!
159 (
160 const bool cacheBb,
161 const edgeList& edges,
162 const pointField& points,
163 const labelRange& range
164 );
165
166 //- Construct from selected edges.
167 // \note Holds references to edges and points!
169 (
170 const bool cacheBb,
171 const edgeList& edges,
172 const pointField& points,
174 );
175
176 //- Construct from selected edges, transferring contents.
177 // \note Holds references to edges and points!
179 (
180 const bool cacheBb,
181 const edgeList& edges,
182 const pointField& points,
184 );
185
186
187 // Constructors (non-caching)
188
189 //- Construct from all edges.
190 // \note Holds references to edges and points!
192 :
193 treeDataEdge(false, edges, points)
194 {}
195
196 //- Construct from range of edges.
197 // \note Holds references to edges and points!
199 (
200 const edgeList& edges,
201 const pointField& points,
202 const labelRange& range
203 )
204 :
206 {}
207
208 //- Construct from selected edges.
209 // \note Holds references to edges and points!
211 (
212 const edgeList& edges,
213 const pointField& points,
215 )
216 :
218 {}
219
220 //- Construct from selected edges, transferring contents.
221 // \note Holds references to edges and points!
223 (
224 const edgeList& edges,
225 const pointField& points,
227 )
228 :
229 treeDataEdge(false, edges, points, std::move(edgeLabels))
230 {}
231
233 // Static Functions
234
235 //- Calculate and return bounding boxes for all edges
237 (
238 const edgeList& edges,
239 const pointField& points
240 );
241
242 //- Calculate and return bounding boxes for specified range of edges
244 (
245 const edgeList& edges,
246 const pointField& points,
248 );
249
250 //- Calculate and return bounding boxes for specified edges
252 (
253 const edgeList& edges,
254 const pointField& points,
255 const labelUList& edgeIds
256 );
257
258 //- Return bounding box of all edges
259 static treeBoundBox bounds
260 (
261 const edgeList& edges,
263 );
264
265 //- Return bounding box of specified range of edges
266 static treeBoundBox bounds
267 (
268 const edgeList& edges,
269 const pointField& points,
270 const labelRange& range
271 );
272
273 //- Return bounding box of specified edges
274 static treeBoundBox bounds
275 (
276 const edgeList& edges,
277 const pointField& points,
278 const labelUList& edgeIds
279 );
280
281
282 // Member Functions
283
284 //- Object dimension == 1 (line element)
285 int nDim() const noexcept { return 1; }
286
287 //- Return bounding box for the specified edge indices
288 treeBoundBox bounds(const labelUList& indices) const;
289
290
291 // Access
292
293 //- The reference point field
294 const pointField& points() const noexcept { return points_; }
295
296 //- The original list of edges
297 const edgeList& edges() const noexcept { return edges_; }
298
299 //- The subset of edge ids to use
300 const labelList& edgeLabels() const noexcept { return edgeLabels_; }
301
302 //- Use a subset of edges
303 bool useSubset() const noexcept { return useSubset_; }
304
305 //- Is the effective edge selection empty?
306 bool empty() const noexcept
307 {
308 return useSubset_ ? edgeLabels_.empty() : edges_.empty();
309 }
310
311 //- The size of edge selection
312 label size() const noexcept
313 {
314 return useSubset_ ? edgeLabels_.size() : edges_.size();
315 }
316
317 //- Map from shape index to original (non-subset) edge label
318 label objectIndex(const label index) const
319 {
320 return useSubset_ && index >= 0 ? edgeLabels_[index] : index;
321 }
322
323 //- Edge at specified shape index
324 const edge& operator[](const label index) const
325 {
326 return edges_[objectIndex(index)];
327 }
328
329 //- Geometric line for edge at specified shape index. Frequently used
330 const linePointRef line(const label index) const
331 {
332 return edges_[objectIndex(index)].line(points_);
333 }
334
335 //- Representative point (edge centre) at shape index
336 point centre(const label index) const
337 {
338 return edges_[objectIndex(index)].centre(points_);
340
341 //- Representative point cloud for contained shapes.
342 //- One point per shape, corresponding to the edge centres.
343 tmp<pointField> centres() const;
344
345
346 // Search
347
348 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
349 // Only makes sense for closed surfaces.
351 (
353 const point&
354 ) const;
355
356 //- Does (bb of) shape at index searchBox
358 (
359 const label index,
360 const treeBoundBox& searchBox
361 ) const;
363 //- Does (bb of) shape at index overlap bb
364 bool overlaps
365 (
366 const label index,
367 const point& centre,
368 const scalar radiusSqr
369 ) const;
370
371 //- Calculates nearest (to sample) point in shape.
372 // Returns actual point and distance (squared)
373 void findNearest
374 (
375 const labelUList& indices,
376 const point& sample,
377
378 scalar& nearestDistSqr,
379 label& nearestIndex,
380 point& nearestPoint
381 ) const;
382};
383
384
385// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386
387} // End namespace Foam
389// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390
391
392#endif
393
394// ************************************************************************* //
scalar range
Minimal example by using system/controlDict.functions:
const Vector< Cmpt > & centre(const Foam::UList< Vector< Cmpt > > &) const noexcept
Return this (for point which is a typedef to Vector<scalar>).
Definition VectorI.H:67
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition edge.H:62
Non-pointer based hierarchical recursive searching.
A range or interval of labels defined by a start and a size.
Definition labelRange.H:66
line(const Point &from, const Point &to)
Construct from two points.
Definition lineI.H:45
A class for managing temporary objects.
Definition tmp.H:75
Standard boundBox with extra functionality for use in octree.
Forward to treeDataEdge findIntersect operations.
findIntersectOp(const indexedOctree< treeDataEdge > &tree)
Forward to treeDataEdge findNearest operations.
findNearestOp(const indexedOctree< treeDataEdge > &tree)
Holds data for octree to work on an edges subset.
bool useSubset() const noexcept
Use a subset of edges.
point centre(const label index) const
Representative point (edge centre) at shape index.
static treeBoundBoxList boxes(const edgeList &edges, const pointField &points)
Calculate and return bounding boxes for all edges.
ClassNameNoDebug("treeDataEdge")
tmp< pointField > centres() const
Representative point cloud for contained shapes. One point per shape, corresponding to the edge centr...
treeDataEdge(const bool cacheBb, const edgeList &edges, const pointField &points)
Construct from all edges.
treeDataEdge(const edgeList &edges, const pointField &points, labelList &&edgeLabels)
Construct from selected edges, transferring contents.
static treeBoundBox bounds(const edgeList &edges, const pointField &points)
Return bounding box of all edges.
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 edge selection empty?
int nDim() const noexcept
Object dimension == 1 (line element).
const labelList & edgeLabels() const noexcept
The subset of edge ids to use.
const edgeList & edges() const noexcept
The original list of edges.
const linePointRef line(const label index) const
Geometric line for edge at specified shape index. Frequently used.
const edge & operator[](const label index) const
Edge at specified shape index.
label objectIndex(const label index) const
Map from shape index to original (non-subset) edge label.
treeDataEdge(const edgeList &edges, const pointField &points, const labelRange &range)
Construct from range of edges.
const pointField & points() const noexcept
The reference point field.
label size() const noexcept
The size of edge selection.
treeDataEdge(const edgeList &edges, const pointField &points)
Construct from all edges.
volumeType getVolumeType(const indexedOctree< treeDataEdge > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
bool overlaps(const label index, const treeBoundBox &searchBox) const
Does (bb of) shape at index searchBox.
treeDataEdge(const edgeList &edges, const pointField &points, const labelUList &edgeLabels)
Construct from selected edges.
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition volumeType.H:56
#define ClassNameNoDebug(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:39
mesh update()
const pointField & points
Namespace for bounding specifications. At the moment, mostly for tables.
Namespace for OpenFOAM.
List< edge > edgeList
List of edge.
Definition edgeList.H:32
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
vectorField pointField
pointField is a vectorField.
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())