CTL  0.6.1
Computed Tomography Library
Public Slots | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
CTL::gui::DataModelViewer Class Reference

The DataModelViewer class provides a visualization tool for data model types. More...

#include <datamodelviewer.h>

Inheritance diagram for CTL::gui::DataModelViewer:
Inheritance graph
[legend]
Collaboration diagram for CTL::gui::DataModelViewer:
Collaboration graph
[legend]

Public Slots

void increaseSamplingDensity ()
 
void hideParameterGUI (bool hide=true)
 
void reduceSamplingDensity ()
 
void setLabelX (const QString &label)
 
void setLabelY (const QString &label)
 
void setNumberOfSamples (int nbSamples)
 
void setSamplingRange (float from, float to)
 
void toggleLogY ()
 

Public Member Functions

 DataModelViewer (QWidget *parent=nullptr)
 
 ~DataModelViewer ()
 
LineSeriesViewdataViewValues () const
 
IntervalSeriesViewdataViewBinIntegrals () const
 
void setData (std::shared_ptr< AbstractDataModel > model)
 Sets the data model visualized by this instance to model. More...
 
void setData (const AbstractDataModel &model)
 Sets the data model visualized by this instance to model. More...
 

Static Public Member Functions

static void plot (std::shared_ptr< AbstractDataModel > model, const QString &labelX="x", const QString &labelY="y")
 Creates a DataModelViewer for model and shows the window. More...
 
static void plot (const AbstractDataModel &model, const QString &labelX="x", const QString &labelY="y")
 Creates a DataModelViewer for model and shows the window. More...
 

Protected Member Functions

void keyPressEvent (QKeyEvent *event) override
 

Private Slots

void updatePlot ()
 

Private Member Functions

void setModelParameter (QVariant parameter)
 

Private Attributes

LineSeriesView_lineView
 
IntervalSeriesView_intervalView
 
Ui::DataModelViewer * ui
 
std::unique_ptr< AbstractDataModel_model
 

Detailed Description

The DataModelViewer class provides a visualization tool for data model types.

This class can be used to visualize data models of subclasses of AbstractDataModel and AbstractIntegrableDataModel. For convenience, the plot() method can be used to achieve a one-line solution, creating a widget that will be destroyed once it is closed by the user.

Data is visualized as a line plot (using LineSeriesView). In case of an integrable model, bin integral data can also be visualized as a bar plot (using IntervalSeriesView). View modes can be toggled using the GUI. The number of values that are sampled from the model (and visualized in the viewport) can be adjusted via the GUI or using the corresponding slots setNumberOfSamples(), increaseSamplingDensity(), and reduceSamplingDensity(). Axis labels (identical for both plot types) can be specified using setLabelX() and setLabelY() or by passing the labels as arguments when using the plot() method, respectively. Linear/logarithmic y-axis visualization can be toggled using toggleLogY() as well as via the GUI.

In case the visualized data model has parameters, these can be adjusted directly within this viewer's GUI. The parameter GUI can be hidden using hideParamterGUI(), if desired. It becomes hidden automatically in case the model does not have any parameters. Modifying model parameters from outside the viewer will not automatically update the plot. If such a setting is required, use updatePlot() to enforce redrawing of the plot. (Note that this will not update the entries in the parameter GUI.)

The following IO operations are supported by this class:

The following example shows how to visualize a data model with the DataModelViewer class:

// create a model of an X-ray spectrum for tube voltage 85 keV
auto model = std::make_shared<TASMIPSpectrumModel>(85.0);
// (static version) using the plot() command
// (property-based version) alternatively
auto viewer = new gui::DataModelViewer; // needs to be deleted at an appropriate time
viewer->setData(model);
viewer->dataViewValues()->chart()->setTheme(QtCharts::QChart::ChartThemeDark);
viewer->resize(750,400);
viewer->show();
Resulting visualization from the example above. (a) static version, (b) property-based version.

As can be seen from the example, the property-based version allows accessing the viewports, and thereby, grants control over their specific settings (such as visual appearance or axis ranges). The viewports are accessible via dataViewValues() and dataViewBinIntegrals() for the line and bar plot view, respectively.

The DataModelViewer can also be used conveniently to inspect compositions of multiple models. The following example illustrates that for a sum of two step function models:

auto step1 = std::make_shared<StepFunctionModel>(10.0, 3.0, StepFunctionModel::RightIsZero);
auto step2 = std::make_shared<StepFunctionModel>(25.0, 1.0, StepFunctionModel::LeftIsZero);
// visualize
Resulting visualization from the composition example. (a) only model 'step1', (b) only model 'step2', (c) sum of 'step1' and 'step2'.

Constructor & Destructor Documentation

◆ DataModelViewer()

CTL::gui::DataModelViewer::DataModelViewer ( QWidget *  parent = nullptr)
explicit

