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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
28 
29 #include "treeDataPoint.H"
30 #include "indexedOctree.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 :
44  points_(points),
45  useSubset_(false)
46 {}
47 
48 
50 (
51  const pointField& points,
52  const labelUList& pointLabels,
53  const bool useSubsetPoints
54 )
55 :
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,
107  const point& sample
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
130 {
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 
179 void 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 
200 void 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 
247 bool 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 // ************************************************************************* //
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
labelList pointLabels(nPoints, -1)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
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
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
Unknown state.
Definition: volumeType.H:64
const point & centre(const label index) const
Point at specified shape index.
tmp< pointField > centres() const
Point cloud.
Definition: treeDataPoint.C:86
defineTypeName(manifoldCellsMeshObject)
void add(const boundBox &bb)
Extend to include the second box.
Definition: boundBoxI.H:323
findNearestOp(const indexedOctree< treeDataPoint > &tree)
treeDataPoint(const pointField &points)
Construct from pointField.
Definition: treeDataPoint.C:35
const pointField & points
Tree tree(triangles.begin(), triangles.end())
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
Describes the interaction of a object and a (templated) point. It carries the info of a successful hi...
Definition: pointHit.H:43
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:1237
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:413
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
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
vector point
Point is a vector.
Definition: point.H:37
Non-pointer based hierarchical recursive searching.
scalar distance() const noexcept
Return distance to hit.
Definition: pointHit.H:169
void findNearest(const labelUList &indices, const point &sample, scalar &nearestDistSqr, label &nearestIndex, point &nearestPoint) const
Calculates nearest (to sample) point in shape.
const point_type & point() const noexcept
Return the point, no checks.
Definition: pointHit.H:161
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:90
A class for managing temporary objects.
Definition: HashPtrTable.H:50
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
Namespace for OpenFOAM.