diff --git a/Modules/Segmentation/Algorithms/mitkDiffSliceOperation.cpp b/Modules/Segmentation/Algorithms/mitkDiffSliceOperation.cpp new file mode 100644 index 0000000000..8ef9d07cd7 --- /dev/null +++ b/Modules/Segmentation/Algorithms/mitkDiffSliceOperation.cpp @@ -0,0 +1,97 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision: $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "DiffSliceOperation.h" + +#include + +mitk::DiffSliceOperation::DiffSliceOperation():Operation(1) +{ + m_TimeStep = 0; + m_Slice = NULL; + m_Image = NULL; + m_WorldGeometry = NULL; + m_SliceGeometry = NULL; + m_ImageIsValid = false; +} + + +mitk::DiffSliceOperation::DiffSliceOperation(mitk::Image* imageVolume, + vtkImageData* slice, + AffineGeometryFrame3D* sliceGeometry, + unsigned int timestep, + AffineGeometryFrame3D* currentWorldGeometry):Operation(1) + +{ + m_WorldGeometry = currentWorldGeometry->Clone(); + m_SliceGeometry = sliceGeometry->Clone(); + + m_TimeStep = timestep; + + /*m_zlibSliceContainer = CompressedImageContainer::New(); + m_zlibSliceContainer->SetImage( slice );*/ + m_Slice = vtkSmartPointer::New(); + m_Slice->DeepCopy(slice); + + m_Image = imageVolume; + + if ( m_Image) { + /*add an observer to listen to the delete event of the image, this is necessary because the operation is then invalid*/ + itk::SimpleMemberCommand< DiffSliceOperation >::Pointer command = itk::SimpleMemberCommand< DiffSliceOperation >::New(); + command->SetCallbackFunction( this, &DiffSliceOperation::OnImageDeleted ); + //get the id of the observer, used to remove it later on + m_DeleteObserverTag = imageVolume->AddObserver( itk::DeleteEvent(), command ); + + + m_ImageIsValid = true; + } + else + m_ImageIsValid = false; + +} + +mitk::DiffSliceOperation::~DiffSliceOperation() +{ + + m_Slice = NULL; + m_WorldGeometry = NULL; + //m_zlibSliceContainer = NULL; + + if (m_ImageIsValid) + { + //if the image is still there, we have to remove the observer from it + m_Image->RemoveObserver( m_DeleteObserverTag ); + } + m_Image = NULL; +} + +vtkImageData* mitk::DiffSliceOperation::GetSlice() +{ + //Image::ConstPointer image = m_zlibSliceContainer->GetImage().GetPointer(); + return m_Slice; +} + +bool mitk::DiffSliceOperation::IsValid() +{ + return m_ImageIsValid && (m_Slice.GetPointer() != NULL) && (m_WorldGeometry.IsNotNull());//TODO improve +} + +void mitk::DiffSliceOperation::OnImageDeleted() +{ + //if our imageVolume is removed e.g. from the datastorage the operation is no lnger valid + m_ImageIsValid = false; +} \ No newline at end of file diff --git a/Modules/Segmentation/Algorithms/mitkDiffSliceOperation.h b/Modules/Segmentation/Algorithms/mitkDiffSliceOperation.h new file mode 100644 index 0000000000..f254211c4e --- /dev/null +++ b/Modules/Segmentation/Algorithms/mitkDiffSliceOperation.h @@ -0,0 +1,117 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef mitkDiffSliceOperation_h_Included +#define mitkDiffSliceOperation_h_Included + +#include "SegmentationExports.h" +#include "mitkCommon.h" +#include +//#include "mitkCompressedImageContainer.h" + +#include +#include +#include + + +namespace mitk +{ + /** \brief An Operation for applying an edited slice to the volume. + \sa DiffSliceOperationApplier + + The information for the operation is specified by properties: + + imageVolume the volume where the slice was extracted from. + slice the slice to be applied. + timestep the timestep in an 4D image. + currentWorldGeometry specifies the axis where the slice has to be applied in the volume. + + This Operation can be used to realize undo-redo functionality for e.g. segmentation purposes. + */ + class Segmentation_EXPORT DiffSliceOperation : public Operation + { + + public: + + mitkClassMacro(DiffSliceOperation, OperationActor); + + //itkNewMacro(DiffSliceOperation); + + //mitkNewMacro4Param(DiffSliceOperation,mitk::Image,mitk::Image,unsigned int, mitk::Geometry2D); + + /** \brief Creates an empty instance. + Note that it is not valid yet. The properties of the object have to be set. + */ + DiffSliceOperation(); + + /** \brief */ + DiffSliceOperation( mitk::Image* imageVolume, vtkImageData* slice, AffineGeometryFrame3D* sliceGeometry, unsigned int timestep, AffineGeometryFrame3D* currentWorldGeometry); + + /** \brief Check if it is a valid operation.*/ + bool IsValid(); + + /** \brief Set the image volume.*/ + void SetImage(mitk::Image* image){ this->m_Image = image;} + /** \brief Get th image volume.*/ + mitk::Image* GetImage(){return this->m_Image;} + + /** \brief Set thee slice to be applied.*/ + void SetImage(vtkImageData* slice){ this->m_Slice = slice;} + /** \brief Get the slice that is applied in the operation.*/ + vtkImageData* GetSlice(); + + /** \brief Get timeStep.*/ + void SetTimeStep(unsigned int timestep){this->m_TimeStep = timestep;} + /** \brief Set timeStep*/ + unsigned int GetTimeStep(){return this->m_TimeStep;} + + /** \brief Set the axis where the slice has to be applied in the volume.*/ + void SetSliceGeometry(AffineGeometryFrame3D* sliceGeometry){this->m_SliceGeometry = sliceGeometry;} + /** \brief Get the axis where the slice has to be applied in the volume.*/ + AffineGeometryFrame3D* GetSliceGeometry(){return this->m_SliceGeometry;} + + /** \brief Set the axis where the slice has to be applied in the volume.*/ + void SetCurrentWorldGeometry(AffineGeometryFrame3D* worldGeometry){this->m_WorldGeometry = worldGeometry;} + /** \brief Get the axis where the slice has to be applied in the volume.*/ + AffineGeometryFrame3D* GetWorldGeometry(){return this->m_WorldGeometry;} + + + protected: + + virtual ~DiffSliceOperation(); + + /** \brief Callback for image observer.*/ + void OnImageDeleted(); + + //CompressedImageContainer::Pointer m_zlibSliceContainer; + + mitk::Image* m_Image; + + vtkSmartPointer m_Slice; + + AffineGeometryFrame3D::Pointer m_SliceGeometry; + + unsigned int m_TimeStep; + + AffineGeometryFrame3D::Pointer m_WorldGeometry; + + bool m_ImageIsValid; + + unsigned long m_DeleteObserverTag; + + }; +} +#endif \ No newline at end of file diff --git a/Modules/Segmentation/Algorithms/mitkDiffSliceOperationApplier.cpp b/Modules/Segmentation/Algorithms/mitkDiffSliceOperationApplier.cpp new file mode 100644 index 0000000000..f302b883a6 --- /dev/null +++ b/Modules/Segmentation/Algorithms/mitkDiffSliceOperationApplier.cpp @@ -0,0 +1,77 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision: $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "DiffSliceOperationApplier.h" +#include "mitkRenderingManager.h" +#include + +mitk::DiffSliceOperationApplier::DiffSliceOperationApplier() +{ +} + +mitk::DiffSliceOperationApplier::~DiffSliceOperationApplier() +{ +} + +void mitk::DiffSliceOperationApplier::ExecuteOperation( Operation* operation ) +{ + DiffSliceOperation* imageOperation = dynamic_cast( operation ); + + //as we only support DiffSliceOperation return if operation is not type of DiffSliceOperation + if(!imageOperation) + return; + + + //chak if the operation is valid + if(imageOperation->IsValid()) + { + //the actual overwrite filter (vtk) + vtkSmartPointer reslice = vtkSmartPointer::New(); + + //Set the slice as 'input' + reslice->SetInputSlice(imageOperation->GetSlice()); + + //set overwrite mode to true to write back to the image volume + reslice->SetOverwriteMode(true); + reslice->Modified(); + + //a wrapper for vtkImageOverwrite + mitk::ExtractSliceFilter::Pointer extractor = mitk::ExtractSliceFilter::New(reslice); + extractor->SetInput( imageOperation->GetImage() ); + extractor->SetTimeStep( imageOperation->GetTimeStep() ); + extractor->SetWorldGeometry( dynamic_cast(imageOperation->GetWorldGeometry()) ); + extractor->SetVtkOutputRequest(true); + extractor->SetResliceTransformByGeometry( imageOperation->GetImage()->GetTimeSlicedGeometry()->GetGeometry3D( imageOperation->GetTimeStep() ) ); + + extractor->Modified(); + extractor->Update(); + + //make sure the modification is rendered + RenderingManager::GetInstance()->RequestUpdateAll(); + imageOperation->GetImage()->Modified(); + } +} + +//mitk::DiffSliceOperationApplier* mitk::DiffSliceOperationApplier::s_Instance = NULL; + +mitk::DiffSliceOperationApplier* mitk::DiffSliceOperationApplier::GetInstance() +{ + //if(!s_Instance) + static DiffSliceOperationApplier* s_Instance = new DiffSliceOperationApplier(); + + return s_Instance; +} \ No newline at end of file diff --git a/Modules/Segmentation/Algorithms/mitkDiffSliceOperationApplier.h b/Modules/Segmentation/Algorithms/mitkDiffSliceOperationApplier.h new file mode 100644 index 0000000000..7695761c80 --- /dev/null +++ b/Modules/Segmentation/Algorithms/mitkDiffSliceOperationApplier.h @@ -0,0 +1,63 @@ +/*=================================================================== + +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 mitkDiffSliceOpertationApplier_h_Included +#define mitkDiffSliceOpertationApplier_h_Included + +#include "SegmentationExports.h" +#include "mitkCommon.h" +#include + +#include "DiffSliceOperation.h" +#include +#include + +namespace mitk +{ + /** \brief Executes a DiffSliceOperation. + \sa DiffSliceOperation + */ + class Segmentation_EXPORT DiffSliceOperationApplier : public OperationActor + { + + public: + + mitkClassMacro(DiffSliceOperationApplier, OperationActor); + + //itkNewMacro(DiffSliceOperationApplier); + + /** \brief Returns an instance of the class */ + static DiffSliceOperationApplier* GetInstance(); + + /** \brief Executes a DiffSliceOperation. + \sa DiffSliceOperation + Note: + Only DiffSliceOperation is supported. + */ + virtual void ExecuteOperation(Operation* op); + + + protected: + + DiffSliceOperationApplier(); + + virtual ~DiffSliceOperationApplier(); + + //static DiffSliceOperationApplier* s_Instance; + + }; +} +#endif \ No newline at end of file