Creates a DataModelViewer and sets its parent to parent.

◆ ~DataModelViewer()

CTL::gui::DataModelViewer::~DataModelViewer ( )

Deletes this instance.

Member Function Documentation

◆ dataViewBinIntegrals()

IntervalSeriesView * CTL::gui::DataModelViewer::dataViewBinIntegrals ( ) const

Returns the viewport for displaying the bin integral data in this instance. Use this to adjust its specific settings if required.

Example: setting a dark theme for the bin integral chart

auto viewer = new gui::DataModelViewer;
// ...
viewer->dataViewBinIntegrals()->chart()->setTheme(QtCharts::QChart::ChartThemeDark);
viewer->show();
See also
IntervalSeriesView.

◆ dataViewValues()

LineSeriesView * CTL::gui::DataModelViewer::dataViewValues ( ) const

Returns the viewport for displaying the line series data in this instance. Use this to adjust its specific settings if required.

Example: setting a specific axis range for the line series view and changing the chart title

auto viewer = new gui::DataModelViewer;
// ...
viewer->dataViewValues()->setRangeX(20.0, 30.0);
viewer->dataViewValues()->chart()->setTitle("Example title");
viewer->show();
See also
LineSeriesView.

◆ hideParameterGUI

void CTL::gui::DataModelViewer::hideParameterGUI ( bool  hide = true)
slot

Hides the model parameter GUI element if hide = true and shows it otherwise.

◆ increaseSamplingDensity

void CTL::gui::DataModelViewer::increaseSamplingDensity ( )
slot

Increases the number of sampling points by 25% of their current value.

◆ plot() [1/2]

void CTL::gui::DataModelViewer::plot ( std::shared_ptr< AbstractDataModel model,
const QString &  labelX = "x",
const QString &  labelY = "y" 
)
static

Creates a DataModelViewer for model and shows the window.

Note that this instance takes a copy of model through its clone() method. model must not be nullptr; throws an std::runtime_error otherwise.

Labels of the axes can be specified by labelX and labelY. If left empty, default axis labels are "x" and "y".

Depending on whether or not model is integrable (see AbstractIntegrableDataModel), the widget also offers the option to visualize bin integrals.

The widget will be deleted automatically if the window is closed.

Example:

// get the attenuation model of lead from the database
auto attModel = attenuationModel(database::Element::Pb);
// visualize
gui::DataModelViewer::plot(attModel, "Energy [keV]", "Mass atten. coeff. [cm^2/g]");

◆ plot() [2/2]

void CTL::gui::DataModelViewer::plot ( const AbstractDataModel model,
const QString &  labelX = "x",
const QString &  labelY = "y" 
)
static

Creates a DataModelViewer for model and shows the window.

Note that this instance takes a copy of model through its clone() method.

Labels of the axes can be specified by labelX and labelY. If left empty, default axis labels are "x" and "y".

Depending on whether or not model is integrable (see AbstractIntegrableDataModel), the widget also offers the option to visualize bin integrals.

The widget will be deleted automatically if the window is closed.

Example:

// create a one-dimensional Gaussian model
auto model = GaussianModel1D();
// visualize

◆ reduceSamplingDensity

void CTL::gui::DataModelViewer::reduceSamplingDensity ( )
slot

Reduces the number of sampling points to 80% of their current value.

◆ setData() [1/2]

void CTL::gui::DataModelViewer::setData ( std::shared_ptr< AbstractDataModel model)

Sets the data model visualized by this instance to model.

Note that this will clone the model, such that the viewer instance will own a copy of model. model must not be nullptr; throws an std::runtime_error otherwise.

◆ setData() [2/2]

void CTL::gui::DataModelViewer::setData ( const AbstractDataModel model)

Sets the data model visualized by this instance to model.

Note that this will clone the model, such that the viewer instance will own a copy of model.

◆ setLabelX

void CTL::gui::DataModelViewer::setLabelX ( const QString &  label)
slot

Sets the label of the x-axis of both plot types to label.

◆ setLabelY

void CTL::gui::DataModelViewer::setLabelY ( const QString &  label)
slot

Sets the label of the y-axis of both plot types to label.

◆ setNumberOfSamples

void CTL::gui::DataModelViewer::setNumberOfSamples ( int  nbSamples)
slot

Sets the number of sampling points to nbSamples.

◆ setSamplingRange

void CTL::gui::DataModelViewer::setSamplingRange ( float  from,
float  to 
)
slot

Sets the range within which the model is sampled to [from, to].

◆ toggleLogY

void CTL::gui::DataModelViewer::toggleLogY ( )
slot

Toggles between linear and logarithmic y-axis display.

◆ updatePlot

void CTL::gui::DataModelViewer::updatePlot ( )
privateslot

Updates the current plot. This will readout all UI elements for information on sampling and performs a new sampling of the values from the model.

This is called automatically when necessary.


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