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-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
29#include "treeBoundBox.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
37}
38
39
40// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41
43(
45)
46:
47 points_(points)
48{}
49
50
51// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52
55{
56 return points_;
57}
58
59
61(
63 const point& sample
64) const
65{
67}
68
69
71(
72 const label index,
73 const treeBoundBox& cubeBb
74) const
75{
76 return cubeBb.contains(points_[index]);
77}
78
79
81(
82 const label index,
83 const point& centre,
84 const scalar radiusSqr
85) const
86{
87 const point& p = points_[index];
88
89 const scalar distSqr = magSqr(p - centre);
90
91 if (distSqr <= radiusSqr)
92 {
93 return true;
94 }
95
96 return false;
97}
98
99
101(
102 const labelUList& indices,
103 const point& sample,
104
105 scalar& nearestDistSqr,
106 label& minIndex,
107 point& nearestPoint
108) const
109{
110 forAll(indices, i)
111 {
112 const label index = indices[i];
113
114 const point& pt = points_[index];
115
116 scalar distSqr = magSqr(pt - sample);
117
118 if (distSqr < nearestDistSqr)
119 {
120 nearestDistSqr = distSqr;
121 minIndex = index;
122 nearestPoint = pt;
123 }
124 }
125}
126
127
129(
130 const labelUList& indices,
131 const linePointRef& ln,
132
133 treeBoundBox& tightest,
134 label& minIndex,
135 point& linePoint,
136 point& nearestPoint
137) const
138{
139 // Best so far
140 scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
141
142 forAll(indices, i)
143 {
144 const label index = indices[i];
145
146 const point& shapePt = points_[index];
147
148 if (tightest.contains(shapePt))
149 {
150 // Nearest point on line
151 pointHit pHit = ln.nearestDist(shapePt);
152 scalar distSqr = sqr(pHit.distance());
153
154 if (distSqr < nearestDistSqr)
155 {
156 nearestDistSqr = distSqr;
157 minIndex = index;
158 linePoint = pHit.rawPoint();
159 nearestPoint = shapePt;
160
161 {
162 point& minPt = tightest.min();
163 minPt = min(ln.start(), ln.end());
164 minPt.x() -= pHit.distance();
165 minPt.y() -= pHit.distance();
166 minPt.z() -= pHit.distance();
167 }
168 {
169 point& maxPt = tightest.max();
170 maxPt = max(ln.start(), ln.end());
171 maxPt.x() += pHit.distance();
172 maxPt.y() += pHit.distance();
173 maxPt.z() += pHit.distance();
174 }
175 }
176 }
177 }
178}
179
180
181// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
Minimal example by using system/controlDict.functions:
int overlaps
Flag to control which overlap calculations are performed.
Definition: PDRparams.H:97
Describes the interaction of a face and a point. It carries the info of a successful hit and (if succ...
Definition: PointHit.H:54
const point_type & rawPoint() const noexcept
The point, no checks.
Definition: PointHit.H:172
scalar distance() const noexcept
Return distance to hit.
Definition: PointHit.H:139
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:91
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:97
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.
const DynamicList< point > & shapePoints() const
Get representative point cloud for all shapes inside.
A line primitive.
Definition: line.H:68
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:89
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:320
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition: volumeType.H:61
@ UNKNOWN
Unknown state.
Definition: volumeType.H:67
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
volScalarField & p
const pointField & points
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensionedSymmTensor sqr(const dimensionedVector &dv)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: MSwindows.C:933
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333