CTL  0.6.1
Computed Tomography Library
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
CTL::TabulatedDataModel Class Reference

The TabulatedDataModel class is a data model that handles values in a lookup table. More...

#include <tabulateddatamodel.h>

Inheritance diagram for CTL::TabulatedDataModel:
Inheritance graph
[legend]
Collaboration diagram for CTL::TabulatedDataModel:
Collaboration graph
[legend]

Public Types

enum  { Type = 30 }
 
- Public Types inherited from CTL::AbstractDataModel
enum  { Type = 0 }
 
- Public Types inherited from CTL::SerializationInterface
enum  { Type = -1, UserType = 65536 }
 

Public Member Functions

int type () const override
 
float valueAt (float position) const override
 
float binIntegral (float position, float binWidth) const override
 
AbstractIntegrableDataModelclone () const override
 
 TabulatedDataModel ()
 
 TabulatedDataModel (const PointSeriesBase &dataSeries)
 
 TabulatedDataModel (QMap< float, float > table)
 
 TabulatedDataModel (const QVector< float > &keys, const QVector< float > &values)
 
const QMap< float, float > & lookupTable () const
 
void clearData ()
 Removes all values from the table.
 
void setData (const PointSeriesBase &dataSeries)
 
void setData (QMap< float, float > table)
 
void setData (const QVector< float > &keys, const QVector< float > &values)
 
QVariant parameter () const override
 
void setParameter (const QVariant &parameter) override
 Sets the data of this instance based on values in parameter. More...
 
void insertDataPoint (float key, float value)
 
- Public Member Functions inherited from CTL::AbstractIntegrableDataModel
float meanValue (float position, float binWidth) const
 
- Public Member Functions inherited from CTL::AbstractDataModel
void fromVariant (const QVariant &variant) override
 
QVariant toVariant () const override
 
bool isIntegrable () const
 
void setName (const QString &name)
 
const QString & name () const
 
- Public Member Functions inherited from CTL::SerializationInterface
virtual ~SerializationInterface ()=default
 

Private Member Functions

QVariantList dataAsVariantList () const
 Puts all data in this instance into a QVariantList and returns it. More...
 
void setDataFromVariantList (const QVariantList &list)
 Sets the data of this instance based on values in list. More...
 

Private Attributes

QMap< float, float > _data
 

Friends

template<class >
struct SerializationHelper::RegisterWithSerializationHelper
 

Additional Inherited Members

- Protected Member Functions inherited from CTL::AbstractIntegrableDataModel
 AbstractIntegrableDataModel (const AbstractIntegrableDataModel &)=default
 
 AbstractIntegrableDataModel (AbstractIntegrableDataModel &&)=default
 
AbstractIntegrableDataModeloperator= (const AbstractIntegrableDataModel &)=default
 
AbstractIntegrableDataModeloperator= (AbstractIntegrableDataModel &&)=default
 
- Protected Member Functions inherited from CTL::AbstractDataModel
 AbstractDataModel (const AbstractDataModel &)=default
 
 AbstractDataModel (AbstractDataModel &&)=default
 
AbstractDataModeloperator= (const AbstractDataModel &)=default
 
AbstractDataModeloperator= (AbstractDataModel &&)=default
 
- Protected Member Functions inherited from CTL::SerializationInterface
 SerializationInterface ()=default
 
 SerializationInterface (const SerializationInterface &)=default
 
 SerializationInterface (SerializationInterface &&)=default
 
SerializationInterfaceoperator= (const SerializationInterface &)=default
 
SerializationInterfaceoperator= (SerializationInterface &&)=default
 

Detailed Description

The TabulatedDataModel class is a data model that handles values in a lookup table.

Sub-classes must implement the method to sample a value at a given position (valueAt()).

Parameters can be set by passing a QVariant that contains all necessary information. Re-implement the setParameter() method to parse the QVariant into your required format within sub-classes of TabulatedDataModel.

Example:

auto table = TabulatedDataModel();
table.insertDataPoint(5.0f, 1.0f);
table.insertDataPoint(10.0f, 3.0f);
table.insertDataPoint(15.0f, 10.0f);
table.insertDataPoint(20.0f, 7.7f);
// get individual values (lin. interpolation)
qInfo() << table.valueAt(7.5f); // output: 2
qInfo() << table.valueAt(14.5f); // output: 9.3
// get bin integrals (trapezoidal rule)
qInfo() << table.binIntegral(7.5f, 5.0f); // output: 10
qInfo() << table.binIntegral(10.0f, 20.0f); // output: 89.25

Constructor & Destructor Documentation

◆ TabulatedDataModel() [1/4]

CTL::TabulatedDataModel::TabulatedDataModel ( )

