initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / octree / octreeDataEdges.C
blob3974a0b91d149af516107ee646fb229e7a75b9fb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
29 #include "line.H"
30 #include "labelList.H"
31 #include "octree.H"
32 #include "linePointRef.H"
33 #include "pointHit.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
55     edges_(edges),
56     points_(points),
57     edgeLabels_(edgeLabels),
58     allBb_(edgeLabels_.size())
60     // Generate tight fitting bounding box
61     forAll(edgeLabels_, i)
62     {
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);
72     }
76 // Construct as copy
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>&,
97     const point&
98 ) const
100     return octree<octreeDataEdges>::UNKNOWN;
104 bool Foam::octreeDataEdges::overlaps
106     const label index,
107     const treeBoundBox& sampleBb
108 ) const
110     return sampleBb.intersects(allBb_[index]);
114 bool Foam::octreeDataEdges::contains
116     const label,
117     const point&
118 ) const
120     notImplemented
121     (
122         "octreeDataEdges::contains(const label, const point&)"
123     );
124     return false;
128 bool Foam::octreeDataEdges::intersects
130     const label,
131     const point&,
132     const point&,
133     point&
134 ) const
136     notImplemented
137     (
138         "octreeDataEdges::intersects(const label, const point&"
139         ", const point&, point&)"
140     );
141     return false;
145 bool Foam::octreeDataEdges::findTightest
147     const label index,
148     const point& sample,
149     treeBoundBox& tightest
150 ) const
152     // Get nearest and furthest away vertex
153     point myNear, myFar;
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)
165     {
166         // Keep current tightest.
167         return false;
168     }
169     else
170     {
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;
177         return true;
178     }
182 // Determine numerical value of sign of sample compared to shape at index
183 Foam::scalar Foam::octreeDataEdges::calcSign
185     const label,
186     const point&,
187     point& n
188 ) const
190     n = vector::zero;
192     return 1;
196 // Calculate nearest point on/in shapei
197 Foam::scalar Foam::octreeDataEdges::calcNearest
199     const label index,
200     const point& sample,
201     point& nearest
202 ) const
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
217     const label index,
218     const linePointRef& sampleLine,
219     point& sampleLinePt,
220     point& shapePt
221 ) const
223     const edge& e = edges_[edgeLabels_[index]];
225     linePointRef edgeLine(e.line(points_));
227     return edgeLine.nearestDist(sampleLine, shapePt, sampleLinePt);
229     
231 void Foam::octreeDataEdges::write
233     Ostream& os,
234     const label index
235 ) const
237     os << edgeLabels_[index] << " " << allBb_[index];
241 // ************************************************************************* //