Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
Medical Imaging Interaction Toolkit
QmitkPlotWidget Class Reference

#include <QmitkPlotWidget.h>

Inheritance diagram for QmitkPlotWidget:
Collaboration diagram for QmitkPlotWidget:

Public Types

typedef double ScalarType
 
typedef std::vector< ScalarTypeDataVector
 
typedef std::vector< std::pair< double, double > > XYDataVector
 

Public Member Functions

 QmitkPlotWidget (QWidget *parent=nullptr, const char *title=nullptr, const char *name=nullptr, Qt::WindowFlags f={})
 
 ~QmitkPlotWidget () override
 
QwtPlot * GetPlot ()
 
void SetPlotTitle (const QwtText &qwt_title)
 
void SetPlotTitle (const char *title)
 
unsigned int InsertCurve (const char *title, QColor color=QColor(Qt::black))
 
void SetAxisTitle (int axis, const char *title)
 
bool SetCurveData (unsigned int curveId, const DataVector &xValues, const DataVector &yValues)
 
bool SetCurveData (unsigned int curveId, const DataVector &xValues, const DataVector &yValues, const DataVector &yLowerError, const DataVector &yUpperError)
 Sets the data with errors for a previously added curve. More...
 
bool SetCurveData (unsigned int curveId, const DataVector &xValues, const DataVector &yValues, const DataVector &xLowerError, const DataVector &xUpperError, const DataVector &yLowerError, const DataVector &yUpperError)
 Sets the data with errors for a previously added curve. More...
 
bool SetCurveData (unsigned int curveId, const XYDataVector &data)
 
void SetCurvePen (unsigned int curveId, const QPen &pen)
 
void SetCurveBrush (unsigned int curveId, const QBrush &brush)
 
void SetCurveStyle (unsigned int curveId, const QwtPlotCurve::CurveStyle style)
 
void SetCurveSymbol (unsigned int curveId, QwtSymbol *symbol)
 
void SetCurveAntialiasingOn (unsigned int curveId)
 
void SetCurveAntialiasingOff (unsigned int curveId)
 
void SetCurveTitle (unsigned int curveId, const char *title)
 
void SetErrorPen (unsigned int curveId, const QPen &pen)
 
void SetErrorStyleSymbols (unsigned int curveId, bool drawSmybols)
 
void SetLegend (QwtLegend *legend, QwtPlot::LegendPosition pos=QwtPlot::RightLegend, double ratio=-1)
 
void SetLegendAttribute (unsigned int curveId, const QwtPlotCurve::LegendAttribute &attribute)
 
void Replot ()
 
void Clear ()
 

Protected Member Functions

double * ConvertToRawArray (const DataVector &values)
 
double * ConvertToRawArray (const XYDataVector &values, unsigned int component)
 
bool AddErrorIntervalCurve (unsigned int curveId, const DataVector &lessError, const DataVector &moreError, bool isXError)
 

Protected Attributes

QwtPlot * m_Plot
 
std::vector< std::tuple< QwtPlotCurve *, QwtPlotIntervalCurve *, QwtPlotIntervalCurve * > > m_PlotCurveVector
 

Detailed Description

Provides a convenient interface for plotting curves using qwt. Designed for qwt version 5.2.1. Can be used with a QmitkPlotDialog, which provides a "Close" button.

See also
QmitkPlotDialog

To plot data do the following:

  1. Create two QmitkPlotWidget::DataVector Objects and fill them with corresponding x/y values. DataVectors are simple stl-vectors of type std::vector<double>. Please note that the xValues vector and the yValues vector MUST have the same size.
  2. Instantiate the widget for example like that: QmitkPlotWidget* widget = new QmitkPlotWidget( this, "widget" ); widget->SetAxisTitle( QwtPlot::xBottom, "My x asis [mm]" ); widget->SetAxisTitle( QwtPlot::yLeft, "My y axis [mm]" ); int curveId = widget->InsertCurve( "My sophisticated data" ); widget->SetCurveData( curveId, xValues, yValues ); widget->SetCurvePen( curveId, QPen( red ) ); widget->SetCurveTitle( curveId, "My curve description" ); widget->Replot();
  3. You can modify the behavior of the plot by directly referencing the QwtPlot instance using the method GetPlot().
    See also
    QwtPlot
    Deprecated:
    (as of 2018_04) Use QmitkChartWidget instead

Definition at line 54 of file QmitkPlotWidget.h.

Member Typedef Documentation

◆ DataVector

This type may be used to store a set of scalar values representing either x or y coordinates of the data points that should be rendered.

Definition at line 73 of file QmitkPlotWidget.h.

◆ ScalarType

represents the data type used for scalar values stored in data arrays. This type is provided by qwt and may not be changed.

Definition at line 66 of file QmitkPlotWidget.h.

