CTL
0.6.1
Computed Tomography Library
|
The IntervalDataSeries class is a container for a series of values sampled in equidistant steps (i.e. intervals with equal bin width). More...
#include <intervaldataseries.h>
Public Types | |
enum | ValueType { BinIntegral, MeanValue } |
Public Member Functions | |
IntervalDataSeries (float binWidth, float firstBinStart=0.0f, ValueType valueType=BinIntegral) | |
Constructs an empty IntervalDataSeries object for a series with bin width binWidth. More... | |
IntervalDataSeries (float binWidth, float firstBinStart, const std::vector< float > &values, ValueType valueType=BinIntegral) | |
Constructs an IntervalDataSeries object and directly sets its data to values. More... | |
void | append (float value) |
Appends value to the series. More... | |
void | append (const std::vector< float > &values) |
Appends all values in values to the series. More... | |
void | clampToRange (const SamplingRange &range) |
Clamps all values in this series to the interval specified by range. More... | |
void | normalizeByIntegral () |
Normalizes the values in the series such that the integral will be one afterwards. | |
void | setValue (uint sampleNb, float value) |
void | setValues (const std::vector< float > &values) |
Sets the values passed by values as bin values for this series. More... | |
SamplingRange | binBounds (uint binNb) const |
Returns the boundaries of the interval covered by the bin with index binNb. More... | |
float | binWidth () const |
Returns the bin width (or x distance between two consecutive sampling points). | |
float | centroid () const |
Returns the centroid of the series. More... | |
float | integral () const |
Returns the integral over the series. More... | |
float | integral (const std::vector< float > &weights) const |
Returns the integral over the series with each bin value being weighted by the corresponding factor in weights. More... | |
IntervalDataSeries | normalizedByIntegral () const |
Returns a copy of the series in which the values have been normalized such that the integral will be one. | |
SamplingRange | samplingRange () const |
Returns the range (of x-values) covered by all bins of this series. More... | |
ValueType | valueType () const |
Returns the type of the values in the series, i.e. whether they represent bin integrals or mean values. More... | |
void | normalizeByMaxAbsVal () |
void | normalizeByMaxVal () |
void | scaleValues (float factor) |
![]() | |
const QList< QPointF > & | data () const |
float | max () const |
float | min () const |
uint | nbSamples () const |
uint | size () const |
float | sum () const |
float | sum (const std::vector< float > &weights) const |
float | weightedSum (const std::vector< float > &weights) const |
float | samplingPoint (uint sampleNb) const |
std::vector< float > | samplingPoints () const |
Range< float > | samplingRange () const |
float | value (uint sampleNb) const |
std::vector< float > | values () const |
Range< float > | valueRange () const |
Static Public Member Functions | |
static IntervalDataSeries | sampledFromModel (const AbstractIntegrableDataModel &dataModel, float from, float to, uint nbSamples, ValueType samples=BinIntegral) |
Return a series of nbSamples values sampled from dataModel within the specified interval [ from, to ]. More... | |
static IntervalDataSeries | sampledFromModel (std::shared_ptr< AbstractIntegrableDataModel > dataModel, float from, float to, uint nbSamples, ValueType samples=BinIntegral) |
Overload for std::shared_ptr input. | |
Private Member Functions | |
std::vector< float > | samplingPointsForIndices (uint startIdx, uint endIdx) const |
Computes the sampling points for bins with indices between startIdx and endIdx. More... | |
Private Attributes | |
float | _binWidth |
float | _firstBinStart |
ValueType | _valueType |
Additional Inherited Members | |
![]() | |
PointSeriesBase (const QList< QPointF > &pointSeries) | |
PointSeriesBase (QList< QPointF > &&pointSeries) | |
void | normalizeByMaxAbsVal () |
void | normalizeByMaxVal () |
void | scaleValues (float factor) |
![]() | |
QList< QPointF > | _data |
The IntervalDataSeries class is a container for a series of values sampled in equidistant steps (i.e. intervals with equal bin width).
This class is a specialization of PointSeriesBase to manage equidistantly-sampled data points. Although data is managed as a series of x and y pairs internally, only y-values might be manipulated, in order to ensure that the actual sampling points (i.e. x-values) are kept on the equidistant 'grid'.
There are two main ways of creating an IntervalDataSeries object:
For 1., the sampledFromModel() factory method can be used. These take a data model and return a series of values sampled within the specified interval. You can choose whether the sampled values shall be data integrated over the entire bin or mean values within the individual intervals.
Example:
When manually filling a series (method 2.), you need to decide on the distance between sampling points (i.e. bin width) used in the series to create an IntervalDataSeries using its constructor. Besides the bin width, you might also set the beginning of the first interval (i.e. lower edge of the first bin) and specify the type of data, your sampled values will represent (i.e. either bin integrals of mean values). Note that all these properties may not be changed afterwards. After creating the series object, data points can be appended to the series with append(). The sampling point (i.e. x-value or bin position) is determined automatically, based on the bin width and the specified beginning of the first bin.
IntervalDataSeries offers the possibility to compute both the sum as well as the integral over all values in the series; see sum() and integral() for details. Further convenience provided includes normalization of the values in the series by the integral (see normalizeByIntegral()), computation of the centroid ('center-of-mass', see centroid()), and the possibility to clamp the sampled series to a specific range of x-values (see clampToRange()).
|
explicit |
Constructs an empty IntervalDataSeries object for a series with bin width binWidth.
If required, set the beginning of the first interval (i.e. lower edge of the first bin) with firstBinStart and specify the type of data, your sampled values will represent (i.e. either bin integrals or mean values) by valueType. Note that none of these properties may be changed afterwards. If unspecified, the first bin will start at 0.0 and the value type will default to BinIntegral.
Data points can be added to the series with append().
Example: we create a series that contains values with bin width 1.0, with its first bin starting at x=-2.5 and representing mean values. We then fill in the values 1, 2, 3, and 4.
Note that the sampling points (i.e. bin centers) are computed automatically based on the bin width and starting point of the first bin.
CTL::IntervalDataSeries::IntervalDataSeries | ( | float | binWidth, |
float | firstBinStart, | ||
const std::vector< float > & | values, | ||
IntervalDataSeries::ValueType | valueType = BinIntegral |
||
) |
Constructs an IntervalDataSeries object and directly sets its data to values.
The series is created with a bin width of binWidth and its first bin starting at firstBinStart. The type of data that is represented by the values in the series (i.e. either bin integrals or mean values) can be set by valueType. Note that none of these properties may be changed afterwards. If unspecified, the first bin will start at 0.0 and the value type will default to BinIntegral.
Data passed by values will be added to the series, defining the first values.size() samples. Additional data points can later be added to the series with append().
Example: we create a series that contains the following samples: (-2.0, 1.0), (-1.0, 2.0), (0.0, 3.0), (1.0, 4.0), which shall represent mean values. For that, we need a bin width of 1.0 and a first bin starting point of -2.5f.
Note that the sampling points (i.e. bin centers) are computed automatically based on the bin width and starting point of the first bin.
void CTL::IntervalDataSeries::append | ( | float | value | ) |
Appends value to the series.
Automatically computes the corresponding sampling point (i.e. bin center coordinate).
Example:
void CTL::IntervalDataSeries::append | ( | const std::vector< float > & | values | ) |
Appends all values in values to the series.
Automatically computes the corresponding sampling points (i.e. bin center coordinates).
Example:
SamplingRange CTL::IntervalDataSeries::binBounds | ( | uint | binNb | ) | const |
Returns the boundaries of the interval covered by the bin with index binNb.
This returns the lower and upper boundary of the interval covered by the bin with index binNb as a SamplingRange.
Example:
float CTL::IntervalDataSeries::centroid | ( | ) | const |
Returns the centroid of the series.
Example:
void CTL::IntervalDataSeries::clampToRange | ( | const SamplingRange & | range | ) |
Clamps all values in this series to the interval specified by range.
This means that all values smaller than range.start() and values larger than range.end() will be set to zero.
Note that a series that used to be normalized beforehand might no longer be normalized after the clamp operation.
Example:
float CTL::IntervalDataSeries::integral | ( | ) | const |
Returns the integral over the series.
If valueType() == IntervalDataSeries::BinIntegral, this is the same as sum().
float CTL::IntervalDataSeries::integral | ( | const std::vector< float > & | weights | ) | const |
Returns the integral over the series with each bin value being weighted by the corresponding factor in weights.
The weight vector must contain at least as many elements as there are samples in the series.
If valueType() == IntervalDataSeries::BinIntegral, this is the same as the weighted sum.
|
static |
Return a series of nbSamples values sampled from dataModel within the specified interval [ from, to ].
You can choose whether the sampled values shall be data integrated over the entire bin or mean values within the individual intervals, by passing the corresponding flag to samples (default: IntervalDataSeries::BinIntegral).
nbSamples must be greater than 0. The resulting series has a bin width of \((\to - from) / nbSamples\).
Example:
|
private |
Computes the sampling points for bins with indices between startIdx and endIdx.
Uses computation scheme that is safe even for small bin widths.
SamplingRange CTL::IntervalDataSeries::samplingRange | ( | ) | const |
Returns the range (of x-values) covered by all bins of this series.
Example:
void CTL::PointSeriesBase::scaleValues |
Normalizes the series by dividing all values (i.e. 'y' part) by the maximum absolute value.
Example:
.
Example:
void CTL::IntervalDataSeries::setValues | ( | const std::vector< float > & | values | ) |
Sets the values passed by values as bin values for this series.
This replaces any previous data.
IntervalDataSeries::ValueType CTL::IntervalDataSeries::valueType | ( | ) | const |
Returns the type of the values in the series, i.e. whether they represent bin integrals or mean values.
This will be BinIntegral in most cases. However, if specified explicitely during creation of an IntervalDataSeries, series can be created with ValueType MeanValue; so consider checking for the actual type with this method if that is of concern for your specific use case.