#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... | |
| int | valueToBin (double val) const |
| Translate value to bin for 1D case. More... | |
| int | clipBin (int bin) const |
| clip a bin index into the histogram [0:nrbins-1]. 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.
00073 : _data(0)
00074 {
00075 }
|
|
|
Copy constructor.
00077 : _data(rhs._data) 00078 { 00079 } |
|
|
Construct a 1D histogram with a range from 0 to dimSize - 1 and a binWidth of 1.
00082 {
00083 _data = new HxHistogramData(REAL_VALUE, 1,
00084 0, dimSize - 1, dimSize,
00085 0, 0, 0,
00086 0, 0, 0);
00087 }
|
|
||||||||||||
|
Construct a 2D histogram with a range from 0 to dimSize - 1 and a binWidth of 1 in each dimension.
00090 {
00091 _data = new HxHistogramData(REAL_VALUE, 2,
00092 0, dimSize1 - 1, dimSize1,
00093 0, dimSize2 - 1, dimSize2,
00094 0, 0, 0);
00095 }
|
|
||||||||||||||||
|
Construct a 3D histogram with a range from 0 to dimSize - 1 and a binWidth of 1 in each dimension.
00098 {
00099 _data = new HxHistogramData(REAL_VALUE, 3,
00100 0, dimSize1 - 1, dimSize1,
00101 0, dimSize2 - 1, dimSize2,
00102 0, dimSize3 - 1, dimSize3);
00103 }
|
|
||||||||||||||||||||||||
|
Construct Histogram with given data type and number of dimensions. The range in a dimension is 0 to dimSize - 1, the binWidth is 1.
00107 {
00108 _data = new HxHistogramData(dataType, dimensions,
00109 0, dimSize1 - 1, dimSize1,
00110 0, dimSize2 - 1, dimSize2,
00111 0, dimSize3 - 1, dimSize3);
00112 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Construct a Histogram with given parameters. If dataType == INT\_VALUE parameters are casted.
00118 {
00119 _data = new HxHistogramData(dataType, dimensions,
00120 lowBin1, highBin1, nBins1,
00121 lowBin2, highBin2, nBins2,
00122 lowBin3, highBin3, nBins3);
00123 }
|
|
|
Read a Histogram from disk.
00130 {
00131 HxString name;
00132 FILE *fp;
00133 IOHEADER header;
00134
00135 name = filename + ".hst";
00136
00137 fp = fopen(name.c_str(), "rb");
00138 if (!fp)
00139 _data = 0;
00140 else {
00141 fread(&header, sizeof(header), 1, fp);
00142
00143 _data = new HxHistogramData(header.dataType, header.dimensions,
00144 header.lowBin1, header.highBin1, header.nBins1,
00145 header.lowBin2, header.highBin2, header.nBins2,
00146 header.lowBin3, header.highBin3, header.nBins3);
00147
00148 if (_data->_dataType == REAL_VALUE)
00149 fread(_data->_bins.realValue, _data->_totSize,
00150 sizeof(*(_data->_bins.realValue)), fp);
00151 else
00152 fread(_data->_bins.intValue, _data->_totSize,
00153 sizeof(*(_data->_bins.intValue)), fp);
00154 fclose(fp);
00155 }
00156 }
|
|
|
Destructor.
00159 {
00160 }
|
|
|
Assignment operator.
00171 {
00172 _data = rhs._data;
00173 return *this;
00174 }
|
|
|
Indicates wether this is a valid histogram.
00178 {
00179 return _data ? 0 : 1;
00180 }
|
|
|
Indicates wether this is a valid histogram.
00184 {
00185 return _data ? 1 : 0;
00186 }
|
|
|
The unique identifier of the histogram.
00190 {
00191 return _data ? _data->_id : 0 ;
00192 }
|
|
|
The data value type. Either INT\_VALUE or REAL\_VALUE.
00196 {
00197 return _data ? _data->_dataType : INT_VALUE;
00198 }
|
|
|
The number of dimensions of the histogram.
00202 {
00203 return _data ? _data->_nDims : 0;
00204 }
|
|
|
The size of the histogram in the i-th dimension. The first dimension has i = 1.
00208 {
00209 if (!_data)
00210 return 0;
00211 switch (dim) {
00212 case 1: return _data->_dimSize1;
00213 case 2: return _data->_dimSize2;
00214 case 3: return _data->_dimSize3;
00215 }
00216 return 0;
00217 }
|
|
|
The total size of the histogram.
00221 {
00222 if (!_data)
00223 return 0;
00224 return _data->_totSize;
00225 }
|
|
|
The lowest bin in the i-th dimension.
00229 {
00230 if (!_data)
00231 return 0;
00232 switch (dim) {
00233 case 1: return _data->_lowBin1;
00234 case 2: return _data->_lowBin2;
00235 case 3: return _data->_lowBin3;
00236 }
00237 return 0;
00238 }
|
|
|
The highest bin in the i-th dimension.
00242 {
00243 if (!_data)
00244 return 0;
00245 switch (dim) {
00246 case 1: return _data->_highBin1;
00247 case 2: return _data->_highBin2;
00248 case 3: return _data->_highBin3;
00249 }
00250 return 0;
00251 }
|
|
|
The bin width in the i-th dimension.
00255 {
00256 if (!_data)
00257 return 0;
00258 switch (dim) {
00259 case 1: return _data->_binWidth1;
00260 case 2: return _data->_binWidth2;
00261 case 3: return _data->_binWidth3;
00262 }
00263 return 0;
00264 }
|
|
||||||||||||
|
Translate bin to value.
00268 {
00269 if (!_data)
00270 return 0;
00271 switch (dimension) {
00272 case 1: return (bin+0.5) * _data->_binWidth1 + _data->_lowBin1;
00273 case 2: return (bin+0.5) * _data->_binWidth2 + _data->_lowBin2;
00274 case 3: return (bin+0.5) * _data->_binWidth3 + _data->_lowBin3;
00275 }
00276 return 0;
00277 }
|
|
||||||||||||
|
Translate value to bin.
00568 {
00569 if (!_data)
00570 return -1;
00571 switch (dimension) {
00572 case 1: return (int) ((val - _data->_lowRange1) * _data->_binFac1);
00573 case 2: return (int) ((val - _data->_lowRange2) * _data->_binFac2);
00574 case 3: return (int) ((val - _data->_lowRange3) * _data->_binFac3);
00575 }
00576 return -1;
00577 }
|
|
|
Translate value to bin for 1D case.
00581 {
00582 if (!_data)
00583 return -1;
00584 return (int) ((val - _data->_lowRange1) * _data->_binFac1);
00585 }
|
|
|
clip a bin index into the histogram [0:nrbins-1].
|
|
|
Get the number of elements in the given bin.
00474 {
00475 return _data ? _data->getBin(bin1) : 0;
00476 }
|
|
||||||||||||
|
Get the number of elements in the given bin.
00480 {
00481 return _data ? _data->getBin(bin2 * _data->_dimSize1 + bin1) : 0;
00482 }
|
|
||||||||||||||||
|
Get the number of elements in the given bin.
00486 {
00487 return _data ? _data->getBin((bin3 * _data->_dimSize2 + bin2) *
00488 _data->_dimSize1 + bin1) : 0;
00489 }
|
|
|
Insert value in 1D histogram.
00281 {
00282 if (_data && (_data->_nDims == 1))
00283 {
00284 int bin = (int) ((val - _data->_lowRange1) * _data->_binFac1);
00285 if (bin >= _data->_dimSize1)
00286 {
00287 if (val==_data->_highBin1)
00288 bin=_data->_dimSize1-1;
00289 else
00290 return; // out of range, don't do anything
00291 }
00292 incBinChecked(bin);
00293 }
00294 }
|
|
|
Insert value in 1D histogram.
00298 {
00299 if (_data && (_data->_nDims == 1))
00300 {
00301 int bin = (int) ((val - _data->_lowRange1) * _data->_binFac1);
00302 if (bin >= _data->_dimSize1)
00303 {
00304 if (val==_data->_highBin1)
00305 bin=_data->_dimSize1-1;
00306 else
00307 return; // out of range, don't do anything
00308 }
00309 incBinChecked(bin);
00310 }
00311 }
|
|
|
Insert value in 1D histogram.
00315 {
00316 if (_data && (_data->_nDims == 1))
00317 {
00318 int bin = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00319 if (bin >= _data->_dimSize1)
00320 {
00321 if (val.x()==_data->_highBin1)
00322 bin=_data->_dimSize1-1;
00323 else
00324 return; // out of range, don't do anything
00325 }
00326 incBinChecked(bin);
00327 }
00328 }
|
|
|
Insert value in 1D histogram.
00332 {
00333 if (_data && (_data->_nDims == 1))
00334 {
00335 int bin = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00336 if (bin >= _data->_dimSize1)
00337 {
00338 if (val.x()==_data->_highBin1)
00339 bin=_data->_dimSize1-1;
00340 else
00341 return; // out of range, don't do anything
00342 }
00343 incBinChecked(bin);
00344 }
00345 }
|
|
|
Insert value in 2D histogram.
00349 {
00350 if (_data && (_data->_nDims == 2))
00351 {
00352 int bin1 = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00353 if (bin1 >= _data->_dimSize1)
00354 {
00355 if (val.x()==_data->_highBin1)
00356 bin1=_data->_dimSize1-1;
00357 else
00358 return; // out of range, don't do anything
00359 }
00360 int bin2 = (int) ((val.y() - _data->_lowRange2) * _data->_binFac2);
00361 if (bin2 >= _data->_dimSize2)
00362 {
00363 if (val.y()==_data->_highBin2)
00364 bin2=_data->_dimSize2-1;
00365 else
00366 return; // out of range, don't do anything
00367 }
00368 incBinChecked(bin1,bin2);
00369 }
00370 }
|
|
|
Insert value in 2D histogram.
00374 {
00375 if (_data && (_data->_nDims == 2))
00376 {
00377 int bin1 = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00378 if (bin1 >= _data->_dimSize1)
00379 {
00380 if (val.x()==_data->_highBin1)
00381 bin1=_data->_dimSize1-1;
00382 else
00383 return; // out of range, don't do anything
00384 }
00385 int bin2 = (int) ((val.y() - _data->_lowRange2) * _data->_binFac2);
00386 if (bin2 >= _data->_dimSize2)
00387 {
00388 if (val.y()==_data->_highBin2)
00389 bin2=_data->_dimSize2-1;
00390 else
00391 return; // out of range, don't do anything
00392 }
00393 incBinChecked(bin1,bin2);
00394 }
00395 }
|
|
|
Insert value in 3D histogram.
00399 {
00400 if (_data && (_data->_nDims == 3))
00401 {
00402 int bin1 = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00403 if (bin1 >= _data->_dimSize1)
00404 {
00405 if (val.x()==_data->_highBin1)
00406 bin1=_data->_dimSize1-1;
00407 else
00408 return; // out of range, don't do anything
00409 }
00410 int bin2 = (int) ((val.y() - _data->_lowRange2) * _data->_binFac2);
00411 if (bin2 >= _data->_dimSize2)
00412 {
00413 if (val.y()==_data->_highBin2)
00414 bin2=_data->_dimSize2-1;
00415 else
00416 return; // out of range, don't do anything
00417 }
00418 int bin3 = (int) ((val.z() - _data->_lowRange3) * _data->_binFac3);
00419 if (bin3 >= _data->_dimSize3)
00420 {
00421 if (val.z()==_data->_highBin3)
00422 bin3=_data->_dimSize3-1;
00423 else
00424 return; // out of range, don't do anything
00425 }
00426 incBin(bin1,bin2,bin3);
00427 }
00428 }
|
|
|
Insert value in 3D histogram.
00432 {
00433 if (_data && (_data->_nDims == 3))
00434 {
00435 int bin1 = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00436 if (bin1 >= _data->_dimSize1)
00437 {
00438 if (val.x()==_data->_highBin1)
00439 bin1=_data->_dimSize1-1;
00440 else
00441 return; // out of range, don't do anything
00442 }
00443 int bin2 = (int) ((val.y() - _data->_lowRange2) * _data->_binFac2);
00444 if (bin2 >= _data->_dimSize2)
00445 {
00446 if (val.y()==_data->_highBin2)
00447 bin2=_data->_dimSize2-1;
00448 else
00449 return; // out of range, don't do anything
00450 }
00451 int bin3 = (int) ((val.z() - _data->_lowRange3) * _data->_binFac3);
00452 if (bin3 >= _data->_dimSize3)
00453 {
00454 if (val.z()==_data->_highBin3)
00455 bin3=_data->_dimSize3-1;
00456 else
00457 return; // out of range, don't do anything
00458 }
00459 incBin(bin1,bin2,bin3);
00460 }
00461 }
|
|
|
Increment the given bin. Checks whether this is a 1D histogram and preserves reference count. Values outside the histogram range are ignored.
00465 {
00466 if (_data) {
00467 if ((_data->_nDims == 1) &&
00468 (bin >= 0) && (bin < _data->_dimSize1)) {
00469 _data->getUnshared();
00470 _data->incBin(bin);
00471 }
00472 }
00473 }
|
|
||||||||||||
|
Increment the given bin. Checks whether this is a 2D histogram and preserves reference count. Values outside the histogram range are ignored.
00477 {
00478 if (_data) {
00479 if ((_data->_nDims == 2) &&
00480 (bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00481 (bin2 >= 0) && (bin2 < _data->_dimSize2)) {
00482 _data->getUnshared();
00483 _data->incBin(bin2 * _data->_dimSize1 + bin1);
00484 }
00485 }
00486 }
|
|
||||||||||||||||
|
Increment the given bin. Checks whether this is a 3D histogram and preserves reference count. Values outside the histogram range are ignored.
00490 {
00491 if (_data) {
00492 if ((_data->_nDims == 3) &&
00493 (bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00494 (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00495 (bin3 >= 0) && (bin3 < _data->_dimSize3)) {
00496 _data->getUnshared();
00497 _data->incBin((bin3 * _data->_dimSize2 + bin2) *
00498 _data->_dimSize1 + bin1);
00499 }
00500 }
00501 }
|
|
|
Insert value in 1D histogram.
00596 {
00597 incBin(clipBin(valueToBin((double) val)));
00598 }
|
|
|
Insert value in 1D histogram.
00602 {
00603 incBin(clipBin(valueToBin(val)));
00604 }
|
|
||||||||||||
|
Kernel Density Estimator.
00506 {
00507 if (!_data || (_data->_dataType != REAL_VALUE))
00508 return;
00509
00510 double ori = (val - _data->_lowBin1) / _data->_binWidth1;
00511 double s = sigma/_data->_binWidth1;
00512 double t, sat;
00513
00514 int binmin = (int) (ori-3*s+0.5);
00515 int binmax = (int) (ori+3*s+0.5);
00516 int bin;
00517
00518 if (binmin < 0)
00519 binmin = 0;
00520
00521 /* gaussian mass left outside kernel */
00522 t = (ori-binmin+0.5)/(sqrt(2.0)*s);
00523
00524 sat = erfc(t)*0.5;
00525
00526 _data->_bins.realValue[binmin ? binmin-1 : 0] += sat;
00527
00528 if (binmax >= _data->_dimSize1)
00529 binmax = _data->_dimSize1-1;
00530
00531 /* gaussian mass right outside kernel */
00532 t = (binmax-ori+0.5)/(sqrt(2.0)*s);
00533
00534 sat = erfc(t)*0.5;
00535
00536 _data->_bins.realValue[binmax < _data->_dimSize1-1 ? binmax+1 : binmax]
00537 += sat;
00538
00539 double a = 1./(sqrt(2*M_PI)*s);
00540 double b = -0.5/(s*s);
00541
00542 for (bin=binmin; bin<=binmax; bin++) {
00543 double v = bin-ori;
00544 _data->_bins.realValue[bin] += a*exp(b*v*v);
00545 }
00546 }
|
|
|
Insert value in 1D histogram.
|
|
|
Insert value in 1D histogram.
|
|
|
Insert value in 2D histogram.
00622 {
00623 int bin1 = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00624 if (bin1 >= _data->_dimSize1)
00625 {
00626 if (val.x()==_data->_highBin1)
00627 bin1=_data->_dimSize1-1;
00628 else
00629 return; // out of range, don't do anything
00630 }
00631 int bin2 = (int) ((val.y() - _data->_lowRange2) * _data->_binFac2);
00632 if (bin2 >= _data->_dimSize2)
00633 {
00634 if (val.y()==_data->_highBin2)
00635 bin2=_data->_dimSize2-1;
00636 else
00637 return; // out of range, don't do anything
00638 }
00639 incBin(bin1,bin2);
00640 }
|
|
|
Insert value in 2D histogram.
00644 {
00645 int bin1 = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00646 if (bin1 >= _data->_dimSize1)
00647 {
00648 if (val.x()==_data->_highBin1)
00649 bin1=_data->_dimSize1-1;
00650 else
00651 return; // out of range, don't do anything
00652 }
00653 int bin2 = (int) ((val.y() - _data->_lowRange2) * _data->_binFac2);
00654 if (bin2 >= _data->_dimSize2)
00655 {
00656 if (val.y()==_data->_highBin2)
00657 bin2=_data->_dimSize2-1;
00658 else
00659 return; // out of range, don't do anything
00660 }
00661 incBin(bin1,bin2);
00662 }
|
|
|
Insert value in 3D histogram.
00666 {
00667 int bin1 = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00668 if (bin1 >= _data->_dimSize1)
00669 {
00670 if (val.x()==_data->_highBin1)
00671 bin1=_data->_dimSize1-1;
00672 else
00673 return; // out of range, don't do anything
00674 }
00675 int bin2 = (int) ((val.y() - _data->_lowRange2) * _data->_binFac2);
00676 if (bin2 >= _data->_dimSize2)
00677 {
00678 if (val.y()==_data->_highBin2)
00679 bin2=_data->_dimSize2-1;
00680 else
00681 return; // out of range, don't do anything
00682 }
00683 int bin3 = (int) ((val.z() - _data->_lowRange3) * _data->_binFac3);
00684 if (bin3 >= _data->_dimSize3)
00685 {
00686 if (val.z()==_data->_highBin3)
00687 bin3=_data->_dimSize3-1;
00688 else
00689 return; // out of range, don't do anything
00690 }
00691 incBin(bin1,bin2,bin3);
00692 }
|
|
|
Insert value in 3D histogram.
00696 {
00697 int bin1 = (int) ((val.x() - _data->_lowRange1) * _data->_binFac1);
00698 if (bin1 >= _data->_dimSize1)
00699 {
00700 if (val.x()==_data->_highBin1)
00701 bin1=_data->_dimSize1-1;
00702 else
00703 return; // out of range, don't do anything
00704 }
00705 int bin2 = (int) ((val.y() - _data->_lowRange2) * _data->_binFac2);
00706 if (bin2 >= _data->_dimSize2)
00707 {
00708 if (val.y()==_data->_highBin2)
00709 bin2=_data->_dimSize2-1;
00710 else
00711 return; // out of range, don't do anything
00712 }
00713 int bin3 = (int) ((val.z() - _data->_lowRange3) * _data->_binFac3);
00714 if (bin3 >= _data->_dimSize3)
00715 {
00716 if (val.z()==_data->_highBin3)
00717 bin3=_data->_dimSize3-1;
00718 else
00719 return; // out of range, don't do anything
00720 }
00721 incBin(bin1,bin2,bin3);
00722 }
|
|
|
Increment the given bin (assumes 1D histogram). Values outside the histogram range are ignored.
00493 {
00494 if ((bin >= 0) && (bin < _data->_dimSize1))
00495 _data->incBin(bin);
00496 }
|
|
||||||||||||
|
Increment the given bin (assumes 2D histogram). Values outside the histogram range are ignored.
00500 {
00501 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00502 (bin2 >= 0) && (bin2 < _data->_dimSize2))
00503 _data->incBin(bin2 * _data->_dimSize1 + bin1);
00504 }
|
|
||||||||||||||||
|
Increment the given bin (assumes 3D histogram). Values outside the histogram range are ignored.
00508 {
00509 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00510 (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00511 (bin3 >= 0) && (bin3 < _data->_dimSize3))
00512 _data->incBin((bin3 * _data->_dimSize2 + bin2) *
00513 _data->_dimSize1 + bin1);
00514 }
|
|
||||||||||||
|
Reset the value of the given bin to val (assumes 1D histogram). Values outside the histogram range are ignored.
00518 {
00519 if ((bin1 >= 0) && (bin1 < _data->_dimSize1))
00520 _data->setBin(bin1, val);
00521 }
|
|
||||||||||||||||
|
Reset the value of the given bin to val (assumes 2D histogram). Values outside the histogram range are ignored.
00525 {
00526 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00527 (bin2 >= 0) && (bin2 < _data->_dimSize2))
00528 _data->setBin(bin2 * _data->_dimSize1 + bin1, val);
00529 }
|
|
||||||||||||||||||||
|
Reset the value of the given bin to val (assumes 3D histogram). Values outside the histogram range are ignored.
00533 {
00534 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00535 (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00536 (bin3 >= 0) && (bin3 < _data->_dimSize3))
00537 _data->setBin((bin3 * _data->_dimSize2 + bin2) *
00538 _data->_dimSize1 + bin1, val);
00539 }
|
|
||||||||||||
|
Reset the value of the given bin to val (assumes 1D histogram). Values outside the histogram range are ignored.
00543 {
00544 if ((bin1 >= 0) && (bin1 < _data->_dimSize1))
00545 _data->setBin(bin1, val);
00546 }
|
|
||||||||||||||||
|
Reset the value of the given bin to val (assumes 2D histogram). Values outside the histogram range are ignored.
00550 {
00551 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00552 (bin2 >= 0) && (bin2 < _data->_dimSize2))
00553 _data->setBin(bin2 * _data->_dimSize1 + bin1, val);
00554 }
|
|
||||||||||||||||||||
|
Reset the value of the given bin to val (assumes 3D histogram). Values outside the histogram range are ignored.
00558 {
00559 if ((bin1 >= 0) && (bin1 < _data->_dimSize1) &&
00560 (bin2 >= 0) && (bin2 < _data->_dimSize2) &&
00561 (bin3 >= 0) && (bin3 < _data->_dimSize3))
00562 _data->setBin((bin3 * _data->_dimSize2 + bin2) *
00563 _data->_dimSize1 + bin1, val);
00564 }
|
|
|
Smooth histogram data.
00550 {
00551 if (!_data)
00552 return HxHistogram();
00553
00554 GaussIIR g(sigma);
00555 HxHistogramData *data = new HxHistogramData(REAL_VALUE, *_data);
00556
00557 /* for now only works for 1D histogram */
00558 /* will be fixed when image processing works on sampled density fields */
00559 /* instead of HxImageRep only... */
00560
00561 #ifndef _DEBUG
00562 g.lineFilter(data->_bins.realValue, data->_totSize);
00563 #endif
00564
00565 return HxHistogram(data);
00566 }
|
|
|
Get histogram modes.
00608 {
00609 HxHistogramData *data = (_data->_dataType != REAL_VALUE) ?
00610 new HxHistogramData(REAL_VALUE, *_data) : _data.pointee();
00611
00612
00613
00614 /* for now only works for 1D histogram */
00615 /* will be fixed when image processing works on sampled density fields */
00616 /* instead of HxImageRep only... */
00617 /* then, see PAMI 22(11), pp. 1318--1323, 2000 */
00618
00619 data->getUnshared();
00620 std::list<MicrosoftListSortDoesntWork> l;
00621
00622 /* maxima detection */
00623 double *ptr = data->_bins.realValue;
00624 double max = *ptr++;
00625 int dir = 1;
00626 for (int i=1; i < data->_totSize; i++) {
00627 double val = *ptr++;
00628 double grad = dir ? val-max : max-val;
00629 if (grad <= 0) {
00630 if (dir == 1) // maximum
00631 l.push_back(MicrosoftListSortDoesntWork(binToValue(i-1,1), max));
00632 // else minimum
00633 dir = dir ? 0 : 1;
00634 }
00635 max = val;
00636 }
00637
00638 if (data != _data.pointee())
00639 delete data;
00640
00641 l.sort();
00642 std::list<HxVec2Double> res;
00643 for (std::list<MicrosoftListSortDoesntWork>::iterator it = l.begin();
00644 it != l.end(); it++)
00645 res.push_back(HxVec2Double(*it));
00646
00647 return res;
00648 }
|
|
|
Normalize histogram data.
00652 {
00653 if (!_data)
00654 return HxHistogram();
00655 HxHistogramData *data = new HxHistogramData(REAL_VALUE, *_data);
00656
00657 int n = data->_totSize;
00658 double norm = sum() / weight;
00659 if (fabs(norm) > 0.0)
00660 {
00661 while (--n >= 0)
00662 data->_bins.realValue[n] /= norm;
00663 data->_sum = weight;
00664 }
00665
00666 return HxHistogram(data);
00667 }
|
|
|
The sum of the histogram.
00671 {
00672 if (!_data)
00673 return 0;
00674 int n = _data->_totSize;
00675 double s = 0;
00676 if (_data->_dataType == REAL_VALUE)
00677 while (--n >= 0)
00678 s += _data->_bins.realValue[n];
00679 else
00680 while (--n >= 0)
00681 s += _data->_bins.intValue[n];
00682 _data->_sum = s;
00683 return s;
00684 }
|
|
|
The minimum number of elements in the histogram.
00688 {
00689 if (!_data)
00690 return 0;
00691 int n = _data->_totSize;
00692 double m;
00693 if (_data->_dataType == REAL_VALUE) {
00694 m = _data->_bins.realValue[0];
00695 while (--n >= 0)
00696 if (_data->_bins.realValue[n] < m)
00697 m = _data->_bins.realValue[n];
00698 }
00699 else {
00700 m = _data->_bins.intValue[0];
00701 while (--n >= 0)
00702 if (_data->_bins.intValue[n] < m)
00703 m = _data->_bins.intValue[n];
00704 }
00705 return m;
00706 }
|
|
|
The minimum number of elements in the histogram. Index is the number of the bin at which the minimum number is first found.
00732 {
00733 if (!_data)
00734 return 0;
00735 int n = _data->_totSize;
00736 double m;
00737 *index = 0;
00738 if (_data->_dataType == REAL_VALUE) {
00739 m = _data->_bins.realValue[0];
00740 while (--n >= 0)
00741 if (_data->_bins.realValue[n] < m) {
00742 m = _data->_bins.realValue[n];
00743 *index = n;
00744 }
00745 }
00746 else {
00747 m = _data->_bins.intValue[0];
00748 while (--n >= 0)
00749 if (_data->_bins.intValue[n] < m) {
00750 m = _data->_bins.intValue[n];
00751 *index = n;
00752 }
00753 }
00754 return m;
00755 }
|
|
|
The maximum number of elements in the histogram.
00710 {
00711 if (!_data)
00712 return 0;
00713 int n = _data->_totSize;
00714 double m;
00715 if (_data->_dataType == REAL_VALUE) {
00716 m = _data->_bins.realValue[0];
00717 while (--n >= 0)
00718 if (_data->_bins.realValue[n] > m)
00719 m = _data->_bins.realValue[n];
00720 }
00721 else {
00722 m = _data->_bins.intValue[0];
00723 while (--n >= 0)
00724 if (_data->_bins.intValue[n] > m)
00725 m = _data->_bins.intValue[n];
00726 }
00727 return m;
00728 }
|
|
|
The maximum number of elements in the histogram. Index is the number of the bin at which the maximum number is first found.
00759 {
00760 if (!_data)
00761 return 0;
00762 int n = _data->_totSize;
00763 double m;
00764 *index = 0;
00765 if (_data->_dataType == REAL_VALUE) {
00766 m = _data->_bins.realValue[0];
00767 while (--n >= 0)
00768 if (_data->_bins.realValue[n] > m) {
00769 m = _data->_bins.realValue[n];
00770 *index = n;
00771 }
00772 }
00773 else {
00774 m = _data->_bins.intValue[0];
00775 while (--n >= 0)
00776 if (_data->_bins.intValue[n] > m) {
00777 m = _data->_bins.intValue[n];
00778 *index = n;
00779 }
00780 }
00781 return m;
00782 }
|
|
|
Intersection of histograms.
00806 {
00807 if (!_data)
00808 return 0;
00809 if (!isEqualSize(rhs))
00810 return -1;
00811 int n = _data->_totSize;
00812 double s = 0;
00813 if (_data->_dataType == REAL_VALUE)
00814 if (rhs._data->_dataType == REAL_VALUE)
00815 s = ::intersect(_data->_bins.realValue, rhs._data->_bins.realValue, n);
00816 else
00817 s = ::intersect(_data->_bins.realValue, rhs._data->_bins.intValue, n);
00818 else
00819 if (rhs._data->_dataType == REAL_VALUE)
00820 s = ::intersect(_data->_bins.intValue, rhs._data->_bins.realValue, n);
00821 else
00822 s = ::intersect(_data->_bins.intValue, rhs._data->_bins.intValue, n);
00823
00824 return s;
00825 }
|
|
|
Chi square intersection of histograms.
00843 {
00844 if (!_data)
00845 return 0;
00846 if (!isEqualSize(rhs))
00847 return -1;
00848 int n = _data->_totSize;
00849 double s = 0;
00850 if (_data->_dataType == REAL_VALUE)
00851 if (rhs._data->_dataType == REAL_VALUE)
00852 s = ::chiSq(_data->_bins.realValue, rhs._data->_bins.realValue, n);
00853 else
00854 s = ::chiSq(_data->_bins.realValue, rhs._data->_bins.intValue, n);
00855 else
00856 if (rhs._data->_dataType == REAL_VALUE)
00857 s = ::chiSq(_data->_bins.intValue, rhs._data->_bins.realValue, n);
00858 else
00859 s = ::chiSq(_data->_bins.intValue, rhs._data->_bins.intValue, n);
00860 return s;
00861 }
|
|
|
Normalized chi square intersection of histograms.
00880 {
00881 if (!_data)
00882 return 0;
00883 if (!isEqualSize(rhs))
00884 return -1;
00885 int n = _data->_totSize;
00886 double s = 0;
00887 if (_data->_dataType == REAL_VALUE)
00888 if (rhs._data->_dataType == REAL_VALUE)
00889 s = ::chiSqNorm(_data->_bins.realValue, rhs._data->_bins.realValue, n);
00890 else
00891 s = ::chiSqNorm(_data->_bins.realValue, rhs._data->_bins.intValue, n);
00892 else
00893 if (rhs._data->_dataType == REAL_VALUE)
00894 s = ::chiSqNorm(_data->_bins.intValue, rhs._data->_bins.realValue, n);
00895 else
00896 s = ::chiSqNorm(_data->_bins.intValue, rhs._data->_bins.intValue, n);
00897 return s;
00898 }
|
|
|
convert dataType.
00164 {
00165 HxHistogramData *data = new HxHistogramData(*_data);
00166 return HxHistogram(data);
00167 }
|
|
||||||||||||
|
Fill the externally allocated buffer with data from this histogram. The pointer to x represents the bin value, y the bin count.
00902 {
00903 if (!_data)
00904 return;
00905
00906 int n = 0;
00907 if (_data->_dataType == REAL_VALUE)
00908 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00909 x[n] = binToValue(dim1,1);
00910 y[n] = _data->_bins.realValue[dim1];
00911 n++;
00912 }
00913 else
00914 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00915 x[n] = binToValue(dim1,1);
00916 y[n] = _data->_bins.intValue[dim1];
00917 n++;
00918 }
00919 }
|
|
||||||||||||||||
|
Fill the externally allocated buffer with data from this histogram. The pointer to x1,x2 represents the bin value, y the bin count.
00923 {
00924 if (!_data)
00925 return;
00926
00927 int n = 0;
00928 if (_data->_dataType == REAL_VALUE)
00929 for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) {
00930 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00931 x1[n] = binToValue(dim1,1);
00932 x2[n] = binToValue(dim2,2);
00933 y[n] = _data->_bins.realValue[dim2 * _data->_dimSize1
00934 + dim1];
00935 n++;
00936 }
00937 }
00938 else
00939 for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) {
00940 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00941 x1[n] = binToValue(dim1,1);
00942 x2[n] = binToValue(dim2,2);
00943 y[n] = _data->_bins.intValue[dim2 * _data->_dimSize1
00944 + dim1];
00945 n++;
00946 }
00947 }
00948 }
|
|
||||||||||||||||||||
|
Fill the externally allocated buffer with data from this histogram. The pointer to x1,x2,x3 represents the bin value, y the bin count.
00952 {
00953 if (!_data)
00954 return;
00955
00956 int n = 0;
00957 if (_data->_dataType == REAL_VALUE)
00958 for (int dim3=0 ; dim3<dimensionSize(3) ; dim3++) {
00959 for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) {
00960 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00961 x1[n] = binToValue(dim1,1);
00962 x2[n] = binToValue(dim2,2);
00963 x3[n] = binToValue(dim3,3);
00964 y[n] = _data->_bins.realValue[(dim3 * _data->_dimSize2
00965 + dim2) * _data->_dimSize1 + dim1];
00966 n++;
00967 }
00968 }
00969 }
00970 else
00971 for (int dim3=0 ; dim3<dimensionSize(3) ; dim3++) {
00972 for (int dim2=0 ; dim2<dimensionSize(2) ; dim2++) {
00973 for (int dim1=0 ; dim1<dimensionSize(1) ; dim1++) {
00974 x1[n] = binToValue(dim1,1);
00975 x2[n] = binToValue(dim2,2);
00976 x3[n] = binToValue(dim3,3);
00977 y[n] = _data->_bins.intValue[(dim3 * _data->_dimSize2
00978 + dim2) * _data->_dimSize1 + dim1];
00979 n++;
00980 }
00981 }
00982 }
00983 }
|
|
|
Fill the externally allocated buffer with data from this histogram.
00987 {
00988 if (!_data)
00989 return;
00990 int n = _data->_totSize;
00991 if (_data->_dataType == REAL_VALUE)
00992 while (--n >= 0)
00993 data[n] = _data->_bins.realValue[n];
00994 else
00995 while (--n >= 0)
00996 data[n] = _data->_bins.intValue[n];
00997 }
|
|
|
Fill the externally allocated buffer with data from this histogram.
01001 {
01002 if (!_data)
01003 return;
01004 int n = _data->_totSize;
01005 if (_data->_dataType == REAL_VALUE)
01006 while (--n >= 0)
01007 data[n] = (int)(_data->_bins.realValue[n] + 0.5);
01008 else
01009 while (--n >= 0)
01010 data[n] = _data->_bins.intValue[n];
01011 }
|
|
||||||||||||||||||||||||||||
|
Assume the histogram is a 3d rgb cube and render it for display in Java in the externally allocated data buffer.
01088 {
01089 if (!_data)
01090 return;
01091 /*
01092 el = (elevation * M_PI) / 180.;
01093 al = (alpha * M_PI) / 180.;
01094 cosa = cos(al);
01095 sina = sin(al);
01096 cose = cos(el);
01097 sine = sin(el);
01098 dataW = dataWidth;
01099 xMin = 190; //for 3D histo
01100 yMax = 190; //255;
01101 */
01102 double el = (elevation * M_PI) / 180.;
01103 double al = (alpha * M_PI) / 180.;
01104 double cosa = cos(al);
01105 double sina = sin(al);
01106 double cose = cos(el);
01107 double sine = sin(el);
01108 int dataW = dataWidth;
01109 int xMin = 190; //for 3D histo
01110 int yMax = 190; //255;
01111 drawAxis(data,cosa,sina,cose,sine,dataW);
01112
01113 int n = 0;
01114
01115 if (_data->_dataType == REAL_VALUE) {
01116 for (int b=0 ; b < _data->_dimSize3 ; b++) {
01117 for (int g=0 ; g < _data->_dimSize2 ; g++) {
01118 for (int r=0 ; r < _data->_dimSize1 ; r++) {
01119 if (_data->_bins.realValue[n] > threshold) {
01120 /*
01121 Doen't work if hist range unequals 0..255
01122 double rV = r * _data->_binWidth1 + _data->_lowBin1;
01123 double gV = g * _data->_binWidth2 + _data->_lowBin2;
01124 double bV = b * _data->_binWidth3 + _data->_lowBin3;
01125 */
01126 double rV = r * 255./(_data->_dimSize1-1);
01127 double gV = g * 255./(_data->_dimSize2-1);
01128 double bV = b * 255./(_data->_dimSize3-1);
01129 setPixelV(data, transf3Dto2D(rV,gV,bV,cosa,sina,cose,sine), HxVec3Int(rV,gV,bV), dataW);
01130 }
01131 n++;
01132 }
01133 }
01134 }
01135 }
01136 else {
01137 for (int b=0 ; b < _data->_dimSize3 ; b++) {
01138 for (int g=0 ; g < _data->_dimSize2 ; g++) {
01139 for (int r=0 ; r < _data->_dimSize1 ; r++) {
01140 if (_data->_bins.intValue[n] > threshold) {
01141 /*
01142 Doen't work if hist range unequals 0..255
01143 double rV = r * _data->_binWidth1 + _data->_lowBin1;
01144 double gV = g * _data->_binWidth2 + _data->_lowBin2;
01145 double bV = b * _data->_binWidth3 + _data->_lowBin3;
01146 */
01147 double rV = r * 255./(_data->_dimSize1-1);
01148 double gV = g * 255./(_data->_dimSize2-1);
01149 double bV = b * 255./(_data->_dimSize3-1);
01150 setPixelV(data, transf3Dto2D(rV,gV,bV,cosa,sina,cose,sine), HxVec3Int(rV,gV,bV), dataW);
01151 }
01152 n++;
01153 }
01154 }
01155 }
01156 }
01157 }
|
|
||||||||||||
|
Print histogram data in the given stream.
01161 {
01162 if (!_data)
01163 return os << "HxHistogram(null)" << STD_ENDL;
01164
01165 int dim1, dim2, dim3;
01166 if (_data->_dataType == REAL_VALUE)
01167 switch (dimensionality()) {
01168 case 1:
01169 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01170 os << binToValue(dim1,1) << delimit <<
01171 float(_data->_bins.realValue[dim1]) << STD_ENDL;
01172 break;
01173 case 2:
01174 for (dim2=0 ; dim2<dimensionSize(2) ; dim2++)
01175 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01176 os << binToValue(dim1,1) << delimit <<
01177 binToValue(dim2,2) << delimit <<
01178 float(_data->_bins.realValue[dim2 * _data->_dimSize1
01179 + dim1]) << STD_ENDL;
01180 break;
01181 case 3:
01182 for (dim3=0; dim3<dimensionSize(3) ; dim3++)
01183 for (dim2=0 ; dim2<dimensionSize(2) ; dim2++)
01184 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01185 os << binToValue(dim1,1) << delimit <<
01186 binToValue(dim2,2) << delimit <<
01187 binToValue(dim3,3) << delimit <<
01188 float(_data->_bins.realValue[(dim3 * _data->_dimSize2
01189 + dim2) * _data->_dimSize1 + dim1]) << STD_ENDL;
01190 break;
01191 }
01192 else
01193 switch (dimensionality()) {
01194 case 1:
01195 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01196 os << binToValue(dim1,1) << delimit <<
01197 _data->_bins.intValue[dim1] << STD_ENDL;
01198 break;
01199 case 2:
01200 for (dim2=0 ; dim2<dimensionSize(2) ; dim2++)
01201 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01202 os << binToValue(dim1,1) << delimit <<
01203 binToValue(dim2,2) << delimit <<
01204 _data->_bins.intValue[dim2 * _data->_dimSize1
01205 + dim1] << STD_ENDL;
01206 break;
01207 case 3:
01208 for (dim3=0; dim3<dimensionSize(3) ; dim3++)
01209 for (dim2=0 ; dim2<dimensionSize(2) ; dim2++)
01210 for (dim1=0 ; dim1<dimensionSize(1) ; dim1++)
01211 os << binToValue(dim1,1) << delimit <<
01212 binToValue(dim2,2) << delimit <<
01213 binToValue(dim3,3) << delimit <<
01214 _data->_bins.intValue[(dim3 * _data->_dimSize2
01215 + dim2) * _data->_dimSize1 + dim1] << STD_ENDL;
01216 break;
01217 }
01218 return os;
01219 }
|
|
|
Write histogram to disk.
01238 {
01239 HxString name;
01240 FILE *fp;
01241 IOHEADER header;
01242
01243 if (!_data)
01244 return 0;
01245
01246 name = filename + ".hst";
01247
01248 fp = fopen(name.c_str(), "wb");
01249 if (!fp)
01250 return 0;
01251
01252 header.dataType = _data->_dataType;
01253 header.dimensions = _data->_nDims;
01254 header.lowBin1 = _data->_lowBin1;
01255 header.highBin1 = _data->_highBin1;
01256 header.nBins1 = _data->_dimSize1;
01257 header.lowBin2 = _data->_lowBin2;
01258 header.highBin2 = _data->_highBin2;
01259 header.nBins2 = _data->_dimSize2;
01260 header.lowBin3 = _data->_lowBin3;
01261 header.highBin3 = _data->_highBin3;
01262 header.nBins3 = _data->_dimSize3;
01263 fwrite(&header, sizeof(header), 1, fp);
01264
01265 if (_data->_dataType == REAL_VALUE)
01266 fwrite(_data->_bins.realValue, _data->_totSize,
01267 sizeof(*(_data->_bins.realValue)), fp);
01268 else
01269 fwrite(_data->_bins.intValue, _data->_totSize,
01270 sizeof(*(_data->_bins.intValue)), fp);
01271
01272 fclose(fp);
01273
01274 return 1;
01275 }
|
|
|
Returns new histogram in which bins with count<=valThreshold are set to 0.0, bins with count>valThreshold keep original value.
01279 {
01280 if (!_data)
01281 return HxHistogram();
01282 HxHistogramData *data = new HxHistogramData(*_data);
01283
01284 int n = data->_totSize;
01285
01286 if (data->_dataType == REAL_VALUE)
01287 while (--n >= 0) {
01288 if (data->_bins.realValue[n]<=valThreshold)
01289 data->_bins.realValue[n]=0.0;
01290 }
01291 else
01292 while (--n >= 0) {
01293 if (data->_bins.intValue[n]<=valThreshold)
01294 data->_bins.intValue[n]=0.0;
01295 }
01296
01297 return HxHistogram(data);
01298 }
|
|
|
Returns number of bins with count>valThreshold. Counts number of non-empty bins by default.
01302 {
01303 if (!_data)
01304 return 0;
01305
01306 int n = _data->_totSize;
01307
01308 int counter=0;
01309
01310 if (_data->_dataType == REAL_VALUE)
01311 while (--n >= 0) {
01312 if (_data->_bins.realValue[n]>valThreshold)
01313 counter++;
01314 }
01315 else
01316 while (--n >= 0) {
01317 if (_data->_bins.intValue[n]>valThreshold)
01318 counter++;
01319 }
01320
01321 return counter;
01322 }
|
|
||||||||||||||||||||||||||||
|
Returns new histogram containing given range of bins only. (Including given min and max.) Default value -1 maps to dimensionSize()-1.
01328 {
01329 if (!_data)
01330 return HxHistogram();
01331
01332 // Default value binMax=-1 maps to dimensionSize()-1.
01333 if (binMax1<0)
01334 binMax1=dimensionSize(1)-1;
01335 if (binMax2<0)
01336 binMax2=dimensionSize(2)-1;
01337 if (binMax3<0)
01338 binMax3=dimensionSize(3)-1;
01339
01340 if (binMin1<0 || binMin2<0 || binMin3<0)
01341 {
01342 STD_CERR << "Error in HxHistogram::reduceRange, minimum smaller than 0." << STD_ENDL;
01343 return HxHistogram();
01344 }
01345
01346 if (binMax1<binMin1 || binMax2<binMin2 || binMax3<binMin3)
01347 {
01348 STD_CERR << "Error in HxHistogram::reduceRange, minimum higher than maximum." << STD_ENDL;
01349 return HxHistogram();
01350 }
01351
01352 // Make new histogram for given range
01353 HxHistogram h=HxHistogram(dataType(),dimensionality(),
01354 binToValue(binMin1,1),binToValue(binMax1,1),binMax1-binMin1+1,
01355 binToValue(binMin2,2),binToValue(binMax2,2),binMax2-binMin2+1,
01356 binToValue(binMin3,3),binToValue(binMax3,3),binMax3-binMin3+1);
01357
01358 if (_data->_dataType == REAL_VALUE) {
01359 for (int z=binMin3; z<=binMax3; z++)
01360 for (int y=binMin2; y<=binMax2; y++)
01361 for (int x=binMin1; x<=binMax1; x++) {
01362 int n = ((z-binMin3) * _data->_dimSize2 + (y-binMin2)) *
01363 _data->_dimSize1 + x-binMin1;
01364 int m = (z * _data->_dimSize2 + y) *
01365 _data->_dimSize1 + x;
01366 h._data->_bins.realValue[n] = _data->_bins.realValue[m];
01367 }
01368 }
01369 else {
01370 for (int z=binMin3; z<=binMax3; z++)
01371 for (int y=binMin2; y<=binMax2; y++)
01372 for (int x=binMin1; x<=binMax1; x++) {
01373 int n = ((z-binMin3) * _data->_dimSize2 + (y-binMin2)) *
01374 _data->_dimSize1 + x-binMin1;
01375 int m = (z * _data->_dimSize2 + y) *
01376 _data->_dimSize1 + x;
01377 h._data->_bins.intValue[n] = _data->_bins.intValue[m];
01378 }
01379 }
01380
01381 return h;
01382 }
|
|
||||||||||||||||||||||||||||
|
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.
01387 {
01388 if (binValMin1==binValMax1) {
01389 binValMin1=_data->_lowBin1;
01390 binValMax1=_data->_highBin1;
01391 }
01392 if (binValMin1<_data->_lowBin1)
01393 binValMin1=_data->_lowBin1;
01394 if (binValMax1>_data->_highBin1)
01395 binValMax1=_data->_highBin1;
01396 if (binValMin2==binValMax2) {
01397 binValMin2=_data->_lowBin2;
01398 binValMax2=_data->_highBin2;
01399 }
01400 if (binValMin2<_data->_lowBin2)
01401 binValMin2=_data->_lowBin2;
01402 if (binValMax2>_data->_highBin2)
01403 binValMax2=_data->_highBin2;
01404 if (binValMin3==binValMax3) {
01405 binValMin3=_data->_lowBin3;
01406 binValMax3=_data->_highBin3;
01407 }
01408 if (binValMin3<_data->_lowBin3)
01409 binValMin3=_data->_lowBin3;
01410 if (binValMax3>_data->_highBin3)
01411 binValMax3=_data->_highBin3;
01412 return reduceRange(valueToBin(binValMin1,1),valueToBin(binValMax1,1),
01413 valueToBin(binValMin2,2),valueToBin(binValMax2,2),
01414 valueToBin(binValMin3,3),valueToBin(binValMax3,3));
01415 }
|
|
|
Projects n-dimensional (1<n<=3) histogram on a 1-D histogram for given dimension.
01420 {
01421 if (dimensionality()<2)
01422 {
01423 // STD_CERR << "Warning. HxHistogram::to1D, dimensionality is " << dimensionality() << STD_ENDL;
01424 return *this;
01425 }
01426
01427 if (dim<1 || dim>3)
01428 {
01429 STD_CERR << "Error. Dimension out of bounds: " << dim << STD_ENDL;
01430 return HxHistogram();
01431 }
01432
01433
01434 HxHistogram result;
01435 result=HxHistogram(dataType(), 1,
01436 lowBin(dim),highBin(dim),dimensionSize(dim),
01437 0,0,0,
01438 0,0,0);
01439
01440 int otherDim1=-1;
01441 int otherDim2=-1;
01442
01443 if (dim==1)
01444 {
01445 otherDim1=3;
01446 otherDim2=2;
01447 }
01448 if (dim==2)
01449 {
01450 otherDim1=3;
01451 otherDim2=1;
01452 }
01453 if (dim==3)
01454 {
01455 otherDim1=2;
01456 otherDim2=1;
01457 }
01458
01459 for (int b=0; b<dimensionSize(dim); b++)
01460 {
01461 double total=0;
01462 for (int sb=0; sb<dimensionSize(otherDim1); sb++)
01463 for (int tb=0; tb<dimensionSize(otherDim2); tb++)
01464 {
01465 if (dim==1)
01466 total+=get(b,tb,sb);
01467 if (dim==2)
01468 total+=get(tb,b,sb);
01469 if (dim==3)
01470 total+=get(tb,sb,b);
01471 }
01472 result.setBin(b, total);
01473 }
01474
01475 return result;
01476 }
|
1.2.12 written by Dimitri van Heesch,
© 1997-2001