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 | 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 "dynamicTreeDataPoint.H"
27 #include "treeBoundBox.H"
28 #include "dynamicIndexedOctree.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 defineTypeNameAndDebug(dynamicTreeDataPoint, 0);
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 (
42  const DynamicList<point>& points
43 )
44 :
45  points_(points)
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
53 {
54  return points_;
55 }
56 
57 
58 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
59 // Only makes sense for closed surfaces.
61 (
63  const point& sample
64 ) const
65 {
66  return volumeType::UNKNOWN;
67 }
68 
69 
70 // Check if any point on shape is inside cubeBb.
72 (
73  const label index,
74  const treeBoundBox& cubeBb
75 ) const
76 {
77  return cubeBb.contains(points_[index]);
78 }
79 
80 
81 // Check if any point on shape is inside sphere.
83 (
84  const label index,
85  const point& centre,
86  const scalar radiusSqr
87 ) const
88 {
89  const point& p = points_[index];
90 
91  const scalar distSqr = magSqr(p - centre);
92 
93  if (distSqr <= radiusSqr)
94  {
95  return true;
96  }
97 
98  return false;
99 }
100 
101 
102 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
103 // nearestPoint.
105 (
106  const labelUList& indices,
107  const point& sample,
108 
109  scalar& nearestDistSqr,
110  label& minIndex,
111  point& nearestPoint
112 ) const
113 {
114  forAll(indices, i)
115  {
116  const label index = indices[i];
117 
118  const point& pt = points_[index];
119 
120  scalar distSqr = magSqr(pt - sample);
121 
122  if (distSqr < nearestDistSqr)
123  {
124  nearestDistSqr = distSqr;
125  minIndex = index;
126  nearestPoint = pt;
127  }
128  }
129 }
130 
131 
132 //- Calculates nearest (to line) point in shape.
133 // Returns point and distance (squared)
135 (
136  const labelUList& indices,
137  const linePointRef& ln,
138 
139  treeBoundBox& tightest,
140  label& minIndex,
141  point& linePoint,
142  point& nearestPoint
143 ) const
144 {
145  // Best so far
146  scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
147 
148  forAll(indices, i)
149  {
150  const label index = indices[i];
151 
152  const point& shapePt = points_[index];
153 
154  if (tightest.contains(shapePt))
155  {
156  // Nearest point on line
157  pointHit pHit = ln.nearestDist(shapePt);
158  scalar distSqr = sqr(pHit.distance());
159 
160  if (distSqr < nearestDistSqr)
161  {
162  nearestDistSqr = distSqr;
163  minIndex = index;
164  linePoint = pHit.rawPoint();
165  nearestPoint = shapePt;
166 
167  {
168  point& minPt = tightest.min();
169  minPt = min(ln.start(), ln.end());
170  minPt.x() -= pHit.distance();
171  minPt.y() -= pHit.distance();
172  minPt.z() -= pHit.distance();
173  }
174  {
175  point& maxPt = tightest.max();
176  maxPt = max(ln.start(), ln.end());
177  maxPt.x() += pHit.distance();
178  maxPt.y() += pHit.distance();
179  maxPt.z() += pHit.distance();
180  }
181  }
182  }
183  }
184 }
185 
186 
187 // ************************************************************************* //
PointHit< Point > nearestDist(const Point &p) const
Return nearest distance to line from a given point.
Definition: lineI.H:95
const Point & rawPoint() const
Return point with no checking.
Definition: PointHit.H:158
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
PointRef start() const
Return first vertex.
Definition: lineI.H:60
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:402
PointRef end() const
Return second vertex.
Definition: lineI.H:66
dimensioned< scalar > magSqr(const dimensioned< Type > &)
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
Namespace for OpenFOAM.
A line primitive.
Definition: line.H:56
const Cmpt & y() const
Definition: VectorI.H:71
volScalarField & p
Definition: createFields.H:51
dynamicTreeDataPoint(const DynamicList< point > &points)
Construct from List. Holds reference!
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
void findNearest(const labelUList &indices, const point &sample, scalar &nearestDistSqr, label &nearestIndex, point &nearestPoint) const
Calculates nearest (to sample) point in shape.
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
const Cmpt & z() const
Definition: VectorI.H:77
scalar distance() const
Return distance to hit.
Definition: PointHit.H:139
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
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
Non-pointer based hierarchical recursive searching. Storage is dynamic, so elements can be deleted...
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does (bb of) shape at index overlap bb.
volumeType getVolumeType(const dynamicIndexedOctree< dynamicTreeDataPoint > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
const DynamicList< point > & shapePoints() const
Get representative point cloud for all shapes inside.
defineTypeNameAndDebug(combustionModel, 0)