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