#include <HxHistogram.h>
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< HxVec2Double > | modes () |
| 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... | |
compute threshold value | |
| int | computeIsodataThreshold (void) |
| int | computeEntropyThreshold (void) |
Output/display | |
| HxHistogram | convert (HxValueType dataType) |
| convert dataType. More... | |
| void | getTheData (double *x, double *y) |
| Fill the externally allocated buffer with data from this histogram. More... | |
| void | getTheData2 (double *x1, double *x2, double *y) |
| Fill the externally allocated buffer with data from this histogram. More... | |
| void | getTheData3 (double *x1, double *x2, double *x3, double *y) |
| Fill the externally allocated buffer with data from this histogram. 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... | |
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.
CHANGED: JMG CdB
|
|
Construct an empty histogram.
00068 : _data(0)
00069 {
00070 }
|
|
|
Copy constructor.
00072 : _data(rhs._data) 00073 { 00074 } |
|
|
Construct a 1D histogram with a range from 0 to dimSize - 1 and a binWidth of 1.
00077 {
00078 _data = new HxHistogramData(REAL_VALUE, 1,
00079 0, dimSize - 1, dimSize,
00080 0, 0, 0,
00081 0, 0, 0);
00082 }
|
|
||||||||||||
|
Construct a 2D histogram with a range from 0 to dimSize - 1 and a binWidth of 1 in each dimension.
00085 {
00086 _data = new HxHistogramData(REAL_VALUE, 2,
00087 0, dimSize1 - 1, dimSize1,
00088 0, dimSize2 - 1, dimSize2,
00089 0, 0, 0);
00090 }
|
|
||||||||||||||||
|
Construct a 3D histogram with a range from 0 to dimSize - 1 and a binWidth of 1 in each dimension.
00093 {
00094 _data = new HxHistogramData(REAL_VALUE, 3,
00095 0, dimSize1 - 1, dimSize1,
00096 0, dimSize2 - 1, dimSize2,
00097 0, dimSize3 - 1, dimSize3);
00098 }
|
|
||||||||||||||||||||||||
|
Construct Histogram with given data type and number of dimensions. The range in a dimension is 0 to dimSize - 1, the binWidth is 1.
00102 {
00103 _data = new HxHistogramData(dataType, dimensions,
00104 0, dimSize1 - 1, dimSize1,
00105 0, dimSize2 - 1, dimSize2,
00106 0, dimSize3 - 1, dimSize3);
00107 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Construct a Histogram with given parameters. If dataType == INT\_VALUE parameters are casted.
00113 {
00114 _data = new HxHistogramData(dataType, dimensions,
00115 lowBin1, highBin1, nBins1,
00116 lowBin2, highBin2, nBins2,
00117 lowBin3, highBin3, nBins3);
00118 }
|
|
|
Read a Histogram from disk.
00125 {
00126 HxString name;
00127 FILE *fp;
00128 IOHEADER header;
00129
00130 name = filename + ".hst";
00131
00132 fp = fopen(name.c_str(), "rb");
00133 if (!fp)
00134 _data = 0;
00135 else {
00136 fread(&header, sizeof(header), 1, fp);
00137
00138 _data = new HxHistogramData(header.dataType, header.dimensions,
00139 header.lowBin1, header.highBin1, header.nBins1,
00140 header.lowBin2, header.highBin2, header.nBins2,
00141 header.lowBin3, header.highBin3, header.nBins3);
00142
00143 if (_data->_dataType == REAL_VALUE)
00144 fread(_data->_bins.realValue, _data->_totSize,
00145 sizeof(*(_data->_bins.realValue)), fp);
00146 else
00147 fread(_data->_bins.intValue, _data->_totSize,
00148 sizeof(*(_data->_bins.intValue)), fp);
00149 fclose(fp);
00150 }
00151 }
|
|
|
Destructor.
00154 {
00155 }
|
|
|
Assignment operator.
00166 {
00167 _data = rhs._data;
00168 return *this;
00169 }
|
|
|
Indicates wether this is a valid histogram.
00173 {
00174 return _data ? 0 : 1;
00175 }
|
|
|
Indicates wether this is a valid histogram.
00179 {
00180 return _data ? 1 : 0;
00181 }
|
|
|
The unique identifier of the histogram.
00185 {
00186 return _data ? _data->_id : 0 ;
00187 }
|
|
|
The data value type. Either INT\_VALUE or REAL\_VALUE.
00191 {
00192 return _data ? _data->_dataType : INT_VALUE;
00193 }
|
|
|
The number of dimensions of the histogram.
00197 {
00198 return _data ? _data->_nDims : 0;
00199 }
|
|
|
The size of the histogram in the i-th dimension. The first dimension has i = 1.
00203 {
00204 if (!_data)
00205 return 0;
00206 switch (dim) {
00207 case 1: return _data->_dimSize1;
00208 case 2: return _data->_dimSize2;
00209 case 3: return _data->_dimSize3;
00210 }
00211 return 0;
00212 }
|
|
|
The total size of the histogram.
00216 {
00217 if (!_data)
00218 return 0;
00219 return _data->_totSize;
00220 }
|
|
|
The lowest bin in the i-th dimension.
00224 {
00225 if (!_data)
00226 return 0;
00227 switch (dim) {
00228 case 1: return _data->_lowBin1;
00229 case 2: return _data->_lowBin2;
00230 case 3: return _data->_lowBin3;
00231 }
00232 return 0;
00233 }
|
|
|
The highest bin in the i-th dimension.
00237 {
00238 if (!_data)
00239 return 0;
00240 switch (dim) {
00241 case 1: return _data->_highBin1;
00242 case 2: return _data->_highBin2;
00243 case 3: return _data->_highBin3;
00244 }
00245 return 0;
00246 }
|
|
|
The bin width in the i-th dimension.
00250 {
00251 if (!_data)
00252 return 0;
00253 switch (dim) {
00254 case 1: return _data->_binWidth1;
00255 case 2: return _data->_binWidth2;
00256 case 3: return _data->_binWidth3;
00257 }
00258 return 0;
00259 }
|
|
||||||||||||
|
Translate bin to value.
00263 {
00264 if (!_data)
00265 return 0;
00266 switch (dimension) {
00267 case 1: return (bin+0.5) * _data->_binWidth1 + _data->_lowBin1;
00268 case 2: return (bin+0.5) * _data->_binWidth2 + _data->_lowBin2;
00269 case 3: return (bin+0.5) * _data->_binWidth3 + _data->_lowBin3;
00270 }
00271 return 0;
00272 }
|
|
||||||||||||
|
Translate value to bin.
00276 {
00277 if (!_data)
00278 return -1;
00279 switch (dimension) {
00280 case 1: return (int) ((val - _data->_lowRange1) * _data->_binFac1);
00281 case 2: return (int) ((val - _data->_lowRange2) * _data->_binFac2);
00282 case 3: return (int) ((val - _data->_lowRange3) * _data->_binFac3);
00283 }
00284 return -1;
00285 }
|
|
|
Get the number of elements in the given bin.
00464 {
00465 return _data ? _data->getBin(bin1) : 0;
00466 }
|
|
||||||||||||
|
Get the number of elements in the given bin.
00470 {
00471 return _data ? _data->getBin(bin2 * _data->_dimSize1 + bin1) : 0;
00472 }
|
|
||||||||||||||||
|
Get the number of elements in the given bin.
00476 {
00477 return _data ? _data->getBin((bin3 * _data->_dimSize2 + bin2) *
00478 _data->_dimSize1 + bin1) : 0;
00479 }
|
|
|
Insert value in 1D histogram.
00289 {
00290 if (_data && (_data->_nDims == 1))
00291 incBinChecked(
00292 (int) ((val - _data->_lowRange1) * _data->_binFac1));
00293 }
|
|
|
Insert value in 1D histogram.
00297 {
00298 if (_data && (_data->_nDims == 1))
00299 incBinChecked(
00300 (int) ((val - _data->_lowRange1) * _data->_binFac1));
00301 }
|
|
|
Insert value in 1D histogram.
00305 {
00306 if (_data && (_data->_nDims == 1))
00307 incBinChecked(
00308 (int) ((val.x() - _data->_lowRange1) * _data->_binFac1));
00309 }
|
|
|
Insert value in 1D histogram.
00313 {
00314 if (_data && (_data->_nDims == 1))
00315 incBinChecked(
00316 (int) ((val.x() - _data->_lowRange1) * _data->_binFac1));
00317 }
|
|
|
Insert value in 2D histogram.
00321 {
00322 if (_data && (_data->_nDims == 2))
00323 incBinChecked(
00324 (int) ((val.x() - _data->_lowRange1) * _data->_binFac1),
00325 (int) ((val.y() - _data->_lowRange2) * _data->_binFac2));
00326 }
|
|
|
Insert value in 2D histogram.
00330 {
00331 if (_data && (_data->_nDims == 2))
00332 incBinChecked(
00333 (int) ((val.x() - _data->_lowRange1) * _data->_binFac1),
00334 (int) ((val.y() - _data->_lowRange2) * _data->_binFac2));
00335 }
|
|
|
Insert value in 3D histogram.
00339 {
00340 if (_data && (_data->_nDims == 3))
00341 incBinChecked(
00342 (int) ((val.x() - _data->_lowRange1) * _data->_binFac1),
00343 (int) ((val.y() - _data->_lowRange2) * _data->_binFac2),
00344 (int) ((val.z() - _data->_lowRange3) * _data->_binFac3));
00345 }
|
|
|
Insert value in 3D histogram.
00349 {
00350 if (_data && (_data->_nDims == 3))
00351 incBinChecked(
00352 (int) ((val.x() - _data->_lowRange1) * _data->_binFac1),
00353 (int) ((val.y() - _data->_lowRange2) * _data->_binFac2),
00354 (int) ((val.z() - _data->_lowRange3) * _data->_binFac3));
00355 }
|
|
|
Increment the given bin. Checks whether this is a 1D histogram and preserves reference count. Values outside the histogram range are ignored.
00359 {
00360 if (_data) {
00361 if ((_data->_nDims == 1) &&
00362 (bin >= 0) && (bin < _data->_dimSize1)) {
00363 _data->getUnshared();
00364 _data->incBin(bin);
00365 }
00366 }
00367 }
|
|
||||||||||||
|
Increment the given bin. Checks whether this is a 2D histogram and preserves reference count. Values outside the histogram range are ignored.
00371 {
00372 if (_data) {
00373 if ((_data->_nDims == 2) &&
00374 (bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00375 (bin2 >= 0) && (bin2 < _data->_dimSize2)) {
00376 _data->getUnshared();
00377 _data->incBin(bin2 * _data->_dimSize1 + bin1);
00378 }
00379 }
00380 }
|
|
||||||||||||||||
|
Increment the given bin. Checks whether this is a 3D histogram and preserves reference count. Values outside the histogram range are ignored.
00384 {
00385 if (_data) {
00386 if ((_data->_nDims == 3) &&
00387 (bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00388 (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00389 (bin3 >= 0) && (bin3 < _data->_dimSize3)) {
00390 _data->getUnshared();
00391 _data->incBin((bin3 * _data->_dimSize2 + bin2) *
00392 _data->_dimSize1 + bin1);
00393 }
00394 }
00395 }
|
|
|
Insert value in 1D histogram.
00558 {
00559 incBin((int) ((val - _data->_lowRange1) * _data->_binFac1));
00560 }
|
|
|
Insert value in 1D histogram.
00564 {
00565 incBin((int) ((val - _data->_lowRange1) * _data->_binFac1));
00566 }
|
|
||||||||||||
|
Kernel Density Estimator.
00400 {
00401 if (!_data || (_data->_dataType != REAL_VALUE))
00402 return;
00403
00404 double ori = (val - _data->_lowBin1) / _data->_binWidth1;
00405 double s = sigma/_data->_binWidth1;
00406 double t, sat;
00407
00408 int binmin = (int) (ori-3*s+0.5);
00409 int binmax = (int) (ori+3*s+0.5);
00410 int bin;
00411
00412 if (binmin < 0)
00413 binmin = 0;
00414
00415 /* gaussian mass left outside kernel */
00416 t = (ori-binmin+0.5)/(sqrt(2.0)*s);
00417
00418 sat = erfc(t)*0.5;
00419
00420 _data->_bins.realValue[binmin ? binmin-1 : 0] += sat;
00421
00422 if (binmax >= _data->_dimSize1)
00423 binmax = _data->_dimSize1-1;
00424
00425 /* gaussian mass right outside kernel */
00426 t = (binmax-ori+0.5)/(sqrt(2.0)*s);
00427
00428 sat = erfc(t)*0.5;
00429
00430 _data->_bins.realValue[binmax < _data->_dimSize1-1 ? binmax+1 : binmax]
00431 += sat;
00432
00433 double a = 1./(sqrt(2*M_PI)*s);
00434 double b = -0.5/(s*s);
00435
00436 for (bin=binmin; bin<=binmax; bin++) {
00437 double v = bin-ori;
00438 _data->_bins.realValue[bin] += a*exp(b*v*v);
00439 }
00440 }
|
|
|
Insert value in 1D histogram.
|
|
|
Insert value in 1D histogram.
|
|
|
Insert value in 2D histogram.
|
|
|
Insert value in 2D histogram.
|
|
|
Insert value in 3D histogram.
|
|
|
Insert value in 3D histogram.
|
|
|
Increment the given bin (assumes 1D histogram). Values outside the histogram range are ignored.
00483 {
00484 if ((bin >= 0) && (bin < _data->_dimSize1))
00485 _data->incBin(bin);
00486 }
|
|
||||||||||||
|
Increment the given bin (assumes 2D histogram). Values outside the histogram range are ignored.
00490 {
00491 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00492 (bin2 >= 0) && (bin2 < _data->_dimSize2))
00493 _data->incBin(bin2 * _data->_dimSize1 + bin1);
00494 }
|
|
||||||||||||||||
|
Increment the given bin (assumes 3D histogram). Values outside the histogram range are ignored.
00498 {
00499 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00500 (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00501 (bin3 >= 0) && (bin3 < _data->_dimSize3))
00502 _data->incBin((bin3 * _data->_dimSize2 + bin2) *
00503 _data->_dimSize1 + bin1);
00504 }
|
|
||||||||||||
|
Reset the value of the given bin to val (assumes 1D histogram). Values outside the histogram range are ignored.
00508 {
00509 if ((bin1 >= 0) && (bin1 < _data->_dimSize1))
00510 _data->setBin(bin1, val);
00511 }
|
|
||||||||||||||||
|
Reset the value of the given bin to val (assumes 2D histogram). Values outside the histogram range are ignored.
00515 {
00516 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00517 (bin2 >= 0) && (bin2 < _data->_dimSize2))
00518 _data->setBin(bin2 * _data->_dimSize1 + bin1, val);
00519 }
|
|
||||||||||||||||||||
|
Reset the value of the given bin to val (assumes 3D histogram). Values outside the histogram range are ignored.
00523 {
00524 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00525 (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00526 (bin3 >= 0) && (bin3 < _data->_dimSize3))
00527 _data->setBin((bin3 * _data->_dimSize2 + bin2) *
00528 _data->_dimSize1 + bin1, val);
00529 }
|
|
||||||||||||
|
Reset the value of the given bin to val (assumes 1D histogram). Values outside the histogram range are ignored.
00533 {
00534 if ((bin1 >= 0) && (bin1 < _data->_dimSize1))
00535 _data->setBin(bin1, val);
00536 }
|
|
||||||||||||||||
|
Reset the value of the given bin to val (assumes 2D histogram). Values outside the histogram range are ignored.
00540 {
00541 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00542 (bin2 >= 0) && (bin2 < _data->_dimSize2))
00543 _data->setBin(bin2 * _data->_dimSize1 + bin1, val);
00544 }
|
|
||||||||||||||||||||
|
Reset the value of the given bin to val (assumes 3D histogram). Values outside the histogram range are ignored.
00548 {
00549 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00550 (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00551 (bin3 >= 0) && (bin3 < _data->_dimSize3))
00552 _data->setBin((bin3 * _data->_dimSize2 + bin2) *
00553 _data->_dimSize1 + bin1, val);
00554 }
|
|
|
Smooth histogram data.
00444 {
00445 if (!_data)
00446 return HxHistogram();
00447
00448 GaussIIR g(sigma);
00449 HxHistogramData *data = new HxHistogramData(REAL_VALUE, *_data);
00450
00451 /* for now only works for 1D histogram */
00452 /* will be fixed when image processing works on sampled density fields */
00453 /* instead of HxImageRep only... */
00454
00455 #ifndef _DEBUG
00456 g.lineFilter(data->_bins.realValue, data->_totSize);
00457 #endif
00458
00459 return HxHistogram(data);
00460 }
|
|
|
Get histogram modes.
00502 {
00503 HxHistogramData *data = (_data->_dataType != REAL_VALUE) ?
00504 new HxHistogramData(REAL_VALUE, *_data) : _data.pointee();
00505
00506
00507
00508 /* for now only works for 1D histogram */
00509 /* will be fixed when image processing works on sampled density fields */
00510 /* instead of HxImageRep only... */
00511 /* then, see PAMI 22(11), pp. 1318--1323, 2000 */
00512
00513 data->getUnshared();
00514 std::list<MicrosoftListSortDoesntWork> l;
00515
00516 /* maxima detection */
00517 double *ptr = data->_bins.realValue;
00518 double max = *ptr++;
00519 int dir = 1;
00520 for (int i=1; i < data->_totSize; i++) {
00521 double val = *ptr++;
00522 double grad = dir ? val-max : max-val;
00523 if (grad <= 0) {
00524 if (dir == 1) // maximum
00525 l.push_back(MicrosoftListSortDoesntWork(binToValue(i-1,1), max));
00526 // else minimum
00527 dir = dir ? 0 : 1;
00528 }
00529 max = val;
00530 }
00531
00532 if (data != _data.pointee())
00533 delete data;
00534
00535 l.sort();
00536 std::list<HxVec2Double> res;
00537 for (std::list<MicrosoftListSortDoesntWork>::iterator it = l.begin();
00538 it != l.end(); it++)
00539 res.push_back(HxVec2Double(*it));
00540
00541 return res;
00542 }
|
|
|
Normalize histogram data.
00546 {
00547 if (!_data)
00548 return HxHistogram();
00549 HxHistogramData *data = new HxHistogramData(REAL_VALUE, *_data);
00550
00551 int n = data->_totSize;
00552 double norm = sum() / weight;
00553 if (fabs(norm) > 0.0)
00554 {
00555 while (--n >= 0)
00556 data->_bins.realValue[n] /= norm;
00557 data->_sum = weight;
00558 }
00559
00560 return HxHistogram(data);
00561 }
|
|
|
The sum of the histogram.
00565 {
00566 if (!_data)
00567 return 0;
00568 int n = _data->_totSize;
00569 double s = 0;
00570 if (_data->_dataType == REAL_VALUE)
00571 while (--n >= 0)
00572 s += _data->_bins.realValue[n];
00573 else
00574 while (--n >= 0)
00575 s += _data->_bins.intValue[n];
00576 _data->_sum = s;
00577 return s;
00578 }
|
|
|
The minimum number of elements in the histogram.
00582 {
00583 if (!_data)
00584 return 0;
00585 int n = _data->_totSize;
00586 double m;
00587 if (_data->_dataType == REAL_VALUE) {
00588 m = _data->_bins.realValue[0];
00589 while (--n >= 0)
00590 if (_data->_bins.realValue[n] < m)
00591 m = _data->_bins.realValue[n];
00592 }
00593 else {
00594 m = _data->_bins.intValue[0];
00595 while (--n >= 0)
00596 if (_data->_bins.intValue[n] < m)
00597 m = _data->_bins.intValue[n];
00598 }
00599 return m;
00600 }
|
|
|
The minimum number of elements in the histogram. Index is the number of the bin at which the minimum number is first found.
00626 {
00627 if (!_data)
00628 return 0;
00629 int n = _data->_totSize;
00630 double m;
00631 *index = 0;
00632 if (_data->_dataType == REAL_VALUE) {
00633 m = _data->_bins.realValue[0];
00634 while (--n >= 0)
00635 if (_data->_bins.realValue[n] < m) {
00636 m = _data->_bins.realValue[n];
00637 *index = n;
00638 }
00639 }
00640 else {
00641 m = _data->_bins.intValue[0];
00642 while (--n >= 0)
00643 if (_data->_bins.intValue[n] < m) {
00644 m = _data->_bins.intValue[n];
00645 *index = n;
00646 }
00647 }
00648 return m;
00649 }
|
|
|
The maximum number of elements in the histogram.
00604 {
00605 if (!_data)
00606 return 0;
00607 int n = _data->_totSize;
00608 double m;
00609 if (_data->_dataType == REAL_VALUE) {
00610 m = _data->_bins.realValue[0];
00611 while (--n >= 0)
00612 if (_data->_bins.realValue[n] > m)
00613 m = _data->_bins.realValue[n];
00614 }
00615 else {
00616 m = _data->_bins.intValue[0];
00617 while (--n >= 0)
00618 if (_data->_bins.intValue[n] > m)
00619 m = _data->_bins.intValue[n];
00620 }
00621 return m;
00622 }
|
|
|
The maximum number of elements in the histogram. Index is the number of the bin at which the maximum number is first found.
00653 {
00654 if (!_data)
00655 return 0;
00656 int n = _data->_totSize;
00657 double m;
00658 *index = 0;
00659 if (_data->_dataType == REAL_VALUE) {
00660 m = _data->_bins.realValue[0];
00661 while (--n >= 0)
00662 if (_data->_bins.realValue[n] > m) {
00663 m = _data->_bins.realValue[n];
00664 *index = n;
00665 }
00666 }
00667 else {
00668 m = _data->_bins.intValue[0];
00669 while (--n >= 0)
00670 if (_data->_bins.intValue[n] > m) {
00671 m = _data->_bins.intValue[n];
00672 *index = n;
00673 }
00674 }
00675 return m;
00676 }
|
|
|
Intersection of histograms.
00700 {
00701 if (!_data)
00702 return 0;
00703 if (!isEqualSize(rhs))
00704 return -1;
00705 int n = _data->_totSize;
00706 double s = 0;
00707 if (_data->_dataType == REAL_VALUE)
00708 if (rhs._data->_dataType == REAL_VALUE)
00709 s = ::intersect(_data->_bins.realValue, rhs._data->_bins.realValue, n);
00710 else
00711 s = ::intersect(_data->_bins.realValue, rhs._data->_bins.intValue, n);
00712 else
00713 if (rhs._data->_dataType == REAL_VALUE)
00714 s = ::intersect(_data->_bins.intValue, rhs._data->_bins.realValue, n);
00715 else
00716 s = ::intersect(_data->_bins.intValue, rhs._data->_bins.intValue, n);
00717
00718 return s;
00719 }
|
|
|
Chi square intersection of histograms.
00737 {
00738 if (!_data)
00739 return 0;
00740 if (!isEqualSize(rhs))
00741 return -1;
00742 int n = _data->_totSize;
00743 double s = 0;
00744 if (_data->_dataType == REAL_VALUE)
00745 if (rhs._data->_dataType == REAL_VALUE)
00746 s = ::chiSq(_data->_bins.realValue, rhs._data->_bins.realValue, n);
00747 else
00748 s = ::chiSq(_data->_bins.realValue, rhs._data->_bins.intValue, n);
00749 else
00750 if (rhs._data->_dataType == REAL_VALUE)
00751 s = ::chiSq(_data->_bins.intValue, rhs._data->_bins.realValue, n);
00752 else
00753 s = ::chiSq(_data->_bins.intValue, rhs._data->_bins.intValue, n);
00754 return s;
00755 }
|
|
|
Normalized chi square intersection of histograms.
00774 {
00775 if (!_data)
00776 return 0;
00777 if (!isEqualSize(rhs))
00778 return -1;
00779 int n = _data->_totSize;
00780 double s = 0;
00781 if (_data->_dataType == REAL_VALUE)
00782 if (rhs._data->_dataType == REAL_VALUE)
00783 s = ::chiSqNorm(_data->_bins.realValue, rhs._data->_bins.realValue, n);
00784 else
00785 s = ::chiSqNorm(_data->_bins.realValue, rhs._data->_bins.intValue, n);
00786 else
00787 if (rhs._data->_dataType == REAL_VALUE)
00788 s = ::chiSqNorm(_data->_bins.intValue, rhs._data->_bins.realValue, n);
00789 else
00790 s = ::chiSqNorm(_data->_bins.intValue, rhs._data->_bins.intValue, n);
00791 return s;
00792 }
|
|
|
convert dataType.
00159 {
00160 HxHistogramData *data = new HxHistogramData(*_data);
00161 return HxHistogram(data);
00162 }
|
|
||||||||||||
|
Fill the externally allocated buffer with data from this histogram. The pointer to x represents the bin value, y the bin count.
00796 {
00797 if (!_data)
00798 return;
00799
00800 int n = 0;
00801 if (_data->_dataType == REAL_VALUE)
00802 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00803 x[n] = binToValue(dim1,1);
00804 y[n] = _data->_bins.realValue[dim1];
00805 n++;
00806 }
00807 else
00808 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00809 x[n] = binToValue(dim1,1);
00810 y[n] = _data->_bins.intValue[dim1];
00811 n++;
00812 }
00813 }
|
|
||||||||||||||||
|
Fill the externally allocated buffer with data from this histogram. The pointer to x1,x2 represents the bin value, y the bin count.
00817 {
00818 if (!_data)
00819 return;
00820
00821 int n = 0;
00822 if (_data->_dataType == REAL_VALUE)
00823 for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) {
00824 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00825 x1[n] = binToValue(dim1,1);
00826 x2[n] = binToValue(dim2,2);
00827 y[n] = _data->_bins.realValue[dim2 * _data->_dimSize1
00828 + dim1];
00829 n++;
00830 }
00831 }
00832 else
00833 for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) {
00834 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00835 x1[n] = binToValue(dim1,1);
00836 x2[n] = binToValue(dim2,2);
00837 y[n] = _data->_bins.intValue[dim2 * _data->_dimSize1
00838 + dim1];
00839 n++;
00840 }
00841 }
00842 }
|
|
||||||||||||||||||||
|
Fill the externally allocated buffer with data from this histogram. The pointer to x1,x2,x3 represents the bin value, y the bin count.
00846 {
00847 if (!_data)
00848 return;
00849
00850 int n = 0;
00851 if (_data->_dataType == REAL_VALUE)
00852 for (int dim3=0 ; dim3<dimensionSize(3) ; dim3++) {
00853 for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) {
00854 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00855 x1[n] = binToValue(dim1,1);
00856 x2[n] = binToValue(dim2,2);
00857 x3[n] = binToValue(dim3,3);
00858 y[n] = _data->_bins.realValue[(dim3 * _data->_dimSize2
00859 + dim2) * _data->_dimSize1 + dim1];
00860 n++;
00861 }
00862 }
00863 }
00864 else
00865 for (int dim3=0 ; dim3<dimensionSize(3) ; dim3++) {
00866 for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) {
00867 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00868 x1[n] = binToValue(dim1,1);
00869 x2[n] = binToValue(dim2,2);
00870 x3[n] = binToValue(dim3,3);
00871 y[n] = _data->_bins.intValue[(dim3 * _data->_dimSize2
00872 + dim2) * _data->_dimSize1 + dim1];
00873 n++;
00874 }
00875 }
00876 }
00877 }
|
|
|
Fill the externally allocated buffer with data from this histogram.
00881 {
00882 if (!_data)
00883 return;
00884 int n = _data->_totSize;
00885 if (_data->_dataType == REAL_VALUE)
00886 while (--n >= 0)
00887 data[n] = _data->_bins.realValue[n];
00888 else
00889 while (--n >= 0)
00890 data[n] = _data->_bins.intValue[n];
00891 }
|
|
|
Fill the externally allocated buffer with data from this histogram.
00895 {
00896 if (!_data)
00897 return;
00898 int n = _data->_totSize;
00899 if (_data->_dataType == REAL_VALUE)
00900 while (--n >= 0)
00901 data[n] = (int)(_data->_bins.realValue[n] + 0.5);
00902 else
00903 while (--n >= 0)
00904 data[n] = _data->_bins.intValue[n];
00905 }
|
|
||||||||||||||||||||||||||||
|
Assume the histogram is a 3d rgb cube and render it for display in Java in the externally allocated data buffer.
00982 {
00983 if (!_data)
00984 return;
00985 /*
00986 el = (elevation * M_PI) / 180.;
00987 al = (alpha * M_PI) / 180.;
00988 cosa = cos(al);
00989 sina = sin(al);
00990 cose = cos(el);
00991 sine = sin(el);
00992 dataW = dataWidth;
00993 xMin = 190; //for 3D histo
00994 yMax = 190; //255;
00995 */
00996 double el = (elevation * M_PI) / 180.;
00997 double al = (alpha * M_PI) / 180.;
00998 double cosa = cos(al);
00999 double sina = sin(al);
01000 double cose = cos(el);
01001 double sine = sin(el);
01002 int dataW = dataWidth;
01003 int xMin = 190; //for 3D histo
01004 int yMax = 190; //255;
01005 drawAxis(data,cosa,sina,cose,sine,dataW);
01006
01007 int n = 0;
01008
01009 if (_data->_dataType == REAL_VALUE) {
01010 for (int b=0 ; b < _data->_dimSize3 ; b++) {
01011 for (int g=0 ; g < _data->_dimSize2 ; g++) {
01012 for (int r=0 ; r < _data->_dimSize1 ; r++) {
01013 if (_data->_bins.realValue[n] > threshold) {
01014 /*
01015 Doen't work if hist range unequals 0..255
01016 double rV = r * _data->_binWidth1 + _data->_lowBin1;
01017 double gV = g * _data->_binWidth2 + _data->_lowBin2;
01018 double bV = b * _data->_binWidth3 + _data->_lowBin3;
01019 */
01020 double rV = r * 255./(_data->_dimSize1-1);
01021 double gV = g * 255./(_data->_dimSize2-1);
01022 double bV = b * 255./(_data->_dimSize3-1);
01023 setPixelV(data, transf3Dto2D(rV,gV,bV,cosa,sina,cose,sine), HxVec3Int(rV,gV,bV), dataW);
01024 }
01025 n++;
01026 }
01027 }
01028 }
01029 }
01030 else {
01031 for (int b=0 ; b < _data->_dimSize3 ; b++) {
01032 for (int g=0 ; g < _data->_dimSize2 ; g++) {
01033 for (int r=0 ; r < _data->_dimSize1 ; r++) {
01034 if (_data->_bins.intValue[n] > threshold) {
01035 /*
01036 Doen't work if hist range unequals 0..255
01037 double rV = r * _data->_binWidth1 + _data->_lowBin1;
01038 double gV = g * _data->_binWidth2 + _data->_lowBin2;
01039 double bV = b * _data->_binWidth3 + _data->_lowBin3;
01040 */
01041 double rV = r * 255./(_data->_dimSize1-1);
01042 double gV = g * 255./(_data->_dimSize2-1);
01043 double bV = b * 255./(_data->_dimSize3-1);
01044 setPixelV(data, transf3Dto2D(rV,gV,bV,cosa,sina,cose,sine), HxVec3Int(rV,gV,bV), dataW);
01045 }
01046 n++;
01047 }
01048 }
01049 }
01050 }
01051 }
|
|
||||||||||||
|
Print histogram data in the given stream.
01055 {
01056 if (!_data)
01057 return os << "HxHistogram(null)" << STD_ENDL;
01058
01059 int dim1, dim2, dim3;
01060 if (_data->_dataType == REAL_VALUE)
01061 switch (dimensionality()) {
01062 case 1:
01063 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01064 os << binToValue(dim1,1) << delimit <<
01065 float(_data->_bins.realValue[dim1]) << STD_ENDL;
01066 break;
01067 case 2:
01068 for (dim2=0 ; dim2<dimensionSize(2) ; dim2++)
01069 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01070 os << binToValue(dim1,1) << delimit <<
01071 binToValue(dim2,2) << delimit <<
01072 float(_data->_bins.realValue[dim2 * _data->_dimSize1
01073 + dim1]) << STD_ENDL;
01074 break;
01075 case 3:
01076 for (dim3=0; dim3<dimensionSize(3) ; dim3++)
01077 for (dim2=0 ; dim2<dimensionSize(2) ; dim2++)
01078 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01079 os << binToValue(dim1,1) << delimit <<
01080 binToValue(dim2,2) << delimit <<
01081 binToValue(dim3,3) << delimit <<
01082 float(_data->_bins.realValue[(dim3 * _data->_dimSize2
01083 + dim2) * _data->_dimSize1 + dim1]) << STD_ENDL;
01084 break;
01085 }
01086 else
01087 switch (dimensionality()) {
01088 case 1:
01089 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01090 os << binToValue(dim1,1) << delimit <<
01091 _data->_bins.intValue[dim1] << STD_ENDL;
01092 break;
01093 case 2:
01094 for (dim2=0 ; dim2<dimensionSize(2) ; dim2++)
01095 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01096 os << binToValue(dim1,1) << delimit <<
01097 binToValue(dim2,2) << delimit <<
01098 _data->_bins.intValue[dim2 * _data->_dimSize1
01099 + dim1] << STD_ENDL;
01100 break;
01101 case 3:
01102 for (dim3=0; dim3<dimensionSize(3) ; dim3++)
01103 for (dim2=0 ; dim2<dimensionSize(2) ; dim2++)
01104 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01105 os << binToValue(dim1,1) << delimit <<
01106 binToValue(dim2,2) << delimit <<
01107 binToValue(dim3,3) << delimit <<
01108 _data->_bins.intValue[(dim3 * _data->_dimSize2
01109 + dim2) * _data->_dimSize1 + dim1] << STD_ENDL;
01110 break;
01111 }
01112 return os;
01113 }
|
|
|
Write histogram to disk.
01132 {
01133 HxString name;
01134 FILE *fp;
01135 IOHEADER header;
01136
01137 if (!_data)
01138 return 0;
01139
01140 name = filename + ".hst";
01141
01142 fp = fopen(name.c_str(), "wb");
01143 if (!fp)
01144 return 0;
01145
01146 header.dataType = _data->_dataType;
01147 header.dimensions = _data->_nDims;
01148 header.lowBin1 = _data->_lowBin1;
01149 header.highBin1 = _data->_highBin1;
01150 header.nBins1 = _data->_dimSize1;
01151 header.lowBin2 = _data->_lowBin2;
01152 header.highBin2 = _data->_highBin2;
01153 header.nBins2 = _data->_dimSize2;
01154 header.lowBin3 = _data->_lowBin3;
01155 header.highBin3 = _data->_highBin3;
01156 header.nBins3 = _data->_dimSize3;
01157 fwrite(&header, sizeof(header), 1, fp);
01158
01159 if (_data->_dataType == REAL_VALUE)
01160 fwrite(_data->_bins.realValue, _data->_totSize,
01161 sizeof(*(_data->_bins.realValue)), fp);
01162 else
01163 fwrite(_data->_bins.intValue, _data->_totSize,
01164 sizeof(*(_data->_bins.intValue)), fp);
01165
01166 fclose(fp);
01167
01168 return 1;
01169 }
|
|
|
Returns new histogram in which bins with count<=valThreshold are set to 0.0, bins with count>valThreshold keep original value.
01173 {
01174 if (!_data)
01175 return HxHistogram();
01176 HxHistogramData *data = new HxHistogramData(*_data);
01177
01178 int n = data->_totSize;
01179
01180 if (data->_dataType == REAL_VALUE)
01181 while (--n >= 0) {
01182 if (data->_bins.realValue[n]<=valThreshold)
01183 data->_bins.realValue[n]=0.0;
01184 }
01185 else
01186 while (--n >= 0) {
01187 if (data->_bins.intValue[n]<=valThreshold)
01188 data->_bins.intValue[n]=0.0;
01189 }
01190
01191 return HxHistogram(data);
01192 }
|
|
|
Returns number of bins with count>valThreshold. Counts number of non-empty bins by default.
01196 {
01197 if (!_data)
01198 return 0;
01199
01200 int n = _data->_totSize;
01201
01202 int counter=0;
01203
01204 if (_data->_dataType == REAL_VALUE)
01205 while (--n >= 0) {
01206 if (_data->_bins.realValue[n]>valThreshold)
01207 counter++;
01208 }
01209 else
01210 while (--n >= 0) {
01211 if (_data->_bins.intValue[n]>valThreshold)
01212 counter++;
01213 }
01214
01215 return counter;
01216 }
|
|
||||||||||||||||||||||||||||
|
Returns new histogram containing given range of bins only. (Including given min and max.) Default value -1 maps to dimensionSize()-1.
01222 {
01223 if (!_data)
01224 return HxHistogram();
01225
01226 // Default value binMax=-1 maps to dimensionSize()-1.
01227 if (binMax1<0)
01228 binMax1=dimensionSize(1)-1;
01229 if (binMax2<0)
01230 binMax2=dimensionSize(2)-1;
01231 if (binMax3<0)
01232 binMax3=dimensionSize(3)-1;
01233
01234 if (binMin1<0 || binMin2<0 || binMin3<0)
01235 {
01236 STD_CERR << "Error in HxHistogram::reduceRange, minimum smaller than 0." << STD_ENDL;
01237 return HxHistogram();
01238 }
01239
01240 if (binMax1<binMin1 || binMax2<binMin2 || binMax3<binMin3)
01241 {
01242 STD_CERR << "Error in HxHistogram::reduceRange, minimum higher than maximum." << STD_ENDL;
01243 return HxHistogram();
01244 }
01245
01246 // Make new histogram for given range
01247 HxHistogram h=HxHistogram(dataType(),dimensionality(),
01248 binToValue(binMin1,1),binToValue(binMax1,1),binMax1-binMin1+1,
01249 binToValue(binMin2,2),binToValue(binMax2,2),binMax2-binMin2+1,
01250 binToValue(binMin3,3),binToValue(binMax3,3),binMax3-binMin3+1);
01251
01252 if (_data->_dataType == REAL_VALUE) {
01253 for (int z=binMin3; z<=binMax3; z++)
01254 for (int y=binMin2; y<=binMax2; y++)
01255 for (int x=binMin1; x<=binMax1; x++) {
01256 int n = ((z-binMin3) * _data->_dimSize2 + (y-binMin2)) *
01257 _data->_dimSize1 + x-binMin1;
01258 int m = (z * _data->_dimSize2 + y) *
01259 _data->_dimSize1 + x;
01260 h._data->_bins.realValue[n] = _data->_bins.realValue[m];
01261 }
01262 }
01263 else {
01264 for (int z=binMin3; z<=binMax3; z++)
01265 for (int y=binMin2; y<=binMax2; y++)
01266 for (int x=binMin1; x<=binMax1; x++) {
01267 int n = ((z-binMin3) * _data->_dimSize2 + (y-binMin2)) *
01268 _data->_dimSize1 + x-binMin1;
01269 int m = (z * _data->_dimSize2 + y) *
01270 _data->_dimSize1 + x;
01271 h._data->_bins.intValue[n] = _data->_bins.intValue[m];
01272 }
01273 }
01274
01275 return h;
01276 }
|
|
||||||||||||||||||||||||||||
|
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.
01281 {
01282 if (binValMin1==binValMax1) {
01283 binValMin1=_data->_lowBin1;
01284 binValMax1=_data->_highBin1;
01285 }
01286 if (binValMin1<_data->_lowBin1)
01287 binValMin1=_data->_lowBin1;
01288 if (binValMax1>_data->_highBin1)
01289 binValMax1=_data->_highBin1;
01290 if (binValMin2==binValMax2) {
01291 binValMin2=_data->_lowBin2;
01292 binValMax2=_data->_highBin2;
01293 }
01294 if (binValMin2<_data->_lowBin2)
01295 binValMin2=_data->_lowBin2;
01296 if (binValMax2>_data->_highBin2)
01297 binValMax2=_data->_highBin2;
01298 if (binValMin3==binValMax3) {
01299 binValMin3=_data->_lowBin3;
01300 binValMax3=_data->_highBin3;
01301 }
01302 if (binValMin3<_data->_lowBin3)
01303 binValMin3=_data->_lowBin3;
01304 if (binValMax3>_data->_highBin3)
01305 binValMax3=_data->_highBin3;
01306 return reduceRange(valueToBin(binValMin1,1),valueToBin(binValMax1,1),
01307 valueToBin(binValMin2,2),valueToBin(binValMax2,2),
01308 valueToBin(binValMin3,3),valueToBin(binValMax3,3));
01309 }
|
|
|
Projects n-dimensional (1<n<=3) histogram on a 1-D histogram for given dimension.
01314 {
01315 if (dimensionality()<2)
01316 {
01317 // STD_CERR << "Warning. HxHistogram::to1D, dimensionality is " << dimensionality() << STD_ENDL;
01318 return *this;
01319 }
01320
01321 if (dim<1 || dim>3)
01322 {
01323 STD_CERR << "Error. Dimension out of bounds: " << dim << STD_ENDL;
01324 return HxHistogram();
01325 }
01326
01327
01328 HxHistogram result;
01329 result=HxHistogram(dataType(), 1,
01330 lowBin(dim),highBin(dim),dimensionSize(dim),
01331 0,0,0,
01332 0,0,0);
01333
01334 int otherDim1=-1;
01335 int otherDim2=-1;
01336
01337 if (dim==1)
01338 {
01339 otherDim1=3;
01340 otherDim2=2;
01341 }
01342 if (dim==2)
01343 {
01344 otherDim1=3;
01345 otherDim2=1;
01346 }
01347 if (dim==3)
01348 {
01349 otherDim1=2;
01350 otherDim2=1;
01351 }
01352
01353 for (int b=0; b<dimensionSize(dim); b++)
01354 {
01355 double total=0;
01356 for (int sb=0; sb<dimensionSize(otherDim1); sb++)
01357 for (int tb=0; tb<dimensionSize(otherDim2); tb++)
01358 {
01359 if (dim==1)
01360 total+=get(b,tb,sb);
01361 if (dim==2)
01362 total+=get(tb,b,sb);
01363 if (dim==3)
01364 total+=get(tb,sb,b);
01365 }
01366 result.setBin(b, total);
01367 }
01368
01369 return result;
01370 }
|
1.2.12 written by Dimitri van Heesch,
© 1997-2001