Main Page   Class Overview   Pixels   Images   Geometry   Quick Index  

HxHistogram Class Reference

Class definition of histogram. More...

#include <HxHistogram.h>

List of all members.

Public Methods

Constructors
 HxHistogram ()
 Construct an empty histogram. More...

 HxHistogram (const HxHistogram &)
 Copy constructor. More...

 HxHistogram (int dimSize)
 Construct a 1D histogram with a range from 0 to dimSize - 1 and a binWidth of 1. More...

 HxHistogram (int dimSize1, int dimSize2)
 Construct a 2D histogram with a range from 0 to dimSize - 1 and a binWidth of 1 in each dimension. More...

 HxHistogram (int dimSize1, int dimSize2, int dimSize3)
 Construct a 3D histogram with a range from 0 to dimSize - 1 and a binWidth of 1 in each dimension. More...

 HxHistogram (HxValueType dataType, int dimensions, int dimSize1, int dimSize2=0, int dimSize3=0)
 Construct Histogram with given data type and number of dimensions. More...

 HxHistogram (HxValueType dataType, int dimensions, double lowBin1, double highBin1, int nBins1, double lowBin2, double highBin2, int nBins2, double lowBin3, double highBin3, int nBins3)
 Construct a Histogram with given parameters. More...

 HxHistogram (HxString filename)
 Read a Histogram from disk. More...

Destructor
 ~HxHistogram ()
 Destructor. More...

Operators
HxHistogram & operator= (const HxHistogram &)
 Assignment operator. More...

int isNull () const
 Indicates wether this is a valid histogram. More...

 operator int () const
 Indicates wether this is a valid histogram. More...

Inquiry
int ident () const
 The unique identifier of the histogram. More...

HxValueType dataType () const
 The data value type. More...

int dimensionality () const
 The number of dimensions of the histogram. More...

int dimensionSize (int dim) const
 The size of the histogram in the i-th dimension. More...

int nrOfBins () const
 The total size of the histogram. More...

double lowBin (int dim) const
 The lowest bin in the i-th dimension. More...

double highBin (int dim) const
 The highest bin in the i-th dimension. More...

double binWidth (int dim) const
 The bin width in the i-th dimension. More...

double binToValue (int bin, int dimension) const
 Translate bin to value. More...

int valueToBin (double value, int dimension) const
 Translate value to bin. More...

double get (int bin1) const
 Get the number of elements in the given bin. More...

double get (int bin1, int bin2) const
 Get the number of elements in the given bin. More...

double get (int bin1, int bin2, int bin3) const
 Get the number of elements in the given bin. More...

Checked modification
void insertValChecked (int val)
 Insert value in 1D histogram. More...

void insertValChecked (double val)
 Insert value in 1D histogram. More...

void insertValChecked (HxScalarInt val)
 Insert value in 1D histogram. More...

void insertValChecked (HxScalarDouble val)
 Insert value in 1D histogram. More...

void insertValChecked (HxVec2Int val)
 Insert value in 2D histogram. More...

void insertValChecked (HxVec2Double val)
 Insert value in 2D histogram. More...

void insertValChecked (HxVec3Int val)
 Insert value in 3D histogram. More...

void insertValChecked (HxVec3Double val)
 Insert value in 3D histogram. More...

void incBinChecked (int bin)
 Increment the given bin. More...

void incBinChecked (int bin1, int bin2)
 Increment the given bin. More...

void incBinChecked (int bin1, int bin2, int bin3)
 Increment the given bin. More...

Unchecked modification
void insertVal (int val)
 Insert value in 1D histogram. More...

void insertVal (double val)
 Insert value in 1D histogram. More...

void insertVal (double val, double sigma)
 Kernel Density Estimator. More...

void insertVal (HxScalarInt val)
 Insert value in 1D histogram. More...

void insertVal (HxScalarDouble val)
 Insert value in 1D histogram. More...

void insertVal (HxVec2Int val)
 Insert value in 2D histogram. More...

void insertVal (HxVec2Double val)
 Insert value in 2D histogram. More...

void insertVal (HxVec3Int val)
 Insert value in 3D histogram. More...

void insertVal (HxVec3Double val)
 Insert value in 3D histogram. More...

void incBin (int bin)
 Increment the given bin (assumes 1D histogram). More...

void incBin (int bin1, int bin2)
 Increment the given bin (assumes 2D histogram). More...

void incBin (int bin1, int bin2, int bin3)
 Increment the given bin (assumes 3D histogram). More...

void setBin (int bin1, long val)
 Reset the value of the given bin to val (assumes 1D histogram). More...

void setBin (int bin1, int bin2, long val)
 Reset the value of the given bin to val (assumes 2D histogram). More...

void setBin (int bin1, int bin2, int bin3, long val)
 Reset the value of the given bin to val (assumes 3D histogram). More...

void setBin (int bin1, double val)
 Reset the value of the given bin to val (assumes 1D histogram). More...

void setBin (int bin1, int bin2, double val)
 Reset the value of the given bin to val (assumes 2D histogram). More...

void setBin (int bin1, int bin2, int bin3, double val)
 Reset the value of the given bin to val (assumes 3D histogram). More...

Statistics
HxHistogram smooth (double sigma=3.0)
 Smooth histogram data. More...

std::list< HxVec2Doublemodes ()
 Get histogram modes. More...

HxHistogram normalize (double weight=1.0)
 Normalize histogram data. More...

double sum () const
 The sum of the histogram. More...

double minVal () const
 The minimum number of elements in the histogram. More...

double minVal (int *index) const
 The minimum number of elements in the histogram. More...

double maxVal () const
 The maximum number of elements in the histogram. More...

double maxVal (int *index) const
 The maximum number of elements in the histogram. More...

double intersection (const HxHistogram &) const
 Intersection of histograms. More...

double chiSquare (const HxHistogram &) const
 Chi square intersection of histograms. More...

double chiSquareNorm (const HxHistogram &) const
 Normalized chi square intersection of histograms. More...

Output/display
HxHistogram convert (HxValueType dataType)
 convert dataType. More...

void getDataDouble (double *data)
 Fill the externally allocated buffer with data from this histogram. More...

void getDataInt (int *data)
 Fill the externally allocated buffer with data from this histogram. More...

void render3d (int *data, int dataWidth, int dataHeight, double elevation, double alpha, double threshold)
 Assume the histogram is a 3d rgb cube and render it for display in Java in the externally allocated data buffer. More...

