Helios++
Helios software for LiDAR simulations
Histogram.hpp
1 #ifndef _SURFACEINSPECTOR_MATHS_HISTOGRAM_HPP_
2 #define _SURFACEINSPECTOR_MATHS_HISTOGRAM_HPP_
3 
4 #include <vector>
5 
6 #include <surfaceinspector/util/Object.hpp>
7 #include <surfaceinspector/maths/functions/GaussianFunction.hpp>
8 
9 using std::vector;
12 
13 namespace SurfaceInspector { namespace maths{
14 
22 template <typename T>
23 class Histogram : public Object{
24 private:
25  // *** SERIALIZATION *** //
26  // *********************** //
27  friend class boost::serialization::access;
34  template <typename Archive>
35  void serialize(Archive &ar, const unsigned int version){
36  ar &m &n;
37  ar &xmin &xmax &delta & step &norm;
38  ar &c &r &d;
39  ar &a &b;
40  }
41 public:
42  // *** ATTRIBUTES *** //
43  // ******************** //
47  size_t m;
51  size_t n;
52 
56  T xmin;
60  T xmax;
64  T delta;
68  T step;
73  T norm;
74 
80  vector<size_t> c;
84  vector<double> r;
90  vector<double> d;
91 
97  vector<T> a;
103  vector<T> b;
104 
105  // *** CONSTRUCTION / DESTRUCTION *** //
106  // *********************************** //
118  vector<T> x,
119  size_t n=256,
120  bool relative=true,
121  bool density=true
122  );
137  T xmin,
138  T xmax,
139  vector<T> x,
140  size_t n=256,
141  bool relative=true,
142  bool density=true
143  );
147  virtual ~Histogram() = default;
148 
149  // *** HISTOGRAM METHODS *** //
150  // *************************** //
168  T findCutPoint(double p);
181  size_t absCumsum(size_t const start, size_t const end);
187  inline T absCumsum() {return absCumsum(0, c.size());}
188 
189 private:
190  // *** INNER METHODS *** //
191  // *********************** //
196  void extractMinMax(vector<T> const &x);
197 
221  void recount(vector<T> const &x);
233 
253 
254 };
255 }}
256 
257 #include <surfaceinspector/maths/Histogram.tpp>
258 
259 #endif
Class for representation and handling of 1D histograms.
Definition: Histogram.hpp:23
T delta
The difference between maximum and minimum value.
Definition: Histogram.hpp:64
Histogram(vector< T > x, size_t n=256, bool relative=true, bool density=true)
Build a histogram from given vector of values and requested number of bins .
size_t n
The number of bins.
Definition: Histogram.hpp:51
virtual ~Histogram()=default
Virtual destructor for the histogram.
size_t m
The number of elements considered to build the histogram.
Definition: Histogram.hpp:47
void extractMinMax(vector< T > const &x)
Extract min and max values from vector of values.
vector< T > a
The start value for each bin.
Definition: Histogram.hpp:97
vector< double > d
The density for each bin corresponding to the unitary area version of the histogram.
Definition: Histogram.hpp:90
vector< T > b
Definition: Histogram.hpp:103
void computeDensity()
Compute the density (or normalized) histogram.
void computeRelativeFrequencies()
Compute the relative frequencies for each bin.
GaussianFunction< T > estimateGaussian()
Estimate a gaussian function from the histogram. Notice this method MUST NOT be called if histogram's...
T findCutPoint(double p)
Obtain the cut point (value) so approximately of the elements are greater than it.
T step
The step between bins. It can also be understood as the bin size.
Definition: Histogram.hpp:68
T absCumsum()
Like absCumsum(size_t const, size_t const) but for the entire histogram.
Definition: Histogram.hpp:187
void recount(vector< T > const &x)
Count the number of elements in each bin, considering given vector of values .
vector< size_t > c
The absolute frequency, it is number of elements in each bin.
Definition: Histogram.hpp:80
Histogram(T xmin, T xmax, vector< T > x, size_t n=256, bool relative=true, bool density=true)
Build a histogram starting at xmin and ending at xmax populated by given vector of values and with r...
size_t absCumsum(size_t const start, size_t const end)
Compute the cumulative sum of absolute frequencies inside given index interval.
T norm
The norm for the unitary area histogram.
Definition: Histogram.hpp:73
T xmax
The maximum value on data used to build the histogram.
Definition: Histogram.hpp:60
vector< double > r
The relative frequency for each bin.
Definition: Histogram.hpp:84
void serialize(Archive &ar, const unsigned int version)
Serialize a Histogram to a stream of bytes.
Definition: Histogram.hpp:35
void computeBinningIntervals()
Compute the interval for each bin.
T xmin
The minimum value on data used to build the histogram.
Definition: Histogram.hpp:56
Implementation of a gaussian function.
Definition: GaussianFunction.hpp:26
Class representing an object. All surface inspector classes must extend Object.
Definition: Object.hpp:12