Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkIVIMWidget.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 "QmitkIVIMWidget.h"
18 
19 #include "mitkHistogramGenerator.h"
20 
21 
22 #include <qwt_scale_engine.h>
23 #include <qwt_legend.h>
24 
25 
27  : QmitkPlotWidget(parent)
28 {
29  // this->SetAxisTitle( QwtPlot::xBottom, "Grayvalue" );
30  // this->SetAxisTitle( QwtPlot::yLeft, "Probability" );
31  // this->Replot();
32  QFrame* canvas = qobject_cast<QFrame*>(m_Plot->canvas());
33  if (canvas)
34  {
35  canvas->setLineWidth(0);
36  canvas->setContentsMargins(0,0,0,0);
37  }
38 
39  auto logScale = new QwtLogScaleEngine();
40  m_Plot->setAxisScaleEngine(0, logScale);
41 
42  m_Plot->setAxisScale( 0, 0.15, 1.0 );
43 }
44 
45 
46 
48 {
49 }
50 
51 
53 {
54 
55 }
56 
57 
59 {
60 
61 }
62 
63 std::vector<double> QmitkIVIMWidget::vec(const vnl_vector<double>& vector)
64 {
65  std::vector<double> retval(vector.size());
66  for(unsigned int i=0; i<vector.size(); i++)
67  {
68  retval.at(i) = vector[i];
69  }
70  return retval;
71 }
72 
74 {
75  this->Clear();
76  if (snap.bvalues.empty())
77  return;
78 
79  QString s("f=%1, D=%2, D*=%3");
80  s = s.arg(snap.currentF,4);
81  s = s.arg(snap.currentD,4);
82  s = s.arg(snap.currentDStar,4);
83  int curveId = this->InsertCurve( s.toLatin1(), QColor(Qt::black) );
84  this->SetCurvePen( curveId, QPen( Qt::NoPen ) );
85 
86  QPen pen;
87  pen.setColor( QColor(Qt::red) );
88  pen.setWidth(2);
89  double maxb = snap.bvalues.max_value();
90  vnl_vector<double> xvals(2);
91  vnl_vector<double> yvals(2);
92  xvals[0] = 0;
93  xvals[1] = maxb;
94  yvals[0] = 1-snap.currentFunceiled;
95  yvals[1] = yvals[0]*exp(-maxb * snap.currentD);
96  curveId = this->InsertCurve( "contribution of D to the signal", pen.color() );
97  this->SetCurveData( curveId, vec(xvals), vec(yvals) );
98  this->SetCurvePen( curveId, pen );
99  this->SetCurveAntialiasingOn( curveId );
100 
101  if(snap.currentDStar != 0)
102  {
103  pen.setColor(Qt::black);
104  int nsampling = 50;
105  xvals.set_size(nsampling);
106  yvals.set_size(nsampling);
107  double f = 1-snap.currentFunceiled;
108  for(int i=0; i<nsampling; i++)
109  {
110  xvals[i] = (((1.0)*i)/(1.0*nsampling))*maxb;
111  yvals[i] = f*exp(- xvals[i] * snap.currentD) + (1-f)*exp(- xvals[i] * (snap.currentD+snap.currentDStar));
112  }
113  curveId = this->InsertCurve( "resulting fit of the model" );
114  this->SetCurveData( curveId, vec(xvals), vec(yvals) );
115  this->SetCurvePen( curveId, pen );
116  this->SetCurveAntialiasingOn( curveId );
117  }
118 
119  // plot points after all curves to force prettier legend formatting
120  // lines
121  // points
122  curveId = this->InsertCurve( "ignored measurement points" );
123  this->SetCurveData( curveId, vec(snap.bvalues), vec(snap.allmeas) );
124  this->SetCurvePen( curveId, QPen(Qt::NoPen) );
125  QwtSymbol* whiteSymbol = new QwtSymbol(QwtSymbol::Diamond, QColor(Qt::white), QColor(Qt::black), QSize(8,8));
126  this->SetCurveSymbol(curveId, whiteSymbol);
127 
128  curveId = this->InsertCurve( "points first fit" );
129  this->SetCurveData( curveId, vec(snap.bvals1), vec(snap.meas1) );
130  this->SetCurvePen( curveId, QPen( Qt::NoPen ) );
131  QwtSymbol* redSymbol = new QwtSymbol(QwtSymbol::Diamond, QColor(Qt::red), QColor(Qt::red), QSize(8,8));
132  this->SetCurveSymbol(curveId, redSymbol);
133 
134  if(snap.currentDStar != 0)
135  {
136  curveId = this->InsertCurve( "additional points second fit" );
137  this->SetCurveData( curveId, vec(snap.bvals2), vec(snap.meas2) );
138  this->SetCurvePen( curveId, QPen( Qt::NoPen ) );
139  QwtSymbol* blackSymbol = new QwtSymbol(QwtSymbol::Diamond, QColor(Qt::black), QColor(Qt::black), QSize(8,8));
140  this->SetCurveSymbol(curveId, blackSymbol);
141  }
142 
143  auto legend = new QwtLegend();
144  m_Plot->insertLegend(legend, QwtPlot::BottomLegend);
145 
146  this->Replot();
147 
148 }
virtual ~QmitkIVIMWidget()
QmitkIVIMWidget(QWidget *)
void SetCurveSymbol(unsigned int curveId, QwtSymbol *symbol)
void SetCurveAntialiasingOn(unsigned int curveId)
void SetCurvePen(unsigned int curveId, const QPen &pen)
unsigned int InsertCurve(const char *title, QColor color=QColor(Qt::black))
bool SetCurveData(unsigned int curveId, const DataVector &xValues, const DataVector &yValues)
void SetParameters(IVIMFilterType::IVIMSnapshot snap)