STD_OSTREAM & put (STD_OSTREAM &, HxString delimit="") const
 Print histogram data in the given stream. More...

int write (HxString filename)
 Write histogram to disk. More...

Reduce operations
HxHistogram threshold (double valThreshold)
 Returns new histogram in which bins with count<=valThreshold are set to 0.0, bins with count>valThreshold keep original value. More...

int countBins (double valThreshold=0.0)
 Returns number of bins with count>valThreshold. More...

HxHistogram reduceRange (int binMin1, int binMax1=-1, int binMin2=0, int binMax2=-1, int binMin3=0, int binMax3=-1)
 Returns new histogram containing given range of bins only. More...

HxHistogram reduceRangeVal (double binValMin1, double binValMax1, double binValMin2=0, double binValMax2=0, double binValMin3=0, double binValMax3=0)
 Returns new histogram containing given range of values (mapped to bin numbers) only. More...

HxHistogram to1D (int dim=1)
 Projects n-dimensional (1<n<=3) histogram on a 1-D histogram for given dimension. More...


Detailed Description

Class definition of histogram.

The current implementation supports 1, 2, and 3 dimensional histograms with real-valued data (no integer data yet). For each dimension a range (lowB - highB) and a number of bins has to be specified (typically highB - lowB + 1 to get a binWidth of 1). The number of bins in a given dimension is known as the dimensionSize. The width of a bin is defined as (highB - lowB) / (nBins - 1). The first bin goes from lowB to lowB + binWidth, the last bin from highB to highB + binWidth.


Constructor & Destructor Documentation

HxHistogram::HxHistogram  
 

Construct an empty histogram.

00067                          : _data(0)
00068 {
00069 }

HxHistogram::HxHistogram const HxHistogram &    rhs
 

Copy constructor.

00071                                                : _data(rhs._data)
00072 {
00073 }

HxHistogram::HxHistogram int    dimSize
 

Construct a 1D histogram with a range from 0 to dimSize - 1 and a binWidth of 1.

00076 {
00077     _data = new HxHistogramData(REAL_VALUE, 1,
00078                                 0, dimSize - 1, dimSize,
00079                                 0, 0, 0,
00080                                 0, 0, 0);
00081 }

HxHistogram::HxHistogram int    dimSize1,
int    dimSize2
 

Construct a 2D histogram with a range from 0 to dimSize - 1 and a binWidth of 1 in each dimension.

00084 {
00085     _data = new HxHistogramData(REAL_VALUE, 2,
00086                                 0, dimSize1 - 1, dimSize1,
00087                                 0, dimSize2 - 1, dimSize2,
00088                                 0, 0, 0);
00089 }

HxHistogram::HxHistogram int    dimSize1,
int    dimSize2,
int    dimSize3
 

Construct a 3D histogram with a range from 0 to dimSize - 1 and a binWidth of 1 in each dimension.

00092 {
00093     _data = new HxHistogramData(REAL_VALUE, 3,
00094                                 0, dimSize1 - 1, dimSize1,
00095                                 0, dimSize2 - 1, dimSize2,
00096                                 0, dimSize3 - 1, dimSize3);
00097 }

HxHistogram::HxHistogram HxValueType    dataType,
int    dimensions,
int    dimSize1,
int    dimSize2 = 0,
int    dimSize3 = 0
 

Construct Histogram with given data type and number of dimensions.

The range in a dimension is 0 to dimSize - 1, the binWidth is 1.

00101 {
00102     _data = new HxHistogramData(dataType, dimensions,
00103                                 0, dimSize1 - 1, dimSize1,
00104                                 0, dimSize2 - 1, dimSize2,
00105                                 0, dimSize3 - 1, dimSize3);
00106 }

HxHistogram::HxHistogram HxValueType    dataType,
int    dimensions,
double    lowBin1,
double    highBin1,
int    nBins1,
double    lowBin2,
double    highBin2,
int    nBins2,
double    lowBin3,
double    highBin3,
int    nBins3
 

Construct a Histogram with given parameters.

If dataType == INT\_VALUE parameters are casted.

00112 {
00113     _data = new HxHistogramData(dataType, dimensions,
00114                                 lowBin1, highBin1, nBins1,
00115                                 lowBin2, highBin2, nBins2,
00116                                 lowBin3, highBin3, nBins3);
00117 }

HxHistogram::HxHistogram HxString    filename
 

Read a Histogram from disk.

00124 {
00125     HxString name;
00126     FILE *fp;
00127     IOHEADER header;
00128 
00129     name = filename + ".hst";
00130 
00131     fp = fopen(name.c_str(), "rb");
00132     if (!fp)
00133         _data = 0;
00134     else {
00135         fread(&header, sizeof(header), 1, fp);
00136 
00137         _data = new HxHistogramData(header.dataType, header.dimensions,
00138                             header.lowBin1, header.highBin1, header.nBins1,
00139                             header.lowBin2, header.highBin2, header.nBins2,
00140                             header.lowBin3, header.highBin3, header.nBins3);
00141 
00142         if (_data->_dataType == REAL_VALUE)
00143             fread(_data->_bins.realValue, _data->_totSize,
00144                 sizeof(*(_data->_bins.realValue)), fp);
00145         else
00146             fread(_data->_bins.intValue, _data->_totSize,
00147                 sizeof(*(_data->_bins.intValue)), fp);
00148         fclose(fp);
00149     }
00150 }

HxHistogram::~HxHistogram  
 

Destructor.

00153 {
00154 }


Member Function Documentation

HxHistogram & HxHistogram::operator= const HxHistogram &    rhs
 

Assignment operator.

00165 {
00166     _data = rhs._data;
00167     return *this;
00168 }

int HxHistogram::isNull   const
 

Indicates wether this is a valid histogram.

00172 { 
00173     return _data ? 0 : 1; 
00174 }

HxHistogram::operator int   const
 

Indicates wether this is a valid histogram.

00178 { 
00179     return _data ? 1 : 0; 
00180 }

int HxHistogram::ident   const
 

The unique identifier of the histogram.

00184 { 
00185     return _data ? _data->_id : 0 ; 
00186 }

HxValueType HxHistogram::dataType   const
 

The data value type.

Either INT\_VALUE or REAL\_VALUE.

00190 {
00191     return _data ? _data->_dataType : INT_VALUE;
00192 }

int HxHistogram::dimensionality   const
 

The number of dimensions of the histogram.

00196 {
00197     return _data ? _data->_nDims : 0;
00198 }

int HxHistogram::dimensionSize int    dim const
 

