diff --git a/Modules/QmitkExt/QmitkPlotWidget.cpp b/Modules/QmitkExt/QmitkPlotWidget.cpp index d6cc46073e..1578eabddb 100644 --- a/Modules/QmitkExt/QmitkPlotWidget.cpp +++ b/Modules/QmitkExt/QmitkPlotWidget.cpp @@ -1,169 +1,164 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include "QmitkPlotWidget.h" QmitkPlotWidget::QmitkPlotWidget(QWidget* parent, const char* title, const char* /*name*/, Qt::WindowFlags f) : QWidget(parent, f) - , m_SeriesData(NULL) { QVBoxLayout* boxLayout = new QVBoxLayout(this); m_Plot = new QwtPlot( QwtText(title), this ) ; m_Plot->setCanvasBackground(Qt::white); boxLayout->addWidget( m_Plot ); } QmitkPlotWidget::~QmitkPlotWidget() { this->Clear(); delete m_Plot; - delete m_SeriesData; } QwtPlot* QmitkPlotWidget::GetPlot() { return m_Plot; } void QmitkPlotWidget::SetLegend(QwtLegend* legend, QwtPlot::LegendPosition pos, double ratio) { m_Plot->insertLegend(legend, pos, ratio); } unsigned int QmitkPlotWidget::InsertCurve(const char* title) { QwtPlotCurve* curve = new QwtPlotCurve(QwtText(title)); m_PlotCurveVector.push_back(curve); curve->attach(m_Plot); return static_cast (m_PlotCurveVector.size() - 1); } void QmitkPlotWidget::SetPlotTitle(const char* title) { m_Plot->setTitle(title); } void QmitkPlotWidget::SetAxisTitle(int axis, const char* title) { m_Plot->setAxisTitle(axis, title); } bool QmitkPlotWidget::SetCurveData( unsigned int curveId, const QmitkPlotWidget::DataVector& xValues, const QmitkPlotWidget::DataVector& yValues ) { 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 ); - delete m_SeriesData; - m_SeriesData = new QwtPointArrayData(rawDataX, rawDataY, static_cast(xValues.size())); - m_PlotCurveVector[curveId]->setSamples(m_SeriesData); + m_PlotCurveVector[curveId]->setSamples(new QwtPointArrayData(rawDataX, rawDataY, static_cast(xValues.size()))); delete[] rawDataX; delete[] rawDataY; return true; } -bool QmitkPlotWidget::SetCurveData( unsigned int curveId, const QmitkPlotWidget::XYDataVector& data ) +bool QmitkPlotWidget::SetCurveData(unsigned int curveId, const XYDataVector& data ) { double* rawDataX = ConvertToRawArray( data, 0 ); double* rawDataY = ConvertToRawArray( data, 1 ); - delete m_SeriesData; - m_SeriesData = new QwtPointArrayData(rawDataX, rawDataY, static_cast(data.size())); - m_PlotCurveVector[curveId]->setData(m_SeriesData); + m_PlotCurveVector[curveId]->setData(new QwtPointArrayData(rawDataX, rawDataY, static_cast(data.size()))); delete[] rawDataX; delete[] rawDataY; return true; } void QmitkPlotWidget::SetCurvePen( unsigned int curveId, const QPen& pen ) { m_PlotCurveVector[curveId]->setPen( pen ); } void QmitkPlotWidget::SetCurveBrush( unsigned int curveId, const QBrush& brush ) { m_PlotCurveVector[curveId]->setBrush( brush ); } void QmitkPlotWidget::SetCurveTitle( unsigned int /*curveId*/, const char* title ) { m_Plot->setTitle( title ); } void QmitkPlotWidget::SetCurveStyle( unsigned int curveId, const QwtPlotCurve::CurveStyle style ) { m_PlotCurveVector[curveId]->setStyle(style); } void QmitkPlotWidget::SetCurveSymbol( unsigned int curveId, QwtSymbol* symbol ) { m_PlotCurveVector[curveId]->setSymbol(symbol); } void QmitkPlotWidget::Replot() { m_Plot->replot(); } void QmitkPlotWidget::Clear() { + m_Plot->detachItems(); m_PlotCurveVector.clear(); m_PlotCurveVector.resize(0); - m_Plot->detachItems(); + } double* QmitkPlotWidget::ConvertToRawArray( const QmitkPlotWidget::DataVector& values ) { 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 QmitkPlotWidget::XYDataVector& values, unsigned int component ) { 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; } diff --git a/Modules/QmitkExt/QmitkPlotWidget.h b/Modules/QmitkExt/QmitkPlotWidget.h index 851eada908..38f9e108db 100644 --- a/Modules/QmitkExt/QmitkPlotWidget.h +++ b/Modules/QmitkExt/QmitkPlotWidget.h @@ -1,218 +1,216 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _QmitkPlotWidget_H_ #define _QmitkPlotWidget_H_ #include #include "QmitkExtExports.h" #include #include #include #include "mitkCommon.h" #include #include /** * 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 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. 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 QwtPlot */ class QmitkExt_EXPORT QmitkPlotWidget: public QWidget { private: Q_OBJECT public: /** * represents the data type used for scalar values stored * in data arrays. This type is provided by qwt and may not * be changed. */ typedef double ScalarType; /** * 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. */ typedef std::vector DataVector; /** * convenience type used to store pairs representing x/y coordinates * that should be rendered as a curve by the plot widget */ typedef std::vector< std::pair< double, double > > XYDataVector; /** * Standard qt constructor */ QmitkPlotWidget(QWidget* parent = 0,const char* title = 0, const char* name = 0, Qt::WindowFlags f = 0); /** * Virtual destructor */ virtual ~QmitkPlotWidget(); /** * Returns the instance of the plot-widget. This may be used * to modify any detail of the appearance of the plot. */ QwtPlot* GetPlot(); void SetPlotTitle(const char* title); /** * Inserts a new curve into the plot-window. * @param title the 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. */ unsigned int InsertCurve( const char* title ); /** * Sets the title of the given axis. For the set of available axes * @see QwtPlot::Axis. * @param axis the axis for which the description should be set. * @param title the name of the axis. */ void SetAxisTitle(int axis, const char* title); /** * 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. * @param curveId the id of the curve for which data should be added. * @param xValues the x coordinates of the points that define the curve * @param yValues the y coordinates of the points that define the curve * @returns whether data was added successfully or not */ bool SetCurveData( unsigned int curveId, const DataVector& xValues, const DataVector& yValues ); /** * 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. * @param curveId the id of the curve for which data should be added. * @param data the coordinates of the points that define the curve * @returns whether data was added successfully or not */ bool SetCurveData( unsigned int curveId, const XYDataVector& data ); /** * Defines how a curve should be drawn. For drawing a curve, a QPen is used. * @param curveId the id of the curve for which appearance should be changed * @param pen a QPen (@see QPen) defining the line style */ void SetCurvePen( unsigned int curveId, const QPen& pen ); /** * 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). * @param curveId the id of the curve for which appearance should be changed * @param brush a QBrush (@see QBrush) defining the line style */ void SetCurveBrush( unsigned int curveId, const QBrush& brush); /** * Sets the style how the line is drawn for the curve; like, plain line, * or with the data points marked with a symbol; * @param: style A QwtPlotCurve::CurveStyle */ void SetCurveStyle( unsigned int curveId, const QwtPlotCurve::CurveStyle style ); /** * Sets the style data points are drawn for the curve; like, a line, * or dots; * @param: symbol A QwtSymbol */ void SetCurveSymbol( unsigned int curveId, QwtSymbol* symbol ); /**m_Skeletonize * Sets the title of the given curve. The title will be shown in the legend of * the QwtPlot. * @param curveId the id of the curve for which the title should be set * @param title the description of the curve that will be shown in the legend. */ void SetCurveTitle( unsigned int curveId, const char* title ); /** * Sets the legend of the plot * */ void SetLegend(QwtLegend* legend, QwtPlot::LegendPosition pos=QwtPlot::RightLegend, double ratio=-1); /** m_Skeletonize * Triggers a replot of the curve. Replot should be called once after * setting new data. */ void Replot(); /** * Resets the plot into an empty state */ void Clear(); protected: /** * Converts the given values into a raw double* array. * A new array is allocated via new and must be deleted[] by the caller. */ double* ConvertToRawArray( const DataVector& values ); /** * Converts the given values into a raw double* array. * A new array is allocated via new and must be deleted[] by the caller. * @param values the x/y values to convert to an array * @param 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. */ double* ConvertToRawArray( const XYDataVector& values, unsigned int component ); QwtPlot* m_Plot; std::vector m_PlotCurveVector; - - QwtSeriesData* m_SeriesData; }; #endif diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/QmitkIVIMWidget.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging/src/QmitkIVIMWidget.cpp index 4cc6e9a0b6..cd3f7aa0b5 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/QmitkIVIMWidget.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/QmitkIVIMWidget.cpp @@ -1,150 +1,150 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkIVIMWidget.h" #include "mitkHistogramGenerator.h" #include #include QmitkIVIMWidget::QmitkIVIMWidget( QWidget * parent ) : QmitkPlotWidget(parent) { // this->SetAxisTitle( QwtPlot::xBottom, "Grayvalue" ); // this->SetAxisTitle( QwtPlot::yLeft, "Probability" ); // this->Replot(); QFrame* canvas = qobject_cast(m_Plot->canvas()); if (canvas) { canvas->setLineWidth(0); canvas->setContentsMargins(0,0,0,0); } QwtLogScaleEngine* logScale = new QwtLogScaleEngine(); m_Plot->setAxisScaleEngine(0, logScale); m_Plot->setAxisScale( 0, 0.15, 1.0 ); } QmitkIVIMWidget::~QmitkIVIMWidget() { } void QmitkIVIMWidget::DrawGauss() { } void QmitkIVIMWidget::ClearItemModel() { } -std::vector QmitkIVIMWidget::vec(vnl_vector vector) +std::vector QmitkIVIMWidget::vec(const vnl_vector& vector) { std::vector retval(vector.size()); for(unsigned int i=0; iClear(); if (snap.bvalues.empty()) return; QString s("f=%1, D=%2, D*=%3"); s = s.arg(snap.currentF,4); s = s.arg(snap.currentD,4); s = s.arg(snap.currentDStar,4); int curveId = this->InsertCurve( s.toAscii() ); this->SetCurvePen( curveId, QPen( Qt::NoPen ) ); curveId = this->InsertCurve( "ignored measurement points" ); this->SetCurveData( curveId, vec(snap.bvalues), vec(snap.allmeas) ); - this->SetCurvePen( curveId, QPen( Qt::NoPen ) ); - QwtSymbol whiteSymbol(QwtSymbol::Diamond, QColor(Qt::white), QColor(Qt::black), QSize(10,10)); - this->SetCurveSymbol(curveId, &whiteSymbol); + this->SetCurvePen( curveId, QPen(Qt::NoPen) ); + QwtSymbol* whiteSymbol = new QwtSymbol(QwtSymbol::Diamond, QColor(Qt::white), QColor(Qt::black), QSize(10,10)); + this->SetCurveSymbol(curveId, whiteSymbol); if(snap.currentDStar != 0) { curveId = this->InsertCurve( "additional points second fit" ); this->SetCurveData( curveId, vec(snap.bvals2), vec(snap.meas2) ); this->SetCurvePen( curveId, QPen( Qt::NoPen ) ); - QwtSymbol blackSymbol(QwtSymbol::Diamond, QColor(Qt::black), QColor(Qt::black), QSize(10,10)); - this->SetCurveSymbol(curveId, &blackSymbol); + QwtSymbol* blackSymbol = new QwtSymbol(QwtSymbol::Diamond, QColor(Qt::black), QColor(Qt::black), QSize(10,10)); + this->SetCurveSymbol(curveId, blackSymbol); } curveId = this->InsertCurve( "points first fit" ); this->SetCurveData( curveId, vec(snap.bvals1), vec(snap.meas1) ); this->SetCurvePen( curveId, QPen( Qt::NoPen ) ); - QwtSymbol redSymbol(QwtSymbol::Diamond, QColor(Qt::red), QColor(Qt::red), QSize(10,10)); - this->SetCurveSymbol(curveId, &redSymbol); + QwtSymbol* redSymbol = new QwtSymbol(QwtSymbol::Diamond, QColor(Qt::red), QColor(Qt::red), QSize(10,10)); + this->SetCurveSymbol(curveId, redSymbol); QPen pen; pen.setColor( QColor(Qt::red) ); pen.setWidth(2); double maxb = snap.bvalues.max_value(); vnl_vector xvals(2); vnl_vector yvals(2); xvals[0] = 0; xvals[1] = maxb; yvals[0] = 1-snap.currentFunceiled; yvals[1] = yvals[0]*exp(-maxb * snap.currentD); curveId = this->InsertCurve( "contribution of D to the signal" ); this->SetCurveData( curveId, vec(xvals), vec(yvals) ); this->SetCurvePen( curveId, pen ); if(snap.currentDStar != 0) { pen.setColor(Qt::black); int nsampling = 50; xvals.set_size(nsampling); yvals.set_size(nsampling); double f = 1-snap.currentFunceiled; for(int i=0; iInsertCurve( "resulting fit of the model" ); this->SetCurveData( curveId, vec(xvals), vec(yvals) ); this->SetCurvePen( curveId, pen ); } // QMargins margins; // margins.setBottom(0); // margins.setLeft(0); // margins.setRight(0); // margins.setTop(0); QwtLegend* legend = new QwtLegend(); // legend->setContentsMargins(margins); m_Plot->insertLegend(legend, QwtPlot::BottomLegend); this->Replot(); } diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/QmitkIVIMWidget.h b/Plugins/org.mitk.gui.qt.diffusionimaging/src/QmitkIVIMWidget.h index 144b6bd34d..f3da316d1c 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/QmitkIVIMWidget.h +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/QmitkIVIMWidget.h @@ -1,58 +1,58 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QmitkIVIMWidget_H_ #define QmitkIVIMWidget_H_ #include "QmitkPlotWidget.h" #include "mitkImage.h" #include "itkDiffusionIntravoxelIncoherentMotionReconstructionImageFilter.h" /** * \brief Widget for displaying image histograms based on the vtkQtChart * framework */ class QmitkIVIMWidget : public QmitkPlotWidget { public: typedef itk::DiffusionIntravoxelIncoherentMotionReconstructionImageFilter IVIMFilterType; typedef mitk::Image::HistogramType HistogramType; typedef mitk::Image::HistogramType::ConstIterator HistogramConstIteratorType; void SetParameters( IVIMFilterType::IVIMSnapshot snap ); QmitkIVIMWidget( QWidget * /*parent = 0 */); virtual ~QmitkIVIMWidget(); void DrawGauss(); void ClearItemModel(); std::vector< std::vector* > m_Vals; private: - std::vector vec(vnl_vector vector); + std::vector vec(const vnl_vector& vector); }; #endif /* QmitkIVIMWidget_H_ */