Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDiffSliceOperation.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 
17 #include "mitkDiffSliceOperation.h"
18 
19 #include <mitkImage.h>
20 
21 #include <itkCommand.h>
22 
24 {
25  m_TimeStep = 0;
26  m_zlibSliceContainer = nullptr;
27  m_Image = nullptr;
28  m_WorldGeometry = nullptr;
29  m_SliceGeometry = nullptr;
30  m_ImageIsValid = false;
31 }
32 
34  Image *slice,
35  SlicedGeometry3D *sliceGeometry,
36  unsigned int timestep,
37  BaseGeometry *currentWorldGeometry)
38  : Operation(1)
39 
40 {
41  m_WorldGeometry = currentWorldGeometry->Clone();
42 
43  /*
44  Quick fix for bug 12338.
45  Guard object - fix this when clone method of PlaneGeometry is cloning the reference geometry (see bug 13392)*/
46  // xxxx m_GuardReferenceGeometry = mitk::BaseGeometry::New();
47  m_GuardReferenceGeometry = dynamic_cast<mitk::PlaneGeometry *>(m_WorldGeometry.GetPointer())->GetReferenceGeometry();
48  /*---------------------------------------------------------------------------------------------------*/
49 
50  m_SliceGeometry = sliceGeometry->Clone();
51 
52  m_TimeStep = timestep;
53 
55  m_zlibSliceContainer->SetImage(slice);
56 
57  m_Image = imageVolume;
58 
59  if (m_Image)
60  {
61  /*add an observer to listen to the delete event of the image, this is necessary because the operation is then
62  * invalid*/
64  command->SetCallbackFunction(this, &DiffSliceOperation::OnImageDeleted);
65  // get the id of the observer, used to remove it later on
66  m_DeleteObserverTag = imageVolume->AddObserver(itk::DeleteEvent(), command);
67 
68  m_ImageIsValid = true;
69  }
70  else
71  m_ImageIsValid = false;
72 }
73 
75 {
76  m_WorldGeometry = nullptr;
77  m_zlibSliceContainer = nullptr;
78 
79  if (m_ImageIsValid)
80  {
81  // if the image is still there, we have to remove the observer from it
82  m_Image->RemoveObserver(m_DeleteObserverTag);
83  }
84  m_Image = nullptr;
85 }
86 
88 {
89  Image::Pointer image = m_zlibSliceContainer->GetImage();
90  return image;
91 }
92 
94 {
95  return m_ImageIsValid && m_zlibSliceContainer.IsNotNull() && (m_WorldGeometry.IsNotNull()); // TODO improve
96 }
97 
99 {
100  // if our imageVolume is removed e.g. from the datastorage the operation is no lnger valid
101  m_ImageIsValid = false;
102 }
itk::SmartPointer< Self > Pointer
bool IsValid()
Check if it is a valid operation.
Base class of all Operation-classes.
Definition: mitkOperation.h:33
SlicedGeometry3D::Pointer m_SliceGeometry
BaseGeometry::Pointer m_WorldGeometry
mitk::BaseGeometry::ConstPointer m_GuardReferenceGeometry
Image class for storing images.
Definition: mitkImage.h:76
void OnImageDeleted()
Callback for image observer.
Describes the geometry of a data object consisting of slices.
Image::Pointer GetSlice()
Get the slice that is applied in the operation.
Pointer Clone() const
DiffSliceOperation()
Creates an empty instance. Note that it is not valid yet. The properties of the object have to be set...
Describes a two-dimensional, rectangular plane.
CompressedImageContainer::Pointer m_zlibSliceContainer
Pointer Clone() const
BaseGeometry Describes the geometry of a data object.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.