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

treeLeaf.H

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 Class
00026     Foam::treeLeaf
00027 
00028 Description
00029     An octree treeLeaf.
00030 
00031 SourceFiles
00032     treeLeaf.C
00033     octreeDataPointTreaLeaf.H       (specialization for points)
00034     octreeDataPointTreeLeaf.C
00035     octreeDataTriSurfaceTreeLeaf.H  (specialization for triSurface)
00036     octreeDataTriSurfaceTreeLeaf.C
00037 
00038 \*---------------------------------------------------------------------------*/
00039 
00040 #ifndef treeLeaf_H
00041 #define treeLeaf_H
00042 
00043 #include "labelList.H"
00044 #include "treeElem.H"
00045 #include "boolList.H"
00046 #include "linePointRef.H"
00047 #include "HashSet.H"
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 namespace Foam
00052 {
00053 
00054 class treeBoundBox;
00055 class Ostream;
00056 
00057 template<class Type> class octree;
00058 template<class Type> class treeLeaf;
00059 
00060 // Forward declaration of friend functions and operators
00061 
00062 template<class Type> Istream& operator>>(Istream&, treeLeaf<Type>&);
00063 template<class Type> Ostream& operator<<(Ostream&, const treeLeaf<Type>&);
00064 
00065 
00066 /*---------------------------------------------------------------------------*\
00067                         Class treeLeafName Declaration
00068 \*---------------------------------------------------------------------------*/
00069 
00070 TemplateName(treeLeaf);
00071 
00072 
00073 /*---------------------------------------------------------------------------*\
00074                            Class treeLeaf Declaration
00075 \*---------------------------------------------------------------------------*/
00076 
00077 template <class Type>
00078 class treeLeaf
00079 :
00080     public treeElem<Type>,
00081     public treeLeafName
00082 {
00083     // Private data
00084 
00085         // Keeps real size (at construction time indices_ might be untrimmed)
00086         label size_;
00087 
00088         // Indices of 'things' whose bb overlaps leaf bb.
00089         labelList indices_;
00090 
00091 
00092     // Private Member Functions
00093 
00094         static void space(Ostream&, const label);
00095 
00096         //- Disallow default bitwise copy construct
00097         treeLeaf(const treeLeaf&);
00098 
00099         //- Disallow default bitwise assignment
00100         void operator=(const treeLeaf&);
00101 
00102 
00103 public:
00104 
00105     // Constructors
00106 
00107         //- Construct with size
00108         treeLeaf(const treeBoundBox& bb, const label size);
00109 
00110         //- Construct from list
00111         treeLeaf(const treeBoundBox& bb, const labelList& indices);
00112 
00113         //- Construct from Istream
00114         treeLeaf(Istream&);
00115 
00116 
00117     // Destructor
00118 
00119         ~treeLeaf();
00120 
00121 
00122     // Member Functions
00123 
00124         // Access
00125 
00126             label size() const
00127             {
00128                 return size_;
00129             }
00130 
00131             const labelList& indices() const
00132             {
00133                 return indices_;
00134             }
00135 
00136         // Edit
00137 
00138             void insert(const label index)
00139             {
00140                 if (size_ >= indices_.size())
00141                 {
00142                     FatalErrorIn
00143                     (
00144                         "treeLeaf<Type>::insert(index)"
00145                     )
00146                         << "overflow"
00147                         << "  size_ :" << size_
00148                         << "  size():" << indices_.size()
00149                         << abort(FatalError);
00150                 }
00151                 indices_[size_++] = index;
00152             }
00153 
00154             void trim()
00155             {
00156                 if (size_ == 0)
00157                 {
00158                     FatalErrorIn
00159                     (
00160                         "treeLeaf<Type>::trim()"
00161                     )
00162                         << "Trying to trim empty leaf: " << endl
00163                         << "  size_ :" << size_
00164                         << "  size():" << indices_.size()
00165                         << abort(FatalError);
00166                 }
00167                 indices_.setSize(size_);
00168             }
00169 
00170             //- Take indices at refineLevel and distribute them to lower levels
00171             treeLeaf<Type>* redistribute
00172             (
00173                 const label,
00174                 octree<Type>&,
00175                 const Type&
00176             );
00177 
00178             label setSubNodeType
00179             (
00180                 const label level,
00181                 octree<Type>& top,
00182                 const Type& shapes
00183             ) const;
00184 
00185         // Search
00186 
00187             //- Get type of sample
00188             label getSampleType
00189             (
00190                 const label level,
00191                 const octree<Type>& top,
00192                 const Type& shapes,
00193                 const point& sample
00194             ) const;
00195 
00196             //- Find index of shape containing sample
00197             label find
00198             (
00199                 const Type& shapes,
00200                 const point& sample
00201             ) const;
00202 
00203             //- Find tightest fitting bounding box in leaf
00204             bool findTightest
00205             (
00206                 const Type& shapes,
00207                 const point& sample,
00208                 treeBoundBox& tightest
00209             ) const;
00210 
00211             //- Find nearest point.
00212             bool findNearest
00213             (
00214                 const Type& shapes,
00215                 const point& sample,
00216                 treeBoundBox& tightest,
00217                 label& tightestI,
00218                 scalar& tightestDist
00219             ) const;
00220 
00221             //- Find nearest shape to line
00222             //  Returns true if found nearer shape and updates nearest and
00223             //  tightest
00224             bool findNearest
00225             (
00226                 const Type& shapes,
00227                 const linePointRef& ln,
00228                 treeBoundBox& tightest,
00229                 label& tightestI,   // index of nearest shape
00230                 point& linePoint,   // nearest point on line
00231                 point& shapePoint   // nearest point on shape
00232             ) const;
00233 
00234             //- Find shapes not outside box. Return true if anything found.
00235             bool findBox
00236             (
00237                 const Type& shapes,
00238                 const boundBox& bb,
00239                 labelHashSet& elements
00240             ) const;
00241 
00242         // Write
00243 
00244             //- Debug: print a leaf
00245             void printLeaf(Ostream&, const label) const;
00246 
00247             //- Debug: Write bb in OBJ format
00248             void writeOBJ
00249             (
00250                 Ostream& os,
00251                 const label level,
00252                 label& vertNo
00253             ) const;
00254 
00255             //- debug:
00256             label countLeaf(Ostream&, const label) const;
00257 
00258 
00259     // IOstream Operators
00260 
00261         friend Istream& operator>> <Type>(Istream&, treeLeaf<Type>&);
00262         friend Ostream& operator<< <Type>(Ostream&, const treeLeaf<Type>&);
00263 };
00264 
00265 
00266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00267 
00268 } // End namespace Foam
00269 
00270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00271 
00272 #ifdef NoRepository
00273 #   include "treeLeaf.C"
00274 #endif
00275 
00276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00277 
00278 #include "octreeDataPointTreeLeaf.H"
00279 #include "octreeDataTriSurfaceTreeLeaf.H"
00280 
00281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00282 
00283 #endif
00284 
00285 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd