Helios++
Helios software for LiDAR simulations
NormalNoiseSource.h
1 #pragma once
2 
3 #include <noise/RandomNoiseSource.h>
4 
14 template <typename RealType>
15 class NormalNoiseSource : public RandomNoiseSource<RealType>{
16 protected:
17  // *** ATTRIBUTES *** //
18  // ******************** //
22  RealType normalNoiseMean = 0.0;
26  RealType normalNoiseStdev = 1.0;
27 
28 public:
29  // *** CONSTRUCTION *** //
30  // ********************* //
39  RealType normalNoiseMean = 0.0,
40  RealType normalNoiseStdev = 1.0
41  ):
42  RandomNoiseSource<RealType>(rg),
43  normalNoiseMean(normalNoiseMean),
44  normalNoiseStdev(normalNoiseStdev)
45  {
46  this->rg.computeNormalDistribution(normalNoiseMean,normalNoiseStdev);
47  this->build();
48  }
56  std::string const & seed,
57  RealType normalNoiseMean = 0.0,
58  RealType normalNoiseStdev = 1.0
59  ):
60  RandomNoiseSource<RealType>(seed),
61  normalNoiseMean(normalNoiseMean),
62  normalNoiseStdev(normalNoiseStdev)
63  {
64  this->rg.computeNormalDistribution(normalNoiseMean,normalNoiseStdev);
65  this->build();
66  }
73  RealType normalNoiseMean = 0.0,
74  RealType normalNoiseStdev = 1.0
75  ):
76  RandomNoiseSource<RealType>(),
77  normalNoiseMean(normalNoiseMean),
78  normalNoiseStdev(normalNoiseStdev)
79  {
80  this->rg.computeNormalDistribution(normalNoiseMean,normalNoiseStdev);
81  this->build();
82  }
83 
84  // *** GETTERS and SETTERS *** //
85  // ***************************** //
90  RealType getMean()
91  {return this->normalNoiseMean;}
105  NormalNoiseSource & setMean(RealType mean)
106  {return this->configureNormalNoise(mean, this->normalNoiseStdev);}
111  RealType getStdev()
112  {return this->normalNoiseStdev;}
126  NormalNoiseSource & setStdev(RealType stdev)
127  {return this->configureNormalNoise(this->normalNoiseMean, stdev);}
128 
129 
130 
131  // *** NOISE CONFIGURATION FUNCTIONS *** //
132  // *************************************** //
139  NormalNoiseSource & configureNormalNoise(RealType mean, RealType stdev);
143  std::string getRandomNoiseType() override
144  {return "NORMAL";}
145 
146  // *** NOISE OBTAINMENT FUNCTIONS *** //
147  // ************************************ //
153  RealType noiseFunction() override
154  {return this->rg.normalDistributionNext();}
155 
156  // *** STREAM OPERATORS *** //
157  // ************************** //
161  template<typename _RealType>
162  friend std::ostream& operator << (
163  std::ostream &out,
165  );
166 };
167 
168 
169 
170 
171 // *** CLASS IMPLEMENTATION *** //
172 // ********************************* //
173 template <typename RealType>
176  RealType mean,
177  RealType stdev
178 ){
179  this->normalNoiseMean = mean;
180  this->normalNoiseStdev = stdev;
181  this->rg.computeNormalDistribution(mean, stdev);
182  return *this;
183 }
184 
185 // *** STREAM OPERATORS *** //
186 // ************************** //
187 template<typename RealType>
188 std::ostream& operator << (std::ostream &out,NormalNoiseSource<RealType> &ns){
189  out << static_cast<RandomNoiseSource<RealType>&>(ns);
190  out << "\t\tNormalNoiseSource:\n"
191  << "\t\t\tnormalNoiseMean = " << ns.getMean() << "\n"
192  << "\t\t\tnormalNoiseStdev = " << ns.getStdev() << "\n";
193  return out;
194 }
RealType normalNoiseMean
The mean for the normal noise computation.
Definition: NormalNoiseSource.h:22
RandomnessGenerator< RealType > rg
RandomnessGenerator to be used to generate random noise.
Definition: RandomNoiseSource.h:23
std::string getRandomNoiseType() override
Definition: NormalNoiseSource.h:143
RealType getStdev()
Obtain the current standard deviation for normal noise generation.
Definition: NormalNoiseSource.h:111
Class to generate random numbers.
Definition: RandomnessGenerator.h:25
NormalNoiseSource(std::string const &seed, RealType normalNoiseMean=0.0, RealType normalNoiseStdev=1.0)
Create a NormalNoiseSource using received seed.
Definition: NormalNoiseSource.h:55
NormalNoiseSource & setStdev(RealType stdev)
Set the current standard deviation for normal noise generation.
Definition: NormalNoiseSource.h:126
NormalNoiseSource(RealType normalNoiseMean=0.0, RealType normalNoiseStdev=1.0)
Create default NormalNoiseSource.
Definition: NormalNoiseSource.h:72
RealType getMean()
Obtain the current mean for normal noise generation.
Definition: NormalNoiseSource.h:90
RealType normalNoiseStdev
the standard deviation for hte normal noise computation
Definition: NormalNoiseSource.h:26
NormalNoiseSource(RandomnessGenerator< RealType > const &rg, RealType normalNoiseMean=0.0, RealType normalNoiseStdev=1.0)
Create a NormalNoiseSource using received RandomnessGenerator.
Definition: NormalNoiseSource.h:37
void build()
Common behavior for all NoiseSource constructors.
Definition: NoiseSource.h:85
Abstract class for random noise handling.
Definition: RandomNoiseSource.h:15
Class for normal noise handling.
Definition: NormalNoiseSource.h:15
RealType noiseFunction() override
Compute next normal nosie value from current random normal distribution.
Definition: NormalNoiseSource.h:153
NormalNoiseSource & configureNormalNoise(RealType mean, RealType stdev)
Configure normal noise.
Definition: NormalNoiseSource.h:175
NormalNoiseSource & setMean(RealType mean)
Set the current mean for normal noise generation.
Definition: NormalNoiseSource.h:105
void computeNormalDistribution(RealType mean, RealType stdev)
Compute a normal distribution using the specified real data type.
Definition: RandomnessGenerator.h:380
friend std::ostream & operator<<(std::ostream &out, NormalNoiseSource< _RealType > &ns)
Output stream behavior.