1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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
25 \*---------------------------------------------------------------------------*/
27 #include "octreeDataEdges.H"
30 #include "labelList.H"
32 #include "linePointRef.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(Foam::octreeDataEdges, 0);
39 Foam::scalar Foam::octreeDataEdges::tol(1E-6);
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 // Construct from selected edges. Bounding box calculated.
48 Foam::octreeDataEdges::octreeDataEdges
50 const edgeList& edges,
51 const pointField& points,
52 const labelList& edgeLabels
57 edgeLabels_(edgeLabels),
58 allBb_(edgeLabels_.size())
60 // Generate tight fitting bounding box
61 forAll(edgeLabels_, i)
63 label edgeI = edgeLabels_[i];
65 const edge& e = edges_[edgeI];
67 const point& a = points_[e.start()];
68 const point& b = points_[e.end()];
70 allBb_[i].min() = min(a, b);
71 allBb_[i].max() = max(a, b);
77 Foam::octreeDataEdges::octreeDataEdges(const octreeDataEdges& shapes)
79 edges_(shapes.edges()),
80 points_(shapes.points()),
81 edgeLabels_(shapes.edgeLabels()),
82 allBb_(shapes.allBb())
86 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
88 Foam::octreeDataEdges::~octreeDataEdges()
92 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 Foam::label Foam::octreeDataEdges::getSampleType
96 const octree<octreeDataEdges>&,
100 return octree<octreeDataEdges>::UNKNOWN;
104 bool Foam::octreeDataEdges::overlaps
107 const treeBoundBox& sampleBb
110 return sampleBb.overlaps(allBb_[index]);
114 bool Foam::octreeDataEdges::contains
122 "octreeDataEdges::contains(const label, const point&)"
128 bool Foam::octreeDataEdges::intersects
138 "octreeDataEdges::intersects(const label, const point&"
139 ", const point&, point&)"
145 bool Foam::octreeDataEdges::findTightest
149 treeBoundBox& tightest
152 // Get nearest and furthest away vertex
154 allBb_[index].calcExtremities(sample, myNear, myFar);
156 const point dist = myFar - sample;
157 scalar myFarDist = mag(dist);
159 point tightestNear, tightestFar;
160 tightest.calcExtremities(sample, tightestNear, tightestFar);
162 scalar tightestFarDist = mag(tightestFar - sample);
164 if (tightestFarDist < myFarDist)
166 // Keep current tightest.
171 // Construct bb around sample and myFar
172 const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
174 tightest.min() = sample - dist2;
175 tightest.max() = sample + dist2;
182 // Determine numerical value of sign of sample compared to shape at index
183 Foam::scalar Foam::octreeDataEdges::calcSign
196 // Calculate nearest point on/in shapei
197 Foam::scalar Foam::octreeDataEdges::calcNearest
204 const edge& e = edges_[edgeLabels_[index]];
206 pointHit nearHit = e.line(points_).nearestDist(sample);
208 nearest = nearHit.rawPoint();
210 return nearHit.distance();
214 // Calculate nearest point on/in shapei
215 Foam::scalar Foam::octreeDataEdges::calcNearest
218 const linePointRef& sampleLine,
223 const edge& e = edges_[edgeLabels_[index]];
225 linePointRef edgeLine(e.line(points_));
227 return edgeLine.nearestDist(sampleLine, shapePt, sampleLinePt);
231 void Foam::octreeDataEdges::write
237 os << edgeLabels_[index] << " " << allBb_[index];
241 // ************************************************************************* //