OpenMS
BaseModel.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: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 #include <OpenMS/KERNEL/DPeak.h>
13 
14 namespace OpenMS
15 {
16 
23  template<UInt D>
25  {
26  public:
27  typedef double IntensityType;
28  typedef double CoordinateType;
30  typedef typename DPeak<D>::Type PeakType;
31  typedef std::vector<PeakType> SamplesType;
32 
33 
35  BaseModel() : DefaultParamHandler("BaseModel")
36  {
37  defaults_.setValue("cutoff", 0.0, "Low intensity cutoff of the model. Peaks below this intensity are not considered part of the model.");
38  }
39 
41  BaseModel(const BaseModel& source) : DefaultParamHandler(source), cut_off_(source.cut_off_)
42  {
43  }
44 
46  ~BaseModel() override
47  {
48  }
49 
51  BaseModel& operator=(const BaseModel& source)
52  {
53  if (&source == this)
54  return *this;
55 
57  cut_off_ = source.cut_off_;
58 
59  return *this;
60  }
61 
63  static void registerChildren();
64 
66  virtual IntensityType getIntensity(const PositionType& pos) const = 0;
67 
69  virtual bool isContained(const PositionType& pos) const
70  {
71  return getIntensity(pos) >= cut_off_;
72  }
73 
78  template<typename PeakType>
79  void fillIntensity(PeakType& peak) const
80  {
81  peak.setIntensity(getIntensity(peak.getPosition()));
82  }
83 
87  template<class PeakIterator>
88  void fillIntensities(PeakIterator begin, PeakIterator end) const
89  {
90  for (PeakIterator it = begin; it != end; ++it)
91  {
92  fillIntensity(*it);
93  }
94  }
95 
97  virtual IntensityType getCutOff() const
98  {
99  return cut_off_;
100  }
101 
103  virtual void setCutOff(IntensityType cut_off)
104  {
105  cut_off_ = cut_off;
106  param_.setValue("cutoff", cut_off_);
107  }
108 
110  virtual void getSamples(SamplesType& cont) const = 0;
111 
113  virtual void getSamples(std::ostream& os)
114  {
115  SamplesType samples;
116  getSamples(samples);
117  for (typename SamplesType::const_iterator it = samples.begin(); it != samples.end(); ++it)
118  {
119  os << *it << std::endl;
120  }
121  }
122 
123  protected:
125 
126  void updateMembers_() override
127  {
128  cut_off_ = (double)param_.getValue("cutoff");
129  }
130  };
131 } // namespace OpenMS
Abstract base class for all D-dimensional models.
Definition: BaseModel.h:25
virtual IntensityType getIntensity(const PositionType &pos) const =0
access model predicted intensity at position pos
DPeak< D >::Type PeakType
Definition: BaseModel.h:30
BaseModel(const BaseModel &source)
copy constructor
Definition: BaseModel.h:41
BaseModel & operator=(const BaseModel &source)
assignment operator
Definition: BaseModel.h:51
double CoordinateType
Definition: BaseModel.h:28
BaseModel()
Default constructor.
Definition: BaseModel.h:35
virtual void setCutOff(IntensityType cut_off)
set cutoff value
Definition: BaseModel.h:103
DPosition< D > PositionType
Definition: BaseModel.h:29
void fillIntensities(PeakIterator begin, PeakIterator end) const
Convenience function that applies fillIntensity() to an iterator range.
Definition: BaseModel.h:88
static void registerChildren()
register all derived classes here (implemented in file BaseModel_impl.h)
~BaseModel() override
Destructor.
Definition: BaseModel.h:46
virtual bool isContained(const PositionType &pos) const
check if position pos is part of the model regarding the models cut-off.
Definition: BaseModel.h:69
virtual IntensityType getCutOff() const
get cutoff value
Definition: BaseModel.h:97
std::vector< PeakType > SamplesType
Definition: BaseModel.h:31
void fillIntensity(PeakType &peak) const
Convenience function to set the intensity of a peak to the predicted intensity at its current positio...
Definition: BaseModel.h:79
virtual void getSamples(SamplesType &cont) const =0
get reasonable set of samples from the model (i.e. for printing)
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: BaseModel.h:126
double IntensityType
Definition: BaseModel.h:27
IntensityType cut_off_
Definition: BaseModel.h:124
virtual void getSamples(std::ostream &os)
fill stream with reasonable set of samples from the model (i.e. for printing)
Definition: BaseModel.h:113
Representation of a coordinate in D-dimensional space.
Definition: DPosition.h:29
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:139
DefaultParamHandler & operator=(const DefaultParamHandler &rhs)
Assignment operator.
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!
Definition: DefaultParamHandler.h:146
const ParamValue & getValue(const std::string &key) const
Returns a value of a parameter.
void setValue(const std::string &key, const ParamValue &value, const std::string &description="", const std::vector< std::string > &tags=std::vector< std::string >())
Sets a value.
RawDataVector::iterator PeakIterator
Profile data iterator type.
Definition: OptimizePick.h:32
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Metafunction to choose among Peak1D respectively Peak2D through a template argument.
Definition: DPeak.h:35