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

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