Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / meshTools / octree / octreeDataEdges.C
blob7ce31e4fb51d8379a10cebf6457814ea42d5a9d4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
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
19     for more details.
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"
28 #include "line.H"
29 #include "labelList.H"
30 #include "octree.H"
31 #include "linePointRef.H"
32 #include "pointHit.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
54     edges_(edges),
55     points_(points),
56     edgeLabels_(edgeLabels),
57     allBb_(edgeLabels_.size())
59     // Generate tight fitting bounding box
60     forAll(edgeLabels_, i)
61     {
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);
71     }
75 // Construct as copy
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>&,
96     const point&
97 ) const
99     return octree<octreeDataEdges>::UNKNOWN;
103 bool Foam::octreeDataEdges::overlaps
105     const label index,
106     const treeBoundBox& sampleBb
107 ) const
109     return sampleBb.overlaps(allBb_[index]);
113 bool Foam::octreeDataEdges::contains
115     const label,
116     const point&
117 ) const
119     notImplemented
120     (
121         "octreeDataEdges::contains(const label, const point&)"
122     );
123     return false;
127 bool Foam::octreeDataEdges::intersects
129     const label,
130     const point&,
131     const point&,
132     point&
133 ) const
135     notImplemented
136     (
137         "octreeDataEdges::intersects(const label, const point&"
138         ", const point&, point&)"
139     );
140     return false;
144 bool Foam::octreeDataEdges::findTightest
146     const label index,
147     const point& sample,
148     treeBoundBox& tightest
149 ) const
151     // Get nearest and furthest away vertex
152     point myNear, myFar;
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)
164     {
165         // Keep current tightest.
166         return false;
167     }
168     else
169     {
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;
176         return true;
177     }
181 // Determine numerical value of sign of sample compared to shape at index
182 Foam::scalar Foam::octreeDataEdges::calcSign
184     const label,
185     const point&,
186     point& n
187 ) const
189     n = vector::zero;
191     return 1;
195 // Calculate nearest point on/in shapei
196 Foam::scalar Foam::octreeDataEdges::calcNearest
198     const label index,
199     const point& sample,
200     point& nearest
201 ) const
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
216     const label index,
217     const linePointRef& sampleLine,
218     point& sampleLinePt,
219     point& shapePt
220 ) const
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
232     Ostream& os,
233     const label index
234 ) const
236     os << edgeLabels_[index] << " " << allBb_[index];
240 // ************************************************************************* //