CVR-Lib last update 20 Sep 2009

cvrUniformContinuousDistribution.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007
00003  * 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   cvrUniformContinuousDistribution.h
00043  *         Contains the class cvr::uniformContinuousDistribution to
00044  *         produce random integers uniformly distributed in an specified
00045  *         interval
00046  * \author Pablo Alvarado
00047  * \date   25.09.2007
00048  *
00049  * revisions ..: $Id: cvrUniformContinuousDistribution.h,v 1.1 2007/09/26 21:21:52 alvarado Exp $
00050  */
00051 
00052 #ifndef _CVR_UNIFORM_CONTINUOUS_DISTRIBUTION_H_
00053 #define _CVR_UNIFORM_CONTINUOUS_DISTRIBUTION_H_
00054 
00055 #include "cvrUnivariateContinuousDistribution.h"
00056 
00057 namespace cvr {
00058 
00059   /**
00060    * Class uniformContinuousDistribution
00061    *
00062    * This class generates (pseudo) random numbers uniformly distributed in an
00063    * interval specified in the parameters.
00064    *
00065    * @see uniformContinuousDistribution::parameters.
00066    *
00067    * @ingroup gRandomContinuous
00068    */
00069   class uniformContinuousDistribution :
00070     public univariateContinuousDistribution {
00071 
00072   public:
00073     /**
00074      * The parameters for the class uniformContinuousDistribution
00075      */
00076     class parameters : public univariateContinuousDistribution::parameters {
00077     public:
00078       /**
00079        * Default constructor
00080        */
00081       parameters();
00082 
00083       /**
00084        * Copy constructor
00085        * @param other the parameters object to be copied
00086        */
00087       parameters(const parameters& other);
00088 
00089       /**
00090        * Destructor
00091        */
00092       ~parameters();
00093 
00094       /**
00095        * Copy the contents of a parameters object
00096        * @param other the parameters object to be copied
00097        * @return a reference to this parameters object
00098        */
00099       parameters& copy(const parameters& other);
00100 
00101       /**
00102        * Copy the contents of a parameters object
00103        * @param other the parameters object to be copied
00104        * @return a reference to this parameters object
00105        */
00106       parameters& operator=(const parameters& other);
00107 
00108       /**
00109        * Returns the complete name of the parameters class.
00110        */
00111       virtual const std::string& name() const;
00112 
00113       /**
00114        * Returns a pointer to a clone of the parameters.
00115        */
00116       virtual parameters* clone() const;
00117 
00118       /**
00119        * Returns a pointer to a new instance of the parameters.
00120        */
00121       virtual parameters* newInstance() const;
00122 
00123       /**
00124        * Write the parameters in the given ioHandler
00125        * @param handler the ioHandler to be used
00126        * @param complete if true (the default) the enclosing begin/end will
00127        *        be also written, otherwise only the data block will be written.
00128        * @return true if write was successful
00129        */
00130       virtual bool write(ioHandler& handler,const bool complete=true) const;
00131 
00132       /**
00133        * Read the parameters from the given ioHandler
00134        * @param handler the ioHandler to be used
00135        * @param complete if true (the default) the enclosing begin/end will
00136        *        be also written, otherwise only the data block will be written.
00137        * @return true if write was successful
00138        */
00139       virtual bool read(ioHandler& handler,const bool complete=true);
00140 
00141       // ------------------------------------------------
00142       // the parameters
00143       // ------------------------------------------------
00144 
00145       /**
00146        * Lower bound of the value interval (inclusive).
00147        *
00148        * This is the smallest value that can be generated.
00149        *
00150        * Default value: 0.0
00151        */
00152       double min;
00153 
00154       /**
00155        * Higher bound of the value interval (exclusive).
00156        *
00157        * This is the highest value that can be generated.
00158        *
00159        * Default value: 1.0
00160        */
00161       double max;
00162 
00163     };
00164 
00165     /**
00166      * Default constructor
00167      */
00168     uniformContinuousDistribution();
00169 
00170     /**
00171      * Constructor with a given interval.
00172      *
00173      * @param min lower interval bound.
00174      * @param max higher interval bound.
00175      */
00176     uniformContinuousDistribution(const double min,const double max);
00177 
00178     /**
00179      * Construct a functor using the given parameters
00180      */
00181     uniformContinuousDistribution(const parameters& par);
00182 
00183     /**
00184      * Copy constructor
00185      * @param other the object to be copied
00186      */
00187     uniformContinuousDistribution(const uniformContinuousDistribution& other);
00188 
00189     /**
00190      * Destructor
00191      */
00192     virtual ~uniformContinuousDistribution();
00193 
00194     /**
00195      * Get a random number.
00196      *
00197      * Returns a random number distributed accordingly to the type of the
00198      * current instance.
00199      *
00200      * @param rnd double reference where the random number has to be left.
00201      * @return true if apply successful or false otherwise.
00202      */
00203     virtual bool apply(float& rnd);
00204 
00205     /**
00206      * Get a random number.
00207      *
00208      * Returns a random number distributed accordingly to the type of the
00209      * current instance.
00210      *
00211      * @param rnd double reference where the random number has to be left.
00212      * @return true if apply successful or false otherwise.
00213      */
00214     virtual bool apply(double& rnd);
00215 
00216     /**
00217      * Virtual method to get a single precision random number.
00218      *
00219      * Returns a random number distributed accordingly to the type of the
00220      * current instance.
00221      *
00222      * The univariateContinuousDistribution can be used to obtain numbers
00223      * in the interval [0,max()], where max() is the method of this class.
00224      *
00225      * @return a random float number.
00226      */
00227     virtual float fdraw();
00228 
00229     /**
00230      * Virtual method to get a double precision random number.
00231      *
00232      * Returns a random number distributed accordingly to the type of the
00233      * current instance.
00234      *
00235      * The univariateContinuousDistribution can be used to obtain numbers
00236      * in the interval [0,max()], where max() is the method of this class.
00237      *
00238      * @return a random float number.
00239      */
00240     virtual double draw();
00241 
00242     /**
00243      * Non-virtual method to get a single precision random number.
00244      *
00245      * Returns a random number distributed accordingly to the type of the
00246      * current instance.
00247      *
00248      * This method can be used to obtain numbers in the interval [min(),max()].
00249      *
00250      * @return a random float number.
00251      */
00252     float frand();
00253 
00254     /**
00255      * Non-virtual method to get a double precision random number.
00256      *
00257      * Returns a random number distributed accordingly to the type of the
00258      * current instance.
00259      *
00260      * This method can be used to obtain numbers in the interval [min(),max()].
00261      *
00262      * @return a random double number.
00263      */
00264     double rand();
00265 
00266     /**
00267      * Virtual method to obtain the minimum possible number
00268      * (inclusive) to be returned by this distribution.
00269      */
00270     double min();
00271 
00272     /**
00273      * Virtual method to obtain the maximum possible number
00274      * (exclusive) to be returned by this distribution.
00275      */
00276     double max();
00277 
00278     /**
00279      * Copy data of "other" functor.
00280      * @param other the functor to be copied
00281      * @return a reference to this functor object
00282      */
00283     uniformContinuousDistribution&
00284     copy(const uniformContinuousDistribution& other);
00285 
00286     /**
00287      * Alias for copy member
00288      * @param other the functor to be copied
00289      * @return a reference to this functor object
00290      */
00291     uniformContinuousDistribution&
00292     operator=(const uniformContinuousDistribution& other);
00293 
00294     /**
00295      * Returns the complete name of the functor class
00296      */
00297     virtual const std::string& name() const;
00298 
00299     /**
00300      * Returns a pointer to a clone of this functor.
00301      */
00302     virtual uniformContinuousDistribution* clone() const;
00303 
00304     /**
00305      * Returns a pointer to a new instance of this functor.
00306      */
00307     virtual uniformContinuousDistribution* newInstance() const;
00308 
00309     /**
00310      * Returns used parameters
00311      */
00312     const parameters& getParameters() const;
00313 
00314     /**
00315      * Update parameters
00316      */
00317     bool updateParameters();
00318 
00319   protected:
00320     /**
00321      * Shadow of the parameters.min;
00322      */
00323     double minimum_;
00324 
00325     /**
00326      * Shadow of the parameters.max;
00327      */
00328     double maximum_;
00329 
00330     /**
00331      * Shadow of the parameters.min;
00332      */
00333     float fminimum_;
00334 
00335     /**
00336      * Shadow of the parameters.max;
00337      */
00338     float fmaximum_;
00339 
00340     /**
00341      * delta_ = (maximum_ - minimum_)*dnorm_
00342      */
00343     double delta_;
00344 
00345     /**
00346      * delta_ = (maximum_ - minimum_)*fnorm_
00347      */
00348     float fdelta_;
00349   };
00350 }
00351 
00352 #endif
00353 

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8