The size of the histogram in the i-th dimension.

The first dimension has i = 1.

00202 {
00203     if (!_data)
00204         return 0;
00205     switch (dim) {
00206     case 1: return _data->_dimSize1;
00207     case 2: return _data->_dimSize2;
00208     case 3: return _data->_dimSize3;
00209     }
00210     return 0;
00211 }

int HxHistogram::nrOfBins   const
 

The total size of the histogram.

00215 {
00216     if (!_data)
00217         return 0;
00218     return _data->_totSize;
00219 }

double HxHistogram::lowBin int    dim const
 

The lowest bin in the i-th dimension.

00223 {
00224     if (!_data)
00225         return 0;
00226     switch (dim) {
00227     case 1: return _data->_lowBin1;
00228     case 2: return _data->_lowBin2;
00229     case 3: return _data->_lowBin3;
00230     }
00231     return 0;
00232 }

double HxHistogram::highBin int    dim const
 

The highest bin in the i-th dimension.

00236 {
00237     if (!_data)
00238         return 0;
00239     switch (dim) {
00240     case 1: return _data->_highBin1;
00241     case 2: return _data->_highBin2;
00242     case 3: return _data->_highBin3;
00243     }
00244     return 0;
00245 }

double HxHistogram::binWidth int    dim const
 

The bin width in the i-th dimension.

00249 {
00250     if (!_data)
00251         return 0;
00252     switch (dim) {
00253     case 1: return _data->_binWidth1;
00254     case 2: return _data->_binWidth2;
00255     case 3: return _data->_binWidth3;
00256     }
00257     return 0;
00258 }

double HxHistogram::binToValue int    bin,
int    dimension
const
 

Translate bin to value.

00262 {
00263     if (!_data)
00264         return 0;
00265     switch (dimension) {
00266     case 1: return bin * _data->_binWidth1 + _data->_lowBin1;
00267     case 2: return bin * _data->_binWidth2 + _data->_lowBin2;
00268     case 3: return bin * _data->_binWidth3 + _data->_lowBin3;
00269     }
00270     return 0;
00271 }

int HxHistogram::valueToBin double    val,
int    dimension
const
 

Translate value to bin.

00275 {
00276     if (!_data)
00277         return -1;
00278     switch (dimension) {
00279     case 1: return (int) (((val - _data->_lowBin1) / _data->_binWidth1) + 0.5);
00280     case 2: return (int) (((val - _data->_lowBin2) / _data->_binWidth2) + 0.5);
00281     case 3: return (int) (((val - _data->_lowBin3) / _data->_binWidth3) + 0.5);
00282     }
00283     return -1;
00284 }

double HxHistogram::get int    bin1 const [inline]
 

Get the number of elements in the given bin.

00428 {
00429     return _data ? _data->getBin(bin1) : 0;
00430 }

double HxHistogram::get int    bin1,
int    bin2
const [inline]
 

Get the number of elements in the given bin.

00434 {
00435     return _data ? _data->getBin(bin2 * _data->_dimSize1 + bin1) : 0;
00436 }

double HxHistogram::get int    bin1,
int    bin2,
int    bin3
const [inline]
 

Get the number of elements in the given bin.

00440 {
00441     return _data ? _data->getBin((bin3 * _data->_dimSize2 + bin2) *
00442                                 _data->_dimSize1 + bin1) : 0;
00443 }

void HxHistogram::insertValChecked int    val
 

Insert value in 1D histogram.

00288 {
00289     if (_data && (_data->_nDims == 1))
00290         incBinChecked(
00291             (int) (((val - _data->_lowBin1) / _data->_binWidth1) + 0.5));
00292 }

void HxHistogram::insertValChecked double    val
 

Insert value in 1D histogram.

00296 {
00297     if (_data && (_data->_nDims == 1))
00298         incBinChecked(
00299             (int) (((val - _data->_lowBin1) / _data->_binWidth1) + 0.5));
00300 }

void HxHistogram::insertValChecked HxScalarInt    val
 

Insert value in 1D histogram.

00304 {
00305     if (_data && (_data->_nDims == 1))
00306         incBinChecked(
00307             (int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5));
00308 }

void HxHistogram::insertValChecked HxScalarDouble    val
 

Insert value in 1D histogram.

00312 {
00313     if (_data && (_data->_nDims == 1))
00314         incBinChecked(
00315             (int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5));
00316 }

void HxHistogram::insertValChecked HxVec2Int    val
 

Insert value in 2D histogram.

00320 {
00321     if (_data && (_data->_nDims == 2))
00322         incBinChecked(
00323             (int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5),
00324             (int) (((val.y() - _data->_lowBin2) / _data->_binWidth2) + 0.5));
00325 }

void HxHistogram::insertValChecked HxVec2Double    val
 

Insert value in 2D histogram.

00329 {
00330     if (_data && (_data->_nDims == 2))
00331         incBinChecked(
00332             (int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5),
00333             (int) (((val.y() - _data->_lowBin2) / _data->_binWidth2) + 0.5));
00334 }

void HxHistogram::insertValChecked HxVec3Int    val
 

Insert value in 3D histogram.

00338 {
00339     if (_data && (_data->_nDims == 3))
00340         incBinChecked(
00341             (int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5),
00342             (int) (((val.y() - _data->_lowBin2) / _data->_binWidth2) + 0.5),
00343             (int) (((val.z() - _data->_lowBin3) / _data->_binWidth3) + 0.5));
00344 }

void HxHistogram::insertValChecked HxVec3Double    val
 

Insert value in 3D histogram.

00348 {
00349     if (_data && (_data->_nDims == 3))
00350         incBinChecked(
00351             (int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5),
00352             (int) (((val.y() - _data->_lowBin2) / _data->_binWidth2) + 0.5),
00353             (int) (((val.z() - _data->_lowBin3) / _data->_binWidth3) + 0.5));
00354 }

void HxHistogram::incBinChecked int    bin
 

Increment the given bin.

Checks whether this is a 1D histogram and preserves reference count. Values outside the histogram range are ignored.

00358 {
00359     if (_data) {
00360         if ((_data->_nDims == 1) &&
00361                 (bin >= 0) && (bin < _data->_dimSize1)) {
00362             _data->getUnshared();
00363             _data->incBin(bin);
00364         }
00365     }
00366 }

void HxHistogram::incBinChecked int    bin1,
int    bin2
 

Increment the given bin.

Checks whether this is a 2D histogram and preserves reference count. Values outside the histogram range are ignored.

