25 #include <vtkPolyData.h>
29 CPPUNIT_TEST_SUITE(mitkSurfaceToImageFilterTestSuite);
33 CPPUNIT_TEST_SUITE_END();
45 void tearDown()
override {}
46 void test3DSurfaceValidOutput()
51 additionalInputImage->Initialize(mitk::MakeScalarPixelType<unsigned int>(), *m_Surface->GetTimeGeometry());
54 surfaceToImageFilter->MakeOutputBinaryOn();
55 surfaceToImageFilter->SetInput(m_Surface);
56 surfaceToImageFilter->SetImage(additionalInputImage);
57 surfaceToImageFilter->Update();
59 CPPUNIT_ASSERT_MESSAGE(
60 "SurfaceToImageFilter_AnyInputImageAndModeSetToBinary_ResultIsImageWithUCHARPixelType",
61 surfaceToImageFilter->GetOutput()->GetPixelType().GetComponentType() == itk::ImageIOBase::UCHAR);
63 surfaceToImageFilter->SetUShortBinaryPixelType(
true);
64 surfaceToImageFilter->Update();
66 CPPUNIT_ASSERT_MESSAGE(
67 "SurfaceToImageFilter_AnyInputImageAndModeSetToBinary_ResultIsImageWithUCHARPixelType",
68 surfaceToImageFilter->GetOutput()->GetPixelType().GetComponentType() == itk::ImageIOBase::USHORT);
71 void test3DSurfaceCorrect()
78 unsigned int *dims =
new unsigned int[3];
82 additionalInputImage->Initialize(mitk::MakeScalarPixelType<unsigned int>(), 3, dims);
83 additionalInputImage->SetOrigin(m_Surface->GetGeometry()->GetOrigin());
84 additionalInputImage->GetGeometry()->SetIndexToWorldTransform(m_Surface->GetGeometry()->GetIndexToWorldTransform());
87 surfaceToImageFilter->MakeOutputBinaryOn();
88 surfaceToImageFilter->SetInput(m_Surface);
89 surfaceToImageFilter->SetImage(additionalInputImage);
90 surfaceToImageFilter->Update();
94 bool valuesCorrect =
true;
97 idx[1] = 0, idx[2] = 0;
98 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
100 idx[1] = 15, idx[2] = 15;
101 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
103 idx[1] = 15, idx[2] = 0;
104 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
106 idx[1] = 0, idx[2] = 15;
107 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
109 idx[1] = 9, idx[2] = 23;
110 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
113 idx[1] = 15, idx[2] = 15;
114 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
116 idx[1] = 15, idx[2] = 15;
117 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
119 idx[1] = 15, idx[2] = 15;
120 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
122 idx[1] = 15, idx[2] = 2;
123 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
125 idx[1] = 2, idx[2] = 15;
126 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
128 idx[1] = 9, idx[2] = 23;
129 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
131 CPPUNIT_ASSERT_MESSAGE(
"SurfaceToImageFilter_BallSurfaceAsInput_OutputCorrect", valuesCorrect ==
true);
134 void test3DSurfaceIn4DImage()
139 unsigned int *dims =
new unsigned int[4];
144 additionalInputImage->Initialize(mitk::MakeScalarPixelType<unsigned int>(), 4, dims);
145 additionalInputImage->SetOrigin(m_Surface->GetGeometry()->GetOrigin());
146 additionalInputImage->GetGeometry()->SetIndexToWorldTransform(m_Surface->GetGeometry()->GetIndexToWorldTransform());
148 unsigned int size =
sizeof(
unsigned char);
149 for (
unsigned int i = 0; i < secondStep->GetDimension(); ++i)
150 size *= secondStep->GetDimension(i);
152 memset(accessor.GetData(), 1, size);
153 additionalInputImage->GetTimeGeometry()->Expand(2);
154 additionalInputImage->GetGeometry(1)->SetSpacing(secondStep->GetGeometry()->GetSpacing());
155 additionalInputImage->GetGeometry(1)->SetOrigin(secondStep->GetGeometry()->GetOrigin());
156 additionalInputImage->GetGeometry(1)->SetIndexToWorldTransform(
157 secondStep->GetGeometry()->GetIndexToWorldTransform());
158 additionalInputImage->SetImportVolume(secondStep->GetData(), 0);
159 additionalInputImage->SetImportVolume(secondStep->GetData(), 1);
162 surfaceToImageFilter->MakeOutputBinaryOn();
163 surfaceToImageFilter->SetInput(m_Surface);
164 surfaceToImageFilter->SetImage(additionalInputImage);
166 surfaceToImageFilter->Update();
170 bool valuesCorrect =
true;
173 idx[1] = 0, idx[2] = 0;
175 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
177 idx[1] = 15, idx[2] = 15;
179 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
181 idx[1] = 15, idx[2] = 0;
183 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
185 idx[1] = 0, idx[2] = 15;
187 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
189 idx[1] = 9, idx[2] = 23;
191 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
194 idx[1] = 15, idx[2] = 15;
196 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
198 idx[1] = 15, idx[2] = 15;
200 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
202 idx[1] = 15, idx[2] = 15;
204 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
206 idx[1] = 15, idx[2] = 2;
208 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
210 idx[1] = 2, idx[2] = 15;
212 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
214 idx[1] = 9, idx[2] = 23;
216 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 1);
219 idx[1] = 15, idx[2] = 15;
221 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
223 idx[1] = 15, idx[2] = 15;
225 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
227 idx[1] = 15, idx[2] = 15;
229 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
231 idx[1] = 15, idx[2] = 2;
233 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
235 idx[1] = 2, idx[2] = 15;
237 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
239 idx[1] = 9, idx[2] = 23;
241 valuesCorrect = valuesCorrect && (outputReader.GetPixelByIndex(idx) == 0);
243 CPPUNIT_ASSERT_MESSAGE(
"SurfaceToImageFilter_BallSurfaceAsInput_Output4DCorrect", valuesCorrect ==
true);
static mitk::Surface::Pointer LoadSurface(const std::string &path)
LoadSurface Convenience method to load an arbitrary mitkSurface.
Gives locked and index-based read access for a particular image part. The class provides several set-...
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.
Test fixture for parameterized tests.
ImageWriteAccessor class to get locked write-access for a particular image part.