Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
37}
38
39
40// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41
43(
45)
46:
47 points_(points)
48{}
49
50
51// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52
61(
64) const
65{
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// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
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
scalar distSqr(const Vector< Cmpt > &v2) const
The L2-norm distance squared from another vector. The magSqr() of the difference.
Definition VectorI.H:95
void grow(const scalar delta)
Expand box by adjusting min/max by specified amount in each dimension.
Definition boundBoxI.H:367
Non-pointer based hierarchical recursive searching. Storage is dynamic, so elements can be deleted.
Holds (reference to) pointField. Encapsulation of data needed for octree searches....
void findNearest(const labelUList &indices, const point &sample, scalar &nearestDistSqr, label &nearestIndex, point &nearestPoint) const
Calculates nearest (to sample) point in shape.
volumeType getVolumeType(const dynamicIndexedOctree< dynamicTreeDataPoint > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
dynamicTreeDataPoint(const DynamicList< point > &points)
Construct from List. Holds reference!
treeBoundBox bounds(const labelUList &indices) const
Return bounding box for the specified point indices.
const point & centre(label index) const
Point at specified shape index.
const DynamicList< point > & points() const noexcept
The original point field.
bool overlaps(const label index, const treeBoundBox &searchBox) const
Does (bb of) shape at index overlap bb.
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.
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
const pointField & points
Namespace for OpenFOAM.
PointHit< point > pointHit
A PointHit with a 3D point.
Definition pointHit.H:51
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
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