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

octreeDataPointTreeLeaf.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 Description
00025 
00026 \*---------------------------------------------------------------------------*/
00027 
00028 //#include <meshTools/octreeDataPointTreeLeaf.H>
00029 #include <meshTools/octreeDataPoint.H>
00030 #include <meshTools/treeLeaf.H>
00031 
00032 // * * * * * * * * * * * * * Template Specialisations  * * * * * * * * * * * //
00033 
00034 template<>
00035 Foam::label Foam::treeLeaf<Foam::octreeDataPoint>::find
00036 (
00037     const octreeDataPoint& shapes,
00038     const point& sample
00039 ) const
00040 {
00041     notImplemented
00042     (
00043         "Foam::treeLeaf<Foam::octreeDataPoint>::find("
00044         "const octreeDataPoint& shapes,"
00045         "const point& sample"
00046     );
00047 
00048     return false;
00049 }
00050 
00051 
00052 template<>
00053 bool Foam::treeLeaf<Foam::octreeDataPoint>::findNearest
00054 (
00055     const octreeDataPoint& shapes,
00056     const point& sample,
00057     treeBoundBox& tightest,
00058     label& tightestI,
00059     scalar& tightestDist
00060 ) const
00061 {
00062     // Some aliases
00063     const pointField& points = shapes.points();
00064     point& tMin = tightest.min();
00065     point& tMax = tightest.max();
00066 
00067     scalar minDist2 = sqr(tightestDist);
00068 
00069     label minIndex = -1;
00070     forAll(indices_, i)
00071     {
00072         label pointi = indices_[i];
00073         scalar dist = magSqr(points[pointi] - sample);
00074 
00075         if (dist < minDist2)
00076         {
00077             minDist2 = dist;
00078             minIndex = pointi;
00079         }
00080     }
00081 
00082     if (minIndex != -1)
00083     {
00084         tightestDist = sqrt(minDist2);
00085     
00086         // New nearer. Update 'tightest' bounding box
00087         tMin.x() = sample.x() - tightestDist;
00088         tMin.y() = sample.y() - tightestDist;
00089         tMin.z() = sample.z() - tightestDist;
00090 
00091         tMax.x() = sample.x() + tightestDist;
00092         tMax.y() = sample.y() + tightestDist;
00093         tMax.z() = sample.z() + tightestDist;
00094 
00095         tightestI = minIndex;
00096 
00097         return true;
00098     }
00099     else
00100     {
00101         // New no nearer so nothing changed
00102         return false;
00103     }
00104 }
00105 
00106 
00107 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines