diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/CMakeLists.txt b/Plugins/org.mitk.gui.qt.rt.dosevisualization/CMakeLists.txt new file mode 100644 index 0000000000..243c436059 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/CMakeLists.txt @@ -0,0 +1,7 @@ +project(org_mitk_gui_qt_rt_dosevisualization) + +MACRO_CREATE_MITK_CTK_PLUGIN( + EXPORT_DIRECTIVE RTDOSEVISUALIZATION_EXPORT + EXPORTED_INCLUDE_SUFFIXES src + MODULE_DEPENDS MitkQtWidgetsExt MitkDicomRT MitkRTUI +) diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/files.cmake b/Plugins/org.mitk.gui.qt.rt.dosevisualization/files.cmake new file mode 100644 index 0000000000..3acb2dbbb9 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/files.cmake @@ -0,0 +1,55 @@ +set(SRC_CPP_FILES +) + +set(INTERNAL_CPP_FILES + org_mitk_gui_qt_rt_dosevisualization_Activator.cpp + RTDoseVisualizer.cpp + RTUIPreferencePage.cpp + DoseVisualizationPreferencePage.cpp + mitkDoseVisPreferenceHelper.cpp + LoadingRTView.cpp +) + +set(UI_FILES + src/internal/RTDoseVisualizerControls.ui + src/internal/DoseVisualizationPreferencePageControls.ui + src/internal/RTUIPreferencePageControls.ui + src/internal/LoadingRTViewControls.ui +) + +set(MOC_H_FILES + src/internal/org_mitk_gui_qt_rt_dosevisualization_Activator.h + src/internal/RTDoseVisualizer.h + src/internal/RTUIPreferencePage.h + src/internal/DoseVisualizationPreferencePage.h + src/internal/LoadingRTView.h +) + +# list of resource files which can be used by the plug-in +# system without loading the plug-ins shared library, +# for example the icon used in the menu and tabs for the +# plug-in views in the workbench +set(CACHED_RESOURCE_FILES + resources/iso.png + resources/iso2.png + resources/icon4.png + resources/icon5.png + resources/icon7.png + plugin.xml +) + +# list of Qt .qrc files which contain additional resources +# specific to this plugin +set(QRC_FILES + +) + +set(CPP_FILES ) + +foreach(file ${SRC_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/${file}) +endforeach(file ${SRC_CPP_FILES}) + +foreach(file ${INTERNAL_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/internal/${file}) +endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/manifest_headers.cmake b/Plugins/org.mitk.gui.qt.rt.dosevisualization/manifest_headers.cmake new file mode 100644 index 0000000000..9492c2783b --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/manifest_headers.cmake @@ -0,0 +1,5 @@ +set(Plugin-Name "RTDoseVisualization") +set(Plugin-Version "0.1") +set(Plugin-Vendor "DKFZ, Software development for Integrated Diagnostic and Therapy") +set(Plugin-ContactAddress "sbr@dkfz-heidelber.de") +set(Require-Plugin org.mitk.gui.qt.common org.commontk.eventadmin) diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/plugin.xml b/Plugins/org.mitk.gui.qt.rt.dosevisualization/plugin.xml new file mode 100644 index 0000000000..7ad988c76e --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/plugin.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/icon4.png b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/icon4.png new file mode 100644 index 0000000000..07e3d5d412 Binary files /dev/null and b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/icon4.png differ diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/icon5.png b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/icon5.png new file mode 100644 index 0000000000..a3338ef126 Binary files /dev/null and b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/icon5.png differ diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/icon7.png b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/icon7.png new file mode 100644 index 0000000000..55f6b4cbf3 Binary files /dev/null and b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/icon7.png differ diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/iso.png b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/iso.png new file mode 100644 index 0000000000..7edf418042 Binary files /dev/null and b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/iso.png differ diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/iso2.png b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/iso2.png new file mode 100644 index 0000000000..2a73d321db Binary files /dev/null and b/Plugins/org.mitk.gui.qt.rt.dosevisualization/resources/iso2.png differ diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/DoseVisualizationPreferencePage.cpp b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/DoseVisualizationPreferencePage.cpp new file mode 100644 index 0000000000..e5e934987f --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/DoseVisualizationPreferencePage.cpp @@ -0,0 +1,377 @@ +/*=================================================================== + +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 "DoseVisualizationPreferencePage.h" +#include "mitkRTUIConstants.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "mitkIsoLevelsGenerator.h" + +#include "org_mitk_gui_qt_rt_dosevisualization_Activator.h" + +DoseVisualizationPreferencePage::DoseVisualizationPreferencePage() + : m_MainControl(0), m_Controls(0), m_referenceDoseChanged(false), m_presetMapChanged(false) +{ + +} + +DoseVisualizationPreferencePage::~DoseVisualizationPreferencePage() +{ + delete m_LevelSetModel; + delete m_DoseColorDelegate; + delete m_DoseValueDelegate; + delete m_DoseVisualDelegate; + delete m_Controls; +} + +void DoseVisualizationPreferencePage::Init(berry::IWorkbench::Pointer ) +{ + +} + +void DoseVisualizationPreferencePage::CreateQtControl(QWidget* parent) +{ + berry::IPreferencesService::Pointer prefService + = berry::Platform::GetServiceRegistry() + .GetServiceById(berry::IPreferencesService::ID); + + m_DoseVisNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID); + + m_MainControl = new QWidget(parent); + m_Controls = new Ui::DoseVisualizationPreferencePageControls; + m_Controls->setupUi( m_MainControl ); + + m_LevelSetModel = new QmitkIsoDoseLevelSetModel(this); + m_DoseColorDelegate = new QmitkDoseColorDelegate(this); + m_DoseValueDelegate = new QmitkDoseValueDelegate(this); + m_DoseVisualDelegate = new QmitkDoseVisualStyleDelegate(this); + + this->m_Controls->isoLevelSetView->setModel(m_LevelSetModel); + this->m_Controls->isoLevelSetView->setItemDelegateForColumn(0,m_DoseColorDelegate); + this->m_Controls->isoLevelSetView->setItemDelegateForColumn(1,m_DoseValueDelegate); + this->m_Controls->isoLevelSetView->setItemDelegateForColumn(2,m_DoseVisualDelegate); + this->m_Controls->isoLevelSetView->setItemDelegateForColumn(3,m_DoseVisualDelegate); + this->m_Controls->isoLevelSetView->setContextMenuPolicy(Qt::CustomContextMenu); + + connect(m_Controls->spinReferenceDose, SIGNAL(valueChanged(double)), m_LevelSetModel, SLOT(setReferenceDose(double))); + connect(m_Controls->spinReferenceDose, SIGNAL(valueChanged(double)), this, SLOT(OnReferenceDoseChanged(double))); + connect(m_Controls->checkGlobalSync, SIGNAL(toggled(bool)), m_Controls->spinReferenceDose, SLOT(setEnabled(bool))); + connect(m_Controls->radioAbsDose, SIGNAL(toggled(bool)), m_LevelSetModel, SLOT(setShowAbsoluteDose(bool))); + connect(m_Controls->isoLevelSetView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnShowContextMenuIsoSet(const QPoint&))); + connect(m_Controls->listPresets, SIGNAL(currentItemChanged ( QListWidgetItem *, QListWidgetItem *)), this, SLOT(OnCurrentItemChanged ( QListWidgetItem *, QListWidgetItem *))); + connect(m_Controls->btnAddPreset, SIGNAL(clicked(bool)), this, SLOT(OnAddPresetClicked(bool))); + connect(m_Controls->btnDelPreset, SIGNAL(clicked(bool)), this, SLOT(OnDelPresetClicked(bool))); + connect(m_Controls->btnResetPreset, SIGNAL(clicked(bool)), this, SLOT(OnResetPresetClicked(bool))); + connect(m_Controls->btnDelLevel, SIGNAL(clicked(bool)), this, SLOT(OnDelLevelClicked(bool))); + connect(m_Controls->btnAddLevel, SIGNAL(clicked(bool)), this, SLOT(OnAddLevelClicked(bool))); + + this->Update(); +} + +QWidget* DoseVisualizationPreferencePage::GetQtControl() const +{ + return m_MainControl; +} + +bool DoseVisualizationPreferencePage::PerformOk() +{ + m_DoseVisNode->PutBool(mitk::rt::UIConstants::DOSE_DISPLAY_ABSOLUTE_ID,m_Controls->radioAbsDose->isChecked()); + m_DoseVisNode->PutBool(mitk::rt::UIConstants::GLOBAL_VISIBILITY_COLORWASH_ID,m_Controls->checkGlobalVisColorWash->isChecked()); + m_DoseVisNode->PutBool(mitk::rt::UIConstants::GLOBAL_VISIBILITY_ISOLINES_ID,m_Controls->checkGlobalVisIsoLine->isChecked()); + m_DoseVisNode->PutDouble(mitk::rt::UIConstants::REFERENCE_DOSE_ID,m_Controls->spinReferenceDose->value()); + m_DoseVisNode->PutBool(mitk::rt::UIConstants::GLOBAL_REFERENCE_DOSE_SYNC_ID, m_Controls->checkGlobalSync->isChecked()); + + mitk::rt::StorePresetsMap(this->m_Presets); + + if (this->m_Presets.find(this->m_selectedPresetName)==this->m_Presets.end()) + { //the preset currently selected in the application is not available any more. Change it to a valid one. + mitk::rt::SetSelectedPresetName(this->m_Presets.begin()->first); + } + + if (this->m_LevelSetModel->isModified()) + { + this->m_presetMapChanged = true; + } + + if (m_referenceDoseChanged) + { + mitk::rt::SignalReferenceDoseChange(m_Controls->checkGlobalSync->isChecked(), m_Controls->spinReferenceDose->value(), mitk::org_mitk_gui_qt_rt_dosevisualization_Activator::GetContext()); + } + + if (m_presetMapChanged) + { + mitk::rt::SignalPresetMapChange(mitk::org_mitk_gui_qt_rt_dosevisualization_Activator::GetContext()); + } + + return true; +} + +void DoseVisualizationPreferencePage::PerformCancel() +{ +} + +void DoseVisualizationPreferencePage::Update() +{ + m_Controls->checkGlobalVisColorWash->setChecked(m_DoseVisNode->GetBool(mitk::rt::UIConstants::GLOBAL_VISIBILITY_COLORWASH_ID, true)); + m_Controls->checkGlobalVisIsoLine->setChecked(m_DoseVisNode->GetBool(mitk::rt::UIConstants::GLOBAL_VISIBILITY_ISOLINES_ID, true)); + m_Controls->radioAbsDose->setChecked(m_DoseVisNode->GetBool(mitk::rt::UIConstants::DOSE_DISPLAY_ABSOLUTE_ID, true)); + m_Controls->radioRelDose->setChecked(!(m_DoseVisNode->GetBool(mitk::rt::UIConstants::DOSE_DISPLAY_ABSOLUTE_ID, false))); + m_Controls->spinReferenceDose->setValue(m_DoseVisNode->GetDouble(mitk::rt::UIConstants::REFERENCE_DOSE_ID, mitk::rt::UIConstants::DEFAULT_REFERENCE_DOSE_VALUE)); + m_Controls->checkGlobalSync->setChecked(m_DoseVisNode->GetBool(mitk::rt::UIConstants::GLOBAL_REFERENCE_DOSE_SYNC_ID, true)); + + m_referenceDoseChanged = false; + m_presetMapChanged = false; + + + berry::IPreferences::Pointer presetsNode = m_DoseVisNode->Node(mitk::rt::UIConstants::ROOT_ISO_PRESETS_PREFERENCE_NODE_ID); + this->m_Presets = mitk::rt::LoadPresetsMap(); + this->m_selectedPresetName = mitk::rt::GetSelectedPresetName(); + UpdatePresetsWidgets(); +} + + +mitk::IsoDoseLevelSet* DoseVisualizationPreferencePage::GetSelectedIsoLevelSet() +{ + QListWidgetItem* selectedItem = m_Controls->listPresets->currentItem(); + + mitk::IsoDoseLevelSet::Pointer result; + + if (selectedItem) + { + result = m_Presets[selectedItem->text().toStdString()]; + } + + return result; +} + +void DoseVisualizationPreferencePage::UpdateLevelSetWidgets() +{ + this->m_Controls->btnAddLevel->setEnabled(this->GetSelectedIsoLevelSet()!=NULL); + + QModelIndex selectedIndex = m_Controls->isoLevelSetView->currentIndex(); + this->m_Controls->btnDelLevel->setEnabled(this->GetSelectedIsoLevelSet()!=NULL && selectedIndex.isValid()); +} + +void DoseVisualizationPreferencePage::UpdatePresetsWidgets() +{ + m_Controls->listPresets->clear(); + + QListWidgetItem* selectedItem = NULL; + for (PresetMapType::iterator pos = m_Presets.begin(); pos != m_Presets.end(); ++pos) + { + QListWidgetItem* item = new QListWidgetItem(QString::fromStdString(pos->first)); + if (!selectedItem) + { + selectedItem = item; + } + + m_Controls->listPresets->addItem(item); + } + + if (selectedItem) + { + m_Controls->listPresets->setCurrentItem(selectedItem); + } + + if (this->m_LevelSetModel->isModified()) + { + this->m_presetMapChanged = true; + } + + this->m_LevelSetModel->setIsoDoseLevelSet(this->GetSelectedIsoLevelSet()); + + m_Controls->btnDelPreset->setEnabled((m_Controls->listPresets->currentItem() != NULL) && (m_Controls->listPresets->count()>1)); +} + +void DoseVisualizationPreferencePage::OnCurrentItemChanged ( QListWidgetItem * currentItem, QListWidgetItem * previousItem) +{ + this->m_LevelSetModel->setIsoDoseLevelSet(this->GetSelectedIsoLevelSet()); +} + +void DoseVisualizationPreferencePage::OnShowContextMenuIsoSet(const QPoint& pos) +{ + QPoint globalPos = m_Controls->isoLevelSetView->viewport()->mapToGlobal(pos); + + QModelIndex selectedIndex = m_Controls->isoLevelSetView->currentIndex(); + + QMenu viewMenu; + QAction* addLevelAct = viewMenu.addAction("Add new level"); + QAction* delLevelAct = viewMenu.addAction("Delete selected level"); + delLevelAct->setEnabled(selectedIndex.isValid()); + viewMenu.addSeparator(); + QAction* invertIsoLineAct = viewMenu.addAction("Invert iso line visibility"); + QAction* activateIsoLineAct = viewMenu.addAction("Activate all iso lines"); + QAction* deactivateIsoLineAct = viewMenu.addAction("Deactivate all iso lines"); + viewMenu.addSeparator(); + QAction* invertColorWashAct = viewMenu.addAction("Invert color wash visibility"); + QAction* activateColorWashAct = viewMenu.addAction("Activate all color wash levels"); + QAction* deactivateColorWashAct = viewMenu.addAction("Deactivate all color wash levels"); + viewMenu.addSeparator(); + QAction* swapAct = viewMenu.addAction("Swap iso line/color wash visibility"); + + QAction* selectedItem = viewMenu.exec(globalPos); + if (selectedItem == invertIsoLineAct) + { + this->m_LevelSetModel->invertVisibilityIsoLines(); + } + else if (selectedItem == activateIsoLineAct) + { + this->m_LevelSetModel->switchVisibilityIsoLines(true); + } + else if (selectedItem == deactivateIsoLineAct) + { + this->m_LevelSetModel->switchVisibilityIsoLines(false); + } + else if (selectedItem == invertColorWashAct) + { + this->m_LevelSetModel->invertVisibilityColorWash(); + } + else if (selectedItem == activateColorWashAct) + { + this->m_LevelSetModel->switchVisibilityColorWash(true); + } + else if (selectedItem == deactivateColorWashAct) + { + this->m_LevelSetModel->switchVisibilityColorWash(false); + } + else if (selectedItem == swapAct) + { + this->m_LevelSetModel->swapVisibility(); + } + else if (selectedItem == addLevelAct) + { + this->m_LevelSetModel->addLevel(); + } + else if (selectedItem == delLevelAct) + { + this->m_LevelSetModel->deleteLevel(selectedIndex); + } +} + +void DoseVisualizationPreferencePage::OnAddPresetClicked(bool checked) +{ + bool done = false; + QString name = tr("new_preset"); + while (!done) + { + bool ok; + name = QInputDialog::getText(m_MainControl, tr("Define name of new preset."), tr("Preset name:"), QLineEdit::Normal, name, &ok); + + if (!ok) + { + return; //cancled by user; + } + + bool uniqueName = m_Presets.find(name.toStdString()) == m_Presets.end(); + if (!uniqueName) + { + QMessageBox box; + box.setText(tr("New preset name is not unique. Please, choose another one.")); + box.exec(); + } + + bool validName = name.indexOf(tr("/")) ==-1; + if (!validName) + { + QMessageBox box; + box.setText(tr("New preset name is not valid. Please don't use \"/\".")); + box.exec(); + } + + done = uniqueName && validName; + } + + mitk::IsoDoseLevelSet::Pointer newSet = mitk::rt::GeneratIsoLevels_Virtuos(); + m_Presets.insert(std::make_pair(name.toStdString(),newSet)); + + m_presetMapChanged = true; + + UpdatePresetsWidgets(); +} + +void DoseVisualizationPreferencePage::OnDelPresetClicked(bool checked) +{ + QListWidgetItem* selectedItem = m_Controls->listPresets->currentItem(); + + if (selectedItem) + { + if (m_Controls->listPresets->count() > 1) + { + m_Presets.erase(selectedItem->text().toStdString()); + + m_presetMapChanged = true; + this->UpdatePresetsWidgets(); + } + } +} + + +void DoseVisualizationPreferencePage::OnResetPresetClicked(bool checked) +{ + QMessageBox box; + box.setText("Do you want to reset the presets?"); + box.setInformativeText("If you reset the presets. All user defined presets will be removed and the default presets will be loaded."); + box.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + box.setDefaultButton(QMessageBox::No); + int ret = box.exec(); + + if (ret == QMessageBox::Yes) + { + mitk::IsoDoseLevelSet::Pointer newSet = mitk::rt::GeneratIsoLevels_Virtuos(); + m_Presets.clear(); + m_Presets.insert(std::make_pair("Virtuos",newSet)); + + m_presetMapChanged = true; + + UpdatePresetsWidgets(); + } +} + + +void DoseVisualizationPreferencePage::OnAddLevelClicked(bool checked) +{ + this->m_LevelSetModel->addLevel(); +} + +void DoseVisualizationPreferencePage::OnDelLevelClicked(bool checked) +{ + QModelIndex selectedIndex = m_Controls->isoLevelSetView->currentIndex(); + + if (!selectedIndex.isValid()) + { + selectedIndex = m_Controls->isoLevelSetView->indexAt(QPoint(1,1)); + } + + this->m_LevelSetModel->deleteLevel(selectedIndex); +} + +void DoseVisualizationPreferencePage::OnReferenceDoseChanged(double dose) +{ + this->m_referenceDoseChanged = true; +}; diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/DoseVisualizationPreferencePage.h b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/DoseVisualizationPreferencePage.h new file mode 100644 index 0000000000..ed45400c1b --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/DoseVisualizationPreferencePage.h @@ -0,0 +1,123 @@ +/*=================================================================== + +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 __DOSE_VISUALIZATION_PREFERENCE_PAGE_H +#define __DOSE_VISUALIZATION_PREFERENCE_PAGE_H + +#include "berryIQtPreferencePage.h" +#include "berryIPreferences.h" + +#include "ui_DoseVisualizationPreferencePageControls.h" + +#include +#include "mitkDoseVisPreferenceHelper.h" + +/*forward declarations*/ +class QmitkIsoDoseLevelSetModel; +class QmitkDoseColorDelegate; +class QmitkDoseValueDelegate; +class QmitkDoseVisualStyleDelegate; + +class QWidget; + +/** +* \class DoseVisualizationPreferencePage +* \brief Preference page for RT Dose visualization +*/ +class DoseVisualizationPreferencePage : public QObject, public berry::IQtPreferencePage +{ + Q_OBJECT + Q_INTERFACES(berry::IPreferencePage) + +public: + DoseVisualizationPreferencePage(); + ~DoseVisualizationPreferencePage(); + + /** + * \brief Called by framework to initialize this preference page, but currently does nothing. + * \param workbench The workbench. + */ + void Init(berry::IWorkbench::Pointer workbench); + + /** + * \brief Called by framework to create the GUI, and connect signals and slots. + * \param widget The Qt widget that acts as parent to all GUI components, as this class itself is not derived from QWidget. + */ + void CreateQtControl(QWidget* widget); + + /** + * \brief Required by framework to get hold of the GUI. + * \return QWidget* the top most QWidget for the GUI. + */ + QWidget* GetQtControl() const; + + /** + * \see IPreferencePage::PerformOk + */ + virtual bool PerformOk(); + + /** + * \see IPreferencePage::PerformCancel + */ + virtual void PerformCancel(); + + /** + * \see IPreferencePage::Update + */ + virtual void Update(); + + public slots: + + void OnCurrentItemChanged ( QListWidgetItem * currentItem, QListWidgetItem * previousItem); + void OnShowContextMenuIsoSet(const QPoint& pos); + void OnAddPresetClicked(bool checked); + void OnDelPresetClicked(bool checked); + void OnResetPresetClicked(bool checked); + void OnAddLevelClicked(bool checked); + void OnDelLevelClicked(bool checked); + void OnReferenceDoseChanged(double dose); + +protected: + + /** Method updates the presets widgets according to the internal members*/ + void UpdatePresetsWidgets(); + /** Method actualizes the level set model and edit buttons according to the currently selected item in the presets list view*/ + void UpdateLevelSetWidgets(); + + /** Method returns the iso dose level set selected in the preset lists. May return NULL if no preset is selected.*/ + mitk::IsoDoseLevelSet* GetSelectedIsoLevelSet(); + + QWidget *m_MainControl; + Ui::DoseVisualizationPreferencePageControls* m_Controls; + + berry::IPreferences::Pointer m_DoseVisNode; + + typedef mitk::rt::PresetMapType PresetMapType; + PresetMapType m_Presets; + std::string m_selectedPresetName; + + bool m_referenceDoseChanged; + bool m_presetMapChanged; + + QmitkIsoDoseLevelSetModel* m_LevelSetModel; + QmitkDoseColorDelegate* m_DoseColorDelegate; + QmitkDoseValueDelegate* m_DoseValueDelegate; + QmitkDoseVisualStyleDelegate* m_DoseVisualDelegate; + +}; + +#endif diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/DoseVisualizationPreferencePageControls.ui b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/DoseVisualizationPreferencePageControls.ui new file mode 100644 index 0000000000..ffbdbcad21 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/DoseVisualizationPreferencePageControls.ui @@ -0,0 +1,307 @@ + + + DoseVisualizationPreferencePageControls + + + + 0 + 0 + 714 + 651 + + + + + 0 + 0 + + + + QmitkTemplate + + + + 5 + + + 5 + + + + + Global viszualization settings: + + + + + + + 0 + 0 + + + + + 105 + 0 + + + + Qt::NoFocus + + + Reference dose [Gy]: + + + + + + + + 0 + 0 + + + + + 65 + 0 + + + + Dose display: + + + + + + + + + relative [%] + + + true + + + + + + + absolute [Gy] + + + + + + + + + Global visibility: + + + + + + + + + Isolines + + + + :/RTUI/eye_open.png + + + + + 24 + 16 + + + + + + + + Colorwash + + + + :/RTUI/eye_open.png + + + + + 24 + 16 + + + + + + + + + + + + + + + + + + 1 + + + 0.100000000000000 + + + 9999.000000000000000 + + + + + + + global sync + + + + + + + + + + + + Iso dose level presets: + + + + 5 + + + 5 + + + + + + 16777215 + 100 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add + + + + + + + Remove + + + + + + + Reset + + + + + + + + + Preset editor: + + + + + + + true + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + + 30 + 20 + + + + 75 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add level + + + + + + + Remove level + + + + + + + + + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/LoadingRTView.cpp b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/LoadingRTView.cpp new file mode 100644 index 0000000000..3da9071e1e --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/LoadingRTView.cpp @@ -0,0 +1,133 @@ +/*=================================================================== + +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. + +===================================================================*/ + + +// Blueberry +#include +#include + +// Qmitk +#include "LoadingRTView.h" + +// Qt +#include +#include + +#include + +const std::string LoadingRTView::VIEW_ID = "org.mitk.views.loadingrtview"; + +void LoadingRTView::SetFocus(){} + +void LoadingRTView::CreateQtPartControl( QWidget *parent ) +{ + // create GUI widgets from the Qt Designer's .ui file + m_Controls.setupUi( parent ); + connect( m_Controls.btnLoadStruct, SIGNAL(clicked()), this, SLOT(LoadRTStructureSet()) ); + connect( m_Controls.btnLoadDose, SIGNAL(clicked()), this, SLOT(LoadRTDoseFile()) ); +} + +void LoadingRTView::LoadRTStructureSet() +{ + QFileDialog dialog; + dialog.setNameFilter(tr("Images (*.dcm")); + + mitk::DicomSeriesReader::StringContainer files; + QStringList fileNames = dialog.getOpenFileNames(); + if(fileNames.empty()) + { + return; + } + QStringListIterator fileNamesIterator(fileNames); + while(fileNamesIterator.hasNext()) + { + files.push_back(fileNamesIterator.next().toStdString()); + } + + std::string tmp = files.front(); + const char* filename = tmp.c_str(); + char* filenameC = const_cast(filename); + + DcmFileFormat file; + OFCondition outp = file.loadFile(filename, EXS_Unknown); + if(outp.bad()) + { + QMessageBox::information(NULL,"Error","Cant read the file"); + } + DcmDataset *dataset = file.getDataset(); + + mitk::DicomRTReader::Pointer readerRT = mitk::DicomRTReader::New(); + std::deque modelVector; + + modelVector = readerRT->ReadDicomFile(filenameC); + + if(modelVector.empty()) + { + QMessageBox::information(NULL, "Error", "Vector is empty ..."); + } + + for(int i=0; iSetData(modelVector.at(i)); + x->SetProperty("name", modelVector.at(i)->GetProperty("name")); + x->SetProperty("color",modelVector.at(i)->GetProperty("contour.color")); + x->SetProperty("contour.color",modelVector.at(i)->GetProperty("contour.color")); + x->SetVisibility(true); + GetDataStorage()->Add(x); + } +} + +void LoadingRTView::LoadRTDoseFile() +{ + QFileDialog dialog; + dialog.setNameFilter(tr("Images (*.dcm")); + + mitk::DicomSeriesReader::StringContainer files; + QStringList fileNames = dialog.getOpenFileNames(); + if(fileNames.empty()) + { + return; + } + QStringListIterator fileNamesIterator(fileNames); + while(fileNamesIterator.hasNext()) + { + files.push_back(fileNamesIterator.next().toStdString()); + } + + std::string tmp = files.front(); + const char* filename = tmp.c_str(); + char* ncFilename = const_cast(filename); + + mitk::DicomRTReader::Pointer _DicomRTReader = mitk::DicomRTReader::New(); + + DcmFileFormat file; + OFCondition outp = file.loadFile(filename, EXS_Unknown); + if(outp.bad()) + { + QMessageBox::information(NULL,"Error","Cant read the file"); + } + DcmDataset *dataset = file.getDataset(); + + mitk::DataNode::Pointer mitkImage = mitk::DataNode::New(); + mitkImage = _DicomRTReader->LoadRTDose(dataset,ncFilename); + + if(mitkImage.IsNotNull()) + { + GetDataStorage()->Add(mitkImage); + } + +} diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/LoadingRTView.h b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/LoadingRTView.h new file mode 100644 index 0000000000..893221b596 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/LoadingRTView.h @@ -0,0 +1,61 @@ +/*=================================================================== + +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 LoadingRTView_h +#define LoadingRTView_h + +#include + +#include + +#include "ui_LoadingRTViewControls.h" + + +/** + \brief LoadingRTView + + \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. + + \sa QmitkAbstractView + \ingroup ${plugin_target}_internal +*/ +class LoadingRTView : public QmitkAbstractView +{ + // this is needed for all Qt objects that should have a Qt meta-object + // (everything that derives from QObject and wants to have signal/slots) + Q_OBJECT + + public: + + static const std::string VIEW_ID; + + protected slots: + + void LoadRTDoseFile(); + void LoadRTStructureSet(); + + protected: + + virtual void CreateQtPartControl(QWidget *parent); + + virtual void SetFocus(); + + Ui::LoadingRTViewControls m_Controls; + +}; + +#endif // LoadingRTView_h diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/LoadingRTViewControls.ui b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/LoadingRTViewControls.ui new file mode 100644 index 0000000000..95f9893a6e --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/LoadingRTViewControls.ui @@ -0,0 +1,100 @@ + + + LoadingRTViewControls + + + + 0 + 0 + 288 + 161 + + + + + 0 + 0 + + + + QmitkTemplate + + + + + + Loading RT Data + + + + + + + + + + 0 + 60 + + + + RT Struct + + + + :/org.mitk.gui.qt.rt.dosevisualization/resources/icon7.png:/org.mitk.gui.qt.rt.dosevisualization/resources/icon7.png + + + + 50 + 50 + + + + + + + + + 0 + 60 + + + + RT Dose + + + + :/org.mitk.gui.qt.rt.dosevisualization/resources/icon5.png:/org.mitk.gui.qt.rt.dosevisualization/resources/icon5.png + + + + 50 + 50 + + + + + + + + + + Qt::Vertical + + + + 20 + 10 + + + + + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTDoseVisualizer.cpp b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTDoseVisualizer.cpp new file mode 100644 index 0000000000..f94a81682b --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTDoseVisualizer.cpp @@ -0,0 +1,847 @@ +/*=================================================================== + +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. + +===================================================================*/ + +// Qt +#include +#include + +// Blueberry +#include +#include + +// MITK +#include + +#include +#include + +// Qmitk +#include "RTDoseVisualizer.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "org_mitk_gui_qt_rt_dosevisualization_Activator.h" + +#include +#include +#include + +#include +#include "QmitkRenderWindow.h" +#include + +#include "mitkSurfaceVtkMapper3D.h" + +#include "mitkSliceNavigationController.h" + +#include "vtkDecimatePro.h" + +const std::string RTDoseVisualizer::VIEW_ID = "org.mitk.views.rt.dosevisualization"; + +RTDoseVisualizer::RTDoseVisualizer() +{ + m_freeIsoValues = mitk::IsoDoseLevelVector::New(); + m_selectedNodeIsoSet = mitk::IsoDoseLevelSet::New(); + + m_freeIsoFilter = vtkSmartPointer::New(); + + m_FreeIsoAdded = false; + m_selectedNode = NULL; + m_selectedPresetName = ""; + m_internalUpdate = false; + m_PrescribedDose_Data = 0.0; +} + +RTDoseVisualizer::~RTDoseVisualizer() +{ + delete m_LevelSetModel; + delete m_DoseColorDelegate; + delete m_DoseValueDelegate; + delete m_DoseVisualDelegate; +} + +void RTDoseVisualizer::InitScrolling(){ + QmitkRenderWindow* rw = this->GetRenderWindowPart()->GetQmitkRenderWindow("axial"); + + itk::MemberCommand::Pointer sliceChangedCommand = + itk::MemberCommand::New(); + sliceChangedCommand->SetCallbackFunction(this, &RTDoseVisualizer::OnSliceChanged); + rw->GetSliceNavigationController()->AddObserver(mitk::SliceNavigationController::GeometrySliceEvent(NULL,0), sliceChangedCommand); +} + +void RTDoseVisualizer::SetFocus(){} + +void RTDoseVisualizer::OnSliceChanged(itk::Object *sender, const itk::EventObject &e) +{ + for(int i=0; iRemove(m_StdIsoLines.at(i)); + } + m_StdIsoLines.clear(); + this->UpdateStdIsolines(); + + if(m_FreeIsoAdded) + { + float pref; + //get the iso dose node + mitk::DataNode::Pointer isoNode = this->GetIsoDoseNode(); + isoNode->GetFloatProperty(mitk::rt::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(),pref); + mitk::Image::Pointer image = dynamic_cast(isoNode->GetData()); + mitk::Image::Pointer slicedImage = this->GetExtractedSlice(image); + + m_Filters.at(0)->SetInputData(slicedImage->GetVtkImageData()); + m_Filters.at(0)->GenerateValues(1,m_FreeIsoValue->GetDoseValue()*pref,m_FreeIsoValue->GetDoseValue()*pref); + m_Filters.at(0)->Update(); + + m_FreeIsoline->GetData()->GetGeometry()->SetOrigin(slicedImage->GetGeometry()->GetOrigin()); + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } +} + +mitk::DataNode::Pointer RTDoseVisualizer::GetIsoDoseNode() +{ + //holt zuerst alle isonodes prüft dann auf visibility und nimmt zuletzt den mit dem höchsten layer + mitk::NodePredicateProperty::Pointer isDosePredicate = mitk::NodePredicateProperty::New(mitk::rt::Constants::DOSE_PROPERTY_NAME.c_str(),mitk::BoolProperty::New(true)); + mitk::DataStorage::SetOfObjects::ConstPointer allIsoDoseNodes = this->GetDataStorage()->GetSubset(isDosePredicate); + int tmp = -1; + int layer = -1; + mitk::DataNode::Pointer isoNode = mitk::DataNode::New(); + for(mitk::DataStorage::SetOfObjects::ConstIterator itIsoDose = allIsoDoseNodes->Begin(); itIsoDose != allIsoDoseNodes->End(); ++itIsoDose) + { + bool isVisible(false); + itIsoDose.Value()->GetBoolProperty("visible",isVisible); + if(isVisible) + { + if(itIsoDose.Value()->GetIntProperty("layer",tmp) && tmp > layer) + { + isoNode = itIsoDose.Value(); + } + } + } + if(isoNode.IsNotNull()) + return isoNode; + else + return NULL; +} + +void RTDoseVisualizer::CreateQtPartControl( QWidget *parent ) +{ + // create GUI widgets from the Qt Designer's .ui file + m_Controls.setupUi( parent ); + + m_LevelSetModel = new QmitkIsoDoseLevelSetModel(this); + m_LevelSetModel->setVisibilityEditOnly(true); + m_DoseColorDelegate = new QmitkDoseColorDelegate(this); + m_DoseValueDelegate = new QmitkDoseValueDelegate(this); + m_DoseVisualDelegate = new QmitkDoseVisualStyleDelegate(this); + + this->UpdateByPreferences(); + this->ActualizeIsoLevelsForAllDoseDataNodes(); + this->ActualizeReferenceDoseForAllDoseDataNodes(); + this->ActualizeDisplayStyleForAllDoseDataNodes(); + + this->m_Controls.isoLevelSetView->setModel(m_LevelSetModel); + this->m_Controls.isoLevelSetView->setItemDelegateForColumn(0,m_DoseColorDelegate); + this->m_Controls.isoLevelSetView->setItemDelegateForColumn(1,m_DoseValueDelegate); + this->m_Controls.isoLevelSetView->setItemDelegateForColumn(2,m_DoseVisualDelegate); + this->m_Controls.isoLevelSetView->setItemDelegateForColumn(3,m_DoseVisualDelegate); + this->m_Controls.isoLevelSetView->setContextMenuPolicy(Qt::CustomContextMenu); + + this->m_Controls.btnRemoveFreeValue->setDisabled(true); + + connect(m_Controls.btnConvert, SIGNAL(clicked()), this, SLOT(OnConvertButtonClicked())); + connect(m_Controls.spinReferenceDose, SIGNAL(valueChanged(double)), this, SLOT(OnReferenceDoseChanged(double))); + connect(m_Controls.spinReferenceDose, SIGNAL(valueChanged(double)), m_LevelSetModel, SLOT(setReferenceDose(double))); + connect(m_Controls.radioAbsDose, SIGNAL(toggled(bool)), m_LevelSetModel, SLOT(setShowAbsoluteDose(bool))); + connect(m_Controls.radioAbsDose, SIGNAL(toggled(bool)), this, SLOT(OnAbsDoseToggled(bool))); + connect(m_Controls.btnAddFreeValue, SIGNAL(clicked()), this, SLOT(OnAddFreeValueClicked())); + connect(m_Controls.btnRemoveFreeValue, SIGNAL(clicked()), this, SLOT(OnRemoveFreeValueClicked())); + connect(m_Controls.checkGlobalVisColorWash, SIGNAL(toggled(bool)), this, SLOT(OnGlobalVisColorWashToggled(bool))); + connect(m_Controls.checkGlobalVisIsoLine, SIGNAL(toggled(bool)), this, SLOT(OnGlobalVisIsoLineToggled(bool))); + connect(m_Controls.isoLevelSetView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnShowContextMenuIsoSet(const QPoint&))); + connect(m_Controls.comboPresets, SIGNAL(currentIndexChanged ( const QString&)), this, SLOT(OnCurrentPresetChanged(const QString&))); + connect(m_Controls.btnUsePrescribedDose, SIGNAL(clicked()), this, SLOT(OnUsePrescribedDoseClicked())); + + ctkServiceReference ref = mitk::org_mitk_gui_qt_rt_dosevisualization_Activator::GetContext()->getServiceReference(); + + ctkDictionary propsForSlot; + if (ref) + { + ctkEventAdmin* eventAdmin = mitk::org_mitk_gui_qt_rt_dosevisualization_Activator::GetContext()->getService(ref); + + propsForSlot[ctkEventConstants::EVENT_TOPIC] = mitk::rt::CTKEventConstants::TOPIC_ISO_DOSE_LEVEL_PRESETS_CHANGED.c_str(); + eventAdmin->subscribeSlot(this, SLOT(OnHandleCTKEventPresetsChanged(ctkEvent)), propsForSlot); + + propsForSlot[ctkEventConstants::EVENT_TOPIC] = mitk::rt::CTKEventConstants::TOPIC_REFERENCE_DOSE_CHANGED.c_str(); + eventAdmin->subscribeSlot(this, SLOT(OnHandleCTKEventReferenceDoseChanged(ctkEvent)), propsForSlot); + } + + this->UpdateBySelectedNode(); +} + +void RTDoseVisualizer::OnReferenceDoseChanged(double value) +{ + if (! m_internalUpdate) + { + mitk::DoseValueAbs referenceDose = 0.0; + bool globalSync = mitk::rt::GetReferenceDoseValue(referenceDose); + + if (globalSync) + { + mitk::rt::SetReferenceDoseValue(globalSync, value); + this->ActualizeReferenceDoseForAllDoseDataNodes(); + } + else + { + if (this->m_selectedNode.IsNotNull()) + { + this->m_selectedNode->SetFloatProperty(mitk::rt::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), value); + } + } + if (this->m_selectedNode.IsNotNull()) + { + mitk::TransferFunction::ControlPoints scalarOpacityPoints; + scalarOpacityPoints.push_back( std::make_pair(0, 1 ) ); + vtkSmartPointer transferFunction = vtkSmartPointer::New(); + mitk::IsoDoseLevelSet::Pointer isoDoseLevelSet = this->m_Presets[this->m_selectedPresetName]; + for(mitk::IsoDoseLevelSet::ConstIterator setIT = isoDoseLevelSet->Begin(); setIT != isoDoseLevelSet->End(); ++setIT) + { + float *hsv = new float[3]; + vtkSmartPointer cCalc = vtkSmartPointer::New(); + if(setIT->GetVisibleColorWash()){ + cCalc->RGBToHSV(setIT->GetColor()[0],setIT->GetColor()[1],setIT->GetColor()[2],&hsv[0],&hsv[1],&hsv[2]); + transferFunction->AddHSVPoint(setIT->GetDoseValue()*value,hsv[0],hsv[1],hsv[2],1.0,1.0); + } + else + { + scalarOpacityPoints.push_back( std::make_pair(setIT->GetDoseValue()*value, 1 ) ); + } + } + mitk::TransferFunction::Pointer mitkTransFunc = mitk::TransferFunction::New(); + mitk::TransferFunctionProperty::Pointer mitkTransFuncProp = mitk::TransferFunctionProperty::New(); + mitkTransFunc->SetColorTransferFunction(transferFunction); + mitkTransFunc->SetScalarOpacityPoints(scalarOpacityPoints); + mitkTransFuncProp->SetValue(mitkTransFunc); + + mitk::RenderingModeProperty::Pointer renderingMode = mitk::RenderingModeProperty::New(); + renderingMode->SetValue(mitk::RenderingModeProperty::COLORTRANSFERFUNCTION_COLOR); + + m_selectedNode->SetProperty("Image Rendering.Transfer Function", mitkTransFuncProp); + m_selectedNode->SetProperty("opacity", mitk::FloatProperty::New(0.5)); + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + } +} + +void RTDoseVisualizer::OnAddFreeValueClicked() +{ + QColor newColor; + //Use HSV schema of QColor to calculate a different color depending on the + //number of already existing free iso lines. + newColor.setHsv((m_freeIsoValues->Size()*85)%360,255,255); + mitk::Color mColor; + mColor[0]=newColor.redF(); + mColor[1]=newColor.greenF(); + mColor[2]=newColor.blueF(); + + mitk::DataNode::Pointer isoNode = this->UpdatePolyData(1,m_Controls.spinReferenceDose->value()*0.5,m_Controls.spinReferenceDose->value()*0.5); + isoNode->SetColor(mColor); + m_FreeIsoLines.push_back(isoNode); + + mitk::IsoDoseLevel::ColorType color; + color[0] = newColor.redF(); + color[1] = newColor.greenF(); + color[2] = newColor.blueF(); + m_freeIsoValues->push_back(mitk::IsoDoseLevel::New(0.5,color,true,false)); + m_FreeIsoValue = mitk::IsoDoseLevel::New(0.5,color,true,false); + UpdateFreeIsoValues(); + mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); + if(m_FreeIsoLines.size()>=1) + { + this->m_Controls.btnAddFreeValue->setDisabled(true); + m_FreeIsoAdded = true; + } + this->m_Controls.btnRemoveFreeValue->setEnabled(true); +} + +void RTDoseVisualizer::OnRemoveFreeValueClicked() +{ + m_freeIsoValues->pop_back(); + mitk::DataNode::Pointer isoNode = m_FreeIsoLines.at(m_FreeIsoLines.size()-1); + m_FreeIsoLines.pop_back(); + m_Filters.pop_back(); + if(m_FreeIsoLines.empty()) + this->m_Controls.btnRemoveFreeValue->setDisabled(true); + if(m_FreeIsoLines.size()<1) + { + m_FreeIsoAdded = false; + this->m_Controls.btnAddFreeValue->setEnabled(true); + } + this->GetDataStorage()->Remove(isoNode); + UpdateFreeIsoValues(); +} + +void RTDoseVisualizer::OnUsePrescribedDoseClicked() +{ + m_Controls.spinReferenceDose->setValue(this->m_PrescribedDose_Data); +} + + +void RTDoseVisualizer::OnShowContextMenuIsoSet(const QPoint& pos) +{ + QPoint globalPos = m_Controls.isoLevelSetView->viewport()->mapToGlobal(pos); + + QMenu viewMenu; + QAction* invertIsoLineAct = viewMenu.addAction("Invert iso line visibility"); + QAction* activateIsoLineAct = viewMenu.addAction("Activate all iso lines"); + QAction* deactivateIsoLineAct = viewMenu.addAction("Deactivate all iso lines"); + viewMenu.addSeparator(); + QAction* invertColorWashAct = viewMenu.addAction("Invert color wash visibility"); + QAction* activateColorWashAct = viewMenu.addAction("Activate all color wash levels"); + QAction* deactivateColorWashAct = viewMenu.addAction("Deactivate all color wash levels"); + viewMenu.addSeparator(); + QAction* swapAct = viewMenu.addAction("Swap iso line/color wash visibility"); + // ... + + QAction* selectedItem = viewMenu.exec(globalPos); + if (selectedItem == invertIsoLineAct) + { + this->m_LevelSetModel->invertVisibilityIsoLines(); + } + else if (selectedItem == activateIsoLineAct) + { + this->m_LevelSetModel->switchVisibilityIsoLines(true); + } + else if (selectedItem == deactivateIsoLineAct) + { + this->m_LevelSetModel->switchVisibilityIsoLines(false); + } + else if (selectedItem == invertColorWashAct) + { + this->m_LevelSetModel->invertVisibilityColorWash(); + } + else if (selectedItem == activateColorWashAct) + { + this->m_LevelSetModel->switchVisibilityColorWash(true); + } + else if (selectedItem == deactivateColorWashAct) + { + this->m_LevelSetModel->switchVisibilityColorWash(false); + } + else if (selectedItem == swapAct) + { + this->m_LevelSetModel->swapVisibility(); + } +} + +void RTDoseVisualizer::UpdateFreeIsoValues() +{ + this->m_Controls.listFreeValues->clear(); + + for (mitk::IsoDoseLevelVector::Iterator pos = this->m_freeIsoValues->Begin(); pos != this->m_freeIsoValues->End(); ++pos) + { + QListWidgetItem* item = new QListWidgetItem; + item->setSizeHint(QSize(0,25)); + QmitkFreeIsoDoseLevelWidget* widget = new QmitkFreeIsoDoseLevelWidget; + + float pref; + m_selectedNode->GetFloatProperty(mitk::rt::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(),pref); + + widget->setIsoDoseLevel(pos->Value().GetPointer()); + widget->setReferenceDose(pref); + connect(m_Controls.spinReferenceDose, SIGNAL(valueChanged(double)), widget, SLOT(setReferenceDose(double))); + connect(widget,SIGNAL(ColorChanged(mitk::IsoDoseLevel*)), this, SLOT(UpdateFreeIsoLineColor(mitk::IsoDoseLevel*))); + connect(widget,SIGNAL(ValueChanged(mitk::IsoDoseLevel*,mitk::DoseValueRel)), this, SLOT(UpdateFreeIsoLine(mitk::IsoDoseLevel*,mitk::DoseValueRel))); + + this->m_Controls.listFreeValues->addItem(item); + this->m_Controls.listFreeValues->setItemWidget(item,widget); + } +} + +void RTDoseVisualizer::UpdateFreeIsoLineColor(mitk::IsoDoseLevel *level) +{ + //push it in and get the key! +// m_freeIsoValues + ::itk::RGBPixel color = level->GetColor(); + mitk::Color mColor; + mColor[0]=color.GetRed(); + mColor[1]=color.GetGreen(); + mColor[2]=color.GetBlue(); + m_FreeIsoline->SetColor(mColor); +} + +void RTDoseVisualizer::UpdateFreeIsoLine(mitk::IsoDoseLevel * level, mitk::DoseValueRel old) +{ + float pref; + m_selectedNode->GetFloatProperty(mitk::rt::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(),pref); + mitk::Image::Pointer image = dynamic_cast(m_selectedNode->GetData()); + mitk::Image::Pointer slicedImage = this->GetExtractedSlice(image); + + m_FreeIsoValue = level; +// m_freeIsoValues->at(0) = level; + + m_Filters.at(0)->SetInputData(slicedImage->GetVtkImageData()); + m_Filters.at(0)->GenerateValues(1,level->GetDoseValue()*pref,level->GetDoseValue()*pref); + m_Filters.at(0)->Update(); + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); +} + +void RTDoseVisualizer::OnAbsDoseToggled(bool showAbs) +{ + if (! m_internalUpdate) + { + mitk::rt::SetDoseDisplayAbsolute(showAbs); + this->ActualizeDisplayStyleForAllDoseDataNodes(); + } +} + +void RTDoseVisualizer::OnGlobalVisColorWashToggled(bool showColorWash) +{ + if (m_selectedNode.IsNotNull()) + { + m_selectedNode->SetBoolProperty(mitk::rt::Constants::DOSE_SHOW_COLORWASH_PROPERTY_NAME.c_str(), showColorWash); + } +} + +void RTDoseVisualizer::OnGlobalVisIsoLineToggled(bool showIsoLines) +{ + if (m_selectedNode.IsNotNull()) + { + m_selectedNode->SetBoolProperty(mitk::rt::Constants::DOSE_SHOW_ISOLINES_PROPERTY_NAME.c_str(), showIsoLines); + mitk::NodePredicateProperty::Pointer isoProp = mitk::NodePredicateProperty:: + New(mitk::rt::Constants::DOSE_ISO_LEVELS_PROPERTY_NAME.c_str(), mitk::BoolProperty::New(true)); + mitk::DataStorage::SetOfObjects::ConstPointer isoSet = this->GetDataStorage()->GetSubset(isoProp); + for(mitk::DataStorage::SetOfObjects::ConstIterator iso = isoSet->Begin(); iso!=isoSet->End(); ++iso) + { + mitk::DataNode::Pointer node = iso.Value(); + node->SetVisibility(showIsoLines); + } + mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); + } +} + + +void RTDoseVisualizer::OnConvertButtonClicked() +{ + this->InitScrolling(); + + QList dataNodes = this->GetDataManagerSelection(); + + mitk::DataNode* selectedNode = NULL; + + if (!dataNodes.empty()) + { + selectedNode = dataNodes[0]; + } + + bool isDoseNode = false; + if(selectedNode && selectedNode->GetBoolProperty(mitk::rt::Constants::DOSE_PROPERTY_NAME.c_str(),isDoseNode) && isDoseNode) + { + selectedNode->SetBoolProperty(mitk::rt::Constants::DOSE_PROPERTY_NAME.c_str(), true); + selectedNode->SetBoolProperty(mitk::rt::Constants::DOSE_SHOW_COLORWASH_PROPERTY_NAME.c_str(), true); + selectedNode->SetBoolProperty(mitk::rt::Constants::DOSE_SHOW_ISOLINES_PROPERTY_NAME.c_str(), true); + selectedNode->SetFloatProperty(mitk::rt::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), m_Controls.spinReferenceDose->value()); + + mitk::IsoDoseLevelSet::Pointer clonedPreset = this->m_Presets[this->m_selectedPresetName]->Clone(); + mitk::IsoDoseLevelSetProperty::Pointer levelSetProp = mitk::IsoDoseLevelSetProperty::New(clonedPreset); + selectedNode->SetProperty(mitk::rt::Constants::DOSE_ISO_LEVELS_PROPERTY_NAME.c_str(),levelSetProp); + + float prescribed; + m_selectedNode->GetFloatProperty(mitk::rt::Constants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str(),prescribed); + + vtkSmartPointer transferFunction = vtkSmartPointer::New(); + + mitk::IsoDoseLevelSet::Pointer isoDoseLevelSet = this->m_Presets[this->m_selectedPresetName]; + + float pref; + m_selectedNode->GetFloatProperty(mitk::rt::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(),pref); + + //Generating the Colorwash + for(mitk::IsoDoseLevelSet::ConstIterator setIT = isoDoseLevelSet->Begin(); setIT != isoDoseLevelSet->End(); ++setIT) + { + float *hsv = new float[3]; + //used for transfer rgb to hsv + vtkSmartPointer cCalc = vtkSmartPointer::New(); + if(setIT->GetVisibleColorWash()){ + cCalc->RGBToHSV(setIT->GetColor()[0],setIT->GetColor()[1],setIT->GetColor()[2],&hsv[0],&hsv[1],&hsv[2]); + transferFunction->AddHSVPoint(setIT->GetDoseValue()*pref,hsv[0],hsv[1],hsv[2],1.0,1.0); + } + } + + //Generating the standard isolines + this->UpdateStdIsolines(); + + mitk::TransferFunction::Pointer mitkTransFunc = mitk::TransferFunction::New(); + mitk::TransferFunctionProperty::Pointer mitkTransFuncProp = mitk::TransferFunctionProperty::New(); + mitkTransFunc->SetColorTransferFunction(transferFunction); + mitkTransFuncProp->SetValue(mitkTransFunc); + + mitk::RenderingModeProperty::Pointer renderingMode = mitk::RenderingModeProperty::New(); + renderingMode->SetValue(mitk::RenderingModeProperty::COLORTRANSFERFUNCTION_COLOR); + + selectedNode->SetProperty("Image Rendering.Transfer Function", mitkTransFuncProp); + selectedNode->SetProperty("Image Rendering.Mode", renderingMode); + m_selectedNode->SetProperty("opacity", mitk::FloatProperty::New(0.5)); + + mitk::IsoDoseLevelVector::Pointer levelVector = mitk::IsoDoseLevelVector::New(); + mitk::IsoDoseLevelVectorProperty::Pointer levelVecProp = mitk::IsoDoseLevelVectorProperty::New(levelVector); + selectedNode->SetProperty(mitk::rt::Constants::DOSE_FREE_ISO_VALUES_PROPERTY_NAME.c_str(),levelVecProp); + + UpdateBySelectedNode(); + + mitk::TimeGeometry::Pointer geo = this->GetDataStorage()->ComputeBoundingGeometry3D(this->GetDataStorage()->GetAll()); + mitk::RenderingManager::GetInstance()->InitializeViews( geo ); + } +} + +const mitk::Geometry2D* RTDoseVisualizer::GetGeometry2D(char* dim) +{ + QmitkRenderWindow* rw = this->GetRenderWindowPart()->GetQmitkRenderWindow(dim); + const mitk::Geometry2D* worldGeo = rw->GetRenderer()->GetCurrentWorldGeometry2D(); + return worldGeo; +} + +mitk::Image::Pointer RTDoseVisualizer::GetExtractedSlice(mitk::Image::Pointer image) +{ + mitk::ExtractSliceFilter::Pointer extractFilter = mitk::ExtractSliceFilter::New(); + extractFilter->SetInput(image); + extractFilter->SetWorldGeometry(this->GetGeometry2D("axial")); + extractFilter->SetResliceTransformByGeometry( image->GetTimeGeometry()->GetGeometryForTimeStep(0) ); + extractFilter->Update(); + mitk::Image::Pointer reslicedImage = extractFilter->GetOutput(); + return reslicedImage; +} + +mitk::DataNode::Pointer RTDoseVisualizer::UpdatePolyData(int num, double min, double max) +{ + mitk::Image::Pointer image = dynamic_cast(m_selectedNode->GetData()); + mitk::Image::Pointer reslicedImage = this->GetExtractedSlice(image); + + vtkSmartPointer contourFilter = vtkSmartPointer::New(); + m_Filters.push_back(contourFilter); + contourFilter->SetInputData(reslicedImage->GetVtkImageData()); + contourFilter->GenerateValues(num,min,max); + contourFilter->Update(); + vtkSmartPointer polyData = vtkSmartPointer::New(); + polyData =contourFilter->GetOutput(); + + mitk::Surface::Pointer isoline = mitk::Surface::New(); + isoline->SetVtkPolyData(polyData); +// isoline->SetGeometry(reslicedImage->GetGeometry()->Clone()); + isoline->SetGeometry(reslicedImage->GetGeometry()); + mitk::Vector3D spacing; + spacing.Fill(1); + isoline->GetGeometry()->SetSpacing(spacing); + + mitk::DataNode::Pointer isolineNode = mitk::DataNode::New(); + isolineNode->SetData(isoline); + mitk::SurfaceVtkMapper3D::Pointer mapper = mitk::SurfaceVtkMapper3D::New(); + isolineNode->SetMapper(1, mapper); + isolineNode->SetName("Isoline1"); + isolineNode->SetProperty( "helper object", mitk::BoolProperty::New(true) ); + isolineNode->SetProperty( "line width", mitk::IntProperty::New(1)); + isolineNode->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false)); + isolineNode->SetBoolProperty(mitk::rt::Constants::DOSE_FREE_ISO_VALUES_PROPERTY_NAME.c_str(),true); + m_FreeIsoline = isolineNode; + this->GetDataStorage()->Add(isolineNode); + return isolineNode; +} + +void RTDoseVisualizer::UpdateStdIsolines() +{ + bool isDoseNode = false; + mitk::IsoDoseLevelSet::Pointer isoDoseLevelSet = this->m_Presets[this->m_selectedPresetName]; + mitk::DataNode::Pointer isoDataNode = this->GetIsoDoseNode(); + if(isoDataNode && isoDataNode->GetBoolProperty(mitk::rt::Constants::DOSE_PROPERTY_NAME.c_str(),isDoseNode) && isDoseNode) + { + mitk::Image::Pointer image = dynamic_cast(isoDataNode->GetData()); + mitk::Image::Pointer reslicedImage = this->GetExtractedSlice(image); + + reslicedImage->SetSpacing(image->GetGeometry()->GetSpacing()); + + float pref; + isoDataNode->GetFloatProperty(mitk::rt::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(),pref); + + unsigned int count (0); + for(mitk::IsoDoseLevelSet::ConstIterator doseIT = isoDoseLevelSet->Begin(); doseIT!=isoDoseLevelSet->End();++doseIT) + { + if(doseIT->GetVisibleIsoLine()){ + ++count; + vtkSmartPointer isolineFilter = vtkSmartPointer::New(); + isolineFilter->SetInputData(reslicedImage->GetVtkImageData()); + isolineFilter->GenerateValues(1,doseIT->GetDoseValue()*pref,doseIT->GetDoseValue()*pref); + isolineFilter->Update(); + vtkSmartPointer polyData = vtkSmartPointer::New(); + polyData=isolineFilter->GetOutput(); + + mitk::Surface::Pointer surface = mitk::Surface::New(); + + surface->SetVtkPolyData(polyData); +// surface->SetGeometry(reslicedImage->GetGeometry()->Clone()); + surface->SetGeometry(reslicedImage->GetGeometry()); + mitk::Vector3D spacing; + spacing.Fill(1); + surface->GetGeometry()->SetSpacing(spacing); + + mitk::DataNode::Pointer isoNode = mitk::DataNode::New(); + isoNode->SetData(surface); + mitk::SurfaceVtkMapper3D::Pointer mapper = mitk::SurfaceVtkMapper3D::New(); + mitk::Color color; + color[0]=doseIT->GetColor()[0];color[1]=doseIT->GetColor()[1];color[2]=doseIT->GetColor()[2]; + isoNode->SetMapper(1,mapper); + isoNode->SetColor(color); + isoNode->SetProperty( "helper object", mitk::BoolProperty::New(true) ); + isoNode->SetProperty( "includeInBoundingBox", mitk::BoolProperty::New(false) ); + isoNode->SetProperty( "line width", mitk::IntProperty::New(1)); + std::stringstream strstr; + strstr<<"StdIsoline_"; + strstr<SetName(strstr.str()); + isoNode->SetBoolProperty(mitk::rt::Constants::DOSE_ISO_LEVELS_PROPERTY_NAME.c_str(),true); + m_StdIsoLines.push_back(isoNode); + this->GetDataStorage()->Add(isoNode, isoDataNode); + } + } + } +} + +void RTDoseVisualizer::OnSelectionChanged( berry::IWorkbenchPart::Pointer /*source*/, + const QList& nodes ) +{ + QList dataNodes = this->GetDataManagerSelection(); + + mitk::DataNode* selectedNode = NULL; + + if (!dataNodes.empty()) + { + bool isDoseNode = false; + dataNodes[0]->GetBoolProperty(mitk::rt::Constants::DOSE_PROPERTY_NAME.c_str(),isDoseNode); + + if (isDoseNode) + { + selectedNode = dataNodes[0]; + } + } + + if (selectedNode != m_selectedNode.GetPointer()) + { + m_selectedNode = selectedNode; + } + + UpdateBySelectedNode(); +} + +void RTDoseVisualizer::UpdateBySelectedNode() +{ + m_Controls.groupNodeSpecific->setEnabled(m_selectedNode.IsNotNull()); + m_Controls.groupFreeValues->setEnabled(m_selectedNode.IsNotNull()); + + if(m_selectedNode.IsNull()) + { + m_Controls.NrOfFractions->setText(QString("N/A. No dose selected")); + m_Controls.prescribedDoseSpecific->setText(QString("N/A. No dose selected")); + m_freeIsoValues = mitk::IsoDoseLevelVector::New(); + UpdateFreeIsoValues(); + } + else + { + //dose specific information + int fracCount = 1; + m_selectedNode->GetIntProperty(mitk::rt::Constants::DOSE_FRACTION_COUNT_PROPERTY_NAME.c_str(),fracCount); + m_Controls.NrOfFractions->setText(QString::number(fracCount)); + + m_PrescribedDose_Data = 0.0; + + float tmp; + m_selectedNode->GetFloatProperty(mitk::rt::Constants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str(),tmp); + m_PrescribedDose_Data = (double)tmp; + + m_Controls.prescribedDoseSpecific->setText(QString::number(m_PrescribedDose_Data)); + + //free iso lines + mitk::IsoDoseLevelVectorProperty::Pointer propIsoVector; + m_selectedNode->GetProperty(propIsoVector, mitk::rt::Constants::DOSE_FREE_ISO_VALUES_PROPERTY_NAME.c_str()); + + if (propIsoVector.IsNull()) + { + m_freeIsoValues = mitk::IsoDoseLevelVector::New(); + propIsoVector = mitk::IsoDoseLevelVectorProperty::New(m_freeIsoValues); + m_selectedNode->SetProperty(mitk::rt::Constants::DOSE_FREE_ISO_VALUES_PROPERTY_NAME.c_str(),propIsoVector); + } + else + { + m_freeIsoValues = propIsoVector->GetValue(); + } + + UpdateFreeIsoValues(); + + //global dose issues + bool showIsoLine = false; + m_selectedNode->GetBoolProperty(mitk::rt::Constants::DOSE_SHOW_COLORWASH_PROPERTY_NAME.c_str(),showIsoLine); + m_Controls.checkGlobalVisIsoLine->setChecked(showIsoLine); + + bool showColorWash = false; + m_selectedNode->GetBoolProperty(mitk::rt::Constants::DOSE_SHOW_COLORWASH_PROPERTY_NAME.c_str(),showColorWash); + m_Controls.checkGlobalVisColorWash->setChecked(showColorWash); + + float referenceDose = 0.0; + m_selectedNode->GetFloatProperty(mitk::rt::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(),referenceDose); + m_Controls.spinReferenceDose->setValue(referenceDose); + + mitk::IsoDoseLevelSetProperty::Pointer propIsoSet = + dynamic_cast(m_selectedNode->GetProperty(mitk::rt::Constants::DOSE_ISO_LEVELS_PROPERTY_NAME.c_str())); + + if (propIsoSet) + { + this->m_selectedNodeIsoSet = propIsoSet->GetValue(); + this->m_LevelSetModel->setIsoDoseLevelSet(m_selectedNodeIsoSet); + } + } +} + +void RTDoseVisualizer::UpdateByPreferences() +{ + m_Presets = mitk::rt::LoadPresetsMap(); + m_internalUpdate = true; + m_Controls.comboPresets->clear(); + this->m_selectedPresetName = mitk::rt::GetSelectedPresetName(); + + int index = 0; + int selectedIndex = -1; + for (mitk::rt::PresetMapType::const_iterator pos = m_Presets.begin(); pos != m_Presets.end(); ++pos, ++index) + { + m_Controls.comboPresets->addItem(QString(pos->first.c_str())); + if (this->m_selectedPresetName == pos->first) + { + selectedIndex = index; + } + } + + if (selectedIndex == -1) + { + selectedIndex = 0; + MITK_WARN << "Error. Cannot iso dose level preset specified in preferences does not exist. Preset name: "<m_selectedPresetName; + this->m_selectedPresetName = m_Presets.begin()->first; + mitk::rt::SetSelectedPresetName(this->m_selectedPresetName); + MITK_INFO << "Changed selected iso dose level preset to first existing preset. New preset name: "<m_selectedPresetName; + } + + m_Controls.comboPresets->setCurrentIndex(selectedIndex); + + this->m_selectedNodeIsoSet = this->m_Presets[this->m_selectedPresetName]; + this->m_LevelSetModel->setIsoDoseLevelSet(m_selectedNodeIsoSet); + + mitk::DoseValueAbs referenceDose = 0.0; + bool globalSync = mitk::rt::GetReferenceDoseValue(referenceDose); + if (globalSync || this->m_selectedNode.IsNull()) + { + m_Controls.spinReferenceDose->setValue(referenceDose); + } + + bool displayAbsoluteDose = mitk::rt::GetDoseDisplayAbsolute(); + m_Controls.radioAbsDose->setChecked(displayAbsoluteDose); + m_Controls.radioRelDose->setChecked(!displayAbsoluteDose); + this->m_LevelSetModel->setShowAbsoluteDose(displayAbsoluteDose); + m_internalUpdate = false; +} + +void RTDoseVisualizer::OnCurrentPresetChanged(const QString& presetName) +{ + if (! m_internalUpdate) + { + mitk::rt::SetSelectedPresetName(presetName.toStdString()); + this->UpdateByPreferences(); + this->ActualizeIsoLevelsForAllDoseDataNodes(); + this->UpdateBySelectedNode(); + } +} + +void RTDoseVisualizer::ActualizeIsoLevelsForAllDoseDataNodes() +{ + std::string presetName = mitk::rt::GetSelectedPresetName(); + + mitk::rt::PresetMapType presetMap = mitk::rt::LoadPresetsMap(); + + mitk::NodePredicateProperty::Pointer isDoseNode = mitk::NodePredicateProperty::New(mitk::rt::Constants::DOSE_PROPERTY_NAME.c_str(), mitk::BoolProperty::New(true)); + + mitk::DataStorage::SetOfObjects::ConstPointer nodes = this->GetDataStorage()->GetSubset(isDoseNode); + + mitk::IsoDoseLevelSet* selectedPreset = presetMap[presetName]; + + if (!selectedPreset) + { + mitkThrow() << "Error. Cannot actualize iso dose level preset. Selected preset idoes not exist. Preset name: "<begin(); pos != nodes->end(); ++pos) + { + mitk::IsoDoseLevelSet::Pointer clonedPreset = selectedPreset->Clone(); + mitk::IsoDoseLevelSetProperty::Pointer propIsoSet = mitk::IsoDoseLevelSetProperty::New(clonedPreset); + (*pos)->SetProperty(mitk::rt::Constants::DOSE_ISO_LEVELS_PROPERTY_NAME.c_str(),propIsoSet); + } +} + +void RTDoseVisualizer::ActualizeReferenceDoseForAllDoseDataNodes() +{ + /** @TODO Klären ob diese präsentations info genauso wie*/ + mitk::DoseValueAbs value = 0; + bool sync = mitk::rt::GetReferenceDoseValue(value); + + if (sync) + { + mitk::NodePredicateProperty::Pointer isDoseNode = mitk::NodePredicateProperty::New(mitk::rt::Constants::DOSE_PROPERTY_NAME.c_str(), mitk::BoolProperty::New(true)); + + mitk::DataStorage::SetOfObjects::ConstPointer nodes = this->GetDataStorage()->GetSubset(isDoseNode); + + for(mitk::DataStorage::SetOfObjects::const_iterator pos = nodes->begin(); pos != nodes->end(); ++pos) + { + (*pos)->SetFloatProperty(mitk::rt::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), value); + } + } +} + +void RTDoseVisualizer::ActualizeDisplayStyleForAllDoseDataNodes() +{ + /** @TODO Klären ob diese präsentations info global oder auch per node gespeichert wird*/ +} + +void RTDoseVisualizer::OnHandleCTKEventReferenceDoseChanged(const ctkEvent& event) +{ + mitk::DoseValueAbs referenceDose = 0.0; + bool globalSync = mitk::rt::GetReferenceDoseValue(referenceDose); + + this->m_Controls.spinReferenceDose->setValue(referenceDose); +} + +void RTDoseVisualizer::OnHandleCTKEventPresetsChanged(const ctkEvent& event) +{ + std::string currentPresetName = mitk::rt::GetSelectedPresetName(); + + this->OnCurrentPresetChanged(QString::fromStdString(currentPresetName)); +} diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTDoseVisualizer.h b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTDoseVisualizer.h new file mode 100644 index 0000000000..854feebfd1 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTDoseVisualizer.h @@ -0,0 +1,207 @@ +/*=================================================================== + +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 RTDoseVisualizer_h +#define RTDoseVisualizer_h + +#include + +#include +#include + +#include + +#include "ui_RTDoseVisualizerControls.h" + +#include + +#include + +#include "mitkDoseVisPreferenceHelper.h" + +// Shader +#include +#include +#include + +#include +#include + +#include + +#include +#include + +/*forward declarations*/ +class QmitkIsoDoseLevelSetModel; +class QmitkDoseColorDelegate; +class QmitkDoseValueDelegate; +class QmitkDoseVisualStyleDelegate; +class ctkEvent; + +/** +\brief RTDoseVisualizer + +\warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. + +\sa QmitkAbstractView +\ingroup ${plugin_target}_internal +*/ +class RTDoseVisualizer : public QmitkAbstractView +{ + // this is needed for all Qt objects that should have a Qt meta-object + // (everything that derives from QObject and wants to have signal/slots) + Q_OBJECT + +public: + + RTDoseVisualizer(); + virtual ~RTDoseVisualizer(); + static const std::string VIEW_ID; + + void OnSliceChanged(itk::Object *sender, const itk::EventObject &e); + + protected slots: + + void OnConvertButtonClicked(); + + void OnAddFreeValueClicked(); + + void OnRemoveFreeValueClicked(); + + void OnUsePrescribedDoseClicked(); + + void OnAbsDoseToggled(bool); + + void OnGlobalVisColorWashToggled(bool); + + void OnGlobalVisIsoLineToggled(bool); + + void OnShowContextMenuIsoSet(const QPoint&); + + void OnCurrentPresetChanged(const QString&); + + void OnReferenceDoseChanged(double); + + void OnHandleCTKEventReferenceDoseChanged(const ctkEvent& event); + + void OnHandleCTKEventPresetsChanged(const ctkEvent& event); + + void UpdateFreeIsoLine(mitk::IsoDoseLevel*level, mitk::DoseValueRel old); + + void UpdateFreeIsoLineColor(mitk::IsoDoseLevel* level); + +protected: + + void InitScrolling(); + + virtual void CreateQtPartControl(QWidget *parent); + + virtual void SetFocus(); + + /// \brief called by QmitkFunctionality when DataManager's selection has changed + virtual void OnSelectionChanged( berry::IWorkbenchPart::Pointer source, + const QList& nodes ); + + /** Method updates the list widget according to the current m_freeIsoValues.*/ + void UpdateFreeIsoValues(); + + /** Update the members according to the currently selected node */ + void UpdateBySelectedNode(); + + /** Update the member widgets according to the information stored in the application preferences*/ + void UpdateByPreferences(); + + /**helper function that iterates throug all data nodes and sets there iso level set property + according to the selected preset. + @TODO: should be moved outside the class, to be available for other classes at well.*/ + void ActualizeIsoLevelsForAllDoseDataNodes(); + + /**helper function that iterates throug all data nodes and sets there reference dose value + according to the preference. + @TODO: should be moved outside the class, to be available for other classes at well.*/ + void ActualizeReferenceDoseForAllDoseDataNodes(); + + /**helper function that iterates through all data nodes and sets there dose display style (relative/absolute) + according to the preference. + @TODO: should be moved outside the class, to be available for other classes at well.*/ + void ActualizeDisplayStyleForAllDoseDataNodes(); + + /** + * @brief UpdatePolyData + * @param num + * @param min + * @param max + * @return + */ + mitk::DataNode::Pointer UpdatePolyData(int num, double min, double max); + + mitk::DataNode::Pointer GetIsoDoseNode(); + + /** + * @brief Calculates the isolines for the dose image + * Number, value and color depends on the selected preset + */ + void UpdateStdIsolines(); + + /** + * @brief Get the active axial slice as 2D image + * Uses a mitkExtractSliceFilter for getting the 2D slice of the + * axial view + * @param image the mitkImage which is shown in the axial window + * @return the 2D mitkImage slice + */ + mitk::Image::Pointer GetExtractedSlice(mitk::Image::Pointer image); + + /** + * @brief Get the mitkGeometry2D of a specific render window + * @param dim the name of the render window + * @return the mitkGeometry2D of the render window + */ + const mitk::Geometry2D* GetGeometry2D(char* dim); + + Ui::RTDoseVisualizerControls m_Controls; + mitk::DataNode::Pointer m_selectedNode; + mitk::IsoDoseLevel::Pointer m_FreeIsoValue; + mitk::IsoDoseLevelVector::Pointer m_freeIsoValues; + std::vector m_FreeIsoLines; + std::vector m_StdIsoLines; + /** Iso level set of the current node. Should normaly be a clone of the + * current iso preset. It held as own member because visibility + * settings may differ.*/ + mitk::IsoDoseLevelSet::Pointer m_selectedNodeIsoSet; + mitk::rt::PresetMapType m_Presets; + std::string m_selectedPresetName; + + mitk::DataNode::Pointer m_FreeIsoline; + bool m_FreeIsoAdded; + + /** Prescribed Dose of the selected data.*/ + mitk::DoseValueAbs m_PrescribedDose_Data; + + QmitkIsoDoseLevelSetModel* m_LevelSetModel; + QmitkDoseColorDelegate* m_DoseColorDelegate; + QmitkDoseValueDelegate* m_DoseValueDelegate; + QmitkDoseVisualStyleDelegate* m_DoseVisualDelegate; + + vtkSmartPointer m_freeIsoFilter; + std::vector< vtkSmartPointer > m_Filters; + + bool m_internalUpdate; +}; + +#endif // RTDoseVisualizer_h diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTDoseVisualizerControls.ui b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTDoseVisualizerControls.ui new file mode 100644 index 0000000000..ad64bd4963 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTDoseVisualizerControls.ui @@ -0,0 +1,514 @@ + + + RTDoseVisualizerControls + + + + 0 + 0 + 421 + 651 + + + + + 0 + 0 + + + + QmitkTemplate + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Dose specific information: + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + true + + + 30 Gy + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + true + + + + + + + + + Number of fractions: + + + + + + + Prescribed dose [Gy]: + + + + + + + Use as reference dose + + + + + + + true + + + + + + + + + + + + + 0 + 0 + + + + Free iso lines: + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 16777215 + 110 + + + + + 0 + 25 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + + + Global iso dose visualization: + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + 0 + 0 + + + + + 65 + 0 + + + + Dose display: + + + + + + + + + + + 0 + 0 + + + + + 65 + 0 + + + + Preset style: + + + + + + + + 0 + 0 + + + + + 105 + 0 + + + + Qt::NoFocus + + + Reference dose [Gy]: + + + + + + + + + + 1 + + + 0.100000000000000 + + + 9999.000000000000000 + + + 0.100000000000000 + + + + + + + + + relative [%] + + + true + + + + + + + absolute [Gy] + + + + + + + + + + + false + + + true + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + + 30 + 20 + + + + 80 + + + + + + + + + Global visibility: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Isolines + + + + :/RTUI/eye_open.png + + + + + 24 + 16 + + + + + + + + false + + + Colorwash + + + + :/RTUI/eye_open.png + + + + + 24 + 16 + + + + + + + + + + + + + + + + + + 255 + 0 + 0 + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + 255 + 0 + 0 + + + + + + + + + 120 + 120 + 120 + + + + + + + 120 + 120 + 120 + + + + + + + + Convert node to dose node (for testing only!) + + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTUIPreferencePage.cpp b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTUIPreferencePage.cpp new file mode 100644 index 0000000000..445efc1532 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTUIPreferencePage.cpp @@ -0,0 +1,117 @@ +/*=================================================================== + +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 "RTUIPreferencePage.h" + +#include "mitkRTUIConstants.h" + +#include +#include + +//----------------------------------------------------------------------------- +RTUIPreferencePage::RTUIPreferencePage() + : m_MainControl(0), m_Controls(0) +{ + +} + + +//----------------------------------------------------------------------------- +RTUIPreferencePage::~RTUIPreferencePage() +{ + delete m_Controls; +} + + +//----------------------------------------------------------------------------- +void RTUIPreferencePage::Init(berry::IWorkbench::Pointer ) +{ + +} + + +//----------------------------------------------------------------------------- +void RTUIPreferencePage::CreateQtControl(QWidget* parent) +{ + berry::IPreferencesService::Pointer prefService + = berry::Platform::GetServiceRegistry() + .GetServiceById(berry::IPreferencesService::ID); + + m_PreferencesNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_PREFERENCE_NODE_ID); + + m_MainControl = new QWidget(parent); + m_Controls = new Ui::RTUIPreferencePageControls; + m_Controls->setupUi( m_MainControl ); + + connect(m_Controls->radioDefault, SIGNAL(toggled(bool)), m_Controls->spinDefault, SLOT(setEnabled(bool))); + connect(m_Controls->radioRelativeToMax, SIGNAL(toggled(bool)), m_Controls->spinRelativeToMax, SLOT(setEnabled(bool))); + + this->Update(); +} + + +//----------------------------------------------------------------------------- +QWidget* RTUIPreferencePage::GetQtControl() const +{ + return m_MainControl; +} + +//----------------------------------------------------------------------------- +bool RTUIPreferencePage::PerformOk() +{ + bool useAsDefaultValue = m_Controls->radioDefault->isChecked(); + m_PreferencesNode->PutBool(mitk::rt::UIConstants::UNKNOWN_PRESCRIBED_DOSE_HANDLING_AS_DEFAULT_ID,useAsDefaultValue); + + if (useAsDefaultValue) + { + m_PreferencesNode->PutDouble(mitk::rt::UIConstants::UNKNOWN_PRESCRIBED_DOSE_HANDLING_VALUE_ID, m_Controls->spinDefault->value()); + } + else + { + m_PreferencesNode->PutDouble(mitk::rt::UIConstants::UNKNOWN_PRESCRIBED_DOSE_HANDLING_VALUE_ID, m_Controls->spinRelativeToMax->value()/100.0); + } + + return true; +} + + +//----------------------------------------------------------------------------- +void RTUIPreferencePage::PerformCancel() +{ +} + + +//----------------------------------------------------------------------------- +void RTUIPreferencePage::Update() +{ + bool useAsDefaultValue = m_PreferencesNode->GetBool(mitk::rt::UIConstants::UNKNOWN_PRESCRIBED_DOSE_HANDLING_AS_DEFAULT_ID, true); + double doseValue = m_PreferencesNode->GetDouble(mitk::rt::UIConstants::UNKNOWN_PRESCRIBED_DOSE_HANDLING_VALUE_ID, 50.0); + + m_Controls->radioDefault->setChecked(useAsDefaultValue); + m_Controls->radioRelativeToMax->setChecked(!useAsDefaultValue); + m_Controls->spinDefault->setEnabled(useAsDefaultValue); + m_Controls->spinRelativeToMax->setEnabled(!useAsDefaultValue); + + if (useAsDefaultValue) + { + m_Controls->spinDefault->setValue(doseValue); + } + else + { + m_Controls->spinRelativeToMax->setValue(doseValue*100.0); + } +} diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTUIPreferencePage.h b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTUIPreferencePage.h new file mode 100644 index 0000000000..208a41773f --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTUIPreferencePage.h @@ -0,0 +1,85 @@ +/*=================================================================== + +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 __RT_UI_PREFERENCE_PAGE_H +#define __RT_UI_PREFERENCE_PAGE_H + +#include "berryIQtPreferencePage.h" +#include "berryIPreferences.h" + +#include "ui_RTUIPreferencePageControls.h" + +class QWidget; + +/** +* \class RTUIPreferencePage +* \brief Preference page for general RT visualization settings. +*/ +class RTUIPreferencePage : public QObject, public berry::IQtPreferencePage +{ + Q_OBJECT + Q_INTERFACES(berry::IPreferencePage) + +public: + RTUIPreferencePage(); + ~RTUIPreferencePage(); + + /** + * \brief Called by framework to initialize this preference page, but currently does nothing. + * \param workbench The workbench. + */ + void Init(berry::IWorkbench::Pointer workbench); + + /** + * \brief Called by framework to create the GUI, and connect signals and slots. + * \param widget The Qt widget that acts as parent to all GUI components, as this class itself is not derived from QWidget. + */ + void CreateQtControl(QWidget* widget); + + /** + * \brief Required by framework to get hold of the GUI. + * \return QWidget* the top most QWidget for the GUI. + */ + QWidget* GetQtControl() const; + + /** + * \see IPreferencePage::PerformOk + */ + virtual bool PerformOk(); + + /** + * \see IPreferencePage::PerformCancel + */ + virtual void PerformCancel(); + + /** + * \see IPreferencePage::Update + */ + virtual void Update(); + + public slots: + +protected: + + QWidget *m_MainControl; + Ui::RTUIPreferencePageControls* m_Controls; + + berry::IPreferences::Pointer m_PreferencesNode; + +}; + +#endif diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTUIPreferencePageControls.ui b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTUIPreferencePageControls.ui new file mode 100644 index 0000000000..efd18081ca --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/RTUIPreferencePageControls.ui @@ -0,0 +1,86 @@ + + + RTUIPreferencePageControls + + + + 0 + 0 + 403 + 438 + + + + Form + + + + + + Handling of unkown prescribed dose: + + + + + + false + + + % + + + 200.000000000000000 + + + 80.000000000000000 + + + + + + + set to default value: + + + + + + + set relative to max dose: + + + + + + + Gy + + + 9999.000000000000000 + + + 50.000000000000000 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/mitkDoseVisPreferenceHelper.cpp b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/mitkDoseVisPreferenceHelper.cpp new file mode 100644 index 0000000000..a8d01b1fd1 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/mitkDoseVisPreferenceHelper.cpp @@ -0,0 +1,245 @@ +/*=================================================================== + +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 "mitkDoseVisPreferenceHelper.h" +#include "mitkRTUIConstants.h" +#include "mitkIsoLevelsGenerator.h" + + +#include + +#include + +#include +#include + +void mitk::rt::StorePresetsMap(const PresetMapType& presetMap) +{ + berry::IPreferencesService::Pointer prefService = + berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID); + + berry::IPreferences::Pointer doseVisNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID); + berry::IPreferences::Pointer presetsNode = doseVisNode->Node(mitk::rt::UIConstants::ROOT_ISO_PRESETS_PREFERENCE_NODE_ID); + + presetsNode->RemoveNode(); + doseVisNode->Flush(); + + //new empty preset node + presetsNode = doseVisNode->Node(mitk::rt::UIConstants::ROOT_ISO_PRESETS_PREFERENCE_NODE_ID); + + //store map in new node + for (PresetMapType::const_iterator pos = presetMap.begin(); pos != presetMap.end(); ++pos) + { + berry::IPreferences::Pointer aPresetNode = presetsNode->Node(pos->first); + + unsigned int id = 0; + + for (mitk::IsoDoseLevelSet::ConstIterator levelPos = pos->second->Begin(); levelPos != pos->second->End(); ++levelPos, ++id ) + { + std::ostringstream stream; + stream << id; + + berry::IPreferences::Pointer levelNode = aPresetNode->Node(stream.str()); + + levelNode->PutDouble(mitk::rt::UIConstants::ISO_LEVEL_DOSE_VALUE_ID,levelPos->GetDoseValue()); + levelNode->PutFloat(mitk::rt::UIConstants::ISO_LEVEL_COLOR_RED_ID,levelPos->GetColor().GetRed()); + levelNode->PutFloat(mitk::rt::UIConstants::ISO_LEVEL_COLOR_GREEN_ID,levelPos->GetColor().GetGreen()); + levelNode->PutFloat(mitk::rt::UIConstants::ISO_LEVEL_COLOR_BLUE_ID,levelPos->GetColor().GetBlue()); + levelNode->PutBool(mitk::rt::UIConstants::ISO_LEVEL_VISIBILITY_ISOLINES_ID,levelPos->GetVisibleIsoLine()); + levelNode->PutBool(mitk::rt::UIConstants::ISO_LEVEL_VISIBILITY_COLORWASH_ID,levelPos->GetVisibleColorWash()); + levelNode->Flush(); + } + + aPresetNode->Flush(); + } + + presetsNode->Flush(); +} + +mitk::rt::PresetMapType mitk::rt::LoadPresetsMap() +{ + berry::IPreferencesService::Pointer prefService = + berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID); + + berry::IPreferences::Pointer presetsNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_ISO_PRESETS_PREFERENCE_NODE_ID); + + typedef std::vector NamesType; + NamesType names = presetsNode->ChildrenNames(); + + PresetMapType presetMap; + + for (NamesType::const_iterator pos = names.begin(); pos != names.end(); ++pos) + { + berry::IPreferences::Pointer aPresetNode = presetsNode->Node(*pos); + + if (aPresetNode.IsNull()) + { + mitkThrow()<< "Error in preference interface. Cannot find preset node under given name. Name: "<<*pos; + } + + mitk::IsoDoseLevelSet::Pointer levelSet = mitk::IsoDoseLevelSet::New(); + + NamesType levelNames = aPresetNode->ChildrenNames(); + for (NamesType::const_iterator levelName = levelNames.begin(); levelName != levelNames.end(); ++levelName) + { + berry::IPreferences::Pointer levelNode = aPresetNode->Node(*levelName); + if (aPresetNode.IsNull()) + { + mitkThrow()<< "Error in preference interface. Cannot find level node under given preset name. Name: "<<*pos<<"; Level id: "<<*levelName; + } + + mitk::IsoDoseLevel::Pointer isoLevel = mitk::IsoDoseLevel::New(); + + isoLevel->SetDoseValue(levelNode->GetDouble(mitk::rt::UIConstants::ISO_LEVEL_DOSE_VALUE_ID,0.0)); + mitk::IsoDoseLevel::ColorType color; + color.SetRed(levelNode->GetFloat(mitk::rt::UIConstants::ISO_LEVEL_COLOR_RED_ID,1.0)); + color.SetGreen(levelNode->GetFloat(mitk::rt::UIConstants::ISO_LEVEL_COLOR_GREEN_ID,1.0)); + color.SetBlue(levelNode->GetFloat(mitk::rt::UIConstants::ISO_LEVEL_COLOR_BLUE_ID,1.0)); + isoLevel->SetColor(color); + isoLevel->SetVisibleIsoLine(levelNode->GetBool(mitk::rt::UIConstants::ISO_LEVEL_VISIBILITY_ISOLINES_ID,true)); + isoLevel->SetVisibleColorWash(levelNode->GetBool(mitk::rt::UIConstants::ISO_LEVEL_VISIBILITY_COLORWASH_ID,true)); + + levelSet->SetIsoDoseLevel(isoLevel); + } + + presetMap.insert(std::make_pair(*pos,levelSet)); + } + + if (presetMap.size() == 0) + { //if there are no presets use fallback and store it. + presetMap = mitk::rt::GenerateDefaultPresetsMap(); + StorePresetsMap(presetMap); + } + + return presetMap; +} + +mitk::rt::PresetMapType mitk::rt::GenerateDefaultPresetsMap() +{ + mitk::rt::PresetMapType result; + + result.insert(std::make_pair(std::string("Virtuos"), mitk::rt::GeneratIsoLevels_Virtuos())); + return result; +} + +std::string mitk::rt::GetSelectedPresetName() +{ + berry::IPreferencesService::Pointer prefService = + berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID); + + berry::IPreferences::Pointer prefNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID); + + std::string result = prefNode->Get(mitk::rt::UIConstants::SELECTED_ISO_PRESET_ID, ""); + + return result; +} + +void mitk::rt::SetSelectedPresetName(const std::string& presetName) +{ + berry::IPreferencesService::Pointer prefService = + berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID); + + berry::IPreferences::Pointer prefNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID); + berry::IPreferences::Pointer presetsNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_ISO_PRESETS_PREFERENCE_NODE_ID); + + typedef std::vector NamesType; + NamesType presetNames = presetsNode->ChildrenNames(); + + NamesType::iterator finding = std::find(presetNames.begin(),presetNames.end(),presetName); + + if (finding == presetNames.end()) + { + mitkThrow()<< "Error. Tried to set invalid selected preset name. Preset name does not exist in the defined presets. Preset name: "<Put(mitk::rt::UIConstants::SELECTED_ISO_PRESET_ID,presetName); +} + +bool mitk::rt::GetReferenceDoseValue(mitk::DoseValueAbs& value) +{ + berry::IPreferencesService::Pointer prefService = + berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID); + + berry::IPreferences::Pointer prefNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID); + + bool result = prefNode->GetBool(mitk::rt::UIConstants::GLOBAL_REFERENCE_DOSE_SYNC_ID, true); + value = prefNode->GetDouble(mitk::rt::UIConstants::REFERENCE_DOSE_ID, mitk::rt::UIConstants::DEFAULT_REFERENCE_DOSE_VALUE); + + return result; +} + +void mitk::rt::SetReferenceDoseValue(bool globalSync, mitk::DoseValueAbs value) +{ + berry::IPreferencesService::Pointer prefService = + berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID); + + berry::IPreferences::Pointer prefNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID); + + prefNode->PutBool(mitk::rt::UIConstants::GLOBAL_REFERENCE_DOSE_SYNC_ID, globalSync); + if (value >= 0) + { + prefNode->PutDouble(mitk::rt::UIConstants::REFERENCE_DOSE_ID, value); + } +} + + +bool mitk::rt::GetDoseDisplayAbsolute() +{ + berry::IPreferencesService::Pointer prefService = + berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID); + + berry::IPreferences::Pointer prefNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID); + + bool result = prefNode->GetBool(mitk::rt::UIConstants::DOSE_DISPLAY_ABSOLUTE_ID, false); + + return result; +} + +void mitk::rt::SetDoseDisplayAbsolute(bool isAbsolute) +{ + berry::IPreferencesService::Pointer prefService = + berry::Platform::GetServiceRegistry().GetServiceById(berry::IPreferencesService::ID); + + berry::IPreferences::Pointer prefNode = prefService->GetSystemPreferences()->Node(mitk::rt::UIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID); + + prefNode->PutBool(mitk::rt::UIConstants::DOSE_DISPLAY_ABSOLUTE_ID, isAbsolute); +} + +void mitk::rt::SignalReferenceDoseChange(bool globalSync, mitk::DoseValueAbs value, ctkPluginContext* context) +{ + ctkServiceReference ref = context->getServiceReference(); + if (ref) + { + ctkEventAdmin* eventAdmin = context->getService(ref); + ctkProperties props; + props["value"] = value; + props["globalSync"] = globalSync; + ctkEvent presetMapChangedEvent(mitk::rt::CTKEventConstants::TOPIC_REFERENCE_DOSE_CHANGED.c_str()); + eventAdmin->sendEvent(presetMapChangedEvent); + } +} + +void mitk::rt::SignalPresetMapChange(ctkPluginContext* context) +{ + ctkServiceReference ref = context->getServiceReference(); + if (ref) + { + ctkEventAdmin* eventAdmin = context->getService(ref); + ctkEvent presetMapChangedEvent(mitk::rt::CTKEventConstants::TOPIC_ISO_DOSE_LEVEL_PRESETS_CHANGED.c_str()); + eventAdmin->sendEvent(presetMapChangedEvent); + } +} diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/mitkDoseVisPreferenceHelper.h b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/mitkDoseVisPreferenceHelper.h new file mode 100644 index 0000000000..ebf9c734b4 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/mitkDoseVisPreferenceHelper.h @@ -0,0 +1,74 @@ +/*=================================================================== + +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 __DOSE_VIS_PREFERENCE_HELPER_H +#define __DOSE_VIS_PREFERENCE_HELPER_H + +#include +#include + +#include "mitkIsoDoseLevelCollections.h" + +class ctkPluginContext; + +namespace mitk +{ + namespace rt + { + typedef std::map PresetMapType; + + /** Stores the given preset map in the application preferences. */ + void StorePresetsMap(const PresetMapType& presetMap); + + /** Loads all defined iso dose level presets from the preferences and stores them + in a map. Key is the name of the preset. + @remark If no presets are stored in the preferences this function will generate default presets + (using GenerateDefaultPresetsMap()) and the stores it in the preferences (to guarantee a consistent state) + before passing the default presets back.*/ + PresetMapType LoadPresetsMap(); + + /** Generate the default presets map.*/ + PresetMapType GenerateDefaultPresetsMap(); + + /**Retrieves the name of the preset, that is currently selected for the application, from the preferences.*/ + std::string GetSelectedPresetName(); + + /** checks if the passed name exists in the preset map. If not an exception is thrown. If it exists, the new + * value will be set.*/ + void SetSelectedPresetName(const std::string& presetName); + + /** retrieves the reference dose from the preferences and indicates if global sync for reference dose is activated + or not. + @param value The reference dose value stored in the preferences. + @return Indicator for global sync. True: global sync activated -> preference value is relevant. + False: global sync deactivated. Value is irrelevant. Each node has its own value.*/ + bool GetReferenceDoseValue(DoseValueAbs& value); + /** Sets the global sync setting and dose reference value in the preferences. + * @param globalSync Indicator if global sync should be set active (true) or inactive (false). If it is true, the value is irrelevant (but will be set). + * @param value The dose reference value that should be stored in the preferences.If set to <0 it will be ignored and not changed/set.*/ + void SetReferenceDoseValue(bool globalSync, DoseValueAbs value = -1); + + bool GetDoseDisplayAbsolute(); + void SetDoseDisplayAbsolute(bool isAbsolute); + + void SignalReferenceDoseChange(bool globalSync, mitk::DoseValueAbs value, ctkPluginContext* context); + void SignalPresetMapChange(ctkPluginContext* context); + + } +} + +#endif diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/org_mitk_gui_qt_rt_dosevisualization_Activator.cpp b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/org_mitk_gui_qt_rt_dosevisualization_Activator.cpp new file mode 100644 index 0000000000..eb0e2631cc --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/org_mitk_gui_qt_rt_dosevisualization_Activator.cpp @@ -0,0 +1,55 @@ +/*=================================================================== + +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 "org_mitk_gui_qt_rt_dosevisualization_Activator.h" + +#include + +#include "RTDoseVisualizer.h" +#include "RTUIPreferencePage.h" +#include "DoseVisualizationPreferencePage.h" +#include "LoadingRTView.h" + +namespace mitk { + + ctkPluginContext* org_mitk_gui_qt_rt_dosevisualization_Activator::m_Context = NULL; + + void org_mitk_gui_qt_rt_dosevisualization_Activator::start(ctkPluginContext* context) + { + BERRY_REGISTER_EXTENSION_CLASS(RTDoseVisualizer, context); + BERRY_REGISTER_EXTENSION_CLASS(RTUIPreferencePage, context) + BERRY_REGISTER_EXTENSION_CLASS(DoseVisualizationPreferencePage, context) + BERRY_REGISTER_EXTENSION_CLASS(LoadingRTView, context) + + m_Context = context; + } + + void org_mitk_gui_qt_rt_dosevisualization_Activator::stop(ctkPluginContext* context) + { + Q_UNUSED(context); + + m_Context = NULL; + } + + ctkPluginContext* org_mitk_gui_qt_rt_dosevisualization_Activator::GetContext() + { + return m_Context; + } + +} + +Q_EXPORT_PLUGIN2(org_mitk_gui_qt_rt_dosevisualization, mitk::org_mitk_gui_qt_rt_dosevisualization_Activator) diff --git a/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/org_mitk_gui_qt_rt_dosevisualization_Activator.h b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/org_mitk_gui_qt_rt_dosevisualization_Activator.h new file mode 100644 index 0000000000..f0f1449354 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.rt.dosevisualization/src/internal/org_mitk_gui_qt_rt_dosevisualization_Activator.h @@ -0,0 +1,46 @@ +/*=================================================================== + +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 org_mitk_gui_qt_rt_dosevisualization_Activator_h +#define org_mitk_gui_qt_rt_dosevisualization_Activator_h + +#include + +namespace mitk { + + class org_mitk_gui_qt_rt_dosevisualization_Activator : + public QObject, public ctkPluginActivator + { + Q_OBJECT + Q_INTERFACES(ctkPluginActivator) + + public: + + void start(ctkPluginContext* context); + void stop(ctkPluginContext* context); + + static ctkPluginContext* GetContext(); + + private: + + static ctkPluginContext* m_Context; + + }; // org_mitk_gui_qt_rt_dosevisualization_Activator + +} + +#endif // org_mitk_gui_qt_rt_dosevisualization_Activator_h