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

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