00370 {
00371     if (_data) {
00372         if ((_data->_nDims == 2) &&
00373                 (bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00374                 (bin2 >= 0) && (bin2 < _data->_dimSize2)) {
00375             _data->getUnshared();
00376             _data->incBin(bin2 * _data->_dimSize1 + bin1);
00377         }
00378     }
00379 }

void HxHistogram::incBinChecked int    bin1,
int    bin2,
int    bin3
 

Increment the given bin.

Checks whether this is a 3D histogram and preserves reference count. Values outside the histogram range are ignored.

00383 {
00384     if (_data) {
00385         if ((_data->_nDims == 3) &&
00386                 (bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00387                 (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00388                 (bin3 >= 0) && (bin3 < _data->_dimSize3)) {
00389             _data->getUnshared();
00390             _data->incBin((bin3 * _data->_dimSize2 + bin2) *
00391                          _data->_dimSize1 + bin1);
00392         }
00393     }
00394 }

void HxHistogram::insertVal int    val [inline]
 

Insert value in 1D histogram.

00522 {
00523     incBin((int) (((val - _data->_lowBin1) / _data->_binWidth1) + 0.5));
00524 }

void HxHistogram::insertVal double    val [inline]
 

Insert value in 1D histogram.

00528 {
00529     incBin((int) (((val - _data->_lowBin1) / _data->_binWidth1) + 0.5));
00530 }

void HxHistogram::insertVal double    val,
double    sigma
 

Kernel Density Estimator.

00399 {
00400     if (!_data || (_data->_dataType != REAL_VALUE))
00401         return;
00402 
00403     double ori = (val - _data->_lowBin1) / _data->_binWidth1;
00404     double s = sigma/_data->_binWidth1;
00405     double t, sat;
00406 
00407     int binmin = (int) (ori-3*s+0.5);
00408     int binmax = (int) (ori+3*s+0.5);
00409     int bin;
00410 
00411     if (binmin < 0)
00412         binmin = 0;
00413 
00414     /* gaussian mass left outside kernel */
00415     t = (ori-binmin+0.5)/(sqrt(2.0)*s);
00416 
00417     sat = erfc(t)*0.5;
00418 
00419     _data->_bins.realValue[binmin ? binmin-1 : 0] += sat;
00420 
00421     if (binmax >= _data->_dimSize1)
00422         binmax = _data->_dimSize1-1;
00423 
00424     /* gaussian mass right outside kernel */
00425     t = (binmax-ori+0.5)/(sqrt(2.0)*s);
00426 
00427     sat = erfc(t)*0.5;
00428 
00429     _data->_bins.realValue[binmax < _data->_dimSize1-1 ? binmax+1 : binmax]
00430         += sat;
00431 
00432     double a = 1./(sqrt(2*M_PI)*s);
00433     double b = -0.5/(s*s);
00434 
00435     for (bin=binmin; bin<=binmax; bin++) {
00436         double v = bin-ori;
00437         _data->_bins.realValue[bin] += a*exp(b*v*v);
00438     }
00439 }

void HxHistogram::insertVal HxScalarInt    val [inline]
 

Insert value in 1D histogram.

00534 {
00535     incBin((int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5));
00536 }

void HxHistogram::insertVal HxScalarDouble    val [inline]
 

Insert value in 1D histogram.

00540 {
00541     incBin((int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5));
00542 }

void HxHistogram::insertVal HxVec2Int    val [inline]
 

Insert value in 2D histogram.

00546 {
00547     incBin((int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5),
00548            (int) (((val.y() - _data->_lowBin2) / _data->_binWidth2) + 0.5));
00549 }

void HxHistogram::insertVal HxVec2Double    val [inline]
 

Insert value in 2D histogram.

00553 {
00554     incBin((int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5),
00555            (int) (((val.y() - _data->_lowBin2) / _data->_binWidth2) + 0.5));
00556 }

void HxHistogram::insertVal HxVec3Int    val [inline]
 

Insert value in 3D histogram.

00560 {
00561     incBin((int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5),
00562            (int) (((val.y() - _data->_lowBin2) / _data->_binWidth2) + 0.5),
00563            (int) (((val.z() - _data->_lowBin3) / _data->_binWidth3) + 0.5));
00564 }

void HxHistogram::insertVal HxVec3Double    val [inline]
 

Insert value in 3D histogram.

00568 {
00569     incBin((int) (((val.x() - _data->_lowBin1) / _data->_binWidth1) + 0.5),
00570            (int) (((val.y() - _data->_lowBin2) / _data->_binWidth2) + 0.5),
00571            (int) (((val.z() - _data->_lowBin3) / _data->_binWidth3) + 0.5));
00572 }

void HxHistogram::incBin int    bin [inline]
 

Increment the given bin (assumes 1D histogram).

Values outside the histogram range are ignored.

00447 {
00448     if ((bin >= 0) && (bin < _data->_dimSize1))
00449         _data->incBin(bin);
00450 }

void HxHistogram::incBin int    bin1,
int    bin2
[inline]
 

Increment the given bin (assumes 2D histogram).

Values outside the histogram range are ignored.

00454 {
00455     if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00456             (bin2 >= 0) && (bin2 < _data->_dimSize2))
00457         _data->incBin(bin2 * _data->_dimSize1 + bin1);
00458 }

void HxHistogram::incBin int    bin1,
int    bin2,
int    bin3
[inline]
 

Increment the given bin (assumes 3D histogram).

Values outside the histogram range are ignored.

00462 {
00463     if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00464             (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00465             (bin3 >= 0) && (bin3 < _data->_dimSize3))
00466         _data->incBin((bin3 * _data->_dimSize2 + bin2) *
00467                      _data->_dimSize1 + bin1);
00468 }

void HxHistogram::setBin int    bin1,
long    val
[inline]
 

Reset the value of the given bin to val (assumes 1D histogram).

Values outside the histogram range are ignored.

00472 {
00473     if ((bin1 >= 0) && (bin1 < _data->_dimSize1))           
00474         _data->setBin(bin1, val);
00475 }

void HxHistogram::setBin int    bin1,
int    bin2,
long    val
[inline]
 

Reset the value of the given bin to val (assumes 2D histogram).

Values outside the histogram range are ignored.

00479 {
00480     if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00481             (bin2 >= 0) && (bin2 < _data->_dimSize2))
00482         _data->setBin(bin2 * _data->_dimSize1 + bin1, val);
00483 }

void HxHistogram::setBin int    bin1,
int    bin2,
int    bin3,
long    val
[inline]
 

Reset the value of the given bin to val (assumes 3D histogram).

Values outside the histogram range are ignored.

00487 {
00488     if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00489             (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00490             (bin3 >= 0) && (bin3 < _data->_dimSize3))
00491         _data->setBin((bin3 * _data->_dimSize2 + bin2) *
00492                      _data->_dimSize1 + bin1, val);
00493 }

void HxHistogram::setBin int    bin1,
double    val
[inline]
 

Reset the value of the given bin to val (assumes 1D histogram).

Values outside the histogram range are ignored.

00497 {
00498     if ((bin1 >= 0) && (bin1 < _data->_dimSize1))           
00499         _data->setBin(bin1, val);
00500 }

void HxHistogram::setBin int    bin1,
int    bin2,
double    val
[inline]
 

Reset the value of the given bin to val (assumes 2D histogram).

Values outside the histogram range are ignored.

00504 {
00505     if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00506             (bin2 >= 0) && (bin2 < _data->_dimSize2))
00507         _data->setBin(bin2 * _data->_dimSize1 + bin1, val);
00508 }

