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 "treeDataEdge.H"
27 #include "indexedOctree.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 defineTypeNameAndDebug(Foam::treeDataEdge, 0);
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 Foam::treeBoundBox Foam::treeDataEdge::calcBb(const label edgeI) const
38 const edge& e = edges_[edgeI];
39 const point& p0 = points_[e[0]];
40 const point& p1 = points_[e[1]];
42 return treeBoundBox(min(p0, p1), max(p0, p1));
46 void Foam::treeDataEdge::update()
50 bbs_.setSize(edgeLabels_.size());
52 forAll(edgeLabels_, i)
54 bbs_[i] = calcBb(edgeLabels_[i]);
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 Foam::treeDataEdge::treeDataEdge
65 const edgeList& edges,
66 const pointField& points,
67 const labelUList& edgeLabels
72 edgeLabels_(edgeLabels),
79 Foam::treeDataEdge::treeDataEdge
82 const edgeList& edges,
83 const pointField& points,
84 const Xfer<labelList>& edgeLabels
89 edgeLabels_(edgeLabels),
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 Foam::pointField Foam::treeDataEdge::shapePoints() const
100 pointField eMids(edgeLabels_.size());
102 forAll(edgeLabels_, i)
104 const edge& e = edges_[edgeLabels_[i]];
106 eMids[i] = e.centre(points_);
112 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
113 // Only makes sense for closed surfaces.
114 Foam::label Foam::treeDataEdge::getVolumeType
116 const indexedOctree<treeDataEdge>& oc,
120 return indexedOctree<treeDataEdge>::UNKNOWN;
124 // Check if any point on shape is inside cubeBb.
125 bool Foam::treeDataEdge::overlaps
128 const treeBoundBox& cubeBb
133 return cubeBb.overlaps(bbs_[index]);
137 return cubeBb.overlaps(calcBb(edgeLabels_[index]));
142 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
144 void Foam::treeDataEdge::findNearest
146 const labelUList& indices,
149 scalar& nearestDistSqr,
156 const label index = indices[i];
158 const edge& e = edges_[edgeLabels_[index]];
160 pointHit nearHit = e.line(points_).nearestDist(sample);
162 scalar distSqr = sqr(nearHit.distance());
164 if (distSqr < nearestDistSqr)
166 nearestDistSqr = distSqr;
168 nearestPoint = nearHit.rawPoint();
174 //- Calculates nearest (to line) point in shape.
175 // Returns point and distance (squared)
176 void Foam::treeDataEdge::findNearest
178 const labelUList& indices,
179 const linePointRef& ln,
181 treeBoundBox& tightest,
188 scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
192 const label index = indices[i];
194 const edge& e = edges_[edgeLabels_[index]];
196 // Note: could do bb test ? Worthwhile?
198 // Nearest point on line
200 scalar dist = e.line(points_).nearestDist(ln, ePoint, lnPt);
201 scalar distSqr = sqr(dist);
203 if (distSqr < nearestDistSqr)
205 nearestDistSqr = distSqr;
208 nearestPoint = ePoint;
211 point& minPt = tightest.min();
212 minPt = min(ln.start(), ln.end());
218 point& maxPt = tightest.max();
219 maxPt = max(ln.start(), ln.end());
229 // ************************************************************************* //