SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLRnd3f.h
Go to the documentation of this file.
1 /**
2  * \file SLRnd3f.h
3  * \date October 2017
4  * \authors Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef SLRND3F_H
11 #define SLRND3F_H
12 
13 #include <SLVec3.h>
14 
15 //-----------------------------------------------------------------------------
16 //! Abstract base class for random 3D point generator
17 class SLRnd3f
18 {
19 public:
20  virtual SLVec3f generate() = 0;
21 
22 protected:
23  std::default_random_engine _generator;
24 };
25 //-----------------------------------------------------------------------------
26 //! Class for random generator for normal distributed 3D points
27 class SLRnd3fNormal : public SLRnd3f
28 {
29 public:
31  {
32  _xDistribution = new std::normal_distribution<SLfloat>(mean.x, stddev.x);
33  _yDistribution = new std::normal_distribution<SLfloat>(mean.y, stddev.y);
34  _zDistribution = new std::normal_distribution<SLfloat>(mean.z, stddev.z);
35  }
36 
38  {
39  delete _xDistribution;
40  delete _yDistribution;
41  delete _zDistribution;
42  }
43 
45  {
46  SLfloat x = _xDistribution->operator()(_generator);
47  SLfloat y = _yDistribution->operator()(_generator);
48  SLfloat z = _zDistribution->operator()(_generator);
49  return SLVec3f(x, y, z);
50  }
51 
52 private:
53  std::normal_distribution<SLfloat>* _xDistribution;
54  std::normal_distribution<SLfloat>* _yDistribution;
55  std::normal_distribution<SLfloat>* _zDistribution;
56 };
57 //-----------------------------------------------------------------------------
58 //! Class for random generator for uniform distributed 3D points
59 class SLRnd3fUniform : public SLRnd3f
60 {
61 public:
63  {
64  _xDistribution = new std::uniform_real_distribution<SLfloat>(min.x, max.x);
65  _yDistribution = new std::uniform_real_distribution<SLfloat>(min.y, max.y);
66  _zDistribution = new std::uniform_real_distribution<SLfloat>(min.z, max.z);
67  }
68 
70  {
71  delete _xDistribution;
72  delete _yDistribution;
73  delete _zDistribution;
74  }
75 
77  {
78  SLfloat x = _xDistribution->operator()(_generator);
79  SLfloat y = _yDistribution->operator()(_generator);
80  SLfloat z = _zDistribution->operator()(_generator);
81  return SLVec3f(x, y, z);
82  }
83 
84 private:
85  std::uniform_real_distribution<SLfloat>* _xDistribution;
86  std::uniform_real_distribution<SLfloat>* _yDistribution;
87  std::uniform_real_distribution<SLfloat>* _zDistribution;
88 };
89 //-----------------------------------------------------------------------------
90 #endif
float SLfloat
Definition: SL.h:173
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
Abstract base class for random 3D point generator.
Definition: SLRnd3f.h:18
virtual SLVec3f generate()=0
std::default_random_engine _generator
Definition: SLRnd3f.h:23
Class for random generator for normal distributed 3D points.
Definition: SLRnd3f.h:28
SLVec3f generate()
Definition: SLRnd3f.h:44
std::normal_distribution< SLfloat > * _zDistribution
Definition: SLRnd3f.h:55
SLRnd3fNormal(SLVec3f mean, SLVec3f stddev)
Definition: SLRnd3f.h:30
std::normal_distribution< SLfloat > * _xDistribution
Definition: SLRnd3f.h:53
std::normal_distribution< SLfloat > * _yDistribution
Definition: SLRnd3f.h:54
~SLRnd3fNormal()
Definition: SLRnd3f.h:37
Class for random generator for uniform distributed 3D points.
Definition: SLRnd3f.h:60
std::uniform_real_distribution< SLfloat > * _xDistribution
Definition: SLRnd3f.h:85
~SLRnd3fUniform()
Definition: SLRnd3f.h:69
SLVec3f generate()
Definition: SLRnd3f.h:76
SLRnd3fUniform(SLVec3f min, SLVec3f max)
Definition: SLRnd3f.h:62
std::uniform_real_distribution< SLfloat > * _zDistribution
Definition: SLRnd3f.h:87
std::uniform_real_distribution< SLfloat > * _yDistribution
Definition: SLRnd3f.h:86
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
T z
Definition: SLVec3.h:43