void HxHistogram::setBin int    bin1,
int    bin2,
int    bin3,
double    val
[inline]
 

Reset the value of the given bin to val (assumes 3D histogram).

Values outside the histogram range are ignored.

00512 {
00513     if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00514             (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00515             (bin3 >= 0) && (bin3 < _data->_dimSize3))
00516         _data->setBin((bin3 * _data->_dimSize2 + bin2) *
00517                      _data->_dimSize1 + bin1, val);
00518 }

HxHistogram HxHistogram::smooth double    sigma = 3.0
 

Smooth histogram data.

00443 {
00444     if (!_data)
00445         return HxHistogram();
00446 
00447     GaussIIR g(sigma);
00448     HxHistogramData *data = new HxHistogramData(REAL_VALUE, *_data);
00449 
00450     /* for now only works for 1D histogram */
00451     /* will be fixed when image processing works on sampled density fields */
00452     /* instead of HxImageRep only... */
00453 
00454 #ifndef _DEBUG
00455     g.lineFilter(data->_bins.realValue, data->_totSize);
00456 #endif
00457 
00458     return HxHistogram(data);
00459 }

std::list< HxVec2Double > HxHistogram::modes  
 

Get histogram modes.

00501 {
00502     HxHistogramData *data = (_data->_dataType != REAL_VALUE) ?
00503         new HxHistogramData(REAL_VALUE, *_data) : _data.pointee();
00504 
00505 
00506 
00507     /* for now only works for 1D histogram */
00508     /* will be fixed when image processing works on sampled density fields */
00509     /* instead of HxImageRep only... */
00510     /* then, see PAMI 22(11), pp. 1318--1323, 2000 */
00511 
00512     data->getUnshared();
00513     std::list<MicrosoftListSortDoesntWork> l;
00514     
00515     /* maxima detection */
00516     double *ptr = data->_bins.realValue;
00517     double max = *ptr++;
00518     int dir = 1;
00519     for (int i=1; i < data->_totSize; i++) {
00520         double val = *ptr++;
00521         double grad = dir ? val-max : max-val;
00522         if (grad <= 0) {
00523             if (dir == 1) // maximum
00524                 l.push_back(MicrosoftListSortDoesntWork(binToValue(i-1,1), max));
00525             // else minimum
00526             dir = dir ? 0 : 1;
00527         }
00528         max = val;
00529     }
00530 
00531     if (data != _data.pointee())
00532         delete data;
00533 
00534     l.sort();
00535     std::list<HxVec2Double> res;
00536     for (std::list<MicrosoftListSortDoesntWork>::iterator it = l.begin();
00537             it != l.end(); it++)
00538         res.push_back(HxVec2Double(*it));
00539 
00540     return res;
00541 }

HxHistogram HxHistogram::normalize double    weight = 1.0
 

Normalize histogram data.

00545 {
00546     if (!_data)
00547         return HxHistogram();
00548     HxHistogramData *data = new HxHistogramData(REAL_VALUE, *_data);
00549 
00550     int n = data->_totSize;
00551     double norm = sum() / weight;
00552     if (fabs(norm) > 0.0)
00553     {
00554         while (--n >= 0)
00555             data->_bins.realValue[n] /= norm;
00556         data->_sum = weight;
00557     }
00558 
00559     return HxHistogram(data);
00560 }

double HxHistogram::sum   const
 

The sum of the histogram.

00564 {
00565     if (!_data)
00566         return 0;
00567     int n = _data->_totSize;
00568     double s = 0;
00569     if (_data->_dataType == REAL_VALUE)
00570         while (--n >= 0)
00571             s += _data->_bins.realValue[n];
00572     else
00573         while (--n >= 0)
00574             s += _data->_bins.intValue[n];
00575     _data->_sum = s;
00576     return s;
00577 }

double HxHistogram::minVal   const
 

The minimum number of elements in the histogram.

00581 {
00582     if (!_data)
00583         return 0;
00584     int n = _data->_totSize;
00585     double m;
00586     if (_data->_dataType == REAL_VALUE) {
00587         m = _data->_bins.realValue[0];
00588         while (--n >= 0)
00589             if (_data->_bins.realValue[n] < m)
00590                 m = _data->_bins.realValue[n];
00591     }
00592     else {
00593         m = _data->_bins.intValue[0];
00594         while (--n >= 0)
00595             if (_data->_bins.intValue[n] < m)
00596                 m = _data->_bins.intValue[n];
00597     }
00598     return m;
00599 }

double HxHistogram::minVal int *    index const
 

The minimum number of elements in the histogram.

Index is the number of the bin at which the minimum number is first found.

00625 {
00626     if (!_data)
00627         return 0;
00628     int n = _data->_totSize;
00629     double m;
00630     *index = 0;
00631     if (_data->_dataType == REAL_VALUE) {
00632         m = _data->_bins.realValue[0];
00633         while (--n >= 0)
00634             if (_data->_bins.realValue[n] < m) {
00635                 m = _data->_bins.realValue[n];
00636                 *index = n;
00637             }
00638     }
00639     else {
00640         m = _data->_bins.intValue[0];
00641         while (--n >= 0)
00642             if (_data->_bins.intValue[n] < m) {
00643                 m = _data->_bins.intValue[n];
00644                 *index = n;
00645             }
00646     }
00647     return m;
00648 }

double HxHistogram::maxVal   const
 

