47 CHistogram(
const double min,
const double max,
const size_t nBins);
55 return CHistogram(min,max,
static_cast<size_t>(ceil((max-min)/binWidth)));
63 void add(
const double x);
66 template <
typename Derived>
67 inline void add(
const Eigen::MatrixBase<Derived> &x)
69 const size_t N = x.size();
70 for (
size_t i=0;i<N;i++)
71 this->add(
static_cast<const double>(x(i)));
76 inline void add(
const std::vector<T> &x)
78 const size_t N = x.size();
79 for (
size_t i=0;i<N;i++)
80 this->add(
static_cast<const double>(x[i]));
97 void getHistogram( std::vector<double> &x, std::vector<double> &hits )
const;
This class provides an easy way of computing histograms for unidimensional real valued variables.
size_t m_count
The total elements count.
int getBinCount(const size_t index) const
Retuns the elements count into the selected bin index, where first one is 0.
double m_binSizeInv
((max-min)/nBins)^-1
double getBinRatio(const size_t index) const
Retuns the ratio in [0,1] range for the selected bin index, where first one is 0.
void add(const Eigen::MatrixBase< Derived > &x)
Add all the elements from a MRPT container to the histogram.
void getHistogramNormalized(std::vector< double > &x, std::vector< double > &hits) const
Returns the list of bin centers & hit counts, normalized such as the integral of the histogram,...
CHistogram(const double min, const double max, const size_t nBins)
Constructor.
static CHistogram createWithFixedWidth(double min, double max, double binWidth)
Constructor with a fixed bin width.
void add(const std::vector< T > &x)
This is an overloaded member function, provided for convenience. It differs from the above function o...
double m_max
The histogram limits.
void getHistogram(std::vector< double > &x, std::vector< double > &hits) const
Returns the list of bin centers & hit counts.
void add(const double x)
Add an element to the histogram.
void clear()
Clear the histogram:
std::vector< size_t > m_bins
The bins counter.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.