Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2017.
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 #ifndef OPENMS_KERNEL_RANGEMANAGER_H
36 #define OPENMS_KERNEL_RANGEMANAGER_H
37 
39 
40 namespace OpenMS
41 {
47  template <UInt D>
49  {
50 public:
52  enum {DIMENSION = D};
59 
62  int_range_(),
63  pos_range_()
64  {}
65 
67  RangeManager(const RangeManager & rhs) :
70  {}
71 
73  virtual ~RangeManager()
74  {}
75 
78  {
79  if (this == &rhs) return *this;
80 
81  int_range_ = rhs.int_range_;
82  pos_range_ = rhs.pos_range_;
83 
84  return *this;
85  }
86 
88  bool operator==(const RangeManager & rhs) const
89  {
90  return int_range_ == rhs.int_range_ &&
91  pos_range_ == rhs.pos_range_;
92  }
93 
95  bool operator!=(const RangeManager & rhs) const
96  {
97  return !(operator==(rhs));
98  }
99 
106 
109  const PositionType & getMin() const
110  {
111  return pos_range_.minPosition();
112  }
113 
115  const PositionType & getMax() const
116  {
117  return pos_range_.maxPosition();
118  }
119 
121  double getMinInt() const
122  {
123  return int_range_.minPosition()[0];
124  }
125 
127  double getMaxInt() const
128  {
129  return int_range_.maxPosition()[0];
130  }
131 
137  virtual void updateRanges() = 0;
138 
140  void clearRanges()
141  {
143  pos_range_ = PositionRangeType::empty;
144  }
145 
147 protected:
149  IntensityRangeType int_range_;
151  PositionRangeType pos_range_;
152 
154  template <class PeakIteratorType>
155  void updateRanges_(const PeakIteratorType & begin, const PeakIteratorType & end)
156  {
157  //prevent invalid range by empty container
158  if (begin == end)
159  {
160  return;
161  }
162 
163  PositionType min = pos_range_.minPosition();
164  PositionType max = pos_range_.maxPosition();
165 
166  double it_min = int_range_.minPosition()[0];
167  double it_max = int_range_.maxPosition()[0];
168 
169  for (PeakIteratorType it = begin; it != end; ++it)
170  {
171  //update position
172  for (UInt i = 0; i < D; ++i)
173  {
174  double tmp = it->getPosition()[i];
175  if (tmp < min[i])
176  {
177  min[i] = tmp;
178  }
179  if (tmp > max[i])
180  {
181  max[i] = tmp;
182  }
183  }
184 
185  //update intensity
186  double tmp = it->getIntensity();
187  if (tmp < it_min)
188  {
189  it_min = tmp;
190  }
191  if (tmp > it_max)
192  {
193  it_max = tmp;
194  }
195  }
196 
197  pos_range_.setMin(min);
198  pos_range_.setMax(max);
199 
200  int_range_.setMinX(it_min);
201  int_range_.setMaxX(it_max);
202  }
203 
204  };
205 } // namespace OpenMS
206 
207 #endif // OPENMS_KERNEL_DRANGE_H
double getMinInt() const
Returns the minimum intensity.
Definition: RangeManager.h:121
void setMaxX(CoordinateType const c)
Mutator for min_ coordinate of the larger point.
Definition: DIntervalBase.h:279
DPosition< D > PositionType
Position Type.
Definition: RangeManager.h:56
PositionRangeType pos_range_
Position range (D-dimensional)
Definition: RangeManager.h:151
bool operator!=(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:95
bool operator==(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:88
double getMaxInt() const
Returns the maximum intensity.
Definition: RangeManager.h:127
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
const PositionType & getMax() const
Returns the maximum position.
Definition: RangeManager.h:115
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
DRange< D > PositionRangeType
Position range type.
Definition: RangeManager.h:54
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:128
const PositionType & getMin() const
Returns the minimum position.
Definition: RangeManager.h:109
DRange< 1 > IntensityRangeType
Intensity range type.
Definition: RangeManager.h:58
RangeManager & operator=(const RangeManager &rhs)
Assignment operator.
Definition: RangeManager.h:77
void clearRanges()
Resets the ranges.
Definition: RangeManager.h:140
IntensityRangeType int_range_
Intensity range (1-dimensional)
Definition: RangeManager.h:149
A D-dimensional half-open interval.
Definition: DRange.h:61
RangeManager(const RangeManager &rhs)
Copy constructor.
Definition: RangeManager.h:67
void setMinX(CoordinateType const c)
Mutator for min_ coordinate of the smaller point.
Definition: DIntervalBase.h:265
void updateRanges_(const PeakIteratorType &begin, const PeakIteratorType &end)
Updates the range using data points in the iterator range.
Definition: RangeManager.h:155
Handles the management of a position and intensity range.
Definition: RangeManager.h:48
virtual ~RangeManager()
Destructor.
Definition: RangeManager.h:73
static DIntervalBase const empty
empty instance
Definition: DIntervalBase.h:231
virtual void updateRanges()=0
Updates minimum and maximum position/intensity.
Definition: RangeManager.h:52
RangeManager()
Default constructor.
Definition: RangeManager.h:61
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:122

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:03 using doxygen 1.8.13