The maximum number of elements in the histogram.

00603 {
00604     if (!_data)
00605         return 0;
00606     int n = _data->_totSize;
00607     double m;
00608     if (_data->_dataType == REAL_VALUE) {
00609         m = _data->_bins.realValue[0];
00610         while (--n >= 0)
00611             if (_data->_bins.realValue[n] > m)
00612                 m = _data->_bins.realValue[n];
00613     }
00614     else {
00615         m = _data->_bins.intValue[0];
00616         while (--n >= 0)
00617             if (_data->_bins.intValue[n] > m)
00618                 m = _data->_bins.intValue[n];
00619     }
00620     return m;
00621 }

double HxHistogram::maxVal int *    index const
 

The maximum number of elements in the histogram.

Index is the number of the bin at which the maximum number is first found.

00652 {
00653     if (!_data)
00654         return 0;
00655     int n = _data->_totSize;
00656     double m;
00657     *index = 0;
00658     if (_data->_dataType == REAL_VALUE) {
00659         m = _data->_bins.realValue[0];
00660         while (--n >= 0)
00661             if (_data->_bins.realValue[n] > m) {
00662                 m = _data->_bins.realValue[n];
00663                 *index = n;
00664             }
00665     }
00666     else {
00667         m = _data->_bins.intValue[0];
00668         while (--n >= 0)
00669             if (_data->_bins.intValue[n] > m) {
00670                 m = _data->_bins.intValue[n];
00671                 *index = n;
00672             }
00673     }
00674     return m;
00675 }

double HxHistogram::intersection const HxHistogram &    rhs const
 

Intersection of histograms.

00699 {
00700     if (!_data)
00701         return 0;
00702     if (!isEqualSize(rhs))
00703         return -1;
00704     int n = _data->_totSize;
00705     double s = 0;
00706     if (_data->_dataType == REAL_VALUE)
00707         if (rhs._data->_dataType == REAL_VALUE)
00708             s = ::intersect(_data->_bins.realValue, rhs._data->_bins.realValue, n);
00709         else
00710             s = ::intersect(_data->_bins.realValue, rhs._data->_bins.intValue, n);
00711     else
00712         if (rhs._data->_dataType == REAL_VALUE)
00713             s = ::intersect(_data->_bins.intValue, rhs._data->_bins.realValue, n);
00714         else
00715             s = ::intersect(_data->_bins.intValue, rhs._data->_bins.intValue, n);
00716 
00717     return s;
00718 }

double HxHistogram::chiSquare const HxHistogram &    rhs const
 

Chi square intersection of histograms.

00736 {
00737     if (!_data)
00738         return 0;
00739     if (!isEqualSize(rhs))
00740         return -1;
00741     int n = _data->_totSize;
00742     double s = 0;
00743     if (_data->_dataType == REAL_VALUE)
00744         if (rhs._data->_dataType == REAL_VALUE)
00745             s = ::chiSq(_data->_bins.realValue, rhs._data->_bins.realValue, n);
00746         else
00747             s = ::chiSq(_data->_bins.realValue, rhs._data->_bins.intValue, n);
00748     else
00749         if (rhs._data->_dataType == REAL_VALUE)
00750             s = ::chiSq(_data->_bins.intValue, rhs._data->_bins.realValue, n);
00751         else
00752             s = ::chiSq(_data->_bins.intValue, rhs._data->_bins.intValue, n);
00753     return s;
00754 }

double HxHistogram::chiSquareNorm const HxHistogram &    rhs const
 

Normalized chi square intersection of histograms.

00773 {
00774     if (!_data)
00775         return 0;
00776     if (!isEqualSize(rhs))
00777         return -1;
00778     int n = _data->_totSize;
00779     double s = 0;
00780     if (_data->_dataType == REAL_VALUE)
00781         if (rhs._data->_dataType == REAL_VALUE)
00782             s = ::chiSqNorm(_data->_bins.realValue, rhs._data->_bins.realValue, n);
00783         else
00784             s = ::chiSqNorm(_data->_bins.realValue, rhs._data->_bins.intValue, n);
00785     else
00786         if (rhs._data->_dataType == REAL_VALUE)
00787             s = ::chiSqNorm(_data->_bins.intValue, rhs._data->_bins.realValue, n);
00788         else
00789             s = ::chiSqNorm(_data->_bins.intValue, rhs._data->_bins.intValue, n);
00790     return s;
00791 }

HxHistogram HxHistogram::convert HxValueType    dataType
 

convert dataType.

00158 {
00159     HxHistogramData *data = new HxHistogramData(*_data);
00160     return HxHistogram(data);
00161 }

void HxHistogram::getDataDouble double *    data
 

Fill the externally allocated buffer with data from this histogram.

00795 {
00796     if (!_data)
00797         return;
00798     int n = _data->_totSize;
00799     if (_data->_dataType == REAL_VALUE)
00800         while (--n >= 0)
00801             data[n] = _data->_bins.realValue[n];
00802     else
00803         while (--n >= 0)
00804             data[n] = _data->_bins.intValue[n];
00805 }

void HxHistogram::getDataInt int *    data
 

Fill the externally allocated buffer with data from this histogram.

00809 {
00810     if (!_data)
00811         return;
00812     int n = _data->_totSize;
00813     if (_data->_dataType == REAL_VALUE)
00814         while (--n >= 0)
00815             data[n] = (int)(_data->_bins.realValue[n] + 0.5);
00816     else
00817         while (--n >= 0)
00818             data[n] = _data->_bins.intValue[n];
00819 }

void HxHistogram::render3d int *    data,
int    dataWidth,
int    dataHeight,
double    elevation,
double    alpha,
double    threshold
 

Assume the histogram is a 3d rgb cube and render it for display in Java in the externally allocated data buffer.

