1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 // Construct from components
49 Foam::treeDataEdge::treeDataEdge
52 const edgeList& edges,
53 const pointField& points,
54 const labelList& edgeLabels
59 edgeLabels_(edgeLabels),
64 bbs_.setSize(edgeLabels_.size());
66 forAll(edgeLabels_, i)
68 bbs_[i] = calcBb(edgeLabels_[i]);
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 Foam::pointField Foam::treeDataEdge::points() const
78 pointField eMids(edgeLabels_.size());
80 forAll(edgeLabels_, i)
82 const edge& e = edges_[edgeLabels_[i]];
84 eMids[i] = e.centre(points_);
90 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
91 // Only makes sense for closed surfaces.
92 Foam::label Foam::treeDataEdge::getVolumeType
94 const indexedOctree<treeDataEdge>& oc,
98 return indexedOctree<treeDataEdge>::UNKNOWN;
102 // Check if any point on shape is inside cubeBb.
103 bool Foam::treeDataEdge::overlaps
106 const treeBoundBox& cubeBb
111 return cubeBb.overlaps(bbs_[index]);
115 return cubeBb.overlaps(calcBb(edgeLabels_[index]));
120 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
122 void Foam::treeDataEdge::findNearest
124 const labelList& indices,
127 scalar& nearestDistSqr,
134 label index = indices[i];
136 const edge& e = edges_[index];
138 pointHit nearHit = e.line(points_).nearestDist(sample);
140 scalar distSqr = sqr(nearHit.distance());
142 if (distSqr < nearestDistSqr)
144 nearestDistSqr = distSqr;
146 nearestPoint = nearHit.rawPoint();
152 //- Calculates nearest (to line) point in shape.
153 // Returns point and distance (squared)
154 void Foam::treeDataEdge::findNearest
156 const labelList& indices,
157 const linePointRef& ln,
159 treeBoundBox& tightest,
166 scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
170 label index = indices[i];
172 const edge& e = edges_[index];
174 // Note: could do bb test ? Worthwhile?
176 // Nearest point on line
178 scalar dist = e.line(points_).nearestDist(ln, ePoint, lnPt);
179 scalar distSqr = sqr(dist);
181 if (distSqr < nearestDistSqr)
183 nearestDistSqr = distSqr;
186 nearestPoint = ePoint;
189 point& minPt = tightest.min();
190 minPt = min(ln.start(), ln.end());
196 point& maxPt = tightest.max();
197 maxPt = max(ln.start(), ln.end());
207 // ************************************************************************* //