LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiNoise.h

00001 /*
00002  * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*----------------------------------------------------------------
00025  * project ....: LTI Digital Image/Signal Processing Library
00026  * file .......: ltiNoise.h
00027  * authors ....: Thomas Rusert
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 06.05.99
00030  * revisions ..: $Id: ltiNoise.h,v 1.6 2006/02/23 18:02:43 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_NOISE_H_
00034 #define _LTI_NOISE_H_
00035 
00036 #include "ltiIteratingFunctor.h"
00037 #include "ltiContinuousRandDist.h"
00038 #include "ltiGaussDist.h"
00039 #include <limits>
00040 
00041 namespace lti {
00042   /** Noise class.
00043    *  
00044    *  Apply puts noise of the specified distribution on the elements of
00045    *  the given MathObject.
00046    *
00047    *  Default is a default contstructed lti::gaussianDistribution.
00048    */
00049   template<class T>
00050   class noise : public iteratingFunctor<T> {
00051   public:
00052     /// scalarParameter class
00053     class parameters : public iteratingFunctor<T>::parameters {
00054     public:
00055       /**
00056        * lower limit for the noise of the type T
00057        *
00058        * Default: std::numeric_limits<T>::min()
00059        */
00060       T lowerLimit;
00061 
00062       /**
00063        * upper limit for the noise of the type T
00064        *
00065        * Default: std::numeric_limits<T>::max()
00066        */
00067       T upperLimit;
00068 
00069       /// default constructor
00070       parameters() : iteratingFunctor<T>::parameters() {
00071         distribution = new gaussianDistribution();
00072         lowerLimit=std::numeric_limits<T>::min();
00073         upperLimit=std::numeric_limits<T>::max();
00074       };
00075 
00076       /// copy constructor
00077       parameters(const parameters& other)
00078         : iteratingFunctor<T>::parameters() {
00079         copy(other);
00080       };
00081 
00082       /// destructor
00083       ~parameters() {
00084         delete distribution;
00085         distribution = 0;
00086       };
00087 
00088       /// sets the noise distribution
00089       void 
00090       setDistribution(const continuousRandomDistribution& theDistribution) {
00091         delete distribution;
00092         distribution = 
00093           dynamic_cast<continuousRandomDistribution*>(theDistribution.clone());
00094       };
00095 
00096       /// returns current noise distribution.
00097       const continuousRandomDistribution& getDistribution() const {
00098         if (isNull(distribution)) {
00099           throw functor::invalidParametersException(getTypeName());
00100         }
00101         return *distribution;
00102       }
00103 
00104       /// copy data of "other" parameters
00105       parameters& copy(const parameters& other) {
00106 #ifndef _LTI_MSC_6
00107         // MS Visual C++ 6 is not able to compile this...
00108         iteratingFunctor<T>::parameters::copy(other);
00109 #else
00110         // ...so we have to use this workaround.
00111         // Conditional on that, copy may not be virtual.
00112         iteratingFunctor<T>::parameters&
00113           (iteratingFunctor<T>::parameters::* p_copy)
00114           (const iteratingFunctor<T>::parameters&) =
00115           iteratingFunctor<T>::parameters::copy;
00116         (this->*p_copy)(other);
00117 #endif
00118 
00119         if (isNull(other.distribution)) {
00120           distribution = 0;
00121         } else {
00122         distribution =
00123           dynamic_cast<continuousRandomDistribution*>(other.getDistribution().clone());
00124         }
00125 
00126         lowerLimit=other.lowerLimit;
00127         upperLimit=other.upperLimit;
00128 
00129         return (*this);
00130       };
00131 
00132       /// returns a pointer to a clone of the parameters.
00133       virtual functor::parameters* clone() const {
00134         return (new parameters(*this));
00135       };
00136 
00137       /// returns the name of this type
00138       virtual const char* getTypeName() const {
00139         return "noise::parameters";
00140       };
00141 
00142     protected:
00143       /// the random distribution to be used.
00144       continuousRandomDistribution* distribution;
00145     };
00146 
00147     /// default constructor
00148     noise();
00149 
00150     /// constructor, sets the parameters, i.e. the noise distribution.
00151     noise(const parameters& theParams);
00152 
00153     /// constructor, sets the noise distribution
00154     noise(const continuousRandomDistribution& theDistribution);
00155 
00156     /// destructor
00157     virtual ~noise() {};
00158 
00159     /// returns the current parameters.
00160     const parameters& getParameters() const;
00161 
00162     /** onPlace version of apply.
00163         applies the functor's function to 'theObject'. */
00164     virtual vector<T>& apply(vector<T>& theObject) const;
00165 
00166     /** onCopy version of apply.
00167         applies the functor's function to the copy of 'theObject',
00168         'newObject'. */
00169     virtual vector<T>& apply(const vector<T>& theObject,
00170                              vector<T>& newObject) const;
00171 
00172     /** onPlace version of apply.
00173         applies the functor's function to 'theObject'. */
00174     virtual matrix<T>& apply(matrix<T>& theObject) const;
00175 
00176     /** onCopy version of apply.
00177         applies the functor's function to the copy of 'theObject',
00178         'newObject'. */
00179     virtual matrix<T>& apply(const matrix<T>& theObject,
00180                              matrix<T>& newObject) const;
00181 
00182     /// returns a pointer to a clone of the functor.
00183     virtual functor* clone() const { return (new noise<T>(*this));};
00184 
00185     /// returns the name of this type
00186     virtual const char* getTypeName() const {return "noise";};
00187   };
00188 }
00189 
00190 #endif

Generated on Sat Apr 10 15:25:54 2010 for LTI-Lib by Doxygen 1.6.1