OpenMS
ContinuousWaveletTransform.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-2023.
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: Eva Lange $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/KERNEL/Peak1D.h>
38 
39 #include <vector>
40 
41 namespace OpenMS
42 {
46  class OPENMS_DLLAPI ContinuousWaveletTransform
47  {
48 public:
50  typedef std::vector<Peak1D>::const_iterator PeakConstIterator;
51 
52 
55  scale_(0),
56  spacing_(0),
57  signal_length_(0),
58  end_left_padding_(0),
59  begin_right_padding_(0)
60  {}
61 
64  {}
65 
67  inline const std::vector<Peak1D> & getSignal() const
68  {
69  return signal_;
70  }
71 
73  inline std::vector<Peak1D> & getSignal()
74  {
75  return signal_;
76  }
77 
79  inline void setSignal(const std::vector<Peak1D> & signal)
80  {
81  signal_ = signal;
82  }
83 
85  inline const std::vector<double> & getWavelet() const
86  {
87  return wavelet_;
88  }
89 
91  inline std::vector<double> & getWavelet()
92  {
93  return wavelet_;
94  }
95 
97  inline void setWavelet(const std::vector<double> & wavelet)
98  {
99  wavelet_ = wavelet;
100  }
101 
102  // Non-mutable access to the scale of the wavelet
103  inline double getScale() const
104  {
105  return scale_;
106  }
107 
109  inline double & getScale()
110  {
111  return scale_;
112  }
113 
115  inline void setScale(double scale)
116  {
117  scale_ = scale;
118  }
119 
120  // Non-mutable access to the spacing of raw data
121  inline double getSpacing() const
122  {
123  return spacing_;
124  }
125 
127  inline double & getSpacing()
128  {
129  return spacing_;
130  }
131 
133  inline void setSpacing(double spacing)
134  {
135  spacing_ = spacing;
136  }
137 
140  {
141  return end_left_padding_;
142  }
143 
146  {
147  return end_left_padding_;
148  }
149 
151  inline void setLeftPaddingIndex(const SignedSize end_left_padding)
152  {
153  end_left_padding_ = end_left_padding;
154  }
155 
158  {
159  return begin_right_padding_;
160  }
161 
164  {
165  return begin_right_padding_;
166  }
167 
169  inline void setRightPaddingIndex(const SignedSize begin_right_padding)
170  {
171  begin_right_padding_ = begin_right_padding;
172  }
173 
176  {
177  return signal_length_;
178  }
179 
182  {
183  return signal_length_;
184  }
185 
187  inline void setSignalLength(const SignedSize signal_length)
188  {
189  signal_length_ = signal_length;
190  }
191 
193  inline int getSize() const
194  {
195  return (int) signal_.size();
196  }
197 
201  virtual void init(double scale, double spacing);
202 
203 
205  inline double operator[](unsigned int i)
206  {
207  return signal_[i].getIntensity();
208  }
209 
210  inline double operator[](unsigned int i) const
211  {
212  return signal_[i].getIntensity();
213  }
214 
215 protected:
217  std::vector<Peak1D> signal_;
218 
220  std::vector<double> wavelet_;
221 
223  double scale_;
224  double spacing_;
226 
232 
233  template <typename InputPeakIterator>
234  double getInterpolatedValue_(double x, InputPeakIterator it_left)
235  {
236  // Interpolate between the point to the left and the point to the right.
237  double left_position = it_left->getMZ();
238  double right_position = (it_left + 1)->getMZ();
239  double d = (x - left_position) / (right_position - left_position);
240 
241  return (it_left + 1)->getIntensity() * d + it_left->getIntensity() * (1 - d);
242  }
243 
244  };
245 
246 } //namespace OpenMS
247 
This class is the base class of the continuous wavelet transformation.
Definition: ContinuousWaveletTransform.h:47
double getInterpolatedValue_(double x, InputPeakIterator it_left)
Definition: ContinuousWaveletTransform.h:234
SignedSize getSignalLength() const
Non-mutable access to signal length [end_left_padding,begin_right_padding].
Definition: ContinuousWaveletTransform.h:175
void setSignal(const std::vector< Peak1D > &signal)
Mutable access to the wavelet transform of the signal.
Definition: ContinuousWaveletTransform.h:79
double scale_
Spacing and scale of the wavelet and length of the signal.
Definition: ContinuousWaveletTransform.h:223
SignedSize & getLeftPaddingIndex()
Mutable access to the position where the signal starts.
Definition: ContinuousWaveletTransform.h:145
std::vector< double > wavelet_
The pre-tabulated wavelet used for the transform.
Definition: ContinuousWaveletTransform.h:220
virtual ~ContinuousWaveletTransform()
Destructor.
Definition: ContinuousWaveletTransform.h:63
SignedSize end_left_padding_
Definition: ContinuousWaveletTransform.h:230
double & getSpacing()
Mutable access to the spacing of raw data.
Definition: ContinuousWaveletTransform.h:127
const std::vector< double > & getWavelet() const
Non-mutable access to the wavelet.
Definition: ContinuousWaveletTransform.h:85
SignedSize getRightPaddingIndex() const
Non-mutable access to the position where the signal ends (in the interval (begin_right_padding_,...
Definition: ContinuousWaveletTransform.h:157
const std::vector< Peak1D > & getSignal() const
Non-mutable access to the wavelet transform of the signal.
Definition: ContinuousWaveletTransform.h:67
SignedSize & getRightPaddingIndex()
Mutable access to the position where the signal starts.
Definition: ContinuousWaveletTransform.h:163
void setSpacing(double spacing)
Mutable access to the spacing of raw data.
Definition: ContinuousWaveletTransform.h:133
double spacing_
Definition: ContinuousWaveletTransform.h:224
void setRightPaddingIndex(const SignedSize begin_right_padding)
Mutable access to position where the signal starts.
Definition: ContinuousWaveletTransform.h:169
double operator[](unsigned int i) const
Definition: ContinuousWaveletTransform.h:210
int getSize() const
Non-mutable access to signal length including padded zeros [0,end].
Definition: ContinuousWaveletTransform.h:193
SignedSize begin_right_padding_
Definition: ContinuousWaveletTransform.h:231
double getSpacing() const
Definition: ContinuousWaveletTransform.h:121
double & getScale()
Mutable access to the spacing of raw data.
Definition: ContinuousWaveletTransform.h:109
std::vector< double > & getWavelet()
Mutable access to the wavelet.
Definition: ContinuousWaveletTransform.h:91
std::vector< Peak1D >::const_iterator PeakConstIterator
Raw data const iterator type.
Definition: ContinuousWaveletTransform.h:50
SignedSize signal_length_
Definition: ContinuousWaveletTransform.h:225
void setWavelet(const std::vector< double > &wavelet)
Mutable access to the signal.
Definition: ContinuousWaveletTransform.h:97
void setScale(double scale)
Mutable access to the spacing of raw data.
Definition: ContinuousWaveletTransform.h:115
SignedSize getLeftPaddingIndex() const
Non-mutable access to the position where the signal starts (in the interval [0,end_left_padding_) are...
Definition: ContinuousWaveletTransform.h:139
double operator[](unsigned int i)
Yields the signal (intensity) at position i.
Definition: ContinuousWaveletTransform.h:205
std::vector< Peak1D > & getSignal()
Mutable access to the wavelet transform of the signal.
Definition: ContinuousWaveletTransform.h:73
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:181
std::vector< Peak1D > signal_
The transformed signal.
Definition: ContinuousWaveletTransform.h:217
ContinuousWaveletTransform()
Constructor.
Definition: ContinuousWaveletTransform.h:54
double getScale() const
Definition: ContinuousWaveletTransform.h:103
void setSignalLength(const SignedSize signal_length)
Mutable access to signal length [end_left_padding,begin_right_padding].
Definition: ContinuousWaveletTransform.h:187
void setLeftPaddingIndex(const SignedSize end_left_padding)
Mutable access to position where the signal starts.
Definition: ContinuousWaveletTransform.h:151
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48