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

RangeManager.h (Maintainer: Marc Sturm)

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: Marc Sturm $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_KERNEL_RANGEMANAGER_H
00028 #define OPENMS_KERNEL_RANGEMANAGER_H
00029 
00030 #include <OpenMS/DATASTRUCTURES/DRange.h>
00031 
00032 namespace OpenMS
00033 {
00039   template <UInt D>
00040   class RangeManager
00041   {
00042     public:
00044       enum { DIMENSION = D };
00046       typedef DRange<D> PositionRangeType;
00048       typedef DPosition<D> PositionType;
00050       typedef DRange<1> IntensityRangeType;
00052       typedef DoubleReal IntensityType;
00053       
00055       RangeManager()
00056         : int_range_(),
00057         pos_range_()
00058       {
00059         
00060       }
00061 
00063       RangeManager(const RangeManager& rhs)
00064         : int_range_(rhs.int_range_),
00065         pos_range_(rhs.pos_range_)
00066       {
00067         
00068       }
00069       
00071       virtual ~RangeManager()
00072       {
00073         
00074       }
00075   
00077       RangeManager& operator = (const RangeManager& rhs)
00078       {
00079         if (this==&rhs) return *this;
00080         
00081         int_range_ = rhs.int_range_;
00082         pos_range_ = rhs.pos_range_;
00083         
00084         return *this;
00085       }
00086   
00088       bool operator == (const RangeManager& rhs) const
00089       {
00090         return
00091           int_range_ == rhs.int_range_ &&
00092           pos_range_ == rhs.pos_range_
00093           ;       
00094       }
00095       
00097       bool operator != (const RangeManager& rhs) const
00098       {
00099         return !(operator==(rhs));
00100       }
00101 
00102       
00109   
00111       const PositionType& getMin() const  
00112       { 
00113         return pos_range_.min(); 
00114       }
00116       const PositionType& getMax() const 
00117       { 
00118         return pos_range_.max(); 
00119       }
00120   
00122       const IntensityType getMinInt() const 
00123       { 
00124         return int_range_.min()[0]; 
00125       }
00127       const IntensityType getMaxInt() const 
00128       { 
00129         return int_range_.max()[0]; 
00130       }
00131       
00138       virtual void updateRanges() = 0;
00139 
00141       void clearRanges()
00142       {
00143         int_range_ = IntensityRangeType::empty;
00144         pos_range_ = PositionRangeType::empty;
00145       }
00146 
00148 
00149     protected:
00151       IntensityRangeType int_range_;
00153       PositionRangeType pos_range_;
00154       
00156       template <class PeakIteratorType>
00157       void updateRanges_(const PeakIteratorType& begin, const PeakIteratorType& end)
00158       {
00159         PositionType min,max;
00160         IntensityType it_min, it_max;
00161         DoubleReal tmp;
00162         
00163         min = pos_range_.min();
00164         max = pos_range_.max();
00165         
00166         //prevent invalid range by empty container
00167         if (begin==end)
00168         {
00169           return;
00170         }
00171         
00172         it_min = int_range_.min()[0];
00173         it_max = int_range_.max()[0];
00174         
00175         for (PeakIteratorType it = begin; it != end; ++it)
00176         {
00177           //update position
00178           for (UInt i = 0; i < D; ++i)
00179           {
00180             tmp = it->getPosition()[i];
00181             if (tmp < min[i])
00182             {
00183               min[i] = tmp;
00184             }
00185             if (tmp > max[i])
00186             {
00187               max[i] = tmp;
00188             }
00189           }
00190         
00191           //update intensity
00192           tmp = it->getIntensity();
00193           if (tmp < it_min)
00194           {
00195           it_min = tmp;
00196           }
00197           if (tmp > it_max)
00198           {
00199             it_max = tmp;
00200           }
00201         }
00202         
00203         pos_range_.setMin(min);
00204         pos_range_.setMax(max);
00205         
00206         int_range_.setMinX(it_min);
00207         int_range_.setMaxX(it_max);
00208       }
00209       
00210   };  // class
00211   
00212 }  // namespace OpenMS
00213 
00214 #endif  // OPENMS_KERNEL_DRANGE_H

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