1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "treeDataPoint.H"
27 #include "treeBoundBox.H"
28 #include "indexedOctree.H"
29 #include "triangleFuncs.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(Foam::treeDataPoint, 0);
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 Foam::treeDataPoint::treeDataPoint(const pointField& points)
45 Foam::treeDataPoint::treeDataPoint
47 const pointField& points,
48 const labelList& pointLabels
52 pointLabels_(pointLabels),
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59 Foam::pointField Foam::treeDataPoint::shapePoints() const
63 return pointField(points_, pointLabels_);
72 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
73 // Only makes sense for closed surfaces.
74 Foam::label Foam::treeDataPoint::getVolumeType
76 const indexedOctree<treeDataPoint>& oc,
80 return indexedOctree<treeDataPoint>::UNKNOWN;
84 // Check if any point on shape is inside cubeBb.
85 bool Foam::treeDataPoint::overlaps
88 const treeBoundBox& cubeBb
91 label pointI = (useSubset_ ? pointLabels_[index] : index);
92 return cubeBb.contains(points_[pointI]);
96 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
98 void Foam::treeDataPoint::findNearest
100 const labelUList& indices,
103 scalar& nearestDistSqr,
110 const label index = indices[i];
111 label pointI = (useSubset_ ? pointLabels_[index] : index);
113 const point& pt = points_[pointI];
115 scalar distSqr = magSqr(pt - sample);
117 if (distSqr < nearestDistSqr)
119 nearestDistSqr = distSqr;
127 //- Calculates nearest (to line) point in shape.
128 // Returns point and distance (squared)
129 void Foam::treeDataPoint::findNearest
131 const labelUList& indices,
132 const linePointRef& ln,
134 treeBoundBox& tightest,
141 scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
145 const label index = indices[i];
146 label pointI = (useSubset_ ? pointLabels_[index] : index);
148 const point& shapePt = points_[pointI];
150 if (tightest.contains(shapePt))
152 // Nearest point on line
153 pointHit pHit = ln.nearestDist(shapePt);
154 scalar distSqr = sqr(pHit.distance());
156 if (distSqr < nearestDistSqr)
158 nearestDistSqr = distSqr;
160 linePoint = pHit.rawPoint();
161 nearestPoint = shapePt;
164 point& minPt = tightest.min();
165 minPt = min(ln.start(), ln.end());
166 minPt.x() -= pHit.distance();
167 minPt.y() -= pHit.distance();
168 minPt.z() -= pHit.distance();
171 point& maxPt = tightest.max();
172 maxPt = max(ln.start(), ln.end());
173 maxPt.x() += pHit.distance();
174 maxPt.y() += pHit.distance();
175 maxPt.z() += pHit.distance();
183 // ************************************************************************* //