◆ XYDataVector

typedef std::vector<std::pair<double, double> > QmitkPlotWidget::XYDataVector

convenience type used to store pairs representing x/y coordinates that should be rendered as a curve by the plot widget

Definition at line 79 of file QmitkPlotWidget.h.

Constructor & Destructor Documentation

◆ QmitkPlotWidget()

QmitkPlotWidget::QmitkPlotWidget ( QWidget *  parent = nullptr,
const char *  title = nullptr,
const char *  name = nullptr,
Qt::WindowFlags  f = {} 
)

Standard qt constructor

◆ ~QmitkPlotWidget()

QmitkPlotWidget::~QmitkPlotWidget ( )
override

Virtual destructor

Member Function Documentation

◆ AddErrorIntervalCurve()

bool QmitkPlotWidget::AddErrorIntervalCurve ( unsigned int  curveId,
const DataVector lessError,
const DataVector moreError,
bool  isXError 
)
protected

Adds an error interval curve.

All errors should be absolutes. The magnitude will be used.

Parameters
curveIdWhich curve should the error curve be added to
lessErrorError in the negative direction (value - lessError)
moreErrorError in the positive direction (value + lessError)
isXErrorShould the error bars be drawn horizontally

◆ Clear()

void QmitkPlotWidget::Clear ( )

Resets the plot into an empty state

◆ ConvertToRawArray() [1/2]

double* QmitkPlotWidget::ConvertToRawArray ( const DataVector values)
protected

Converts the given values into a raw double* array. A new array is allocated via new and must be deleted[] by the caller.

◆ ConvertToRawArray() [2/2]

double* QmitkPlotWidget::ConvertToRawArray ( const XYDataVector values,
unsigned int  component 
)
protected

Converts the given values into a raw double* array. A new array is allocated via new and must be deleted[] by the caller.

Parameters
valuesthe x/y values to convert to an array
componentdefines if the x values (0) or the y values(1) should be converted. Other values than 0 and 1 will not be accepted.

◆ GetPlot()

QwtPlot* QmitkPlotWidget::GetPlot ( )

Returns the instance of the plot-widget. This may be used to modify any detail of the appearance of the plot.

◆ InsertCurve()

unsigned int QmitkPlotWidget::InsertCurve ( const char *  title,
QColor  color = QColor(Qt::black) 
)

Inserts a new curve into the plot-window.

Parameters
titlethe name of the curve
color
Returns
the id of the curve. Use this id to refer to the curve, if you want to modify or add data.

◆ Replot()

void QmitkPlotWidget::Replot ( )

Triggers a replot of the curve. Replot should be called once after setting new data.

◆ SetAxisTitle()

void QmitkPlotWidget::SetAxisTitle ( int  axis,
const char *  title 
)

Sets the title of the given axis. For the set of available axes

See also
QwtPlot::Axis.
Parameters
axisthe axis for which the description should be set.
titlethe name of the axis.

◆ SetCurveAntialiasingOff()

void QmitkPlotWidget::SetCurveAntialiasingOff ( unsigned int  curveId)

◆ SetCurveAntialiasingOn()

void QmitkPlotWidget::SetCurveAntialiasingOn ( unsigned int  curveId)

◆ SetCurveBrush()

void QmitkPlotWidget::SetCurveBrush ( unsigned int  curveId,
const QBrush &  brush 
)

Assign a brush, which defines the fill pattern of shapes drawn by a QPainter. In case of brush.style() != QBrush::NoBrush and * style() != QwtPlotCurve::Sticks the area between the curve and the baseline will be filled. In case !brush.color().isValid() the area will be filled by pen.color(). The fill algorithm simply connects the first and the last curve point to the baseline. So the curve data has to be sorted (ascending or descending).

Parameters
curveIdthe id of the curve for which appearance should be changed
brusha QBrush (
See also
QBrush) defining the line style

◆ SetCurveData() [1/4]

bool QmitkPlotWidget::SetCurveData ( unsigned int  curveId,
const DataVector xValues,
const DataVector yValues 
)

Sets the data for a previously added curve. Data is provided as two vectors of double. The first vector represents the x coordinates, the second vector represents the y coordinates.

Parameters
curveIdthe id of the curve for which data should be added.
xValuesthe x coordinates of the points that define the curve
yValuesthe y coordinates of the points that define the curve
Returns
whether data was added successfully or not

◆ SetCurveData() [2/4]

bool QmitkPlotWidget::SetCurveData ( unsigned int  curveId,
const DataVector xValues,
const DataVector yValues,
const DataVector xLowerError,
const DataVector xUpperError,
const DataVector yLowerError,
const DataVector yUpperError 
)

Sets the data with errors for a previously added curve.

