1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
29 #include "treeDataPoint.H"
30 #include "treeBoundBox.H"
31 #include "indexedOctree.H"
33 #include "triangleFuncs.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(Foam::treeDataPoint, 0);
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 // Construct from components
43 Foam::treeDataPoint::treeDataPoint(const pointField& points)
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 Foam::pointField Foam::treeDataPoint::points() const
57 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
58 // Only makes sense for closed surfaces.
59 Foam::label Foam::treeDataPoint::getVolumeType
61 const indexedOctree<treeDataPoint>& oc,
65 return indexedOctree<treeDataPoint>::UNKNOWN;
69 // Check if any point on shape is inside cubeBb.
70 bool Foam::treeDataPoint::overlaps
73 const treeBoundBox& cubeBb
76 return cubeBb.contains(points_[index]);
80 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
82 void Foam::treeDataPoint::findNearest
84 const labelList& indices,
87 scalar& nearestDistSqr,
94 label index = indices[i];
96 const point& pt = points_[index];
98 scalar distSqr = magSqr(pt - sample);
100 if (distSqr < nearestDistSqr)
102 nearestDistSqr = distSqr;
110 //- Calculates nearest (to line) point in shape.
111 // Returns point and distance (squared)
112 void Foam::treeDataPoint::findNearest
114 const labelList& indices,
115 const linePointRef& ln,
117 treeBoundBox& tightest,
124 scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
128 label index = indices[i];
130 const point& shapePt = points_[index];
132 if (tightest.contains(shapePt))
134 // Nearest point on line
135 pointHit pHit = ln.nearestDist(shapePt);
136 scalar distSqr = sqr(pHit.distance());
138 if (distSqr < nearestDistSqr)
140 nearestDistSqr = distSqr;
142 linePoint = pHit.rawPoint();
143 nearestPoint = shapePt;
146 point& minPt = tightest.min();
147 minPt = min(ln.start(), ln.end());
148 minPt.x() -= pHit.distance();
149 minPt.y() -= pHit.distance();
150 minPt.z() -= pHit.distance();
153 point& maxPt = tightest.max();
154 maxPt = max(ln.start(), ln.end());
155 maxPt.x() += pHit.distance();
156 maxPt.y() += pHit.distance();
157 maxPt.z() += pHit.distance();
165 // ************************************************************************* //