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