diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp index 076eb3d29b..c596f9ead7 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp @@ -1,158 +1,144 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include // mitk core #include #include #include #include #include // mitk gui common plugin #include // qt #include QmitkDataNodeColorMapAction::QmitkDataNodeColorMapAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { setText(tr("Colormap")); InitializeAction(); } QmitkDataNodeColorMapAction::QmitkDataNodeColorMapAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { setText(tr("Colormap")); InitializeAction(); } void QmitkDataNodeColorMapAction::InitializeAction() { setCheckable(true); setMenu(new QMenu); connect(menu(), &QMenu::aboutToShow, this, &QmitkDataNodeColorMapAction::OnMenuAboutShow); } void QmitkDataNodeColorMapAction::OnMenuAboutShow() { auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } mitk::BaseRenderer::Pointer baseRenderer = GetBaseRenderer(); mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast(dataNode->GetProperty("LookupTable", baseRenderer)); if (lookupTableProperty.IsNull()) { mitk::LookupTable::Pointer mitkLut = mitk::LookupTable::New(); lookupTableProperty = mitk::LookupTableProperty::New(); lookupTableProperty->SetLookupTable(mitkLut); dataNode->SetProperty("LookupTable", lookupTableProperty, baseRenderer); } mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue(); if (lookupTable.IsNull()) { return; } menu()->clear(); QAction* lutAction; for (const auto& lutTypeString : lookupTable->typenameList) { lutAction = menu()->addAction(QString::fromStdString(lutTypeString)); lutAction->setCheckable(true); if (lutTypeString == lookupTable->GetActiveTypeAsString()) { lutAction->setChecked(true); } connect(lutAction, &QAction::triggered, this, &QmitkDataNodeColorMapAction::OnActionTriggered); } } void QmitkDataNodeColorMapAction::OnActionTriggered(bool /*checked*/) { mitk::BaseRenderer::Pointer baseRenderer = GetBaseRenderer(); auto selectedNodes = GetSelectedNodes(); for (auto& dataNode : selectedNodes) { if (dataNode.IsNull()) { continue; } mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast(dataNode->GetProperty("LookupTable", baseRenderer)); if (lookupTableProperty.IsNull()) { continue; } mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue(); if (lookupTable.IsNull()) { continue; } mitk::LookupTable::Pointer renderWindowSpecificLuT = lookupTable->Clone(); QAction* senderAction = qobject_cast(QObject::sender()); if (nullptr == senderAction) { continue; } // set lookup table type defined by the action string std::string activatedItem = senderAction->text().toStdString(); renderWindowSpecificLuT->SetType(activatedItem); dataNode->SetProperty("LookupTable", mitk::LookupTableProperty::New(renderWindowSpecificLuT), baseRenderer); - if (mitk::LookupTable::LookupTableType::MULTILABEL == lookupTable->GetActiveType()) - { - // special case: multilabel => set the level window to include the whole pixel range - UseWholePixelRange(dataNode); - } - mitk::RenderingModeProperty::Pointer renderingMode = dynamic_cast(dataNode->GetProperty("Image Rendering.Mode", baseRenderer)); - renderingMode->SetValue(mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR); + + renderingMode->SetValue(mitk::LookupTable::LookupTableType::MULTILABEL != renderWindowSpecificLuT->GetActiveType() + ? mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR + : mitk::RenderingModeProperty::LOOKUPTABLE_COLOR); if (nullptr == baseRenderer) { mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } else { mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow()); } } } - -void QmitkDataNodeColorMapAction::UseWholePixelRange(mitk::DataNode* node) -{ - auto image = dynamic_cast(node->GetData()); - if (nullptr != image) - { - mitk::LevelWindow levelWindow; - levelWindow.SetToImageRange(image); - node->SetLevelWindow(levelWindow); - } -} diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.h index 9645994164..486829b68c 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.h +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.h @@ -1,48 +1,46 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef QMITKDATANODECOLORMAPACTION_H #define QMITKDATANODECOLORMAPACTION_H #include #include "QmitkAbstractDataNodeAction.h" // mitk core #include // qt #include class MITK_QT_APP QmitkDataNodeColorMapAction : public QAction, public QmitkAbstractDataNodeAction { Q_OBJECT public: QmitkDataNodeColorMapAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); QmitkDataNodeColorMapAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); private Q_SLOTS: void OnMenuAboutShow(); void OnActionTriggered(bool); protected: void InitializeAction() override; - void UseWholePixelRange(mitk::DataNode* node); - }; #endif // QMITKDATANODECOLORMAPACTION_H