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

octreeDataTriSurfaceTreeLeaf.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 "octreeDataTriSurfaceTreeLeaf.H"
00030 #include "octreeDataTriSurface.H"
00031 
00032 // * * * * * * * * * * * * * Template Specialisations  * * * * * * * * * * * //
00033 
00034 template<>
00035 bool Foam::treeLeaf<Foam::octreeDataTriSurface>::findNearest
00036 (
00037     const octreeDataTriSurface& shapes,
00038     const point& sample,
00039     treeBoundBox& tightest,
00040     label& tightestI,
00041     scalar& tightestDist
00042 ) const
00043 {
00044     // Some aliases
00045     const treeBoundBoxList& allBb = shapes.allBb();
00046     point& min = tightest.min();
00047     point& max = tightest.max();
00048 
00049     point nearest;
00050 
00051     bool changed = false;
00052     forAll(indices_, i)
00053     {
00054         label faceI = indices_[i];
00055 
00056         // Quick rejection test.
00057         if (tightest.overlaps(allBb[faceI]))
00058         {
00059             // Full calculation
00060             scalar dist = shapes.calcNearest(faceI, sample, nearest);
00061 
00062             if (dist < tightestDist)
00063             {
00064                 // Update bb (centered around sample, span is dist)
00065                 min.x() = sample.x() - dist;
00066                 min.y() = sample.y() - dist;
00067                 min.z() = sample.z() - dist;
00068 
00069                 max.x() = sample.x() + dist;
00070                 max.y() = sample.y() + dist;
00071                 max.z() = sample.z() + dist;
00072 
00073                 tightestI = faceI;
00074                 tightestDist = dist;
00075 
00076                 changed = true;
00077             }
00078         }
00079     }
00080     return changed;
00081 }
00082 
00083 
00084 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd