Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
Medical Imaging Interaction Toolkit
mitkImageTimeSelectorTest.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 "mitkImage.h"
14 #include "mitkImageGenerator.h"
15 #include "mitkImageTimeSelector.h"
16 
17 #include "mitkTestingMacros.h"
18 
19 #include "mitkIOUtil.h"
20 #include <itksys/SystemTools.hxx>
21 
22 #include <fstream>
23 
25 namespace
26 {
27  std::string m_Filename;
28  mitk::Image::Pointer m_Image;
29 } // end of anonymous namespace
30 
32 static void Setup()
33 {
34  try
35  {
36  m_Image = mitk::IOUtil::Load<mitk::Image>(m_Filename);
37  }
38  catch (const itk::ExceptionObject &e)
39  {
40  MITK_TEST_FAILED_MSG(<< "(Setup) Caught exception from IOUtil while loading input : " << m_Filename << "\n"
41  << e.what())
42  }
43 }
44 
46 {
47  Setup();
48 
50  timeSelector->SetInput(m_Image);
51 
52  // test all timesteps
53  const unsigned int maxTimeStep = m_Image->GetTimeSteps();
54  for (unsigned int t = 0; t < maxTimeStep; t++)
55  {
56  timeSelector->SetTimeNr(t);
57  timeSelector->Update();
58 
59  mitk::Image::Pointer currentTimestepImage = timeSelector->GetOutput();
60 
61  std::stringstream ss;
62  ss << " : Valid image in timestep " << t;
63 
64  MITK_TEST_CONDITION_REQUIRED(currentTimestepImage.IsNotNull(), ss.str().c_str());
65  }
66 }
67 
69 {
70  Setup();
71 
73 
74  const unsigned int maxTimeStep = m_Image->GetTimeSteps();
75  mitk::TimeGeometry *tsg = m_Image->GetTimeGeometry();
76  auto *ptg = dynamic_cast<mitk::ProportionalTimeGeometry *>(tsg);
77  ptg->Expand(maxTimeStep + 1);
78  ptg->SetTimeStepGeometry(ptg->GetGeometryForTimeStep(0), maxTimeStep);
79 
80  mitk::Image::Pointer expandedImage = mitk::Image::New();
81  expandedImage->Initialize(m_Image->GetPixelType(0), *tsg);
82 
83  timeSelector->SetInput(expandedImage);
84 
85  for (unsigned int t = 0; t < maxTimeStep + 1; t++)
86  {
87  timeSelector->SetTimeNr(t);
88  timeSelector->Update();
89 
90  mitk::Image::Pointer currentTimestepImage = timeSelector->GetOutput();
91 
92  std::stringstream ss;
93  ss << " : Valid image in timestep " << t;
94 
95  MITK_TEST_CONDITION_REQUIRED(currentTimestepImage.IsNotNull(), ss.str().c_str());
96  }
97 }
98 
99 int mitkImageTimeSelectorTest(int /*argc*/, char *argv[])
100 {
102 
103  m_Filename = std::string(argv[1]);
104 
107 
108  MITK_TEST_END();
109 }
static void Valid_ImageExpandedByTimestep_ReturnsTrue()
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
void Expand(TimeStepType size) override
Expands the time geometry to the given number of time steps.
#define MITK_TEST_FAILED_MSG(MSG)
Fail and finish test with message MSG.
static void Setup()
Global test setup.
static Pointer New()
int mitkImageTimeSelectorTest(int, char *argv[])
and MITK_TEST_END()
static void Valid_AllInputTimesteps_ReturnsTrue()
static Pointer New()