1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 "treeDataEdge.H"
30 #include "indexedOctree.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 Foam::treeBoundBox Foam::treeDataEdge::calcBb(const label edgeI) const
40 const edge& e = edges_[edgeI];
41 const point& p0 = points_[e[0]];
42 const point& p1 = points_[e[1]];
44 return treeBoundBox(min(p0, p1), max(p0, p1));
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 // Construct from components
51 Foam::treeDataEdge::treeDataEdge
54 const edgeList& edges,
55 const pointField& points,
56 const labelList& edgeLabels
61 edgeLabels_(edgeLabels),
66 bbs_.setSize(edgeLabels_.size());
68 forAll(edgeLabels_, i)
70 bbs_[i] = calcBb(edgeLabels_[i]);
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 Foam::pointField Foam::treeDataEdge::points() const
80 pointField eMids(edgeLabels_.size());
82 forAll(edgeLabels_, i)
84 const edge& e = edges_[edgeLabels_[i]];
86 eMids[i] = e.centre(points_);
92 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
93 // Only makes sense for closed surfaces.
94 Foam::label Foam::treeDataEdge::getVolumeType
96 const indexedOctree<treeDataEdge>& oc,
100 return indexedOctree<treeDataEdge>::UNKNOWN;
104 // Check if any point on shape is inside cubeBb.
105 bool Foam::treeDataEdge::overlaps
108 const treeBoundBox& cubeBb
113 return cubeBb.intersects(bbs_[index]);
117 return cubeBb.intersects(calcBb(edgeLabels_[index]));
122 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
124 void Foam::treeDataEdge::findNearest
126 const labelList& indices,
129 scalar& nearestDistSqr,
136 label index = indices[i];
138 const edge& e = edges_[index];
140 pointHit nearHit = e.line(points_).nearestDist(sample);
142 scalar distSqr = sqr(nearHit.distance());
144 if (distSqr < nearestDistSqr)
146 nearestDistSqr = distSqr;
148 nearestPoint = nearHit.rawPoint();
154 //- Calculates nearest (to line) point in shape.
155 // Returns point and distance (squared)
156 void Foam::treeDataEdge::findNearest
158 const labelList& indices,
159 const linePointRef& ln,
161 treeBoundBox& tightest,
168 scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
172 label index = indices[i];
174 const edge& e = edges_[index];
176 // Note: could do bb test ? Worthwhile?
178 // Nearest point on line
180 scalar dist = e.line(points_).nearestDist(ln, ePoint, lnPt);
181 scalar distSqr = sqr(dist);
183 if (distSqr < nearestDistSqr)
185 nearestDistSqr = distSqr;
188 nearestPoint = ePoint;
191 point& minPt = tightest.min();
192 minPt = min(ln.start(), ln.end());
198 point& maxPt = tightest.max();
199 maxPt = max(ln.start(), ln.end());
209 // ************************************************************************* //