Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

InterpolationModel.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Clemens Groepl $
00032 // $Authors: $
00033 // --------------------------------------------------------------------------
00034 
00035 
00036 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_INTERPOLATIONMODEL_H
00037 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_INTERPOLATIONMODEL_H
00038 
00039 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/BaseModel.h>
00040 #include <OpenMS/MATH/MISC/LinearInterpolation.h>
00041 
00042 namespace OpenMS
00043 {
00055   class OPENMS_DLLAPI InterpolationModel :
00056     public BaseModel<1>
00057   {
00058 
00059 public:
00060     typedef DoubleReal IntensityType;
00061     typedef DPosition<1> PositionType;
00062     typedef DoubleReal CoordinateType;
00063     typedef Math::LinearInterpolation<DoubleReal> LinearInterpolation;
00064 
00066     InterpolationModel() :
00067       BaseModel<1>(),
00068       interpolation_()
00069     {
00070       this->defaults_.setValue("interpolation_step", 0.1, "Sampling rate for the interpolation of the model function ");
00071       this->defaults_.setValue("intensity_scaling", 1.0, "Scaling factor used to adjust the model distribution to the intensities of the data");
00072     }
00073 
00075     InterpolationModel(const InterpolationModel & source) :
00076       BaseModel<1>(source),
00077       interpolation_(source.interpolation_),
00078       interpolation_step_(source.interpolation_step_),
00079       scaling_(source.scaling_)
00080     {
00081     }
00082 
00084     virtual ~InterpolationModel()
00085     {
00086     }
00087 
00089     virtual InterpolationModel & operator=(const InterpolationModel & source)
00090     {
00091       if (&source == this) return *this;
00092 
00093       BaseModel<1>::operator=(source);
00094       interpolation_step_ = source.interpolation_step_;
00095       interpolation_ = source.interpolation_;
00096       scaling_ = source.scaling_;
00097 
00098       return *this;
00099     }
00100 
00102     IntensityType getIntensity(const PositionType & pos) const
00103     {
00104       return interpolation_.value(pos[0]);
00105     }
00106 
00108     IntensityType getIntensity(CoordinateType coord) const
00109     {
00110       return interpolation_.value(coord);
00111     }
00112 
00114     const LinearInterpolation & getInterpolation() const
00115     {
00116       return interpolation_;
00117     }
00118 
00124     CoordinateType getScalingFactor() const
00125     {
00126       return scaling_;
00127     }
00128 
00134     virtual void setOffset(CoordinateType offset)
00135     {
00136       interpolation_.setOffset(offset);
00137     }
00138 
00140     void getSamples(SamplesType & cont) const
00141     {
00142       cont = SamplesType();
00143       BaseModel<1>::PeakType peak;
00144       for (Size i = 0; i < interpolation_.getData().size(); ++i)
00145       {
00146         peak.setIntensity(interpolation_.getData()[i]);
00147         peak.getPosition()[0] = interpolation_.index2key(i);
00148         cont.push_back(peak);
00149       }
00150     }
00151 
00153     virtual CoordinateType getCenter() const
00154     {
00155       throw Exception::NotImplemented(__FILE__, __LINE__, __PRETTY_FUNCTION__);
00156       return CoordinateType();           // we will never get here, but this avoids a warning
00157     }
00158 
00160     virtual void setSamples()
00161     {
00162       throw Exception::NotImplemented(__FILE__, __LINE__, __PRETTY_FUNCTION__);
00163     }
00164 
00170     void setInterpolationStep(CoordinateType interpolation_step)
00171     {
00172       interpolation_step_ = interpolation_step;
00173       this->param_.setValue("interpolation_step", interpolation_step_);
00174     }
00175 
00176     void setScalingFactor(CoordinateType scaling)
00177     {
00178       scaling_ = scaling;
00179       this->param_.setValue("intensity_scaling", scaling_);
00180     }
00181 
00182 protected:
00183     LinearInterpolation interpolation_;
00184     CoordinateType interpolation_step_;
00185     CoordinateType scaling_;
00186 
00187     void updateMembers_()
00188     {
00189       BaseModel<1>::updateMembers_();
00190       interpolation_step_ = this->param_.getValue("interpolation_step");
00191       scaling_ = this->param_.getValue("intensity_scaling");
00192     }
00193 
00194   };
00195 }
00196 
00197 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_INTERPOLATIONMODEL_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:40 using doxygen 1.7.1