treeDataPoint.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 | Copyright (C) 2011-2013 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 
91 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
92 // Only makes sense for closed surfaces.
94 (
96  const point& sample
97 ) const
98 {
99  return volumeType::UNKNOWN;
100 }
101 
102 
103 // Check if any point on shape is inside cubeBb.
105 (
106  const label index,
107  const treeBoundBox& cubeBb
108 ) const
109 {
110  label pointI = (useSubset_ ? pointLabels_[index] : index);
111  return cubeBb.contains(points_[pointI]);
112 }
113 
114 
115 // Check if any point on shape is inside sphere.
117 (
118  const label index,
119  const point& centre,
120  const scalar radiusSqr
121 ) const
122 {
123  label pointI = (useSubset_ ? pointLabels_[index] : index);
124 
125  if (magSqr(points_[pointI] - centre) <= radiusSqr)
126  {
127  return true;
128  }
129 
130  return false;
131 }
132 
133 
134 void Foam::treeDataPoint::findNearestOp::operator()
135 (
136  const labelUList& indices,
137  const point& sample,
138 
139  scalar& nearestDistSqr,
140  label& minIndex,
141  point& nearestPoint
142 ) const
143 {
144  const treeDataPoint& shape = tree_.shapes();
145 
146  forAll(indices, i)
147  {
148  const label index = indices[i];
149  label pointI =
150  (
151  shape.useSubset()
152  ? shape.pointLabels()[index]
153  : index
154  );
155 
156  const point& pt = shape.points()[pointI];
157 
158  scalar distSqr = magSqr(pt - sample);
159 
160  if (distSqr < nearestDistSqr)
161  {
162  nearestDistSqr = distSqr;
163  minIndex = index;
164  nearestPoint = pt;
165  }
166  }
167 }
168 
169 
170 void Foam::treeDataPoint::findNearestOp::operator()
171 (
172  const labelUList& indices,
173  const linePointRef& ln,
174 
175  treeBoundBox& tightest,
176  label& minIndex,
177  point& linePoint,
178  point& nearestPoint
179 ) const
180 {
181  const treeDataPoint& shape = tree_.shapes();
182 
183  // Best so far
184  scalar nearestDistSqr = GREAT;
185  if (minIndex >= 0)
186  {
187  nearestDistSqr = magSqr(linePoint - nearestPoint);
188  }
189 
190  forAll(indices, i)
191  {
192  const label index = indices[i];
193  label pointI =
194  (
195  shape.useSubset()
196  ? shape.pointLabels()[index]
197  : index
198  );
199 
200  const point& shapePt = shape.points()[pointI];
201 
202  if (tightest.contains(shapePt))
203  {
204  // Nearest point on line
205  pointHit pHit = ln.nearestDist(shapePt);
206  scalar distSqr = sqr(pHit.distance());
207 
208  if (distSqr < nearestDistSqr)
209  {
210  nearestDistSqr = distSqr;
211  minIndex = index;
212  linePoint = pHit.rawPoint();
213  nearestPoint = shapePt;
214 
215  {
216  point& minPt = tightest.min();
217  minPt = min(ln.start(), ln.end());
218  minPt.x() -= pHit.distance();
219  minPt.y() -= pHit.distance();
220  minPt.z() -= pHit.distance();
221  }
222  {
223  point& maxPt = tightest.max();
224  maxPt = max(ln.start(), ln.end());
225  maxPt.x() += pHit.distance();
226  maxPt.y() += pHit.distance();
227  maxPt.z() += pHit.distance();
228  }
229  }
230  }
231  }
232 }
233 
234 
235 bool Foam::treeDataPoint::findIntersectOp::operator()
236 (
237  const label index,
238  const point& start,
239  const point& end,
240  point& result
241 ) const
242 {
244  (
245  "treeDataPoint::intersects(const label, const point&,"
246  "const point&, point&)"
247  );
248  return false;
249 }
250 
251 
252 // ************************************************************************* //
const Point & rawPoint() const
Return point with no checking.
Definition: PointHit.H:158
volumeType getVolumeType(const indexedOctree< treeDataPoint > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
Definition: treeDataPoint.C:94
const labelList & pointLabels() const
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:402
dimensioned< scalar > magSqr(const dimensioned< Type > &)
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does (bb of) shape at index overlap bb.
findIntersectOp(const indexedOctree< treeDataPoint > &tree)
Definition: treeDataPoint.C:70
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
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:75
static const Vector max
Definition: Vector.H:82
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Namespace for OpenFOAM.
A line primitive.
Definition: line.H:56
const pointField & points() const
const Cmpt & y() const
Definition: VectorI.H:71
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:855
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define forAll(list, i)
Definition: UList.H:421
const Cmpt & x() const
Definition: VectorI.H:65
pointField shapePoints() const
Get representative point cloud for all shapes inside.
Definition: treeDataPoint.C:78
const Cmpt & z() const
Definition: VectorI.H:77
bool useSubset() const
treeDataPoint(const pointField &)
Construct from pointField. Holds reference!
Definition: treeDataPoint.C:41
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:47
scalar distance() const
Return distance to hit.
Definition: PointHit.H:139
static const Vector min
Definition: Vector.H:83
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
#define notImplemented(functionName)
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:356
findNearestOp(const indexedOctree< treeDataPoint > &tree)
Definition: treeDataPoint.C:61
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
defineTypeNameAndDebug(combustionModel, 0)