Visual Servoing Platform  version 3.6.1 under development (2024-12-07)
vpGaussRand Class Reference

#include <visp3/core/vpGaussRand.h>

Public Member Functions

 vpGaussRand ()
 
 vpGaussRand (double sigma_val, double mean_val, long noise_seed=0)
 
void setSigmaMean (double sigma_val, double mean_val)
 
void seed (long seed_val)
 
double operator() ()
 

Detailed Description

Class for generating random number with normal probability density.

The algorithms and notations used are described in [16].

The code below shows how to use the random generator to get values that have their mean equal to 10 with a standard deviation equal to 0.5.

#include <iostream>
#include <visp3/core/vpGaussRand.h>
int main()
{
vpGaussRand noise(0.5, 10);
for(int i=0; i< 10; i++) {
std::cout << "noise " << i << ": " << noise() << std::endl;
}
return 0;
}
Class for generating random number with normal probability density.
Definition: vpGaussRand.h:117

The previous example produces the following printings:

noise 0: 10.645
noise 1: 9.67129
noise 2: 10.1208
noise 3: 10.1039
noise 4: 10.8667
noise 5: 9.89823
noise 6: 9.81414
noise 7: 9.96076
noise 8: 11.0795
noise 9: 9.79229

Note that the previous example produces always the same "random" results. To produce real random values, you need to initialize the random generator with different values using seed(). For example, this could be done using the current time. The code becomes:

#include <iostream>
#include <visp3/core/vpGaussRand.h>
#include <visp3/core/vpTime.h>

int main()
{
  vpGaussRand noise(0.5, 10);
  long seed = (long)vpTime::measureTimeMs();

  noise.seed(seed);
  for(int i=0; i< 10; i++) {
    std::cout << "noise " << i << ": " << noise() << std::endl;
  }
  return 0;
}

Now if you run the previous example you will always get different values:

noise 0: 10.5982
noise 1: 9.19111
noise 2: 9.82498
noise 3: 9.07857
noise 4: 9.9285
noise 5: 10.3688
noise 6: 9.75621
noise 7: 10.3259
noise 8: 10.4238
noise 9: 10.2391
Examples
ClassUsingPclViewer.cpp, catchLineFitting.cpp, catchParticleFilter.cpp, catchPoseRansac2.cpp, catchRand.cpp, pf-nonlinear-complex-example.cpp, pf-nonlinear-example.cpp, testPose.cpp, testTukeyEstimator.cpp, tutorial-meandrift.cpp, tutorial-pf.cpp, tutorial-ukf.cpp, ukf-linear-example.cpp, ukf-nonlinear-complex-example.cpp, and ukf-nonlinear-example.cpp.

Definition at line 116 of file vpGaussRand.h.

Constructor & Destructor Documentation

◆ vpGaussRand() [1/2]

vpGaussRand::vpGaussRand ( )
inline

Default noise generator constructor.

Definition at line 122 of file vpGaussRand.h.

◆ vpGaussRand() [2/2]

vpGaussRand::vpGaussRand ( double  sigma_val,
double  mean_val,
long  noise_seed = 0 
)
inline

Gaussian noise random generator constructor.

Parameters
sigma_val: Standard deviation.
mean_val: Mean value.
noise_seed: Seed of the noise

Definition at line 131 of file vpGaussRand.h.

Member Function Documentation

◆ operator()()

double vpGaussRand::operator() ( )
inline

Return a random value from the Gaussian noise generator.

Definition at line 160 of file vpGaussRand.h.

◆ seed()

void vpGaussRand::seed ( long  seed_val)
inline

Set the seed of the noise.

Parameters
seed_val: New seed.
Examples
ClassUsingPclViewer.cpp, and testTukeyEstimator.cpp.

Definition at line 152 of file vpGaussRand.h.

◆ setSigmaMean()

void vpGaussRand::setSigmaMean ( double  sigma_val,
double  mean_val 
)
inline

Set the standard deviation and mean for gaussian noise.

Parameters
sigma_val: New standard deviation sigma.
mean_val: New mean value.
Examples
ClassUsingPclViewer.cpp.

Definition at line 141 of file vpGaussRand.h.