dynamicTreeDataPoint.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) 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 "dynamicTreeDataPoint.H"
30 #include "dynamicIndexedOctree.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 (
45 )
46 :
47  points_(points)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
55 {
56  return treeBoundBox(points_, indices);
57 }
58 
59 
61 (
63  const point& sample
64 ) const
65 {
66  return volumeType::UNKNOWN;
67 }
68 
69 
71 (
72  const label index,
73  const treeBoundBox& searchBox
74 ) const
75 {
76  return searchBox.contains(centre(index));
77 }
78 
79 
81 (
82  const label index,
83  const point& centre,
84  const scalar radiusSqr
85 ) const
86 {
87  return (centre.distSqr(this->centre(index)) <= radiusSqr);
88 }
89 
90 
92 (
93  const labelUList& indices,
94  const point& sample,
95 
96  scalar& nearestDistSqr,
97  label& minIndex,
98  point& nearestPoint
99 ) const
100 {
101  for (const label index : indices)
102  {
103  const point& pt = centre(index);
104 
105  const scalar distSqr = sample.distSqr(pt);
106 
107  if (distSqr < nearestDistSqr)
108  {
109  nearestDistSqr = distSqr;
110  minIndex = index;
111  nearestPoint = pt;
112  }
113  }
114 }
115 
116 
118 (
119  const labelUList& indices,
120  const linePointRef& ln,
121 
122  treeBoundBox& tightest,
123  label& minIndex,
124  point& linePoint,
125  point& nearestPoint
126 ) const
127 {
128  const treeBoundBox lnBb(ln.box());
129 
130  // Best so far
131  scalar nearestDistSqr = linePoint.distSqr(nearestPoint);
132 
133  for (const label index : indices)
134  {
135  const point& pt = centre(index);
136 
137  if (tightest.contains(pt))
138  {
139  // Nearest point on line
140  pointHit pHit = ln.nearestDist(pt);
141  const scalar distSqr = sqr(pHit.distance());
142 
143  if (distSqr < nearestDistSqr)
144  {
145  nearestDistSqr = distSqr;
146  minIndex = index;
147  linePoint = pHit.point();
148  nearestPoint = pt;
149 
150  tightest = lnBb;
151  tightest.grow(pHit.distance());
152  }
153  }
154  }
155 }
156 
157 
158 // ************************************************************************* //
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An enumeration wrapper for classification of a location as being inside/outside of a volume...
Definition: volumeType.H:55
bool overlaps(const label index, const treeBoundBox &searchBox) const
Does (bb of) shape at index overlap bb.
volumeType getVolumeType(const dynamicIndexedOctree< dynamicTreeDataPoint > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
Unknown state.
Definition: volumeType.H:64
dynamicTreeDataPoint(const DynamicList< point > &points)
Construct from List. Holds reference!
defineTypeName(manifoldCellsMeshObject)
line< point, const point & > linePointRef
A line using referred points.
Definition: line.H:66
const pointField & points
Non-pointer based hierarchical recursive searching. Storage is dynamic, so elements can be deleted...
void findNearest(const labelUList &indices, const point &sample, scalar &nearestDistSqr, label &nearestIndex, point &nearestPoint) const
Calculates nearest (to sample) point in shape.
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...
treeBoundBox bounds(const labelUList &indices) const
Return bounding box for the specified point indices.
vector point
Point is a vector.
Definition: point.H:37
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.
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:90
PointHit< point > pointHit
A PointHit with a 3D point.
Definition: pointHit.H:43
Namespace for OpenFOAM.