00896 {
00897     if (!_data)
00898         return;
00899     /*
00900     el = (elevation * M_PI) / 180.;
00901     al = (alpha * M_PI) / 180.;
00902     cosa = cos(al);
00903     sina = sin(al);
00904     cose = cos(el);
00905     sine = sin(el);
00906     dataW = dataWidth;
00907     xMin = 190; //for 3D histo
00908     yMax = 190; //255;
00909     */
00910     double el = (elevation * M_PI) / 180.;
00911     double al = (alpha * M_PI) / 180.;
00912     double cosa = cos(al);
00913     double sina = sin(al);
00914     double cose = cos(el);
00915     double sine = sin(el);
00916     int dataW = dataWidth;
00917     int xMin = 190; //for 3D histo
00918     int yMax = 190; //255;
00919     drawAxis(data,cosa,sina,cose,sine,dataW);
00920 
00921     int n = 0;
00922 
00923     if (_data->_dataType == REAL_VALUE) {
00924         for (int b=0 ; b < _data->_dimSize3 ; b++) {
00925             for (int g=0 ; g < _data->_dimSize2 ; g++) {
00926                 for (int r=0 ; r < _data->_dimSize1 ; r++) {
00927                     if (_data->_bins.realValue[n] > threshold) {
00928                         /*
00929                           Doen't work if hist range unequals 0..255
00930                         double rV = r * _data->_binWidth1 + _data->_lowBin1;
00931                         double gV = g * _data->_binWidth2 + _data->_lowBin2;
00932                         double bV = b * _data->_binWidth3 + _data->_lowBin3;
00933                         */
00934                         double rV = r * 255./(_data->_dimSize1-1);
00935                         double gV = g * 255./(_data->_dimSize2-1);
00936                         double bV = b * 255./(_data->_dimSize3-1);
00937                         setPixelV(data, transf3Dto2D(rV,gV,bV,cosa,sina,cose,sine), HxVec3Int(rV,gV,bV), dataW);
00938                     }
00939                     n++;
00940                 }
00941             }
00942         }
00943     }
00944     else {
00945         for (int b=0 ; b < _data->_dimSize3 ; b++) {
00946             for (int g=0 ; g < _data->_dimSize2 ; g++) {
00947                 for (int r=0 ; r < _data->_dimSize1 ; r++) {
00948                     if (_data->_bins.intValue[n] > threshold) {
00949                         /*
00950                           Doen't work if hist range unequals 0..255
00951                         double rV = r * _data->_binWidth1 + _data->_lowBin1;
00952                         double gV = g * _data->_binWidth2 + _data->_lowBin2;
00953                         double bV = b * _data->_binWidth3 + _data->_lowBin3;
00954                         */
00955                         double rV = r * 255./(_data->_dimSize1-1);
00956                         double gV = g * 255./(_data->_dimSize2-1);
00957                         double bV = b * 255./(_data->_dimSize3-1);
00958                         setPixelV(data, transf3Dto2D(rV,gV,bV,cosa,sina,cose,sine), HxVec3Int(rV,gV,bV), dataW);
00959                     }
00960                     n++;
00961                 }
00962             }
00963         }
00964     }
00965 }

STD_OSTREAM & HxHistogram::put STD_OSTREAM &    os,
HxString    delimit = " "
const
 

Print histogram data in the given stream.

00969 {
00970     if (!_data)
00971         return os << "HxHistogram(null)" << STD_ENDL;
00972     if (_data->_dataType == REAL_VALUE)
00973         for (int dim3=0; dim3<dimensionSize(3) ; dim3++) 
00974             for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) 
00975                 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++)
00976                     os << _data->_bins.realValue[(dim3 * _data->_dimSize2
00977                         + dim2) * _data->_dimSize1 + dim1] << delimit;
00978     else
00979         for (int dim3=0; dim3<dimensionSize(3) ; dim3++) 
00980             for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) 
00981                 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++)
00982                     os << _data->_bins.intValue[(dim3 * _data->_dimSize2
00983                         + dim2) * _data->_dimSize1 + dim1] << delimit;
00984     return os;
00985 }

int HxHistogram::write HxString    filename
 

Write histogram to disk.

01004 {
01005     HxString name;
01006     FILE *fp;
01007     IOHEADER header;
01008 
01009     if (!_data)
01010         return 0;
01011     
01012     name = filename + ".hst";
01013 
01014     fp = fopen(name.c_str(), "wb");
01015     if (!fp)
01016         return 0;
01017 
01018     header.dataType = _data->_dataType;
01019     header.dimensions = _data->_nDims;
01020     header.lowBin1 = _data->_lowBin1;
01021     header.highBin1 = _data->_highBin1;
01022     header.nBins1 = _data->_dimSize1;
01023     header.lowBin2 = _data->_lowBin2;
01024     header.highBin2 = _data->_highBin2;
01025     header.nBins2 = _data->_dimSize2;
01026     header.lowBin3 = _data->_lowBin3;
01027     header.highBin3 = _data->_highBin3;
01028     header.nBins3 = _data->_dimSize3;
01029     fwrite(&header, sizeof(header), 1, fp);
01030 
01031     if (_data->_dataType == REAL_VALUE)
01032         fwrite(_data->_bins.realValue, _data->_totSize,
01033             sizeof(*(_data->_bins.realValue)), fp);
01034     else
01035         fwrite(_data->_bins.intValue, _data->_totSize,
01036             sizeof(*(_data->_bins.intValue)), fp);
01037 
01038     fclose(fp);
01039 
01040     return 1;
01041 }

HxHistogram HxHistogram::threshold double    valThreshold
 

Returns new histogram in which bins with count<=valThreshold are set to 0.0, bins with count>valThreshold keep original value.

01045 {
01046     if (!_data)
01047         return HxHistogram();
01048     HxHistogramData *data = new HxHistogramData(*_data);
01049 
01050     int n = data->_totSize;
01051 
01052     if (data->_dataType == REAL_VALUE)
01053         while (--n >= 0) {
01054             if (data->_bins.realValue[n]<=valThreshold)
01055                 data->_bins.realValue[n]=0.0;
01056         }
01057     else
01058         while (--n >= 0) {
01059             if (data->_bins.intValue[n]<=valThreshold)
01060                 data->_bins.intValue[n]=0.0;
01061         }
01062     
01063     return HxHistogram(data);
01064 }

int HxHistogram::countBins double    valThreshold = 0.0
 

Returns number of bins with count>valThreshold.

Counts number of non-empty bins by default.

01068 {
01069     if (!_data)
01070         return 0;    
01071 
01072     int n = _data->_totSize;    
01073     
01074     int counter=0;
01075 
01076     if (_data->_dataType == REAL_VALUE)
01077         while (--n >= 0) {
01078             if (_data->_bins.realValue[n]>valThreshold)
01079                counter++;
01080         }
01081     else
01082         while (--n >= 0) {
01083             if (_data->_bins.intValue[n]>valThreshold)
01084                counter++;
01085         }
01086     
01087     return counter;
01088 }

HxHistogram HxHistogram::reduceRange int    binMin1,
int    binMax1 = -1,
int    binMin2 = 0,
int    binMax2 = -1,
int    binMin3 = 0,
int    binMax3 = -1
 

