DGtal 1.3.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Data Fields
DGtal::RegularBinner< TQuantity > Struct Template Reference

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). More...

#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

◆ Bin

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

Definition at line 67 of file Histogram.h.

◆ Quantity

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

Definition at line 65 of file Histogram.h.

◆ Self

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

Definition at line 66 of file Histogram.h.

Constructor & Destructor Documentation

◆ RegularBinner()

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 }
TQuantity Quantity
Definition: Histogram.h:65
int max(int a, int b)

References max(), and DGtal::RegularBinner< TQuantity >::myWidth.

Member Function Documentation

◆ operator()()

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 }
static const std::decay< T >::type ONE
Constant One.
Definition: NumberTraits.h:103
static const std::decay< T >::type ZERO
Constant Zero.
Definition: NumberTraits.h:100
static double castToDouble(const std::decay< T >::type &aT)
Cast method to double (for I/O or board export uses only).
Definition: NumberTraits.h:164
DGtal::uint32_t Bin
Definition: Histogram.h:67

References DGtal::RegularBinner< TQuantity >::myMax, DGtal::RegularBinner< TQuantity >::myMin, DGtal::RegularBinner< TQuantity >::myNb, and DGtal::RegularBinner< TQuantity >::myWidth.

◆ size()

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.

96 {
97 return myNb;
98 }

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

Field Documentation

◆ myMax

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

any value above is considered the same.

Definition at line 70 of file Histogram.h.

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

◆ myMin

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

any value below is considered the same.

Definition at line 69 of file Histogram.h.

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

◆ myNb

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 >::operator()(), and DGtal::RegularBinner< TQuantity >::size().

◆ myWidth

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

the width of each bin.

Definition at line 72 of file Histogram.h.

Referenced by DGtal::RegularBinner< TQuantity >::operator()(), and DGtal::RegularBinner< TQuantity >::RegularBinner().


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