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

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