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

octreeDataCell.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 "octreeDataCell.H"
00030 #include "polyMesh.H"
00031 #include "primitiveMesh.H"
00032 #include "treeNode.H"
00033 
00034 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00035 
00036 // Construct from components
00037 Foam::octreeDataCell::octreeDataCell
00038 (
00039     const polyMesh& mesh,
00040     const labelList& cellLabels,
00041     const treeBoundBoxList& bbs
00042 )
00043 :
00044     mesh_(mesh),
00045     cellLabels_(cellLabels),
00046     bbs_(bbs)
00047 {}
00048 
00049 
00050 // Construct from mesh (assumes all cells)
00051 Foam::octreeDataCell::octreeDataCell
00052 (
00053     const polyMesh& mesh
00054 )
00055 :
00056     mesh_(mesh),
00057     cellLabels_(mesh_.nCells()),
00058     bbs_
00059     (
00060         mesh_.nCells(),
00061         treeBoundBox::invertedBox
00062     )
00063 {
00064     // Set one-one indexing
00065     for (label i=0; i < mesh_.nCells(); i++)
00066     {
00067         cellLabels_[i] = i;
00068     }
00069 
00070     const pointField& points = mesh_.points();
00071     const faceList& faces = mesh_.faces();
00072     const cellList& cells = mesh_.cells();
00073 
00074     forAll(cells, celli)
00075     {
00076         const labelList& facesi = cells[celli];
00077 
00078         forAll(facesi, facei)
00079         {
00080             const labelList& pointsi = faces[facesi[facei]];
00081 
00082             forAll(pointsi, pointi)
00083             {
00084                 const point& p = points[pointsi[pointi]];
00085                 
00086                 bbs_[celli].min() = min(bbs_[celli].min(), p);
00087                 bbs_[celli].max() = max(bbs_[celli].max(), p);
00088             }
00089         }
00090     }
00091 }
00092 
00093 
00094 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00095 
00096 Foam::label Foam::octreeDataCell::getSampleType
00097 (
00098     octree<octreeDataCell>&,
00099     const point&
00100 ) const
00101 {
00102     return octree<octreeDataCell>::UNKNOWN;
00103 }
00104 
00105 
00106 bool Foam::octreeDataCell::overlaps
00107 (
00108     const label index,
00109     const treeBoundBox& cubeBb
00110 ) const
00111 {
00112     return cubeBb.overlaps(bbs_[index]);
00113 }
00114 
00115 
00116 bool Foam::octreeDataCell::contains
00117 (
00118     const label index,
00119     const point& sample
00120 ) const
00121 {
00122     return mesh_.pointInCell(sample, cellLabels_[index]);
00123 }
00124 
00125 
00126 bool Foam::octreeDataCell::intersects
00127 (
00128     const label,
00129     const point&,
00130     const point&,
00131     point&
00132 ) const
00133 {
00134     //Hack: don't know what to do here.
00135 
00136     notImplemented
00137     (
00138         "octreeDataCell::intersects(const label, const point&,"
00139         "const point&, point&)"
00140     );
00141 
00142     return false;
00143 }
00144 
00145 
00146 bool Foam::octreeDataCell::findTightest
00147 (
00148     const label index,
00149     const point& sample,
00150     treeBoundBox& tightest
00151 ) const
00152 {
00153 
00154     // get nearest and furthest away vertex
00155     point myNear, myFar;
00156     bbs_[index].calcExtremities(sample, myNear, myFar);
00157 
00158     const point dist = myFar - sample;
00159     scalar myFarDist = mag(dist);
00160 
00161     point tightestNear, tightestFar;
00162     tightest.calcExtremities(sample, tightestNear, tightestFar);
00163 
00164     scalar tightestFarDist = mag(tightestFar - sample);
00165 
00166     if (tightestFarDist < myFarDist)
00167     {
00168         // Keep current tightest.
00169         return false;
00170     }
00171     else
00172     {
00173         // Construct bb around sample and myFar
00174         const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z())); 
00175 
00176         tightest.min() = sample - dist2;
00177         tightest.max() = sample + dist2;
00178 
00179         return true;
00180     }
00181 }
00182 
00183 
00184 // Determine numerical value of sign of sample compared to shape at index
00185 Foam::scalar Foam::octreeDataCell::calcSign
00186 (
00187     const label,
00188     const point&,
00189     vector& n
00190 ) const
00191 {
00192     n = vector::zero;
00193 
00194     return GREAT;
00195 }
00196 
00197 
00198 // Calculate nearest point on/in shapei
00199 Foam::scalar Foam::octreeDataCell::calcNearest
00200 (
00201     const label index,
00202     const point& sample,
00203     point& nearest
00204 ) const
00205 {
00206     nearest = mesh_.cellCentres()[cellLabels_[index]];
00207 
00208     return mag(nearest - sample);
00209 }
00210 
00211 
00212 // Calculate nearest point on/in shapei
00213 Foam::scalar Foam::octreeDataCell::calcNearest
00214 (
00215     const label index,
00216     const linePointRef& ln,
00217     point& linePt,
00218     point& shapePt
00219 ) const
00220 {
00221     notImplemented
00222     (
00223         "octreeDataCell::calcNearest(const label, const linePointRef&"
00224         ", point& linePt, point&)"
00225     );
00226     return GREAT;
00227 }
00228     
00229 
00230 void Foam::octreeDataCell::write
00231 (
00232     Ostream& os,
00233     const label index
00234 ) const
00235 {
00236     os << cellLabels_[index] << " " << bbs_[index];
00237 }
00238 
00239 
00240 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd