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

boundBox.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::boundBox
00027 
00028 Description
00029     A bounding box defined in terms of the points at its extremities.
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #ifndef boundBox_H
00034 #define boundBox_H
00035 
00036 #include "pointField.H"
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 namespace Foam
00041 {
00042 
00043 // Forward declaration of friend functions and operators
00044 
00045 class boundBox;
00046 template<class T> class tmp;
00047 
00048 Ostream& operator<<(Ostream& os, const boundBox& b);
00049 
00050 
00051 /*---------------------------------------------------------------------------*\
00052                           Class boundBox Declaration
00053 \*---------------------------------------------------------------------------*/
00054 
00055 class boundBox
00056 {
00057     // Private data
00058 
00059         //- Minimum and maximum describing the bounding box
00060         point min_, max_;
00061 
00062     // Private Member Functions
00063 
00064         //- Calculate the bounding box from the given pointField.
00065         //  Does parallel communication (doReduce = true)
00066         void calculate(const pointField&, const bool doReduce = true);
00067 
00068 public:
00069 
00070     // Static data members
00071 
00072         //- The great value used for greatBox and invertedBox
00073         static const scalar great;
00074 
00075         //- A very large boundBox: min/max == -/+ VGREAT
00076         static const boundBox greatBox;
00077 
00078         //- A very large inverted boundBox: min/max == +/- VGREAT
00079         static const boundBox invertedBox;
00080 
00081 
00082     // Constructors
00083 
00084         //- Construct null, setting points to zero
00085         boundBox()
00086         :
00087             min_(point::zero),
00088             max_(point::zero)
00089         {}
00090 
00091         //- Construct from components
00092         boundBox(const point& min, const point& max)
00093         :
00094             min_(min),
00095             max_(max)
00096         {}
00097 
00098         //- Construct as the bounding box of the given pointField.
00099         //  Does parallel communication (doReduce = true)
00100         boundBox(const pointField&, const bool doReduce = true);
00101 
00102         //- Construct as the bounding box of the given temporary pointField.
00103         //  Does parallel communication (doReduce = true)
00104         boundBox(const tmp<pointField>&, const bool doReduce = true);
00105 
00106         //- Construct from Istream
00107         boundBox(Istream&);
00108 
00109 
00110     // Member functions
00111 
00112         // Access
00113 
00114             //- Minimum describing the bounding box
00115             const point& min() const
00116             {
00117                 return min_;
00118             }
00119 
00120             //- Maximum describing the bounding box
00121             const point& max() const
00122             {
00123                 return max_;
00124             }
00125 
00126             //- Minimum describing the bounding box, non-const access
00127             point& min()
00128             {
00129                 return min_;
00130             }
00131 
00132             //- Maximum describing the bounding box, non-const access
00133             point& max()
00134             {
00135                 return max_;
00136             }
00137 
00138             //- The midpoint of the bounding box
00139             point midpoint() const
00140             {
00141                 return 0.5 * (max_ + min_);
00142             }
00143 
00144             //- The bounding box span (from minimum to maximum)
00145             vector span() const
00146             {
00147                 return (max_ - min_);
00148             }
00149 
00150             //- The magnitude of the bounding box span
00151             scalar mag() const
00152             {
00153                 return ::Foam::mag(max_ - min_);
00154             }
00155 
00156             //- Smallest length/height/width dimension
00157             scalar minDim() const
00158             {
00159                 return cmptMin(span());
00160             }
00161 
00162             //- Largest length/height/width dimension
00163             scalar maxDim() const
00164             {
00165                 return cmptMax(span());
00166             }
00167 
00168             //- Average length/height/width dimension
00169             scalar avgDim() const
00170             {
00171                 return cmptAv(span());
00172             }
00173 
00174 
00175         // Query
00176 
00177             //- Overlaps/touches boundingBox?
00178             bool overlaps(const boundBox& bb) const
00179             {
00180                 return
00181                 (
00182                     bb.max_.x() >= min_.x() && bb.min_.x() <= max_.x()
00183                  && bb.max_.y() >= min_.y() && bb.min_.y() <= max_.y()
00184                  && bb.max_.z() >= min_.z() && bb.min_.z() <= max_.z()
00185                 );
00186             }
00187 
00188             //- Contains point? (inside or on edge)
00189             bool contains(const point& pt) const
00190             {
00191                 return
00192                 (
00193                     pt.x() >= min_.x() && pt.x() <= max_.x()
00194                  && pt.y() >= min_.y() && pt.y() <= max_.y()
00195                  && pt.z() >= min_.z() && pt.z() <= max_.z()
00196                 );
00197             }
00198 
00199             //- Contains point? (inside only)
00200             bool containsInside(const point& pt) const
00201             {
00202                 return
00203                 (
00204                     pt.x() > min_.x() && pt.x() < max_.x()
00205                  && pt.y() > min_.y() && pt.y() < max_.y()
00206                  && pt.z() > min_.z() && pt.z() < max_.z()
00207                 );
00208             }
00209 
00210 
00211     // Friend Operators
00212 
00213         friend bool operator==(const boundBox& a, const boundBox& b)
00214         {
00215             return (a.min_ == b.min_) && (a.max_ == b.max_);
00216         }
00217 
00218         friend bool operator!=(const boundBox& a, const boundBox& b)
00219         {
00220             return !(a == b);
00221         }
00222 
00223 
00224     // IOstream operator
00225 
00226         friend Istream& operator>>(Istream& is, boundBox&);
00227         friend Ostream& operator<<(Ostream& os, const boundBox&);
00228 };
00229 
00230 
00231 //- Data associated with boundBox type are contiguous
00232 template<>
00233 inline bool contiguous<boundBox>() {return contiguous<point>();}
00234 
00235 
00236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00237 
00238 } // End namespace Foam
00239 
00240 // #include "boundBoxI.H"
00241 
00242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00243 
00244 #endif
00245 
00246 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd