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 (
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 // ************************************************************************* //
dynamicTreeDataPoint.H
p
p
Definition: pEqn.H:62
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
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::dynamicTreeDataPoint::points_
const DynamicList< point > & points_
Definition: dynamicTreeDataPoint.H:63
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::dynamicTreeDataPoint::findNearest
void findNearest(const labelUList &indices, const point &sample, scalar &nearestDistSqr, label &nearestIndex, point &nearestPoint) const
Calculates nearest (to sample) point in shape.
Definition: dynamicTreeDataPoint.C:105
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::dynamicTreeDataPoint::shapePoints
const DynamicList< point > & shapePoints() const
Get representative point cloud for all shapes inside.
Definition: dynamicTreeDataPoint.C:52
Foam::dynamicTreeDataPoint::overlaps
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does (bb of) shape at index overlap bb.
Definition: dynamicTreeDataPoint.C:72
Foam::dynamicIndexedOctree
Non-pointer based hierarchical recursive searching. Storage is dynamic, so elements can be deleted.
Definition: dynamicIndexedOctree.H:55
dynamicIndexedOctree.H
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
treeBoundBox.H
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
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
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::Vector< scalar >
Foam::dynamicTreeDataPoint::getVolumeType
volumeType getVolumeType(const dynamicIndexedOctree< dynamicTreeDataPoint > &, const point &) const
Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
Definition: dynamicTreeDataPoint.C:61
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
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::line
A line primitive.
Definition: line.H:56
Foam::dynamicTreeDataPoint::dynamicTreeDataPoint
dynamicTreeDataPoint(const DynamicList< point > &points)
Construct from List. Holds reference!
Definition: dynamicTreeDataPoint.C:41
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
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)