OpenMS
ContinuousWaveletTransform.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Eva Lange $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/KERNEL/Peak1D.h>
12 
13 #include <vector>
14 
15 namespace OpenMS
16 {
20  class OPENMS_DLLAPI ContinuousWaveletTransform
21  {
22 public:
24  typedef std::vector<Peak1D>::const_iterator PeakConstIterator;
25 
26 
29  scale_(0),
30  spacing_(0),
31  signal_length_(0),
32  end_left_padding_(0),
33  begin_right_padding_(0)
34  {}
35 
38  {}
39 
41  inline const std::vector<Peak1D> & getSignal() const
42  {
43  return signal_;
44  }
45 
47  inline std::vector<Peak1D> & getSignal()
48  {
49  return signal_;
50  }
51 
53  inline void setSignal(const std::vector<Peak1D> & signal)
54  {
55  signal_ = signal;
56  }
57 
59  inline const std::vector<double> & getWavelet() const
60  {
61  return wavelet_;
62  }
63 
65  inline std::vector<double> & getWavelet()
66  {
67  return wavelet_;
68  }
69 
71  inline void setWavelet(const std::vector<double> & wavelet)
72  {
73  wavelet_ = wavelet;
74  }
75 
76  // Non-mutable access to the scale of the wavelet
77  inline double getScale() const
78  {
79  return scale_;
80  }
81 
83  inline double & getScale()
84  {
85  return scale_;
86  }
87 
89  inline void setScale(double scale)
90  {
91  scale_ = scale;
92  }
93 
94  // Non-mutable access to the spacing of raw data
95  inline double getSpacing() const
96  {
97  return spacing_;
98  }
99 
101  inline double & getSpacing()
102  {
103  return spacing_;
104  }
105 
107  inline void setSpacing(double spacing)
108  {
109  spacing_ = spacing;
110  }
111 
114  {
115  return end_left_padding_;
116  }
117 
120  {
121  return end_left_padding_;
122  }
123 
125  inline void setLeftPaddingIndex(const SignedSize end_left_padding)
126  {
127  end_left_padding_ = end_left_padding;
128  }
129 
132  {
133  return begin_right_padding_;
134  }
135 
138  {
139  return begin_right_padding_;
140  }
141 
143  inline void setRightPaddingIndex(const SignedSize begin_right_padding)
144  {
145  begin_right_padding_ = begin_right_padding;
146  }
147 
150  {
151  return signal_length_;
152  }
153 
156  {
157  return signal_length_;
158  }
159 
161  inline void setSignalLength(const SignedSize signal_length)
162  {
163  signal_length_ = signal_length;
164  }
165 
167  inline int getSize() const
168  {
169  return (int) signal_.size();
170  }
171 
175  virtual void init(double scale, double spacing);
176 
177 
179  inline double operator[](unsigned int i)
180  {
181  return signal_[i].getIntensity();
182  }
183 
184  inline double operator[](unsigned int i) const
185  {
186  return signal_[i].getIntensity();
187  }
188 
189 protected:
191  std::vector<Peak1D> signal_;
192 
194  std::vector<double> wavelet_;
195 
197  double scale_;
198  double spacing_;
200 
206 
207  template <typename InputPeakIterator>
208  double getInterpolatedValue_(double x, InputPeakIterator it_left)
209  {
210  // Interpolate between the point to the left and the point to the right.
211  double left_position = it_left->getMZ();
212  double right_position = (it_left + 1)->getMZ();
213  double d = (x - left_position) / (right_position - left_position);
214 
215  return (it_left + 1)->getIntensity() * d + it_left->getIntensity() * (1 - d);
216  }
217 
218  };
219 
220 } //namespace OpenMS
221 
This class is the base class of the continuous wavelet transformation.
Definition: ContinuousWaveletTransform.h:21
double getInterpolatedValue_(double x, InputPeakIterator it_left)
Definition: ContinuousWaveletTransform.h:208
SignedSize getSignalLength() const
Non-mutable access to signal length [end_left_padding,begin_right_padding].
Definition: ContinuousWaveletTransform.h:149
void setSignal(const std::vector< Peak1D > &signal)
Mutable access to the wavelet transform of the signal.
Definition: ContinuousWaveletTransform.h:53
double scale_
Spacing and scale of the wavelet and length of the signal.
Definition: ContinuousWaveletTransform.h:197
SignedSize & getLeftPaddingIndex()
Mutable access to the position where the signal starts.
Definition: ContinuousWaveletTransform.h:119
std::vector< double > wavelet_
The pre-tabulated wavelet used for the transform.
Definition: ContinuousWaveletTransform.h:194
virtual ~ContinuousWaveletTransform()
Destructor.
Definition: ContinuousWaveletTransform.h:37
SignedSize end_left_padding_
Definition: ContinuousWaveletTransform.h:204
double & getSpacing()
Mutable access to the spacing of raw data.
Definition: ContinuousWaveletTransform.h:101
const std::vector< double > & getWavelet() const
Non-mutable access to the wavelet.
Definition: ContinuousWaveletTransform.h:59
SignedSize getRightPaddingIndex() const
Non-mutable access to the position where the signal ends (in the interval (begin_right_padding_,...
Definition: ContinuousWaveletTransform.h:131
const std::vector< Peak1D > & getSignal() const
Non-mutable access to the wavelet transform of the signal.
Definition: ContinuousWaveletTransform.h:41
SignedSize & getRightPaddingIndex()
Mutable access to the position where the signal starts.
Definition: ContinuousWaveletTransform.h:137
void setSpacing(double spacing)
Mutable access to the spacing of raw data.
Definition: ContinuousWaveletTransform.h:107
double spacing_
Definition: ContinuousWaveletTransform.h:198
void setRightPaddingIndex(const SignedSize begin_right_padding)
Mutable access to position where the signal starts.
Definition: ContinuousWaveletTransform.h:143
double operator[](unsigned int i) const
Definition: ContinuousWaveletTransform.h:184
int getSize() const
Non-mutable access to signal length including padded zeros [0,end].
Definition: ContinuousWaveletTransform.h:167
SignedSize begin_right_padding_
Definition: ContinuousWaveletTransform.h:205
double getSpacing() const
Definition: ContinuousWaveletTransform.h:95
double & getScale()
Mutable access to the spacing of raw data.
Definition: ContinuousWaveletTransform.h:83
std::vector< double > & getWavelet()
Mutable access to the wavelet.
Definition: ContinuousWaveletTransform.h:65
std::vector< Peak1D >::const_iterator PeakConstIterator
Raw data const iterator type.
Definition: ContinuousWaveletTransform.h:24
SignedSize signal_length_
Definition: ContinuousWaveletTransform.h:199
void setWavelet(const std::vector< double > &wavelet)
Mutable access to the signal.
Definition: ContinuousWaveletTransform.h:71
void setScale(double scale)
Mutable access to the spacing of raw data.
Definition: ContinuousWaveletTransform.h:89
SignedSize getLeftPaddingIndex() const
Non-mutable access to the position where the signal starts (in the interval [0,end_left_padding_) are...
Definition: ContinuousWaveletTransform.h:113
double operator[](unsigned int i)
Yields the signal (intensity) at position i.
Definition: ContinuousWaveletTransform.h:179
std::vector< Peak1D > & getSignal()
Mutable access to the wavelet transform of the signal.
Definition: ContinuousWaveletTransform.h:47
virtual void init(double scale, double spacing)
Perform possibly necessary preprocessing steps, like tabulating the Wavelet.
SignedSize & getSignalLength()
Mutable access to signal length [end_left_padding,begin_right_padding].
Definition: ContinuousWaveletTransform.h:155
std::vector< Peak1D > signal_
The transformed signal.
Definition: ContinuousWaveletTransform.h:191
ContinuousWaveletTransform()
Constructor.
Definition: ContinuousWaveletTransform.h:28
double getScale() const
Definition: ContinuousWaveletTransform.h:77
void setSignalLength(const SignedSize signal_length)
Mutable access to signal length [end_left_padding,begin_right_padding].
Definition: ContinuousWaveletTransform.h:161
void setLeftPaddingIndex(const SignedSize end_left_padding)
Mutable access to position where the signal starts.
Definition: ContinuousWaveletTransform.h:125
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:108
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22