diff --git a/Modules/Segmentation/Algorithms/mitkSegmentationHelper.cpp b/Modules/Segmentation/Algorithms/mitkSegmentationHelper.cpp new file mode 100644 index 0000000000..c65ac2c200 --- /dev/null +++ b/Modules/Segmentation/Algorithms/mitkSegmentationHelper.cpp @@ -0,0 +1,45 @@ +/*============================================================================ + +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 "mitkSegmentationHelper.h" + +#include +#include +#include + +mitk::Image::Pointer mitk::SegmentationHelper::GetStaticSegmentationTemplate(const Image* referenceImage) +{ + if (referenceImage == nullptr) + return nullptr; + + const auto* referenceGeometry = referenceImage->GetTimeGeometry(); + + const auto timePoint = mitk::RenderingManager::GetInstance()->GetTimeNavigationController()->GetSelectedTimePoint(); + const auto timeStep = referenceGeometry->IsValidTimePoint(timePoint) + ? referenceGeometry->TimePointToTimeStep(timePoint) + : 0; + + auto geometry = ProportionalTimeGeometry::New(); + geometry->SetFirstTimePoint(referenceGeometry->GetMinimumTimePoint()); + geometry->SetStepDuration(referenceGeometry->GetMaximumTimePoint() - referenceGeometry->GetMinimumTimePoint()); + geometry->SetTimeStepGeometry(referenceImage->GetGeometry(timeStep), 0); + + auto selector = mitk::ImageTimeSelector::New(); + selector->SetInput(referenceImage); + selector->SetTimeNr(timeStep); + selector->Update(); + + Image::Pointer templateImage = selector->GetOutput(); + templateImage->SetTimeGeometry(geometry); + + return templateImage; +} diff --git a/Modules/Segmentation/Algorithms/mitkSegmentationHelper.h b/Modules/Segmentation/Algorithms/mitkSegmentationHelper.h new file mode 100644 index 0000000000..7da2fa57ae --- /dev/null +++ b/Modules/Segmentation/Algorithms/mitkSegmentationHelper.h @@ -0,0 +1,26 @@ +/*============================================================================ + +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 mitkSegmentationHelper_h +#define mitkSegmentationHelper_h + +#include +#include + +namespace mitk::SegmentationHelper +{ + /** \brief Get a template image for a static segmentation of a dynamic (3d+t) reference image. + */ + MITKSEGMENTATION_EXPORT Image::Pointer GetStaticSegmentationTemplate(const Image* referenceImage); +} + +#endif diff --git a/Modules/Segmentation/files.cmake b/Modules/Segmentation/files.cmake index d931118bc0..c35539f7fe 100644 --- a/Modules/Segmentation/files.cmake +++ b/Modules/Segmentation/files.cmake @@ -1,107 +1,108 @@ set(CPP_FILES Algorithms/mitkCalculateSegmentationVolume.cpp Algorithms/mitkContourModelSetToImageFilter.cpp Algorithms/mitkContourSetToPointSetFilter.cpp Algorithms/mitkContourUtils.cpp Algorithms/mitkCorrectorAlgorithm.cpp Algorithms/mitkDiffImageApplier.cpp Algorithms/mitkDiffSliceOperation.cpp Algorithms/mitkDiffSliceOperationApplier.cpp Algorithms/mitkFeatureBasedEdgeDetectionFilter.cpp Algorithms/mitkImageLiveWireContourModelFilter.cpp Algorithms/mitkImageToContourFilter.cpp #Algorithms/mitkImageToContourModelFilter.cpp Algorithms/mitkImageToLiveWireContourFilter.cpp Algorithms/mitkManualSegmentationToSurfaceFilter.cpp Algorithms/mitkOtsuSegmentationFilter.cpp + Algorithms/mitkSegmentationHelper.cpp Algorithms/mitkSegmentationObjectFactory.cpp Algorithms/mitkShapeBasedInterpolationAlgorithm.cpp Algorithms/mitkShowSegmentationAsSmoothedSurface.cpp Algorithms/mitkShowSegmentationAsSurface.cpp Algorithms/mitkVtkImageOverwrite.cpp Controllers/mitkSegmentationInterpolationController.cpp Controllers/mitkToolManager.cpp Controllers/mitkSegmentationModuleActivator.cpp Controllers/mitkToolManagerProvider.cpp DataManagement/mitkContour.cpp DataManagement/mitkContourSet.cpp DataManagement/mitkExtrudedContour.cpp Interactions/mitkAddContourTool.cpp Interactions/mitkAutoCropTool.cpp Interactions/mitkSegWithPreviewTool.cpp Interactions/mitkBinaryThresholdBaseTool.cpp Interactions/mitkBinaryThresholdTool.cpp Interactions/mitkBinaryThresholdULTool.cpp Interactions/mitkCalculateGrayValueStatisticsTool.cpp Interactions/mitkCalculateVolumetryTool.cpp Interactions/mitkContourModelInteractor.cpp Interactions/mitkContourModelLiveWireInteractor.cpp Interactions/mitkLiveWireTool2D.cpp Interactions/mitkContourTool.cpp Interactions/mitkCreateSurfaceTool.cpp Interactions/mitkDrawPaintbrushTool.cpp Interactions/mitkErasePaintbrushTool.cpp Interactions/mitkEraseRegionTool.cpp Interactions/mitkFeedbackContourTool.cpp Interactions/mitkFillRegionTool.cpp Interactions/mitkOtsuTool3D.cpp Interactions/mitkPaintbrushTool.cpp Interactions/mitkPixelManipulationTool.cpp Interactions/mitkRegionGrowingTool.cpp Interactions/mitkSegmentationsProcessingTool.cpp Interactions/mitkSetRegionTool.cpp Interactions/mitkSegTool2D.cpp Interactions/mitkSubtractContourTool.cpp Interactions/mitkTool.cpp Interactions/mitkToolCommand.cpp Interactions/mitkPickingTool.cpp Interactions/mitknnUnetTool.cpp Interactions/mitkSegmentationInteractor.cpp #SO Interactions/mitkProcessExecutor.cpp Rendering/mitkContourMapper2D.cpp Rendering/mitkContourSetMapper2D.cpp Rendering/mitkContourSetVtkMapper3D.cpp Rendering/mitkContourVtkMapper3D.cpp SegmentationUtilities/BooleanOperations/mitkBooleanOperation.cpp SegmentationUtilities/MorphologicalOperations/mitkMorphologicalOperations.cpp #Added from ML Controllers/mitkSliceBasedInterpolationController.cpp Algorithms/mitkSurfaceStampImageFilter.cpp ) set(RESOURCE_FILES Add_48x48.png Add_Cursor_32x32.png AI_48x48.png AI_Cursor_32x32.png Erase_48x48.png Erase_Cursor_32x32.png Fill_48x48.png Fill_Cursor_32x32.png LiveWire_48x48.png LiveWire_Cursor_32x32.png Otsu_48x48.png Paint_48x48.png Paint_Cursor_32x32.png Pick_48x48.png RegionGrowing_48x48.png RegionGrowing_Cursor_32x32.png Subtract_48x48.png Subtract_Cursor_32x32.png Threshold_48x48.png TwoThresholds_48x48.png Wipe_48x48.png Wipe_Cursor_32x32.png Interactions/dummy.xml Interactions/LiveWireTool.xml Interactions/PickingTool.xml Interactions/PressMoveRelease.xml Interactions/PressMoveReleaseAndPointSetting.xml Interactions/PressMoveReleaseWithCTRLInversion.xml Interactions/PressMoveReleaseWithCTRLInversionAllMouseMoves.xml Interactions/SegmentationToolsConfig.xml Interactions/ContourModelModificationConfig.xml Interactions/ContourModelModificationInteractor.xml ) diff --git a/Modules/SegmentationUI/Qmitk/QmitkStaticDynamicSegmentationDialog.cpp b/Modules/SegmentationUI/Qmitk/QmitkStaticDynamicSegmentationDialog.cpp index 280a3b5107..01cd216935 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkStaticDynamicSegmentationDialog.cpp +++ b/Modules/SegmentationUI/Qmitk/QmitkStaticDynamicSegmentationDialog.cpp @@ -1,75 +1,52 @@ /*============================================================================ 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 "QmitkStaticDynamicSegmentationDialog.h" -#include -#include -#include +#include #include QmitkStaticDynamicSegmentationDialog::QmitkStaticDynamicSegmentationDialog(QWidget *parent) : QMessageBox(parent) { this->setWindowModality(Qt::WindowModality::NonModal); this->setIcon(QMessageBox::Question); this->setWindowTitle(tr("Create a static or dynamic segmentation?")); this->setText(tr("The selected image has multiple time steps.")); this->setInformativeText(tr("Do you want to create a static " "segmentation that is identical for all time steps or do you want to create a " "dynamic segmentation to segment individual time steps?")); QAbstractButton* staticButton = this->addButton(tr("Create static segmentation"), QMessageBox::AcceptRole); this->addButton(tr("Create dynamic segmentation"), QMessageBox::AcceptRole); // only the static button needs to be connected to take care of the special case, where // the time steps of the 4D image are combined into a single time step of the 3D segmentation. connect(staticButton, &QAbstractButton::clicked, this, &QmitkStaticDynamicSegmentationDialog::OnStaticButtonClicked); } void QmitkStaticDynamicSegmentationDialog::SetReferenceImage(const mitk::Image* referenceImage) { m_ReferenceImage = referenceImage; m_SegmentationTemplate = referenceImage; - - const auto currentTimePoint = mitk::RenderingManager::GetInstance()->GetTimeNavigationController()->GetSelectedTimePoint(); - m_ImageTimeStep = 0; - if (m_ReferenceImage->GetTimeGeometry()->IsValidTimePoint(currentTimePoint)) - { - m_ImageTimeStep = m_ReferenceImage->GetTimeGeometry()->TimePointToTimeStep(currentTimePoint); - } } mitk::Image::ConstPointer QmitkStaticDynamicSegmentationDialog::GetSegmentationTemplate() const { return m_SegmentationTemplate; } void QmitkStaticDynamicSegmentationDialog::OnStaticButtonClicked(bool /*checked*/) { - auto selector = mitk::ImageTimeSelector::New(); - selector->SetInput(m_ReferenceImage); - selector->SetTimeNr(m_ImageTimeStep); - selector->Update(); - mitk::Image::Pointer newImage = selector->GetOutput(); - - const auto referenceTimeGeometry = m_ReferenceImage->GetTimeGeometry(); - auto timeGeometry = mitk::ProportionalTimeGeometry::New(); - timeGeometry->SetFirstTimePoint(referenceTimeGeometry->GetMinimumTimePoint()); - timeGeometry->SetStepDuration(referenceTimeGeometry->GetMaximumTimePoint() - referenceTimeGeometry->GetMinimumTimePoint()); - timeGeometry->SetTimeStepGeometry(m_ReferenceImage->GetGeometry(m_ImageTimeStep), 0); - - newImage->SetTimeGeometry(timeGeometry); - - m_SegmentationTemplate = newImage; + m_SegmentationTemplate = mitk::SegmentationHelper::GetStaticSegmentationTemplate(m_ReferenceImage); } diff --git a/Modules/SegmentationUI/Qmitk/QmitkStaticDynamicSegmentationDialog.h b/Modules/SegmentationUI/Qmitk/QmitkStaticDynamicSegmentationDialog.h index 28b933cf59..8633f26ff3 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkStaticDynamicSegmentationDialog.h +++ b/Modules/SegmentationUI/Qmitk/QmitkStaticDynamicSegmentationDialog.h @@ -1,53 +1,51 @@ /*============================================================================ 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 QMITKSTATICDYNAMICSEGMENTATIONDIALOG_H #define QMITKSTATICDYNAMICSEGMENTATIONDIALOG_H #include #include #include /** * \brief Dialog for static / dynamic segmentation node creation. * * This dialog is used to ask a user about the dimensionality of a newly created segmentation. * If the user wants to create a static / 3D segmentation image from a given 4D reference image, * the time steps of the reference image are combined into a single time step, with a step duration * that is as long as the step duration of all 4D time steps combined. */ class MITKSEGMENTATIONUI_EXPORT QmitkStaticDynamicSegmentationDialog : public QMessageBox { Q_OBJECT public: QmitkStaticDynamicSegmentationDialog(QWidget* parent = nullptr); void SetReferenceImage(const mitk::Image* referenceImage); mitk::Image::ConstPointer GetSegmentationTemplate() const; private Q_SLOTS: void OnStaticButtonClicked(bool checked = false); private: mitk::Image::ConstPointer m_SegmentationTemplate; const mitk::Image* m_ReferenceImage; - unsigned int m_ImageTimeStep = 0; - }; #endif // QMITKSTATICDYNAMICSEGMENTATIONDIALOG_H