Helios++
Helios software for LiDAR simulations
NormalNoiseSource.h
1 #pragma once
2 
3 #include <string>
4 #include <noise/RandomNoiseSource.h>
5 
15 template <typename RealType>
16 class NormalNoiseSource : public RandomNoiseSource<RealType>{
17 protected:
18  // *** ATTRIBUTES *** //
19  // ******************** //
23  RealType normalNoiseMean = 0.0;
27  RealType normalNoiseStdev = 1.0;
28 
29 public:
30  // *** CONSTRUCTION *** //
31  // ********************* //
40  RealType normalNoiseMean = 0.0,
41  RealType normalNoiseStdev = 1.0
42  ):
43  RandomNoiseSource<RealType>(rg),
46  {
48  this->build();
49  }
57  std::string const & seed,
58  RealType normalNoiseMean = 0.0,
59  RealType normalNoiseStdev = 1.0
60  ):
61  RandomNoiseSource<RealType>(seed),
64  {
65  this->rg.computeNormalDistribution(normalNoiseMean,normalNoiseStdev);
66  this->build();
67  }
74  RealType normalNoiseMean = 0.0,
75  RealType normalNoiseStdev = 1.0
76  ):
77  RandomNoiseSource<RealType>(),
80  {
81  this->rg.computeNormalDistribution(normalNoiseMean,normalNoiseStdev);
82  this->build();
83  }
84 
85  // *** GETTERS and SETTERS *** //
86  // ***************************** //
91  RealType getMean()
92  {return this->normalNoiseMean;}
106  NormalNoiseSource & setMean(RealType mean)
107  {return this->configureNormalNoise(mean, this->normalNoiseStdev);}
112  RealType getStdev()
113  {return this->normalNoiseStdev;}
127  NormalNoiseSource & setStdev(RealType stdev)
128  {return this->configureNormalNoise(this->normalNoiseMean, stdev);}
129 
130 
131 
132  // *** NOISE CONFIGURATION FUNCTIONS *** //
133  // *************************************** //
140  NormalNoiseSource & configureNormalNoise(RealType mean, RealType stdev);
144  std::string getRandomNoiseType() override
145  {return "NORMAL";}
146 
147  // *** NOISE OBTAINMENT FUNCTIONS *** //
148  // ************************************ //
154  RealType noiseFunction() override
155  {return this->rg.normalDistributionNext();}
156 
157  // *** STREAM OPERATORS *** //
158  // ************************** //
162  template<typename _RealType>
163  friend std::ostream& operator << (
164  std::ostream &out,
166  );
167 };
168 
169 
170 
171 
172 // *** CLASS IMPLEMENTATION *** //
173 // ********************************* //
174 template <typename RealType>
177  RealType mean,
178  RealType stdev
179 ){
180  this->normalNoiseMean = mean;
181  this->normalNoiseStdev = stdev;
182  this->rg.computeNormalDistribution(mean, stdev);
183  return *this;
184 }
185 
186 // *** STREAM OPERATORS *** //
187 // ************************** //
188 template<typename RealType>
189 std::ostream& operator << (std::ostream &out,NormalNoiseSource<RealType> &ns){
190  out << static_cast<RandomNoiseSource<RealType>&>(ns);
191  out << "\t\tNormalNoiseSource:\n"
192  << "\t\t\tnormalNoiseMean = " << ns.getMean() << "\n"
193  << "\t\t\tnormalNoiseStdev = " << ns.getStdev() << "\n";
194  return out;
195 }
void build()
Common behavior for all NoiseSource constructors.
Definition: NoiseSource.h:85
Class for normal noise handling.
Definition: NormalNoiseSource.h:16
NormalNoiseSource(RealType normalNoiseMean=0.0, RealType normalNoiseStdev=1.0)
Create default NormalNoiseSource.
Definition: NormalNoiseSource.h:73
NormalNoiseSource(std::string const &seed, RealType normalNoiseMean=0.0, RealType normalNoiseStdev=1.0)
Create a NormalNoiseSource using received seed.
Definition: NormalNoiseSource.h:56
RealType normalNoiseStdev
the standard deviation for hte normal noise computation
Definition: NormalNoiseSource.h:27
NormalNoiseSource & setStdev(RealType stdev)
Set the current standard deviation for normal noise generation.
Definition: NormalNoiseSource.h:127
friend std::ostream & operator<<(std::ostream &out, NormalNoiseSource< _RealType > &ns)
Output stream behavior.
std::string getRandomNoiseType() override
Definition: NormalNoiseSource.h:144
RealType getStdev()
Obtain the current standard deviation for normal noise generation.
Definition: NormalNoiseSource.h:112
RealType getMean()
Obtain the current mean for normal noise generation.
Definition: NormalNoiseSource.h:91
NormalNoiseSource & setMean(RealType mean)
Set the current mean for normal noise generation.
Definition: NormalNoiseSource.h:106
RealType noiseFunction() override
Compute next normal nosie value from current random normal distribution.
Definition: NormalNoiseSource.h:154
NormalNoiseSource & configureNormalNoise(RealType mean, RealType stdev)
Configure normal noise.
Definition: NormalNoiseSource.h:176
NormalNoiseSource(RandomnessGenerator< RealType > const &rg, RealType normalNoiseMean=0.0, RealType normalNoiseStdev=1.0)
Create a NormalNoiseSource using received RandomnessGenerator.
Definition: NormalNoiseSource.h:38
RealType normalNoiseMean
The mean for the normal noise computation.
Definition: NormalNoiseSource.h:23
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 computeNormalDistribution(RealType mean, RealType stdev)
Compute a normal distribution using the specified real data type.
Definition: RandomnessGenerator.h:400