FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "treeDataPoint.H"
29 #include <meshTools/treeBoundBox.H>
30 #include "indexedOctree.H"
31 #include <OpenFOAM/polyMesh.H>
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 // Construct from components
43 :
44  points_(points)
45 {}
46 
47 
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 
51 {
52  return points_;
53 }
54 
55 
56 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
57 // Only makes sense for closed surfaces.
59 (
61  const point& sample
62 ) const
63 {
65 }
66 
67 
68 // Check if any point on shape is inside cubeBb.
70 (
71  const label index,
72  const treeBoundBox& cubeBb
73 ) const
74 {
75  return cubeBb.contains(points_[index]);
76 }
77 
78 
79 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
80 // nearestPoint.
82 (
83  const labelList& indices,
84  const point& sample,
85 
86  scalar& nearestDistSqr,
87  label& minIndex,
88  point& nearestPoint
89 ) const
90 {
91  forAll(indices, i)
92  {
93  label index = indices[i];
94 
95  const point& pt = points_[index];
96 
97  scalar distSqr = magSqr(pt - sample);
98 
99  if (distSqr < nearestDistSqr)
100  {
101  nearestDistSqr = distSqr;
102  minIndex = index;
103  nearestPoint = pt;
104  }
105  }
106 }
107 
108 
109 //- Calculates nearest (to line) point in shape.
110 // Returns point and distance (squared)
112 (
113  const labelList& indices,
114  const linePointRef& ln,
115 
116  treeBoundBox& tightest,
117  label& minIndex,
118  point& linePoint,
119  point& nearestPoint
120 ) const
121 {
122  // Best so far
123  scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
124 
125  forAll(indices, i)
126  {
127  label index = indices[i];
128 
129  const point& shapePt = points_[index];
130 
131  if (tightest.contains(shapePt))
132  {
133  // Nearest point on line
134  pointHit pHit = ln.nearestDist(shapePt);
135  scalar distSqr = sqr(pHit.distance());
136 
137  if (distSqr < nearestDistSqr)
138  {
139  nearestDistSqr = distSqr;
140  minIndex = index;
141  linePoint = pHit.rawPoint();
142  nearestPoint = shapePt;
143 
144  {
145  point& minPt = tightest.min();
146  minPt = min(ln.start(), ln.end());
147  minPt.x() -= pHit.distance();
148  minPt.y() -= pHit.distance();
149  minPt.z() -= pHit.distance();
150  }
151  {
152  point& maxPt = tightest.max();
153  maxPt = max(ln.start(), ln.end());
154  maxPt.x() += pHit.distance();
155  maxPt.y() += pHit.distance();
156  maxPt.z() += pHit.distance();
157  }
158  }
159  }
160  }
161 }
162 
163 
164 // ************************ vim: set sw=4 sts=4 et: ************************ //