22 CPPUNIT_TEST_SUITE(mitkCropTimestepsImageFilterTestSuite);
25 MITK_TEST(Setter_UpperBoundaryTimestepSmallerThanLowerBoundaryTimestep);
26 MITK_TEST(Setter_UpperTimestepsGreaterThanMaxImageTimestep);
32 CPPUNIT_TEST_SUITE_END();
34 std::string m_ImageFilename2D, m_ImageFilename3D, m_ImageFilename2Dt, m_ImageFilename3Dt;
42 m_ImageFilename3Dt =
GetTestDataFilePath(
"3D+t-ITKIO-TestData/LinearModel_4D_arbitrary_time_geometry.nrrd");
46 void tearDown()
override 50 void Constructor_Null()
52 m_cropTimestepsFilter->SetInput(
nullptr);
53 CPPUNIT_ASSERT_THROW(m_cropTimestepsFilter->Update(), itk::ExceptionObject);
56 void Constructor_NoTime()
58 auto refImage2D = mitk::IOUtil::Load<mitk::Image>(m_ImageFilename2D);
59 auto refImage3D = mitk::IOUtil::Load<mitk::Image>(m_ImageFilename3D);
60 m_cropTimestepsFilter->SetInput(refImage2D);
62 m_cropTimestepsFilter->SetInput(refImage3D);
66 void Setter_UpperBoundaryTimestepSmallerThanLowerBoundaryTimestep()
69 auto refImage2Dt = mitk::IOUtil::Load<mitk::Image>(m_ImageFilename2Dt);
70 m_cropTimestepsFilter->SetInput(refImage2Dt);
71 unsigned int lowerTimeStep = 5;
72 unsigned int upperTimeStep = 4;
73 m_cropTimestepsFilter->SetLowerBoundaryTimestep(lowerTimeStep);
74 m_cropTimestepsFilter->SetUpperBoundaryTimestep(upperTimeStep);
75 CPPUNIT_ASSERT_EQUAL(m_cropTimestepsFilter->GetLowerBoundaryTimestep(), lowerTimeStep);
76 CPPUNIT_ASSERT_EQUAL(m_cropTimestepsFilter->GetUpperBoundaryTimestep(), upperTimeStep);
80 void Setter_UpperTimestepsGreaterThanMaxImageTimestep()
83 auto refImage2Dt = mitk::IOUtil::Load<mitk::Image>(m_ImageFilename2Dt);
84 m_cropTimestepsFilter->SetInput(refImage2Dt);
85 unsigned int upperTimeStep = 11;
86 m_cropTimestepsFilter->SetUpperBoundaryTimestep(upperTimeStep);
87 CPPUNIT_ASSERT_EQUAL(m_cropTimestepsFilter->GetUpperBoundaryTimestep(), upperTimeStep);
88 CPPUNIT_ASSERT_NO_THROW(m_cropTimestepsFilter->Update());
89 CPPUNIT_ASSERT_EQUAL(m_cropTimestepsFilter->GetUpperBoundaryTimestep(), refImage2Dt->GetTimeSteps());
95 auto refImage3Dt = mitk::IOUtil::Load<mitk::Image>(m_ImageFilename3Dt);
96 auto timeGeometryBefore = refImage3Dt->GetTimeGeometry()->Clone();
97 m_cropTimestepsFilter->SetInput(refImage3Dt);
98 unsigned int expectedLowerTimestep = 0;
100 CPPUNIT_ASSERT_EQUAL(m_cropTimestepsFilter->GetLowerBoundaryTimestep(), expectedLowerTimestep);
101 CPPUNIT_ASSERT_EQUAL(m_cropTimestepsFilter->GetUpperBoundaryTimestep(), expectedUpperTimestep);
102 CPPUNIT_ASSERT_NO_THROW(m_cropTimestepsFilter->Update());
103 CPPUNIT_ASSERT_EQUAL(m_cropTimestepsFilter->GetLowerBoundaryTimestep(), expectedLowerTimestep);
104 CPPUNIT_ASSERT_EQUAL(m_cropTimestepsFilter->GetUpperBoundaryTimestep(), refImage3Dt->GetTimeSteps());
105 auto result = m_cropTimestepsFilter->GetOutput();
106 auto timeGeometry = result->GetTimeGeometry();
107 CPPUNIT_ASSERT_EQUAL(timeGeometryBefore->GetMinimumTimePoint(), timeGeometry->GetMinimumTimePoint());
108 CPPUNIT_ASSERT_EQUAL(timeGeometryBefore->GetMaximumTimePoint(), timeGeometry->GetMaximumTimePoint());
110 CPPUNIT_ASSERT_EQUAL(result->GetTimeSteps(), refImage3Dt->GetTimeSteps());
113 void Filter_OnlyLowerBoundary()
116 auto refImage3Dt = mitk::IOUtil::Load<mitk::Image>(m_ImageFilename3Dt);
118 auto timeGeometryBefore = refImage3Dt->GetTimeGeometry()->Clone();
119 m_cropTimestepsFilter->SetInput(refImage3Dt);
120 unsigned int lowerTimestep = 2;
121 m_cropTimestepsFilter->SetLowerBoundaryTimestep(lowerTimestep);
122 CPPUNIT_ASSERT_NO_THROW(m_cropTimestepsFilter->Update());
123 auto result = m_cropTimestepsFilter->GetOutput();
124 auto timeGeometry = result->GetTimeGeometry();
125 CPPUNIT_ASSERT_EQUAL(timeGeometryBefore->TimeStepToTimePoint(lowerTimestep), timeGeometry->GetMinimumTimePoint());
126 CPPUNIT_ASSERT_EQUAL(timeGeometryBefore->GetMaximumTimePoint(), timeGeometry->GetMaximumTimePoint());
127 CPPUNIT_ASSERT_EQUAL(refImage3Dt->GetTimeSteps()-lowerTimestep, result->GetTimeSteps());
130 void Filter_OnlyUpperBoundary()
133 auto refImage3Dt = mitk::IOUtil::Load<mitk::Image>(m_ImageFilename3Dt);
134 auto timeGeometryBefore = refImage3Dt->GetTimeGeometry()->Clone();
135 m_cropTimestepsFilter->SetInput(refImage3Dt);
136 unsigned int upperTimestep = 7;
137 m_cropTimestepsFilter->SetUpperBoundaryTimestep(upperTimestep);
138 CPPUNIT_ASSERT_NO_THROW(m_cropTimestepsFilter->Update());
139 auto result = m_cropTimestepsFilter->GetOutput();
140 auto timeGeometry = result->GetTimeGeometry();
141 CPPUNIT_ASSERT_EQUAL(timeGeometryBefore->TimeStepToTimePoint(upperTimestep), timeGeometry->GetMaximumTimePoint());
142 CPPUNIT_ASSERT_EQUAL(timeGeometryBefore->GetMinimumTimePoint(), timeGeometry->GetMinimumTimePoint());
143 CPPUNIT_ASSERT_EQUAL(upperTimestep, result->GetTimeSteps());
146 void Filter_BothBoundaries()
149 auto refImage3Dt = mitk::IOUtil::Load<mitk::Image>(m_ImageFilename3Dt);
150 m_cropTimestepsFilter->SetInput(refImage3Dt);
151 auto timeGeometryBefore = refImage3Dt->GetTimeGeometry()->Clone();
152 unsigned int lowerTimestep = 1;
153 unsigned int upperTimestep = 7;
154 m_cropTimestepsFilter->SetLowerBoundaryTimestep(lowerTimestep);
155 m_cropTimestepsFilter->SetUpperBoundaryTimestep(upperTimestep);
156 CPPUNIT_ASSERT_NO_THROW(m_cropTimestepsFilter->Update());
157 auto result = m_cropTimestepsFilter->GetOutput();
158 auto timeGeometry = result->GetTimeGeometry();
159 CPPUNIT_ASSERT_EQUAL(timeGeometryBefore->TimeStepToTimePoint(upperTimestep), timeGeometry->GetMaximumTimePoint());
160 CPPUNIT_ASSERT_EQUAL(timeGeometryBefore->TimeStepToTimePoint(lowerTimestep), timeGeometry->GetMinimumTimePoint());
161 CPPUNIT_ASSERT_EQUAL(upperTimestep-lowerTimestep, result->GetTimeSteps());
164 void Filter_BothBoundaries2Dt()
167 auto refImage2Dt = mitk::IOUtil::Load<mitk::Image>(m_ImageFilename2Dt);
168 m_cropTimestepsFilter->SetInput(refImage2Dt);
169 unsigned int lowerTimestep = 1;
170 unsigned int upperTimestep = 2;
171 m_cropTimestepsFilter->SetLowerBoundaryTimestep(lowerTimestep);
172 m_cropTimestepsFilter->SetUpperBoundaryTimestep(upperTimestep);
173 CPPUNIT_ASSERT_NO_THROW(m_cropTimestepsFilter->Update());
174 auto result = m_cropTimestepsFilter->GetOutput();
175 auto timeGeometry = result->GetTimeGeometry();
176 CPPUNIT_ASSERT_EQUAL(
mitk::TimePointType(upperTimestep), timeGeometry->GetMaximumTimePoint());
177 CPPUNIT_ASSERT_EQUAL(
mitk::TimePointType(lowerTimestep), timeGeometry->GetMinimumTimePoint());
178 CPPUNIT_ASSERT_EQUAL(upperTimestep - lowerTimestep, result->GetTimeSteps());
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Test fixture for parameterized tests.
mitk::ScalarType TimePointType