OpenMS  2.4.0
Peak1D.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-2018.
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/CONCEPT/Types.h>
39 
40 #include <iosfwd>
41 #include <functional>
42 
43 namespace OpenMS
44 {
45 
54  class OPENMS_DLLAPI Peak1D
55  {
56 public:
57 
61  enum {DIMENSION = 1};
63  typedef float IntensityType;
67  typedef double CoordinateType;
69 
73  inline Peak1D() :
74  position_(),
75  intensity_(0)
76  {}
77 
80  position_(a),
81  intensity_(b)
82  {}
83 
85  inline Peak1D(const Peak1D & p) :
86  position_(p.position_),
87  intensity_(p.intensity_)
88  {}
89 
99  {}
100 
102 
106  inline IntensityType getIntensity() const { return intensity_; }
110  inline void setIntensity(IntensityType intensity) { intensity_ = intensity; }
111 
113  inline CoordinateType getMZ() const
114  {
115  return position_[0];
116  }
117 
119  inline void setMZ(CoordinateType mz)
120  {
121  position_[0] = mz;
122  }
123 
125  inline CoordinateType getPos() const
126  {
127  return position_[0];
128  }
129 
131  inline void setPos(CoordinateType pos)
132  {
133  position_[0] = pos;
134  }
135 
137  inline PositionType const & getPosition() const
138  {
139  return position_;
140  }
141 
144  {
145  return position_;
146  }
147 
149  inline void setPosition(PositionType const & position)
150  {
151  position_ = position;
152  }
153 
155 
157  inline Peak1D & operator=(const Peak1D & rhs)
158  {
159  if (this == &rhs) return *this;
160 
161  intensity_ = rhs.intensity_;
162  position_ = rhs.position_;
163 
164  return *this;
165  }
166 
168  inline bool operator==(const Peak1D & rhs) const
169  {
170 #pragma clang diagnostic push
171 #pragma clang diagnostic ignored "-Wfloat-equal"
172  return intensity_ == rhs.intensity_ && position_ == rhs.position_;
173 #pragma clang diagnostic pop
174  }
175 
177  inline bool operator!=(const Peak1D & rhs) const
178  {
179  return !(operator==(rhs));
180  }
181 
186  struct IntensityLess :
189  std::binary_function<Peak1D, Peak1D, bool>
190  {
191  inline bool operator()(Peak1D const & left, Peak1D const & right) const
192  {
193  return left.getIntensity() < right.getIntensity();
194  }
195 
196  inline bool operator()(Peak1D const & left, IntensityType right) const
197  {
198  return left.getIntensity() < right;
199  }
200 
201  inline bool operator()(IntensityType left, Peak1D const & right) const
202  {
203  return left < right.getIntensity();
204  }
205 
206  inline bool operator()(IntensityType left, IntensityType right) const
207  {
208  return left < right;
209  }
210 
211  };
212 
214  struct MZLess :
215  public std::binary_function<Peak1D, Peak1D, bool>
216  {
217  inline bool operator()(const Peak1D & left, const Peak1D & right) const
218  {
219  return left.getMZ() < right.getMZ();
220  }
221 
222  inline bool operator()(Peak1D const & left, CoordinateType right) const
223  {
224  return left.getMZ() < right;
225  }
226 
227  inline bool operator()(CoordinateType left, Peak1D const & right) const
228  {
229  return left < right.getMZ();
230  }
231 
232  inline bool operator()(CoordinateType left, CoordinateType right) const
233  {
234  return left < right;
235  }
236 
237  };
238 
240  struct PositionLess :
241  public std::binary_function<Peak1D, Peak1D, bool>
242  {
243  inline bool operator()(const Peak1D & left, const Peak1D & right) const
244  {
245  return left.getPosition() < right.getPosition();
246  }
247 
248  inline bool operator()(const Peak1D & left, const PositionType & right) const
249  {
250  return left.getPosition() < right;
251  }
252 
253  inline bool operator()(const PositionType & left, const Peak1D & right) const
254  {
255  return left < right.getPosition();
256  }
257 
258  inline bool operator()(const PositionType & left, const PositionType & right) const
259  {
260  return left < right;
261  }
262 
263  };
265 
266 protected:
271  };
272 
274  OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Peak1D & point);
275 
276 } // namespace OpenMS
277 
Peak1D & operator=(const Peak1D &rhs)
Assignment operator.
Definition: Peak1D.h:157
bool operator()(Peak1D const &left, IntensityType right) const
Definition: Peak1D.h:196
bool operator()(Peak1D const &left, CoordinateType right) const
Definition: Peak1D.h:222
PositionType & getPosition()
Mutable access to the position.
Definition: Peak1D.h:143
Size< TNeedle >::Type position(const PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:561
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:113
bool operator()(const Peak1D &left, const PositionType &right) const
Definition: Peak1D.h:248
bool operator()(const Peak1D &left, const Peak1D &right) const
Definition: Peak1D.h:217
PositionType const & getPosition() const
Non-mutable access to the position.
Definition: Peak1D.h:137
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
bool operator()(IntensityType left, IntensityType right) const
Definition: Peak1D.h:206
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool operator==(const Peak1D &rhs) const
Equality operator.
Definition: Peak1D.h:168
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:119
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:110
bool operator!=(const Peak1D &rhs) const
Equality operator.
Definition: Peak1D.h:177
Comparator by position. As this class has dimension 1, this is basically an alias for MZLess...
Definition: Peak1D.h:240
bool operator()(const PositionType &left, const Peak1D &right) const
Definition: Peak1D.h:253
bool operator()(const PositionType &left, const PositionType &right) const
Definition: Peak1D.h:258
Peak1D()
Definition: Peak1D.h:73
double CoordinateType
Coordinate type.
Definition: Peak1D.h:67
bool operator()(Peak1D const &left, Peak1D const &right) const
Definition: Peak1D.h:191
PositionType position_
The data point position.
Definition: Peak1D.h:268
void setPosition(PositionType const &position)
Mutable access to the position.
Definition: Peak1D.h:149
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
CoordinateType getPos() const
Alias for getMZ()
Definition: Peak1D.h:125
Peak1D(const Peak1D &p)
Copy constructor.
Definition: Peak1D.h:85
Comparator by m/z position.
Definition: Peak1D.h:214
bool operator()(const Peak1D &left, const Peak1D &right) const
Definition: Peak1D.h:243
bool operator()(CoordinateType left, CoordinateType right) const
Definition: Peak1D.h:232
Peak1D(PositionType a, IntensityType b)
construct with position and intensity
Definition: Peak1D.h:79
bool operator()(CoordinateType left, Peak1D const &right) const
Definition: Peak1D.h:227
float IntensityType
Intensity type.
Definition: Peak1D.h:63
IntensityType intensity_
The data point intensity.
Definition: Peak1D.h:270
void setPos(CoordinateType pos)
Alias for setMZ()
Definition: Peak1D.h:131
bool operator()(IntensityType left, Peak1D const &right) const
Definition: Peak1D.h:201
DPosition< 1 > PositionType
Position type.
Definition: Peak1D.h:65
IntensityType getIntensity() const
Definition: Peak1D.h:108
~Peak1D()
Destructor.
Definition: Peak1D.h:98