latest version v1.9 - last update 10 Apr 2010 |
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 .......: ltiUniformDist.h 00027 * authors ....: Thomas Rusert 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 19.05.99 00030 * revisions ..: $Id: ltiUniformDist.h,v 1.9 2006/02/08 12:51:38 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_UNIFORMDIST_H_ 00034 #define _LTI_UNIFORMDIST_H_ 00035 00036 #include "ltiContinuousRandDist.h" 00037 00038 namespace lti { 00039 /** 00040 * Uniform distributed random number class. 00041 */ 00042 class uniformDistribution : public continuousRandomDistribution { 00043 public: 00044 /** 00045 * parameters class for the uniform distribution 00046 */ 00047 class parameters : public continuousRandomDistribution::parameters { 00048 public: 00049 /** 00050 * default constructor 00051 */ 00052 parameters() : lowerLimit(0),upperLimit(1) {}; 00053 00054 /** 00055 * copy constructor 00056 */ 00057 parameters(const parameters& other) 00058 : continuousRandomDistribution::parameters() { 00059 copy(other); 00060 }; 00061 00062 /** 00063 * destructor 00064 */ 00065 ~parameters() {}; 00066 00067 /** 00068 * lower limit (inclusive) 00069 */ 00070 double lowerLimit; 00071 00072 /** 00073 * upper limit (exclusive) 00074 */ 00075 double upperLimit; 00076 00077 /** 00078 * copy data of "other" parameters 00079 */ 00080 parameters& copy(const parameters& other) { 00081 #ifndef _LTI_MSC_6 00082 // MS Visual C++ 6 is not able to compile this... 00083 continuousRandomDistribution::parameters::copy(other); 00084 #else 00085 // ...so we have to use this workaround. 00086 // Conditional on that, copy may not be virtual. 00087 continuousRandomDistribution::parameters& 00088 (continuousRandomDistribution::parameters::* p_copy) 00089 (const continuousRandomDistribution::parameters&) = 00090 continuousRandomDistribution::parameters::copy; 00091 (this->*p_copy)(other); 00092 #endif 00093 00094 lowerLimit = other.lowerLimit; 00095 upperLimit = other.upperLimit; 00096 00097 return (*this); 00098 } 00099 00100 /** 00101 * returns a pointer to a clone of the parameters. 00102 */ 00103 virtual functor::parameters* clone() const { 00104 return (new parameters(*this)); 00105 }; 00106 00107 /** 00108 * returns the name of this type 00109 */ 00110 virtual const char* getTypeName() const { 00111 return "uniformDistribution::parameters"; 00112 }; 00113 }; 00114 00115 /** 00116 * default constructor. 00117 * Sets lower (inclusive) and upper (exclusive) limit of the distribution. 00118 */ 00119 uniformDistribution(const double& lower=0.0, 00120 const double& upper=1.0); 00121 00122 /** 00123 * Constructor. 00124 * 00125 * Sets lower (inclusive) and upper (exclusive) limit of the distribution. 00126 * Additionally, it initializes the random number generation with the 00127 * given seed. This is sometimes necessary, when the algorithms that uses 00128 * random number, still should behave "deterministically", in the sense 00129 * that the results should always be the same. 00130 * 00131 * The value of the seed follows the same rules as the C function srand. 00132 * 00133 * If you don't know what to give, just give "1". 00134 */ 00135 uniformDistribution(const double& lower, 00136 const double& upper, 00137 const unsigned int seed); 00138 00139 /** 00140 * constructor, sets the parameters 00141 */ 00142 uniformDistribution(const parameters& theParams); 00143 00144 /** 00145 * destructor 00146 */ 00147 virtual ~uniformDistribution() {}; 00148 00149 /** 00150 * returns the current parameters. 00151 */ 00152 const parameters& getParameters() const; 00153 00154 /** 00155 * set functor's parameters. 00156 * This member makes a copy of <em>theParam</em>: the functor 00157 * will keep its own copy of the parameters! 00158 * @return true if successful, false otherwise 00159 */ 00160 virtual bool updateParameters(); 00161 00162 /** 00163 * Draws a uniform distributed random number between lowerLimit 00164 * (inclusive) and upperLimit (exclusive). Use lowerLimit>upperLimit if 00165 * you want to have numbers excluding the lower limit (=upperLimit) and 00166 * including the upper limit (=lowerLimit). 00167 */ 00168 virtual double draw() const; 00169 00170 /** 00171 * returns a pointer to a clone of the functor. 00172 */ 00173 virtual functor* clone() const { 00174 return (new uniformDistribution(*this)); 00175 }; 00176 00177 /** 00178 * returns the name of this type 00179 */ 00180 virtual const char* getTypeName() const { 00181 return "uniformDistribution"; 00182 }; 00183 00184 protected: 00185 /** 00186 * scaling constant for random number generator 00187 */ 00188 double m; 00189 00190 /** 00191 * shift constant 00192 */ 00193 double b; 00194 }; 00195 } 00196 00197 #endif