OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

octreeDataEdges.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "octreeDataEdges.H"
00028 
00029 #include "line.H"
00030 #include "labelList.H"
00031 #include "octree.H"
00032 #include "linePointRef.H"
00033 #include "pointHit.H"
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 defineTypeNameAndDebug(Foam::octreeDataEdges, 0);
00038 
00039 Foam::scalar Foam::octreeDataEdges::tol(1E-6);
00040 
00041 
00042 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00043 
00044 
00045 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00046 
00047 // Construct from selected edges. Bounding box calculated.
00048 Foam::octreeDataEdges::octreeDataEdges
00049 (
00050     const edgeList& edges,
00051     const pointField& points,
00052     const labelList& edgeLabels
00053 )
00054 :
00055     edges_(edges),
00056     points_(points),
00057     edgeLabels_(edgeLabels),
00058     allBb_(edgeLabels_.size())
00059 {
00060     // Generate tight fitting bounding box
00061     forAll(edgeLabels_, i)
00062     {
00063         label edgeI = edgeLabels_[i];
00064 
00065         const edge& e = edges_[edgeI];
00066 
00067         const point& a = points_[e.start()];
00068         const point& b = points_[e.end()];
00069 
00070         allBb_[i].min() = min(a, b);
00071         allBb_[i].max() = max(a, b);
00072     }
00073 }
00074 
00075 
00076 // Construct as copy
00077 Foam::octreeDataEdges::octreeDataEdges(const octreeDataEdges& shapes)
00078 :
00079     edges_(shapes.edges()),
00080     points_(shapes.points()),
00081     edgeLabels_(shapes.edgeLabels()),
00082     allBb_(shapes.allBb())
00083 {}
00084 
00085 
00086 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00087 
00088 Foam::octreeDataEdges::~octreeDataEdges()
00089 {}
00090 
00091 
00092 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00093 
00094 Foam::label Foam::octreeDataEdges::getSampleType
00095 (
00096     const octree<octreeDataEdges>&,
00097     const point&
00098 ) const
00099 {
00100     return octree<octreeDataEdges>::UNKNOWN;
00101 }
00102 
00103 
00104 bool Foam::octreeDataEdges::overlaps
00105 (
00106     const label index,
00107     const treeBoundBox& sampleBb
00108 ) const
00109 {
00110     return sampleBb.overlaps(allBb_[index]);
00111 }
00112 
00113 
00114 bool Foam::octreeDataEdges::contains
00115 (
00116     const label,
00117     const point&
00118 ) const
00119 {
00120     notImplemented
00121     (
00122         "octreeDataEdges::contains(const label, const point&)"
00123     );
00124     return false;
00125 }
00126 
00127 
00128 bool Foam::octreeDataEdges::intersects
00129 (
00130     const label,
00131     const point&,
00132     const point&,
00133     point&
00134 ) const
00135 {
00136     notImplemented
00137     (
00138         "octreeDataEdges::intersects(const label, const point&"
00139         ", const point&, point&)"
00140     );
00141     return false;
00142 }
00143 
00144 
00145 bool Foam::octreeDataEdges::findTightest
00146 (
00147     const label index,
00148     const point& sample,
00149     treeBoundBox& tightest
00150 ) const
00151 {
00152     // Get nearest and furthest away vertex
00153     point myNear, myFar;
00154     allBb_[index].calcExtremities(sample, myNear, myFar);
00155 
00156     const point dist = myFar - sample;
00157     scalar myFarDist = mag(dist);
00158 
00159     point tightestNear, tightestFar;
00160     tightest.calcExtremities(sample, tightestNear, tightestFar);
00161 
00162     scalar tightestFarDist = mag(tightestFar - sample);
00163 
00164     if (tightestFarDist < myFarDist)
00165     {
00166         // Keep current tightest.
00167         return false;
00168     }
00169     else
00170     {
00171         // Construct bb around sample and myFar
00172         const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z())); 
00173 
00174         tightest.min() = sample - dist2;
00175         tightest.max() = sample + dist2;
00176 
00177         return true;
00178     }
00179 }
00180 
00181 
00182 // Determine numerical value of sign of sample compared to shape at index
00183 Foam::scalar Foam::octreeDataEdges::calcSign
00184 (
00185     const label,
00186     const point&,
00187     point& n
00188 ) const
00189 {
00190     n = vector::zero;
00191 
00192     return 1;
00193 }
00194 
00195 
00196 // Calculate nearest point on/in shapei
00197 Foam::scalar Foam::octreeDataEdges::calcNearest
00198 (
00199     const label index,
00200     const point& sample,
00201     point& nearest
00202 ) const
00203 {
00204     const edge& e = edges_[edgeLabels_[index]];
00205 
00206     pointHit nearHit = e.line(points_).nearestDist(sample);
00207 
00208     nearest = nearHit.rawPoint();
00209 
00210     return nearHit.distance();
00211 }
00212 
00213 
00214 // Calculate nearest point on/in shapei
00215 Foam::scalar Foam::octreeDataEdges::calcNearest
00216 (
00217     const label index,
00218     const linePointRef& sampleLine,
00219     point& sampleLinePt,
00220     point& shapePt
00221 ) const
00222 {
00223     const edge& e = edges_[edgeLabels_[index]];
00224 
00225     linePointRef edgeLine(e.line(points_));
00226 
00227     return edgeLine.nearestDist(sampleLine, shapePt, sampleLinePt);
00228 }
00229     
00230 
00231 void Foam::octreeDataEdges::write
00232 (
00233     Ostream& os,
00234     const label index
00235 ) const
00236 {
00237     os << edgeLabels_[index] << " " << allBb_[index];
00238 }
00239 
00240 
00241 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd