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

triSurfaceSearch.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 "triSurfaceSearch.H"
00027 #include <meshTools/indexedOctree.H>
00028 #include <OpenFOAM/boolList.H>
00029 #include <meshTools/treeDataTriSurface.H>
00030 #include <triSurface/triSurface.H>
00031 #include <OpenFOAM/line.H>
00032 #include <OSspecific/cpuTime.H>
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00040 
00041 const point triSurfaceSearch::greatPoint(GREAT, GREAT, GREAT);
00042 
00043 
00044 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00045 
00046 // Construct from surface. Holds reference!
00047 triSurfaceSearch::triSurfaceSearch(const triSurface& surface)
00048 :
00049     surface_(surface),
00050     treePtr_(NULL)
00051 {
00052     // Random number generator. Bit dodgy since not exactly random ;-)
00053     Random rndGen(65431);
00054 
00055     // Slightly extended bb. Slightly off-centred just so on symmetric
00056     // geometry there are less face/edge aligned items.
00057     treeBoundBox treeBb
00058     (
00059         treeBoundBox(surface_.points(), surface_.meshPoints()).extend
00060         (
00061             rndGen,
00062             1E-4
00063         )
00064     );
00065     treeBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
00066     treeBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
00067 
00068     treePtr_.reset
00069     (
00070         new indexedOctree<treeDataTriSurface>
00071         (
00072             treeDataTriSurface(surface_),
00073             treeBb,
00074             8,      // maxLevel
00075             10,     // leafsize
00076             3.0     // duplicity
00077         )
00078     );
00079 }
00080 
00081 
00082 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00083 
00084 // Determine inside/outside for samples
00085 boolList triSurfaceSearch::calcInside(const pointField& samples) const
00086 {
00087     boolList inside(samples.size());
00088 
00089     forAll(samples, sampleI)
00090     {
00091         const point& sample = samples[sampleI];
00092 
00093         if (!tree().bb().contains(sample))
00094         {
00095             inside[sampleI] = false;
00096         }
00097         else if
00098         (
00099             tree().getVolumeType(sample)
00100          == indexedOctree<treeDataTriSurface>::INSIDE
00101         )
00102         {
00103             inside[sampleI] = true;
00104         }
00105         else
00106         {
00107             inside[sampleI] = false;
00108         }
00109     }
00110     return inside;
00111 }
00112 
00113 
00114 labelList triSurfaceSearch::calcNearestTri
00115 (
00116     const pointField& samples,
00117     const vector& span
00118 ) const
00119 {
00120     labelList nearest(samples.size());
00121 
00122     const scalar nearestDistSqr = 0.25*magSqr(span);
00123 
00124     pointIndexHit hitInfo;
00125 
00126     forAll(samples, sampleI)
00127     {
00128         hitInfo = tree().findNearest(samples[sampleI], nearestDistSqr);
00129 
00130         if (hitInfo.hit())
00131         {
00132             nearest[sampleI] = hitInfo.index();
00133         }
00134         else
00135         {
00136             nearest[sampleI] = -1;
00137         }
00138     }
00139 
00140     return nearest;
00141 }
00142 
00143 
00144 // Nearest point on surface
00145 tmp<pointField> triSurfaceSearch::calcNearest
00146 (
00147     const pointField& samples,
00148     const vector& span
00149 ) const
00150 {
00151     const scalar nearestDistSqr = 0.25*magSqr(span);
00152 
00153     tmp<pointField> tnearest(new pointField(samples.size()));
00154     pointField& nearest = tnearest();
00155 
00156     pointIndexHit hitInfo;
00157 
00158     forAll(samples, sampleI)
00159     {
00160         hitInfo = tree().findNearest(samples[sampleI], nearestDistSqr);
00161 
00162         if (hitInfo.hit())
00163         {
00164             nearest[sampleI] = hitInfo.hitPoint();
00165         }
00166         else
00167         {
00168             nearest[sampleI] = greatPoint;
00169         }
00170     }
00171 
00172     return tnearest;
00173 }
00174 
00175 
00176 pointIndexHit triSurfaceSearch::nearest(const point& pt, const vector& span)
00177  const
00178 {
00179     const scalar nearestDistSqr = 0.25*magSqr(span);
00180 
00181     return tree().findNearest(pt, nearestDistSqr);
00182 }
00183 
00184 
00185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00186 
00187 } // End namespace Foam
00188 
00189 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines