#include <QmitkPlotWidget.h>
Public Types | |
typedef double | ScalarType |
typedef std::vector< ScalarType > | DataVector |
typedef std::vector< std::pair < double, double > > | XYDataVector |
Public Member Functions | |
QmitkPlotWidget (QWidget *parent=0, const char *title=0, const char *name=0, Qt::WindowFlags f=0) | |
virtual | ~QmitkPlotWidget () |
QwtPlot * | GetPlot () |
void | SetPlotTitle (const char *title) |
unsigned int | InsertCurve (const char *title) |
void | SetAxisTitle (int axis, const char *title) |
bool | SetCurveData (unsigned int curveId, const DataVector &xValues, const DataVector &yValues) |
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 | SetCurveTitle (unsigned int curveId, const char *title) |
void | Replot () |
void | Clear () |
Protected Member Functions | |
double * | ConvertToRawArray (const DataVector &values) |
double * | ConvertToRawArray (const XYDataVector &values, unsigned int component) |
Protected Attributes | |
QwtPlot * | m_Plot |
std::vector< QwtPlotCurve * > | m_PlotCurveVector |
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.
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().
Definition at line 54 of file QmitkPlotWidget.h.
typedef std::vector<ScalarType> QmitkPlotWidget::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 70 of file QmitkPlotWidget.h.
typedef double QmitkPlotWidget::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 63 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 76 of file QmitkPlotWidget.h.
QmitkPlotWidget::QmitkPlotWidget | ( | QWidget * | parent = 0 , |
const char * | title = 0 , |
||
const char * | name = 0 , |
||
Qt::WindowFlags | f = 0 |
||
) |
Standard qt constructor
Definition at line 23 of file QmitkPlotWidget.cpp.
References m_Plot, and QwtPlot::setCanvasBackground().
QmitkPlotWidget::~QmitkPlotWidget | ( | ) | [virtual] |
void QmitkPlotWidget::Clear | ( | ) |
Resets the plot into an empty state
Definition at line 123 of file QmitkPlotWidget.cpp.
References QwtPlot::clear(), m_Plot, and m_PlotCurveVector.
Referenced by ~QmitkPlotWidget().
{ m_PlotCurveVector.clear(); m_PlotCurveVector.resize(0); m_Plot->clear(); }
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 131 of file QmitkPlotWidget.cpp.
Referenced by SetCurveData().
{ double* raw = new double[ values.size() ]; for( unsigned int i = 0; i < values.size(); ++i ) raw[i] = values[i]; return raw; }
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.
values | the x/y values to convert to an array |
component | defines 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 140 of file QmitkPlotWidget.cpp.
{ double* raw = new double[ values.size() ]; for( unsigned int i = 0; i < values.size(); ++i ) { switch (component) { case (0): raw[i] = values[i].first; break; case (1): raw[i] = values[i].second; break; default: std::cout << "Component must be either 0 or 1."<< std::endl; } } return raw; }
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 39 of file QmitkPlotWidget.cpp.
References m_Plot.
Referenced by QmitkPlotDialog::GetQwtPlot().
{ return m_Plot; }
unsigned int QmitkPlotWidget::InsertCurve | ( | const char * | title ) |
Inserts a new curve into the plot-window.
title | the name of the curve |
Definition at line 45 of file QmitkPlotWidget.cpp.
References QwtPlotItem::attach(), m_Plot, and m_PlotCurveVector.
Referenced by QmitkIGTExampleView::OnShowErrorPlot().
{ QwtPlotCurve* curve = new QwtPlotCurve(QwtText(title)); m_PlotCurveVector.push_back(curve); curve->attach(m_Plot); return static_cast<unsigned int> (m_PlotCurveVector.size() - 1); }
void QmitkPlotWidget::Replot | ( | ) |
Triggers a replot of the curve. Replot should be called once after setting new data.
Definition at line 117 of file QmitkPlotWidget.cpp.
References m_Plot, and QwtPlot::replot().
Referenced by QmitkIGTExampleView::OnErrorValueChanged().
void QmitkPlotWidget::SetAxisTitle | ( | int | axis, |
const char * | title | ||
) |
Sets the title of the given axis. For the set of available axes
axis | the axis for which the description should be set. |
title | the name of the axis. |
Definition at line 58 of file QmitkPlotWidget.cpp.
References m_Plot, and QwtPlot::setAxisTitle().
Referenced by QmitkIGTExampleView::OnShowErrorPlot().
{ m_Plot->setAxisTitle(axis, title); }
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).
curveId | the id of the curve for which appearance should be changed |
brush | a QBrush ( |
Definition at line 96 of file QmitkPlotWidget.cpp.
References m_PlotCurveVector.
{ m_PlotCurveVector[curveId]->setBrush( brush ); }
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.
curveId | the id of the curve for which data should be added. |
xValues | the x coordinates of the points that define the curve |
yValues | the y coordinates of the points that define the curve |
Definition at line 64 of file QmitkPlotWidget.cpp.
References ConvertToRawArray(), and m_PlotCurveVector.
Referenced by QmitkIGTExampleView::OnErrorValueChanged().
{ if ( xValues.size() != yValues.size() ) { std::cerr << "Sizes of data arrays don't match." << std::endl; return false; } double* rawDataX = ConvertToRawArray( xValues ); double* rawDataY = ConvertToRawArray( yValues ); m_PlotCurveVector[curveId]->setData( rawDataX, rawDataY, static_cast<int>(xValues.size()) ); delete[] rawDataX; delete[] rawDataY; return true; }
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.
curveId | the id of the curve for which data should be added. |
data | the coordinates of the points that define the curve |
Definition at line 80 of file QmitkPlotWidget.cpp.
References ConvertToRawArray(), and m_PlotCurveVector.
{ double* rawDataX = ConvertToRawArray( data, 0 ); double* rawDataY = ConvertToRawArray( data, 1 ); m_PlotCurveVector[curveId]->setData( rawDataX, rawDataY, static_cast<int>(data.size()) ); delete[] rawDataX; delete[] rawDataY; return true; }
void QmitkPlotWidget::SetCurvePen | ( | unsigned int | curveId, |
const QPen & | pen | ||
) |
Defines how a curve should be drawn. For drawing a curve, a QPen is used.
curveId | the id of the curve for which appearance should be changed |
pen | a QPen ( |
Definition at line 90 of file QmitkPlotWidget.cpp.
References m_PlotCurveVector.
Referenced by QmitkIGTExampleView::OnShowErrorPlot().
{ m_PlotCurveVector[curveId]->setPen( pen ); }
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;
style A QwtPlotCurve::CurveStyle |
Definition at line 107 of file QmitkPlotWidget.cpp.
References m_PlotCurveVector.
{ m_PlotCurveVector[curveId]->setStyle(style); }
void QmitkPlotWidget::SetCurveSymbol | ( | unsigned int | curveId, |
QwtSymbol * | symbol | ||
) |
Sets the style data points are drawn for the curve; like, a line, or dots;
symbol A QwtSymbol |
Definition at line 112 of file QmitkPlotWidget.cpp.
References m_PlotCurveVector.
{ m_PlotCurveVector[curveId]->setSymbol(*symbol); }
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.
curveId | the id of the curve for which the title should be set |
title | the description of the curve that will be shown in the legend. |
Definition at line 102 of file QmitkPlotWidget.cpp.
References m_Plot, and QwtPlot::setTitle().
void QmitkPlotWidget::SetPlotTitle | ( | const char * | title ) |
Definition at line 53 of file QmitkPlotWidget.cpp.
References m_Plot, and QwtPlot::setTitle().
Referenced by QmitkIGTExampleView::OnShowErrorPlot().
QwtPlot* QmitkPlotWidget::m_Plot [protected] |
Definition at line 199 of file QmitkPlotWidget.h.
Referenced by Clear(), GetPlot(), InsertCurve(), QmitkPlotWidget(), Replot(), SetAxisTitle(), SetCurveTitle(), SetPlotTitle(), and ~QmitkPlotWidget().
std::vector<QwtPlotCurve*> QmitkPlotWidget::m_PlotCurveVector [protected] |
Definition at line 200 of file QmitkPlotWidget.h.
Referenced by Clear(), InsertCurve(), SetCurveBrush(), SetCurveData(), SetCurvePen(), SetCurveStyle(), and SetCurveSymbol().