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

The GaussianModel2D class represents a two-dimensional Gaussian curve. More...

#include <datamodels2d.h>

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

Public Types

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

Public Member Functions

int type () const override
 
float valueAt (float x, float y) const override
 Returns the value from the model at position (x, y). More...
 
AbstractDataModel2Dclone () const override
 
 GaussianModel2D (float amplitude=1.0f, float mean=0.0f, float std=1.0f, float correlation=0.0f)
 Constructs a GaussianModel2D; a model representing a two-dimensional Gaussian curve. More...
 
 GaussianModel2D (float amplitude, float meanX, float meanY, float stdX, float stdY, float correlation=0.0f)
 Constructs a GaussianModel2D; a model representing a two-dimensional Gaussian curve. More...
 
QVariant toVariant () const override
 
QVariant parameter () const override
 
void setParameter (const QVariant &parameter) override
 Sets the parameters contained in parameter (a QVariantMap). More...
 
virtual void setParameter (const QVariant &parameter)
 
void setParameter (const QString &name, const QVariant &value)
 
- Public Member Functions inherited from CTL::AbstractDataModel2D
void setParameter (const QString &name, const QVariant &value)
 
void fromVariant (const QVariant &variant) override
 
QString name () const
 
void setName (const QString &name)
 
Chunk2D< float > sampleChunk (const SamplingRange &xRange, const SamplingRange &yRange, uint nbSamplesX, uint nbSamplesY) const
 
- Public Member Functions inherited from CTL::SerializationInterface
virtual ~SerializationInterface ()=default
 

Private Member Functions

void setSaveCorr (float corr)
 Helper function to set correlation value within valid range.
 
void setSaveStdX (float std)
 Helper function to set standard deviation value within valid range.
 
void setSaveStdY (float std)
 Helper function to set standard deviation value within valid range.
 

Private Attributes

float _ampl = 1.0f
 
float _meanX = 0.0f
 
float _meanY = 0.0f
 
float _stdX = 1.0f
 
float _stdY = 1.0f
 
float _corr = 0.0f
 

Friends

template<class >
struct SerializationHelper::RegisterWithSerializationHelper
 

Additional Inherited Members

- Protected Member Functions inherited from CTL::AbstractDataModel2D
 AbstractDataModel2D (const AbstractDataModel2D &)=default
 
 AbstractDataModel2D (AbstractDataModel2D &&)=default
 
AbstractDataModel2Doperator= (const AbstractDataModel2D &)=default
 
AbstractDataModel2Doperator= (AbstractDataModel2D &&)=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 GaussianModel2D class represents a two-dimensional Gaussian curve.

This model maps input values according to a two-dimensional Gaussian function.

Constructor & Destructor Documentation

◆ GaussianModel2D() [1/2]

CTL::GaussianModel2D::GaussianModel2D ( float  amplitude = 1.0f,
float  mean = 0.0f,
float  std = 1.0f,
float  correlation = 0.0f 
)
explicit

Constructs a GaussianModel2D; a model representing a two-dimensional Gaussian curve.

This creates a model representing a two-dimensional Gaussian function specified by amplitude, mean, std, and correlation.

The passed parameters mean and std will be uses for both dimensions. Same as GaussianModel2D(amplitude, mean, mean, std, std, correlation).

Note that the input to std must be strictly positive, i.e. std > 0; and correlation must be between (excluding the borders) -1 and 1, i.e. -1.0 < correlation < 1.0.

Throws an std::domain_error for invalid input.

See also
valueAt()

◆ GaussianModel2D() [2/2]

CTL::GaussianModel2D::GaussianModel2D ( float  amplitude,
float  meanX,
float  meanY,
float  stdX,
float  stdY,
float  correlation = 0.0f 
)

Constructs a GaussianModel2D; a model representing a two-dimensional Gaussian curve.

This creates a model representing a two-dimensional Gaussian function specified by amplitude, meanX, meanY, stdX, stdY, and correlation.

Note that the input to both standard deviation parameters (stdX, stdY) must be strictly positive, i.e. stdX > 0, stdY > 0; and correlation must be between (excluding the borders) -1 and 1, i.e. -1.0 < correlation < 1.0.

