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

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