Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

DBoundingBox.h (Maintainer: Clemens Groepl)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Clemens Groepl $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_DATASTRUCTURES_DBOUNDINGBOX_H
00028 #define OPENMS_DATASTRUCTURES_DBOUNDINGBOX_H
00029 
00030 #include <OpenMS/DATASTRUCTURES/DIntervalBase.h>
00031 
00032 namespace OpenMS
00033 {
00034 
00042   template <UInt D>
00043   class DBoundingBox
00044     : public Internal::DIntervalBase<D>
00045   {
00046 
00047    public:
00048 
00053 
00054     enum { DIMENSION = D };
00056     typedef Internal::DIntervalBase<D> Base;
00058     typedef typename Base::PositionType PositionType;
00060     typedef typename Base::CoordinateType CoordinateType;
00062 
00063 
00064     // for convenience
00065     using Base::min_;
00066     using Base::max_;
00067 
00070 
00071     DBoundingBox()
00072       : Base()
00073     {
00074     }
00075 
00077     DBoundingBox(const DBoundingBox& rhs)
00078       : Base(rhs)
00079     {
00080     }
00081 
00083     DBoundingBox & operator=(const DBoundingBox& rhs)
00084     {
00085       Base::operator=(rhs);
00086       return *this;
00087     }
00088 
00090     DBoundingBox & operator=(const Base& rhs)
00091     {
00092       Base::operator=(rhs);
00093       return *this;
00094     }
00095 
00097     ~DBoundingBox()
00098     {
00099     }
00100 
00102     DBoundingBox(const PositionType& minimum, const PositionType& maximum )
00103       : Base ( minimum,  maximum )
00104     {
00105     }
00106 
00108 
00111 
00113     void enlarge(const PositionType& p)
00114     {
00115       for ( UInt i = 0; i < DIMENSION; ++i )
00116       {
00117         if ( p[i] < min_[i] ) min_[i] = p[i];
00118         if ( p[i] > max_[i] ) max_[i] = p[i];
00119       }
00120     }
00121 
00123     void enlarge(CoordinateType x, CoordinateType y)
00124     {
00125       enlarge( PositionType(x,y) );
00126     }
00127     //}@
00128 
00131 
00133     bool operator == (const DBoundingBox& rhs) const
00134     {
00135       return Base::operator==(rhs);
00136     }
00137 
00139     bool operator == (const Base& rhs) const
00140     {
00141       return Base::operator==(rhs);
00142     }
00143 
00150     bool encloses(const PositionType& position) const
00151     {
00152       for ( UInt i = 0; i < DIMENSION; ++i )
00153       {
00154         if ( position[i] < min_[i] || position[i] > max_[i] )
00155         {
00156           return false;
00157         }
00158       }
00159       return true;
00160     }
00161 
00163     bool encloses(CoordinateType x, CoordinateType y) const
00164     {
00165       return encloses( PositionType(x,y) );
00166     }
00167 
00171     bool intersects(const DBoundingBox& bounding_box) const
00172     {
00173       for ( UInt i = 0; i < DIMENSION; ++i )
00174       {
00175         if ( bounding_box .min_[i] > max_[i] ) return false;
00176         if ( bounding_box.max_[i] <  min_[i] ) return false;
00177       }
00178       return true;
00179     }
00180 
00182     bool isEmpty() const
00183     {
00184       return *this == Base::empty;
00185     }
00186 
00188 
00189 
00190   };
00191 
00196   template <UInt D>
00197   std::ostream& operator << (std::ostream& os, const DBoundingBox<D>& bounding_box)
00198   {
00199     os << "--DBOUNDINGBOX BEGIN--"<<std::endl;
00200     os << "MIN --> " << bounding_box.min() << std::endl;
00201     os << "MAX --> " << bounding_box.max() << std::endl;
00202     os << "--DBOUNDINGBOX END--"<<std::endl;
00203     return os;
00204   }
00205 
00206 
00207 } // namespace OpenMS
00208 
00209 #endif // OPENMS_KERNEL_DBOUNDINGBOX_H

Generated Tue Apr 1 15:36:33 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1