CTL
0.6.1
Computed Tomography Library
|
The TabulatedDataModel class is a data model that handles values in a lookup table. More...
#include <tabulateddatamodel.h>
Public Types | |
enum | { Type = 30 } |
![]() | |
enum | { Type = 0 } |
![]() | |
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 |
AbstractIntegrableDataModel * | clone () 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 ¶meter) override |
Sets the data of this instance based on values in parameter. More... | |
void | insertDataPoint (float key, float value) |
![]() | |
float | meanValue (float position, float binWidth) const |
![]() | |
void | fromVariant (const QVariant &variant) override |
QVariant | toVariant () const override |
bool | isIntegrable () const |
void | setName (const QString &name) |
const QString & | name () const |
![]() | |
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 | |
![]() | |
AbstractIntegrableDataModel (const AbstractIntegrableDataModel &)=default | |
AbstractIntegrableDataModel (AbstractIntegrableDataModel &&)=default | |
AbstractIntegrableDataModel & | operator= (const AbstractIntegrableDataModel &)=default |
AbstractIntegrableDataModel & | operator= (AbstractIntegrableDataModel &&)=default |
![]() | |
AbstractDataModel (const AbstractDataModel &)=default | |
AbstractDataModel (AbstractDataModel &&)=default | |
AbstractDataModel & | operator= (const AbstractDataModel &)=default |
AbstractDataModel & | operator= (AbstractDataModel &&)=default |
![]() | |
SerializationInterface ()=default | |
SerializationInterface (const SerializationInterface &)=default | |
SerializationInterface (SerializationInterface &&)=default | |
SerializationInterface & | operator= (const SerializationInterface &)=default |
SerializationInterface & | operator= (SerializationInterface &&)=default |
![]() | |
DataModelPtr | |
Template alias name for CopyableUniquePtr<ModelType> to a suitable ModelType. | |
AbstractDataModelPtr | |
Alias name for DataModelPtr<AbstractDataModel>. More... | |
std::unique_ptr< ModelType > | makeDataModel (ConstructorArguments &&... arguments) |
using DataModelPtr | CopyableUniquePtr |
Alias name for CopyableUniquePtr<ModelType> to a suitable ModelType. | |
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:
CTL::TabulatedDataModel::TabulatedDataModel | ( | ) |
Constructs an empty TabulatedDataModel.
|
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:
|
explicit |
Constructs a TabulatedDataModel with lookup values given by table.
Example:
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:
|
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.
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.
|
overridevirtual |
Creates a copy of this instance and returns a base class pointer to the new object.
Implements CTL::AbstractIntegrableDataModel.
|
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.
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.
const QMap< float, float > & CTL::TabulatedDataModel::lookupTable | ( | ) | const |
Returns a constant reference to the lookup table stored in this instance
|
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:
Reimplemented from CTL::AbstractDataModel.
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:
void CTL::TabulatedDataModel::setData | ( | QMap< float, float > | table | ) |
Sets the lookup table of this instance to table.
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.
|
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.
|
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.
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.
|
inlineoverridevirtual |
Returns the type id of this instance.
Reimplemented from CTL::AbstractDataModel.
|
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.