ViSP  2.10.0
vpNoise.h
1 /****************************************************************************
2  *
3  * $Id: vpNoise.h 5179 2015-01-16 09:42:33Z 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 
56 #include <visp/vpConfig.h>
57 
58 
68 class VISP_EXPORT vpUniRand
69 {
70  /*unsigned*/ long a ;
71  /*unsigned*/ long m ; //2^31-1
72  /*unsigned*/ long q ; //integer part of m/a
73  /*unsigned*/ long r ;//r=m mod a
74  double normalizer ; //we use a normalizer > m to ensure ans will never be 1 (it is the case if x = 739806647)
75 
76  private:
77  void draw0();
78  protected:
79  long x;
80  double draw1();
81 
82  public:
83  vpUniRand(const long seed = 0)
84  : a(16807), m(2147483647), q(127773), r(2836), normalizer(2147484721.0), x((seed)? seed : 739806647)
85  {
86  }
87  virtual ~vpUniRand() {};
88 
89  double operator()() {return draw1();}
90 
91 };
92 
167 class VISP_EXPORT vpGaussRand : public vpUniRand
168 {
169  private :
170  double mean;
171  double sigma;
172  double gaussianDraw();
173 
174  public:
175 
179  vpGaussRand() : vpUniRand(), mean(0), sigma(0) {}
180 
188  vpGaussRand(const double sigma_val, const double mean_val, const long noise_seed = 0)
189  : vpUniRand(noise_seed), mean(mean_val), sigma(sigma_val) {}
190 
197  void setSigmaMean(const double sigma_val, const double mean_val) {
198  this->mean = mean_val;
199  this->sigma = sigma_val;
200  }
201 
207  void seed(const long seed_val) {
208  x=seed_val;
209  }
210 
214  double operator()() {
215  return sigma*gaussianDraw()+mean;
216  }
217 };
218 
219 #endif
vpGaussRand()
Definition: vpNoise.h:179
void setSigmaMean(const double sigma_val, const double mean_val)
Definition: vpNoise.h:197
void seed(const long seed_val)
Definition: vpNoise.h:207
virtual ~vpUniRand()
Definition: vpNoise.h:87
vpUniRand(const long seed=0)
Definition: vpNoise.h:83
double operator()()
Definition: vpNoise.h:89
double operator()()
Definition: vpNoise.h:214
vpGaussRand(const double sigma_val, const double mean_val, const long noise_seed=0)
Definition: vpNoise.h:188
Class for generating random number with normal probability density.
Definition: vpNoise.h:167
long x
Definition: vpNoise.h:79
Class for generating random numbers with uniform probability density.
Definition: vpNoise.h:68