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

RangeManager.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: Stephan Aiche$
00032 // $Authors: Marc Sturm $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_KERNEL_RANGEMANAGER_H
00036 #define OPENMS_KERNEL_RANGEMANAGER_H
00037 
00038 #include <OpenMS/DATASTRUCTURES/DRange.h>
00039 
00040 namespace OpenMS
00041 {
00047   template <UInt D>
00048   class RangeManager
00049   {
00050 public:
00052     enum {DIMENSION = D};
00054     typedef DRange<D> PositionRangeType;
00056     typedef DPosition<D> PositionType;
00058     typedef DRange<1> IntensityRangeType;
00059 
00061     RangeManager() :
00062       int_range_(),
00063       pos_range_()
00064     {}
00065 
00067     RangeManager(const RangeManager & rhs) :
00068       int_range_(rhs.int_range_),
00069       pos_range_(rhs.pos_range_)
00070     {}
00071 
00073     virtual ~RangeManager()
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 int_range_ == rhs.int_range_ &&
00091              pos_range_ == rhs.pos_range_;
00092     }
00093 
00095     bool operator!=(const RangeManager & rhs) const
00096     {
00097       return !(operator==(rhs));
00098     }
00099 
00106 
00107 
00109     const PositionType & getMin() const
00110     {
00111       return pos_range_.minPosition();
00112     }
00113 
00115     const PositionType & getMax() const
00116     {
00117       return pos_range_.maxPosition();
00118     }
00119 
00121     DoubleReal getMinInt() const
00122     {
00123       return int_range_.minPosition()[0];
00124     }
00125 
00127     DoubleReal getMaxInt() const
00128     {
00129       return int_range_.maxPosition()[0];
00130     }
00131 
00137     virtual void updateRanges() = 0;
00138 
00140     void clearRanges()
00141     {
00142       int_range_ = IntensityRangeType::empty;
00143       pos_range_ = PositionRangeType::empty;
00144     }
00145 
00147 protected:
00149     IntensityRangeType int_range_;
00151     PositionRangeType pos_range_;
00152 
00154     template <class PeakIteratorType>
00155     void updateRanges_(const PeakIteratorType & begin, const PeakIteratorType & end)
00156     {
00157       //prevent invalid range by empty container
00158       if (begin == end)
00159       {
00160         return;
00161       }
00162 
00163       PositionType min = pos_range_.minPosition();
00164       PositionType max = pos_range_.maxPosition();
00165 
00166       DoubleReal it_min = int_range_.minPosition()[0];
00167       DoubleReal it_max = int_range_.maxPosition()[0];
00168 
00169       for (PeakIteratorType it = begin; it != end; ++it)
00170       {
00171         //update position
00172         for (UInt i = 0; i < D; ++i)
00173         {
00174           DoubleReal tmp = it->getPosition()[i];
00175           if (tmp < min[i])
00176           {
00177             min[i] = tmp;
00178           }
00179           if (tmp > max[i])
00180           {
00181             max[i] = tmp;
00182           }
00183         }
00184 
00185         //update intensity
00186         DoubleReal tmp = it->getIntensity();
00187         if (tmp < it_min)
00188         {
00189           it_min = tmp;
00190         }
00191         if (tmp > it_max)
00192         {
00193           it_max = tmp;
00194         }
00195       }
00196 
00197       pos_range_.setMin(min);
00198       pos_range_.setMax(max);
00199 
00200       int_range_.setMinX(it_min);
00201       int_range_.setMaxX(it_max);
00202     }
00203 
00204   };
00205 }  // namespace OpenMS
00206 
00207 #endif  // OPENMS_KERNEL_DRANGE_H

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