OpenMS  2.4.0
RangeManager.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2018.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 
39 namespace OpenMS
40 {
46  template <UInt D>
48  {
49 public:
51  enum {DIMENSION = D};
58 
61  int_range_(),
62  pos_range_()
63  {}
64 
66  RangeManager(const RangeManager & rhs) :
69  {}
70 
72  virtual ~RangeManager()
73  {}
74 
77  {
78  if (this == &rhs) return *this;
79 
80  int_range_ = rhs.int_range_;
81  pos_range_ = rhs.pos_range_;
82 
83  return *this;
84  }
85 
87  bool operator==(const RangeManager & rhs) const
88  {
89  return int_range_ == rhs.int_range_ &&
90  pos_range_ == rhs.pos_range_;
91  }
92 
94  bool operator!=(const RangeManager & rhs) const
95  {
96  return !(operator==(rhs));
97  }
98 
105 
108  const PositionType & getMin() const
109  {
110  return pos_range_.minPosition();
111  }
112 
114  const PositionType & getMax() const
115  {
116  return pos_range_.maxPosition();
117  }
118 
120  double getMinInt() const
121  {
122  return int_range_.minPosition()[0];
123  }
124 
126  double getMaxInt() const
127  {
128  return int_range_.maxPosition()[0];
129  }
130 
136  virtual void updateRanges() = 0;
137 
139  void clearRanges()
140  {
142  pos_range_ = PositionRangeType::empty;
143  }
144 
146 protected:
151 
153  template <class PeakIteratorType>
154  void updateRanges_(const PeakIteratorType & begin, const PeakIteratorType & end)
155  {
156  //prevent invalid range by empty container
157  if (begin == end)
158  {
159  return;
160  }
161 
162  PositionType min = pos_range_.minPosition();
163  PositionType max = pos_range_.maxPosition();
164 
165  double it_min = int_range_.minPosition()[0];
166  double it_max = int_range_.maxPosition()[0];
167 
168  for (PeakIteratorType it = begin; it != end; ++it)
169  {
170  //update position
171  for (UInt i = 0; i < D; ++i)
172  {
173  double tmp = it->getPosition()[i];
174  if (tmp < min[i])
175  {
176  min[i] = tmp;
177  }
178  if (tmp > max[i])
179  {
180  max[i] = tmp;
181  }
182  }
183 
184  //update intensity
185  double tmp = it->getIntensity();
186  if (tmp < it_min)
187  {
188  it_min = tmp;
189  }
190  if (tmp > it_max)
191  {
192  it_max = tmp;
193  }
194  }
195 
196  pos_range_.setMin(min);
197  pos_range_.setMax(max);
198 
199  int_range_.setMinX(it_min);
200  int_range_.setMaxX(it_max);
201  }
202 
203  };
204 } // namespace OpenMS
205 
double getMinInt() const
Returns the minimum intensity.
Definition: RangeManager.h:120
void setMaxX(CoordinateType const c)
Mutator for min_ coordinate of the larger point.
Definition: DIntervalBase.h:278
DPosition< D > PositionType
Position Type.
Definition: RangeManager.h:55
PositionRangeType pos_range_
Position range (D-dimensional)
Definition: RangeManager.h:150
bool operator!=(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:94
bool operator==(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:87
double getMaxInt() const
Returns the maximum intensity.
Definition: RangeManager.h:126
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
const PositionType & getMax() const
Returns the maximum position.
Definition: RangeManager.h:114
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
DRange< D > PositionRangeType
Position range type.
Definition: RangeManager.h:53
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:127
const PositionType & getMin() const
Returns the minimum position.
Definition: RangeManager.h:108
DRange< 1 > IntensityRangeType
Intensity range type.
Definition: RangeManager.h:57
RangeManager & operator=(const RangeManager &rhs)
Assignment operator.
Definition: RangeManager.h:76
void clearRanges()
Resets the ranges.
Definition: RangeManager.h:139
IntensityRangeType int_range_
Intensity range (1-dimensional)
Definition: RangeManager.h:148
A D-dimensional half-open interval.
Definition: DRange.h:60
RangeManager(const RangeManager &rhs)
Copy constructor.
Definition: RangeManager.h:66
void setMinX(CoordinateType const c)
Mutator for min_ coordinate of the smaller point.
Definition: DIntervalBase.h:264
void updateRanges_(const PeakIteratorType &begin, const PeakIteratorType &end)
Updates the range using data points in the iterator range.
Definition: RangeManager.h:154
Handles the management of a position and intensity range.
Definition: RangeManager.h:47
virtual ~RangeManager()
Destructor.
Definition: RangeManager.h:72
static DIntervalBase const empty
empty instance
Definition: DIntervalBase.h:230
virtual void updateRanges()=0
Updates minimum and maximum position/intensity.
Definition: RangeManager.h:51
RangeManager()
Default constructor.
Definition: RangeManager.h:60
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:121