CTL  0.6.1
Computed Tomography Library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CTL::PointSeriesBase Class Reference

The PointSeriesBase class is the base class used to represent a series of data tuples. More...

#include <pointseriesbase.h>

Inheritance diagram for CTL::PointSeriesBase:
Inheritance graph
[legend]

Public Member Functions

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
 

Protected Member Functions

 PointSeriesBase (const QList< QPointF > &pointSeries)
 
 PointSeriesBase (QList< QPointF > &&pointSeries)
 
void normalizeByMaxAbsVal ()
 
void normalizeByMaxVal ()
 
void scaleValues (float factor)
 

Protected Attributes

QList< QPointF > _data
 

Detailed Description

The PointSeriesBase class is the base class used to represent a series of data tuples.

This class stores data tuples (sampling point and the corresponding value) as a QList<QPointF>. This is done to achieve straightforward compatability with QCharts for visualization purposes.

Data managed by this class cannot be modified through its public interface. Manipulation options, e.g. the possibility to add/remove data points, needs to be provided by dedicated sub-classes.

A number of typical 'inspection' methods is provided. These methods operate on the values (i.e. 'y' part) stored int the tuples. The collection includes min() / max() queries and computation of sum() and weightedSum(), as well as individual queries for the full range covered by either the sampling points (i.e. 'x' part) or the values in the series, see samplingRange() / valueRange().

Protected member methods are available to scale and normalize values in the series. Consider turning them public in sub-classes if appropriate.

Currently, the CTL contains two dedicated sub-classes: XYDataSeries and IntervalDataSeries. Please refer to the individual documentation for their specific purpose.

Constructor & Destructor Documentation

◆ PointSeriesBase() [1/2]

CTL::PointSeriesBase::PointSeriesBase ( const QList< QPointF > &  pointSeries)
explicitprotected

Constructs a PointSeriesBase and sets the data to pointSeries (by copying).

Note that, once created, data cannot be modified through the public interface of this class.

◆ PointSeriesBase() [2/2]

CTL::PointSeriesBase::PointSeriesBase ( QList< QPointF > &&  pointSeries)
explicitprotected

Constructs a PointSeriesBase and sets the data to pointSeries (by moving).

Note that, once created, data cannot be modified through the public interface of this class.

Member Function Documentation

◆ data()

const QList< QPointF > & CTL::PointSeriesBase::data ( ) const

Returns a reference-to-const to the data managed by this instance.

◆ max()

float CTL::PointSeriesBase::max ( ) const

Returns the maximum of the values (i.e. 'y' part of the tuples) in this series.

◆ min()

float CTL::PointSeriesBase::min ( ) const

Returns the minimum of the values (i.e. 'y' part of the tuples) in this series.

◆ nbSamples()

uint CTL::PointSeriesBase::nbSamples ( ) const

Returns the number of samples (i.e. sampling point / value pairs) in this series.

◆ samplingPoint()

float CTL::PointSeriesBase::samplingPoint ( uint  sampleNb) const

Returns the sampling point (i.e. 'x' part) of the sample with index sampleNb in this series.

◆ samplingPoints()

std::vector< float > CTL::PointSeriesBase::samplingPoints ( ) const

Returns all sampling points (i.e. 'x' part) in this series as an std::vector.

Preserves the original order of the points.

◆ samplingRange()

Range< float > CTL::PointSeriesBase::samplingRange ( ) const

Returns the range (smallest to highest sampling point) covered by the sampling points (i.e. 'x' part) in this series.

◆ scaleValues()

void CTL::PointSeriesBase::scaleValues ( float  factor)
protected

Normalizes the series by dividing all values (i.e. 'y' part) by the maximum absolute value.

Example:

auto x = std::vector<float>(6);
std::iota(x.begin(), x.end(), 0.0f);
auto y = std::vector<float>(6);
std::iota(y.begin(), y.end(), -3.0f);
auto series = XYDataSeries(x, y);
qInfo() << series.values();
// output: std::vector(-3, -2, -1, 0, 1, 2)
series.normalizeByMaxAbsVal();
qInfo() << series.values();
// output: std::vector(-1, -0.666667, -0.333333, 0, 0.333333, 0.666667)
/
void PointSeriesBase::normalizeByMaxAbsVal()
{
auto maxEl = std::max_element(_data.begin(), _data.end(),
[] (const QPointF& a, const QPointF& b) {
return qAbs(a.y()) < qAbs(b.y()); });
scaleValues(1.0f / qAbs(maxEl->y()));
}

.

Example:

auto x = std::vector<float>(6);
std::iota(x.begin(), x.end(), 0.0f);
auto y = std::vector<float>(6);
std::iota(y.begin(), y.end(), -3.0f);
auto series = XYDataSeries(x, y);
qInfo() << series.values();
// output: std::vector(-3, -2, -1, 0, 1, 2)
series.normalizeByMaxVal();
qInfo() << series.values();
// output: std::vector(-1.5, -1, -0.5, 0, 0.5, 1)
/
void PointSeriesBase::normalizeByMaxVal()
{
scaleValues(1.0f / max());
}

◆ size()

uint CTL::PointSeriesBase::size ( ) const

Returns the number of samples (i.e. sampling point / value pairs) in this series.

Same as nbSamples().

◆ sum() [1/2]

float CTL::PointSeriesBase::sum ( ) const

Returns the sum over all values in the series.

◆ sum() [2/2]

float CTL::PointSeriesBase::sum ( const std::vector< float > &  weights) const

Returns the weighted sum of all values in the series. Each value in the series is multiplied by the corresponding weight factor from weights within summation. The weight vector must contain at least as many elements as there are samples in the series.

◆ value()

float CTL::PointSeriesBase::value ( uint  sampleNb) const

Returns the value (i.e. 'y' part) of the sample with index sampleNb in this series.

◆ valueRange()

Range< float > CTL::PointSeriesBase::valueRange ( ) const

Returns the range (smallest to highest value) covered by the values (i.e. 'y' part) in this series.

Same as

Range<float>(min(), max())

, but potentially more efficient.

◆ values()

std::vector< float > CTL::PointSeriesBase::values ( ) const

Returns all values (i.e. 'y' part) in this series as an std::vector.

Preserves the original order of the points.

◆ weightedSum()

float CTL::PointSeriesBase::weightedSum ( const std::vector< float > &  weights) const

Alias for sum(const std::vector<float>&), same as

sum(weights)

.


The documentation for this class was generated from the following files: