Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkPlotWidget.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef QmitkPlotWidget_h
14 #define QmitkPlotWidget_h
15 
17 #include <mitkCommon.h>
18 #include <QWidget>
19 #include <qwt_legend.h>
20 #include <qwt_plot.h>
21 #include <qwt_plot_curve.h>
22 #include <qwt_plot_intervalcurve.h>
23 #include <qwt_symbol.h>
24 #include <qwt_text.h>
25 #include <tuple>
26 #include <vector>
27 
51  : public QWidget
52  {
53 private:
54  Q_OBJECT
55 
56 public:
58  typedef double ScalarType;
59 
61  typedef std::vector<ScalarType> DataVector;
62 
64  typedef std::vector<std::pair<double, double>> XYDataVector;
65 
73  QmitkPlotWidget(QWidget *parent = nullptr,
74  const char *title = nullptr,
75  const char *name = nullptr,
76  Qt::WindowFlags f = {});
77 
79  ~QmitkPlotWidget() override;
80 
85  QwtPlot *GetPlot();
86 
91  void SetPlotTitle(const QwtText &qwt_title);
92 
97  void SetPlotTitle(const char *title);
98 
105  unsigned int InsertCurve(const char *title, QColor color = QColor(Qt::black));
106 
112  void SetAxisTitle(int axis, const char *title);
113 
122  bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues);
123 
133  bool SetCurveData(unsigned int curveId,
134  const DataVector &xValues,
135  const DataVector &yValues,
136  const DataVector &yLowerError,
137  const DataVector &yUpperError);
138 
150  bool SetCurveData(unsigned int curveId,
151  const DataVector &xValues,
152  const DataVector &yValues,
153  const DataVector &xLowerError,
154  const DataVector &xUpperError,
155  const DataVector &yLowerError,
156  const DataVector &yUpperError);
157 
164  bool SetCurveData(unsigned int curveId, const XYDataVector &data);
165 
171  void SetCurvePen(unsigned int curveId, const QPen &pen);
172 
182  void SetCurveBrush(unsigned int curveId, const QBrush &brush);
183 
189  void SetCurveStyle(unsigned int curveId, const QwtPlotCurve::CurveStyle style);
190 
196  void SetCurveSymbol(unsigned int curveId, QwtSymbol *symbol);
197 
202  void SetCurveAntialiasingOn(unsigned int curveId);
203 
208  void SetCurveAntialiasingOff(unsigned int curveId);
209 
215  void SetCurveTitle(unsigned int curveId, const char *title);
216 
222  void SetErrorPen(unsigned int curveId, const QPen &pen);
223 
229  void SetErrorStyleSymbols(unsigned int curveId, bool drawSmybols);
230 
237  void SetLegend(QwtLegend *legend, QwtPlot::LegendPosition pos = QwtPlot::RightLegend, double ratio = -1);
238 
244  void SetLegendAttribute(unsigned int curveId, const QwtPlotCurve::LegendAttribute &attribute);
245 
247  void Replot();
248 
250  void Clear();
251 
252 protected:
257  double *ConvertToRawArray(const DataVector &values);
258 
266  double *ConvertToRawArray(const XYDataVector &values, unsigned int component);
267 
278  bool AddErrorIntervalCurve(unsigned int curveId,
279  const DataVector &lessError,
280  const DataVector &moreError,
281  bool isXError);
282 
283  QwtPlot *m_Plot;
284  std::vector<std::tuple<QwtPlotCurve *, QwtPlotIntervalCurve *, QwtPlotIntervalCurve *>> m_PlotCurveVector;
285 };
286 
287 #endif
#define MITKQTWIDGETSEXT_EXPORT
Convenience widget providing a high-level interface for plotting curves using Qwt.
bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues)
Set curve data from separate x and y vectors.
void SetCurvePen(unsigned int curveId, const QPen &pen)
Set the pen (line style) for a curve.
double * ConvertToRawArray(const XYDataVector &values, unsigned int component)
std::vector< ScalarType > DataVector
Vector of scalar values representing x or y coordinates.
std::vector< std::tuple< QwtPlotCurve *, QwtPlotIntervalCurve *, QwtPlotIntervalCurve * > > m_PlotCurveVector
bool SetCurveData(unsigned int curveId, const XYDataVector &data)
Set curve data from a vector of (x, y) pairs.
unsigned int InsertCurve(const char *title, QColor color=QColor(Qt::black))
Insert a new curve into the plot.
void SetCurveTitle(unsigned int curveId, const char *title)
Set the title of a curve (shown in the plot title, not legend).
void SetCurveStyle(unsigned int curveId, const QwtPlotCurve::CurveStyle style)
Set the curve drawing style (lines, sticks, dots, etc.).
std::vector< std::pair< double, double > > XYDataVector
Vector of (x, y) pairs representing curve data points.
void SetCurveAntialiasingOn(unsigned int curveId)
Enable antialiasing for a curve.
double * ConvertToRawArray(const DataVector &values)
void SetAxisTitle(int axis, const char *title)
Set the title of an axis.
void Clear()
Clear all curves and reset the plot to an empty state.
double ScalarType
Scalar type used for data values (double, defined by Qwt).
void SetCurveBrush(unsigned int curveId, const QBrush &brush)
Set the brush (fill pattern) for a curve.
bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues, const DataVector &xLowerError, const DataVector &xUpperError, const DataVector &yLowerError, const DataVector &yUpperError)
Set curve data with both x and y error bars.
void SetErrorPen(unsigned int curveId, const QPen &pen)
Set the pen for drawing error bars.
QwtPlot * GetPlot()
Get the underlying QwtPlot instance for low-level customization.
void SetLegendAttribute(unsigned int curveId, const QwtPlotCurve::LegendAttribute &attribute)
Set a legend attribute for a curve.
void Replot()
Trigger a replot. Call after setting new data or changing appearance.
void SetCurveSymbol(unsigned int curveId, QwtSymbol *symbol)
Set the symbol used for drawing data points.
QmitkPlotWidget(QWidget *parent=nullptr, const char *title=nullptr, const char *name=nullptr, Qt::WindowFlags f={})
Construct the plot widget.
void SetErrorStyleSymbols(unsigned int curveId, bool drawSmybols)
Set error bar drawing style.
bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues, const DataVector &yLowerError, const DataVector &yUpperError)
Set curve data with y-axis error bars.
void SetPlotTitle(const char *title)
Set the plot title using plain text.
void SetCurveAntialiasingOff(unsigned int curveId)
Disable antialiasing for a curve.
void SetPlotTitle(const QwtText &qwt_title)
Set the plot title using a formatted QwtText.
void SetLegend(QwtLegend *legend, QwtPlot::LegendPosition pos=QwtPlot::RightLegend, double ratio=-1)
Set the plot legend.
bool AddErrorIntervalCurve(unsigned int curveId, const DataVector &lessError, const DataVector &moreError, bool isXError)
~QmitkPlotWidget() override
Destructor. Clears all curves and deletes the plot.