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

treeDataPoint.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 "treeDataPoint.H"
00030 #include "treeBoundBox.H"
00031 #include "indexedOctree.H"
00032 #include "polyMesh.H"
00033 #include "triangleFuncs.H"
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 defineTypeNameAndDebug(Foam::treeDataPoint, 0);
00038 
00039 
00040 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00041 
00042 // Construct from components
00043 Foam::treeDataPoint::treeDataPoint(const pointField& points)
00044 :
00045     points_(points)
00046 {}
00047 
00048 
00049 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00050 
00051 Foam::pointField Foam::treeDataPoint::points() const
00052 {
00053     return points_;
00054 }
00055 
00056 
00057 //- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
00058 //  Only makes sense for closed surfaces.
00059 Foam::label Foam::treeDataPoint::getVolumeType
00060 (
00061     const indexedOctree<treeDataPoint>& oc,
00062     const point& sample
00063 ) const
00064 {
00065     return indexedOctree<treeDataPoint>::UNKNOWN;
00066 }
00067 
00068 
00069 // Check if any point on shape is inside cubeBb.
00070 bool Foam::treeDataPoint::overlaps
00071 (
00072     const label index,
00073     const treeBoundBox& cubeBb
00074 ) const
00075 {
00076     return cubeBb.contains(points_[index]);
00077 }
00078 
00079 
00080 // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
00081 // nearestPoint.
00082 void Foam::treeDataPoint::findNearest
00083 (
00084     const labelList& indices,
00085     const point& sample,
00086 
00087     scalar& nearestDistSqr,
00088     label& minIndex,
00089     point& nearestPoint
00090 ) const
00091 {
00092     forAll(indices, i)
00093     {
00094         label index = indices[i];
00095 
00096         const point& pt = points_[index];
00097 
00098         scalar distSqr = magSqr(pt - sample);
00099 
00100         if (distSqr < nearestDistSqr)
00101         {
00102             nearestDistSqr = distSqr;
00103             minIndex = index;
00104             nearestPoint = pt;
00105         }
00106     }
00107 }
00108 
00109 
00110 //- Calculates nearest (to line) point in shape.
00111 //  Returns point and distance (squared)
00112 void Foam::treeDataPoint::findNearest
00113 (
00114     const labelList& indices,
00115     const linePointRef& ln,
00116 
00117     treeBoundBox& tightest,
00118     label& minIndex,
00119     point& linePoint,
00120     point& nearestPoint
00121 ) const
00122 {
00123     // Best so far
00124     scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
00125 
00126     forAll(indices, i)
00127     {
00128         label index = indices[i];
00129 
00130         const point& shapePt = points_[index];
00131 
00132         if (tightest.contains(shapePt))
00133         {
00134             // Nearest point on line
00135             pointHit pHit = ln.nearestDist(shapePt);
00136             scalar distSqr = sqr(pHit.distance());
00137 
00138             if (distSqr < nearestDistSqr)
00139             {
00140                 nearestDistSqr = distSqr;
00141                 minIndex = index;
00142                 linePoint = pHit.rawPoint();
00143                 nearestPoint = shapePt;
00144 
00145                 {
00146                     point& minPt = tightest.min();
00147                     minPt = min(ln.start(), ln.end());
00148                     minPt.x() -= pHit.distance();
00149                     minPt.y() -= pHit.distance();
00150                     minPt.z() -= pHit.distance();
00151                 }
00152                 {
00153                     point& maxPt = tightest.max();
00154                     maxPt = max(ln.start(), ln.end());
00155                     maxPt.x() += pHit.distance();
00156                     maxPt.y() += pHit.distance();
00157                     maxPt.z() += pHit.distance();
00158                 }
00159             }
00160         }
00161     }
00162 }
00163 
00164 
00165 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd