OpenMS  2.7.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-2021.
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  RangeManager(RangeManager&&) noexcept = default;
73 
75  virtual ~RangeManager()
76  {}
77 
80  {
81  if (this == &rhs) return *this;
82 
83  int_range_ = rhs.int_range_;
84  pos_range_ = rhs.pos_range_;
85 
86  return *this;
87  }
88 
90  bool operator==(const RangeManager & rhs) const
91  {
92  return int_range_ == rhs.int_range_ &&
93  pos_range_ == rhs.pos_range_;
94  }
95 
97  bool operator!=(const RangeManager & rhs) const
98  {
99  return !(operator==(rhs));
100  }
101 
109 
111  const PositionType & getMin() const
112  {
113  return pos_range_.minPosition();
114  }
115 
117  const PositionType & getMax() const
118  {
119  return pos_range_.maxPosition();
120  }
121 
123  double getMinInt() const
124  {
125  return int_range_.minPosition()[0];
126  }
127 
129  double getMaxInt() const
130  {
131  return int_range_.maxPosition()[0];
132  }
133 
139  virtual void updateRanges() = 0;
140 
142  void clearRanges()
143  {
145  pos_range_ = PositionRangeType::empty;
146  }
147 
149 protected:
154 
156  template <class PeakIteratorType>
157  void updateRanges_(const PeakIteratorType & begin, const PeakIteratorType & end)
158  {
159  //prevent invalid range by empty container
160  if (begin == end)
161  {
162  return;
163  }
164 
165  PositionType min = pos_range_.minPosition();
166  PositionType max = pos_range_.maxPosition();
167 
168  double it_min = int_range_.minPosition()[0];
169  double it_max = int_range_.maxPosition()[0];
170 
171  for (PeakIteratorType it = begin; it != end; ++it)
172  {
173  //update position
174  for (UInt i = 0; i < D; ++i)
175  {
176  double tmp = it->getPosition()[i];
177  if (tmp < min[i])
178  {
179  min[i] = tmp;
180  }
181  if (tmp > max[i])
182  {
183  max[i] = tmp;
184  }
185  }
186 
187  //update intensity
188  double tmp = it->getIntensity();
189  if (tmp < it_min)
190  {
191  it_min = tmp;
192  }
193  if (tmp > it_max)
194  {
195  it_max = tmp;
196  }
197  }
198 
199  pos_range_.setMin(min);
200  pos_range_.setMax(max);
201 
202  int_range_.setMinX(it_min);
203  int_range_.setMaxX(it_max);
204  }
205 
206  };
207 } // namespace OpenMS
208 
Representation of a coordinate in D-dimensional space.
Definition: DPosition.h:54
A D-dimensional half-open interval.
Definition: DRange.h:62
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:130
void setMinX(CoordinateType const c)
Mutator for min_ coordinate of the smaller point.
Definition: DIntervalBase.h:267
void setMaxX(CoordinateType const c)
Mutator for min_ coordinate of the larger point.
Definition: DIntervalBase.h:281
static DIntervalBase const empty
empty instance
Definition: DIntervalBase.h:233
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:124
Handles the management of a position and intensity range.
Definition: RangeManager.h:48
IntensityRangeType int_range_
Intensity range (1-dimensional)
Definition: RangeManager.h:151
void updateRanges_(const PeakIteratorType &begin, const PeakIteratorType &end)
Updates the range using data points in the iterator range.
Definition: RangeManager.h:157
RangeManager()
Default constructor.
Definition: RangeManager.h:60
const PositionType & getMin() const
Returns the minimum position.
Definition: RangeManager.h:111
DPosition< D > PositionType
Position Type.
Definition: RangeManager.h:55
bool operator==(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:90
virtual void updateRanges()=0
Updates minimum and maximum position/intensity.
DRange< 1 > IntensityRangeType
Intensity range type.
Definition: RangeManager.h:57
double getMaxInt() const
Returns the maximum intensity.
Definition: RangeManager.h:129
RangeManager(const RangeManager &rhs)
Copy constructor.
Definition: RangeManager.h:66
void clearRanges()
Resets the ranges.
Definition: RangeManager.h:142
PositionRangeType pos_range_
Position range (D-dimensional)
Definition: RangeManager.h:153
const PositionType & getMax() const
Returns the maximum position.
Definition: RangeManager.h:117
@ DIMENSION
Definition: RangeManager.h:51
DRange< D > PositionRangeType
Position range type.
Definition: RangeManager.h:53
RangeManager & operator=(const RangeManager &rhs)
Assignment operator.
Definition: RangeManager.h:79
bool operator!=(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:97
double getMinInt() const
Returns the minimum intensity.
Definition: RangeManager.h:123
RangeManager(RangeManager &&) noexcept=default
Move constructor.
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47