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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "dynamicTreeDataPoint.H"
29 #include "treeBoundBox.H"
30 #include "dynamicIndexedOctree.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 defineTypeNameAndDebug(dynamicTreeDataPoint, 0);
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 (
45 )
46 :
47  points_(points)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
55 {
56  return points_;
57 }
58 
59 
61 (
63  const point& sample
64 ) const
65 {
66  return volumeType::UNKNOWN;
67 }
68 
69 
71 (
72  const label index,
73  const treeBoundBox& cubeBb
74 ) const
75 {
76  return cubeBb.contains(points_[index]);
77 }
78 
79 
81 (
82  const label index,
83  const point& centre,
84  const scalar radiusSqr
85 ) const
86 {
87  const point& p = points_[index];
88 
89  const scalar distSqr = magSqr(p - centre);
90 
91  if (distSqr <= radiusSqr)
92  {
93  return true;
94  }
95 
96  return false;
97 }
98 
99 
101 (
102  const labelUList& indices,
103  const point& sample,
104 
105  scalar& nearestDistSqr,
106  label& minIndex,
107  point& nearestPoint
108 ) const
109 {
110  forAll(indices, i)
111  {
112  const label index = indices[i];
113 
114  const point& pt = points_[index];
115 
116  scalar distSqr = magSqr(pt - sample);
117 
118  if (distSqr < nearestDistSqr)
119  {
120  nearestDistSqr = distSqr;
121  minIndex = index;
122  nearestPoint = pt;
123  }
124  }
125 }
126 
127 
129 (
130  const labelUList& indices,
131  const linePointRef& ln,
132 
133  treeBoundBox& tightest,
134  label& minIndex,
135  point& linePoint,
136  point& nearestPoint
137 ) const
138 {
139  // Best so far
140  scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
141 
142  forAll(indices, i)
143  {
144  const label index = indices[i];
145 
146  const point& shapePt = points_[index];
147 
148  if (tightest.contains(shapePt))
149  {
150  // Nearest point on line
151  pointHit pHit = ln.nearestDist(shapePt);
152  scalar distSqr = sqr(pHit.distance());
153 
154  if (distSqr < nearestDistSqr)
155  {
156  nearestDistSqr = distSqr;
157  minIndex = index;
158  linePoint = pHit.rawPoint();
159  nearestPoint = shapePt;
160 
161  {
162  point& minPt = tightest.min();
163  minPt = min(ln.start(), ln.end());
164  minPt.x() -= pHit.distance();
165  minPt.y() -= pHit.distance();
166  minPt.z() -= pHit.distance();
167  }
168  {
169  point& maxPt = tightest.max();
170  maxPt = max(ln.start(), ln.end());
171  maxPt.x() += pHit.distance();
172  maxPt.y() += pHit.distance();
173  maxPt.z() += pHit.distance();
174  }
175  }
176  }
177  }
178 }
179 
180 
181 // ************************************************************************* //
dynamicTreeDataPoint.H
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::PointHit
Describes the interaction of a face and a point. It carries the info of a successful hit and (if succ...
Definition: PointHit.H:53
Foam::DynamicList< point >
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:101
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:86
Foam::dynamicTreeDataPoint::shapePoints
const DynamicList< point > & shapePoints() const
Get representative point cloud for all shapes inside.
Definition: dynamicTreeDataPoint.C:54
Foam::PointHit::distance
scalar distance() const noexcept
Return distance to hit.
Definition: PointHit.H:139
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:97
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::dynamicTreeDataPoint::overlaps
bool overlaps(const label index, const treeBoundBox &sampleBb) const
Does (bb of) shape at index overlap bb.
Definition: dynamicTreeDataPoint.C:71
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:91
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::dynamicIndexedOctree
Non-pointer based hierarchical recursive searching. Storage is dynamic, so elements can be deleted.
Definition: dynamicIndexedOctree.H:57
dynamicIndexedOctree.H
Foam::volumeType
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition: volumeType.H:60
treeBoundBox.H
Foam::volumeType::UNKNOWN
Unknown state.
Definition: volumeType.H:67
Foam::PointHit::rawPoint
const point_type & rawPoint() const noexcept
The point, no checks.
Definition: PointHit.H:172
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::treeBoundBox::contains
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:320
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< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::line
A line primitive.
Definition: line.H:53
Foam::dynamicTreeDataPoint::dynamicTreeDataPoint
dynamicTreeDataPoint(const DynamicList< point > &points)
Construct from List. Holds reference!
Definition: dynamicTreeDataPoint.C:43
Foam::ln
bool ln(const fileName &src, const fileName &dst)
Create a softlink. dst should not exist. Returns true if successful.
Definition: MSwindows.C:925
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
sample
Minimal example by using system/controlDict.functions: