Helios++
Helios software for LiDAR simulations
UniformNoiseSource.h
1 #pragma once
2 
3 #include <noise/RandomNoiseSource.h>
4 
14 template <typename RealType>
15 class UniformNoiseSource : public RandomNoiseSource<RealType>{
16 protected:
17  // *** ATTRIBUTES *** //
18  // ******************** //
22  RealType uniformNoiseMin = 0.0;
26  RealType uniformNoiseMax = 1.0;
27 
28 public:
29  // *** CONSTRUCTION *** //
30  // ********************* //
39  RealType uniformNoiseMin = 0.0,
40  RealType uniformNoiseMax = 1.0
41  ):
42  RandomNoiseSource<RealType>(rg),
43  uniformNoiseMin(uniformNoiseMin),
44  uniformNoiseMax(uniformNoiseMax)
45  {
47  uniformNoiseMin,
48  uniformNoiseMax
49  );
50  this->build();
51  }
59  std::string const & seed,
60  RealType uniformNoiseMin = 0.0,
61  RealType uniformNoiseMax = 1.0
62  ):
63  RandomNoiseSource<RealType>(seed),
64  uniformNoiseMin(uniformNoiseMin),
65  uniformNoiseMax(uniformNoiseMax)
66  {
67  this->rg.computeUniformRealDistribution(
68  uniformNoiseMin,
69  uniformNoiseMax
70  );
71  this->build();
72  }
79  RealType uniformNoiseMin = 0.0,
80  RealType uniformNoiseMax = 1.0
81  ):
82  RandomNoiseSource<RealType>(),
83  uniformNoiseMin(uniformNoiseMin),
84  uniformNoiseMax(uniformNoiseMax)
85  {
86  this->rg.computeUniformRealDistribution(
87  uniformNoiseMin,
88  uniformNoiseMax
89  );
90  this->build();
91  }
92 
93  // *** GETTERS and SETTERS *** //
94  // ***************************** /
99  RealType getMin()
100  {return this->uniformNoiseMin;}
114  UniformNoiseSource & setMin(RealType min)
115  {return this->configureUniformNoise(min, this->uniformNoiseMax);}
120  RealType getMax()
121  {return this->uniformNoiseMax;}
135  UniformNoiseSource & setMax(RealType max)
136  {return this->configureUniformNoise(this->uniformNoiseMin, max);}
137 
138  // *** NOISE CONFIGURATION FUNCTIONS *** //
139  // *************************************** //
147  UniformNoiseSource & configureUniformNoise(RealType min, RealType max);
151  std::string getRandomNoiseType() override
152  {return "UNIFORM";}
153 
154  // *** NOISE OBTAINMENT FUNCTIONS *** //
155  // ************************************ //
161  RealType noiseFunction() override
162  {return this->rg.uniformRealDistributionNext();}
163 
164  // *** STREAM OPERATORS *** //
165  // ************************** //
169  template<typename _RealType>
170  friend std::ostream& operator << (
171  std::ostream &out,
173  );
174 };
175 
176 
177 
178 
179 // *** CLASS IMPLEMENTATION *** //
180 // ********************************* //
181 template <typename RealType>
184  RealType min,
185  RealType max
186 ){
187  this->uniformNoiseMin = min;
188  this->uniformNoiseMax = max;
189  this->rg.computeUniformRealDistribution(min, max);
190  return *this;
191 }
192 
193 // *** STREAM OPERATORS *** //
194 // ************************** //
195 template<typename RealType>
196 std::ostream& operator<<(std::ostream &out, UniformNoiseSource<RealType> &ns){
197  out << static_cast<RandomNoiseSource<RealType>&>(ns);
198  out << "\t\tUniformNoiseSource:\n"
199  << "\t\t\tuniformNoiseMin = " << ns.getMin() << "\n"
200  << "\t\t\tuniformNoiseMax = " << ns.getMax() << "\n";
201  return out;
202 }
UniformNoiseSource & setMax(RealType max)
Set the current maximum for uniform noise generation.
Definition: UniformNoiseSource.h:135
RandomnessGenerator< RealType > rg
RandomnessGenerator to be used to generate random noise.
Definition: RandomNoiseSource.h:23
friend std::ostream & operator<<(std::ostream &out, UniformNoiseSource< _RealType > &ns)
Output stream behavior.
Class to generate random numbers.
Definition: RandomnessGenerator.h:25
RealType uniformNoiseMax
The maximum value the uniform noise is configured to support.
Definition: UniformNoiseSource.h:26
RealType getMax()
Obtain the current maximum for uniform noise generation.
Definition: UniformNoiseSource.h:120
UniformNoiseSource(RandomnessGenerator< RealType > const &rg, RealType uniformNoiseMin=0.0, RealType uniformNoiseMax=1.0)
Create a UniformNoiseSource using received RandomnessGenerator.
Definition: UniformNoiseSource.h:37
UniformNoiseSource(RealType uniformNoiseMin=0.0, RealType uniformNoiseMax=1.0)
Create default UniformNoiseSource.
Definition: UniformNoiseSource.h:78
Class for uniform noise handling.
Definition: UniformNoiseSource.h:15
RealType uniformNoiseMin
The minimum value the uniform noise is configured to support.
Definition: UniformNoiseSource.h:22
UniformNoiseSource(std::string const &seed, RealType uniformNoiseMin=0.0, RealType uniformNoiseMax=1.0)
Create a UniformNoiseSource using received seed.
Definition: UniformNoiseSource.h:58
UniformNoiseSource & setMin(RealType min)
Set the current minimum for uniform noise generation.
Definition: UniformNoiseSource.h:114
void build()
Common behavior for all NoiseSource constructors.
Definition: NoiseSource.h:85
Abstract class for random noise handling.
Definition: RandomNoiseSource.h:15
RealType noiseFunction() override
Compute next uniform noise value from current random uniform distribution.
Definition: UniformNoiseSource.h:161
UniformNoiseSource & configureUniformNoise(RealType min, RealType max)
Configure uniform noise.
Definition: UniformNoiseSource.h:183
RealType getMin()
Obtain the current minimum for uniform noise generation.
Definition: UniformNoiseSource.h:99
void computeUniformRealDistribution(RealType lowerBound, RealType upperBound)
Compute a uniform real distribution using the specified real data type.
Definition: RandomnessGenerator.h:343
std::string getRandomNoiseType() override
Definition: UniformNoiseSource.h:151