Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkDiffSliceOperation.h"
14 
15 #include <mitkImage.h>
16 
17 #include <itkCommand.h>
18 
20 {
21  m_TimeStep = 0;
22  m_zlibSliceContainer = nullptr;
23  m_Image = nullptr;
24  m_WorldGeometry = nullptr;
25  m_SliceGeometry = nullptr;
26  m_ImageIsValid = false;
28 }
29 
31  Image *slice,
32  SlicedGeometry3D *sliceGeometry,
33  unsigned int timestep,
34  BaseGeometry *currentWorldGeometry)
35  : Operation(1)
36 
37 {
38  m_WorldGeometry = currentWorldGeometry->Clone();
39 
40  /*
41  Quick fix for bug 12338.
42  Guard object - fix this when clone method of PlaneGeometry is cloning the reference geometry (see bug 13392)*/
43  // xxxx m_GuardReferenceGeometry = mitk::BaseGeometry::New();
44  m_GuardReferenceGeometry = dynamic_cast<mitk::PlaneGeometry *>(m_WorldGeometry.GetPointer())->GetReferenceGeometry();
45  /*---------------------------------------------------------------------------------------------------*/
46 
47  m_SliceGeometry = sliceGeometry->Clone();
48 
49  m_TimeStep = timestep;
50 
52  m_zlibSliceContainer->SetImage(slice);
53 
54  m_Image = imageVolume;
56 
57  if (m_Image)
58  {
59  /*add an observer to listen to the delete event of the image, this is necessary because the operation is then
60  * invalid*/
61  itk::SimpleMemberCommand<DiffSliceOperation>::Pointer command = itk::SimpleMemberCommand<DiffSliceOperation>::New();
62  command->SetCallbackFunction(this, &DiffSliceOperation::OnImageDeleted);
63  // get the id of the observer, used to remove it later on
64  m_DeleteObserverTag = imageVolume->AddObserver(itk::DeleteEvent(), command);
65 
66  m_ImageIsValid = true;
67  }
68  else
69  m_ImageIsValid = false;
70 }
71 
73 {
74  m_WorldGeometry = nullptr;
75  m_zlibSliceContainer = nullptr;
76 
77  if (m_ImageIsValid)
78  {
79  // if the image is still there, we have to remove the observer from it
80  m_Image->RemoveObserver(m_DeleteObserverTag);
81  }
82  m_Image = nullptr;
83 }
84 
86 {
88  return image;
89 }
90 
92 {
93  return m_ImageIsValid && m_zlibSliceContainer.IsNotNull() && (m_WorldGeometry.IsNotNull()); // TODO improve
94 }
95 
97 {
98  // if our imageVolume is removed e.g. from the datastorage the operation is no lnger valid
99  m_ImageIsValid = false;
100 }
bool IsValid()
Check if it is a valid operation.
Base class of all Operation-classes.
Definition: mitkOperation.h:29
Pointer Clone() const
SlicedGeometry3D::Pointer m_SliceGeometry
Pointer Clone() const
BaseGeometry::Pointer m_WorldGeometry
mitk::BaseGeometry::ConstPointer m_GuardReferenceGeometry
Image class for storing images.
Definition: mitkImage.h:72
mitk::Image::Pointer image
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.
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
BaseGeometry Describes the geometry of a data object.