Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkImageMaskGenerator.cpp
Go to the documentation of this file.
1 
2 
5 #include <stdexcept>
6 
7 namespace mitk {
8 
10 {
11  if (m_internalMaskImage != maskImage)
12  {
13  m_internalMaskImage = maskImage;
14  this->Modified();
15  }
16 }
17 
18 void ImageMaskGenerator::SetTimeStep(unsigned int timeStep)
19 {
20  if (timeStep != m_TimeStep)
21  {
22  m_TimeStep = timeStep;
23  UpdateInternalMask();
24  }
25 }
26 
27 void ImageMaskGenerator::UpdateInternalMask()
28 {
29  unsigned int timeStepForExtraction;
30 
31  if (m_TimeStep >= m_internalMaskImage->GetTimeSteps())
32  {
33  MITK_WARN << "Warning: time step > number of time steps in mask image, using last time step";
34  timeStepForExtraction = m_internalMaskImage->GetTimeSteps() - 1;
35  }
36  else
37  {
38  timeStepForExtraction = m_TimeStep;
39  }
41  imageTimeSelector->SetInput(m_internalMaskImage);
42  imageTimeSelector->SetTimeNr(timeStepForExtraction);
43  imageTimeSelector->UpdateLargestPossibleRegion();
44 
46  m_InternalMask = imageTimeSelector->GetOutput();
47 }
48 
49 
51 {
52  if (m_internalMaskImage.IsNull())
53  {
54  MITK_ERROR << "Mask Image is nullptr";
55  }
56  if (IsUpdateRequired())
57  {
58  UpdateInternalMask();
59  }
60 
61  return m_InternalMask;
62 }
63 
64 bool ImageMaskGenerator::IsUpdateRequired() const
65 {
66  unsigned long internalMaskTimeStamp = m_InternalMask->GetMTime();
67  unsigned long maskImageTimeStamp = m_internalMaskImage->GetMTime();
68 
69  if (maskImageTimeStamp > internalMaskTimeStamp) // inputs have changed
70  {
71  return true;
72  }
73 
74  if (this->GetMTime() > maskImageTimeStamp) // input has changed
75  {
76  return true;
77  }
78 
79  return false;
80 }
81 
82 }
83 
84 
85 
86 
87 
88 
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< Self > Pointer
void SetImageMask(mitk::Image::Pointer maskImage)
#define MITK_WARN
Definition: mitkLogMacros.h:23
mitk::Image::Pointer m_InternalMask
static Pointer New()
mitk::Image::Pointer GetMask()
GetMask must be overridden by derived classes.
static Pointer New()
void SetTimeStep(unsigned int timeStep)