00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_INTERPOLATIONMODEL_H
00029 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_INTERPOLATIONMODEL_H
00030
00031 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/BaseModel.h>
00032 #include <OpenMS/MATH/MISC/LinearInterpolation.h>
00033
00034 namespace OpenMS
00035 {
00057 class InterpolationModel
00058 : public BaseModel<1>
00059 {
00060
00061 public:
00062 typedef DPeak<1>::IntensityType IntensityType;
00063 typedef DPosition<1> PositionType;
00064 typedef PositionType::CoordinateType CoordinateType;
00065 typedef Math::LinearInterpolation<CoordinateType,IntensityType> LinearInterpolation;
00066 typedef LinearInterpolation::container_type ContainerType;
00067 typedef DPeakArray<DPeak<1> > SamplesType;
00068
00070 InterpolationModel()
00071 : BaseModel<1>(),
00072 interpolation_()
00073 {
00074 this->defaults_.setValue("interpolation_step",0.1,"Sampling rate for the interpolation of the model function ");
00075 this->defaults_.setValue("intensity_scaling",1.0,"Scaling factor used to adjust the model distribution to the intensities of the data");
00076 }
00077
00079 InterpolationModel(const InterpolationModel& source)
00080 : BaseModel<1>(source),
00081 interpolation_(source.interpolation_),
00082 interpolation_step_(source.interpolation_step_),
00083 scaling_(source.scaling_)
00084 {
00085 }
00086
00088 virtual ~InterpolationModel()
00089 {
00090 }
00091
00093 virtual InterpolationModel& operator = (const InterpolationModel& source)
00094 {
00095 if (&source ==this) return *this;
00096
00097 BaseModel<1>::operator = (source);
00098 interpolation_step_ = source.interpolation_step_;
00099 interpolation_ = source.interpolation_;
00100 scaling_ = source.scaling_;
00101
00102 return *this;
00103 }
00104
00106 IntensityType getIntensity(const PositionType& pos) const
00107 {
00108 return interpolation_.value(pos[0]);
00109 }
00110
00112 IntensityType getIntensity(CoordinateType coord) const
00113 {
00114 return interpolation_.value(coord);
00115 }
00116
00118 const LinearInterpolation& getInterpolation() const
00119 {
00120 return interpolation_;
00121 }
00122
00128 CoordinateType getScalingFactor() const
00129 {
00130 return scaling_;
00131 }
00132
00138 virtual void setOffset(CoordinateType offset)
00139 {
00140 interpolation_.setOffset(offset);
00141 }
00142
00144 void getSamples(SamplesType& cont) const
00145 {
00146 cont = SamplesType();
00147 DPeak<1> peak;
00148 for (UInt i=0; i<interpolation_.getData().size(); ++i)
00149 {
00150 peak.setIntensity( interpolation_.getData()[i] );
00151 peak.getPosition()[0] = interpolation_.index2key(i);
00152 cont.push_back(peak);
00153 }
00154 }
00155
00157 virtual CoordinateType getCenter() const=0;
00158
00160 virtual void setSamples() =0;
00161
00167 void setInterpolationStep(CoordinateType interpolation_step)
00168 {
00169 interpolation_step_ = interpolation_step;
00170 this->param_.setValue("interpolation_step",interpolation_step_);
00171 }
00172
00173 void setScalingFactor(CoordinateType scaling)
00174 {
00175 scaling_ = scaling;
00176 this->param_.setValue("intensity_scaling",scaling_);
00177 }
00178
00179 protected:
00180 LinearInterpolation interpolation_;
00181 CoordinateType interpolation_step_;
00182 CoordinateType scaling_;
00183
00184 void updateMembers_()
00185 {
00186 BaseModel<1>::updateMembers_();
00187 interpolation_step_ = this->param_.getValue("interpolation_step");
00188 scaling_ = this->param_.getValue("intensity_scaling");
00189 }
00190 };
00191 }
00192
00193 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_INTERPOLATIONMODEL_H