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