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

DBoundingBox.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Clemens Groepl $
00032 // $Authors: $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_DATASTRUCTURES_DBOUNDINGBOX_H
00036 #define OPENMS_DATASTRUCTURES_DBOUNDINGBOX_H
00037 
00038 #include <OpenMS/DATASTRUCTURES/DIntervalBase.h>
00039 
00040 namespace OpenMS
00041 {
00042 
00050   template <UInt D>
00051   class DBoundingBox :
00052     public Internal::DIntervalBase<D>
00053   {
00054 
00055 public:
00056 
00061 
00062     enum {DIMENSION = D};
00064     typedef Internal::DIntervalBase<D> Base;
00066     typedef typename Base::PositionType PositionType;
00068     typedef typename Base::CoordinateType CoordinateType;
00070 
00071 
00072     // for convenience
00073     using Base::min_;
00074     using Base::max_;
00075 
00078 
00079     DBoundingBox() :
00080       Base()
00081     {
00082     }
00083 
00085     DBoundingBox(const DBoundingBox & rhs) :
00086       Base(rhs)
00087     {
00088     }
00089 
00091     DBoundingBox & operator=(const DBoundingBox & rhs)
00092     {
00093       Base::operator=(rhs);
00094       return *this;
00095     }
00096 
00098     DBoundingBox & operator=(const Base & rhs)
00099     {
00100       Base::operator=(rhs);
00101       return *this;
00102     }
00103 
00105     ~DBoundingBox()
00106     {
00107     }
00108 
00110     DBoundingBox(const PositionType & minimum, const PositionType & maximum) :
00111       Base(minimum, maximum)
00112     {
00113     }
00114 
00116 
00119 
00121     void enlarge(const PositionType & p)
00122     {
00123       for (UInt i = 0; i < DIMENSION; ++i)
00124       {
00125         if (p[i] < min_[i]) min_[i] = p[i];
00126         if (p[i] > max_[i]) max_[i] = p[i];
00127       }
00128     }
00129 
00131     void enlarge(CoordinateType x, CoordinateType y)
00132     {
00133       enlarge(PositionType(x, y));
00134     }
00135 
00136     //}@
00137 
00140 
00142     bool operator==(const DBoundingBox & rhs) const
00143     {
00144       return Base::operator==(rhs);
00145     }
00146 
00148     bool operator==(const Base & rhs) const
00149     {
00150       return Base::operator==(rhs);
00151     }
00152 
00159     bool encloses(const PositionType & position) const
00160     {
00161       for (UInt i = 0; i < DIMENSION; ++i)
00162       {
00163         if (position[i] < min_[i] || position[i] > max_[i])
00164         {
00165           return false;
00166         }
00167       }
00168       return true;
00169     }
00170 
00172     bool encloses(CoordinateType x, CoordinateType y) const
00173     {
00174       return encloses(PositionType(x, y));
00175     }
00176 
00180     bool intersects(const DBoundingBox & bounding_box) const
00181     {
00182       for (UInt i = 0; i < DIMENSION; ++i)
00183       {
00184         if (bounding_box.min_[i] > max_[i]) return false;
00185 
00186         if (bounding_box.max_[i] <  min_[i]) return false;
00187       }
00188       return true;
00189     }
00190 
00192     bool isEmpty() const
00193     {
00194       for (UInt i = 0; i != D; i++)
00195       {
00196         if (max_[i] <= min_[i])
00197         {
00198           return true;
00199         }
00200       }
00201       return false;
00202     }
00203 
00205 
00206 
00207   };
00208 
00213   template <UInt D>
00214   std::ostream & operator<<(std::ostream & os, const DBoundingBox<D> & bounding_box)
00215   {
00216     os << "--DBOUNDINGBOX BEGIN--" << std::endl;
00217     os << "MIN --> " << bounding_box.minPosition() << std::endl;
00218     os << "MAX --> " << bounding_box.maxPosition() << std::endl;
00219     os << "--DBOUNDINGBOX END--" << std::endl;
00220     return os;
00221   }
00222 
00223 } // namespace OpenMS
00224 
00225 #endif // OPENMS_KERNEL_DBOUNDINGBOX_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:38 using doxygen 1.7.1