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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::treeDataEdge
29 
30 Description
31  Holds data for octree to work on an edges subset.
32 
33 SourceFiles
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 
48 namespace Foam
49 {
50 
51 // Forward Declarations
52 template<class Type> class indexedOctree;
53 
54 /*---------------------------------------------------------------------------*\
55  Class treeDataEdge Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class 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_)
78  treeBoundBoxList bbs_;
79 
80 
81  // Private Member Functions
82 
83  //- Initialise all member data
84  void update();
85 
86 
87 public:
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,
173  const labelUList& edgeLabels
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  :
205  treeDataEdge(false, edges, points, range)
206  {}
207 
208  //- Construct from selected edges.
209  // \note Holds references to edges and points!
211  (
212  const edgeList& edges,
213  const pointField& points,
214  const labelUList& edgeLabels
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 
232 
233  // Static Functions
234 
235  //- Calculate and return bounding boxes for all edges
236  static treeBoundBoxList boxes
237  (
238  const edgeList& edges,
239  const pointField& points
240  );
241 
242  //- Calculate and return bounding boxes for specified range of edges
243  static treeBoundBoxList boxes
244  (
245  const edgeList& edges,
246  const pointField& points,
247  const labelRange& range
248  );
249 
250  //- Calculate and return bounding boxes for specified edges
251  static treeBoundBoxList boxes
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,
262  const pointField& points
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_);
339  }
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
357  bool overlaps
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 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
bool empty() const noexcept
Is the effective edge selection empty?
Definition: treeDataEdge.H:372
A line primitive.
Definition: line.H:52
static treeBoundBoxList boxes(const edgeList &edges, const pointField &points)
Calculate and return bounding boxes for all edges.
const edgeList & edges() const noexcept
The original list of edges.
Definition: treeDataEdge.H:357
List< edge > edgeList
List of edge.
Definition: edgeList.H:32
bool useSubset() const noexcept
Use a subset of edges.
Definition: treeDataEdge.H:367
treeDataEdge(const bool cacheBb, const edgeList &edges, const pointField &points)
Construct from all edges.
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
Holds data for octree to work on an edges subset.
Definition: treeDataEdge.H:53
An enumeration wrapper for classification of a location as being inside/outside of a volume...
Definition: volumeType.H:55
label objectIndex(const label index) const
Map from shape index to original (non-subset) edge label.
Definition: treeDataEdge.H:388
scalar range
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
findNearestOp(const indexedOctree< treeDataEdge > &tree)
Definition: treeDataEdge.C:360
label size() const noexcept
The size of edge selection.
Definition: treeDataEdge.H:380
static treeBoundBox bounds(const edgeList &edges, const pointField &points)
Return bounding box of all edges.
tmp< pointField > centres() const
Representative point cloud for contained shapes. One point per shape, corresponding to the edge centr...
Definition: treeDataEdge.C:290
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
line< point, const point & > linePointRef
A line using referred points.
Definition: line.H:66
point centre(const label index) const
Representative point (edge centre) at shape index.
Definition: treeDataEdge.H:412
findIntersectOp(const indexedOctree< treeDataEdge > &tree)
Definition: treeDataEdge.C:369
Tree tree(triangles.begin(), triangles.end())
Forward to treeDataEdge findNearest operations.
Definition: treeDataEdge.H:102
ClassNameNoDebug("treeDataEdge")
bool overlaps(const label index, const treeBoundBox &searchBox) const
Does (bb of) shape at index searchBox.
Definition: treeDataEdge.C:334
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:1237
const direction noexcept
Definition: Scalar.H:258
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
mesh update()
Forward to treeDataEdge findIntersect operations.
Definition: treeDataEdge.H:136
treeDataEdge(const edgeList &edges, const pointField &points)
Construct from all edges.
Definition: treeDataEdge.H:222
int nDim() const noexcept
Object dimension == 1 (line element)
Definition: treeDataEdge.H:339
vector point
Point is a vector.
Definition: point.H:37
Non-pointer based hierarchical recursive searching.
const labelList & edgeLabels() const noexcept
The subset of edge ids to use.
Definition: treeDataEdge.H:362
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:90
const pointField & points() const noexcept
The reference point field.
Definition: treeDataEdge.H:352
const linePointRef line(const label index) const
Geometric line for edge at specified shape index. Frequently used.
Definition: treeDataEdge.H:404
const edge & operator[](const label index) const
Edge at specified shape index.
Definition: treeDataEdge.H:396
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50
void findNearest(const labelUList &indices, const point &sample, scalar &nearestDistSqr, label &nearestIndex, point &nearestPoint) const
Calculates nearest (to sample) point in shape.
Definition: treeDataEdge.C:376
Namespace for OpenFOAM.
volumeType getVolumeType(const indexedOctree< treeDataEdge > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
Definition: treeDataEdge.C:324