1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Stephan Aiche$
25
// $Authors: Marc Sturm $
26
// --------------------------------------------------------------------------
28
#ifndef OPENMS_KERNEL_RANGEMANAGER_H
29
#define OPENMS_KERNEL_RANGEMANAGER_H
31
#include <OpenMS/DATASTRUCTURES/DRange.h>
36
@brief Handles the managment of a position and intensity range.
38
This is needed for all peak and feature container like Spectrum, MSExperiment and FeatureMap.
44
/// Dimension of the position range
45
enum { DIMENSION = D };
46
/// Position range type
47
typedef DRange<D> PositionRangeType;
49
typedef DPosition<D> PositionType;
50
/// Intensity range type
51
typedef DRange<1> IntensityRangeType;
53
/// Default constructor
61
RangeManager(const RangeManager& rhs)
62
: int_range_(rhs.int_range_),
63
pos_range_(rhs.pos_range_)
68
virtual ~RangeManager()
72
/// Assignment operator
73
RangeManager& operator = (const RangeManager& rhs)
75
if (this==&rhs) return *this;
77
int_range_ = rhs.int_range_;
78
pos_range_ = rhs.pos_range_;
84
bool operator == (const RangeManager& rhs) const
87
int_range_ == rhs.int_range_ &&
88
pos_range_ == rhs.pos_range_
93
bool operator != (const RangeManager& rhs) const
95
return !(operator==(rhs));
102
@note The range values are not updated automatically. Call updateRanges() to update the values!
106
/// Returns the minimum position
107
const PositionType& getMin() const
109
return pos_range_.minPosition();
111
/// Returns the maximum position
112
const PositionType& getMax() const
114
return pos_range_.maxPosition();
117
/// Returns the minimum intensity
118
DoubleReal getMinInt() const
120
return int_range_.minPosition()[0];
122
/// Returns the maximum intensity
123
DoubleReal getMaxInt() const
125
return int_range_.maxPosition()[0];
129
@brief Updates minimum and maximum position/intensity.
131
This method is usually implemented by calling clearRanges() and
134
virtual void updateRanges() = 0;
136
/// Resets the ranges
139
int_range_ = IntensityRangeType::empty;
140
pos_range_ = PositionRangeType::empty;
146
/// Intensity range (1-dimensional)
147
IntensityRangeType int_range_;
148
/// Position range (D-dimensional)
149
PositionRangeType pos_range_;
151
/// Updates the range using data points in the iterator range.
152
template <class PeakIteratorType>
153
void updateRanges_(const PeakIteratorType& begin, const PeakIteratorType& end)
156
//prevent invalid range by empty container
162
PositionType min = pos_range_.minPosition();
163
PositionType max = pos_range_.maxPosition();
165
DoubleReal it_min = int_range_.minPosition()[0];
166
DoubleReal it_max = int_range_.maxPosition()[0];
168
for (PeakIteratorType it = begin; it != end; ++it)
171
for (UInt i = 0; i < D; ++i)
173
DoubleReal tmp = it->getPosition()[i];
185
DoubleReal tmp = it->getIntensity();
196
pos_range_.setMin(min);
197
pos_range_.setMax(max);
199
int_range_.setMinX(it_min);
200
int_range_.setMaxX(it_max);
205
} // namespace OpenMS
207
#endif // OPENMS_KERNEL_DRANGE_H