MCPcopy Create free account
hub / github.com/MITK/MITK / mitkImageTest

Function mitkImageTest

Modules/Core/test/mitkImageTest.cpp:160–538  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158};
159
160int mitkImageTest(int argc, char *argv[])
161{
162 MITK_TEST_BEGIN(mitkImageTest);
163
164 mitkImageTestClass tester;
165 tester.SetClonedGeometry_None_ClonedEqualInput();
166
167 // Create Image out of nowhere
168 mitk::Image::Pointer imgMem = mitk::Image::New();
169 mitk::PixelType pt = mitk::MakeScalarPixelType<int>();
170 unsigned int dim[] = {100, 100, 20};
171
172 MITK_TEST_CONDITION_REQUIRED(imgMem.IsNotNull(), "An image was created. ");
173
174 // Initialize image
175 imgMem->Initialize(pt, 3, dim);
176
177 MITK_TEST_CONDITION_REQUIRED(imgMem->IsInitialized(), "Image::IsInitialized() ?");
178 MITK_TEST_CONDITION_REQUIRED(imgMem->GetPixelType() == pt, "PixelType was set correctly.");
179
180 int *p = nullptr;
181 int *p2 = nullptr;
182 try
183 {
184 mitk::ImageReadAccessor imgMemAcc(imgMem);
185 p = (int *)imgMemAcc.GetData();
186 }
187 catch ( const mitk::Exception &e )
188 {
189 MITK_ERROR << e.what();
190 }
191 MITK_TEST_CONDITION(p != nullptr, "GetData() returned not-nullptr pointer.");
192
193 // filling image
194 const unsigned int size = dim[0] * dim[1] * dim[2];
195 for (unsigned int i = 0; i < size; ++i, ++p)
196 *p = (signed int)i;
197
198 // Getting it again and compare with filled values:
199 try
200 {
201 mitk::ImageReadAccessor imgMemAcc(imgMem);
202 p2 = (int *)imgMemAcc.GetData();
203 }
204 catch ( const mitk::Exception &e )
205 {
206 MITK_ERROR << e.what();
207 }
208 MITK_TEST_CONDITION(p2 != nullptr, "GetData() returned not-nullptr pointer.");
209
210 bool isEqual = true;
211 for (unsigned int i = 0; i < size; ++i, ++p2)
212 {
213 if (*p2 != (signed int)i)
214 {
215 isEqual = false;
216 }
217 }

Callers

nothing calls this directly

Calls 15

FillVector3DFunction · 0.85
FillArrayFunction · 0.85
MatrixEqualElementWiseFunction · 0.85
IsNotNullMethod · 0.80
whatMethod · 0.80
SetVolumeMethod · 0.80
SetImageGeometryMethod · 0.80
GetGeometryMethod · 0.80
GetSlicedGeometryMethod · 0.80

Tested by

no test coverage detected