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