ViSP  2.9.0
vpNoise.h
1 /****************************************************************************
2  *
3  * $Id: vpNoise.h 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Generation of random number with uniform and normal probability density.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
43 #ifndef vpNoise_hh
44 #define vpNoise_hh
45 
46 
58 #include <visp/vpConfig.h>
59 
60 
72 class VISP_EXPORT vpUniRand
73 {
74  /*unsigned*/ long a ;
75  /*unsigned*/ long m ; //2^31-1
76  /*unsigned*/ long q ; //integer part of m/a
77  /*unsigned*/ long r ;//r=m mod a
78  double normalizer ; //we use a normalizer > m to ensure ans will never be 1 (it is the case if x = 739806647)
79 
80  private:
81  void draw0();
82  protected:
83  long x;
84  double draw1();
85 
86  public:
87  vpUniRand(const long seed = 0)
88  : a(16807), m(2147483647), q(127773), r(2836), normalizer(2147484721.0), x((seed)? seed : 739806647)
89  {
90  }
91  virtual ~vpUniRand() {};
92 
93  double operator()() {return draw1();}
94 
95 };
96 
121 class vpGaussRand : public vpUniRand
122 {
123  private :
124  double mean;
125  double sigma;
126  double gaussianDraw();
127 
128  public:
129 
133  vpGaussRand() : vpUniRand(), mean(0), sigma(0) {}
134 
142  vpGaussRand(const double sigma_val, const double mean_val, const long noise_seed = 0)
143  : vpUniRand(noise_seed), mean(mean_val), sigma(sigma_val) {}
144 
151  void setSigmaMean(const double sigma_val, const double mean_val) {
152  this->mean = mean_val;
153  this->sigma = sigma_val;
154  }
155 
161  void seed(const long seed_val) {
162  x=seed_val;
163  }
164 
168  double operator()() {
169  return sigma*gaussianDraw()+mean;
170  }
171 };
172 
173 #endif
vpGaussRand()
Definition: vpNoise.h:133
void setSigmaMean(const double sigma_val, const double mean_val)
Definition: vpNoise.h:151
void seed(const long seed_val)
Definition: vpNoise.h:161
virtual ~vpUniRand()
Definition: vpNoise.h:91
vpUniRand(const long seed=0)
Definition: vpNoise.h:87
double operator()()
Definition: vpNoise.h:93
double operator()()
Definition: vpNoise.h:168
vpGaussRand(const double sigma_val, const double mean_val, const long noise_seed=0)
Definition: vpNoise.h:142
Class for generating random number with normal probability density.
Definition: vpNoise.h:121
long x
Definition: vpNoise.h:83
Class for generating random numbers with uniform probability density.
Definition: vpNoise.h:72