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

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