diff --git a/Modules/Segmentation/Algorithms/mitkContourModelSetToImageFilter.cpp b/Modules/Segmentation/Algorithms/mitkContourModelSetToImageFilter.cpp new file mode 100644 index 0000000000..196cdca31c --- /dev/null +++ b/Modules/Segmentation/Algorithms/mitkContourModelSetToImageFilter.cpp @@ -0,0 +1,272 @@ +/*=================================================================== + +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 "mitkContourModelSetToImageFilter.h" + +#include +#include +#include +#include +#include +#include + +#include + +mitk::ContourModelSetToImageFilter::ContourModelSetToImageFilter() + : m_MakeOutputBinary( true ), + m_TimeStep( 0 ), + m_ReferenceImage( 0 ) +{ + // Create the output. + itk::DataObject::Pointer output = this->MakeOutput(0); + Superclass::SetNumberOfRequiredInputs(1); + Superclass::SetNumberOfRequiredOutputs(1); + Superclass::SetNthOutput(0, output); +} + +mitk::ContourModelSetToImageFilter::~ContourModelSetToImageFilter() +{ +} + +void mitk::ContourModelSetToImageFilter::GenerateInputRequestedRegion() +{ + mitk::Image* output = this->GetOutput(); + if((output->IsInitialized()==false) ) + return; + + GenerateTimeInInputRegion(output, const_cast< mitk::Image * > ( m_ReferenceImage )); +} + +void mitk::ContourModelSetToImageFilter::GenerateOutputInformation() +{ + mitk::Image::Pointer output = this->GetOutput(); + + itkDebugMacro(<<"GenerateOutputInformation()"); + + if((m_ReferenceImage == NULL) || + (m_ReferenceImage->IsInitialized() == false) || + (m_ReferenceImage->GetTimeGeometry() == NULL)) return; + + if (m_MakeOutputBinary) + { + output->Initialize(mitk::MakeScalarPixelType() , *m_ReferenceImage->GetTimeGeometry(),1,1); + } + else + { + output->Initialize(m_ReferenceImage->GetPixelType(), *m_ReferenceImage->GetTimeGeometry()); + } + + output->SetPropertyList(m_ReferenceImage->GetPropertyList()->Clone()); +} + +itk::DataObject::Pointer mitk::ContourModelSetToImageFilter::MakeOutput ( DataObjectPointerArraySizeType /*idx*/ ) +{ + return OutputType::New().GetPointer(); +} + +itk::DataObject::Pointer mitk::ContourModelSetToImageFilter::MakeOutput( const DataObjectIdentifierType & name ) +{ + itkDebugMacro("MakeOutput(" << name << ")"); + if( this->IsIndexedOutputName(name) ) + { + return this->MakeOutput( this->MakeIndexFromOutputName(name) ); + } + return OutputType::New().GetPointer(); +} + +const mitk::ContourModelSet* mitk::ContourModelSetToImageFilter::GetInput(void) +{ + if (this->GetNumberOfInputs() < 1) + { + return 0; + } + + return static_cast< const mitk::ContourModelSet* > + ( this->ProcessObject::GetInput(0) ); +} + +void mitk::ContourModelSetToImageFilter::SetInput(const ContourModelSet *input) +{ + // Process object is not const-correct so the const_cast is required here + this->ProcessObject::SetNthInput(0, + const_cast< mitk::ContourModelSet* >( input ) ); +} + +void mitk::ContourModelSetToImageFilter::SetImage(const mitk::Image *refImage) +{ + m_ReferenceImage = refImage; +} + +const mitk::Image* mitk::ContourModelSetToImageFilter::GetImage(void) +{ + return m_ReferenceImage; +} + +void mitk::ContourModelSetToImageFilter::GenerateData() +{ + mitk::ContourModelSet* contourSet = const_cast(this->GetInput()); + + // Assure that the volume data of the output is set (fill volume with zeros) + this->InitializeOutputEmpty(); + + mitk::Image::Pointer outputImage = const_cast(this->GetOutput()); + + + if(outputImage.IsNull() || outputImage->IsInitialized() == false || !outputImage->IsVolumeSet(m_TimeStep)) + { + MITK_ERROR<<"Error creating output for specified image!"; + return; + } + + if (!contourSet || contourSet->GetContourModelList()->size() == 0) + { + MITK_ERROR<<"No contours specified!"; + return; + } + + mitk::BaseGeometry* outputImageGeo = outputImage->GetGeometry(m_TimeStep); + + // Create mitkVtkImageOverwrite which is needed to write the slice back into the volume + vtkSmartPointer reslice = vtkSmartPointer::New(); + + // Create ExtractSliceFilter for extracting the corresponding slices from the volume + mitk::ExtractSliceFilter::Pointer extractor = mitk::ExtractSliceFilter::New(reslice); + extractor->SetInput( outputImage ); + extractor->SetTimeStep( m_TimeStep ); + extractor->SetResliceTransformByGeometry( outputImageGeo ); + + // Fill each contour of the contourmodelset into the image + mitk::ContourModelSet::ContourModelSetIterator it = contourSet->Begin(); + mitk::ContourModelSet::ContourModelSetIterator end = contourSet->End(); + while (it != end) + { + mitk::ContourModel* contour = it->GetPointer(); + + // 1. Create slice geometry using the contour points + mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New(); + mitk::Point3D point3D, tempPoint; + mitk::Vector3D normal; + + mitk::Image::Pointer slice; + + int sliceIndex; + bool isFrontside = true; + bool isRotated = false; + + // Determine plane orientation + point3D = contour->GetVertexAt(0)->Coordinates; + tempPoint = contour->GetVertexAt(contour->GetNumberOfVertices()*0.25)->Coordinates; + mitk::Vector3D vec = point3D - tempPoint; + vec.Normalize(); + outputImageGeo->WorldToIndex(point3D, point3D); + + mitk::PlaneGeometry::PlaneOrientation orientation; + if (mitk::Equal(vec[0], 0)) + { + orientation = mitk::PlaneGeometry::Sagittal; + sliceIndex = point3D[0]; + } + else if (mitk::Equal(vec[1], 0)) + { + orientation = mitk::PlaneGeometry::Frontal; + sliceIndex = point3D[1]; + } + else if (mitk::Equal(vec[2], 0)) + { + orientation = mitk::PlaneGeometry::Axial; + sliceIndex = point3D[2]; + } + else + { + // TODO Maybe rotate geometry to extract slice? + MITK_ERROR<<"Cannot detect correct slice number! Only axial, sagittal and frontal oriented contours are supported!"; + return; + } + + // Initialize plane using the detected orientation + plane->InitializeStandardPlane(outputImageGeo, orientation, sliceIndex, isFrontside, isRotated); + point3D = plane->GetOrigin(); + normal = plane->GetNormal(); + normal.Normalize(); + point3D += normal * 0.5;//pixelspacing is 1, so half the spacing is 0.5 + plane->SetOrigin(point3D); + + // 2. Extract slice at the given position + extractor->SetWorldGeometry( plane ); + extractor->SetVtkOutputRequest(false); + reslice->SetOverwriteMode(false); + + extractor->Modified(); + extractor->Update(); + + slice = extractor->GetOutput(); + + // 3. Fill contour into slice + mitk::ContourModel::Pointer projectedContour = mitk::ContourModelUtils::ProjectContourTo2DSlice(slice, contour, true, false); + mitk::ContourModelUtils::FillContourInSlice(projectedContour, slice); + + // 4. Write slice back into image volume + reslice->SetInputSlice(slice->GetVtkImageData()); + + //set overwrite mode to true to write back to the image volume + reslice->SetOverwriteMode(true); + reslice->Modified(); + + extractor->SetVtkOutputRequest(true); + extractor->Modified(); + extractor->Update(); + + plane = 0; + ++it; + } + + outputImage->Modified(); + outputImage->GetVtkImageData()->Modified(); +} + +void mitk::ContourModelSetToImageFilter::InitializeOutputEmpty() +{ + // Initialize the output's volume with zeros + mitk::Image* output = this->GetOutput(); + unsigned int byteSize = output->GetPixelType().GetSize(); + + if(output->GetDimension() < 4) + { + for (unsigned int dim = 0; dim < output->GetDimension(); ++dim) + { + byteSize *= output->GetDimension(dim); + } + + mitk::ImageWriteAccessor writeAccess(output, output->GetVolumeData(0)); + + memset( writeAccess.GetData(), 0, byteSize ); + } + else + { + //if we have a time-resolved image we need to set memory to 0 for each time step + for (unsigned int dim = 0; dim < 3; ++dim) + { + byteSize *= output->GetDimension(dim); + } + + for( unsigned int volumeNumber = 0; volumeNumber < output->GetDimension(3); volumeNumber++) + { + mitk::ImageWriteAccessor writeAccess(output, output->GetVolumeData(volumeNumber)); + + memset( writeAccess.GetData(), 0, byteSize ); + } + } +} diff --git a/Modules/Segmentation/Algorithms/mitkContourModelSetToImageFilter.h b/Modules/Segmentation/Algorithms/mitkContourModelSetToImageFilter.h new file mode 100644 index 0000000000..1d15d5a97f --- /dev/null +++ b/Modules/Segmentation/Algorithms/mitkContourModelSetToImageFilter.h @@ -0,0 +1,100 @@ +/*=================================================================== + +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 _MITK_CONTOURMODEL_SOURCE_H +#define _MITK_CONTOURMODEL_SOURCE_H + +#include +#include + +namespace mitk +{ + +class ContourModelSet; + +/** + * @brief Fills a given mitk::ContourModelSet into a given mitk::Image + * @ingroup Process + */ +class MitkSegmentation_EXPORT ContourModelSetToImageFilter : public ImageSource +{ +public: + + mitkClassMacro( ContourModelSetToImageFilter, ImageSource ) + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + itkSetMacro(MakeOutputBinary, bool); + itkGetMacro(MakeOutputBinary, bool); + itkBooleanMacro(MakeOutputBinary); + + itkSetMacro(TimeStep, unsigned int); + + /** + * Allocates a new output object and returns it. Currently the + * index idx is not evaluated. + * @param idx the index of the output for which an object should be created + * @returns the new object + */ + virtual itk::DataObject::Pointer MakeOutput ( DataObjectPointerArraySizeType idx ); + + /** + * This is a default implementation to make sure we have something. + * Once all the subclasses of ProcessObject provide an appopriate + * MakeOutput(), then ProcessObject::MakeOutput() can be made pure + * virtual. + */ + virtual itk::DataObject::Pointer MakeOutput(const DataObjectIdentifierType &name); + + virtual void GenerateInputRequestedRegion(); + + virtual void GenerateOutputInformation(); + + virtual void GenerateData(); + + const mitk::ContourModelSet* GetInput(void); + + using itk::ProcessObject::SetInput; + virtual void SetInput(const mitk::ContourModelSet* input); + + /** + * @brief Set the image which will be used to initialize the output of this filter. + * @param refImage the image used to initialize the output image + */ + void SetImage(const mitk::Image *refImage); + + const mitk::Image *GetImage(void); + +protected: + + ContourModelSetToImageFilter(); + + virtual ~ContourModelSetToImageFilter(); + + /** + * @brief Initializes the volume of the output image with zeros + */ + void InitializeOutputEmpty(); + + bool m_MakeOutputBinary; + + unsigned int m_TimeStep; + + const mitk::Image* m_ReferenceImage; +}; + +} +#endif // #_MITK_CONTOURMODEL_SOURCE_H diff --git a/Modules/Segmentation/Testing/files.cmake b/Modules/Segmentation/Testing/files.cmake index 4bd2610b02..cee738df69 100644 --- a/Modules/Segmentation/Testing/files.cmake +++ b/Modules/Segmentation/Testing/files.cmake @@ -1,33 +1,34 @@ set(MODULE_TESTS mitkContourMapper2DTest.cpp mitkContourTest.cpp + mitkContourModelSetToImageFilterTest.cpp mitkDataNodeSegmentationTest.cpp mitkImageToContourFilterTest.cpp # mitkSegmentationInterpolationTest.cpp mitkOverwriteSliceFilterTest.cpp mitkOverwriteSliceFilterObliquePlaneTest.cpp # mitkToolManagerTest.cpp mitkToolManagerProviderTest.cpp ) if(MITK_ENABLE_RENDERING_TESTING) #since mitkInteractionTestHelper is currently creating a vtkRenderWindow set(MODULE_TESTS ${MODULE_TESTS} mitkToolInteractionTest.cpp ) endif() set(MODULE_IMAGE_TESTS mitkManualSegmentationToSurfaceFilterTest.cpp #only runs on images mitkOverwriteSliceImageFilterTest.cpp #only runs on images ) set(MODULE_CUSTOM_TESTS ) set(MODULE_TESTIMAGES US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) diff --git a/Modules/Segmentation/Testing/mitkContourModelSetToImageFilterTest.cpp b/Modules/Segmentation/Testing/mitkContourModelSetToImageFilterTest.cpp new file mode 100644 index 0000000000..682bcfce7f --- /dev/null +++ b/Modules/Segmentation/Testing/mitkContourModelSetToImageFilterTest.cpp @@ -0,0 +1,60 @@ +/*=================================================================== + +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 +#include +#include +#include +#include +#include + +class mitkContourModelSetToImageFilterTestSuite : public mitk::TestFixture +{ + CPPUNIT_TEST_SUITE(mitkContourModelSetToImageFilterTestSuite); + MITK_TEST(TestFillContourSetIntoImage); + CPPUNIT_TEST_SUITE_END(); + +private: + + mitk::ContourModelSetToImageFilter::Pointer m_ContourFiller; + +public: + + void setUp() + { + m_ContourFiller = mitk::ContourModelSetToImageFilter::New(); + CPPUNIT_ASSERT_MESSAGE("Failed to initialize ContourModelSetToImageFilter", m_ContourFiller.IsNotNull()); + } + + void TestFillContourSetIntoImage() + { + mitk::Image::Pointer refImage = mitk::IOUtil::LoadImage(GetTestDataFilePath("ContourModel/RefImage.nrrd")); + CPPUNIT_ASSERT_MESSAGE("Failed to load reference image", refImage.IsNotNull()); + std::vector > readerOutput; + readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("ContourModel/Contours.cnt_set")); + mitk::ContourModelSet::Pointer cnt_set = dynamic_cast(readerOutput.at(0).GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Failed to load contours", cnt_set.IsNotNull()); + + m_ContourFiller->SetImage(refImage); + m_ContourFiller->SetInput(cnt_set); + m_ContourFiller->Update(); + mitk::Image::Pointer filledImage = m_ContourFiller->GetOutput(); + + MITK_ASSERT_EQUAL(refImage, filledImage, "Error filling contours into image"); + } +}; + +MITK_TEST_SUITE_REGISTRATION(mitkContourModelSetToImageFilter) diff --git a/Modules/Segmentation/files.cmake b/Modules/Segmentation/files.cmake index 59d2b99d96..b29502db2a 100644 --- a/Modules/Segmentation/files.cmake +++ b/Modules/Segmentation/files.cmake @@ -1,122 +1,119 @@ set(CPP_FILES Algorithms/mitkCalculateSegmentationVolume.cpp - #Algorithms/mitkContourModelSource.cpp - #Algorithms/mitkContourModelSubDivisionFilter.cpp - #Algorithms/mitkContourModelToPointSetFilter.cpp - #Algorithms/mitkContourModelToSurfaceFilter.cpp + Algorithms/mitkContourModelSetToImageFilter.cpp Algorithms/mitkContourSetToPointSetFilter.cpp Algorithms/mitkContourUtils.cpp Algorithms/mitkCorrectorAlgorithm.cpp Algorithms/mitkDiffImageApplier.cpp Algorithms/mitkDiffSliceOperation.cpp Algorithms/mitkDiffSliceOperationApplier.cpp Algorithms/mitkImageLiveWireContourModelFilter.cpp Algorithms/mitkImageToContourFilter.cpp #Algorithms/mitkImageToContourModelFilter.cpp Algorithms/mitkImageToLiveWireContourFilter.cpp Algorithms/mitkManualSegmentationToSurfaceFilter.cpp Algorithms/mitkOtsuSegmentationFilter.cpp Algorithms/mitkOverwriteDirectedPlaneImageFilter.cpp Algorithms/mitkOverwriteSliceImageFilter.cpp Algorithms/mitkSegmentationObjectFactory.cpp Algorithms/mitkSegmentationSink.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/mitkContourElement.cpp #DataManagement/mitkContourModel.cpp DataManagement/mitkContourSet.cpp DataManagement/mitkExtrudedContour.cpp Interactions/mitkAdaptiveRegionGrowingTool.cpp Interactions/mitkAddContourTool.cpp Interactions/mitkAutoCropTool.cpp Interactions/mitkAutoSegmentationTool.cpp Interactions/mitkBinaryThresholdTool.cpp Interactions/mitkBinaryThresholdULTool.cpp Interactions/mitkCalculateGrayValueStatisticsTool.cpp Interactions/mitkCalculateVolumetryTool.cpp Interactions/mitkContourInteractor.cpp Interactions/mitkContourModelInteractor.cpp Interactions/mitkContourModelLiveWireInteractor.cpp Interactions/mitkContourTool.cpp Interactions/mitkCorrectorTool2D.cpp Interactions/mitkCreateSurfaceTool.cpp Interactions/mitkDrawPaintbrushTool.cpp Interactions/mitkErasePaintbrushTool.cpp Interactions/mitkEraseRegionTool.cpp Interactions/mitkExtrudedContourInteractor.cpp Interactions/mitkFastMarchingTool.cpp Interactions/mitkFastMarchingTool3D.cpp Interactions/mitkFeedbackContourTool.cpp Interactions/mitkFillRegionTool.cpp Interactions/mitkLiveWireTool2D.cpp Interactions/mitkOtsuTool3D.cpp Interactions/mitkPaintbrushTool.cpp Interactions/mitkPixelManipulationTool.cpp Interactions/mitkRegionGrow3DTool.cpp Interactions/mitkRegionGrowingTool.cpp Interactions/mitkSegmentationsProcessingTool.cpp Interactions/mitkSetRegionTool.cpp Interactions/mitkSegTool2D.cpp Interactions/mitkSubtractContourTool.cpp Interactions/mitkTool.cpp Interactions/mitkToolCommand.cpp Interactions/mitkWatershedTool.cpp Interactions/mitkPickingTool.cpp #IO/mitkContourModelIOFactory.cpp #IO/mitkContourModelReader.cpp #IO/mitkContourModelWriter.cpp #IO/mitkContourModelWriterFactory.cpp Rendering/mitkContourMapper2D.cpp #Rendering/mitkContourModelGLMapper2D.cpp #Rendering/mitkContourModelMapper2D.cpp #Rendering/mitkContourModelMapper3D.cpp Rendering/mitkContourSetMapper2D.cpp Rendering/mitkContourSetVtkMapper3D.cpp Rendering/mitkContourVtkMapper3D.cpp SegmentationUtilities/BooleanOperations/mitkBooleanOperation.cpp SegmentationUtilities/MorphologicalOperations/mitkMorphologicalOperations.cpp ) set(RESOURCE_FILES Add_48x48.png Add_Cursor_32x32.png Correction_48x48.png Correction_Cursor_32x32.png Erase_48x48.png Erase_Cursor_32x32.png FastMarching_48x48.png FastMarching_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 Watershed_48x48.png Watershed_Cursor_32x32.png Wipe_48x48.png Wipe_Cursor_32x32.png Interactions/dummy.xml Interactions/LiveWireTool.xml Interactions/PressMoveRelease.xml Interactions/PressMoveReleaseAndPointSetting.xml Interactions/PressMoveReleaseWithCTRLInversion.xml Interactions/PressMoveReleaseWithCTRLInversionAllMouseMoves.xml Interactions/SegmentationToolsConfig.xml ) diff --git a/Modules/SurfaceInterpolation/CMakeLists.txt b/Modules/SurfaceInterpolation/CMakeLists.txt index f3d740bc6e..843831ba5b 100644 --- a/Modules/SurfaceInterpolation/CMakeLists.txt +++ b/Modules/SurfaceInterpolation/CMakeLists.txt @@ -1,7 +1,7 @@ MITK_CREATE_MODULE( - DEPENDS MitkImageExtraction + DEPENDS MitkAlgorithmsExt PACKAGE_DEPENDS Eigen WARNINGS_AS_ERRORS ) add_subdirectory(Testing) diff --git a/Plugins/org.mitk.gui.qt.registration/plugin.xml b/Plugins/org.mitk.gui.qt.registration/plugin.xml index 094f1eab40..a84ea39342 100644 --- a/Plugins/org.mitk.gui.qt.registration/plugin.xml +++ b/Plugins/org.mitk.gui.qt.registration/plugin.xml @@ -1,28 +1,30 @@ + diff --git a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.cpp b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.cpp index 8c287ae903..19d85d6b86 100644 --- a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.cpp +++ b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.cpp @@ -1,1467 +1,1469 @@ /*=================================================================== 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. ===================================================================*/ // Qmitk includes #include "QmitkRigidRegistrationView.h" #include "QmitkStdMultiWidget.h" // MITK includes #include "mitkDataNodeObject.h" #include #include "mitkManualSegmentationToSurfaceFilter.h" #include #include #include "mitkNodePredicateDataType.h" #include "mitkNodePredicateAnd.h" #include "mitkNodePredicateProperty.h" // QT includes #include "qinputdialog.h" #include "qmessagebox.h" #include "qcursor.h" #include "qapplication.h" #include "qradiobutton.h" #include "qslider.h" #include "qtooltip.h" // VTK includes #include // ITK includes #include // BlueBerry includes #include "berryIWorkbenchWindow.h" #include "berryISelectionService.h" const std::string QmitkRigidRegistrationView::VIEW_ID = "org.mitk.views.rigidregistration"; using namespace berry; struct SelListenerRigidRegistration : ISelectionListener { berryObjectMacro(SelListenerRigidRegistration); SelListenerRigidRegistration(QmitkRigidRegistrationView* view) { m_View = view; } void DoSelectionChanged(ISelection::ConstPointer selection) { // save current selection in member variable m_View->m_CurrentSelection = selection.Cast(); // do something with the selected items if(m_View->m_CurrentSelection) { if (m_View->m_CurrentSelection->Size() != 2) { if (m_View->m_FixedNode.IsNull() || m_View->m_MovingNode.IsNull()) { m_View->m_Controls.m_StatusLabel->show(); m_View->m_Controls.TextLabelFixed->hide(); m_View->m_Controls.m_FixedLabel->hide(); m_View->m_Controls.TextLabelMoving->hide(); m_View->m_Controls.m_MovingLabel->hide(); m_View->m_Controls.m_UseMaskingCB->hide(); m_View->m_Controls.m_OpacityLabel->setEnabled(false); m_View->m_Controls.m_OpacitySlider->setEnabled(false); m_View->m_Controls.label->setEnabled(false); m_View->m_Controls.label_2->setEnabled(false); m_View->m_Controls.m_ShowRedGreenValues->setEnabled(false); m_View->m_Controls.m_SwitchImages->hide(); } } else { m_View->m_Controls.m_StatusLabel->hide(); bool foundFixedImage = false; mitk::DataNode::Pointer fixedNode; // iterate selection for (IStructuredSelection::iterator i = m_View->m_CurrentSelection->Begin(); i != m_View->m_CurrentSelection->End(); ++i) { // extract datatree node if (mitk::DataNodeObject::Pointer nodeObj = i->Cast()) { mitk::DataNode::Pointer node = nodeObj->GetDataNode(); // only look at interesting types if(QString("Image").compare(node->GetData()->GetNameOfClass())==0) { if (dynamic_cast(node->GetData())->GetDimension() == 4) { m_View->m_Controls.m_StatusLabel->show(); QMessageBox::information( NULL, "RigidRegistration", "Only 2D or 3D images can be processed.", QMessageBox::Ok ); return; } if (foundFixedImage == false) { fixedNode = node; foundFixedImage = true; } else { // m_View->SetImagesVisible(selection); m_View->FixedSelected(fixedNode); m_View->MovingSelected(node); m_View->m_Controls.m_StatusLabel->hide(); m_View->m_Controls.TextLabelFixed->show(); m_View->m_Controls.m_FixedLabel->show(); m_View->m_Controls.TextLabelMoving->show(); m_View->m_Controls.m_MovingLabel->show(); m_View->m_Controls.m_UseMaskingCB->show(); m_View->m_Controls.m_OpacityLabel->setEnabled(true); m_View->m_Controls.m_OpacitySlider->setEnabled(true); m_View->m_Controls.label->setEnabled(true); m_View->m_Controls.label_2->setEnabled(true); m_View->m_Controls.m_ShowRedGreenValues->setEnabled(true); } } else { m_View->m_Controls.m_StatusLabel->show(); return; } } } } } else if (m_View->m_FixedNode.IsNull() || m_View->m_MovingNode.IsNull()) { m_View->m_Controls.m_StatusLabel->show(); } } void SelectionChanged(IWorkbenchPart::Pointer part, ISelection::ConstPointer selection) { // check, if selection comes from datamanager if (part) { QString partname(part->GetPartName().c_str()); if(partname.compare("Data Manager")==0) { // apply selection DoSelectionChanged(selection); } } } QmitkRigidRegistrationView* m_View; }; QmitkRigidRegistrationView::QmitkRigidRegistrationView(QObject * /*parent*/, const char * /*name*/) : QmitkFunctionality(), m_MultiWidget(NULL), m_MovingNode(NULL), m_MovingMaskNode(NULL), m_FixedNode(NULL), m_FixedMaskNode(NULL), m_ShowRedGreen(false), m_Opacity(0.5), m_OriginalOpacity(1.0), m_Deactivated(false),m_FixedDimension(0), m_MovingDimension(0) { m_TranslateSliderPos[0] = 0; m_TranslateSliderPos[1] = 0; m_TranslateSliderPos[2] = 0; m_RotateSliderPos[0] = 0; m_RotateSliderPos[1] = 0; m_RotateSliderPos[2] = 0; m_ScaleSliderPos[0] = 0; m_ScaleSliderPos[1] = 0; m_ScaleSliderPos[2] = 0; translationParams = new int[3]; rotationParams = new int[3]; scalingParams = new int[3]; m_TimeStepperAdapter = NULL; this->GetDataStorage()->RemoveNodeEvent.AddListener(mitk::MessageDelegate1 ( this, &QmitkRigidRegistrationView::DataNodeHasBeenRemoved )); } QmitkRigidRegistrationView::~QmitkRigidRegistrationView() { if(m_SelListener.IsNotNull()) { berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) s->RemovePostSelectionListener(m_SelListener); m_SelListener = NULL; } this->GetDataStorage()->RemoveNodeEvent.RemoveListener(mitk::MessageDelegate1 ( this, &QmitkRigidRegistrationView::DataNodeHasBeenRemoved )); } void QmitkRigidRegistrationView::CreateQtPartControl(QWidget* parent) { m_Controls.setupUi(parent); m_Controls.m_ManualFrame->hide(); m_Controls.timeSlider->hide(); m_Controls.TextLabelFixed->hide(); m_Controls.m_FixedLabel->hide(); m_Controls.TextLabelMoving->hide(); m_Controls.m_MovingLabel->hide(); //m_Controls.m_UseFixedImageMask->hide(); //m_Controls.m_UseMovingImageMask->hide(); m_Controls.m_UseMaskingCB->hide(); m_Controls.m_OpacityLabel->setEnabled(false); m_Controls.m_OpacitySlider->setEnabled(false); m_Controls.label->setEnabled(false); m_Controls.label_2->setEnabled(false); m_Controls.m_ShowRedGreenValues->setEnabled(false); m_Controls.m_SwitchImages->hide(); if (m_Controls.m_RigidTransform->currentIndex() == 1) { m_Controls.frame->show(); } else { m_Controls.frame->hide(); } m_Controls.m_ManualFrame->setEnabled(false); m_Parent->setEnabled(false); mitk::NodePredicateAnd::Pointer andPred = // we want binary images in the selectors mitk::NodePredicateAnd::New(mitk::NodePredicateDataType::New("Image"), mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true))); m_Controls.m_FixedImageCB->SetPredicate(andPred); m_Controls.m_FixedImageCB->SetDataStorage(this->GetDataStorage()); m_Controls.m_FixedImageCB->hide(); m_Controls.m_FixedMaskLB->hide(); m_Controls.m_MovingImageCB->SetPredicate(andPred); m_Controls.m_MovingImageCB->SetDataStorage(this->GetDataStorage()); m_Controls.m_MovingImageCB->hide(); m_Controls.m_MovingMaskLB->hide(); + m_Controls.m_RigidTransform->removeTab(1); + this->CreateConnections(); this->CheckCalculateEnabled(); } void QmitkRigidRegistrationView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_Parent->setEnabled(true); m_MultiWidget = &stdMultiWidget; m_MultiWidget->SetWidgetPlanesVisibility(true); } void QmitkRigidRegistrationView::StdMultiWidgetNotAvailable() { m_Parent->setEnabled(false); m_MultiWidget = NULL; } void QmitkRigidRegistrationView::CreateConnections() { connect( m_Controls.m_ManualRegistrationCheckbox, SIGNAL(toggled(bool)), this, SLOT(ShowManualRegistrationFrame(bool))); connect((QObject*)(m_Controls.m_SwitchImages),SIGNAL(clicked()),this,SLOT(SwitchImages())); connect(m_Controls.m_ShowRedGreenValues, SIGNAL(toggled(bool)), this, SLOT(ShowRedGreen(bool))); connect(m_Controls.m_ShowContour, SIGNAL(toggled(bool)), this, SLOT(EnableContour(bool))); //connect(m_Controls.m_UseFixedImageMask, SIGNAL(toggled(bool)), this, SLOT(UseFixedMaskImageChecked(bool))); //connect(m_Controls.m_UseMovingImageMask, SIGNAL(toggled(bool)), this, SLOT(UseMovingMaskImageChecked(bool))); connect(m_Controls.m_RigidTransform, SIGNAL(currentChanged(int)), this, SLOT(TabChanged(int))); connect(m_Controls.m_OpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityUpdate(int))); connect(m_Controls.m_ContourSlider, SIGNAL(sliderReleased()), this, SLOT(ShowContour())); connect(m_Controls.m_CalculateTransformation, SIGNAL(clicked()), this, SLOT(Calculate())); connect(m_Controls.m_UndoTransformation,SIGNAL(clicked()),this,SLOT(UndoTransformation())); connect(m_Controls.m_RedoTransformation,SIGNAL(clicked()),this,SLOT(RedoTransformation())); connect(m_Controls.m_AutomaticTranslation,SIGNAL(clicked()),this,SLOT(AlignCenters())); connect(m_Controls.m_StopOptimization,SIGNAL(clicked()), this , SLOT(StopOptimizationClicked())); connect(m_Controls.m_XTransSlider, SIGNAL(valueChanged(int)), this, SLOT(xTrans_valueChanged(int))); connect(m_Controls.m_YTransSlider, SIGNAL(valueChanged(int)), this, SLOT(yTrans_valueChanged(int))); connect(m_Controls.m_ZTransSlider, SIGNAL(valueChanged(int)), this, SLOT(zTrans_valueChanged(int))); connect(m_Controls.m_XRotSlider, SIGNAL(valueChanged(int)), this, SLOT(xRot_valueChanged(int))); connect(m_Controls.m_YRotSlider, SIGNAL(valueChanged(int)), this, SLOT(yRot_valueChanged(int))); connect(m_Controls.m_ZRotSlider, SIGNAL(valueChanged(int)), this, SLOT(zRot_valueChanged(int))); connect(m_Controls.m_XScaleSlider, SIGNAL(valueChanged(int)), this, SLOT(xScale_valueChanged(int))); connect(m_Controls.m_YScaleSlider, SIGNAL(valueChanged(int)), this, SLOT(yScale_valueChanged(int))); connect(m_Controls.m_ZScaleSlider, SIGNAL(valueChanged(int)), this, SLOT(zScale_valueChanged(int))); connect(m_Controls.m_LoadRigidRegistrationParameter, SIGNAL(clicked()), m_Controls.qmitkRigidRegistrationSelector1, SLOT(LoadRigidRegistrationParameter())); connect(m_Controls.m_SaveRigidRegistrationParameter, SIGNAL(clicked()), m_Controls.qmitkRigidRegistrationSelector1, SLOT(SaveRigidRegistrationParameter())); connect(m_Controls.m_LoadRigidRegistrationTestParameter, SIGNAL(clicked()), m_Controls.qmitkRigidRegistrationSelector1, SLOT(LoadRigidRegistrationTestParameter())); connect(m_Controls.m_SaveRigidRegistrationTestParameter, SIGNAL(clicked()), m_Controls.qmitkRigidRegistrationSelector1, SLOT(SaveRigidRegistrationTestParameter())); connect(m_Controls.qmitkRigidRegistrationSelector1,SIGNAL(OptimizerChanged(double)),this,SLOT(SetOptimizerValue( double ))); connect(m_Controls.qmitkRigidRegistrationSelector1,SIGNAL(TransformChanged()),this,SLOT(CheckCalculateEnabled())); connect(m_Controls.qmitkRigidRegistrationSelector1,SIGNAL(AddNewTransformationToUndoList()),this,SLOT(AddNewTransformationToUndoList())); connect(m_Controls.m_UseMaskingCB, SIGNAL(stateChanged(int)),this,SLOT(OnUseMaskingChanged(int))); connect(m_Controls.m_FixedImageCB, SIGNAL(OnSelectionChanged(const mitk::DataNode*)),this,SLOT(OnFixedMaskImageChanged(const mitk::DataNode*))); connect(m_Controls.m_MovingImageCB, SIGNAL(OnSelectionChanged(const mitk::DataNode*)),this,SLOT(OnMovingMaskImageChanged(const mitk::DataNode*))); } void QmitkRigidRegistrationView::Activated() { m_Deactivated = false; mitk::RenderingManager::GetInstance()->RequestUpdateAll(); QmitkFunctionality::Activated(); if (m_SelListener.IsNull()) { m_SelListener = berry::ISelectionListener::Pointer(new SelListenerRigidRegistration(this)); this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(/*"org.mitk.views.datamanager",*/ m_SelListener); berry::ISelection::ConstPointer sel( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); m_CurrentSelection = sel.Cast(); m_SelListener.Cast()->DoSelectionChanged(sel); } this->OpacityUpdate(m_Controls.m_OpacitySlider->value()); this->ShowRedGreen(m_Controls.m_ShowRedGreenValues->isChecked()); this->ClearTransformationLists(); this->CheckCalculateEnabled(); /* m_Deactivated = false; mitk::RenderingManager::GetInstance()->RequestUpdateAll(); QmitkFunctionality::Activated(); if (m_SelListener.IsNull()) { m_SelListener = berry::ISelectionListener::Pointer(new SelListenerRigidRegistration(this)); this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(/ *"org.mitk.views.datamanager",* / m_SelListener); berry::ISelection::ConstPointer sel( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); m_CurrentSelection = sel.Cast(); m_SelListener.Cast()->DoSelectionChanged(sel); } this->OpacityUpdate(m_Controls.m_OpacitySlider->value()); this->ShowRedGreen(m_Controls.m_ShowRedGreenValues->isChecked()); this->ClearTransformationLists(); this->CheckCalculateEnabled();*/ } void QmitkRigidRegistrationView::Visible() { /* m_Deactivated = false; mitk::RenderingManager::GetInstance()->RequestUpdateAll(); QmitkFunctionality::Activated(); if (m_SelListener.IsNull()) { m_SelListener = berry::ISelectionListener::Pointer(new SelListenerRigidRegistration(this)); this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener("org.mitk.views.datamanager", m_SelListener); berry::ISelection::ConstPointer sel( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); m_CurrentSelection = sel.Cast(); m_SelListener.Cast()->DoSelectionChanged(sel); } this->OpacityUpdate(m_Controls.m_OpacitySlider->value()); this->ShowRedGreen(m_Controls.m_ShowRedGreenValues->isChecked()); this->ClearTransformationLists(); this->CheckCalculateEnabled();*/ } void QmitkRigidRegistrationView::Deactivated() { m_Deactivated = true; this->SetImageColor(false); if (m_FixedNode.IsNotNull()) m_FixedNode->SetOpacity(1.0); m_FixedNode = NULL; m_MovingNode = NULL; this->ClearTransformationLists(); berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) s->RemovePostSelectionListener(m_SelListener); m_SelListener = NULL; /* m_Deactivated = true; this->SetImageColor(false); m_FixedNode = NULL; m_MovingNode = NULL; this->ClearTransformationLists(); berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) s->RemovePostSelectionListener(m_SelListener); m_SelListener = NULL; mitk::RenderingManager::GetInstance()->RequestUpdateAll(); QmitkFunctionality::Deactivated();*/ } void QmitkRigidRegistrationView::Hidden() { /*m_Deactivated = true; this->SetImageColor(false); m_FixedNode = NULL; m_MovingNode = NULL; this->ClearTransformationLists(); berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) s->RemovePostSelectionListener(m_SelListener); m_SelListener = NULL; //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); //QmitkFunctionality::Deactivated();*/ } void QmitkRigidRegistrationView::DataNodeHasBeenRemoved(const mitk::DataNode* node) { if(node == m_FixedNode || node == m_MovingNode) { m_Controls.m_StatusLabel->show(); m_Controls.TextLabelFixed->hide(); m_Controls.m_FixedLabel->hide(); m_Controls.TextLabelMoving->hide(); m_Controls.m_MovingLabel->hide(); m_Controls.m_OpacityLabel->setEnabled(false); m_Controls.m_OpacitySlider->setEnabled(false); m_Controls.label->setEnabled(false); m_Controls.label_2->setEnabled(false); m_Controls.m_ShowRedGreenValues->setEnabled(false); m_Controls.m_SwitchImages->hide(); } else if(node == m_ContourHelperNode) { // can this cause a memory leak? m_ContourHelperNode = NULL; } } void QmitkRigidRegistrationView::FixedSelected(mitk::DataNode::Pointer fixedImage) { if (m_FixedNode.IsNotNull()) { this->SetImageColor(false); m_FixedNode->SetOpacity(1.0); } m_FixedNode = fixedImage; if (m_FixedNode.IsNotNull()) { m_FixedNode->SetOpacity(0.5); m_FixedNode->SetVisibility(true); m_Controls.TextLabelFixed->setText(QString::fromStdString(m_FixedNode->GetName())); m_Controls.m_FixedLabel->show(); m_Controls.TextLabelFixed->show(); m_Controls.m_SwitchImages->show(); mitk::ColorProperty::Pointer colorProperty; colorProperty = dynamic_cast(m_FixedNode->GetProperty("color")); if ( colorProperty.IsNotNull() ) { m_FixedColor = colorProperty->GetColor(); } this->SetImageColor(m_ShowRedGreen); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); if (dynamic_cast(m_FixedNode->GetData())) { m_FixedDimension = dynamic_cast(m_FixedNode->GetData())->GetDimension(); m_Controls.qmitkRigidRegistrationSelector1->SetFixedDimension(m_FixedDimension); m_Controls.qmitkRigidRegistrationSelector1->SetFixedNode(m_FixedNode); } // what's about masking? m_Controls.m_UseMaskingCB->show(); // Modify slider range mitk::Image::Pointer image = dynamic_cast(m_FixedNode->GetData()); int min = (int)image->GetStatistics()->GetScalarValueMin(); int max = (int)image->GetStatistics()->GetScalarValueMax(); m_Controls.m_ContourSlider->setRange(min, max); // Set slider to a default value int avg = (min+max) / 2; m_Controls.m_ContourSlider->setSliderPosition(avg); m_Controls.m_ThresholdLabel->setText(QString::number(avg)); } else { m_Controls.m_FixedLabel->hide(); m_Controls.TextLabelFixed->hide(); m_Controls.m_SwitchImages->hide(); } this->CheckCalculateEnabled(); if(this->GetActiveStdMultiWidget()) { m_TimeStepperAdapter = new QmitkStepperAdapter((QObject*) m_Controls.timeSlider, m_MultiWidget->GetTimeNavigationController()->GetTime(), "sliceNavigatorTimeFromRigidRegistration"); connect( m_TimeStepperAdapter, SIGNAL( Refetch() ), this, SLOT( UpdateTimestep() ) ); } } void QmitkRigidRegistrationView::MovingSelected(mitk::DataNode::Pointer movingImage) { if (m_MovingNode.IsNotNull()) { m_MovingNode->SetOpacity(m_OriginalOpacity); if (m_FixedNode == m_MovingNode) m_FixedNode->SetOpacity(0.5); this->SetImageColor(false); } // selection did not change - do onot reset if( m_MovingNode.IsNotNull() && m_MovingNode == movingImage) { } else { m_MovingNode = movingImage; if (m_MovingNode.IsNotNull()) { m_MovingNode->SetVisibility(true); m_Controls.TextLabelMoving->setText(QString::fromStdString(m_MovingNode->GetName())); m_Controls.m_MovingLabel->show(); m_Controls.TextLabelMoving->show(); mitk::ColorProperty::Pointer colorProperty; colorProperty = dynamic_cast(m_MovingNode->GetProperty("color")); if ( colorProperty.IsNotNull() ) { m_MovingColor = colorProperty->GetColor(); } this->SetImageColor(m_ShowRedGreen); m_MovingNode->GetFloatProperty("opacity", m_OriginalOpacity); this->OpacityUpdate(m_Opacity); // what's about masking? m_Controls.m_UseMaskingCB->show(); } else { m_Controls.m_MovingLabel->hide(); m_Controls.TextLabelMoving->hide(); m_Controls.m_UseMaskingCB->hide(); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); this->MovingImageChanged(); this->CheckCalculateEnabled(); } } bool QmitkRigidRegistrationView::CheckCalculate() { if(m_MovingNode==m_FixedNode) return false; return true; } void QmitkRigidRegistrationView::AddNewTransformationToUndoList() { mitk::BaseData::Pointer movingData = m_MovingNode->GetData(); m_UndoGeometryList.push_back(static_cast(movingData->GetGeometry()->Clone().GetPointer())); GeometryMapType childGeometries = GeometryMapType(); if(m_MovingMaskNode.IsNotNull()) { childGeometries.insert(std::pair(m_MovingMaskNode, static_cast(m_MovingMaskNode->GetData()->GetGeometry()->Clone().GetPointer()))); } mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); if(children.IsNotNull() && children->Size() != 0) { unsigned long size; size = children->Size(); for (unsigned long i = 0; i < size; ++i) { childGeometries.insert(std::pair(children->GetElement(i), static_cast(children->GetElement(i)->GetData()->GetGeometry()->Clone().GetPointer()))); } } m_UndoChildGeometryList.push_back(childGeometries); m_RedoGeometryList.clear(); m_RedoChildGeometryList.clear(); this->SetUndoEnabled(true); this->SetRedoEnabled(false); } void QmitkRigidRegistrationView::UndoTransformation() { if(!m_UndoGeometryList.empty()) { mitk::BaseData::Pointer movingData = m_MovingNode->GetData(); m_RedoGeometryList.push_back(static_cast(movingData->GetGeometry(0)->Clone().GetPointer())); unsigned long size = 0; GeometryMapType childGeometries = GeometryMapType(); if(m_MovingMaskNode.IsNotNull()) { ++size; } mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); size += children->Size(); for (unsigned long i = 0; i < size; ++i) { if(i==0) { childGeometries.insert(std::pair(m_MovingMaskNode, static_cast(m_MovingMaskNode->GetData()->GetGeometry()->Clone().GetPointer()))); } else { childGeometries.insert(std::pair(children->GetElement(i), static_cast(children->GetElement(i)->GetData()->GetGeometry()->Clone().GetPointer()))); } } m_RedoChildGeometryList.push_back(childGeometries); movingData->SetGeometry(m_UndoGeometryList.back()); m_UndoGeometryList.pop_back(); GeometryMapType oldChildGeometries; oldChildGeometries = m_UndoChildGeometryList.back(); m_UndoChildGeometryList.pop_back(); GeometryMapType::iterator iter; for (unsigned long j = 0; j < size; ++j) { if(j == 0) // we have put the geometry for the moving mask at position one { iter = oldChildGeometries.find(m_MovingMaskNode); mitk::Geometry3D* geo = static_cast((*iter).second); m_MovingMaskNode->GetData()->SetGeometry(geo); m_MovingMaskNode->GetData()->GetTimeGeometry()->Update(); } else { iter = oldChildGeometries.find(children->GetElement(j)); children->GetElement(j)->GetData()->SetGeometry((*iter).second); } } //\FIXME when geometry is substituted the matrix referenced by the actor created by the mapper //is still pointing to the old one. Workaround: delete mapper //m_MovingNode->SetMapper(1, NULL); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); this->SetRedoEnabled(true); } if(!m_UndoGeometryList.empty()) { this->SetUndoEnabled(true); } else { this->SetUndoEnabled(false); } this->CheckCalculateEnabled(); } void QmitkRigidRegistrationView::RedoTransformation() { if(!m_RedoGeometryList.empty()) { mitk::BaseData::Pointer movingData = m_MovingNode->GetData(); m_UndoGeometryList.push_back(static_cast(movingData->GetGeometry(0)->Clone().GetPointer())); unsigned long size = 0; GeometryMapType childGeometries = GeometryMapType(); if(m_MovingMaskNode.IsNotNull()) { ++size; } mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); size += children->Size(); for (unsigned long i = 0; i < size; ++i) { if(i == 0) { childGeometries.insert(std::pair(m_MovingMaskNode, static_cast(m_MovingMaskNode->GetData()->GetGeometry()->Clone().GetPointer()))); } else { childGeometries.insert(std::pair(children->GetElement(i), static_cast(children->GetElement(i)->GetData()->GetGeometry()->Clone().GetPointer()))); } } m_UndoChildGeometryList.push_back(childGeometries); movingData->SetGeometry(m_RedoGeometryList.back()); m_RedoGeometryList.pop_back(); GeometryMapType oldChildGeometries; oldChildGeometries = m_RedoChildGeometryList.back(); m_RedoChildGeometryList.pop_back(); GeometryMapType::iterator iter; for (unsigned long j = 0; j < size; ++j) { if(j == 0) { iter = oldChildGeometries.find(m_MovingMaskNode); m_MovingMaskNode->GetData()->SetGeometry((*iter).second); } else { iter = oldChildGeometries.find(children->GetElement(j)); children->GetElement(j)->GetData()->SetGeometry((*iter).second); } } movingData->GetTimeGeometry()->Update(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); this->SetUndoEnabled(true); } if(!m_RedoGeometryList.empty()) { this->SetRedoEnabled(true); } else { this->SetRedoEnabled(false); } } void QmitkRigidRegistrationView::ShowRedGreen(bool redGreen) { m_ShowRedGreen = redGreen; this->SetImageColor(m_ShowRedGreen); } void QmitkRigidRegistrationView::EnableContour(bool show) { if(show) ShowContour(); // Can happen when the m_ContourHelperNode was deleted before and now the show contour checkbox is turned off if(m_ContourHelperNode.IsNull()) return; m_Controls.m_ContourSlider->setEnabled(show); m_ContourHelperNode->SetProperty("visible", mitk::BoolProperty::New(show)); mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); } void QmitkRigidRegistrationView::ShowContour() { int threshold = m_Controls.m_ContourSlider->value(); bool show = m_Controls.m_ShowContour->isChecked(); if(m_FixedNode.IsNull() || !show) return; // Update the label next to the slider m_Controls.m_ThresholdLabel->setText(QString::number(threshold)); mitk::Image::Pointer image = dynamic_cast(m_FixedNode->GetData()); typedef itk::Image FloatImageType; typedef itk::Image ShortImageType; // Create a binary image using the given treshold typedef itk::BinaryThresholdImageFilter ThresholdFilterType; FloatImageType::Pointer floatImage = FloatImageType::New(); mitk::CastToItkImage(image, floatImage); ThresholdFilterType::Pointer thresholdFilter = ThresholdFilterType::New(); thresholdFilter->SetInput(floatImage); thresholdFilter->SetLowerThreshold(threshold); thresholdFilter->SetUpperThreshold((int)image->GetStatistics()->GetScalarValueMax()); thresholdFilter->SetInsideValue(1); thresholdFilter->SetOutsideValue(0); thresholdFilter->Update(); ShortImageType::Pointer binaryImage = thresholdFilter->GetOutput(); mitk::Image::Pointer mitkBinaryImage = mitk::Image::New(); mitk::CastToMitkImage(binaryImage, mitkBinaryImage); // Create a contour from the binary image mitk::ManualSegmentationToSurfaceFilter::Pointer surfaceFilter = mitk::ManualSegmentationToSurfaceFilter::New(); surfaceFilter->SetInput( mitkBinaryImage ); surfaceFilter->SetThreshold( 1 ); //expects binary image with zeros and ones surfaceFilter->SetUseGaussianImageSmooth(false); // apply gaussian to thresholded image ? surfaceFilter->SetMedianFilter3D(false); // apply median to segmentation before marching cubes ? surfaceFilter->SetDecimate( mitk::ImageToSurfaceFilter::NoDecimation ); surfaceFilter->UpdateLargestPossibleRegion(); // calculate normals for nicer display mitk::Surface::Pointer surface = surfaceFilter->GetOutput(); if(m_ContourHelperNode.IsNull()) { m_ContourHelperNode = mitk::DataNode::New(); m_ContourHelperNode->SetData(surface); m_ContourHelperNode->SetProperty("opacity", mitk::FloatProperty::New(1.0) ); m_ContourHelperNode->SetProperty("line width", mitk::IntProperty::New(2) ); m_ContourHelperNode->SetProperty("scalar visibility", mitk::BoolProperty::New(false) ); m_ContourHelperNode->SetProperty( "name", mitk::StringProperty::New("surface") ); m_ContourHelperNode->SetProperty("color", mitk::ColorProperty::New(1.0, 0.0, 0.0)); m_ContourHelperNode->SetBoolProperty("helper object", true); this->GetDataStorage()->Add(m_ContourHelperNode); } else { m_ContourHelperNode->SetData(surface); } mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); } void QmitkRigidRegistrationView::SetImageColor(bool redGreen) { if (!redGreen && m_FixedNode.IsNotNull()) { m_FixedNode->SetColor(m_FixedColor); } if (!redGreen && m_MovingNode.IsNotNull()) { m_MovingNode->SetColor(m_MovingColor); } if (redGreen && m_FixedNode.IsNotNull()) { m_FixedNode->SetColor(1.0f, 0.0f, 0.0f); } if (redGreen && m_MovingNode.IsNotNull()) { m_MovingNode->SetColor(0.0f, 1.0f, 0.0f); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkRigidRegistrationView::OpacityUpdate(float opacity) { m_Opacity = opacity; if (m_MovingNode.IsNotNull()) { m_MovingNode->SetOpacity(m_Opacity); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkRigidRegistrationView::OpacityUpdate(int opacity) { float fValue = ((float)opacity)/100.0f; this->OpacityUpdate(fValue); } void QmitkRigidRegistrationView::ClearTransformationLists() { this->SetUndoEnabled(false); this->SetRedoEnabled(false); m_UndoGeometryList.clear(); m_UndoChildGeometryList.clear(); m_RedoGeometryList.clear(); m_RedoChildGeometryList.clear(); } void QmitkRigidRegistrationView::Translate(int* translateVector) { if (m_MovingNode.IsNotNull()) { mitk::Vector3D translateVec; mitk::ScalarType sliderSensitivity = 0.1; translateVec[0] = sliderSensitivity * (translateVector[0] - m_TranslateSliderPos[0]); translateVec[1] = sliderSensitivity * (translateVector[1] - m_TranslateSliderPos[1]); translateVec[2] = sliderSensitivity * (translateVector[2] - m_TranslateSliderPos[2]); m_TranslateSliderPos[0] = translateVector[0]; m_TranslateSliderPos[1] = translateVector[1]; m_TranslateSliderPos[2] = translateVector[2]; vtkMatrix4x4* translationMatrix = vtkMatrix4x4::New(); translationMatrix->Identity(); double (*transMatrix)[4] = translationMatrix->Element; transMatrix[0][3] = -translateVec[0]; transMatrix[1][3] = -translateVec[1]; transMatrix[2][3] = -translateVec[2]; translationMatrix->Invert(); m_MovingNode->GetData()->GetGeometry()->Compose( translationMatrix ); m_MovingNode->GetData()->Modified(); mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); unsigned long size; size = children->Size(); mitk::DataNode::Pointer childNode; for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( translationMatrix ); childNode->GetData()->Modified(); } m_RedoGeometryList.clear(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkRigidRegistrationView::Rotate(int* rotateVector) { if (m_MovingNode.IsNotNull()) { mitk::Vector3D rotateVec; rotateVec[0] = rotateVector[0] - m_RotateSliderPos[0]; rotateVec[1] = rotateVector[1] - m_RotateSliderPos[1]; rotateVec[2] = rotateVector[2] - m_RotateSliderPos[2]; m_RotateSliderPos[0] = rotateVector[0]; m_RotateSliderPos[1] = rotateVector[1]; m_RotateSliderPos[2] = rotateVector[2]; vtkMatrix4x4* rotationMatrix = vtkMatrix4x4::New(); vtkMatrix4x4* translationMatrix = vtkMatrix4x4::New(); rotationMatrix->Identity(); translationMatrix->Identity(); double (*rotMatrix)[4] = rotationMatrix->Element; double (*transMatrix)[4] = translationMatrix->Element; mitk::Point3D centerBB = m_MovingNode->GetData()->GetGeometry()->GetCenter(); transMatrix[0][3] = centerBB[0]; transMatrix[1][3] = centerBB[1]; transMatrix[2][3] = centerBB[2]; translationMatrix->Invert(); m_MovingNode->GetData()->GetGeometry()->Compose( translationMatrix ); mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); unsigned long size; size = children->Size(); mitk::DataNode::Pointer childNode; for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( translationMatrix ); childNode->GetData()->Modified(); } double radianX = rotateVec[0] * vnl_math::pi / 180; double radianY = rotateVec[1] * vnl_math::pi / 180; double radianZ = rotateVec[2] * vnl_math::pi / 180; if ( rotateVec[0] != 0 ) { rotMatrix[1][1] = cos( radianX ); rotMatrix[1][2] = -sin( radianX ); rotMatrix[2][1] = sin( radianX ); rotMatrix[2][2] = cos( radianX ); } else if ( rotateVec[1] != 0 ) { rotMatrix[0][0] = cos( radianY ); rotMatrix[0][2] = sin( radianY ); rotMatrix[2][0] = -sin( radianY ); rotMatrix[2][2] = cos( radianY ); } else if ( rotateVec[2] != 0 ) { rotMatrix[0][0] = cos( radianZ ); rotMatrix[0][1] = -sin( radianZ ); rotMatrix[1][0] = sin( radianZ ); rotMatrix[1][1] = cos( radianZ ); } m_MovingNode->GetData()->GetGeometry()->Compose( rotationMatrix ); for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( rotationMatrix ); childNode->GetData()->Modified(); } translationMatrix->Invert(); m_MovingNode->GetData()->GetGeometry()->Compose( translationMatrix ); for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( translationMatrix ); childNode->GetData()->Modified(); } m_MovingNode->GetData()->Modified(); m_RedoGeometryList.clear(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkRigidRegistrationView::Scale(int* scaleVector) { if (m_MovingNode.IsNotNull()) { mitk::Vector3D scaleVec; scaleVec[0] = scaleVector[0] - m_ScaleSliderPos[0]; scaleVec[1] = scaleVector[1] - m_ScaleSliderPos[1]; scaleVec[2] = scaleVector[2] - m_ScaleSliderPos[2]; m_ScaleSliderPos[0] = scaleVector[0]; m_ScaleSliderPos[1] = scaleVector[1]; m_ScaleSliderPos[2] = scaleVector[2]; vtkMatrix4x4* scalingMatrix = vtkMatrix4x4::New(); scalingMatrix->Identity(); double (*scaleMatrix)[4] = scalingMatrix->Element; if (scaleVec[0] >= 0) { for(int i = 0; i= 0) { for(int i = 0; i= 0) { for(int i = 0; iInvert(); m_MovingNode->GetData()->GetGeometry()->Compose( scalingMatrix ); m_MovingNode->GetData()->Modified(); mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); unsigned long size; size = children->Size(); mitk::DataNode::Pointer childNode; for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( scalingMatrix ); childNode->GetData()->Modified(); } m_RedoGeometryList.clear(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkRigidRegistrationView::AlignCenters() { if (m_FixedNode.IsNotNull() && m_MovingNode.IsNotNull()) { mitk::Point3D fixedPoint = m_FixedNode->GetData()->GetGeometry()->GetCenter(); mitk::Point3D movingPoint = m_MovingNode->GetData()->GetGeometry()->GetCenter(); mitk::Vector3D translateVec; translateVec = fixedPoint - movingPoint; m_Controls.m_XTransSlider->setValue((int)m_Controls.m_XTransSlider->value() + (int)translateVec[0]); m_Controls.m_YTransSlider->setValue((int)m_Controls.m_YTransSlider->value() + (int)translateVec[1]); m_Controls.m_ZTransSlider->setValue((int)m_Controls.m_ZTransSlider->value() + (int)translateVec[2]); } } void QmitkRigidRegistrationView::SetUndoEnabled( bool enable ) { m_Controls.m_UndoTransformation->setEnabled(enable); } void QmitkRigidRegistrationView::SetRedoEnabled( bool enable ) { m_Controls.m_RedoTransformation->setEnabled(enable); } void QmitkRigidRegistrationView::CheckCalculateEnabled() { if (m_FixedNode.IsNotNull() && m_MovingNode.IsNotNull()) { m_Controls.m_ManualFrame->setEnabled(true); m_Controls.m_CalculateTransformation->setEnabled(true); if ( (m_FixedDimension != m_MovingDimension && std::max(m_FixedDimension, m_MovingDimension) != 4) || m_FixedDimension < 2 /*|| m_FixedDimension > 3*/) { m_Controls.m_CalculateTransformation->setEnabled(false); } else if (m_Controls.qmitkRigidRegistrationSelector1->GetSelectedTransform() < 5 && (m_FixedDimension < 2) /*|| m_FixedDimension > 3)*/) { m_Controls.m_CalculateTransformation->setEnabled(false); } else if ((m_Controls.qmitkRigidRegistrationSelector1->GetSelectedTransform() > 4 && m_Controls.qmitkRigidRegistrationSelector1->GetSelectedTransform() < 13) && !(m_FixedDimension > 2)) { m_Controls.m_CalculateTransformation->setEnabled(false); } else if (m_Controls.qmitkRigidRegistrationSelector1->GetSelectedTransform() > 12 && m_FixedDimension != 2) { m_Controls.m_CalculateTransformation->setEnabled(false); } } else { m_Controls.m_CalculateTransformation->setEnabled(false); m_Controls.m_ManualFrame->setEnabled(false); } } void QmitkRigidRegistrationView::xTrans_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { translationParams[0]=v; translationParams[1]=m_Controls.m_YTransSlider->value(); translationParams[2]=m_Controls.m_ZTransSlider->value(); Translate(translationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::yTrans_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { translationParams[0]=m_Controls.m_XTransSlider->value(); translationParams[1]=v; translationParams[2]=m_Controls.m_ZTransSlider->value(); Translate(translationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::zTrans_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { translationParams[0]=m_Controls.m_XTransSlider->value(); translationParams[1]=m_Controls.m_YTransSlider->value(); translationParams[2]=v; Translate(translationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::xRot_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { rotationParams[0]=v; rotationParams[1]=m_Controls.m_YRotSlider->value(); rotationParams[2]=m_Controls.m_ZRotSlider->value(); Rotate(rotationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::yRot_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { rotationParams[0]=m_Controls.m_XRotSlider->value(); rotationParams[1]=v; rotationParams[2]=m_Controls.m_ZRotSlider->value(); Rotate(rotationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::zRot_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { rotationParams[0]=m_Controls.m_XRotSlider->value(); rotationParams[1]=m_Controls.m_YRotSlider->value(); rotationParams[2]=v; Rotate(rotationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::xScale_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { scalingParams[0]=v; scalingParams[1]=m_Controls.m_YScaleSlider->value(); scalingParams[2]=m_Controls.m_ZScaleSlider->value(); Scale(scalingParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::yScale_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { scalingParams[0]=m_Controls.m_XScaleSlider->value(); scalingParams[1]=v; scalingParams[2]=m_Controls.m_ZScaleSlider->value(); Scale(scalingParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::zScale_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { scalingParams[0]=m_Controls.m_XScaleSlider->value(); scalingParams[1]=m_Controls.m_YScaleSlider->value(); scalingParams[2]=v; Scale(scalingParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::MovingImageChanged() { if (dynamic_cast(m_MovingNode->GetData())) { m_Controls.m_XTransSlider->setValue(0); m_Controls.m_YTransSlider->setValue(0); m_Controls.m_ZTransSlider->setValue(0); translationParams[0]=0; translationParams[1]=0; translationParams[2]=0; m_Controls.m_XRotSlider->setValue(0); m_Controls.m_YRotSlider->setValue(0); m_Controls.m_ZRotSlider->setValue(0); rotationParams[0]=0; rotationParams[1]=0; rotationParams[2]=0; m_Controls.m_XScaleSlider->setValue(0); m_Controls.m_YScaleSlider->setValue(0); m_Controls.m_ZScaleSlider->setValue(0); scalingParams[0]=0; scalingParams[1]=0; scalingParams[2]=0; m_MovingDimension = dynamic_cast(m_MovingNode->GetData())->GetDimension(); m_Controls.qmitkRigidRegistrationSelector1->SetMovingDimension(m_MovingDimension); m_Controls.qmitkRigidRegistrationSelector1->SetMovingNode(m_MovingNode); this->CheckCalculateEnabled(); } } void QmitkRigidRegistrationView::Calculate() { m_Controls.qmitkRigidRegistrationSelector1->SetFixedNode(m_FixedNode); m_Controls.qmitkRigidRegistrationSelector1->SetMovingNode(m_MovingNode); if (m_FixedMaskNode.IsNotNull() && m_Controls.m_UseMaskingCB->isChecked()) { m_Controls.qmitkRigidRegistrationSelector1->SetFixedMaskNode(m_FixedMaskNode); } else { m_Controls.qmitkRigidRegistrationSelector1->SetFixedMaskNode(NULL); } if (m_MovingMaskNode.IsNotNull() && m_Controls.m_UseMaskingCB->isChecked()) { m_Controls.qmitkRigidRegistrationSelector1->SetMovingMaskNode(m_MovingMaskNode); } else { m_Controls.qmitkRigidRegistrationSelector1->SetMovingMaskNode(NULL); } m_Controls.frame_2->setEnabled(false); m_Controls.frame_3->setEnabled(false); m_Controls.m_CalculateTransformation->setEnabled(false); m_Controls.m_StopOptimization->setEnabled(true); m_Controls.qmitkRigidRegistrationSelector1->CalculateTransformation(((QmitkSliderNavigatorWidget*)m_Controls.timeSlider)->GetPos()); m_Controls.m_StopOptimization->setEnabled(false); m_Controls.frame_2->setEnabled(true); m_Controls.frame_3->setEnabled(true); m_Controls.m_CalculateTransformation->setEnabled(true); m_Controls.qmitkRigidRegistrationSelector1->StopOptimization(false); } void QmitkRigidRegistrationView::SetOptimizerValue( double value ) { m_Controls.m_OptimizerValueLCD->display(value); } void QmitkRigidRegistrationView::StopOptimizationClicked() { m_Controls.qmitkRigidRegistrationSelector1->StopOptimization(true); } void QmitkRigidRegistrationView::UpdateTimestep() { mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkRigidRegistrationView::ShowManualRegistrationFrame(bool show) { if (show) { m_Controls.m_ManualFrame->show(); } else { m_Controls.m_ManualFrame->hide(); } } void QmitkRigidRegistrationView::SetImagesVisible(berry::ISelection::ConstPointer /*selection*/) { if (this->m_CurrentSelection->Size() == 0) { // show all images mitk::DataStorage::SetOfObjects::ConstPointer setOfObjects = this->GetDataStorage()->GetAll(); for (mitk::DataStorage::SetOfObjects::ConstIterator nodeIt = setOfObjects->Begin() ; nodeIt != setOfObjects->End(); ++nodeIt) // for each node { if ( (nodeIt->Value().IsNotNull()) && (nodeIt->Value()->GetProperty("visible")) && dynamic_cast(nodeIt->Value()->GetData())==NULL) { nodeIt->Value()->SetVisibility(true); } } } else { // hide all images mitk::DataStorage::SetOfObjects::ConstPointer setOfObjects = this->GetDataStorage()->GetAll(); for (mitk::DataStorage::SetOfObjects::ConstIterator nodeIt = setOfObjects->Begin() ; nodeIt != setOfObjects->End(); ++nodeIt) // for each node { if ( (nodeIt->Value().IsNotNull()) && (nodeIt->Value()->GetProperty("visible")) && dynamic_cast(nodeIt->Value()->GetData())==NULL) { nodeIt->Value()->SetVisibility(false); } } } } void QmitkRigidRegistrationView::TabChanged(int index) { if (index == 0) { m_Controls.frame->hide(); } else { m_Controls.frame->show(); } } void QmitkRigidRegistrationView::SwitchImages() { mitk::DataNode::Pointer newMoving = m_FixedNode; mitk::DataNode::Pointer newFixed = m_MovingNode; this->FixedSelected(newFixed); this->MovingSelected(newMoving); if(m_ContourHelperNode.IsNotNull()) { // Update the contour ShowContour(); } if(m_Controls.m_UseMaskingCB->isChecked()) { mitk::DataNode::Pointer tempMovingMask = NULL; mitk::DataNode::Pointer tempFixedMask = NULL; if(m_FixedMaskNode.IsNotNull()) // it is initialized { tempFixedMask = m_Controls.m_FixedImageCB->GetSelectedNode(); } if(m_MovingMaskNode.IsNotNull()) // it is initialized { tempMovingMask = m_Controls.m_MovingImageCB->GetSelectedNode(); } m_Controls.m_FixedImageCB->SetSelectedNode(tempMovingMask); m_Controls.m_MovingImageCB->SetSelectedNode(tempFixedMask); } } void QmitkRigidRegistrationView::OnUseMaskingChanged( int state ) { if(state == Qt::Checked) { m_Controls.m_FixedImageCB->show(); m_Controls.m_MovingImageCB->show(); m_Controls.m_MovingMaskLB->show(); m_Controls.m_FixedMaskLB->show(); } else { m_Controls.m_FixedImageCB->hide(); m_Controls.m_MovingImageCB->hide(); m_Controls.m_MovingMaskLB->hide(); m_Controls.m_FixedMaskLB->hide(); m_FixedMaskNode = NULL; m_MovingMaskNode = NULL; } } void QmitkRigidRegistrationView::OnFixedMaskImageChanged( const mitk::DataNode* node ) { if(m_Controls.m_UseMaskingCB->isChecked()) m_FixedMaskNode = const_cast(node); else m_FixedMaskNode = NULL; } void QmitkRigidRegistrationView::OnMovingMaskImageChanged( const mitk::DataNode* node ) { if(m_Controls.m_UseMaskingCB->isChecked()) m_MovingMaskNode = const_cast(node); else m_MovingMaskNode = NULL; } diff --git a/Plugins/org.mitk.gui.qt.segmentation/files.cmake b/Plugins/org.mitk.gui.qt.segmentation/files.cmake index 24a87be816..cde1e33fb3 100644 --- a/Plugins/org.mitk.gui.qt.segmentation/files.cmake +++ b/Plugins/org.mitk.gui.qt.segmentation/files.cmake @@ -1,78 +1,81 @@ set(SRC_CPP_FILES QmitkSegmentationPreferencePage.cpp ) set(INTERNAL_CPP_FILES mitkPluginActivator.cpp QmitkSegmentationView.cpp QmitkThresholdAction.cpp QmitkCreatePolygonModelAction.cpp #QmitkStatisticsAction.cpp QmitkAutocropAction.cpp QmitkDeformableClippingPlaneView.cpp Common/QmitkDataSelectionWidget.cpp SegmentationUtilities/QmitkSegmentationUtilitiesView.cpp SegmentationUtilities/QmitkSegmentationUtilityWidget.cpp SegmentationUtilities/BooleanOperations/QmitkBooleanOperationsWidget.cpp SegmentationUtilities/ImageMasking/QmitkImageMaskingWidget.cpp + SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidget.cpp SegmentationUtilities/MorphologicalOperations/QmitkMorphologicalOperationsWidget.cpp SegmentationUtilities/SurfaceToImage/QmitkSurfaceToImageWidget.cpp SegmentationUtilities/CTKWidgets/QmitkCTKWidgetsWidget.cpp ) set(UI_FILES src/internal/QmitkSegmentationControls.ui src/internal/QmitkDeformableClippingPlaneViewControls.ui src/internal/Common/QmitkDataSelectionWidgetControls.ui src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesViewControls.ui src/internal/SegmentationUtilities/BooleanOperations/QmitkBooleanOperationsWidgetControls.ui src/internal/SegmentationUtilities/ImageMasking/QmitkImageMaskingWidgetControls.ui + src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidgetControls.ui src/internal/SegmentationUtilities/MorphologicalOperations/QmitkMorphologicalOperationsWidgetControls.ui src/internal/SegmentationUtilities/SurfaceToImage/QmitkSurfaceToImageWidgetControls.ui ) set(MOC_H_FILES src/QmitkSegmentationPreferencePage.h src/internal/mitkPluginActivator.h src/internal/QmitkSegmentationView.h src/internal/QmitkThresholdAction.h src/internal/QmitkCreatePolygonModelAction.h #src/internal/QmitkStatisticsAction.h src/internal/QmitkAutocropAction.h src/internal/QmitkDeformableClippingPlaneView.h src/internal/Common/QmitkDataSelectionWidget.h src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesView.h src/internal/SegmentationUtilities/QmitkSegmentationUtilityWidget.h src/internal/SegmentationUtilities/BooleanOperations/QmitkBooleanOperationsWidget.h src/internal/SegmentationUtilities/ImageMasking/QmitkImageMaskingWidget.h + src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidget.h src/internal/SegmentationUtilities/MorphologicalOperations/QmitkMorphologicalOperationsWidget.h src/internal/SegmentationUtilities/SurfaceToImage/QmitkSurfaceToImageWidget.h src/internal/SegmentationUtilities/CTKWidgets/QmitkCTKWidgetsWidget.h ) set(CACHED_RESOURCE_FILES resources/segmentation.png resources/deformablePlane.png resources/clipping_plane_translate_48x48.png resources/clipping_plane_rotate48x48.png resources/clipping_plane_deform48x48.png resources/SegmentationUtilities_48x48.png plugin.xml ) set(QRC_FILES resources/segmentation.qrc resources/SegmentationUtilities.qrc resources/BooleanOperationsWidget.qrc resources/MorphologicalOperationsWidget.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.segmentation/resources/ContourModelSetToImage_48x48.png b/Plugins/org.mitk.gui.qt.segmentation/resources/ContourModelSetToImage_48x48.png new file mode 100644 index 0000000000..aaf163e33b Binary files /dev/null and b/Plugins/org.mitk.gui.qt.segmentation/resources/ContourModelSetToImage_48x48.png differ diff --git a/Plugins/org.mitk.gui.qt.segmentation/resources/SegmentationUtilities.qrc b/Plugins/org.mitk.gui.qt.segmentation/resources/SegmentationUtilities.qrc index d070baaf05..5b257c350f 100644 --- a/Plugins/org.mitk.gui.qt.segmentation/resources/SegmentationUtilities.qrc +++ b/Plugins/org.mitk.gui.qt.segmentation/resources/SegmentationUtilities.qrc @@ -1,10 +1,11 @@ BooleanOperations_48x48.png + ContourModelSetToImage_48x48.png ImageMasking_48x48.png MorphologicalOperations_48x48.png SurfaceToImage_48x48.png SegmentationUtilities_48x48.png CTKWidgets_48x48.png diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkDataSelectionWidget.cpp b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkDataSelectionWidget.cpp index 1df4b355ce..231887ec1c 100644 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkDataSelectionWidget.cpp +++ b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkDataSelectionWidget.cpp @@ -1,158 +1,165 @@ /*=================================================================== 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 "QmitkDataSelectionWidget.h" #include +#include +#include #include #include #include #include #include +#include #include #include #include #include #include #include #include #include static mitk::NodePredicateBase::Pointer CreatePredicate(QmitkDataSelectionWidget::Predicate predicate) { switch(predicate) { case QmitkDataSelectionWidget::ImagePredicate: return mitk::NodePredicateAnd::New( mitk::TNodePredicateDataType::New(), mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true))), mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object"))).GetPointer(); case QmitkDataSelectionWidget::SegmentationPredicate: return mitk::NodePredicateAnd::New( mitk::TNodePredicateDataType::New(), mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true)), mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object"))).GetPointer(); case QmitkDataSelectionWidget::SurfacePredicate: return mitk::NodePredicateAnd::New( mitk::TNodePredicateDataType::New(), mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object"))).GetPointer(); case QmitkDataSelectionWidget::ImageAndSegmentationPredicate: return mitk::NodePredicateAnd::New( mitk::TNodePredicateDataType::New(), mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object"))).GetPointer(); - + case QmitkDataSelectionWidget::ContourModelPredicate: + return mitk::NodePredicateAnd::New( + mitk::NodePredicateOr::New( mitk::TNodePredicateDataType::New(), + mitk::TNodePredicateDataType::New()), + mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object"))).GetPointer(); default: assert(false && "Unknown predefined predicate!"); return NULL; } } QmitkDataSelectionWidget::QmitkDataSelectionWidget(QWidget* parent) : QWidget(parent) { m_Controls.setupUi(this); m_Controls.helpLabel->hide(); } QmitkDataSelectionWidget::~QmitkDataSelectionWidget() { } unsigned int QmitkDataSelectionWidget::AddDataStorageComboBox(QmitkDataSelectionWidget::Predicate predicate) { return this->AddDataStorageComboBox("", predicate); } unsigned int QmitkDataSelectionWidget::AddDataStorageComboBox(mitk::NodePredicateBase* predicate) { return this->AddDataStorageComboBox("", predicate); } unsigned int QmitkDataSelectionWidget::AddDataStorageComboBox(const QString &labelText, QmitkDataSelectionWidget::Predicate predicate) { return this->AddDataStorageComboBox(labelText, CreatePredicate(predicate)); } unsigned int QmitkDataSelectionWidget::AddDataStorageComboBox(const QString &labelText, mitk::NodePredicateBase* predicate) { int row = m_Controls.gridLayout->rowCount(); if (!labelText.isEmpty()) { QLabel* label = new QLabel(labelText, m_Controls.dataSelectionWidget); label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); m_Controls.gridLayout->addWidget(label, row, 0); } QmitkDataStorageComboBox* comboBox = new QmitkDataStorageComboBox(this->GetDataStorage(), predicate, m_Controls.dataSelectionWidget); connect(comboBox, SIGNAL(OnSelectionChanged(const mitk::DataNode *)), this, SLOT(OnSelectionChanged(const mitk::DataNode *))); m_Controls.gridLayout->addWidget(comboBox, row, 1); m_DataStorageComboBoxes.push_back(comboBox); return static_cast(m_DataStorageComboBoxes.size() - 1); } mitk::DataStorage::Pointer QmitkDataSelectionWidget::GetDataStorage() const { mitk::IDataStorageService::Pointer service = berry::Platform::GetServiceRegistry().GetServiceById(mitk::IDataStorageService::ID); assert(service.IsNotNull()); return service->GetDefaultDataStorage()->GetDataStorage(); } mitk::DataNode::Pointer QmitkDataSelectionWidget::GetSelection(unsigned int index) { assert(index < m_DataStorageComboBoxes.size()); return m_DataStorageComboBoxes[index]->GetSelectedNode(); } void QmitkDataSelectionWidget::SetPredicate(unsigned int index, Predicate predicate) { this->SetPredicate(index, CreatePredicate(predicate)); } void QmitkDataSelectionWidget::SetPredicate(unsigned int index, mitk::NodePredicateBase* predicate) { assert(index < m_DataStorageComboBoxes.size()); m_DataStorageComboBoxes[index]->SetPredicate(predicate); } void QmitkDataSelectionWidget::SetHelpText(const QString& text) { if (!text.isEmpty()) { m_Controls.helpLabel->setText(text); if (!m_Controls.helpLabel->isVisible()) m_Controls.helpLabel->show(); } else { m_Controls.helpLabel->hide(); } } void QmitkDataSelectionWidget::OnSelectionChanged(const mitk::DataNode* selection) { std::vector::iterator it = std::find(m_DataStorageComboBoxes.begin(), m_DataStorageComboBoxes.end(), sender()); assert(it != m_DataStorageComboBoxes.end()); emit SelectionChanged(std::distance(m_DataStorageComboBoxes.begin(), it), selection); } diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkDataSelectionWidget.h b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkDataSelectionWidget.h index 8b0f44b17f..b0eaaf78bd 100644 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkDataSelectionWidget.h +++ b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkDataSelectionWidget.h @@ -1,70 +1,71 @@ /*=================================================================== 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 QmitkDataSelectionWidget_h #define QmitkDataSelectionWidget_h #include #include #include #include namespace mitk { class NodePredicateBase; } class QmitkDataStorageComboBox; class QmitkDataSelectionWidget : public QWidget { Q_OBJECT public: enum Predicate { ImagePredicate, SegmentationPredicate, SurfacePredicate, - ImageAndSegmentationPredicate + ImageAndSegmentationPredicate, + ContourModelPredicate }; explicit QmitkDataSelectionWidget(QWidget* parent = NULL); ~QmitkDataSelectionWidget(); unsigned int AddDataStorageComboBox(Predicate predicate); unsigned int AddDataStorageComboBox(mitk::NodePredicateBase* predicate = NULL); unsigned int AddDataStorageComboBox(const QString &labelText, Predicate predicate); unsigned int AddDataStorageComboBox(const QString &labelText, mitk::NodePredicateBase* predicate = NULL); mitk::DataStorage::Pointer GetDataStorage() const; mitk::DataNode::Pointer GetSelection(unsigned int index); void SetPredicate(unsigned int index, Predicate predicate); void SetPredicate(unsigned int index, mitk::NodePredicateBase* predicate); void SetHelpText(const QString& text); signals: void SelectionChanged(unsigned int index, const mitk::DataNode* selection); private slots: void OnSelectionChanged(const mitk::DataNode* selection); private: Ui::QmitkDataSelectionWidgetControls m_Controls; std::vector m_DataStorageComboBoxes; }; #endif diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidget.cpp b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidget.cpp new file mode 100644 index 0000000000..24ec826e15 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidget.cpp @@ -0,0 +1,172 @@ +/*=================================================================== + +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 "QmitkContourModelToImageWidget.h" +#include "mitkImage.h" +#include "../../Common/QmitkDataSelectionWidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static const char* const HelpText = "Select a image and a contour(set)"; + +QmitkContourModelToImageWidget::QmitkContourModelToImageWidget(mitk::SliceNavigationController* timeNavigationController, QWidget* parent) + : QmitkSegmentationUtilityWidget(timeNavigationController, parent) +{ + m_Controls.setupUi(this); + + m_Controls.dataSelectionWidget->AddDataStorageComboBox(QmitkDataSelectionWidget::ImageAndSegmentationPredicate); + m_Controls.dataSelectionWidget->AddDataStorageComboBox(QmitkDataSelectionWidget::ContourModelPredicate); + m_Controls.dataSelectionWidget->SetHelpText(HelpText); + + this->EnableButtons(false); + + connect (m_Controls.btnProcess, SIGNAL(pressed()), this, SLOT(OnProcessPressed())); + + connect(m_Controls.dataSelectionWidget, SIGNAL(SelectionChanged(unsigned int, const mitk::DataNode*)), + this, SLOT(OnSelectionChanged(unsigned int, const mitk::DataNode*))); + + if( m_Controls.dataSelectionWidget->GetSelection(0).IsNotNull() && + m_Controls.dataSelectionWidget->GetSelection(1).IsNotNull() ) + { + this->OnSelectionChanged( 0, m_Controls.dataSelectionWidget->GetSelection(0)); + } +} + +QmitkContourModelToImageWidget::~QmitkContourModelToImageWidget() +{ +} + +void QmitkContourModelToImageWidget::OnSelectionChanged(unsigned int index, const mitk::DataNode* selection) +{ + QmitkDataSelectionWidget* dataSelectionWidget = m_Controls.dataSelectionWidget; + mitk::DataNode::Pointer node0 = dataSelectionWidget->GetSelection(0); + mitk::DataNode::Pointer node1 = dataSelectionWidget->GetSelection(1); + + if (node0.IsNull() || node1.IsNull() ) + { + this->EnableButtons(false); + dataSelectionWidget->SetHelpText(HelpText); + } + else + { + this->SelectionControl(index, selection); + } +} + +void QmitkContourModelToImageWidget::SelectionControl(unsigned int index, const mitk::DataNode* /*selection*/) +{ + QmitkDataSelectionWidget* dataSelectionWidget = m_Controls.dataSelectionWidget; + mitk::DataNode::Pointer node = dataSelectionWidget->GetSelection(index); + + dataSelectionWidget->SetHelpText(""); + this->EnableButtons(); +} + +void QmitkContourModelToImageWidget::EnableButtons(bool enable) +{ + m_Controls.btnProcess->setEnabled(enable); +} + +void QmitkContourModelToImageWidget::OnProcessPressed() +{ + QmitkDataSelectionWidget* dataSelectionWidget = m_Controls.dataSelectionWidget; + + mitk::DataNode::Pointer imageNode = dataSelectionWidget->GetSelection(0); + mitk::DataNode::Pointer contourNode = dataSelectionWidget->GetSelection(1); + + if(imageNode.IsNull() || contourNode.IsNull() ) + { + MITK_ERROR << "Selection does not contain valid data"; + QMessageBox::information( this, "Contour To Image", + "Selection does not contain valid data, please select a binary image and a contour(set)", QMessageBox::Ok ); + m_Controls.btnProcess->setEnabled(false); + return; + } + + mitk::Image::Pointer image = static_cast(imageNode->GetData()); + + if (image.IsNull()) + { + MITK_ERROR<<"Error writing contours into image! Invalid image data selected!"; + return; + } + + unsigned int timeStep = this->GetTimeNavigationController()->GetTime()->GetPos(); + + mitk::ContourModelSet::Pointer contourSet; + mitk::ContourModel::Pointer contour = dynamic_cast(contourNode->GetData()); + if (contour.IsNotNull()) + { + contourSet = mitk::ContourModelSet::New(); + contourSet->AddContourModel(contour); + } + else + { + contourSet = static_cast(contourNode->GetData()); + if (contourSet.IsNull()) + { + MITK_ERROR<<"Error writing contours into binary image! Invalid contour data selected!"; + return; + } + } + + //Disable Buttons during calculation and initialize Progressbar + this->EnableButtons(false); + unsigned int num_contours = contourSet->GetContourModelList()->size(); + mitk::ProgressBar::GetInstance()->AddStepsToDo(num_contours); + mitk::ProgressBar::GetInstance()->Progress(); + + // Use mitk::ContourModelSetToImageFilter to fill the ContourModelSet into the image + mitk::ContourModelSetToImageFilter::Pointer contourFiller = mitk::ContourModelSetToImageFilter::New(); + contourFiller->SetTimeStep(timeStep); + contourFiller->SetImage(image); + contourFiller->SetInput(contourSet); + contourFiller->MakeOutputBinaryOn(); + contourFiller->Update(); + + // Add result to data storage + mitk::Image::Pointer result = contourFiller->GetOutput(); + if (result.IsNull()) + { + MITK_ERROR<<"Could not write the selected contours into the image!"; + return; + } + + result->DisconnectPipeline(); + mitk::DataNode::Pointer filled = mitk::DataNode::New(); + std::stringstream stream; + stream << imageNode->GetName(); + stream << "_"; + stream << contourNode->GetName(); + filled->SetName(stream.str()); + filled->SetData(result); + dataSelectionWidget->GetDataStorage()->Add(filled, imageNode); + + this->EnableButtons(); + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); +} diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidget.h b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidget.h new file mode 100644 index 0000000000..52750f08f6 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidget.h @@ -0,0 +1,76 @@ +/*=================================================================== + +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 QmitkContourModelToImageWidget_h +#define QmitkContourModelToImageWidget_h + +#include "../QmitkSegmentationUtilityWidget.h" +#include + +namespace mitk { + class Image; + class ContourModelSet; + class ContourModel; + class Geometry3D; + class PlaneGeometry; +} + +/*! + \brief QmitkContourModelToImageWidget + + Tool masks an image with a binary image or a surface. The Method requires + an image and a binary image mask or a surface. The input image and the binary + image mask must be of the same size. Masking with a surface creates first a + binary image of the surface and then use this for the masking of the input image. +*/ +class QmitkContourModelToImageWidget : public QmitkSegmentationUtilityWidget +{ + Q_OBJECT + +public: + + /** @brief Default constructor, including creation of GUI elements and signals/slots connections. */ + explicit QmitkContourModelToImageWidget(mitk::SliceNavigationController* timeNavigationController, QWidget* parent = NULL); + + /** @brief Defaul destructor. */ + ~QmitkContourModelToImageWidget(); + +private slots: + + /** @brief This slot is called if the selection in the workbench is changed. */ + void OnSelectionChanged(unsigned int index, const mitk::DataNode* selection); + + /** @brief This slot is called if user activates the button to mask an image. */ + void OnProcessPressed(); + +private: + + /** @brief Check if selections is valid. */ + void SelectionControl( unsigned int index, const mitk::DataNode* selection); + + /** @brief Enable buttons if data selction is valid. */ + void EnableButtons(bool enable = true); + + /** @brief Fills a mitk::ContourModel into a given segmentation image */ + itk::SmartPointer ContourModelToImage(itk::SmartPointer segmenationImage, itk::SmartPointer contour ); + + /** @brief Fills a whole ContourModelSet into a given segmentation image */ + itk::SmartPointer ContourModelSetToImage( itk::SmartPointer segmenationImage, itk::SmartPointer contourSet ); + + Ui::QmitkContourModelToImageWidgetControls m_Controls; +}; + +#endif diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidgetControls.ui b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidgetControls.ui new file mode 100644 index 0000000000..d69bca34b7 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/ContourModelToImage/QmitkContourModelToImageWidgetControls.ui @@ -0,0 +1,48 @@ + + + QmitkContourModelToImageWidgetControls + + + + 0 + 0 + 180 + 154 + + + + + + + + + + Process + + + + + + + Qt::Vertical + + + + 20 + 273 + + + + + + + + + QmitkDataSelectionWidget + QWidget +
internal/Common/QmitkDataSelectionWidget.h
+
+
+ + +
diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesView.cpp b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesView.cpp index 0c62bdb2c1..2a052fa130 100644 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesView.cpp +++ b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesView.cpp @@ -1,99 +1,105 @@ /*=================================================================== 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. ===================================================================*/ // #define ENABLE_CTK_WIDGETS_WIDGET #include "QmitkSegmentationUtilitiesView.h" #include "BooleanOperations/QmitkBooleanOperationsWidget.h" +#include "ContourModelToImage/QmitkContourModelToImageWidget.h" #include "ImageMasking/QmitkImageMaskingWidget.h" #include "MorphologicalOperations/QmitkMorphologicalOperationsWidget.h" #include "SurfaceToImage/QmitkSurfaceToImageWidget.h" #include "CTKWidgets/QmitkCTKWidgetsWidget.h" QmitkSegmentationUtilitiesView::QmitkSegmentationUtilitiesView() : m_BooleanOperationsWidget(NULL), + m_ContourModelToImageWidget(NULL), m_ImageMaskingWidget(NULL), m_MorphologicalOperationsWidget(NULL), m_SurfaceToImageWidget(NULL), m_CTKWidgetsWidget(NULL) { } QmitkSegmentationUtilitiesView::~QmitkSegmentationUtilitiesView() { } void QmitkSegmentationUtilitiesView::CreateQtPartControl(QWidget* parent) { m_Controls.setupUi(parent); mitk::IRenderWindowPart* renderWindowPart = this->GetRenderWindowPart(); mitk::SliceNavigationController* timeNavigationController = renderWindowPart != NULL ? renderWindowPart->GetTimeNavigationController() : NULL; m_BooleanOperationsWidget = new QmitkBooleanOperationsWidget(timeNavigationController, parent); + m_ContourModelToImageWidget = new QmitkContourModelToImageWidget(timeNavigationController, parent); m_ImageMaskingWidget = new QmitkImageMaskingWidget(timeNavigationController, parent); m_MorphologicalOperationsWidget = new QmitkMorphologicalOperationsWidget(timeNavigationController, parent); m_SurfaceToImageWidget = new QmitkSurfaceToImageWidget(timeNavigationController, parent); this->AddUtilityWidget(m_BooleanOperationsWidget, QIcon(":/SegmentationUtilities/BooleanOperations_48x48.png"), "Boolean Operations"); + this->AddUtilityWidget(m_ContourModelToImageWidget, QIcon(":/SegmentationUtilities/ContourModelSetToImage_48x48.png"), "Contour To Image"); this->AddUtilityWidget(m_ImageMaskingWidget, QIcon(":/SegmentationUtilities/ImageMasking_48x48.png"), "Image Masking"); this->AddUtilityWidget(m_MorphologicalOperationsWidget, QIcon(":/SegmentationUtilities/MorphologicalOperations_48x48.png"), "Morphological Operations"); this->AddUtilityWidget(m_SurfaceToImageWidget, QIcon(":/SegmentationUtilities/SurfaceToImage_48x48.png"), "Surface To Image"); #ifdef ENABLE_CTK_WIDGETS_WIDGET m_CTKWidgetsWidget = new QmitkCTKWidgetsWidget(timeNavigationController, parent); this->AddUtilityWidget(m_CTKWidgetsWidget, QIcon(":/SegmentationUtilities/CTKWidgets_48x48.png"), "CTK Widgets"); #endif } void QmitkSegmentationUtilitiesView::AddUtilityWidget(QWidget* widget, const QIcon& icon, const QString& text) { m_Controls.toolBox->addItem(widget, icon, text); } void QmitkSegmentationUtilitiesView::SetFocus() { m_Controls.toolBox->setFocus(); } void QmitkSegmentationUtilitiesView::RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) { mitk::SliceNavigationController* timeNavigationController = renderWindowPart->GetTimeNavigationController(); m_BooleanOperationsWidget->SetTimeNavigationController(timeNavigationController); + m_ContourModelToImageWidget->SetTimeNavigationController(timeNavigationController); m_ImageMaskingWidget->SetTimeNavigationController(timeNavigationController); m_MorphologicalOperationsWidget->SetTimeNavigationController(timeNavigationController); m_SurfaceToImageWidget->SetTimeNavigationController(timeNavigationController); #ifdef ENABLE_CTK_WIDGETS_WIDGET m_CTKWidgetsWidget->SetTimeNavigationController(timeNavigationController); #endif } void QmitkSegmentationUtilitiesView::RenderWindowPartDeactivated(mitk::IRenderWindowPart*) { m_BooleanOperationsWidget->SetTimeNavigationController(NULL); + m_ContourModelToImageWidget->SetTimeNavigationController(NULL); m_ImageMaskingWidget->SetTimeNavigationController(NULL); m_MorphologicalOperationsWidget->SetTimeNavigationController(NULL); m_SurfaceToImageWidget->SetTimeNavigationController(NULL); #ifdef ENABLE_CTK_WIDGETS_WIDGET m_CTKWidgetsWidget->SetTimeNavigationController(NULL); #endif } diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesView.h b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesView.h index ef82651dad..ebd991eabd 100644 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesView.h +++ b/Plugins/org.mitk.gui.qt.segmentation/src/internal/SegmentationUtilities/QmitkSegmentationUtilitiesView.h @@ -1,55 +1,57 @@ /*=================================================================== 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 QmitkSegmentationUtilitiesView_h #define QmitkSegmentationUtilitiesView_h #include #include #include class QmitkBooleanOperationsWidget; +class QmitkContourModelToImageWidget; class QmitkImageMaskingWidget; class QmitkMorphologicalOperationsWidget; class QmitkSurfaceToImageWidget; class QmitkCTKWidgetsWidget; class QmitkSegmentationUtilitiesView : public QmitkAbstractView, public mitk::IRenderWindowPartListener { Q_OBJECT public: QmitkSegmentationUtilitiesView(); ~QmitkSegmentationUtilitiesView(); void CreateQtPartControl(QWidget* parent); void SetFocus(); void RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart); void RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderWindowPart); private: void AddUtilityWidget(QWidget* widget, const QIcon& icon, const QString& text); Ui::QmitkSegmentationUtilitiesViewControls m_Controls; QmitkBooleanOperationsWidget* m_BooleanOperationsWidget; + QmitkContourModelToImageWidget* m_ContourModelToImageWidget; QmitkImageMaskingWidget* m_ImageMaskingWidget; QmitkMorphologicalOperationsWidget* m_MorphologicalOperationsWidget; QmitkSurfaceToImageWidget* m_SurfaceToImageWidget; QmitkCTKWidgetsWidget* m_CTKWidgetsWidget; }; #endif