Parameters
curveIdthe id of the curve for which data should be added.
xValuesthe x coordinates of the points that define the curve
yValuesthe y coordinates of the points that define the curve
xLowerErrorthe magnitude (>0) of the error in the lesser direction of x
xUpperErrorthe magnitude (>0) of the error in the larger direction of x
yLowerErrorthe magnitude (>0) of the error in the lesser direction of y
yUpperErrorthe magnitude (>0) of the error in the larger direction of y
Returns
whether data was added successfully or not

◆ SetCurveData() [3/4]

bool QmitkPlotWidget::SetCurveData ( unsigned int  curveId,
const DataVector xValues,
const DataVector yValues,
const DataVector yLowerError,
const DataVector yUpperError 
)

Sets the data with errors for a previously added curve.

Parameters
curveIdthe id of the curve for which data should be added.
xValuesthe x coordinates of the points that define the curve
yValuesthe y coordinates of the points that define the curve
yLowerErrorthe magnitude (>0) of the error in the lesser direction of y
yUpperErrorthe magnitude (>0) of the error in the larger direction of y
Returns
whether data was added successfully or not

◆ SetCurveData() [4/4]

bool QmitkPlotWidget::SetCurveData ( unsigned int  curveId,
const XYDataVector data 
)

Sets the data for a previously added curve. Data is provided as a vectors of pairs. The pairs represent x/y coordinates of the points that define the curve.

Parameters
curveIdthe id of the curve for which data should be added.
datathe coordinates of the points that define the curve
Returns
whether data was added successfully or not

◆ SetCurvePen()

void QmitkPlotWidget::SetCurvePen ( unsigned int  curveId,
const QPen &  pen 
)

Defines how a curve should be drawn. For drawing a curve, a QPen is used.

Parameters
curveIdthe id of the curve for which appearance should be changed
pena QPen (
See also
QPen) defining the line style

◆ SetCurveStyle()

void QmitkPlotWidget::SetCurveStyle ( unsigned int  curveId,
const QwtPlotCurve::CurveStyle  style 
)

Sets the style how the line is drawn for the curve; like, plain line, or with the data points marked with a symbol;

Parameters
curveId
styleA QwtPlotCurve::CurveStyle

◆ SetCurveSymbol()

void QmitkPlotWidget::SetCurveSymbol ( unsigned int  curveId,
QwtSymbol *  symbol 
)

Sets the style data points are drawn for the curve; like, a line, or dots;

Parameters
curveId
symbolA QwtSymbol

◆ SetCurveTitle()

void QmitkPlotWidget::SetCurveTitle ( unsigned int  curveId,
const char *  title 
)

Sets the title of the given curve. The title will be shown in the legend of the QwtPlot.

Parameters
curveIdthe id of the curve for which the title should be set
titlethe description of the curve that will be shown in the legend.

◆ SetErrorPen()

void QmitkPlotWidget::SetErrorPen ( unsigned int  curveId,
const QPen &  pen 
)

Defines how a curves errors should be drawn. For drawing a QPen is used.

Parameters
curveIdthe id of the curve for which error appearance should be changed
pena QPen (
See also
QPen) defining the line style

◆ SetErrorStyleSymbols()

void QmitkPlotWidget::SetErrorStyleSymbols ( unsigned int  curveId,
bool  drawSmybols 
)

Defines the style of errors, symbols or as a curve.

Parameters
curveIdthe id of the curve for which error appearance should be changed
drawSmybolstrue - draw symbols, false - draw curve

◆ SetLegend()

void QmitkPlotWidget::SetLegend ( QwtLegend *  legend,
QwtPlot::LegendPosition  pos = QwtPlot::RightLegend,
double  ratio = -1 
)

Sets the legend of the plot

◆ SetLegendAttribute()

void QmitkPlotWidget::SetLegendAttribute ( unsigned int  curveId,
const QwtPlotCurve::LegendAttribute &  attribute 
)

Set a curve's legend attribute

Parameters
curveIdthe id of the curve
attributethe legend attribute to be set

◆ SetPlotTitle() [1/2]

void QmitkPlotWidget::SetPlotTitle ( const char *  title)

Set plain text title, using default formatting

◆ SetPlotTitle() [2/2]

void QmitkPlotWidget::SetPlotTitle ( const QwtText &  qwt_title)

Set the title using (formatted) QwtText object

Member Data Documentation

◆ m_Plot

QwtPlot* QmitkPlotWidget::m_Plot
protected

Definition at line 297 of file QmitkPlotWidget.h.

◆ m_PlotCurveVector

std::vector<std::tuple<QwtPlotCurve *, QwtPlotIntervalCurve *, QwtPlotIntervalCurve *> > QmitkPlotWidget::m_PlotCurveVector
protected

Definition at line 298 of file QmitkPlotWidget.h.


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