All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
treeDataPoint.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 "treeDataPoint.H"
27 #include "treeBoundBox.H"
28 #include "indexedOctree.H"
29 #include "triangleFuncs.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 defineTypeNameAndDebug(treeDataPoint, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 :
43  points_(points),
44  useSubset_(false)
45 {}
46 
47 
49 (
50  const pointField& points,
51  const labelList& pointLabels
52 )
53 :
54  points_(points),
55  pointLabels_(pointLabels),
56  useSubset_(true)
57 {}
58 
59 
61 (
63 )
64 :
65  tree_(tree)
66 {}
67 
68 
70 (
72 )
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
79 {
80  if (useSubset_)
81  {
82  return pointField(points_, pointLabels_);
83  }
84  else
85  {
86  return points_;
87  }
88 }
89 
90 
92 (
94  const point& sample
95 ) const
96 {
97  return volumeType::unknown;
98 }
99 
100 
102 (
103  const label index,
104  const treeBoundBox& cubeBb
105 ) const
106 {
107  label pointi = (useSubset_ ? pointLabels_[index] : index);
108  return cubeBb.contains(points_[pointi]);
109 }
110 
111 
113 (
114  const label index,
115  const point& centre,
116  const scalar radiusSqr
117 ) const
118 {
119  label pointi = (useSubset_ ? pointLabels_[index] : index);
120 
121  if (magSqr(points_[pointi] - centre) <= radiusSqr)
122  {
123  return true;
124  }
125 
126  return false;
127 }
128 
129 
130 void Foam::treeDataPoint::findNearestOp::operator()
131 (
132  const labelUList& indices,
133  const point& sample,
134 
135  scalar& nearestDistSqr,
136  label& minIndex,
137  point& nearestPoint
138 ) const
139 {
140  const treeDataPoint& shape = tree_.shapes();
141 
142  forAll(indices, i)
143  {
144  const label index = indices[i];
145  label pointi =
146  (
147  shape.useSubset()
148  ? shape.pointLabels()[index]
149  : index
150  );
151 
152  const point& pt = shape.points()[pointi];
153 
154  scalar distSqr = magSqr(pt - sample);
155 
156  if (distSqr < nearestDistSqr)
157  {
158  nearestDistSqr = distSqr;
159  minIndex = index;
160  nearestPoint = pt;
161  }
162  }
163 }
164 
165 
166 void Foam::treeDataPoint::findNearestOp::operator()
167 (
168  const labelUList& indices,
169  const linePointRef& ln,
170 
171  treeBoundBox& tightest,
172  label& minIndex,
173  point& linePoint,
174  point& nearestPoint
175 ) const
176 {
177  const treeDataPoint& shape = tree_.shapes();
178 
179  // Best so far
180  scalar nearestDistSqr = great;
181  if (minIndex >= 0)
182  {
183  nearestDistSqr = magSqr(linePoint - nearestPoint);
184  }
185 
186  forAll(indices, i)
187  {
188  const label index = indices[i];
189  label pointi =
190  (
191  shape.useSubset()
192  ? shape.pointLabels()[index]
193  : index
194  );
195 
196  const point& shapePt = shape.points()[pointi];
197 
198  if (tightest.contains(shapePt))
199  {
200  // Nearest point on line
201  pointHit pHit = ln.nearestDist(shapePt);
202  scalar distSqr = sqr(pHit.distance());
203 
204  if (distSqr < nearestDistSqr)
205  {
206  nearestDistSqr = distSqr;
207  minIndex = index;
208  linePoint = pHit.rawPoint();
209  nearestPoint = shapePt;
210 
211  {
212  point& minPt = tightest.min();
213  minPt = min(ln.start(), ln.end());
214  minPt.x() -= pHit.distance();
215  minPt.y() -= pHit.distance();
216  minPt.z() -= pHit.distance();
217  }
218  {
219  point& maxPt = tightest.max();
220  maxPt = max(ln.start(), ln.end());
221  maxPt.x() += pHit.distance();
222  maxPt.y() += pHit.distance();
223  maxPt.z() += pHit.distance();
224  }
225  }
226  }
227  }
228 }
229 
230 
231 bool Foam::treeDataPoint::findIntersectOp::operator()
232 (
233  const label index,
234  const point& start,
235  const point& end,
236  point& result
237 ) const
238 {
240  return false;
241 }
242 
243 
244 // ************************************************************************* //
volumeType getVolumeType(const indexedOctree< treeDataPoint > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
Definition: treeDataPoint.C:92
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
A line primitive.
Definition: line.H:56
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:59
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does (bb of) shape at index overlap bb.
static const Form max
Definition: VectorSpace.H:115
dimensionedSymmTensor sqr(const dimensionedVector &dv)
bool useSubset() const
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
static const Form min
Definition: VectorSpace.H:116
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
findNearestOp(const indexedOctree< treeDataPoint > &tree)
Definition: treeDataPoint.C:61
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
const Cmpt & x() const
Definition: VectorI.H:75
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:908
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:394
dimensioned< scalar > magSqr(const dimensioned< Type > &)
const Point & rawPoint() const
Return point with no checking.
Definition: PointHit.H:158
defineTypeNameAndDebug(combustionModel, 0)
findIntersectOp(const indexedOctree< treeDataPoint > &tree)
Definition: treeDataPoint.C:70
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:47
const pointField & points() const
const labelList & pointLabels() const
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:87
treeDataPoint(const pointField &)
Construct from pointField. Holds reference!
Definition: treeDataPoint.C:41
pointField shapePoints() const
Get representative point cloud for all shapes inside.
Definition: treeDataPoint.C:78
scalar distance() const
Return distance to hit.
Definition: PointHit.H:139
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
Namespace for OpenFOAM.