last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 2007 00003 * ITCR, Pablo Alvarado 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 /** 00042 * \file cvrUnivariateDiscreteDistribution.h 00043 * Contains the class cvr::univariateDiscreteDistribution, 00044 * parent of all univariate discrete random distributions. 00045 * \author Pablo Alvarado 00046 * \date 23.09.2007 00047 * 00048 * revisions ..: $Id: cvrUnivariateDiscreteDistribution.h,v 1.2 2007/09/28 00:06:17 alvarado Exp $ 00049 */ 00050 00051 #ifndef _CVR_UNIVARIATE_DISCRETE_DISTRIBUTION_H_ 00052 #define _CVR_UNIVARIATE_DISCRETE_DISTRIBUTION_H_ 00053 00054 #include "cvrRandomDistribution.h" 00055 00056 namespace cvr { 00057 00058 /** 00059 * Class univariateDiscreteDistribution 00060 * 00061 * All univariate continuous distributions return random numbers in a 00062 * floating point format. This class establishes the basic interface to 00063 * allow virtual inheritance of the apply methods. 00064 * 00065 * @see univariateDiscreteDistribution::parameters. 00066 * 00067 * @ingroup gRandomDiscrete 00068 */ 00069 class univariateDiscreteDistribution : public randomDistribution { 00070 public: 00071 /** 00072 * Default constructor 00073 */ 00074 univariateDiscreteDistribution(); 00075 00076 /** 00077 * Copy constructor 00078 * @param othe the object to be copied 00079 */ 00080 univariateDiscreteDistribution(const univariateDiscreteDistribution& othe); 00081 00082 /** 00083 * Destructor 00084 */ 00085 virtual ~univariateDiscreteDistribution(); 00086 00087 /** 00088 * Get a random number. 00089 * 00090 * Returns a random number distributed accordingly to the type of the 00091 * current instance. 00092 * 00093 * The univariateDiscreteDistribution can be used to obtain numbers 00094 * in the interval [0,max()]. 00095 * 00096 * @param rnd double reference where the random number has to be left. 00097 * @return true if apply successful or false otherwise. 00098 */ 00099 virtual bool apply(int& rnd) = 0; 00100 00101 /** 00102 * Virtual method to get a integer random number. 00103 * 00104 * Returns a random number distributed accordingly to the type of the 00105 * current instance. 00106 * 00107 * The univariateDiscreteDistribution can be used to obtain numbers 00108 * in the interval [0,max()], where max() is the method of this class. 00109 * 00110 * @return a random float number. 00111 */ 00112 virtual int draw() = 0; 00113 00114 /** 00115 * Non-virtual method to get a integer random number. 00116 * 00117 * Returns a random number distributed accordingly to the type of the 00118 * current instance. 00119 * 00120 * The univariateDiscreteDistribution can be used to obtain numbers 00121 * in the interval [0,max()], where max() is the method of this class. 00122 * 00123 * @return a random float number. 00124 */ 00125 int rand(); 00126 00127 /** 00128 * Virtual method to obtain the maximum possible number 00129 * (inclusive) to be returned by this distribution 00130 */ 00131 virtual int max() const = 0; 00132 00133 /** 00134 * Virtual method to obtain the minimum possible number 00135 * (inclusive) to be returned by this distribution. 00136 */ 00137 virtual int min() const = 0; 00138 00139 /** 00140 * Returns a pointer to a clone of this functor. 00141 */ 00142 virtual univariateDiscreteDistribution* clone() const = 0; 00143 00144 /** 00145 * Returns a pointer to a new instance of this functor. 00146 */ 00147 virtual univariateDiscreteDistribution* newInstance() const = 0; 00148 00149 }; 00150 } 00151 00152 #endif 00153