Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkKurtosisWidget.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "QmitkKurtosisWidget.h"
18 
19 #include <qwt_scale_engine.h>
20 #include <qwt_legend.h>
21 
23  : QmitkPlotWidget(parent)
24 {
25  QFrame* canvas = qobject_cast< QFrame* >( m_Plot->canvas() );
26  if( canvas )
27  {
28  canvas->setLineWidth(0);
29  canvas->setContentsMargins(0, 0, 0, 0);
30  }
31 
32 }
33 
35 {
36 
37 }
38 
39 
41 {
42  this->Clear();
43 
44  if( snap.bvalues.empty() )
45  return;
46 
47  double max_y_val = 1.4 * fmax( snap.measurements[0], snap.m_BzeroFit );
48 
49  auto logScale = new QwtLogScaleEngine();
50  m_Plot->setAxisScaleEngine(0, logScale );
51  m_Plot->setAxisScale(0, 0.1, max_y_val );
52 
53  QString s("D=%1, K=%2");
54  s = s.arg( snap.m_D, 4); s = s.arg( snap.m_K, 4);
55 
56  // insert formatted value string to legend (curve without pen)
57  int curveId = this->InsertCurve( s.toLatin1(), QColor( Qt::black ) );
58  this->SetCurvePen( curveId, QPen( Qt::NoPen ) );
59 
60  QPen pen;
61  pen.setColor( QColor( Qt::red ));
62  pen.setWidth(2);
63  pen.setStyle( Qt::PenStyle::DashLine );
64 
65  // get the x-axis maximum
66  const double max_bvalue = snap.bvalues.max_value();
67 
68  //
69  // Data-points
70  //
71  auto measured_values = toStdVec( snap.measurements );
72  double y_bzero = measured_values[0];
73 
74  if( snap.m_fittedBZero )
75  {
76  /*auto c_measurements_curve = this->InsertCurve( "Corrected measured values with fitted b=0" );
77  this->SetCurveData( c_measurements_curve, toStdVec( snap.fit_bvalues ), toStdVec( snap.fit_measurements / snap.m_BzeroFit ) );
78  this->SetCurvePen( c_measurements_curve, QPen(Qt::NoPen) );
79  QwtSymbol* whiteDiamond = new QwtSymbol(QwtSymbol::Diamond, QColor(Qt::white), QColor(Qt::black), QSize(8,8));
80  this->SetCurveSymbol( c_measurements_curve, whiteDiamond );*/
81 
82  std::vector<double> single_bzero;
83  single_bzero.push_back(0);
84 
85  std::vector<double> fitted_bzero;
86  fitted_bzero.push_back( snap.m_BzeroFit );
87 
88  auto c_measurements_bzero = this->InsertCurve( "Fitted b=0" );
89  this->SetCurveData( c_measurements_bzero, single_bzero, fitted_bzero );
90  this->SetCurvePen( c_measurements_bzero, QPen(Qt::NoPen) );
91  QwtSymbol* blackDiamond = new QwtSymbol(QwtSymbol::Diamond, QColor(Qt::black), QColor(Qt::black), QSize(8,8));
92  this->SetCurveSymbol( c_measurements_bzero, blackDiamond );
93 
94  y_bzero = snap.m_BzeroFit;
95 
96  MITK_DEBUG("Kurtosis.Widget.Bzero") << "[Fitted] " << snap.m_BzeroFit << ": [Measured] " << snap.measurements[0];
97  }
98 
99 
100  auto measurements_curve = this->InsertCurve( "Measured values" );
101  this->SetCurveData( measurements_curve, toStdVec( snap.bvalues ), measured_values );
102  this->SetCurvePen( measurements_curve, QPen(Qt::NoPen) );
103  QwtSymbol* redDiamond = new QwtSymbol(QwtSymbol::Diamond, QColor(Qt::red), QColor(Qt::red), QSize(8,8));
104  this->SetCurveSymbol( measurements_curve, redDiamond );
105 
106  //
107  // Kurtosis - full modelled signal
108  //
109  pen.setColor( QColor( Qt::black ));
110  pen.setStyle( Qt::SolidLine );
111  const unsigned int num_samples = 50;
112 
113  vnl_vector<double> x_K_model(num_samples);
114  vnl_vector<double> y_K_model(num_samples);
115 
116  vnl_vector<double> y_D_model(num_samples);
117 
118  const double x_tics_offset = max_bvalue / static_cast<double>( num_samples );
119 
120  for( unsigned int i=0; i<num_samples; ++i)
121  {
122  x_K_model[i] = i * x_tics_offset;
123 
124  double bval = x_K_model[i];
125  y_K_model[i] = y_bzero * exp( -bval * snap.m_D + bval*bval * snap.m_D * snap.m_D * snap.m_K / 6.0 );
126  y_D_model[i] = y_bzero * exp( -bval * snap.m_D );
127  }
128 
129  auto kurtosis_curve = this->InsertCurve( "Resulting fit of the model" );
130  this->SetCurveData( kurtosis_curve, toStdVec( x_K_model ), toStdVec( y_K_model ) );
131  this->SetCurvePen( kurtosis_curve, pen );
132  this->SetCurveAntialiasingOn( kurtosis_curve );
133 
134  auto d_curve = this->InsertCurve( "D-part of the fitted model" );
135  this->SetCurveData( d_curve, toStdVec( x_K_model ), toStdVec( y_D_model ) );
136 
137  pen.setColor( QColor( Qt::red));
138  pen.setStyle( Qt::PenStyle::DashLine );
139  this->SetCurvePen( d_curve, pen );
140  this->SetCurveAntialiasingOn( d_curve );
141 
142  //
143  // add Legend
144  //
145  auto legend = new QwtLegend();
146  legend->setMaxColumns(3);
147  m_Plot->insertLegend( legend, QwtPlot::BottomLegend );
148 
149  this->Replot();
150 }
151 
152 std::vector<double> QmitkKurtosisWidget::toStdVec(const vnl_vector<double>& vector)
153 {
154  std::vector<double> retval(vector.size());
155  for(unsigned int i=0; i<vector.size(); i++)
156  {
157  retval.at(i) = vector[i];
158  }
159  return retval;
160 }
161 
#define MITK_DEBUG
Definition: mitkLogMacros.h:26
void SetCurveSymbol(unsigned int curveId, QwtSymbol *symbol)
void SetCurveAntialiasingOn(unsigned int curveId)
void SetCurvePen(unsigned int curveId, const QPen &pen)
Struct describing a result (and the data) of a Kurtosis model fit.
unsigned int InsertCurve(const char *title, QColor color=QColor(Qt::black))
bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues)
void SetData(KurtosisFilterType::KurtosisSnapshot snap)