CTL  0.6.1
Computed Tomography Library
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
CTL::AbstractDataModel Class Referenceabstract

The AbstractDataModel class is the base class for basic data models. More...

#include <abstractdatamodel.h>

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

Public Types

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

Public Member Functions

int type () const override
 
virtual float valueAt (float position) const =0
 
virtual AbstractDataModelclone () const =0
 
virtual QVariant parameter () const
 
virtual void setParameter (const QVariant &parameter)
 
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
 

Protected Member Functions

 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
 

Private Attributes

QString _name
 

Friends

template<class >
struct SerializationHelper::RegisterWithSerializationHelper
 

Related Functions

(Note that these are not member functions.)

 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.
 

Detailed Description

The AbstractDataModel class is the base class for basic data models.

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 AbstractDataModel.

To enable de-/serialization of sub-class objects, also reimplement the parameter() method such that it stores all parameters of the model in a QVariant. Additionally, call the macro DECLARE_SERIALIZABLE_TYPE(YourNewClassName) within the .cpp file of your new class (substitute "YourNewClassName" with the actual class name). Objects of the new class can then be de-/serialized with any of the serializer classes (see also AbstractSerializer).

Alternatively, the de-/serialization interface methods toVariant() and fromVariant() can be reimplemented directly. This might be required in some specific situations (usually when polymorphic class members are in use). For the majority of cases, using the parameter() / setParameter() approach should be sufficient and is recommended.

Member Function Documentation

◆ clone()

AbstractDataModel * CTL::AbstractDataModel::clone ( ) const
pure virtual

◆ fromVariant()

void CTL::AbstractDataModel::fromVariant ( const QVariant &  variant)
overridevirtual

Decodes all information required to describe this instance from variant. Required to provide de-/serialization functionality.

Reimplemented from CTL::SerializationInterface.

◆ isIntegrable()

bool CTL::AbstractDataModel::isIntegrable ( ) const

Convenience function that returns true if a dynamic_cast to AbstractIntegrableDataModel is successful and false otherwise.

Returns true if this instance allows integration of data (i.e. it provides the binIntegral() method).

Same as dynamic_cast<const AbstractIntegrableDataModel*>(this).

◆ name()

const QString & CTL::AbstractDataModel::name ( ) const

Returns the name of this model.

◆ parameter()

QVariant CTL::AbstractDataModel::parameter ( ) const
virtual

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 in CTL::FixedXraySpectrumModel, CTL::GaussianModel1D, CTL::RectFunctionModel, CTL::ConstantModel, CTL::StepFunctionModel, CTL::AbstractIntegrableDataModelOperation, CTL::XraySpectrumTabulatedModel, CTL::SaturatedSplineModel, CTL::TabulatedDataModel, CTL::SaturatedLinearModel, CTL::AbstractXraySpectrumModel, CTL::NumericalIntegrationDecorator, and CTL::AbstractDataModelOperation.

◆ setName()

void CTL::AbstractDataModel::setName ( const QString &  name)

Sets the name of this model to name.

◆ setParameter()

void CTL::AbstractDataModel::setParameter ( const QVariant &  parameter)
virtual

Passes parameter to this instance.

Encapsulate all necessary information into the passed QVariant and re-implement this method within your sub-class to parse it into your required format.

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:

DirectBaseClass::setParameter(parameter);
// assuming our class has a parameter member "double _myNewParameter"
_myNewParameter = parameter.toMap().value("my new parameter").toDouble();

Reimplemented in CTL::TASMIPSpectrumModel, CTL::FixedXraySpectrumModel, CTL::GaussianModel1D, CTL::RectFunctionModel, CTL::ConstantModel, CTL::StepFunctionModel, CTL::AbstractIntegrableDataModelOperation, CTL::XraySpectrumTabulatedModel, CTL::SaturatedSplineModel, CTL::TabulatedDataModel, CTL::SaturatedLinearModel, CTL::NumericalIntegrationDecorator, CTL::AbstractXraySpectrumModel, and CTL::AbstractDataModelOperation.

◆ toVariant()

QVariant CTL::AbstractDataModel::toVariant ( ) const
overridevirtual

Encodes all information required to describe this instance into a QVariant.

Required to provide de-/serialization functionality.

Reimplemented from CTL::SerializationInterface.

Reimplemented in CTL::GaussianModel1D.

◆ type()

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

◆ valueAt()

float CTL::AbstractDataModel::valueAt ( float  position) const
pure virtual

Friends And Related Function Documentation

◆ AbstractDataModelPtr()

Alias name for DataModelPtr<AbstractDataModel>.

It provide unique_ptr like behavior for subclasses of AbstractDataModel with option to copy by means of deep copying (provided by clone()).

◆ makeDataModel()

std::unique_ptr< ModelType > makeDataModel ( ConstructorArguments &&...  arguments)
related

Global (free) make function that creates a new AbstractDataModel from the constructor arguments. The component is returned as a std::unique_ptr<ModelType>, whereas ModelType is the template argument of this function that needs to be specified.


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