OpenMS
InterpolationModel.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, 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: $
7 // --------------------------------------------------------------------------
8 
9 
10 #pragma once
11 
14 
15 namespace OpenMS
16 {
28  class OPENMS_DLLAPI InterpolationModel :
29  public BaseModel
30  {
31 
32 public:
33  typedef double IntensityType;
35  typedef double CoordinateType;
36  using KeyType = double;
38 
41  BaseModel(),
42  interpolation_()
43  {
44  this->defaults_.setValue("interpolation_step", 0.1, "Sampling rate for the interpolation of the model function ");
45  this->defaults_.setValue("intensity_scaling", 1.0, "Scaling factor used to adjust the model distribution to the intensities of the data");
46  defaultsToParam_();
47  }
48 
51  BaseModel(source),
52  interpolation_(source.interpolation_),
53  interpolation_step_(source.interpolation_step_),
54  scaling_(source.scaling_)
55  {
56  updateMembers_();
57  }
58 
60  ~InterpolationModel() override = default;
61 
64  {
65  if (&source == this) return *this;
66 
67  BaseModel::operator=(source);
68  interpolation_step_ = source.interpolation_step_;
69  interpolation_ = source.interpolation_;
70  scaling_ = source.scaling_;
71 
72  updateMembers_();
73 
74  return *this;
75  }
76 
78  IntensityType getIntensity(const PositionType & pos) const override
79  {
80  return interpolation_.value(pos[0]);
81  }
82 
85  {
86  return interpolation_.value(coord);
87  }
88 
91  {
92  return interpolation_;
93  }
94 
101  {
102  return scaling_;
103  }
104 
110  virtual void setOffset(CoordinateType offset)
111  {
112  interpolation_.setOffset(offset);
113  }
114 
116  void getSamples(SamplesType & cont) const override
117  {
118  cont.clear();
119  using PeakT = BaseModel::PeakType;
120  PeakT peak;
121  for (Size i = 0; i < interpolation_.getData().size(); ++i)
122  {
123  peak.getPosition()[0] = interpolation_.index2key((KeyType)i);
124  peak.setIntensity((PeakT::IntensityType)interpolation_.getData()[i]);
125  cont.push_back(peak);
126  }
127  }
128 
130  virtual CoordinateType getCenter() const
131  {
132  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
133  }
134 
136  virtual void setSamples()
137  {
138  throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
139  }
140 
146  void setInterpolationStep(CoordinateType interpolation_step)
147  {
148  interpolation_step_ = interpolation_step;
149  this->param_.setValue("interpolation_step", interpolation_step_);
150  }
151 
153  {
154  scaling_ = scaling;
155  this->param_.setValue("intensity_scaling", scaling_);
156  }
157 
158 protected:
162 
163  void updateMembers_() override
164  {
166  interpolation_step_ = this->param_.getValue("interpolation_step");
167  scaling_ = this->param_.getValue("intensity_scaling");
168  }
169 
170  };
171 }
172 
Abstract base class for 1-dimensional models.
Definition: BaseModel.h:22
BaseModel & operator=(const BaseModel &source)
assignment operator
Definition: BaseModel.h:48
double CoordinateType
Definition: BaseModel.h:25
std::vector< PeakType > SamplesType
Definition: BaseModel.h:28
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: BaseModel.h:120
double IntensityType
Definition: BaseModel.h:24
DPeak< 1 >::Type PeakType
Definition: BaseModel.h:27
Not implemented exception.
Definition: Exception.h:399
Abstract class for 1D-models that are approximated using linear interpolation.
Definition: InterpolationModel.h:30
DPosition< 1 > PositionType
Definition: InterpolationModel.h:34
double KeyType
Definition: InterpolationModel.h:36
double CoordinateType
Definition: InterpolationModel.h:35
void setScalingFactor(CoordinateType scaling)
Definition: InterpolationModel.h:152
InterpolationModel()
Default constructor.
Definition: InterpolationModel.h:40
virtual void setSamples()
set sample/supporting points of interpolation wrt params.
Definition: InterpolationModel.h:136
~InterpolationModel() override=default
destructor
InterpolationModel(const InterpolationModel &source)
copy constructor
Definition: InterpolationModel.h:50
CoordinateType scaling_
Definition: InterpolationModel.h:161
virtual CoordinateType getCenter() const
"center" of the model, particular definition (depends on the derived model)
Definition: InterpolationModel.h:130
IntensityType getIntensity(const PositionType &pos) const override
access model predicted intensity at position pos
Definition: InterpolationModel.h:78
void setInterpolationStep(CoordinateType interpolation_step)
Set the interpolation step for the linear interpolation of the model.
Definition: InterpolationModel.h:146
LinearInterpolation interpolation_
Definition: InterpolationModel.h:159
virtual void setOffset(CoordinateType offset)
set the offset of the model
Definition: InterpolationModel.h:110
CoordinateType interpolation_step_
Definition: InterpolationModel.h:160
const LinearInterpolation & getInterpolation() const
Returns the interpolation class.
Definition: InterpolationModel.h:90
void getSamples(SamplesType &cont) const override
get reasonable set of samples from the model (i.e. for printing)
Definition: InterpolationModel.h:116
IntensityType getIntensity(CoordinateType coord) const
access model predicted intensity at position pos
Definition: InterpolationModel.h:84
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: InterpolationModel.h:163
double IntensityType
Definition: InterpolationModel.h:33
Math::LinearInterpolation< KeyType > LinearInterpolation
Definition: InterpolationModel.h:37
InterpolationModel & operator=(const InterpolationModel &source)
assignment operator
Definition: InterpolationModel.h:63
CoordinateType getScalingFactor() const
get the scaling for the model
Definition: InterpolationModel.h:100
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19