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
25 \*---------------------------------------------------------------------------*/
27 #include "treeDataEdge.H"
28 #include "indexedOctree.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::treeDataEdge, 0);
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 Foam::treeBoundBox Foam::treeDataEdge::calcBb(const label edgeI) const
39 const edge& e = edges_[edgeI];
40 const point& p0 = points_[e[0]];
41 const point& p1 = points_[e[1]];
43 return treeBoundBox(min(p0, p1), max(p0, p1));
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 // Construct from components
50 Foam::treeDataEdge::treeDataEdge
53 const edgeList& edges,
54 const pointField& points,
55 const labelList& edgeLabels
60 edgeLabels_(edgeLabels),
65 bbs_.setSize(edgeLabels_.size());
67 forAll(edgeLabels_, i)
69 bbs_[i] = calcBb(edgeLabels_[i]);
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 Foam::pointField Foam::treeDataEdge::points() const
79 pointField eMids(edgeLabels_.size());
81 forAll(edgeLabels_, i)
83 const edge& e = edges_[edgeLabels_[i]];
85 eMids[i] = e.centre(points_);
91 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
92 // Only makes sense for closed surfaces.
93 Foam::label Foam::treeDataEdge::getVolumeType
95 const indexedOctree<treeDataEdge>& oc,
99 return indexedOctree<treeDataEdge>::UNKNOWN;
103 // Check if any point on shape is inside cubeBb.
104 bool Foam::treeDataEdge::overlaps
107 const treeBoundBox& cubeBb
112 return cubeBb.overlaps(bbs_[index]);
116 return cubeBb.overlaps(calcBb(edgeLabels_[index]));
121 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
123 void Foam::treeDataEdge::findNearest
125 const labelList& indices,
128 scalar& nearestDistSqr,
135 label index = indices[i];
137 const edge& e = edges_[index];
139 pointHit nearHit = e.line(points_).nearestDist(sample);
141 scalar distSqr = sqr(nearHit.distance());
143 if (distSqr < nearestDistSqr)
145 nearestDistSqr = distSqr;
147 nearestPoint = nearHit.rawPoint();
153 //- Calculates nearest (to line) point in shape.
154 // Returns point and distance (squared)
155 void Foam::treeDataEdge::findNearest
157 const labelList& indices,
158 const linePointRef& ln,
160 treeBoundBox& tightest,
167 scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
171 label index = indices[i];
173 const edge& e = edges_[index];
175 // Note: could do bb test ? Worthwhile?
177 // Nearest point on line
179 scalar dist = e.line(points_).nearestDist(ln, ePoint, lnPt);
180 scalar distSqr = sqr(dist);
182 if (distSqr < nearestDistSqr)
184 nearestDistSqr = distSqr;
187 nearestPoint = ePoint;
190 point& minPt = tightest.min();
191 minPt = min(ln.start(), ln.end());
197 point& maxPt = tightest.max();
198 maxPt = max(ln.start(), ln.end());
208 // ************************************************************************* //