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

RangeUtils.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_RANGEUTILS_H
00028 #define OPENMS_KERNEL_RANGEUTILS_H
00029 
00030 #include <functional>
00031 #include <algorithm>
00032 #include <vector>
00033 #include <OpenMS/CONCEPT/Types.h>
00034 
00035 namespace OpenMS 
00036 { 
00085   template <class SpectrumType>
00086   class InRTRange
00087     : std::unary_function<SpectrumType, bool>
00088   {
00089     public:
00097       InRTRange(DoubleReal min, DoubleReal max, bool reverse = false)
00098         : 
00099         min_(min),
00100         max_(max),
00101         reverse_(reverse)
00102       {
00103         
00104       }
00105     
00106       inline bool operator()(const SpectrumType& s) const
00107       {
00108         DoubleReal tmp = s.getRT();
00109         if (reverse_)
00110         {
00111           return ( min_ > tmp || max_ < tmp ); 
00112         }
00113         return ( min_ <= tmp && max_ >= tmp );
00114       }
00115     
00116     protected:
00117       DoubleReal min_, max_;
00118       bool reverse_;
00119   };
00120 
00128   template <class SpectrumType>
00129   class InMSLevelRange
00130     : std::unary_function<SpectrumType, bool>
00131   {
00132     public:
00139       InMSLevelRange(const std::vector<UInt>& levels, bool reverse = false)
00140         : 
00141         levels_(levels),
00142         reverse_(reverse)
00143       {
00144         
00145       }
00146     
00147       inline bool operator()(const SpectrumType& s) const
00148       {
00149         UInt tmp = s.getMSLevel();
00150         if (reverse_)
00151         {
00152           return ( std::find(levels_.begin(), levels_.end(), tmp) == levels_.end() ); 
00153         }
00154         return ( std::find(levels_.begin(), levels_.end(), tmp) != levels_.end() );
00155       }
00156     
00157     protected:
00158       std::vector<UInt> levels_;
00159       bool reverse_;
00160   };
00161 
00169   template <class SpectrumType>
00170   class HasScanMode
00171     : std::unary_function<SpectrumType, bool>
00172   {
00173     public:
00180       HasScanMode(Int mode, bool reverse = false)
00181         : 
00182         mode_(mode),
00183         reverse_(reverse)
00184       {
00185         
00186       }
00187     
00188       inline bool operator()(const SpectrumType& s) const
00189       {
00190         if (reverse_)
00191         {
00192           return s.getInstrumentSettings().getScanMode() != mode_ ; 
00193         }
00194         return s.getInstrumentSettings().getScanMode() == mode_ ; 
00195       }
00196     
00197     protected:
00198       Int mode_;
00199       bool reverse_;
00200   };
00201 
00209   template <class SpectrumType>
00210   class IsEmptySpectrum
00211     : std::unary_function<SpectrumType, bool>
00212   {
00213     public:
00219       IsEmptySpectrum(bool reverse = false)
00220         : reverse_(reverse)
00221       {
00222         
00223       }
00224     
00225       inline bool operator()(const SpectrumType& s) const
00226       {
00227         if (reverse_)
00228         {
00229           return s.size() != 0 ; 
00230         }
00231         return s.size() == 0 ; 
00232       }
00233     
00234     protected:
00235       bool reverse_;
00236   };
00237 
00247   template <class PeakType>
00248   class InMzRange
00249     : std::unary_function<PeakType, bool>
00250   {
00251     public:
00259       InMzRange(DoubleReal min, DoubleReal max, bool reverse = false)
00260         : 
00261         min_(min),
00262         max_(max),
00263         reverse_(reverse)
00264       {
00265         
00266       }
00267     
00268       inline bool operator()(const PeakType& p) const
00269       {
00270         DoubleReal tmp = p.getPosition()[0];
00271         if (reverse_)
00272         {
00273           return ( min_ > tmp || max_ < tmp ); 
00274         }
00275         return ( min_ <= tmp && max_ >= tmp );
00276       }
00277     
00278     protected:
00279       DoubleReal min_, max_;
00280       bool reverse_;
00281   };
00282   
00290   template <class PeakType>
00291   class InIntensityRange
00292     : std::unary_function<PeakType, bool>
00293   {
00294     public:
00302       InIntensityRange(DoubleReal min, DoubleReal max, bool reverse = false)
00303         : 
00304         min_(min),
00305         max_(max),
00306         reverse_(reverse)
00307       {
00308         
00309       }
00310     
00311       inline bool operator()(const PeakType& p) const
00312       {
00313         DoubleReal tmp = p.getIntensity();
00314         if (reverse_)
00315         {
00316           return ( min_ > tmp || max_ < tmp ); 
00317         }
00318         return ( min_ <= tmp && max_ >= tmp );
00319       }
00320     
00321     protected:
00322       DoubleReal min_, max_;
00323       bool reverse_;
00324   };
00325 
00326 } // namespace OpenMS
00327 
00328 #endif // OPENMS_KERNEL_RANGEUTILS_H
00329 
00330 
00331 

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