| OpenMS 2.5.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-2020.
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
37 #include <OpenMS/DATASTRUCTURES/DRange.h>
38
39 namespace OpenMS
40 {
46 template <UInt D>
47 class RangeManager
48 {
49 public:
51 enum {DIMENSION = D};
53 typedef DRange<D> PositionRangeType;
55 typedef DPosition<D> PositionType;
57 typedef DRange<1> IntensityRangeType;
58
60 RangeManager() :
61 int_range_(),
62 pos_range_()
63 {}
64
66 RangeManager(const RangeManager & rhs) :
67 int_range_(rhs.int_range_),
68 pos_range_(rhs.pos_range_)
69 {}
70
72 RangeManager(RangeManager&&) noexcept = default;
73
75 virtual ~RangeManager()
76 {}
77
79 RangeManager & operator=(const RangeManager & rhs)
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
108
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 {
144 int_range_ = IntensityRangeType::empty;
145 pos_range_ = PositionRangeType::empty;
146 }
147
149 protected:
151 IntensityRangeType int_range_;
153 PositionRangeType pos_range_;
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
OpenMS::RangeManager::getMin
const PositionType & getMin() const
Returns the minimum position.
Definition: RangeManager.h:111
OpenMS::Internal::DIntervalBase::setMinX
void setMinX(CoordinateType const c)
Mutator for min_ coordinate of the smaller point.
Definition: DIntervalBase.h:267
OpenMS::RangeManager::PositionType
DPosition< D > PositionType
Position Type.
Definition: RangeManager.h:55
OpenMS::RangeManager::clearRanges
void clearRanges()
Resets the ranges.
Definition: RangeManager.h:142
DRange.h
OpenMS::RangeManager
Handles the management of a position and intensity range.
Definition: RangeManager.h:47
OpenMS::RangeManager::IntensityRangeType
DRange< 1 > IntensityRangeType
Intensity range type.
Definition: RangeManager.h:57
OpenMS::RangeManager::RangeManager
RangeManager(const RangeManager &rhs)
Copy constructor.
Definition: RangeManager.h:66
OpenMS::RangeManager::RangeManager
RangeManager()
Default constructor.
Definition: RangeManager.h:60
OpenMS::RangeManager::getMinInt
double getMinInt() const
Returns the minimum intensity.
Definition: RangeManager.h:123
OpenMS::RangeManager::getMax
const PositionType & getMax() const
Returns the maximum position.
Definition: RangeManager.h:117
OpenMS::RangeManager::int_range_
IntensityRangeType int_range_
Intensity range (1-dimensional)
Definition: RangeManager.h:151
OpenMS::Internal::DIntervalBase::maxPosition
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:130
OpenMS::RangeManager::updateRanges
virtual void updateRanges()=0
Updates minimum and maximum position/intensity.
OpenMS::RangeManager::operator==
bool operator==(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:90
OpenMS::Internal::DIntervalBase::setMaxX
void setMaxX(CoordinateType const c)
Mutator for min_ coordinate of the larger point.
Definition: DIntervalBase.h:281
OpenMS::RangeManager::getMaxInt
double getMaxInt() const
Returns the maximum intensity.
Definition: RangeManager.h:129
OpenMS::RangeManager::pos_range_
PositionRangeType pos_range_
Position range (D-dimensional)
Definition: RangeManager.h:153
OpenMS::RangeManager::updateRanges_
void updateRanges_(const PeakIteratorType &begin, const PeakIteratorType &end)
Updates the range using data points in the iterator range.
Definition: RangeManager.h:157
OpenMS::RangeManager::operator=
RangeManager & operator=(const RangeManager &rhs)
Assignment operator.
Definition: RangeManager.h:79
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::DRange
A D-dimensional half-open interval.
Definition: DRange.h:60
OpenMS::RangeManager::PositionRangeType
DRange< D > PositionRangeType
Position range type.
Definition: RangeManager.h:53
OpenMS::RangeManager::DIMENSION
Definition: RangeManager.h:51
OpenMS::Internal::DIntervalBase::minPosition
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:124
OpenMS::RangeManager::operator!=
bool operator!=(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:97
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::DPosition< D >
OpenMS::Internal::DIntervalBase::empty
static DIntervalBase const empty
empty instance
Definition: DIntervalBase.h:233