Returns new histogram containing given range of bins only.

(Including given min and max.) Default value -1 maps to dimensionSize()-1.

01094 {
01095     if (!_data)
01096         return HxHistogram();
01097     
01098     // Default value binMax=-1 maps to dimensionSize()-1.
01099     if (binMax1<0)
01100         binMax1=dimensionSize(1)-1;
01101     if (binMax2<0)
01102         binMax2=dimensionSize(2)-1;
01103     if (binMax3<0)
01104         binMax3=dimensionSize(3)-1;
01105 
01106     if (binMin1<0 || binMin2<0 || binMin3<0)
01107     {
01108         STD_CERR << "Error in HxHistogram::reduceRange, minimum smaller than 0." << STD_ENDL;
01109         return HxHistogram();
01110     }
01111 
01112     if (binMax1<binMin1 || binMax2<binMin2 || binMax3<binMin3)
01113     {
01114         STD_CERR << "Error in HxHistogram::reduceRange, minimum higher than maximum." << STD_ENDL;
01115         return HxHistogram();
01116     }
01117 
01118     // Make new histogram for given range
01119     HxHistogram h=HxHistogram(dataType(),dimensionality(),
01120         binToValue(binMin1,1),binToValue(binMax1,1),binMax1-binMin1+1,
01121         binToValue(binMin2,2),binToValue(binMax2,2),binMax2-binMin2+1,
01122         binToValue(binMin3,3),binToValue(binMax3,3),binMax3-binMin3+1);
01123 
01124     if (_data->_dataType == REAL_VALUE) {
01125         for (int z=binMin3; z<=binMax3; z++)
01126             for (int y=binMin2; y<=binMax2; y++)
01127                 for (int x=binMin1; x<=binMax1; x++) {
01128                     int n = ((z-binMin3) * _data->_dimSize2 + (y-binMin2)) *
01129                          _data->_dimSize1 + x-binMin1;
01130                     int m = (z * _data->_dimSize2 + y) *
01131                          _data->_dimSize1 + x;
01132                     h._data->_bins.realValue[n] = _data->_bins.realValue[m];
01133                 }
01134     }
01135     else {
01136         for (int z=binMin3; z<=binMax3; z++)
01137             for (int y=binMin2; y<=binMax2; y++)
01138                 for (int x=binMin1; x<=binMax1; x++) {
01139                     int n = ((z-binMin3) * _data->_dimSize2 + (y-binMin2)) *
01140                          _data->_dimSize1 + x-binMin1;
01141                     int m = (z * _data->_dimSize2 + y) *
01142                          _data->_dimSize1 + x;
01143                     h._data->_bins.intValue[n] = _data->_bins.intValue[m];
01144                 }
01145     }
01146 
01147     return h;
01148 }

HxHistogram HxHistogram::reduceRangeVal double    binValMin1,
double    binValMax1,
double    binValMin2 = 0,
double    binValMax2 = 0,
double    binValMin3 = 0,
double    binValMax3 = 0
 

Returns new histogram containing given range of values (mapped to bin numbers) only.

(Including bins for given min and max.) If min==max, the whole range for that dimension is returned.

01153 {
01154     if (binValMin1==binValMax1) {
01155         binValMin1=_data->_lowBin1;
01156         binValMax1=_data->_highBin1;
01157     }
01158     if (binValMin1<_data->_lowBin1)
01159         binValMin1=_data->_lowBin1;
01160     if (binValMax1>_data->_highBin1)
01161         binValMax1=_data->_highBin1;
01162     if (binValMin2==binValMax2) {
01163         binValMin2=_data->_lowBin2;
01164         binValMax2=_data->_highBin2;
01165     }
01166     if (binValMin2<_data->_lowBin2)
01167         binValMin2=_data->_lowBin2;
01168     if (binValMax2>_data->_highBin2)
01169         binValMax2=_data->_highBin2;
01170     if (binValMin3==binValMax3) {
01171         binValMin3=_data->_lowBin3;
01172         binValMax3=_data->_highBin3;
01173     }
01174     if (binValMin3<_data->_lowBin3)
01175         binValMin3=_data->_lowBin3;
01176     if (binValMax3>_data->_highBin3)
01177         binValMax3=_data->_highBin3;
01178     return reduceRange(valueToBin(binValMin1,1),valueToBin(binValMax1,1),
01179         valueToBin(binValMin2,2),valueToBin(binValMax2,2),
01180         valueToBin(binValMin3,3),valueToBin(binValMax3,3));
01181 }

HxHistogram HxHistogram::to1D int    dim = 1
 

Projects n-dimensional (1<n<=3) histogram on a 1-D histogram for given dimension.

01186 {
01187     if (dimensionality()<2)
01188     {
01189 //      STD_CERR << "Warning. HxHistogram::to1D, dimensionality is " << dimensionality() << STD_ENDL;       
01190         return *this;
01191     }
01192 
01193     if (dim<1 || dim>3)
01194     {
01195         STD_CERR << "Error. Dimension out of bounds: " << dim << STD_ENDL;      
01196         return HxHistogram();
01197     }
01198 
01199     
01200     HxHistogram result; 
01201     result=HxHistogram(dataType(), 1, 
01202                         lowBin(dim),highBin(dim),dimensionSize(dim),
01203                         0,0,0,
01204                         0,0,0);
01205 
01206     int otherDim1=-1;
01207     int otherDim2=-1;
01208 
01209     if (dim==1)
01210     {
01211         otherDim1=3;
01212         otherDim2=2;
01213     }
01214     if (dim==2)
01215     {
01216         otherDim1=3;
01217         otherDim2=1;
01218     }
01219     if (dim==3)
01220     {
01221         otherDim1=2;
01222         otherDim2=1;
01223     }
01224 
01225     for (int b=0; b<dimensionSize(dim); b++)
01226     {
01227         double total=0;
01228         for (int sb=0; sb<dimensionSize(otherDim1); sb++)
01229             for (int tb=0; tb<dimensionSize(otherDim2); tb++)
01230             {                   
01231                 if (dim==1)
01232                     total+=get(b,tb,sb);
01233                 if (dim==2)
01234                     total+=get(tb,b,sb);
01235                 if (dim==3)
01236                     total+=get(tb,sb,b);
01237             }           
01238         result.setBin(b, total);
01239     }
01240 
01241     return result;
01242 }


The documentation for this class was generated from the following files:
Generated on Tue Jan 8 13:59:25 2002 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001