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 .......: ltiRandDist.h 00027 * authors ....: Thomas Rusert 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 21.04.99 00030 * revisions ..: $Id: ltiContinuousRandDist.h,v 1.9 2006/02/08 12:15:03 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_CONTINUOUSRANDDIST_H_ 00034 #define _LTI_CONTINUOUSRANDDIST_H_ 00035 00036 #include "ltiRandDist.h" 00037 00038 namespace lti { 00039 /** 00040 * Base random number class. 00041 * 00042 * 00043 */ 00044 class continuousRandomDistribution : public randomDistribution { 00045 public: 00046 00047 /** 00048 * parameters of the random distribution 00049 */ 00050 class parameters : public randomDistribution::parameters { 00051 public: 00052 /** 00053 * copy data of "other" parameters 00054 */ 00055 parameters& copy(const parameters& other) { 00056 #ifndef _LTI_MSC_6 00057 // MS Visual C++ 6 is not able to compile this... 00058 randomDistribution::parameters::copy(other); 00059 #else 00060 // ...so we have to use this workaround. 00061 // Conditional on that, copy may not be virtual. 00062 randomDistribution::parameters& 00063 (randomDistribution::parameters::*p_copy)(const randomDistribution::parameters&) = 00064 randomDistribution::parameters::copy; 00065 (this->*p_copy)(other); 00066 #endif 00067 00068 return *this; 00069 }; 00070 00071 }; 00072 00073 /** 00074 * default constructor. 00075 * 00076 * Initializes the pseudo-random number generator using system time. 00077 * If reInit is false, the generator is initialized only when 00078 * instantiating the first continuousRandomDistribution object. 00079 */ 00080 continuousRandomDistribution(bool reInit=false); 00081 00082 /** 00083 * this constructor initializes the pseudo-random number generator 00084 * using the given value 00085 */ 00086 continuousRandomDistribution(const unsigned int theValue); 00087 00088 /** 00089 * destructor 00090 */ 00091 virtual ~continuousRandomDistribution(); 00092 00093 /** 00094 * draws a number from the distribution. For this class the values 00095 * are distributed uniformly in [0;1). This method always (for 00096 * any distribution) returns a value between 0.0 (inclusive) and 00097 * 1.0 (exclusive). 00098 */ 00099 inline virtual double draw() const { 00100 return random(); 00101 } 00102 00103 /** 00104 * draws a number from the specified distribution using the virtual 00105 * function draw(). 00106 */ 00107 template<class T> 00108 bool apply(T& theObject) const { 00109 theObject = T(draw()); 00110 return true; 00111 }; 00112 00113 /** 00114 * returns a pointer to a clone of the functor. 00115 */ 00116 virtual functor* clone() const { 00117 return (new continuousRandomDistribution(*this)); 00118 }; 00119 00120 /** 00121 * returns the name of this type 00122 */ 00123 virtual const char* getTypeName() const { 00124 return "continuousRandomDistribution"; 00125 }; 00126 00127 /** 00128 * copy member 00129 */ 00130 continuousRandomDistribution& 00131 copy(const continuousRandomDistribution& other); 00132 00133 }; 00134 } 00135 00136 #endif