latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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 .......: ltiDiscreteRandDist.h 00027 * authors ....: Peter Doerfler 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 26.03.02 00030 * revisions ..: $Id: ltiDiscreteRandDist.h,v 1.6 2006/02/08 12:17:15 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_DISCRETERANDDIST_H_ 00034 #define _LTI_DISCRETERANDDIST_H_ 00035 00036 #include "ltiRandDist.h" 00037 00038 namespace lti { 00039 /** 00040 * Base random number class. 00041 * 00042 * 00043 */ 00044 class discreteRandomDistribution : 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 discreteRandomDistribution object. 00079 */ 00080 discreteRandomDistribution(bool reInit=false); 00081 00082 /** 00083 * this constructor initializes the pseudo-random number generator 00084 * using the given value 00085 */ 00086 discreteRandomDistribution(const unsigned int theValue); 00087 00088 /** 00089 * destructor 00090 */ 00091 virtual ~discreteRandomDistribution(); 00092 00093 /** 00094 * draws a number from the distribution. 00095 * Returns either 1 or 0, for occurence of the event or not. 00096 */ 00097 virtual int draw() const=0; 00098 00099 /** 00100 * draws a number from the specified distribution using the virtual 00101 * function draw(). 00102 */ 00103 template<class T> 00104 bool apply(T& theObject) const { 00105 theObject = T(draw()); 00106 return true; 00107 }; 00108 00109 /** 00110 * returns a pointer to a clone of the functor. 00111 */ 00112 virtual functor* clone() const=0; 00113 00114 /** 00115 * returns the name of this type 00116 */ 00117 virtual const char* getTypeName() const { 00118 return "discreteRandomDistribution"; 00119 }; 00120 00121 /** 00122 * copy member 00123 */ 00124 discreteRandomDistribution& copy(const discreteRandomDistribution& other); 00125 00126 }; 00127 } 00128 00129 #endif