~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to include/OpenMS/TRANSFORMATIONS/RAW2PEAK/ContinuousWaveletTransform.h

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- mode: C++; tab-width: 2; -*-
2
 
// vi: set ts=2:
3
 
//
4
 
// --------------------------------------------------------------------------
5
 
//                   OpenMS Mass Spectrometry Framework
6
 
// --------------------------------------------------------------------------
7
 
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
8
 
//
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.
13
 
//
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.
18
 
//
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
 
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-2013.
 
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.
22
29
//
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: Alexandra Zerck $
35
42
 
36
43
namespace OpenMS
37
44
{
38
 
        /**
39
 
                 @brief This class is the base class of the continuous wavelet transformation. 
40
 
        */
41
 
        class OPENMS_DLLAPI ContinuousWaveletTransform
42
 
        {
43
 
        public:
 
45
  /**
 
46
       @brief This class is the base class of the continuous wavelet transformation.
 
47
  */
 
48
  class OPENMS_DLLAPI ContinuousWaveletTransform
 
49
  {
 
50
public:
44
51
    /// Raw data const iterator type
45
 
    typedef std::vector<Peak1D >::const_iterator PeakConstIterator;
 
52
    typedef std::vector<Peak1D>::const_iterator PeakConstIterator;
46
53
 
47
54
 
48
55
    /// Constructor
49
 
    ContinuousWaveletTransform()
50
 
                        : scale_(0),
51
 
                                spacing_(0),
52
 
                                signal_length_(0),
53
 
                                end_left_padding_(0),
54
 
                                begin_right_padding_(0)
 
56
    ContinuousWaveletTransform() :
 
57
      scale_(0),
 
58
      spacing_(0),
 
59
      signal_length_(0),
 
60
      end_left_padding_(0),
 
61
      begin_right_padding_(0)
55
62
    {}
56
63
 
57
64
    /// Destructor.
59
66
    {}
60
67
 
61
68
    /// Non-mutable access to the wavelet transform of the signal
62
 
    inline const std::vector<Peak1D>& getSignal() const
63
 
    {
64
 
                        return signal_;
65
 
    }
66
 
    /// Mutable access to the wavelet transform of the signal
67
 
    inline std::vector<Peak1D>& getSignal()
68
 
    {
69
 
                        return signal_;
70
 
    }
71
 
    /// Mutable access to the wavelet transform of the signal
72
 
    inline void setSignal(const std::vector<Peak1D>& signal)
73
 
    {
74
 
                        signal_ = signal;
 
69
    inline const std::vector<Peak1D> & getSignal() const
 
70
    {
 
71
      return signal_;
 
72
    }
 
73
 
 
74
    /// Mutable access to the wavelet transform of the signal
 
75
    inline std::vector<Peak1D> & getSignal()
 
76
    {
 
77
      return signal_;
 
78
    }
 
79
 
 
80
    /// Mutable access to the wavelet transform of the signal
 
81
    inline void setSignal(const std::vector<Peak1D> & signal)
 
82
    {
 
83
      signal_ = signal;
75
84
    }
76
85
 
77
86
    /// Non-mutable access to the wavelet
78
 
    inline const std::vector<double>& getWavelet() const
 
87
    inline const std::vector<double> & getWavelet() const
79
88
    {
80
 
                        return wavelet_;
 
89
      return wavelet_;
81
90
    }
 
91
 
82
92
    /// Mutable access to the wavelet
83
 
    inline std::vector<double>& getWavelet()
 
93
    inline std::vector<double> & getWavelet()
84
94
    {
85
 
                        return wavelet_;
 
95
      return wavelet_;
86
96
    }
 
97
 
87
98
    /// Mutable access to the signal
88
 
    inline void setWavelet(const std::vector<double>& wavelet)
 
99
    inline void setWavelet(const std::vector<double> & wavelet)
89
100
    {
90
 
                        wavelet_ = wavelet;
 
101
      wavelet_ = wavelet;
91
102
    }
92
103
 
93
104
    // Non-mutable access to the scale of the wavelet
94
105
    inline DoubleReal getScale() const
95
106
    {
96
 
                        return scale_;
 
107
      return scale_;
97
108
    }
 
109
 
98
110
    /// Mutable access to the spacing of raw data
99
 
    inline double& getScale()
 
111
    inline double & getScale()
100
112
    {
101
 
                        return scale_;
 
113
      return scale_;
102
114
    }
 
115
 
103
116
    /// Mutable access to the spacing of raw data
104
117
    inline void setScale(DoubleReal scale)
105
118
    {
106
 
                        scale_ = scale;
 
119
      scale_ = scale;
107
120
    }
108
121
 
109
122
    // Non-mutable access to the spacing of raw data
110
123
    inline DoubleReal getSpacing() const
111
124
    {
112
 
                        return spacing_;
 
125
      return spacing_;
113
126
    }
 
127
 
114
128
    /// Mutable access to the spacing of raw data
115
 
    inline double& getSpacing()
 
129
    inline double & getSpacing()
116
130
    {
117
 
                        return spacing_;
 
131
      return spacing_;
118
132
    }
 
133
 
119
134
    /// Mutable access to the spacing of raw data
120
135
    inline void setSpacing(double spacing)
121
136
    {
122
 
                        spacing_ = spacing;
 
137
      spacing_ = spacing;
123
138
    }
124
139
 
125
140
    /// Non-mutable access to the position where the signal starts (in the intervall [0,end_left_padding_) are the padded zeros)
126
141
    inline SignedSize getLeftPaddingIndex() const
127
142
    {
128
 
                        return end_left_padding_;
 
143
      return end_left_padding_;
129
144
    }
 
145
 
130
146
    /// Mutable access to the position where the signal starts
131
 
    inline SignedSize& getLeftPaddingIndex()
 
147
    inline SignedSize & getLeftPaddingIndex()
132
148
    {
133
 
                        return end_left_padding_;
 
149
      return end_left_padding_;
134
150
    }
 
151
 
135
152
    /// Mutable access to position where the signal starts
136
153
    inline void setLeftPaddingIndex(const SignedSize end_left_padding)
137
154
    {
138
 
                        end_left_padding_ = end_left_padding;
 
155
      end_left_padding_ = end_left_padding;
139
156
    }
140
157
 
141
158
    /// Non-mutable access to the position where the signal ends (in the intervall (begin_right_padding_,end] are the padded zeros)
142
159
    inline SignedSize getRightPaddingIndex() const
143
160
    {
144
 
                        return begin_right_padding_;
 
161
      return begin_right_padding_;
145
162
    }
 
163
 
146
164
    /// Mutable access to the position where the signal starts
147
 
    inline SignedSize& getRightPaddingIndex()
 
165
    inline SignedSize & getRightPaddingIndex()
148
166
    {
149
 
                        return begin_right_padding_;
 
167
      return begin_right_padding_;
150
168
    }
 
169
 
151
170
    /// Mutable access to position where the signal starts
152
171
    inline void setRightPaddingIndex(const SignedSize begin_right_padding)
153
172
    {
154
 
                        begin_right_padding_ = begin_right_padding;
 
173
      begin_right_padding_ = begin_right_padding;
155
174
    }
156
175
 
157
176
    /// Non-mutable access to signal length [end_left_padding,begin_right_padding]
158
177
    inline SignedSize getSignalLength() const
159
178
    {
160
 
                        return signal_length_;
 
179
      return signal_length_;
161
180
    }
 
181
 
162
182
    /// Mutable access to signal length [end_left_padding,begin_right_padding]
163
 
    inline SignedSize& getSignalLength()
 
183
    inline SignedSize & getSignalLength()
164
184
    {
165
 
                        return signal_length_;
 
185
      return signal_length_;
166
186
    }
 
187
 
167
188
    /// Mutable access to signal length [end_left_padding,begin_right_padding]
168
189
    inline void setSignalLength(const SignedSize signal_length)
169
190
    {
170
 
                        signal_length_ = signal_length;
 
191
      signal_length_ = signal_length;
171
192
    }
172
193
 
173
194
    /// Non-mutable access to signal length including padded zeros [0,end]
174
195
    inline int getSize() const
175
196
    {
176
 
                        return (int) signal_.size();
 
197
      return (int) signal_.size();
177
198
    }
178
199
 
179
 
 
180
200
    /**
181
 
                         @brief Perform possibly necessary preprocessing steps, like tabulating the Wavelet.
 
201
             @brief Perform possibly necessary preprocessing steps, like tabulating the Wavelet.
182
202
    */
183
203
    virtual void init(double scale, double spacing);
184
204
 
185
205
 
186
206
    /// Yields the signal (intensity) at position i
187
 
    inline double operator [] (unsigned int i)
188
 
    {
189
 
                        return signal_[i].getIntensity();
190
 
    }
191
 
 
192
 
    inline double operator [] (unsigned int i) const
193
 
    {
194
 
                        return signal_[i].getIntensity();
195
 
    }
196
 
                
197
 
 
198
 
 
199
 
 
200
 
        protected:
 
207
    inline double operator[](unsigned int i)
 
208
    {
 
209
      return signal_[i].getIntensity();
 
210
    }
 
211
 
 
212
    inline double operator[](unsigned int i) const
 
213
    {
 
214
      return signal_[i].getIntensity();
 
215
    }
 
216
 
 
217
protected:
201
218
    /// The transformed signal
202
 
                std::vector<Peak1D> signal_;
 
219
    std::vector<Peak1D> signal_;
203
220
 
204
221
    /// The pretabulated wavelet used for the transform
205
222
    std::vector<double> wavelet_;
215
232
    SignedSize end_left_padding_;
216
233
    SignedSize begin_right_padding_;
217
234
 
218
 
                template < typename InputPeakIterator >
219
 
                double getInterpolatedValue_(double x, InputPeakIterator it_left)
220
 
                {
221
 
        // Interpolate between the point to the left and the point to the right.
222
 
        double left_position = it_left->getMZ();
223
 
        double right_position = (it_left+1)->getMZ();
224
 
        double d=(x-left_position)/(right_position-left_position);
225
 
 
226
 
        return ((it_left+1)->getIntensity()*d+it_left->getIntensity()*(1-d));
227
 
                }
228
 
 
229
 
        };
 
235
    template <typename InputPeakIterator>
 
236
    double getInterpolatedValue_(double x, InputPeakIterator it_left)
 
237
    {
 
238
      // Interpolate between the point to the left and the point to the right.
 
239
      double left_position = it_left->getMZ();
 
240
      double right_position = (it_left + 1)->getMZ();
 
241
      double d = (x - left_position) / (right_position - left_position);
 
242
 
 
243
      return (it_left + 1)->getIntensity() * d + it_left->getIntensity() * (1 - d);
 
244
    }
 
245
 
 
246
  };
230
247
 
231
248
} //namespace OpenMS
232
249
 
233
250
#endif
234