Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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::treeDataPoint
29
30Description
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
38SourceFiles
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
53namespace Foam
54{
55
56// Forward Declarations
57template<class Type> class indexedOctree;
59/*---------------------------------------------------------------------------*\
60 Class treeDataPoint Declaration
61\*---------------------------------------------------------------------------*/
62
63class 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
77public:
78
79 //- Forward to treeDataPoint findNearest operations
80 class findNearestOp
81 {
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);
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
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
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.
221 ) const;
222
223 //- Does (bb of) shape at index searchBox
224 bool overlaps
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
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// ************************************************************************* //
Minimal example by using system/controlDict.functions:
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Non-pointer based hierarchical recursive searching.
A class for managing temporary objects.
Definition tmp.H:75
Standard boundBox with extra functionality for use in octree.
Forward to treeDataPoint findIntersect operations (not possible).
findIntersectOp(const indexedOctree< treeDataPoint > &tree)
Forward to treeDataPoint findNearest operations.
findNearestOp(const indexedOctree< treeDataPoint > &tree)
bool useSubset() const noexcept
Use a subset of points.
tmp< pointField > centres() const
Point cloud.
treeDataPoint(const pointField &points)
Construct from pointField.
ClassNameNoDebug("treeDataPoint")
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 point field empty?
int nDim() const noexcept
Object dimension == 0 (point element).
const point & centre(const label index) const
Point at specified shape index.
label objectIndex(const label index) const
Map to the original (non-subset) point label.
label pointLabel(label index) const
Map to the original (non-subset) point label.
const point & operator[](const label index) const
Point at specified shape index.
const pointField & points() const noexcept
The original point field.
volumeType getVolumeType(const indexedOctree< treeDataPoint > &os, const point &sample) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
label size() const noexcept
The size of the effective point field.
bool overlaps(const label index, const treeBoundBox &searchBox) const
Does (bb of) shape at index searchBox.
const labelList & pointLabels() const noexcept
The subset of point ids to use.
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
OBJstream os(runTime.globalPath()/outputName)
Namespace for bounding specifications. At the moment, mostly for tables.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
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())