Visual Servoing Platform version 3.5.0
vpGaussRand.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See http://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Generation of random number with uniform and normal probability density.
33 *
34 * Authors:
35 * Eric Marchand
36 *
37 *****************************************************************************/
38
39#ifndef vpGaussRand_hh
40#define vpGaussRand_hh
41
42#include <visp3/core/vpConfig.h>
43#include <visp3/core/vpUniRand.h>
44
120class VISP_EXPORT vpGaussRand
121{
122private:
123 double gaussianDraw();
124
125 vpUniRand m_rng;
126 double m_mean;
127 double m_sigma;
128 bool m_AlreadyDone;
129 double m_x2;
130
131public:
135 vpGaussRand() : m_rng(), m_mean(0), m_sigma(0), m_AlreadyDone(false), m_x2(0) {}
136
144 vpGaussRand(double sigma_val, double mean_val, long noise_seed = 0)
145 : m_rng(noise_seed), m_mean(mean_val), m_sigma(sigma_val), m_AlreadyDone(false), m_x2(0)
146 {
147 }
148
155 void setSigmaMean(double sigma_val, double mean_val)
156 {
157 m_mean = mean_val;
158 m_sigma = sigma_val;
159 }
160
166 void seed(long seed_val) { m_rng.setSeed(seed_val, 0x123465789ULL); }
167
171 double operator()() { return m_sigma * gaussianDraw() + m_mean; }
172};
173
174#endif
Class for generating random number with normal probability density.
Definition: vpGaussRand.h:121
void setSigmaMean(double sigma_val, double mean_val)
Definition: vpGaussRand.h:155
vpGaussRand(double sigma_val, double mean_val, long noise_seed=0)
Definition: vpGaussRand.h:144
double operator()()
Definition: vpGaussRand.h:171
void seed(long seed_val)
Definition: vpGaussRand.h:166
Class for generating random numbers with uniform probability density.
Definition: vpUniRand.h:101
void setSeed(uint64_t initstate, uint64_t initseq)
Definition: vpUniRand.cpp:212