OpenFOAM logo
Open Source CFD Toolkit

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