DGtal  0.9.4beta
Public Types | Public Member Functions | Data Fields
DGtal::RegularBinner< TQuantity > Struct Template Reference

#include <DGtal/math/Histogram.h>

Public Types

typedef TQuantity Quantity
 
typedef RegularBinner< QuantitySelf
 
typedef DGtal::uint32_t Bin
 

Public Member Functions

 RegularBinner (const Quantity &min, const Quantity &max, Bin n)
 
Bin size () const
 
Bin operator() (const Quantity &q) const
 

Data Fields

Quantity myMin
 
Quantity myMax
 
Bin myNb
 
Quantity myWidth
 

Detailed Description

template<typename TQuantity>
struct DGtal::RegularBinner< TQuantity >

Aim: Represents an elementary functor that partitions quantities into regular intervals, given a range [min,max] range and a number nb of intervals (each interval is called a bin).

Description of template class 'RegularBinner'

Model of CBinner.

Template Parameters
TQuantityany number type, model of CEuclideanRing.

Definition at line 64 of file Histogram.h.

Member Typedef Documentation

template<typename TQuantity >
typedef DGtal::uint32_t DGtal::RegularBinner< TQuantity >::Bin

Definition at line 67 of file Histogram.h.

template<typename TQuantity >
typedef TQuantity DGtal::RegularBinner< TQuantity >::Quantity

Definition at line 65 of file Histogram.h.

template<typename TQuantity >
typedef RegularBinner< Quantity > DGtal::RegularBinner< TQuantity >::Self

Definition at line 66 of file Histogram.h.

Constructor & Destructor Documentation

template<typename TQuantity >
DGtal::RegularBinner< TQuantity >::RegularBinner ( const Quantity min,
const Quantity max,
Bin  n 
)
inline

Creates a regular binner that place quantities in range [min,max] in n bins (numbered from 0 to n-1), such that all bins have equal width \(\frac{max-min}{n}\).

Parameters
minany quantity smaller than min falls into bin 0.
maxany quantity greater than max falls into bin n-1.
nthe number of bins.
Precondition
n>0.

Definition at line 84 of file Histogram.h.

85  : myMin( min ), myMax( max ), myNb( n )
86  {
87  ASSERT( max > min );
88  ASSERT( n > 0 );
89  myWidth = ( max - min ) / static_cast<Quantity>( n );
90  }

Member Function Documentation

template<typename TQuantity >
Bin DGtal::RegularBinner< TQuantity >::operator() ( const Quantity q) const
inline

Places the quantity q into the correct bin.

Parameters
qany quantity
Returns
the associated bin (integer in [0,size()-1].

Definition at line 105 of file Histogram.h.

106  {
107  if ( q <= myMin ) return NumberTraits<Bin>::ZERO;
108  else if ( q >= myMax ) return myNb - NumberTraits<Bin>::ONE;
109  else return static_cast<Bin>( floor( NumberTraits<Quantity>::castToDouble( ( q - myMin ) / myWidth ) ) );
110  }
DGtal::uint32_t Bin
Definition: Histogram.h:67
template<typename TQuantity >
Bin DGtal::RegularBinner< TQuantity >::size ( ) const
inline
Returns
the number of bins of this binner.

Definition at line 95 of file Histogram.h.

References DGtal::RegularBinner< TQuantity >::myNb.

96  {
97  return myNb;
98  }

Field Documentation

template<typename TQuantity >
Quantity DGtal::RegularBinner< TQuantity >::myMax

any value above is considered the same.

Definition at line 70 of file Histogram.h.

template<typename TQuantity >
Quantity DGtal::RegularBinner< TQuantity >::myMin

any value below is considered the same.

Definition at line 69 of file Histogram.h.

template<typename TQuantity >
Bin DGtal::RegularBinner< TQuantity >::myNb

the number of bins.

Definition at line 71 of file Histogram.h.

Referenced by DGtal::RegularBinner< TQuantity >::size().

template<typename TQuantity >
Quantity DGtal::RegularBinner< TQuantity >::myWidth

the width of each bin.

Definition at line 72 of file Histogram.h.


The documentation for this struct was generated from the following file: