diff --git a/Plugins/org.mitk.gui.qt.imagecropper/CMakeLists.txt b/Plugins/org.mitk.gui.qt.imagecropper/CMakeLists.txt index 4d2a1eebde..c6772ccead 100644 --- a/Plugins/org.mitk.gui.qt.imagecropper/CMakeLists.txt +++ b/Plugins/org.mitk.gui.qt.imagecropper/CMakeLists.txt @@ -1,8 +1,8 @@ project(org_mitk_gui_qt_imagecropper) mitk_create_plugin( EXPORT_DIRECTIVE MITK_QT_IMAGECROPPER EXPORTED_INCLUDE_SUFFIXES src - MODULE_DEPENDS MitkQtWidgetsExt MitkBoundingShape MitkMultilabel + MODULE_DEPENDS MitkQtWidgetsExt MitkBoundingShape MitkMultilabel MitkROI ) diff --git a/Plugins/org.mitk.gui.qt.imagecropper/files.cmake b/Plugins/org.mitk.gui.qt.imagecropper/files.cmake index 59435c5859..58e89a3b01 100644 --- a/Plugins/org.mitk.gui.qt.imagecropper/files.cmake +++ b/Plugins/org.mitk.gui.qt.imagecropper/files.cmake @@ -1,32 +1,34 @@ set(INTERNAL_CPP_FILES mitkPluginActivator.cpp QmitkImageCropperView.cpp + QmitkConvertGeometryDataToROIAction.cpp ) set(UI_FILES src/internal/QmitkImageCropperViewControls.ui ) set(MOC_H_FILES src/internal/mitkPluginActivator.h src/internal/QmitkImageCropperView.h + src/internal/QmitkConvertGeometryDataToROIAction.h ) set(CACHED_RESOURCE_FILES resources/crop.svg plugin.xml ) set(QRC_FILES resources/imagecropper.qrc ) 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.imagecropper/manifest_headers.cmake b/Plugins/org.mitk.gui.qt.imagecropper/manifest_headers.cmake index 8211a4fb19..dc360f2d35 100644 --- a/Plugins/org.mitk.gui.qt.imagecropper/manifest_headers.cmake +++ b/Plugins/org.mitk.gui.qt.imagecropper/manifest_headers.cmake @@ -1,5 +1,5 @@ set(Plugin-Name "MITK Image Cropper") set(Plugin-Version "1.0.0") set(Plugin-Vendor "German Cancer Research Center (DKFZ)") set(Plugin-ContactAddress "https://www.mitk.org") -set(Require-Plugin org.mitk.gui.qt.common) +set(Require-Plugin org.mitk.gui.qt.common org.mitk.gui.qt.application) diff --git a/Plugins/org.mitk.gui.qt.imagecropper/plugin.xml b/Plugins/org.mitk.gui.qt.imagecropper/plugin.xml index ccc04b49d1..3974b6148f 100644 --- a/Plugins/org.mitk.gui.qt.imagecropper/plugin.xml +++ b/Plugins/org.mitk.gui.qt.imagecropper/plugin.xml @@ -1,27 +1,31 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <plugin> <extension point="org.blueberry.ui.views"> <view id="org.mitk.views.imagecropper" name="Image Cropper" category="General" icon="resources/crop.svg" class="QmitkImageCropperView" > <description>Crop images to a given size</description> <keywordReference id="org.mitk.views.imagecropper.ViewKeyword"/> </view> </extension> + <extension point="org.mitk.gui.qt.datamanager.contextMenuActions"> + <contextMenuAction nodeDescriptorName="GeometryData" label="Convert to ROI" icon="" class="QmitkConvertGeometryDataToROIAction" /> + </extension> + <extension point="org.blueberry.ui.keywords"> <keyword id="org.mitk.views.imagecropper.ViewKeyword" label="Size" /> <keyword id="org.mitk.views.imagecropper.ViewKeyword" label="Match Size" /> <keyword id="org.mitk.views.imagecropper.ViewKeyword" label="Resizing" /> <keyword id="org.mitk.views.imagecropper.ViewKeyword" label="Changing Dimension" /> <keyword id="org.mitk.views.imagecropper.ViewKeyword" label="Image Dimension" /> <keyword id="org.mitk.views.imagecropper.ViewKeyword" label="Image cropping" /> </extension> </plugin> diff --git a/Plugins/org.mitk.gui.qt.imagecropper/src/internal/QmitkConvertGeometryDataToROIAction.cpp b/Plugins/org.mitk.gui.qt.imagecropper/src/internal/QmitkConvertGeometryDataToROIAction.cpp new file mode 100644 index 0000000000..50fcc3a3e1 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.imagecropper/src/internal/QmitkConvertGeometryDataToROIAction.cpp @@ -0,0 +1,96 @@ +/*============================================================================ + +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 "QmitkConvertGeometryDataToROIAction.h" + +#include <mitkGeometryData.h> +#include <mitkImage.h> +#include <mitkNodePredicateDataType.h> + +#include <QMessageBox> + +namespace +{ + void handleInvalidNodeSelection() + { + auto message = QStringLiteral("All selected bounding boxes must be child nodes of a single common reference image!"); + MITK_ERROR << message; + QMessageBox::warning(nullptr, QStringLiteral("Convert to ROI"), message); + } + + std::vector<const mitk::DataNode*> filterNodeSelection(const QList<mitk::DataNode::Pointer>& selectedNodes, const mitk::DataStorage* dataStorage) + { + std::vector<const mitk::DataNode*> result; + + std::copy_if(selectedNodes.cbegin(), selectedNodes.cend(), std::back_inserter(result), [](const mitk::DataNode* node) { + return node != nullptr && dynamic_cast<mitk::GeometryData*>(node->GetData()) != nullptr; + }); + + const mitk::Image* referenceImage = nullptr; + + for (auto node : result) + { + auto sources = dataStorage->GetSources(node, mitk::TNodePredicateDataType<mitk::Image>::New()); + + if (sources->size() != 1) + mitkThrow(); + + if (referenceImage == nullptr) + { + referenceImage = static_cast<mitk::Image*>(sources->front()->GetData()); + } + else if (referenceImage != sources->front()->GetData()) + { + mitkThrow(); + } + } + + return result; + } +} + +QmitkConvertGeometryDataToROIAction::QmitkConvertGeometryDataToROIAction() +{ +} + +QmitkConvertGeometryDataToROIAction::~QmitkConvertGeometryDataToROIAction() +{ +} + +void QmitkConvertGeometryDataToROIAction::Run(const QList<mitk::DataNode::Pointer>& selectedNodes) +{ + try + { + auto nodes = filterNodeSelection(selectedNodes, m_DataStorage); + } + catch (const mitk::Exception&) + { + handleInvalidNodeSelection(); + } +} + +void QmitkConvertGeometryDataToROIAction::SetDataStorage(mitk::DataStorage* dataStorage) +{ + m_DataStorage = dataStorage; +} + +void QmitkConvertGeometryDataToROIAction::SetFunctionality(berry::QtViewPart*) +{ +} + +void QmitkConvertGeometryDataToROIAction::SetSmoothed(bool) +{ +} + +void QmitkConvertGeometryDataToROIAction::SetDecimated(bool) +{ +} diff --git a/Plugins/org.mitk.gui.qt.imagecropper/src/internal/QmitkConvertGeometryDataToROIAction.h b/Plugins/org.mitk.gui.qt.imagecropper/src/internal/QmitkConvertGeometryDataToROIAction.h new file mode 100644 index 0000000000..8797841a76 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.imagecropper/src/internal/QmitkConvertGeometryDataToROIAction.h @@ -0,0 +1,37 @@ +/*============================================================================ + +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 QmitkConvertGeometryDataToROIAction_h +#define QmitkConvertGeometryDataToROIAction_h + +#include <mitkIContextMenuAction.h> + +class QmitkConvertGeometryDataToROIAction : public QObject, public mitk::IContextMenuAction +{ + Q_OBJECT + Q_INTERFACES(mitk::IContextMenuAction) + +public: + QmitkConvertGeometryDataToROIAction(); + ~QmitkConvertGeometryDataToROIAction() override; + + void Run(const QList<mitk::DataNode::Pointer>& selectedNodes) override; + void SetDataStorage(mitk::DataStorage* dataStorage) override; + void SetFunctionality(berry::QtViewPart* functionality) override; + void SetSmoothed(bool smoothed) override; + void SetDecimated(bool decimated) override; + +private: + mitk::DataStorage::Pointer m_DataStorage; +}; + +#endif diff --git a/Plugins/org.mitk.gui.qt.imagecropper/src/internal/mitkPluginActivator.cpp b/Plugins/org.mitk.gui.qt.imagecropper/src/internal/mitkPluginActivator.cpp index 0902061f1c..291f8f1849 100644 --- a/Plugins/org.mitk.gui.qt.imagecropper/src/internal/mitkPluginActivator.cpp +++ b/Plugins/org.mitk.gui.qt.imagecropper/src/internal/mitkPluginActivator.cpp @@ -1,26 +1,28 @@ /*============================================================================ 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 <mitkBoundingShapeObjectFactory.h> #include "mitkPluginActivator.h" #include "QmitkImageCropperView.h" +#include "QmitkConvertGeometryDataToROIAction.h" void mitk::mitkPluginActivator::start(ctkPluginContext* context) { RegisterBoundingShapeObjectFactory(); BERRY_REGISTER_EXTENSION_CLASS(QmitkImageCropperView, context) + BERRY_REGISTER_EXTENSION_CLASS(QmitkConvertGeometryDataToROIAction, context) } void mitk::mitkPluginActivator::stop(ctkPluginContext*) { }