dynamicTreeDataPoint.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "dynamicTreeDataPoint.H"
27 #include "treeBoundBox.H"
28 #include "dynamicIndexedOctree.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 (
43 )
44 :
45  points_(points)
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
53 {
54  return points_;
55 }
56 
57 
59 (
61  const point& sample
62 ) const
63 {
64  return volumeType::unknown;
65 }
66 
67 
69 (
70  const label index,
71  const treeBoundBox& cubeBb
72 ) const
73 {
74  return cubeBb.contains(points_[index]);
75 }
76 
77 
79 (
80  const label index,
81  const point& centre,
82  const scalar radiusSqr
83 ) const
84 {
85  const point& p = points_[index];
86 
87  const scalar distSqr = magSqr(p - centre);
88 
89  if (distSqr <= radiusSqr)
90  {
91  return true;
92  }
93 
94  return false;
95 }
96 
97 
99 (
100  const labelUList& indices,
101  const point& sample,
102 
103  scalar& nearestDistSqr,
104  label& minIndex,
105  point& nearestPoint
106 ) const
107 {
108  forAll(indices, i)
109  {
110  const label index = indices[i];
111 
112  const point& pt = points_[index];
113 
114  scalar distSqr = magSqr(pt - sample);
115 
116  if (distSqr < nearestDistSqr)
117  {
118  nearestDistSqr = distSqr;
119  minIndex = index;
120  nearestPoint = pt;
121  }
122  }
123 }
124 
125 
127 (
128  const labelUList& indices,
129  const linePointRef& ln,
130 
131  treeBoundBox& tightest,
132  label& minIndex,
133  point& linePoint,
134  point& nearestPoint
135 ) const
136 {
137  // Best so far
138  scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
139 
140  forAll(indices, i)
141  {
142  const label index = indices[i];
143 
144  const point& shapePt = points_[index];
145 
146  if (tightest.contains(shapePt))
147  {
148  // Nearest point on line
149  pointHit pHit = ln.nearestDist(shapePt);
150  scalar distSqr = sqr(pHit.distance());
151 
152  if (distSqr < nearestDistSqr)
153  {
154  nearestDistSqr = distSqr;
155  minIndex = index;
156  linePoint = pHit.rawPoint();
157  nearestPoint = shapePt;
158 
159  {
160  point& minPt = tightest.min();
161  minPt = min(ln.start(), ln.end());
162  minPt.x() -= pHit.distance();
163  minPt.y() -= pHit.distance();
164  minPt.z() -= pHit.distance();
165  }
166  {
167  point& maxPt = tightest.max();
168  maxPt = max(ln.start(), ln.end());
169  maxPt.x() += pHit.distance();
170  maxPt.y() += pHit.distance();
171  maxPt.z() += pHit.distance();
172  }
173  }
174  }
175  }
176 }
177 
178 
179 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
scalar distance() const
Return distance to hit.
Definition: PointHit.H:139
const Point & rawPoint() const
Return point with no checking.
Definition: PointHit.H:158
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
const Cmpt & x() const
Definition: VectorI.H:75
const point & min() const
Minimum point defining the bounding box.
Definition: boundBoxI.H:60
const point & max() const
Maximum point defining the bounding box.
Definition: boundBoxI.H:66
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....
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does (bb of) shape at index overlap bb.
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.
dynamicTreeDataPoint(const DynamicList< point > &points)
Construct from List. Holds reference!
A line primitive.
Definition: line.H:71
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:90
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:387
const pointField & points
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dimensionedSymmTensor sqr(const dimensionedVector &dv)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:908
volScalarField & p