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-2015 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  return false;
245 }
246 
247 
248 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Foam::treeDataPoint::pointLabels
const labelList & pointLabels() const
Definition: treeDataPoint.H:149
Foam::Vector::min
static const Vector min
Definition: Vector.H:83
Foam::treeDataPoint::points
const pointField & points() const
Definition: treeDataPoint.H:154
Foam::treeDataPoint::findIntersectOp::findIntersectOp
findIntersectOp(const indexedOctree< treeDataPoint > &tree)
Definition: treeDataPoint.C:70
Foam::treeDataPoint::useSubset
bool useSubset() const
Definition: treeDataPoint.H:159
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::PointHit
This class describes the interaction of a face and a point. It carries the info of a successful hit a...
Definition: PointHit.H:51
Foam::PointHit::rawPoint
const Point & rawPoint() const
Return point with no checking.
Definition: PointHit.H:158
Foam::treeBoundBox
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:75
Foam::Vector::max
static const Vector max
Definition: Vector.H:82
indexedOctree.H
Foam::treeDataPoint::treeDataPoint
treeDataPoint(const pointField &)
Construct from pointField. Holds reference!
Definition: treeDataPoint.C:41
Foam::treeDataPoint
Holds (reference to) pointField. Encapsulation of data needed for octree searches....
Definition: treeDataPoint.H:59
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:365
Foam::PointHit::distance
scalar distance() const
Return distance to hit.
Definition: PointHit.H:139
Foam::label
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
Foam::volumeType
Definition: volumeType.H:54
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
treeDataPoint.H
treeBoundBox.H
Foam::treeDataPoint::shapePoints
pointField shapePoints() const
Get representative point cloud for all shapes inside.
Definition: treeDataPoint.C:78
Foam::indexedOctree
Non-pointer based hierarchical recursive searching.
Definition: treeDataTriSurface.H:47
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
triangleFuncs.H
Foam::treeDataPoint::findNearestOp::findNearestOp
findNearestOp(const indexedOctree< treeDataPoint > &tree)
Definition: treeDataPoint.C:61
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::treeBoundBox::contains
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:395
Foam::treeDataPoint::getVolumeType
volumeType getVolumeType(const indexedOctree< treeDataPoint > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
Definition: treeDataPoint.C:94
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::UList
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
Foam::treeDataPoint::overlaps
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does (bb of) shape at index overlap bb.
Definition: treeDataPoint.C:105
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::line
A line primitive.
Definition: line.H:56
Foam::ln
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: POSIX.C:854
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::volumeType::UNKNOWN
@ UNKNOWN
Definition: volumeType.H:61
pointLabels
labelList pointLabels(nPoints, -1)
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)