Constructs an empty TabulatedDataModel.

◆ TabulatedDataModel() [2/4]

CTL::TabulatedDataModel::TabulatedDataModel ( const PointSeriesBase dataSeries)
explicit

Constructs a TabulatedDataModel with lookup values given by dataSeries.

If dataSeries contains multiple entries with same x value, only the last one will be found in the lookup table after construction.

Example:

XYDataSeries dataSeries;
dataSeries.append(1.2f, 3.4f);
dataSeries.append(4.5f, 6.7f);
dataSeries.append(8.9f, 10.11f);
auto table = TabulatedDataModel(dataSeries);
qInfo() << table.lookupTable();
// output: QMap((1.2, 3.4)(4.5, 6.7)(8.9, 10.11))
// double entry
dataSeries.append(4.5f, 42.0f); // now 'dataSeries' has two entries with a key (x value) of 4.5
// its value (42.0) will replace the old one (i.e. 13.37)
// re-construct the model
table = TabulatedDataModel(dataSeries);
qInfo() << table.lookupTable();
// output: QMap((1.2, 3.4)(4.5, 42)(8.9, 10.11))
// Warning: Tabulated data already contains a value with the key 4.5 ; the previous table entry will be replaced.
See also
setData(const PointSeriesBase&).

◆ TabulatedDataModel() [3/4]

CTL::TabulatedDataModel::TabulatedDataModel ( QMap< float, float >  table)
explicit

Constructs a TabulatedDataModel with lookup values given by table.

Example:

QMap<float, float> values;
values[5.0f] = 1.0f;
values[10.0f] = 3.0f;
values[15.0f] = 10.0f;
values[20.0f] = 7.7f;
auto table = TabulatedDataModel(std::move(values));

◆ TabulatedDataModel() [4/4]

CTL::TabulatedDataModel::TabulatedDataModel ( const QVector< float > &  keys,
const QVector< float > &  values 
)

Constructs a TabulatedDataModel with lookup values given by keys and values.

Data with the same key will be overwritten and the entry occuring last in the vector will remain in the resulting tabulated data.

Both vectors need to have the same length; throws an exception otherwise.

Example:

auto keys = QVector<float>{ 2.1f, 4.2f, 13.9f, 7.8f };
auto values = QVector<float>{ 42.0f, 13.37f, 42.0f, 13.37f };
auto table = TabulatedDataModel(keys, values);
qInfo() << table.lookupTable();
// output: QMap((2.1, 42)(4.2, 13.37)(7.8, 13.37)(13.9, 42))
// double entry
keys.append(4.2f); // now we have two entries of 4.2 in the 'keys' vector
values.append(66.6f); // this value will replace the old one (i.e. 13.37)
// re-construct the model
table = TabulatedDataModel(keys, values);
qInfo() << table.lookupTable();
// output: QMap((2.1, 42)(4.2, 66.6)(7.8, 13.37)(13.9, 42))
// differing length of keys and values
keys.append(10.0f);
try {
table = TabulatedDataModel(keys, values);
} catch (std::domain_error& err) {
qInfo() << err.what();
}
// output: TabulatedDataModel::setData(): keys and values have different size.

Member Function Documentation

◆ binIntegral()

float CTL::TabulatedDataModel::binIntegral ( float  position,
float  binWidth 
) const
overridevirtual

Returns the integral of the tabulated data over the interval \( \left[position-\frac{binWidth}{2},\,position+\frac{binWidth}{2}\right] \).

This method uses trapezoid integration. The following figure provides an example of the procedure.

Example of integration of lookup table data in a TabulatedDataModel.

The table contains 10 data points (star symbols). Integration is shown for three different cases. Interval 1: The integration bin covers multiple tabulated values. In this case, the result is a sum over all partial intervals. If one (or both) integration border(s) is outside the range of tabulated values, the requested point is extrapolated linearly to zero (see left side of Interval 1). Interval 2: Integration bin lays between two tabulated values. Interval 3: Interval is fully outside the range of tabulated data. This bin integral returns zero.

Implements CTL::AbstractIntegrableDataModel.

◆ clone()

AbstractIntegrableDataModel * CTL::TabulatedDataModel::clone ( ) const
overridevirtual

Creates a copy of this instance and returns a base class pointer to the new object.

Implements CTL::AbstractIntegrableDataModel.

◆ dataAsVariantList()

QVariantList CTL::TabulatedDataModel::dataAsVariantList ( ) const
private

Puts all data in this instance into a QVariantList and returns it.

The returned QVariantList contains all data points in the table of this instance - these data points are the individual entries in the list. Each of these entries itself is a QVariantList with two elements, the (key, value)-pair for the table entry.