Throws an std::domain_error for invalid input.

See also
valueAt()

Member Function Documentation

◆ parameter()

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

Returns the parameters of this model as a QVariant.

Default implementation returns an empty QVariant. Override in custom classes to encode all relevant information from the class' members. The returned QVariant must contain all information to fully specify the objects state. In particular, calling setParameter(parameter()) should not change the state of an object.

Reimplemented from CTL::AbstractDataModel2D.

◆ setParameter() [1/3]

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

Sets the parameters contained in parameter (a QVariantMap).

The value passed to parameter must be a QVariantMap containing one or multiple of the following (key, value)-pairs:

-("amplitude", [float] amplitude), -("meanX", [float] meanX), -("meanY", [float] meanY), -("stdX", [float] stdX), -("stdY", [float] stdY), -("correlation", [float] correlation).

stdX and stdY must be strictly positive, i.e. i.e. stdX > 0, stdY > 0; for other input, a warning is generated and a default value of 1.0 will be set. correlation must be between (excluding the borders) -1 and 1, i.e. -1.0 < correlation < 1.0; for other input, a warning is generated and a default value of 0.0 will be set.

Example: setting mean in y direction to 3, amplitude to 2.5 and a correlation of 0.5

auto gaussian = std::make_shared<GaussianModel2D>();
gaussian->setParameter(QVariantMap{ { "meanY", 3.0f },
{ "amplitude", 2.5f },
{ "correlation", 0.5f } } );

Reimplemented from CTL::AbstractDataModel2D.

◆ setParameter() [2/3]

void CTL::AbstractDataModel2D::setParameter

Sets the parameter with tag name to value, by passing a QVariantMap containing only the name, value pair as its sole entry to setParameter(const QVariant&).

This method is only useful if setParameter(const QVariant&) is implemented in a way that it allows for individual parameters to be set if the QVariant passed to it does only contain a selection of parameters. When overriding setParameter(const QVariant&) in custom classes, this method will be shadowed. In case you implemented setParameter(const QVariant&) in the way described above (i.e. such that setting individual parameters is possible), re-enable this method in the sub-class via

.

◆ setParameter() [3/3]

void CTL::AbstractDataModel2D::setParameter

Sets the parameters of this model based on data held in parameter.

Default implementation does nothing. Override in custom classes to extract all relevant information from parameter and set class members accordingly. A call to this method (given an appropriate input parameter) should prepare the full state of the object. In particular, calling setParameter(parameter()) should not change the state of an object.

◆ toVariant()

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

Interface to store all member variables in a QVariant.

Stores the object's type-id.

Reimplement this method such that it stores all newly introduced object data when sub-classing. This needs to cover everything that is necessary to fully determine the state of an object. 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::toVariant().toMap();
ret.insert("my member variable", _myMemberVariable);
return ret;

Reimplemented from CTL::AbstractDataModel2D.

◆ type()

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

Returns the type-id of the serializable object. Used in deserialization to determine the proper object type.

Add derived classes to the enumeration using the CTL_TYPE_ID macro.

Reimplemented from CTL::AbstractDataModel2D.

◆ valueAt()

float CTL::GaussianModel2D::valueAt ( float  x,
float  y 
) const
overridevirtual

Returns the value from the model at position (x, y).

With the defining parameters of the Gaussian curve according to the constructor (see GaussianModel2D()):

  • amplitude: \( A \)
  • meanX: \( \mu_x \)
  • meanY: \( \mu_y \)
  • stdX: \( \sigma_x \)
  • stdY: \( \sigma_y \)
  • correlation: \( c \)

the resulting value is given by follwoing relation:

\( f(x)= \frac{A}{2\pi \sigma_x \sigma_y \sqrt{1-c^2}} \cdot \exp\left[-\frac{1}{2 (1-c^2)} \cdot \left( \frac{(x-\mu_x)^2}{\sigma_x^2} + \frac{(y-\mu_y)^2}{\sigma_y^2} - \frac{2c \cdot (x-\mu_x)(y-\mu_y)}{\sigma_x \sigma_y} \right) \right] \)

Implements CTL::AbstractDataModel2D.


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