ViSP  2.8.0
vpNoise.h
1 /****************************************************************************
2  *
3  * $Id: vpNoise.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 
75 
76  /*unsigned*/ long a ;
77  /*unsigned*/ long m ; //2^31-1
78  /*unsigned*/ long q ; //integer part of m/a
79  /*unsigned*/ long r ;//r=m mod a
80  double normalizer ; //we use a normalizer > m to ensure ans will never be 1 (it is the case if x = 739806647)
81 
82 
83 private:
84  void draw0();
85 protected:
86  long x;
87  double draw1();
88  void init()
89  {
90  a = 16807 ;
91  m = /*(unsigned long)*/2147483647 ; //2^31-1
92  q = 127773 ; //integer part of m/a
93  r = 2836 ;//r=m mod a
94  //we use a normalizer > m to ensure ans will never be
95  // 1 (it is the case if x = 739806647)
96  normalizer = 2147484721.0 ;
97  }
98 
99 public:
100  vpUniRand(const long seed = 0):x((seed)? seed : 739806647)
101  {
102  init() ;
103  }
104  double operator()() {return draw1();}
105 
106 };
107 
133 class vpGaussRand : public vpUniRand
134 {
135  double mean;
136  double sigma;
137 
138 public:
139 
140  // Initialization
141  vpGaussRand() {init();mean=0;sigma=0;x=739806647;}
142  vpGaussRand(const double sqrtvariance,
143  const double _mean,
144  const long seed = 0):mean(_mean), sigma(sqrtvariance)
145  {
146  init() ;
147  mean = 0 ;
148  if (seed) x=seed; else x=739806647;
149  }
156  inline void setSigmaMean(const double _s, const double _m) {mean=_m;sigma=_s;}
162  inline void seed(const long seed) {x=seed;}
163  inline double operator()() {return sigma*gaussianDraw()+mean;}
164 
165 private :
166  double gaussianDraw();
167 };
168 
169 #endif
vpGaussRand(const double sqrtvariance, const double _mean, const long seed=0)
Definition: vpNoise.h:142
vpGaussRand()
Definition: vpNoise.h:141
void seed(const long seed)
Definition: vpNoise.h:162
vpUniRand(const long seed=0)
Definition: vpNoise.h:100
double operator()()
Definition: vpNoise.h:104
double operator()()
Definition: vpNoise.h:163
void init()
Definition: vpNoise.h:88
Class for generating random number with normal probability density.
Definition: vpNoise.h:133
long x
Definition: vpNoise.h:86
void setSigmaMean(const double _s, const double _m)
Definition: vpNoise.h:156
Class for generating random numbers with uniform probability density.
Definition: vpNoise.h:72