◆ insertDataPoint()

void CTL::TabulatedDataModel::insertDataPoint ( float  key,
float  value 
)

Inserts the (key, value) pair into the lookup table of this instance.

If an entry with the same key already exists, it will be overwritten.

◆ lookupTable()

const QMap< float, float > & CTL::TabulatedDataModel::lookupTable ( ) const

Returns a constant reference to the lookup table stored in this instance

◆ parameter()

QVariant CTL::TabulatedDataModel::parameter ( ) const
overridevirtual

Returns the parameters of this instance as a QVariant.

Re-implement this method within your sub-class such that it encapsulates all necessary information into a QVariant.

Best practice is to invoke the base class version of this method to take care of all content originating from underlying base classes.

A typical reimplementation in sub-classes might look like this:

QVariantMap ret = DirectBaseClass::parameter().toMap();
ret.insert("my new parameter", _myNewParameter);
return ret;

Reimplemented from CTL::AbstractDataModel.

◆ setData() [1/3]

void CTL::TabulatedDataModel::setData ( const PointSeriesBase dataSeries)

Sets the lookup table of this instance to the values in dataSeries. This replaces any previous data.

dataSeries should not contain multiple entries with the same x value; if it does contain such values, any reoccuring value replaces the previous one. Ultimately, only the key-value-pair corresponding to the entry appearing last in dataSeries (i.e. from all of those with same x) will be in the table after this call.

Example:

TabulatedDataModel table; // an empty table model
// create an XryTube object, set the tube voltage to 115 kV and sample its spectrum
XrayTube tube;
tube.setTubeVoltage(115.0f);
const auto sampledSpectrum = tube.spectrum(10); // sample 10 values
// set the data for 'table' to the points of the sampled spectrum
table.setData(sampledSpectrum);
// print table
for(auto it = table.lookupTable().cbegin(); it != table.lookupTable().cend(); ++it)
qInfo() << it.key() << it.value();
// output: 5.75 6.47231e-05
// 17.25 0.047528
// 28.75 0.193677
// 40.25 0.2194
// 51.75 0.193015
// 63.25 0.186251
// 74.75 0.0760962
// 86.25 0.0484104
// 97.75 0.0269858
// 109.25 0.00857234

◆ setData() [2/3]

void CTL::TabulatedDataModel::setData ( QMap< float, float >  table)

Sets the lookup table of this instance to table.

◆ setData() [3/3]

void CTL::TabulatedDataModel::setData ( const QVector< float > &  keys,
const QVector< float > &  values 
)

Sets the lookup table of this instance to the values given by keys and values.

Data with the same key will be overwritten and the entry occuring last in the vector will remain in the resulting tabulated data.

Both vectors need to have the same length; throws an exception otherwise.

◆ setDataFromVariantList()

void CTL::TabulatedDataModel::setDataFromVariantList ( const QVariantList &  list)
private

Sets the data of this instance based on values in list.

The passed QVariantList list must contain all data points that shall be in the table - these data points are individual entries in list. Each of these entries itself must be a QVariantList with two elements, the (key, value)-pair for the table entry. Entries with less than two elements will be ignored.

Note that this method is private, but we illustrate an example anyways. Example: set the data points (1, 3) and (3, 7) to the table.

auto table = std::make_shared<TabulatedDataModel>();
table->setDataFromVariantList(QVariantList{ QVariantList{1.0, 3.0},
QVariantList{3.0, 7.0} });

◆ setParameter()

void CTL::TabulatedDataModel::setParameter ( const QVariant &  parameter)
overridevirtual

Sets the data of this instance based on values in parameter.

The passed parameter must be a QVariantMap that contains an entry "data" which is a QVariantList that contains all data points that shall be put into the table

See setDataFromVariantList() for more details.

Example: set the data points (1, 3) and (3, 7) to the table.

auto table = std::make_shared<TabulatedDataModel>();
const auto dataList = QVariantList{ QVariantList{1.0, 3.0},
QVariantList{3.0, 7.0} };
table->setParameter(QVariantMap{ {"data", dataList} });

Note that it will typically be much simpler to clear the table (see clearData()) and insert data points individually (see insertDataPoint()) or use a setData() method.

Reimplemented from CTL::AbstractDataModel.

◆ type()

int CTL::TabulatedDataModel::type ( ) const
inlineoverridevirtual

Returns the type id of this instance.

Reimplemented from CTL::AbstractDataModel.

◆ valueAt()

float CTL::TabulatedDataModel::valueAt ( float  pos) const
overridevirtual

Returns a linearly interpolated value at position pos based on the data in the lookup table.

Returns zero if pos is outside the range of the available tabulated data.

Implements CTL::AbstractDataModel.


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