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