Loading...
Searching...
No Matches
treeDataPoint.C
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
27\*---------------------------------------------------------------------------*/
28
30#include "indexedOctree.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
40// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41
43:
44 points_(points),
45 useSubset_(false)
46{}
47
48
50(
51 const pointField& points,
53 const bool useSubsetPoints
54)
56 points_(points),
57 pointLabels_(pointLabels),
58 useSubset_(useSubsetPoints)
59{}
60
61
63(
64 const pointField& points,
66 const bool useSubsetPoints
67)
68:
69 points_(points),
70 pointLabels_(std::move(pointLabels)),
71 useSubset_(useSubsetPoints)
72{}
73
74
75// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76
78{
79 if (useSubset_)
80 {
81 treeBoundBox bb;
82 for (const label index : indices)
83 {
84 bb.add(points_[pointLabels_[index]]);
85 }
86 return bb;
87 }
88
89 return treeBoundBox(points_, indices);
90}
91
92
94{
95 if (useSubset_)
96 {
97 return tmp<pointField>::New(points_, pointLabels_);
98 }
99
100 return points_;
101}
102
103
105(
106 const indexedOctree<treeDataPoint>& oc,
108) const
109{
110 return volumeType::UNKNOWN;
111}
112
113
115(
116 const label index,
117 const treeBoundBox& searchBox
118) const
119{
120 return searchBox.contains(centre(index));
121}
122
123
125(
126 const label index,
127 const point& centre,
128 const scalar radiusSqr
129) const
131 return (centre.distSqr(this->centre(index)) <= radiusSqr);
132}
133
134
135// * * * * * * * * * * * * * * * * Searching * * * * * * * * * * * * * * * * //
136
138(
140)
141:
142 tree_(tree)
143{}
144
145
147(
149)
150{}
151
152
154(
155 const labelUList& indices,
156 const point& sample,
157
158 scalar& nearestDistSqr,
159 label& minIndex,
160 point& nearestPoint
161) const
162{
163 for (const label index : indices)
164 {
165 const point& pt = centre(index);
166
167 const scalar distSqr = sample.distSqr(pt);
168
169 if (distSqr < nearestDistSqr)
170 {
171 nearestDistSqr = distSqr;
172 minIndex = index;
173 nearestPoint = pt;
174 }
175 }
176}
177
178
179void Foam::treeDataPoint::findNearestOp::operator()
180(
181 const labelUList& indices,
182 const point& sample,
183
184 scalar& nearestDistSqr,
185 label& minIndex,
186 point& nearestPoint
187) const
188{
189 tree_.shapes().findNearest
190 (
191 indices,
192 sample,
193 nearestDistSqr,
194 minIndex,
195 nearestPoint
196 );
197}
198
199
200void Foam::treeDataPoint::findNearestOp::operator()
201(
202 const labelUList& indices,
203 const linePointRef& ln,
204
205 treeBoundBox& tightest,
206 label& minIndex,
207 point& linePoint,
208 point& nearestPoint
209) const
210{
211 const treeDataPoint& shape = tree_.shapes();
212
213 const treeBoundBox lnBb(ln.box());
214
215 // Best so far
216 scalar nearestDistSqr = GREAT;
217 if (minIndex >= 0)
218 {
219 nearestDistSqr = linePoint.distSqr(nearestPoint);
220 }
221
222 for (const label index : indices)
223 {
224 const point& pt = shape.centre(index);
225
226 if (tightest.contains(pt))
227 {
228 // Nearest point on line
229 pointHit pHit = ln.nearestDist(pt);
230 const scalar distSqr = sqr(pHit.distance());
231
232 if (distSqr < nearestDistSqr)
233 {
234 nearestDistSqr = distSqr;
235 minIndex = index;
236 linePoint = pHit.point();
237 nearestPoint = pt;
238
239 tightest = lnBb;
240 tightest.grow(pHit.distance());
241 }
242 }
243 }
244}
245
246
247bool Foam::treeDataPoint::findIntersectOp::operator()
248(
249 const label index,
250 const point& start,
251 const point& end,
252 point& result
253) const
254{
256 return false;
257}
258
259
260// ************************************************************************* //
Minimal example by using system/controlDict.functions:
scalar distance() const noexcept
Return distance to hit.
Definition pointHit.H:169
const point_type & point() const noexcept
Return the point, no checks.
Definition pointHit.H:161
void grow(const scalar delta)
Expand box by adjusting min/max by specified amount in each dimension.
Definition boundBoxI.H:367
void add(const boundBox &bb)
Extend to include the second box.
Definition boundBoxI.H:323
Non-pointer based hierarchical recursive searching.
A class for managing temporary objects.
Definition tmp.H:75
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition tmp.H:215
Standard boundBox with extra functionality for use in octree.
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
findIntersectOp(const indexedOctree< treeDataPoint > &tree)
findNearestOp(const indexedOctree< treeDataPoint > &tree)
Holds (reference to) pointField. Encapsulation of data needed for octree searches....
tmp< pointField > centres() const
Point cloud.
treeDataPoint(const pointField &points)
Construct from pointField.
void findNearest(const labelUList &indices, const point &sample, scalar &nearestDistSqr, label &nearestIndex, point &nearestPoint) const
Calculates nearest (to sample) point in shape.
treeBoundBox bounds(const labelUList &indices) const
Return bounding box for the specified point indices.
const point & centre(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.
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
@ UNKNOWN
Unknown state.
Definition volumeType.H:64
#define defineTypeName(Type)
Define the typeName.
Definition className.H:113
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition error.H:688
const pointField & points
const char * end
Definition SVGTools.H:223
Namespace for OpenFOAM.
PointHit< point > pointHit
A PointHit with a 3D point.
Definition pointHit.H:51
List< label > labelList
A List of labels.
Definition List.H:62
dimensionedSymmTensor sqr(const dimensionedVector &dv)
line< point, const point & > linePointRef
A line using referred points.
Definition line.H:66
vector point
Point is a vector.
Definition point.H:37
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
labelList pointLabels(nPoints, -1)
Tree tree(triangles.begin(), triangles.end())