Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkIsoDoseLevelSetModel.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 <QColor>
18 #include <QSize>
19 
21 #include "mitkRTUIConstants.h"
22 
24  : QAbstractTableModel(parent),
25  m_showAbsoluteDose(false),
26  m_visibilityEditOnly(false),
27  m_referenceDose(mitk::RTUIConstants::DEFAULT_REFERENCE_DOSE_VALUE),
28  m_modified(false)
29 {
30  m_DoseSet = mitk::IsoDoseLevelSet::New();
31 }
32 
33 void
36 {
37  if (pSet)
38  {
39  emit beginResetModel();
40 
41  m_DoseSet = pSet;
42  m_modified = false;
43 
44  emit endResetModel();
45  }
46 };
47 
48 int
50  rowCount(const QModelIndex &parent) const
51 {
52  if(parent.isValid())
53  {
54  return 0;
55  }
56 
57  return m_DoseSet->Size();
58 }
59 
60 int
62  columnCount(const QModelIndex &parent) const
63 {
64  if(parent.isValid())
65  return 0;
66 
67  return 4;
68 }
69 
70 QVariant
72  data(const QModelIndex &index, int role) const
73 {
74  if(!index.isValid())
75  return QVariant();
76 
77  QVariant result;
78 
79  if (static_cast<unsigned int>(index.row()) < m_DoseSet->Size())
80  {
81  const mitk::IsoDoseLevel& level = m_DoseSet->GetIsoDoseLevel(static_cast<mitk::IsoDoseLevelSet::IsoLevelIndexType>(index.row()));
82 
83  switch(index.column())
84  {
85  case 0:
86  if(role == Qt::EditRole || role == Qt::DecorationRole)
87  {
88  QColor color;
89  color.setRgbF(level.GetColor().GetRed(),level.GetColor().GetGreen(),level.GetColor().GetBlue());
90  result = QVariant(color);
91  }
92  else if (role == Qt::ToolTipRole)
93  {
94  result = QVariant("Color of the iso dose level.");
95  }
96  break;
97  case 1:
98  if(role == Qt::DisplayRole)
99  {
100  if (this->m_showAbsoluteDose)
101  {
102  result = QVariant(QString::number(level.GetDoseValue()*this->m_referenceDose)+QString(" Gy"));
103  }
104  else
105  {
106  result = QVariant(QString::number(level.GetDoseValue()*100)+QString(" %"));
107  }
108  }
109  else if(role == Qt::EditRole)
110  {
111  if (this->m_showAbsoluteDose)
112  {
113  result = QVariant(level.GetDoseValue()*this->m_referenceDose);
114  }
115  else
116  {
117  result = QVariant(level.GetDoseValue()*100);
118  }
119  }
120  else if (role == Qt::ToolTipRole)
121  {
122  result = QVariant("Minimum dose value of this level / Value of the iso line.");
123  }
124  else if (role == Qt::UserRole+1)
125  {
126  result = QVariant(this->m_showAbsoluteDose);
127  }
128  break;
129  case 2:
130  if(role == Qt::DisplayRole || role == Qt::EditRole)
131  {
132  result = QVariant(level.GetVisibleIsoLine());
133  }
134  else if (role == Qt::ToolTipRole)
135  {
136  result = QVariant("Show isoline for this dose level.");
137  }
138  break;
139  case 3:
140  if(role == Qt::DisplayRole || role == Qt::EditRole)
141  {
142  result = QVariant(level.GetVisibleColorWash());
143  }
144  else if (role == Qt::ToolTipRole)
145  {
146  result = QVariant("Show colorwash for this dose level.");
147  }
148  break;
149  }
150  }
151 
152  return result;
153 }
154 
155 Qt::ItemFlags
157  flags(const QModelIndex &index) const
158 {
159  Qt::ItemFlags flags = QAbstractItemModel::flags(index);
160 
161  if (static_cast<unsigned int>(index.row()) < m_DoseSet->Size())
162  {
163  if (index.column() < 4)
164  {
165  if ((index.column() > 1) || (index.column() >= 0 && !this->m_visibilityEditOnly))
166  {
167  flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
168  }
169  else if (index.column() >= 0 && this->m_visibilityEditOnly)
170  {
171  flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable;
172  }
173  }
174  }
175 
176  return flags;
177 }
178 
179 QVariant
181  headerData(int section, Qt::Orientation orientation, int role) const
182 {
183  if( (Qt::DisplayRole == role) &&
184  (Qt::Horizontal == orientation))
185  {
186  if (section==0)
187  {
188  return QVariant("Color");
189  }
190  else if (section==1)
191  {
192  if (m_showAbsoluteDose)
193  {
194  return QVariant("Dose [Gy]");
195  }
196  else
197  {
198  return QVariant("Dose [%]");
199  }
200  }
201  else if (section==2)
202  {
203  return QVariant("IsoLines");
204  }
205  else if (section==3)
206  {
207  return QVariant("ColorWash");
208  }
209  }
210  return QVariant();
211 }
212 
213 bool
215  setData(const QModelIndex &index, const QVariant &value, int role)
216 {
217  if(!index.isValid() || (m_DoseSet->Size() <= static_cast<unsigned int>(index.row())) || (index.column()>3))
218  {
219  return false;
220  }
221 
222  if(Qt::EditRole == role)
223  {
224  const mitk::IsoDoseLevel& level = m_DoseSet->GetIsoDoseLevel(static_cast<mitk::IsoDoseLevelSet::IsoLevelIndexType>(index.row()));
225  mitk::IsoDoseLevel::Pointer pNewLevel = level.Clone();
226  switch(index.column())
227  {
228  case 0:
229  {
230  QColor val = value.value<QColor>();
232  color.SetRed(val.redF());
233  color.SetGreen(val.greenF());
234  color.SetBlue(val.blueF());
235  pNewLevel->SetColor(color);
236  emit dataChanged(index,index);
237  break;
238  }
239  case 1:
240  if (this->m_showAbsoluteDose)
241  {
242  pNewLevel->SetDoseValue(value.toDouble()/this->m_referenceDose);
243  }
244  else
245  {
246  pNewLevel->SetDoseValue(value.toDouble()/100.0);
247  }
248  emit dataChanged(index,index);
249  break;
250  case 2:
251  pNewLevel->SetVisibleIsoLine(value.toBool());
252  emit dataChanged(index,index);
253  break;
254  case 3:
255  pNewLevel->SetVisibleColorWash(value.toBool());
256  emit dataChanged(index,index);
257  break;
258  }
259 
260  emit beginResetModel();
261 
262  m_DoseSet->DeleteIsoDoseLevel(static_cast<mitk::IsoDoseLevelSet::IsoLevelIndexType>(index.row()));
263  m_DoseSet->SetIsoDoseLevel(pNewLevel);
264 
265  m_modified = true;
266 
267  emit endResetModel();
268 
269  return true;
270  }
271 
272  return false;
273 };
274 
276  setReferenceDose(double newReferenceDose)
277 {
278  if (newReferenceDose<= 0)
279  {
280  mitkThrow() << "Error. Passed prescribed dose is negative or equals 0.";
281  }
282 
283  if (newReferenceDose != m_referenceDose)
284  {
285  this->m_referenceDose = newReferenceDose;
286  if(m_showAbsoluteDose)
287  {
288  emit beginResetModel();
289  emit endResetModel();
290  }
291  }
292 };
293 
295  setShowAbsoluteDose(bool showAbsoluteDose)
296 
297 {
298  if (showAbsoluteDose != m_showAbsoluteDose)
299  {
300  emit beginResetModel();
301  this->m_showAbsoluteDose = showAbsoluteDose;
302  emit endResetModel();
303  }
304 };
305 
307 {
308  if (onlyVisibility != m_visibilityEditOnly)
309  {
310  emit beginResetModel();
311  this->m_visibilityEditOnly = onlyVisibility;
312  emit endResetModel();
313  }
314 };
315 
316 bool
319 {
320  return this->m_showAbsoluteDose;
321 };
322 
326 {
327  return this->m_referenceDose;
328 };
329 
330 bool
333 {
334  return this->m_visibilityEditOnly;
335 };
336 
338 {
339  emit beginResetModel();
340 
341  for (mitk::IsoDoseLevelSet::IsoLevelIndexType pos = 0; pos < m_DoseSet->Size(); ++pos)
342  {
343  mitk::IsoDoseLevel::Pointer pNewLevel = m_DoseSet->GetIsoDoseLevel(pos).Clone();
344  pNewLevel->SetVisibleIsoLine(activate);
345  m_DoseSet->SetIsoDoseLevel(pNewLevel);
346  }
347 
348  m_modified = true;
349 
350  emit endResetModel();
351 }
352 
354 {
355  emit beginResetModel();
356 
357  for (mitk::IsoDoseLevelSet::IsoLevelIndexType pos = 0; pos < m_DoseSet->Size(); ++pos)
358  {
359  mitk::IsoDoseLevel::Pointer pNewLevel = m_DoseSet->GetIsoDoseLevel(pos).Clone();
360  pNewLevel->SetVisibleColorWash(activate);
361  m_DoseSet->SetIsoDoseLevel(pNewLevel);
362  }
363 
364  m_modified = true;
365 
366  emit endResetModel();
367 }
368 
370 {
371  emit beginResetModel();
372 
373  for (mitk::IsoDoseLevelSet::IsoLevelIndexType pos = 0; pos < m_DoseSet->Size(); ++pos)
374  {
375  mitk::IsoDoseLevel::Pointer pNewLevel = m_DoseSet->GetIsoDoseLevel(pos).Clone();
376  pNewLevel->SetVisibleIsoLine(!pNewLevel->GetVisibleIsoLine());
377  m_DoseSet->SetIsoDoseLevel(pNewLevel);
378  }
379 
380  m_modified = true;
381 
382  emit endResetModel();
383 }
384 
386 {
387  emit beginResetModel();
388 
389  for (mitk::IsoDoseLevelSet::IsoLevelIndexType pos = 0; pos < m_DoseSet->Size(); ++pos)
390  {
391  mitk::IsoDoseLevel::Pointer pNewLevel = m_DoseSet->GetIsoDoseLevel(pos).Clone();
392  pNewLevel->SetVisibleColorWash(!pNewLevel->GetVisibleColorWash());
393  m_DoseSet->SetIsoDoseLevel(pNewLevel);
394  }
395 
396  m_modified = true;
397 
398  emit endResetModel();
399 }
400 
402 {
403  emit beginResetModel();
404 
405  for (mitk::IsoDoseLevelSet::IsoLevelIndexType pos = 0; pos < m_DoseSet->Size(); ++pos)
406  {
407  mitk::IsoDoseLevel::Pointer pNewLevel = m_DoseSet->GetIsoDoseLevel(pos).Clone();
408  bool colorWash = pNewLevel->GetVisibleColorWash();
409  pNewLevel->SetVisibleColorWash(pNewLevel->GetVisibleIsoLine());
410  pNewLevel->SetVisibleIsoLine(colorWash);
411  m_DoseSet->SetIsoDoseLevel(pNewLevel);
412  }
413 
414  m_modified = true;
415 
416  emit endResetModel();
417 }
418 
420 {
421  mitk::IsoDoseLevel::DoseValueType doseVal = 0.01;
422 
423  if (m_DoseSet->Size()>0)
424  {
425  doseVal = m_DoseSet->GetIsoDoseLevel(m_DoseSet->Size()-1).GetDoseValue()+0.01;
426  }
427 
429 
430  emit beginResetModel();
431  m_DoseSet->SetIsoDoseLevel(pNewLevel);
432  m_modified = true;
433  emit endResetModel();
434 }
435 
436 void QmitkIsoDoseLevelSetModel::deleteLevel(const QModelIndex &index)
437 {
438  if(!index.isValid() || (m_DoseSet->Size() <= static_cast<unsigned int>(index.row())) || (index.column()>3))
439  {
440  return;
441  }
442 
443  emit beginResetModel();
444  m_DoseSet->DeleteIsoDoseLevel(static_cast<mitk::IsoDoseLevelSet::IsoLevelIndexType>(index.row()));
445  m_modified = true;
446  emit endResetModel();
447 }
448 
450 {
451  return m_modified;
452 }
itk::SmartPointer< Self > Pointer
Stores values needed for the representation/visualization of dose iso levels.
virtual QVariant data(const QModelIndex &index, int role) const
void deleteLevel(const QModelIndex &index)
virtual DoseValueType GetDoseValue() const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
virtual void SetColor(ColorType _arg)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
DataCollection - Class to facilitate loading/accessing structured data.
void setShowAbsoluteDose(bool showAbsoluteDose)
Slot that can be used to adjust whether the dose should be displayed in absolute or relative units...
void setIsoDoseLevelSet(mitk::IsoDoseLevelSet *pSet)
Stores values needed for the representation/visualization of dose iso levels.
void setReferenceDose(double newReferenceDose)
Slot that can be used to set the prescribed dose.
static Pointer New()
#define mitkThrow()
void switchVisibilityIsoLines(bool activate)
void switchVisibilityColorWash(bool activate)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
::itk::RGBPixel< float > ColorType
DoseValueRel DoseValueType
virtual ColorType GetColor() const
mitk::DoseValueAbs getReferenceDose() const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
QmitkIsoDoseLevelSetModel(QObject *parent=NULL)
double DoseValueAbs
Represents absolute dose values (in Gy).
virtual bool GetVisibleIsoLine() const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
void setVisibilityEditOnly(bool onlyVisibility)
Slat that can be used to adjust wether the model allows to edit only visibilities (no dose value or c...
static Pointer New()
virtual bool GetVisibleColorWash() const