OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

treeBoundBox.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-2007 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     treeBoundBox
00027 
00028 Description
00029     Standard boundBox + extra functionality for use in octree.
00030 
00031 SourceFiles
00032     treeBoundBoxI.H
00033     treeBoundBox.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef treeBoundBox_H
00038 #define treeBoundBox_H
00039 
00040 #include "boundBox.H"
00041 #include "direction.H"
00042 #include "pointField.H"
00043 #include "edgeList.H"
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 namespace Foam
00048 {
00049 
00050 class Random;
00051 
00052 /*---------------------------------------------------------------------------*\
00053                            Class treeBoundBox Declaration
00054 \*---------------------------------------------------------------------------*/
00055 
00056 class treeBoundBox
00057 :
00058     public boundBox
00059 {
00060 
00061 public:
00062 
00063     // Static data members
00064 
00065         static treeBoundBox greatBox;
00066 
00067         // Bits used for octant coding
00068         static const direction RIGHTHALF   = 0x1 << 0;
00069         static const direction TOPHALF     = 0x1 << 1;
00070         static const direction FRONTHALF   = 0x1 << 2;
00071 
00072         // Bits used for face coding
00073         static const direction NOFACE     = 0;
00074         static const direction LEFTBIT    = 0x1 << 0;
00075         static const direction RIGHTBIT   = 0x1 << 1;
00076         static const direction BELOWBIT   = 0x1 << 2;
00077         static const direction ABOVEBIT   = 0x1 << 3;
00078         static const direction BEHINDBIT  = 0x1 << 4;
00079         static const direction INFRONTBIT = 0x1 << 5;
00080 
00081         //- Face on which neighbour is
00082         static direction neighbourFaceBits(const label&);
00083 
00084 
00085     // Constructors
00086 
00087         //- Construct null setting points to zero
00088         inline treeBoundBox();
00089 
00090         //- Construct from components
00091         inline treeBoundBox(const point& min, const point& max);
00092 
00093         //- Construct from components
00094         inline treeBoundBox(const boundBox& bb);
00095 
00096         //- Construct as the bounding box of the given pointField. Local
00097         //  processor domain only (no reduce as in boundBox)
00098         treeBoundBox(const pointField& points);
00099 
00100         //- Construct from Istream
00101         treeBoundBox(Istream&);
00102 
00103 
00104     // Member functions
00105 
00106         // Access
00107 
00108             //- Smallest of length,height,width
00109             scalar minDim() const;
00110 
00111             //- Largest of length,height,width
00112             scalar maxDim() const;
00113 
00114             //- Average of length,height,width
00115             scalar avgDim() const;
00116 
00117             //- Typical dimension length,height,width
00118             scalar typDim() const;
00119 
00120             //- vertex coordinates
00121             pointField points() const;
00122 
00123             //- edges expressed in terms of points()
00124             edgeList edges() const;
00125 
00126 
00127         // Check
00128 
00129             //- Calculates midpoint
00130             point mid() const;
00131 
00132             //- Sub box given by octant number. Midpoint calculated.
00133             treeBoundBox subBbox(const direction) const;
00134 
00135             //- Sub box given by octant number. Midpoint provided.
00136             treeBoundBox subBbox(const point& mid, const direction) const;
00137 
00138             //- Returns octant number given point. Midpoint calculated.
00139             inline direction subOctant
00140             (
00141                 const point& sample
00142             ) const;
00143 
00144             //- Returns octant number given point. Midpoint provided.
00145             static inline direction subOctant
00146             (
00147                 const point& mid,
00148                 const point& sample
00149             );
00150 
00151             //- Returns octant number given point. Midpoint calculated.
00152             //  onEdge set if sample on edge of subOctant
00153             inline direction subOctant
00154             (
00155                 const point& mid,
00156                 bool& onEdge
00157             ) const;
00158 
00159             //- Returns octant number given point. Midpoint provided.
00160             //  onEdge set if sample on edge of subOctant
00161             static inline direction subOctant
00162             (
00163                 const point& mid,
00164                 const point& sample,
00165                 bool& onEdge
00166             );
00167 
00168             //- Returns octant number given intersection. Midpoint provided.
00169             //  onEdge set if sample on edge of subOctant. If onEdge
00170             // the direction vector determines which octant to use
00171             // (acc. to which octant the sample would be if it were moved 
00172             //  along dir)
00173             static inline direction subOctant
00174             (
00175                 const point& mid,
00176                 const vector& dir,
00177                 const point& sample,
00178                 bool& onEdge
00179             );
00180 
00181             //- Intersects other boundingbox?
00182             inline bool intersects(const treeBoundBox&) const;
00183 
00184             //- Intersects segment; set point to intersection position,
00185             //  return true if intersection found.
00186             // (intPt argument used during calculation even if not intersecting)
00187             bool intersects(const point&, const point&, point& intPt) const;
00188 
00189             //- fully contains bb
00190             bool contains(const treeBoundBox& bb) const;
00191 
00192             //- Contains point? (inside or on edge)
00193             inline bool contains(const point&) const;
00194 
00195             //- Contains point? (only inside)
00196             bool containsNarrow(const point&) const;
00197 
00198             //- Contains point inside or
00199             //  on edge and moving in direction dir would cause it to go
00200             //  inside.
00201             bool contains(const vector& dir, const point&) const;
00202 
00203             //- Position of point relative to bb
00204             direction posBits(const point&) const;
00205 
00206             //- Calculate nearest and furthest (to sample) vertex coords of
00207             //  bounding box
00208             void calcExtremities
00209             (
00210                 const point& sample,
00211                 point& nearest,
00212                 point& furthest
00213             ) const;
00214 
00215             //- Returns distance sample to furthest away corner.
00216             scalar maxDist(const point& sample) const;
00217 
00218             //- Compare distance to point with other bounding box
00219             //  return:
00220             //  -1 : all vertices of my bounding box are nearer than any of
00221             //       other
00222             //  +1 : all vertices of my bounding box are further away than
00223             //       any of other
00224             //   0 : none of the above.
00225             label distanceCmp(const point&, const treeBoundBox& other) const;
00226 
00227             //- Return slightly wider bounding box
00228             //  Extends all dimensions with s*span*Random::scalar01()
00229             inline treeBoundBox extend(Random&, const scalar s) const;
00230 
00231     // Friend Operators
00232 
00233         friend bool operator==(const treeBoundBox&, const treeBoundBox&);
00234         friend bool operator!=(const treeBoundBox&, const treeBoundBox&);
00235 
00236 
00237     // IOstream operator
00238 
00239         friend Istream& operator>>(Istream&, treeBoundBox&);
00240 };
00241 
00242 
00243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00244 
00245 } // End namespace Foam
00246 
00247 #include "treeBoundBoxI.H"
00248 
00249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00250 
00251 #endif
00252 
00253 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd