treeDataPoint.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-2013 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::treeDataPoint
29 
30 Description
31  Holds (reference to) pointField. Encapsulation of data needed for
32  octree searches.
33  Used for searching for nearest point. No bounding boxes around points.
34  Only overlaps and calcNearest are implemented, rest makes little sense.
35 
36  Optionally works on subset of points.
37 
38 SourceFiles
39  treeDataPoint.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Foam_treeDataPoint_H
44 #define Foam_treeDataPoint_H
45 
46 #include "pointField.H"
47 #include "treeBoundBox.H"
48 #include "line.H"
49 #include "volumeType.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward Declarations
57 template<class Type> class indexedOctree;
58 
59 /*---------------------------------------------------------------------------*\
60  Class treeDataPoint Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class treeDataPoint
64 {
65  // Private Data
66 
67  //- Reference to the underlying point field
68  const pointField& points_;
69 
70  //- Subset of points to work on (or empty)
71  const labelList pointLabels_;
72 
73  //- Use subset of points (pointLabels)
74  const bool useSubset_;
75 
76 
77 public:
78 
79  //- Forward to treeDataPoint findNearest operations
80  class findNearestOp
81  {
82  const indexedOctree<treeDataPoint>& tree_;
83 
84  public:
85 
87 
88  void operator()
89  (
90  const labelUList& indices,
91  const point& sample,
92 
93  scalar& nearestDistSqr,
94  label& minIndex,
95  point& nearestPoint
96  ) const;
97 
98  void operator()
99  (
100  const labelUList& indices,
101  const linePointRef& ln,
102 
103  treeBoundBox& tightest,
104  label& minIndex,
105  point& linePoint,
106  point& nearestPoint
107  ) const;
108  };
109 
110 
111  //- Forward to treeDataPoint findIntersect operations (not possible)
112  class findIntersectOp
113  {
114  public:
115 
118  //- Calculate intersection of triangle with ray.
119  // Sets result accordingly
120  bool operator()
121  (
122  const label index,
123  const point& start,
124  const point& end,
125  point& intersectionPoint
126  ) const;
127  };
128 
129 
130  // Declare name of the class
131  ClassNameNoDebug("treeDataPoint");
132 
133 
134  // Constructors (non-caching)
135 
136  //- Construct from pointField
137  // \note Holds reference to the points!
138  explicit treeDataPoint(const pointField& points);
139 
140  //- Construct from subset of pointField, copies point ids
141  // \note Holds reference to the points!
143  (
144  const pointField& points,
145  const labelUList& pointLabels,
146  const bool useSubsetPoints = true
147  );
148 
149  //- Construct from subset of pointField, moves point ids
150  // \note Holds reference to the points!
152  (
153  const pointField& points,
155  const bool useSubsetPoints = true
156  );
157 
158 
159  // Member Functions
160 
161  //- Object dimension == 0 (point element)
162  int nDim() const noexcept { return 0; }
163 
164  //- Return bounding box for the specified point indices
165  treeBoundBox bounds(const labelUList& indices) const;
166 
167 
168  // Access
169 
170  //- The original point field
171  const pointField& points() const noexcept { return points_; }
172 
173  //- The subset of point ids to use
174  const labelList& pointLabels() const noexcept { return pointLabels_; }
175 
176  //- Use a subset of points
177  bool useSubset() const noexcept { return useSubset_; }
178 
179  //- Is the effective point field empty?
180  bool empty() const noexcept
181  {
182  return useSubset_ ? pointLabels_.empty() : points_.empty();
183  }
184 
185  //- The size of the effective point field
186  label size() const noexcept
187  {
188  return useSubset_ ? pointLabels_.size() : points_.size();
189  }
190 
191  //- Map to the original (non-subset) point label
192  label objectIndex(const label index) const
193  {
194  return useSubset_ && index >= 0 ? pointLabels_[index] : index;
195  }
196 
197  //- Point at specified shape index
198  const point& operator[](const label index) const
199  {
200  return points_[objectIndex(index)];
201  }
202 
203  //- Point at specified shape index
204  const point& centre(const label index) const
205  {
206  return points_[objectIndex(index)];
207  }
208 
209  //- Point cloud
210  tmp<pointField> centres() const;
211 
212 
213  // Search
214 
215  //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
216  // Only makes sense for closed surfaces.
218  (
220  const point& sample
221  ) const;
222 
223  //- Does (bb of) shape at index searchBox
224  bool overlaps
225  (
226  const label index,
227  const treeBoundBox& searchBox
228  ) const;
229 
230  //- Does shape at index overlap the sphere
231  bool overlaps
232  (
233  const label index,
234  const point& centre,
235  const scalar radiusSqr
236  ) const;
237 
238  //- Calculates nearest (to sample) point in shape.
239  // Returns actual point and distance (squared)
240  void findNearest
241  (
242  const labelUList& indices,
243  const point& sample,
244 
245  scalar& nearestDistSqr,
246  label& nearestIndex,
247  point& nearestPoint
248  ) const;
249 
250 
251  // Housekeeping
252 
253  //- Map to the original (non-subset) point label
255  label pointLabel(label index) const { return objectIndex(index); }
256 };
257 
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 } // End namespace Foam
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
265 
266 #endif
267 
268 // ************************************************************************* //
bool useSubset() const noexcept
Use a subset of points.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
const point & operator[](const label index) const
Point at specified shape index.
A line primitive.
Definition: line.H:52
Holds (reference to) pointField. Encapsulation of data needed for octree searches. Used for searching for nearest point. No bounding boxes around points. Only overlaps and calcNearest are implemented, rest makes little sense.
Definition: treeDataPoint.H:58
const pointField & points() const noexcept
The original point field.
Forward to treeDataPoint findNearest operations.
Definition: treeDataPoint.H:83
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
bool overlaps(const label index, const treeBoundBox &searchBox) const
Does (bb of) shape at index searchBox.
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 to the original (non-subset) point label.
const point & centre(const label index) const
Point at specified shape index.
tmp< pointField > centres() const
Point cloud.
Definition: treeDataPoint.C:86
bool empty() const noexcept
Is the effective point field empty?
findNearestOp(const indexedOctree< treeDataPoint > &tree)
treeDataPoint(const pointField &points)
Construct from pointField.
Definition: treeDataPoint.C:35
Tree tree(triangles.begin(), triangles.end())
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
OBJstream os(runTime.globalPath()/outputName)
findIntersectOp(const indexedOctree< treeDataPoint > &tree)
treeBoundBox bounds(const labelUList &indices) const
Return bounding box for the specified point indices.
Definition: treeDataPoint.C:70
volumeType getVolumeType(const indexedOctree< treeDataPoint > &os, const point &sample) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
Definition: treeDataPoint.C:98
Forward to treeDataPoint findIntersect operations (not possible)
Non-pointer based hierarchical recursive searching.
label size() const noexcept
The size of the effective point field.
label pointLabel(label index) const
Map to the original (non-subset) point label.
ClassNameNoDebug("treeDataPoint")
void findNearest(const labelUList &indices, const point &sample, scalar &nearestDistSqr, label &nearestIndex, point &nearestPoint) const
Calculates nearest (to sample) point in shape.
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:90
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50
int nDim() const noexcept
Object dimension == 0 (point element)
const labelList & pointLabels() const noexcept
The subset of point ids to use.
Namespace for OpenFOAM.