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