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

Function testItkImageIsCenterBased

Modules/Core/test/mitkGeometry3DTest.cpp:239–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237#include <itkImage.h>
238
239int testItkImageIsCenterBased()
240{
241 MITK_TEST_OUTPUT(<< "Testing whether itk::Image coordinates are center-based.");
242 typedef itk::Image<int, 3> ItkIntImage3D;
243 ItkIntImage3D::Pointer itkintimage = ItkIntImage3D::New();
244 ItkIntImage3D::SizeType size;
245 size.Fill(10);
246 mitk::Point3D origin;
247 mitk::FillVector3D(origin, 2, 3, 7);
248 itkintimage->Initialize();
249 itkintimage->SetRegions(size);
250 itkintimage->SetOrigin(origin);
251 std::cout << "[PASSED]" << std::endl;
252
253 MITK_TEST_OUTPUT(<< " Testing itk::Image::TransformPhysicalPointToContinuousIndex(origin)==(0,0,0)");
254 mitk::Point3D globalOrigin;
255 mitk::FillVector3D(globalOrigin, 0, 0, 0);
256
257 auto originContinuousIndex = itkintimage->TransformPhysicalPointToContinuousIndex<mitk::ScalarType, mitk::ScalarType>(origin);
258 MITK_TEST_CONDITION_REQUIRED(originContinuousIndex == globalOrigin, "");
259
260 MITK_TEST_OUTPUT(<< " Testing itk::Image::TransformPhysicalPointToIndex(origin)==(0,0,0)");
261 itk::Index<3> itkindex = itkintimage->TransformPhysicalPointToIndex(origin);
262 itk::Index<3> globalOriginIndex;
263 for (unsigned int i = 0; i < 3; ++i)
264 globalOriginIndex[i] = static_cast<itk::IndexValueType>(globalOrigin[i]);
265 MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, "");
266
267 MITK_TEST_OUTPUT(<< " Testing itk::Image::TransformPhysicalPointToIndex(origin-0.5*spacing)==(0,0,0)");
268 mitk::Vector3D halfSpacingStep = itkintimage->GetSpacing() * 0.5;
269 mitk::Matrix3D rotation;
270 mitk::Point3D originOffCenter = origin - halfSpacingStep;
271 itkindex = itkintimage->TransformPhysicalPointToIndex(originOffCenter);
272 MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, "");
273
274 MITK_TEST_OUTPUT(
275 << " Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing-eps, itk::Index)==(0,0,0)");
276 originOffCenter = origin + halfSpacingStep;
277 originOffCenter -= mitk::Vector(0.0001);
278 itkindex = itkintimage->TransformPhysicalPointToIndex(originOffCenter);
279 MITK_TEST_CONDITION_REQUIRED(itkindex == globalOriginIndex, "");
280
281 MITK_TEST_OUTPUT(<< " Testing itk::Image::TransformPhysicalPointToIndex(origin+0.5*spacing, itk::Index)==(1,1,1)");
282 originOffCenter = origin + halfSpacingStep;
283 itk::Index<3> global111;
284 mitk::FillVector3D(global111, 1, 1, 1);
285 itkindex = itkintimage->TransformPhysicalPointToIndex(originOffCenter);
286 MITK_TEST_CONDITION_REQUIRED(itkindex == global111, "");
287
288 MITK_TEST_OUTPUT(<< "=> Yes, itk::Image coordinates are center-based.");
289
290 return EXIT_SUCCESS;
291}
292
293int testGeometry3D(bool imageGeometry)
294{

Callers 1

mitkGeometry3DTestFunction · 0.85

Calls 7

FillVector3DFunction · 0.85
VectorClass · 0.85
NewFunction · 0.50
FillMethod · 0.45
InitializeMethod · 0.45
SetOriginMethod · 0.45
GetSpacingMethod · 0.45

Tested by

no test coverage detected