|
OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
|
A histogram for a data set. More...
#include <histogramdata.h>
Public Types | |
| typedef std::int32_t | size_type |
| typedef std::int64_t | count_type |
Public Member Functions | |
| HistogramData (size_type _nbins, double _min, double _max) | |
| HistogramData (const count_type *bins, int nbins, double min, double max) | |
| HistogramData (const HistogramData &other) | |
| HistogramData & | operator= (const HistogramData &other) |
| HistogramData & | operator+= (const HistogramData &other) |
| HistogramData & | operator-= (const HistogramData &other) |
| HistogramData & | operator*= (count_type factor) |
| bool | operator== (const HistogramData &other) const |
| bool | operator!= (const HistogramData &other) const |
| count_type | get (double value) const |
| count_type | getcount () const |
| void | scale (double oldmin, double oldmax, double newmin, double newmax) |
| void | clear () |
| void | calculateConversionFactors (double *A, double *B) const |
Static Public Member Functions | |
| static void | getLinearTransform (double *offset, double *scale, double oldmin, double oldmax, double newmin, double newmax) |
A histogram for a data set.
The histogram is described by the fixed total number of bins, the center value of the samples in the first bin, and the center value of the samples in the last bin.
The width of each bin is given by (max - min) / (nbins - 1). Bin 0 holds samples with values min_ +/-binwidth/2.
This means that the total range of samples that can be represented in the histogram is actually min-binwidth/2 to max+binwidth/2, which is slightly larger than just min..max unless each of the bins can only hold a single value (e.g. data converted from 8-bit storage, in 256 bins).
This definition has some subtle effects, best illustrated by a few examples.
If the source data is ui8_t, the logical range is 0..255. Assume nbins=256. This gives binwidth=1, and the true range of the histogram -0.5..+255.5. But since the input is integral, the actual range is just 0..255 inclusive. Try to fill the histogram with evenly distrubuted random data and you end up with each bin having roughly the same number of elements.
Now consider ui16_t, range 0..65535 and nbins is still 256. This gives binwidth=257, not 256. The true range of the histogram is -128.5..+65663.5. Try to fill the histogram with evenly distrubuted random data and you end up with the first and the last bin having approximately half as many elements as all the others. This is not really a problem, but may seem a bit surprising.
| InternalZGY::HistogramData::HistogramData | ( | size_type | nbins, |
| double | min, | ||
| double | max | ||
| ) |
Create a new HistogramData.
| InternalZGY::HistogramData::HistogramData | ( | const count_type * | bins, |
| int | nbins, | ||
| double | min, | ||
| double | max | ||
| ) |
Copy constructor from a histogram passed as discrete information. Useful for converting from some other histogram type. Always create a fixed-range histogram with the same range and number of bins as the source. If this is not what you need, convert it using operator+=().
| InternalZGY::HistogramData::HistogramData | ( | const HistogramData & | other | ) |
Standard copy constructor. Needs to be explicit because of the allocated data for bins.
| void InternalZGY::HistogramData::calculateConversionFactors | ( | double * | A, |
| double * | B | ||
| ) | const |
Get the linear transform for mapping from application values to bin numbers. The resulting bin number is meant to be rounded to nearest integral value. If the histogram range is not initialized yet (can happen if histogram is empty) then a transform is returned that will map all values to a non-existant bin.
| void InternalZGY::HistogramData::clear | ( | ) |
Erase all values from the histogram. The range remains unchanged.
| HistogramData::count_type InternalZGY::HistogramData::get | ( | double | value | ) | const |
Get sample count for this value
Given a sample value, return how many times this sample was found. This is almost the inverse of AddOne, but the function does no scaling of the value.
| HistogramData::count_type InternalZGY::HistogramData::getcount | ( | ) | const |
Get sample count for all values
Return the total number of samples added to any bin. Currently this is returned by summing all the bins, if this is a performance problem that it is possible to maintain a separate count member. Called from compare().
|
static |
Get the linear transform (offset, scale) that will map values from the range oldmin..oldmax to the range newmin..newmax. If either range is empty, the identity transform will be returned.
| bool InternalZGY::HistogramData::operator!= | ( | const HistogramData & | other | ) | const |
See operator== for a description.
| HistogramData & InternalZGY::HistogramData::operator*= | ( | count_type | factor | ) |
Multiply HistogramBuilder with a constant N, equivalent to creating a new instance and adding the old one to it N times. N can be negative.
| HistogramData & InternalZGY::HistogramData::operator+= | ( | const HistogramData & | other | ) |
Add the samples found in another histogram, just as if the samples had been added one at a time using Add().
| HistogramData & InternalZGY::HistogramData::operator-= | ( | const HistogramData & | other | ) |
Subtract the samples found in another histogram, more or less undoing the effect of add. The min/max range in the statistics might be left showing a too wide range.
| HistogramData & InternalZGY::HistogramData::operator= | ( | const HistogramData & | other | ) |
Standard assignment operator. Needs to be explicit because of the allocated data for bins.
| bool InternalZGY::HistogramData::operator== | ( | const HistogramData & | other | ) | const |
Two histograms are considered equal if they return the same bin count for any input value. In practice there is some slop, as only the center of each bin of either histogram is checked. The statistics information need not match. Nor is there any check that the histograms have the same range or even the same number of bins.
| void InternalZGY::HistogramData::scale | ( | double | oldmin, |
| double | oldmax, | ||
| double | newmin, | ||
| double | newmax | ||
| ) |
Calculate the linear transform needed to convert from one range (typically the natural data range of the integral storage type) to the data range that the application wants to see. Then update the histogram and associated statistics so they look like the transform had been done on every single data point before adding it.
1.8.17