Medical Imaging Interaction Toolkit  2016.11.0
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=nullptr)
 
virtual ~QmitkPlotWidget ()
 
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

Definition at line 56 of file QmitkPlotWidget.h.

Member Typedef Documentation

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 74 of file QmitkPlotWidget.h.

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 67 of file QmitkPlotWidget.h.

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 80 of file QmitkPlotWidget.h.

Constructor & Destructor Documentation

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

Standard qt constructor

Definition at line 25 of file QmitkPlotWidget.cpp.

References m_Plot.

QmitkPlotWidget::~QmitkPlotWidget ( )
virtual

Virtual destructor

Definition at line 34 of file QmitkPlotWidget.cpp.

References Clear(), and m_Plot.

Member Function Documentation

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
xValuesVector of x values an error bar belongs to
valuesThe original data value
lessErrorError in the negative direction (value - lessError)
moreErrorError in the positive direction (value + lessError)
isXErrorShould the error bars be drawn horizontally

Definition at line 265 of file QmitkPlotWidget.cpp.

References m_PlotCurveVector.

Referenced by SetCurveData().

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.

Definition at line 237 of file QmitkPlotWidget.cpp.

Referenced by SetCurveData().

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.

Definition at line 245 of file QmitkPlotWidget.cpp.

QwtPlot * QmitkPlotWidget::GetPlot ( )

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

Definition at line 40 of file QmitkPlotWidget.cpp.

References m_Plot.

Referenced by QmitkPlotDialog::GetQwtPlot().

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
Returns
the id of the curve. Use this id to refer to the curve, if you want to modify or add data.

Definition at line 55 of file QmitkPlotWidget.cpp.

References m_Plot, and m_PlotCurveVector.

Referenced by QmitkResidualAnalysisWidget::DrawMeans(), QmitkResidualAnalysisWidget::DrawPercentagesOfOutliers(), QmitkTbssRoiAnalysisWidget::Plot(), QmitkTbssRoiAnalysisWidget::PlotFiberBundles(), QmitkKurtosisWidget::SetData(), QmitkODFDetailsWidget::SetParameters(), QmitkIVIMWidget::SetParameters(), and QmitkPartialVolumeAnalysisWidget::SetParameters().

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.

Definition at line 90 of file QmitkPlotWidget.cpp.

References m_Plot.

void QmitkPlotWidget::SetCurveAntialiasingOff ( unsigned int  curveId)

Definition at line 186 of file QmitkPlotWidget.cpp.

References m_PlotCurveVector.

void QmitkPlotWidget::SetCurveAntialiasingOn ( unsigned int  curveId)
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

Definition at line 159 of file QmitkPlotWidget.cpp.

References m_PlotCurveVector.

Referenced by QmitkPartialVolumeAnalysisWidget::SetParameters().

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

Definition at line 95 of file QmitkPlotWidget.cpp.

References ConvertToRawArray(), and m_PlotCurveVector.

Referenced by QmitkResidualAnalysisWidget::DrawMeans(), QmitkResidualAnalysisWidget::DrawPercentagesOfOutliers(), QmitkTbssRoiAnalysisWidget::Plot(), QmitkTbssRoiAnalysisWidget::PlotFiberBundles(), SetCurveData(), QmitkKurtosisWidget::SetData(), QmitkODFDetailsWidget::SetParameters(), QmitkIVIMWidget::SetParameters(), and QmitkPartialVolumeAnalysisWidget::SetParameters().

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

Definition at line 113 of file QmitkPlotWidget.cpp.

References AddErrorIntervalCurve(), and SetCurveData().

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

Definition at line 126 of file QmitkPlotWidget.cpp.

References AddErrorIntervalCurve(), and SetCurveData().

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

Definition at line 142 of file QmitkPlotWidget.cpp.

References ConvertToRawArray(), and m_PlotCurveVector.

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

Definition at line 153 of file QmitkPlotWidget.cpp.

References m_PlotCurveVector.

Referenced by QmitkResidualAnalysisWidget::DrawMeans(), QmitkResidualAnalysisWidget::DrawPercentagesOfOutliers(), QmitkTbssRoiAnalysisWidget::Plot(), QmitkTbssRoiAnalysisWidget::PlotFiberBundles(), QmitkKurtosisWidget::SetData(), QmitkODFDetailsWidget::SetParameters(), QmitkIVIMWidget::SetParameters(), and QmitkPartialVolumeAnalysisWidget::SetParameters().

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

Definition at line 170 of file QmitkPlotWidget.cpp.

References m_PlotCurveVector.

Referenced by QmitkResidualAnalysisWidget::DrawMeans().

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

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

Parameters

Definition at line 175 of file QmitkPlotWidget.cpp.

References m_PlotCurveVector.

Referenced by QmitkKurtosisWidget::SetData(), and QmitkIVIMWidget::SetParameters().

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.

Definition at line 165 of file QmitkPlotWidget.cpp.

References m_Plot.

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

Definition at line 191 of file QmitkPlotWidget.cpp.

References m_PlotCurveVector.

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

Definition at line 203 of file QmitkPlotWidget.cpp.

References m_PlotCurveVector.

void QmitkPlotWidget::SetLegend ( QwtLegend *  legend,
QwtPlot::LegendPosition  pos = QwtPlot::RightLegend,
double  ratio = -1 
)
void QmitkPlotWidget::SetLegendAttribute ( unsigned int  curveId,
const QwtPlotCurve::LegendAttribute &  attribute 
)

Set a curve's legend attribute

Parameters
curveIdthe id of the curve
attributethe öegend attribute to be set

Definition at line 50 of file QmitkPlotWidget.cpp.

References m_PlotCurveVector.

void QmitkPlotWidget::SetPlotTitle ( const QwtText &  qwt_title)
void QmitkPlotWidget::SetPlotTitle ( const char *  title)

Set plain text title, using default formatting

Definition at line 84 of file QmitkPlotWidget.cpp.

References SetPlotTitle().

Member Data Documentation

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

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