OpenMS
Loading...
Searching...
No Matches
Peak2D.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg$
6// $Authors: Marc Sturm $
7// --------------------------------------------------------------------------
8
9#pragma once
10
14
15#include <iosfwd>
16#include <functional>
17
18namespace OpenMS
19{
20
29 class OPENMS_DLLAPI Peak2D
30 {
31public:
32
35
37 typedef float IntensityType;
39 typedef double CoordinateType;
43
46
49 {
50 RT = 0,
51 MZ = 1,
52 DIMENSION = 2
53 };
54
56 static char const * shortDimensionName(UInt const dim);
58 static char const * shortDimensionNameRT();
60 static char const * shortDimensionNameMZ();
61
63 static char const * fullDimensionName(UInt const dim);
65 static char const * fullDimensionNameRT();
67 static char const * fullDimensionNameMZ();
68
70 static char const * shortDimensionUnit(UInt const dim);
72 static char const * shortDimensionUnitRT();
74 static char const * shortDimensionUnitMZ();
75
77 static char const * fullDimensionUnit(UInt const dim);
79 static char const * fullDimensionUnitRT();
81 static char const * fullDimensionUnitMZ();
82
84
85protected:
86
89
91 static char const * const dimension_name_short_[DIMENSION];
92
94 static char const * const dimension_name_full_[DIMENSION];
95
97 static char const * const dimension_unit_short_[DIMENSION];
98
100 static char const * const dimension_unit_full_[DIMENSION];
101
103
104public:
105
109 Peak2D() = default;
110
112 explicit Peak2D(const PositionType& pos, const IntensityType in) :
113 position_(pos),
114 intensity_(in)
115 {}
116
118 Peak2D(const Peak2D & p) = default;
119
121 Peak2D(Peak2D&&) noexcept = default;
122
124 Peak2D& operator=(const Peak2D& rhs) = default;
125
127 Peak2D& operator=(Peak2D&&) noexcept = default;
136 ~Peak2D() noexcept = default;
137
139
143 IntensityType getIntensity() const
144 {
145 return intensity_;
146 }
147
150 {
151 intensity_ = intensity;
152 }
153
155 PositionType const & getPosition() const
156 {
157 return position_;
158 }
159
162 {
163 return position_;
164 }
165
167 void setPosition(const PositionType & position)
168 {
169 position_ = position;
170 }
171
174 {
175 return position_[MZ];
176 }
177
179 void setMZ(CoordinateType coordinate)
180 {
181 position_[MZ] = coordinate;
182 }
183
186 {
187 return position_[RT];
188 }
189
191 void setRT(CoordinateType coordinate)
192 {
193 position_[RT] = coordinate;
194 }
195
197
199 bool operator==(const Peak2D& rhs) const = default;
200
202 bool operator!=(const Peak2D & rhs) const
203 {
204 return !(operator==(rhs));
205 }
206
215 {
216 bool operator()(const Peak2D & left, const Peak2D & right) const
217 {
218 return left.getIntensity() < right.getIntensity();
219 }
220
221 bool operator()(const Peak2D & left, IntensityType right) const
222 {
223 return left.getIntensity() < right;
224 }
225
226 bool operator()(IntensityType left, const Peak2D & right) const
227 {
228 return left < right.getIntensity();
229 }
230
231 bool operator()(IntensityType left, IntensityType right) const
232 {
233 return left < right;
234 }
235
236 };
237
239 struct RTLess
240 {
241 bool operator()(const Peak2D & left, const Peak2D & right) const
242 {
243 return left.getRT() < right.getRT();
244 }
245
246 bool operator()(const Peak2D & left, CoordinateType right) const
247 {
248 return left.getRT() < right;
249 }
250
251 bool operator()(CoordinateType left, const Peak2D & right) const
252 {
253 return left < right.getRT();
254 }
255
257 {
258 return left < right;
259 }
260
261 };
262
264 struct MZLess
265 {
266 bool operator()(const Peak2D & left, const Peak2D & right) const
267 {
268 return left.getMZ() < right.getMZ();
269 }
270
271 bool operator()(const Peak2D & left, CoordinateType right) const
272 {
273 return left.getMZ() < right;
274 }
275
276 bool operator()(CoordinateType left, const Peak2D & right) const
277 {
278 return left < right.getMZ();
279 }
280
282 {
283 return left < right;
284 }
285
286 };
287
290 {
291 bool operator()(const Peak2D & left, const Peak2D & right) const
292 {
293 return left.getPosition() < right.getPosition();
294 }
295
296 bool operator()(const Peak2D & left, const PositionType & right) const
297 {
298 return left.getPosition() < right;
299 }
300
301 bool operator()(const PositionType & left, const Peak2D & right) const
302 {
303 return left < right.getPosition();
304 }
305
306 bool operator()(const PositionType & left, const PositionType & right) const
307 {
308 return left < right;
309 }
310
311 };
313
314 friend OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Peak2D & point);
315
316protected:
317
319 PositionType position_{};
321 IntensityType intensity_{};
322 };
323
325 OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Peak2D & point);
326
327} // namespace OpenMS
328
329// Hash function specialization for Peak2D
330namespace std
331{
332 template<>
333 struct hash<OpenMS::Peak2D>
334 {
335 std::size_t operator()(const OpenMS::Peak2D& p) const noexcept
336 {
337 std::size_t seed = OpenMS::hash_float(p.getRT());
339 OpenMS::hash_combine(seed, OpenMS::hash_float(p.getIntensity()));
340 return seed;
341 }
342 };
343} // namespace std
344
Representation of a coordinate in D-dimensional space.
Definition DPosition.h:32
A 2-dimensional raw data point or peak.
Definition Peak2D.h:30
CoordinateType getMZ() const
Returns the m/z coordinate (index 1)
Definition Peak2D.h:173
static char const * shortDimensionNameMZ()
Short name of the dimension (abbreviated form)
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition Peak2D.h:179
Peak2D(Peak2D &&) noexcept=default
Move constructor.
static char const * fullDimensionNameMZ()
Full name of the dimension (self-explanatory form)
static char const * fullDimensionUnitRT()
Unit of measurement (self-explanatory form)
PositionType const & getPosition() const
Non-mutable access to the position.
Definition Peak2D.h:155
static char const * shortDimensionUnitRT()
Unit of measurement (abbreviated form)
Peak2D(const PositionType &pos, const IntensityType in)
Member constructor.
Definition Peak2D.h:112
float IntensityType
Intensity type.
Definition Peak2D.h:37
double CoordinateType
Coordinate type (of the position)
Definition Peak2D.h:39
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition Peak2D.h:191
static char const * fullDimensionUnit(UInt const dim)
Unit of measurement (self-explanatory form)
static char const * shortDimensionUnit(UInt const dim)
Unit of measurement (abbreviated form)
static char const * fullDimensionName(UInt const dim)
Full name of the dimension (self-explanatory form)
IntensityType getIntensity() const
Definition Peak2D.h:143
friend std::ostream & operator<<(std::ostream &os, const Peak2D &point)
Print the contents to a stream.
static char const * fullDimensionUnitMZ()
Unit of measurement (self-explanatory form)
static char const * fullDimensionNameRT()
Full name of the dimension (self-explanatory form)
void setIntensity(IntensityType intensity)
Sets data point intensity (height)
Definition Peak2D.h:149
static char const * shortDimensionUnitMZ()
Unit of measurement (abbreviated form)
PositionType & getPosition()
Mutable access to the position.
Definition Peak2D.h:161
void setPosition(const PositionType &position)
Mutable access to the position.
Definition Peak2D.h:167
DimensionDescription
This enum maps the symbolic names of the dimensions to numbers.
Definition Peak2D.h:49
Peak2D()=default
DPosition< 2 > PositionType
Position type.
Definition Peak2D.h:41
bool operator!=(const Peak2D &rhs) const
Equality operator.
Definition Peak2D.h:202
static char const * shortDimensionNameRT()
Short name of the dimension (abbreviated form)
bool operator==(const Peak2D &rhs) const =default
Equality operator.
static char const * shortDimensionName(UInt const dim)
Short name of the dimension (abbreviated form)
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition Peak2D.h:185
Peak2D(const Peak2D &p)=default
Copy constructor.
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
bool operator==(const IDBoostGraph::ProteinGroup &lhs, const IDBoostGraph::ProteinGroup &rhs)
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
void hash_combine(std::size_t &seed, std::size_t value) noexcept
Combine a hash value with additional data using golden ratio mixing.
Definition HashUtils.h:87
std::size_t hash_float(T value) noexcept
Hash for a floating point type (float or double).
Definition HashUtils.h:142
@ RT
RT in seconds.
STL namespace.
Definition Peak2D.h:215
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition Peak2D.h:216
bool operator()(const Peak2D &left, IntensityType right) const
Definition Peak2D.h:221
bool operator()(IntensityType left, const Peak2D &right) const
Definition Peak2D.h:226
bool operator()(IntensityType left, IntensityType right) const
Definition Peak2D.h:231
Comparator by m/z position.
Definition Peak2D.h:265
bool operator()(CoordinateType left, CoordinateType right) const
Definition Peak2D.h:281
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition Peak2D.h:266
bool operator()(CoordinateType left, const Peak2D &right) const
Definition Peak2D.h:276
bool operator()(const Peak2D &left, CoordinateType right) const
Definition Peak2D.h:271
Comparator by position. Lexicographical comparison (first RT then m/z) is done.
Definition Peak2D.h:290
bool operator()(const PositionType &left, const PositionType &right) const
Definition Peak2D.h:306
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition Peak2D.h:291
bool operator()(const Peak2D &left, const PositionType &right) const
Definition Peak2D.h:296
bool operator()(const PositionType &left, const Peak2D &right) const
Definition Peak2D.h:301
Comparator by RT position.
Definition Peak2D.h:240
bool operator()(CoordinateType left, CoordinateType right) const
Definition Peak2D.h:256
bool operator()(const Peak2D &left, const Peak2D &right) const
Definition Peak2D.h:241
bool operator()(CoordinateType left, const Peak2D &right) const
Definition Peak2D.h:251
bool operator()(const Peak2D &left, CoordinateType right) const
Definition Peak2D.h:246
std::size_t operator()(const OpenMS::Peak2D &p) const noexcept
Definition Peak2D.h:335