OpenMS  2.8.0
InterpolationModel.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-2021.
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: $
33 // --------------------------------------------------------------------------
34 
35 
36 #pragma once
37 
40 
41 namespace OpenMS
42 {
54  class OPENMS_DLLAPI InterpolationModel :
55  public BaseModel<1>
56  {
57 
58 public:
59  typedef double IntensityType;
61  typedef double CoordinateType;
63 
66  BaseModel<1>(),
67  interpolation_()
68  {
69  this->defaults_.setValue("interpolation_step", 0.1, "Sampling rate for the interpolation of the model function ");
70  this->defaults_.setValue("intensity_scaling", 1.0, "Scaling factor used to adjust the model distribution to the intensities of the data");
71  defaultsToParam_();
72  }
73 
76  BaseModel<1>(source),
77  interpolation_(source.interpolation_),
78  interpolation_step_(source.interpolation_step_),
79  scaling_(source.scaling_)
80  {
81  updateMembers_();
82  }
83 
85  ~InterpolationModel() override = default;
86 
89  {
90  if (&source == this) return *this;
91 
93  interpolation_step_ = source.interpolation_step_;
94  interpolation_ = source.interpolation_;
95  scaling_ = source.scaling_;
96 
97  updateMembers_();
98 
99  return *this;
100  }
101 
103  IntensityType getIntensity(const PositionType & pos) const override
104  {
105  return interpolation_.value(pos[0]);
106  }
107 
110  {
111  return interpolation_.value(coord);
112  }
113 
116  {
117  return interpolation_;
118  }
119 
126  {
127  return scaling_;
128  }
129 
135  virtual void setOffset(CoordinateType offset)
136  {
137  interpolation_.setOffset(offset);
138  }
139 
141  void getSamples(SamplesType & cont) const override
142  {
143  cont = SamplesType();
145  for (Size i = 0; i < interpolation_.getData().size(); ++i)
146  {
147 #pragma clang diagnostic push
148 #pragma clang diagnostic ignored "-Wconversion"
149  peak.setIntensity(interpolation_.getData()[i]);
150 #pragma clang diagnostic pop
151  peak.getPosition()[0] = interpolation_.index2key(i);
152  cont.push_back(peak);
153  }
154  }
155 
157  virtual CoordinateType getCenter() const
158  {
159  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
160  }
161 
163  virtual void setSamples()
164  {
165  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
166  }
167 
173  void setInterpolationStep(CoordinateType interpolation_step)
174  {
175  interpolation_step_ = interpolation_step;
176  this->param_.setValue("interpolation_step", interpolation_step_);
177  }
178 
180  {
181  scaling_ = scaling;
182  this->param_.setValue("intensity_scaling", scaling_);
183  }
184 
185 protected:
189 
190  void updateMembers_() override
191  {
193  interpolation_step_ = this->param_.getValue("interpolation_step");
194  scaling_ = this->param_.getValue("intensity_scaling");
195  }
196 
197  };
198 }
199 
Abstract base class for all D-dimensional models.
Definition: BaseModel.h:52
std::vector< PeakType > SamplesType
Definition: BaseModel.h:60
virtual BaseModel & operator=(const BaseModel &source)
assignment operator
Definition: BaseModel.h:83
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: BaseModel.h:157
Not implemented exception.
Definition: Exception.h:430
Abstract class for 1D-models that are approximated using linear interpolation.
Definition: InterpolationModel.h:56
Math::LinearInterpolation< double > LinearInterpolation
Definition: InterpolationModel.h:62
DPosition< 1 > PositionType
Definition: InterpolationModel.h:60
double CoordinateType
Definition: InterpolationModel.h:61
void setScalingFactor(CoordinateType scaling)
Definition: InterpolationModel.h:179
InterpolationModel()
Default constructor.
Definition: InterpolationModel.h:65
virtual void setSamples()
set sample/supporting points of interpolation wrt params.
Definition: InterpolationModel.h:163
~InterpolationModel() override=default
destructor
InterpolationModel(const InterpolationModel &source)
copy constructor
Definition: InterpolationModel.h:75
CoordinateType scaling_
Definition: InterpolationModel.h:188
virtual CoordinateType getCenter() const
"center" of the model, particular definition (depends on the derived model)
Definition: InterpolationModel.h:157
IntensityType getIntensity(const PositionType &pos) const override
access model predicted intensity at position pos
Definition: InterpolationModel.h:103
void setInterpolationStep(CoordinateType interpolation_step)
Set the interpolation step for the linear interpolation of the model.
Definition: InterpolationModel.h:173
LinearInterpolation interpolation_
Definition: InterpolationModel.h:186
virtual void setOffset(CoordinateType offset)
set the offset of the model
Definition: InterpolationModel.h:135
CoordinateType interpolation_step_
Definition: InterpolationModel.h:187
const LinearInterpolation & getInterpolation() const
Returns the interpolation class.
Definition: InterpolationModel.h:115
void getSamples(SamplesType &cont) const override
get reasonable set of samples from the model (i.e. for printing)
Definition: InterpolationModel.h:141
IntensityType getIntensity(CoordinateType coord) const
access model predicted intensity at position pos
Definition: InterpolationModel.h:109
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: InterpolationModel.h:190
double IntensityType
Definition: InterpolationModel.h:59
InterpolationModel & operator=(const InterpolationModel &source)
assignment operator
Definition: InterpolationModel.h:88
CoordinateType getScalingFactor() const
get the scaling for the model
Definition: InterpolationModel.h:125
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47