FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "octreeDataEdges.H"
00027 
00028 #include <OpenFOAM/line.H>
00029 #include <OpenFOAM/labelList.H>
00030 #include "octree.H"
00031 #include <OpenFOAM/linePointRef.H>
00032 #include <OpenFOAM/pointHit.H>
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 defineTypeNameAndDebug(Foam::octreeDataEdges, 0);
00037 
00038 Foam::scalar Foam::octreeDataEdges::tol(1E-6);
00039 
00040 
00041 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00042 
00043 
00044 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00045 
00046 // Construct from selected edges. Bounding box calculated.
00047 Foam::octreeDataEdges::octreeDataEdges
00048 (
00049     const edgeList& edges,
00050     const pointField& points,
00051     const labelList& edgeLabels
00052 )
00053 :
00054     edges_(edges),
00055     points_(points),
00056     edgeLabels_(edgeLabels),
00057     allBb_(edgeLabels_.size())
00058 {
00059     // Generate tight fitting bounding box
00060     forAll(edgeLabels_, i)
00061     {
00062         label edgeI = edgeLabels_[i];
00063 
00064         const edge& e = edges_[edgeI];
00065 
00066         const point& a = points_[e.start()];
00067         const point& b = points_[e.end()];
00068 
00069         allBb_[i].min() = min(a, b);
00070         allBb_[i].max() = max(a, b);
00071     }
00072 }
00073 
00074 
00075 // Construct as copy
00076 Foam::octreeDataEdges::octreeDataEdges(const octreeDataEdges& shapes)
00077 :
00078     edges_(shapes.edges()),
00079     points_(shapes.points()),
00080     edgeLabels_(shapes.edgeLabels()),
00081     allBb_(shapes.allBb())
00082 {}
00083 
00084 
00085 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00086 
00087 Foam::octreeDataEdges::~octreeDataEdges()
00088 {}
00089 
00090 
00091 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00092 
00093 Foam::label Foam::octreeDataEdges::getSampleType
00094 (
00095     const octree<octreeDataEdges>&,
00096     const point&
00097 ) const
00098 {
00099     return octree<octreeDataEdges>::UNKNOWN;
00100 }
00101 
00102 
00103 bool Foam::octreeDataEdges::overlaps
00104 (
00105     const label index,
00106     const treeBoundBox& sampleBb
00107 ) const
00108 {
00109     return sampleBb.overlaps(allBb_[index]);
00110 }
00111 
00112 
00113 bool Foam::octreeDataEdges::contains
00114 (
00115     const label,
00116     const point&
00117 ) const
00118 {
00119     notImplemented
00120     (
00121         "octreeDataEdges::contains(const label, const point&)"
00122     );
00123     return false;
00124 }
00125 
00126 
00127 bool Foam::octreeDataEdges::intersects
00128 (
00129     const label,
00130     const point&,
00131     const point&,
00132     point&
00133 ) const
00134 {
00135     notImplemented
00136     (
00137         "octreeDataEdges::intersects(const label, const point&"
00138         ", const point&, point&)"
00139     );
00140     return false;
00141 }
00142 
00143 
00144 bool Foam::octreeDataEdges::findTightest
00145 (
00146     const label index,
00147     const point& sample,
00148     treeBoundBox& tightest
00149 ) const
00150 {
00151     // Get nearest and furthest away vertex
00152     point myNear, myFar;
00153     allBb_[index].calcExtremities(sample, myNear, myFar);
00154 
00155     const point dist = myFar - sample;
00156     scalar myFarDist = mag(dist);
00157 
00158     point tightestNear, tightestFar;
00159     tightest.calcExtremities(sample, tightestNear, tightestFar);
00160 
00161     scalar tightestFarDist = mag(tightestFar - sample);
00162 
00163     if (tightestFarDist < myFarDist)
00164     {
00165         // Keep current tightest.
00166         return false;
00167     }
00168     else
00169     {
00170         // Construct bb around sample and myFar
00171         const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z())); 
00172 
00173         tightest.min() = sample - dist2;
00174         tightest.max() = sample + dist2;
00175 
00176         return true;
00177     }
00178 }
00179 
00180 
00181 // Determine numerical value of sign of sample compared to shape at index
00182 Foam::scalar Foam::octreeDataEdges::calcSign
00183 (
00184     const label,
00185     const point&,
00186     point& n
00187 ) const
00188 {
00189     n = vector::zero;
00190 
00191     return 1;
00192 }
00193 
00194 
00195 // Calculate nearest point on/in shapei
00196 Foam::scalar Foam::octreeDataEdges::calcNearest
00197 (
00198     const label index,
00199     const point& sample,
00200     point& nearest
00201 ) const
00202 {
00203     const edge& e = edges_[edgeLabels_[index]];
00204 
00205     pointHit nearHit = e.line(points_).nearestDist(sample);
00206 
00207     nearest = nearHit.rawPoint();
00208 
00209     return nearHit.distance();
00210 }
00211 
00212 
00213 // Calculate nearest point on/in shapei
00214 Foam::scalar Foam::octreeDataEdges::calcNearest
00215 (
00216     const label index,
00217     const linePointRef& sampleLine,
00218     point& sampleLinePt,
00219     point& shapePt
00220 ) const
00221 {
00222     const edge& e = edges_[edgeLabels_[index]];
00223 
00224     linePointRef edgeLine(e.line(points_));
00225 
00226     return edgeLine.nearestDist(sampleLine, shapePt, sampleLinePt);
00227 }
00228     
00229 
00230 void Foam::octreeDataEdges::write
00231 (
00232     Ostream& os,
00233     const label index
00234 ) const
00235 {
00236     os << edgeLabels_[index] << " " << allBb_[index];
00237 }
00238 
00239 
00240 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines