1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
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 "octreeDataEdges.H"
29 #include "labelList.H"
31 #include "linePointRef.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(Foam::octreeDataEdges, 0);
38 Foam::scalar Foam::octreeDataEdges::tol(1E-6);
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 // Construct from selected edges. Bounding box calculated.
47 Foam::octreeDataEdges::octreeDataEdges
49 const edgeList& edges,
50 const pointField& points,
51 const labelList& edgeLabels
56 edgeLabels_(edgeLabels),
57 allBb_(edgeLabels_.size())
59 // Generate tight fitting bounding box
60 forAll(edgeLabels_, i)
62 label edgeI = edgeLabels_[i];
64 const edge& e = edges_[edgeI];
66 const point& a = points_[e.start()];
67 const point& b = points_[e.end()];
69 allBb_[i].min() = min(a, b);
70 allBb_[i].max() = max(a, b);
76 Foam::octreeDataEdges::octreeDataEdges(const octreeDataEdges& shapes)
78 edges_(shapes.edges()),
79 points_(shapes.points()),
80 edgeLabels_(shapes.edgeLabels()),
81 allBb_(shapes.allBb())
85 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
87 Foam::octreeDataEdges::~octreeDataEdges()
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 Foam::label Foam::octreeDataEdges::getSampleType
95 const octree<octreeDataEdges>&,
99 return octree<octreeDataEdges>::UNKNOWN;
103 bool Foam::octreeDataEdges::overlaps
106 const treeBoundBox& sampleBb
109 return sampleBb.overlaps(allBb_[index]);
113 bool Foam::octreeDataEdges::contains
121 "octreeDataEdges::contains(const label, const point&)"
127 bool Foam::octreeDataEdges::intersects
137 "octreeDataEdges::intersects(const label, const point&"
138 ", const point&, point&)"
144 bool Foam::octreeDataEdges::findTightest
148 treeBoundBox& tightest
151 // Get nearest and furthest away vertex
153 allBb_[index].calcExtremities(sample, myNear, myFar);
155 const point dist = myFar - sample;
156 scalar myFarDist = mag(dist);
158 point tightestNear, tightestFar;
159 tightest.calcExtremities(sample, tightestNear, tightestFar);
161 scalar tightestFarDist = mag(tightestFar - sample);
163 if (tightestFarDist < myFarDist)
165 // Keep current tightest.
170 // Construct bb around sample and myFar
171 const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
173 tightest.min() = sample - dist2;
174 tightest.max() = sample + dist2;
181 // Determine numerical value of sign of sample compared to shape at index
182 Foam::scalar Foam::octreeDataEdges::calcSign
195 // Calculate nearest point on/in shapei
196 Foam::scalar Foam::octreeDataEdges::calcNearest
203 const edge& e = edges_[edgeLabels_[index]];
205 pointHit nearHit = e.line(points_).nearestDist(sample);
207 nearest = nearHit.rawPoint();
209 return nearHit.distance();
213 // Calculate nearest point on/in shapei
214 Foam::scalar Foam::octreeDataEdges::calcNearest
217 const linePointRef& sampleLine,
222 const edge& e = edges_[edgeLabels_[index]];
224 linePointRef edgeLine(e.line(points_));
226 return edgeLine.nearestDist(sampleLine, shapePt, sampleLinePt);
230 void Foam::octreeDataEdges::write
236 os << edgeLabels_[index] << " " << allBb_[index];
240 // ************************************************************************* //