Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
Medical Imaging Interaction Toolkit
mitkImageTest.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 // mitk includes
14 #include "mitkException.h"
15 #include "mitkIOUtil.h"
16 #include "mitkImageGenerator.h"
18 #include "mitkImageReadAccessor.h"
19 #include "mitkPixelTypeMultiplex.h"
20 #include <mitkImage.h>
21 #include <mitkImageCast.h>
22 #include <mitkImageDataItem.h>
24 #include <mitkTestingMacros.h>
25 
26 #include "mitkImageSliceSelector.h"
27 
28 // itk includes
29 #include <itkImage.h>
30 #include <itkMersenneTwisterRandomVariateGenerator.h>
31 
32 // stl includes
33 #include <fstream>
34 
35 // vtk includes
36 #include <vtkImageData.h>
37 
38 // Checks if reference count is correct after using GetVtkImageData()
39 bool ImageVtkDataReferenceCheck(const char *fname)
40 {
41  const std::string filename = std::string(fname);
42  try
43  {
44  mitk::Image::Pointer image = mitk::IOUtil::Load<mitk::Image>(filename);
45  MITK_TEST_CONDITION_REQUIRED(image.IsNotNull(), "Non-nullptr image")
46 
47  vtkImageData *vtk = image->GetVtkImageData();
48 
49  if (vtk == nullptr)
50  return false;
51  }
52  catch (...)
53  {
54  MITK_TEST_FAILED_MSG(<< "Could not read file for testing: " << filename);
55  return false;
56  }
57 
58  return true;
59 }
60 
61 template <class T>
64  mitk::Point3D &point,
65  mitk::ScalarType &value)
66 {
67  // generate a random point in world coordinates
68  mitk::Point3D xMax, yMax, zMax, xMaxIndex, yMaxIndex, zMaxIndex;
69  xMaxIndex.Fill(0.0f);
70  yMaxIndex.Fill(0.0f);
71  zMaxIndex.Fill(0.0f);
72  xMaxIndex[0] = image->GetLargestPossibleRegion().GetSize()[0];
73  yMaxIndex[1] = image->GetLargestPossibleRegion().GetSize()[1];
74  zMaxIndex[2] = image->GetLargestPossibleRegion().GetSize()[2];
75  image->GetGeometry()->IndexToWorld(xMaxIndex, xMax);
76  image->GetGeometry()->IndexToWorld(yMaxIndex, yMax);
77  image->GetGeometry()->IndexToWorld(zMaxIndex, zMax);
78  MITK_INFO << "Origin " << image->GetGeometry()->GetOrigin()[0] << " " << image->GetGeometry()->GetOrigin()[1] << " "
79  << image->GetGeometry()->GetOrigin()[2] << "";
80  MITK_INFO << "MaxExtend " << xMax[0] << " " << yMax[1] << " " << zMax[2] << "";
81 
82  itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer randomGenerator =
83  itk::Statistics::MersenneTwisterRandomVariateGenerator::New();
84  randomGenerator->Initialize(std::rand()); // initialize with random value, to get sensible random points for the image
85  point[0] = randomGenerator->GetUniformVariate(image->GetGeometry()->GetOrigin()[0], xMax[0]);
86  point[1] = randomGenerator->GetUniformVariate(image->GetGeometry()->GetOrigin()[1], yMax[1]);
87  point[2] = randomGenerator->GetUniformVariate(image->GetGeometry()->GetOrigin()[2], zMax[2]);
88  MITK_INFO << "RandomPoint " << point[0] << " " << point[1] << " " << point[2] << "";
89 
90  // test values and max/min
91  mitk::ScalarType imageMin = image->GetStatistics()->GetScalarValueMin();
92  mitk::ScalarType imageMax = image->GetStatistics()->GetScalarValueMax();
93 
94  // test accessing PixelValue with coordinate leading to a negative index
95  const mitk::Point3D geom_origin = image->GetGeometry()->GetOrigin();
96  const mitk::Point3D geom_center = image->GetGeometry()->GetCenter();
97 
98  // shift position from origin outside of the image ( in the opposite direction to [center-origin] vector which points
99  // in the inside)
100  mitk::Point3D position = geom_origin + (geom_origin - geom_center);
101 
102  MITK_INFO << "Testing access outside of the image";
103  unsigned int dim = image->GetDimension();
104  if (dim == 3 || dim == 4)
105  {
106  mitk::ImagePixelReadAccessor<T, 3> imAccess3(image, image->GetVolumeData(0));
107 
108  // Comparison ?>=0 not needed since all position[i] and timestep are unsigned int
109  // (position[0]>=0 && position[1] >=0 && position[2]>=0 && timestep>=0)
110  // bug-11978 : we still need to catch index with negative values
111  if (point[0] < 0 || point[1] < 0 || point[2] < 0)
112  {
113  MITK_WARN << "Given position (" << point << ") is out of image range, returning 0.";
114  }
115  else
116  {
117  value = static_cast<mitk::ScalarType>(imAccess3.GetPixelByWorldCoordinates(point));
118  MITK_TEST_CONDITION((value >= imageMin && value <= imageMax), "Value returned is between max/min");
119  }
120  itk::Index<3> itkIndex;
121  image->GetGeometry()->WorldToIndex(position, itkIndex);
123  imAccess3.GetPixelByIndexSafe(itkIndex);
125  }
126  MITK_INFO << imageMin << " " << imageMax << " " << value << "";
127 }
128 
129 class mitkImageTestClass
130 {
131 public:
132  void SetClonedGeometry_None_ClonedEqualInput()
133  {
134  mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage<float>(100, 100, 100, 1, 0.2, 0.3, 0.4);
135 
136  //-----------------
137  // geometry information for image
138  mitk::Point3D origin;
139  mitk::Vector3D right, bottom;
140  mitk::Vector3D spacing;
141  mitk::FillVector3D(origin, 17.0, 19.92, 7.83);
142  mitk::FillVector3D(right, 1.0, 2.0, 3.0);
143  mitk::FillVector3D(bottom, 0.0, -3.0, 2.0);
144  mitk::FillVector3D(spacing, 0.78, 0.91, 2.23);
145 
146  // InitializeStandardPlane(rightVector, downVector, spacing)
148  planegeometry->InitializeStandardPlane(100, 100, right, bottom, &spacing);
149  planegeometry->SetOrigin(origin);
150  planegeometry->ChangeImageGeometryConsideringOriginOffset(true);
151 
152  image->SetClonedGeometry(planegeometry);
153 
154  mitk::BaseGeometry::Pointer imageGeometry = image->GetGeometry();
155 
156  MITK_ASSERT_EQUAL(imageGeometry, planegeometry, "Matrix elements of cloned matrix equal original matrix");
157  }
158 };
159 
160 int mitkImageTest(int argc, char *argv[])
161 {
163 
164  mitkImageTestClass tester;
165  tester.SetClonedGeometry_None_ClonedEqualInput();
166 
167  // Create Image out of nowhere
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  }
218  MITK_TEST_CONDITION(isEqual, "The values previously set as data are correct [pixelwise comparison].");
219 
220  // Testing GetSliceData() and compare with filled values:
221 
222  try
223  {
224  mitk::ImageReadAccessor imgMemAcc(imgMem, imgMem->GetSliceData(dim[2] / 2));
225  p2 = (int *)imgMemAcc.GetData();
226  }
227  catch ( const mitk::Exception &e )
228  {
229  MITK_ERROR << e.what();
230  }
231  MITK_TEST_CONDITION_REQUIRED(p2 != nullptr, "Valid slice data returned");
232 
233  unsigned int xy_size = dim[0] * dim[1];
234  unsigned int start_mid_slice = (dim[2] / 2) * xy_size;
235  isEqual = true;
236  for (unsigned int i = 0; i < xy_size; ++i, ++p2)
237  {
238  if (*p2 != (signed int)(i + start_mid_slice))
239  {
240  isEqual = false;
241  }
242  }
243  MITK_TEST_CONDITION(isEqual, "The SliceData are correct [pixelwise comparison]. ");
244 
245  imgMem = mitk::Image::New();
246 
247  // testing re-initialization of test image
248  mitk::PixelType pType = mitk::MakePixelType<int, int, 1>();
249  imgMem->Initialize(pType, 3, dim);
250  MITK_TEST_CONDITION_REQUIRED(imgMem->GetDimension() == 3, "Testing initialization parameter dimension!");
251  MITK_TEST_CONDITION_REQUIRED(imgMem->GetPixelType() == pType, "Testing initialization parameter pixeltype!");
253  imgMem->GetDimension(0) == dim[0] && imgMem->GetDimension(1) == dim[1] && imgMem->GetDimension(2) == dim[2],
254  "Testing initialization of dimensions!");
255  MITK_TEST_CONDITION(imgMem->IsInitialized(), "Image is initialized.");
256 
257  // Setting volume again:
258  try
259  {
260  mitk::ImageReadAccessor imgMemAcc(imgMem);
261  imgMem->SetVolume(imgMemAcc.GetData());
262  }
263  catch ( const mitk::Exception &e )
264  {
265  MITK_ERROR << e.what();
266  }
267 
268  //-----------------
269  // geometry information for image
270  mitk::Point3D origin;
271  mitk::Vector3D right, bottom;
272  mitk::Vector3D spacing;
273  mitk::FillVector3D(origin, 17.0, 19.92, 7.83);
274  mitk::FillVector3D(right, 1.0, 2.0, 3.0);
275  mitk::FillVector3D(bottom, 0.0, -3.0, 2.0);
276  mitk::FillVector3D(spacing, 0.78, 0.91, 2.23);
277 
278  // InitializeStandardPlane(rightVector, downVector, spacing)
280  planegeometry->InitializeStandardPlane(100, 100, right, bottom, &spacing);
281  planegeometry->SetOrigin(origin);
282  planegeometry->SetImageGeometry(true);
283 
284  // Testing Initialize(const mitk::PixelType& type, const mitk::Geometry3D& geometry, unsigned int slices) with
285  // PlaneGeometry and GetData(): ";
286  imgMem->Initialize(mitk::MakePixelType<int, int, 1>(), *planegeometry);
288  imgMem->GetGeometry()->GetOrigin() == static_cast<mitk::BaseGeometry *>(planegeometry)->GetOrigin(),
289  "Testing correct setting of geometry via initialize!");
290 
291  try
292  {
293  mitk::ImageReadAccessor imgMemAcc(imgMem);
294  p = (int *)imgMemAcc.GetData();
295  }
296  catch ( const mitk::Exception &e )
297  {
298  MITK_ERROR << e.what();
299  }
300  MITK_TEST_CONDITION_REQUIRED(p != nullptr, "GetData() returned valid pointer.");
301 
302  // Testing Initialize(const mitk::PixelType& type, int sDim, const mitk::PlaneGeometry& geometry) and GetData(): ";
303  imgMem->Initialize(mitk::MakePixelType<int, int, 1>(), 40, *planegeometry);
304 
305  try
306  {
307  mitk::ImageReadAccessor imgMemAcc(imgMem);
308  p = (int *)imgMemAcc.GetData();
309  }
310  catch ( const mitk::Exception &e )
311  {
312  MITK_ERROR << e.what();
313  }
314  MITK_TEST_CONDITION_REQUIRED(p != nullptr, "GetData() returned valid pointer.");
315 
316  //-----------------
317  // testing origin information and methods
318  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(imgMem->GetGeometry()->GetOrigin(), origin),
319  "Testing correctness of origin via GetGeometry()->GetOrigin(): ");
320 
321  // Setting origin via SetOrigin(origin): ";
322  mitk::FillVector3D(origin, 37.0, 17.92, 27.83);
323  imgMem->SetOrigin(origin);
324 
325  // Test origin
326  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(imgMem->GetGeometry()->GetOrigin(), origin),
327  "Testing correctness of changed origin via GetGeometry()->GetOrigin(): ");
329  mitk::Equal(imgMem->GetSlicedGeometry()->GetPlaneGeometry(0)->GetOrigin(), origin),
330  "Testing correctness of changed origin via GetSlicedGeometry()->GetPlaneGeometry(0)->GetOrigin(): ");
331 
332  //-----------------
333  // testing spacing information and methodsunsigned int dim[]={100,100,20};
334  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(imgMem->GetGeometry()->GetSpacing(), spacing),
335  "Testing correct spacing from Geometry3D!");
336 
337  mitk::FillVector3D(spacing, 7.0, 0.92, 1.83);
338  imgMem->SetSpacing(spacing);
339  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(imgMem->GetGeometry()->GetSpacing(), spacing),
340  "Testing correctness of changed spacing via GetGeometry()->GetSpacing(): ");
342  mitk::Equal(imgMem->GetSlicedGeometry()->GetPlaneGeometry(0)->GetSpacing(), spacing),
343  "Testing correctness of changed spacing via GetSlicedGeometry()->GetPlaneGeometry(0)->GetSpacing(): ");
344 
346  try
347  {
348  mitk::ImageReadAccessor imgMemAcc(imgMem);
349  vecImg->Initialize(imgMem->GetPixelType(), *imgMem->GetGeometry(), 2 /* #channels */, 0 /*tDim*/);
350  vecImg->SetImportChannel(const_cast<void *>(imgMemAcc.GetData()), 0, mitk::Image::CopyMemory);
351  vecImg->SetImportChannel(const_cast<void *>(imgMemAcc.GetData()), 1, mitk::Image::CopyMemory);
352 
353  mitk::ImageReadAccessor vecImgAcc(vecImg);
354  mitk::ImageReadAccessor vecImgAcc0(vecImg, vecImg->GetChannelData(0));
355  mitk::ImageReadAccessor vecImgAcc1(vecImg, vecImg->GetChannelData(1));
356 
357  MITK_TEST_CONDITION_REQUIRED(vecImgAcc0.GetData() != nullptr && vecImgAcc1.GetData() != nullptr,
358  "Testing set and return of channel data!");
359 
360  MITK_TEST_CONDITION_REQUIRED(vecImg->IsValidSlice(0, 0, 1), "");
361  MITK_TEST_OUTPUT(<< " Testing whether CopyMemory worked");
362  MITK_TEST_CONDITION_REQUIRED(imgMemAcc.GetData() != vecImgAcc.GetData(), "");
363  MITK_TEST_OUTPUT(<< " Testing destruction after SetImportChannel");
364  vecImg = nullptr;
365  MITK_TEST_CONDITION_REQUIRED(vecImg.IsNull(), "testing destruction!");
366  }
367  catch ( const mitk::Exception &e )
368  {
369  MITK_ERROR << e.what();
370  }
371  //-----------------
372  MITK_TEST_OUTPUT(<< "Testing initialization via vtkImageData");
373  MITK_TEST_OUTPUT(<< " Setting up vtkImageData");
374  vtkImageData *vtkimage = vtkImageData::New();
375  vtkimage->Initialize();
376  vtkimage->SetDimensions(2, 3, 4);
377  double vtkorigin[] = {-350, -358.203, -1363.5};
378  vtkimage->SetOrigin(vtkorigin);
379  mitk::Point3D vtkoriginAsMitkPoint;
380  mitk::vtk2itk(vtkorigin, vtkoriginAsMitkPoint);
381  double vtkspacing[] = {1.367, 1.367, 2};
382  vtkimage->SetSpacing(vtkspacing);
383  vtkimage->AllocateScalars(VTK_SHORT, 1);
384  std::cout << "[PASSED]" << std::endl;
385 
386  MITK_TEST_OUTPUT(<< " Testing mitk::Image::Initialize(vtkImageData*, ...)");
387  mitk::Image::Pointer mitkByVtkImage = mitk::Image::New();
388  mitkByVtkImage->Initialize(vtkimage);
389  MITK_TEST_CONDITION_REQUIRED(mitkByVtkImage->IsInitialized(), "");
390  vtkimage->Delete();
391 
392  MITK_TEST_OUTPUT(<< " Testing whether spacing has been correctly initialized from vtkImageData");
393  mitk::Vector3D spacing2 = mitkByVtkImage->GetGeometry()->GetSpacing();
394  mitk::Vector3D vtkspacingAsMitkVector;
395  mitk::vtk2itk(vtkspacing, vtkspacingAsMitkVector);
396  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(spacing2, vtkspacingAsMitkVector), "");
397 
399  << " Testing whether GetSlicedGeometry(0)->GetOrigin() has been correctly initialized from vtkImageData");
400  mitk::Point3D origin2 = mitkByVtkImage->GetSlicedGeometry(0)->GetOrigin();
401  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(origin2, vtkoriginAsMitkPoint), "");
402 
403  MITK_TEST_OUTPUT(<< " Testing whether GetGeometry()->GetOrigin() has been correctly initialized from vtkImageData");
404  origin2 = mitkByVtkImage->GetGeometry()->GetOrigin();
405  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(origin2, vtkoriginAsMitkPoint), "");
406 
407  MITK_TEST_OUTPUT(<< " Testing if vtkOrigin is (0, 0, 0). This behaviour is due to historical development of MITK. "
408  "Aslo see bug 5050!");
409  vtkImageData *vtkImage = imgMem->GetVtkImageData();
410  auto vtkOrigin = vtkImage->GetOrigin();
411  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(vtkOrigin[0], 0), "testing vtkOrigin[0] to be 0");
412  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(vtkOrigin[1], 0), "testing vtkOrigin[1] to be 0");
413  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(vtkOrigin[2], 0), "testing vtkOrigin[2] to be 0");
414 
415  // TODO test the following initializers on channel-incorporation
416  // void mitk::Image::Initialize(const mitk::PixelType& type, unsigned int dimension, unsigned int *dimensions,
417  // unsigned int channels)
418  // void mitk::Image::Initialize(const mitk::PixelType& type, int sDim, const mitk::PlaneGeometry& geometry2d, bool
419  // flipped, unsigned int channels, int tDim )
420  // void mitk::Image::Initialize(const mitk::Image* image)
421  // void mitk::Image::Initialize(const mitkIpPicDescriptor* pic, int channels, int tDim, int sDim)
422 
423  // mitk::Image::Pointer vecImg = mitk::Image::New();
424  // vecImg->Initialize(PixelType(typeid(float), 6, itk::ImageIOBase::SYMMETRICSECONDRANKTENSOR),
425  // *imgMem->GetGeometry(), 2 /* #channels */, 0 /*tDim*/, false /*shiftBoundingBoxMinimumToZero*/ );
426  // vecImg->Initialize(PixelType(typeid(itk::Vector<float,6>)), *imgMem->GetGeometry(), 2 /* #channels */, 0 /*tDim*/,
427  // false /*shiftBoundingBoxMinimumToZero*/ );
428 
429  // testing access by index coordinates and by world coordinates
430 
431  MITK_TEST_CONDITION_REQUIRED(argc == 2, "Check if test image is accessible!");
432  const std::string filename = std::string(argv[1]);
434  try
435  {
436  image = mitk::IOUtil::Load<mitk::Image>(filename);
437  MITK_TEST_CONDITION_REQUIRED(image.IsNotNull(), "Non-nullptr image")
438  }
439  catch (...)
440  {
441  MITK_TEST_FAILED_MSG(<< "Could not read file for testing: " << filename);
442  return 0;
443  }
444 
445  mitk::Point3D point;
446  mitk::ScalarType value = -1.;
447 
449  TestRandomPixelAccess, image->GetImageDescriptor()->GetChannelTypeById(0), image, point, value)
450 
451  {
452  // testing the clone method of mitk::Image
453  mitk::Image::Pointer cloneImage = image->Clone();
454  MITK_TEST_CONDITION_REQUIRED(cloneImage->GetDimension() == image->GetDimension(), "Clone (testing dimension)");
455  MITK_TEST_CONDITION_REQUIRED(cloneImage->GetPixelType() == image->GetPixelType(), "Clone (testing pixel type)");
456  // After cloning an image the geometry of both images should be equal too
457  MITK_TEST_CONDITION_REQUIRED(cloneImage->GetGeometry()->GetOrigin() == image->GetGeometry()->GetOrigin(),
458  "Clone (testing origin)");
459  MITK_TEST_CONDITION_REQUIRED(cloneImage->GetGeometry()->GetSpacing() == image->GetGeometry()->GetSpacing(),
460  "Clone (testing spacing)");
462  mitk::MatrixEqualElementWise(cloneImage->GetGeometry()->GetIndexToWorldTransform()->GetMatrix(),
463  image->GetGeometry()->GetIndexToWorldTransform()->GetMatrix()),
464  "Clone (testing transformation matrix)");
466  mitk::MatrixEqualElementWise(cloneImage->GetTimeGeometry()
467  ->GetGeometryForTimeStep(cloneImage->GetDimension(3) - 1)
468  ->GetIndexToWorldTransform()
469  ->GetMatrix(),
470  cloneImage->GetTimeGeometry()
471  ->GetGeometryForTimeStep(image->GetDimension(3) - 1)
472  ->GetIndexToWorldTransform()
473  ->GetMatrix()),
474  "Clone(testing time sliced geometry)");
475 
476  for (unsigned int i = 0u; i < cloneImage->GetDimension(); ++i)
477  {
478  MITK_TEST_CONDITION_REQUIRED(cloneImage->GetDimension(i) == image->GetDimension(i),
479  "Clone (testing dimension " << i << ")");
480  }
481  }
482  // access via itk
483  if (image->GetDimension() > 3) // CastToItk only works with 3d images so we need to check for 4d images
484  {
486  selector->SetTimeNr(0);
487  selector->SetInput(image);
488  selector->Update();
489  image = selector->GetOutput();
490  }
491 
492  if (image->GetDimension() == 3)
493  {
494  typedef itk::Image<double, 3> ItkFloatImage3D;
495  ItkFloatImage3D::Pointer itkimage;
496  try
497  {
498  mitk::CastToItkImage(image, itkimage);
499  MITK_TEST_CONDITION_REQUIRED(itkimage.IsNotNull(), "Test conversion to itk::Image!");
500  }
501  catch ( const std::exception &e )
502  {
503  MITK_INFO << e.what();
504  }
505  mitk::Point3D itkPhysicalPoint;
506  image->GetGeometry()->WorldToItkPhysicalPoint(point, itkPhysicalPoint);
507  MITK_INFO << "ITKPoint " << itkPhysicalPoint[0] << " " << itkPhysicalPoint[1] << " " << itkPhysicalPoint[2] << "";
508 
509  mitk::Point3D backTransformedPoint;
510  image->GetGeometry()->ItkPhysicalPointToWorld(itkPhysicalPoint, backTransformedPoint);
511 
512  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(point, backTransformedPoint),
513  "Testing world->itk-physical->world consistency");
514 
515  itk::Index<3> idx;
516  bool status = itkimage->TransformPhysicalPointToIndex(itkPhysicalPoint, idx);
517 
518  MITK_INFO << "ITK Index " << idx[0] << " " << idx[1] << " " << idx[2] << "";
519 
520  if (status && value != -1.)
521  {
522  float valByItk = itkimage->GetPixel(idx);
523  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(valByItk, value),
524  "Compare value of pixel returned by mitk in comparison to itk");
525  }
526  else
527  {
528  MITK_WARN << "Index is out buffered region!";
529  }
530  }
531  else
532  {
533  MITK_INFO << "Image does not contain three dimensions, some test cases are skipped!";
534  }
535 
536  // clone generated 3D image with one slice in z direction (cf. bug 11058)
537  auto *threeDdim = new unsigned int[3];
538  threeDdim[0] = 100;
539  threeDdim[1] = 200;
540  threeDdim[2] = 1;
541  mitk::Image::Pointer threeDImage = mitk::Image::New();
542  threeDImage->Initialize(mitk::MakeScalarPixelType<float>(), 3, threeDdim);
543  mitk::Image::Pointer cloneThreeDImage = threeDImage->Clone();
544  // check that the clone image has the same dimensionality as the source image
545  MITK_TEST_CONDITION_REQUIRED(cloneThreeDImage->GetDimension() == 3,
546  "Testing if the clone image initializes with 3D!");
547 
549  "Checking reference count of Image after using GetVtkImageData()");
550 
551  MITK_TEST_END();
552 }
#define MITK_TEST_FOR_EXCEPTION_END(EXCEPTIONCLASS)
Gives locked and index-based read access for a particular image part. The class provides several set-...
bool MatrixEqualElementWise(const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix1, const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix2, mitk::ScalarType epsilon=mitk::eps)
Check for element-wise matrix equality with a user defined accuracy.
Definition: mitkMatrix.h:140
#define MITK_INFO
Definition: mitkLogMacros.h:18
#define MITK_ERROR
Definition: mitkLogMacros.h:20
double ScalarType
bool ImageVtkDataReferenceCheck(const char *fname)
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
void TestRandomPixelAccess(const mitk::PixelType, mitk::Image::Pointer image, mitk::Point3D &point, mitk::ScalarType &value)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:106
#define MITK_TEST_OUTPUT(x)
Output some text.
#define MITK_WARN
Definition: mitkLogMacros.h:19
#define mitkPixelTypeMultiplex3(function, ptype, param1, param2, param3)
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
#define MITK_TEST_CONDITION(COND, MSG)
int mitkImageTest(int argc, char *argv[])
#define MITK_TEST_FAILED_MSG(MSG)
Fail and finish test with message MSG.
#define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG)
Testing macro to test if two objects are equal.
#define MITK_TEST_FOR_EXCEPTION_BEGIN(EXCEPTIONCLASS)
Begin block which should be checked for exceptions.
void vtk2itk(const Tin &in, Tout &out)
mitk::Image::Pointer image
static Pointer New()
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
static Pointer New()
and MITK_TEST_END()
ImageReadAccessor class to get locked read access for a particular image part.
BaseGeometry Describes the geometry of a data object.
const void * GetData() const
Gives const access to the data.
static Pointer New()
Class for defining the data type of pixels.
Definition: mitkPixelType.h:51