Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDiffSliceOperationApplier.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include "mitkDiffSliceOperation.h"
20 #include "mitkRenderingManager.h"
21 #include "mitkSegTool2D.h"
22 #include <mitkExtractSliceFilter.h>
23 #include <mitkVtkImageOverwrite.h>
24 
25 // VTK
26 #include <vtkSmartPointer.h>
27 
29 {
30 }
31 
33 {
34 }
35 
37 {
38  DiffSliceOperation *imageOperation = dynamic_cast<DiffSliceOperation *>(operation);
39 
40  // as we only support DiffSliceOperation return if operation is not type of DiffSliceOperation
41  if (!imageOperation)
42  return;
43 
44  // chak if the operation is valid
45  if (imageOperation->IsValid())
46  {
47  // the actual overwrite filter (vtk)
48  vtkSmartPointer<mitkVtkImageOverwrite> reslice = vtkSmartPointer<mitkVtkImageOverwrite>::New();
49 
50  mitk::Image::Pointer slice = imageOperation->GetSlice();
51  // Set the slice as 'input'
52  reslice->SetInputSlice(const_cast<vtkImageData *>(slice->GetVtkImageData()));
53 
54  // set overwrite mode to true to write back to the image volume
55  reslice->SetOverwriteMode(true);
56  reslice->Modified();
57 
58  // a wrapper for vtkImageOverwrite
60  extractor->SetInput(imageOperation->GetImage());
61  extractor->SetTimeStep(imageOperation->GetTimeStep());
62  extractor->SetWorldGeometry(dynamic_cast<PlaneGeometry *>(imageOperation->GetWorldGeometry()));
63  extractor->SetVtkOutputRequest(true);
64  extractor->SetResliceTransformByGeometry(imageOperation->GetImage()->GetGeometry(imageOperation->GetTimeStep()));
65 
66  extractor->Modified();
67  extractor->Update();
68 
69  // make sure the modification is rendered
71  imageOperation->GetImage()->Modified();
72 
74  extractor2->SetInput(imageOperation->GetImage());
75  extractor2->SetTimeStep(imageOperation->GetTimeStep());
76  extractor2->SetWorldGeometry(dynamic_cast<PlaneGeometry *>(imageOperation->GetWorldGeometry()));
77  extractor2->SetResliceTransformByGeometry(imageOperation->GetImage()->GetGeometry(imageOperation->GetTimeStep()));
78  extractor2->Modified();
79  extractor2->Update();
80 
81  // TODO Move this code to SurfaceInterpolationController!
82  mitk::Image::Pointer slice2 = extractor2->GetOutput();
83  mitk::PlaneGeometry::Pointer plane = dynamic_cast<PlaneGeometry *>(imageOperation->GetWorldGeometry());
84  slice2->DisconnectPipeline();
85  mitk::SegTool2D::UpdateSurfaceInterpolation(slice2, imageOperation->GetImage(), plane, true);
86  }
87 }
88 
89 mitk::DiffSliceOperationApplier *mitk::DiffSliceOperationApplier::GetInstance()
90 {
91  static DiffSliceOperationApplier *s_Instance = new DiffSliceOperationApplier();
92  return s_Instance;
93 }
BaseGeometry * GetWorldGeometry()
Get the axis where the slice has to be applied in the volume.
bool IsValid()
Check if it is a valid operation.
Base class of all Operation-classes.
Definition: mitkOperation.h:33
static Pointer New()
An Operation for applying an edited slice to the volume.
virtual void ExecuteOperation(Operation *op) override
Executes a DiffSliceOperation.
static RenderingManager * GetInstance()
Image::Pointer GetSlice()
Get the slice that is applied in the operation.
static void UpdateSurfaceInterpolation(const Image *slice, const Image *workingImage, const PlaneGeometry *plane, bool detectIntersection)
Updates the surface interpolation by extracting the contour form the given slice. ...
Describes a two-dimensional, rectangular plane.
unsigned int GetTimeStep()
Set timeStep.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:129
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
mitk::Image * GetImage()
Get th image volume.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.