34 #include <itkMersenneTwisterRandomVariateGenerator.h>
40 #include <vtkImageData.h>
45 const std::string
filename = std::string(fname);
51 vtkImageData *vtk = image->GetVtkImageData();
72 mitk::Point3D xMax, yMax, zMax, xMaxIndex, yMaxIndex, zMaxIndex;
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] <<
"";
88 randomGenerator->Initialize(std::rand());
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] <<
"";
99 const mitk::Point3D geom_origin = image->GetGeometry()->GetOrigin();
100 const mitk::Point3D geom_center = image->GetGeometry()->GetCenter();
104 mitk::Point3D position = geom_origin + (geom_origin - geom_center);
106 MITK_INFO <<
"Testing access outside of the image";
107 unsigned int dim = image->GetDimension();
108 if (dim == 3 || dim == 4)
115 if (point[0] < 0 || point[1] < 0 || point[2] < 0)
117 MITK_WARN <<
"Given position (" << point <<
") is out of image range, returning 0.";
121 value =
static_cast<mitk::ScalarType>(imAccess3.GetPixelByWorldCoordinates(point));
122 MITK_TEST_CONDITION((value >= imageMin && value <= imageMax),
"Value returned is between max/min");
125 image->GetGeometry()->WorldToIndex(position, itkIndex);
127 imAccess3.GetPixelByIndexSafe(itkIndex);
130 MITK_INFO << imageMin <<
" " << imageMax <<
" " << value <<
"";
133 class mitkImageTestClass
136 void SetClonedGeometry_None_ClonedEqualInput()
138 mitk::Image::Pointer image = mitk::ImageGenerator::GenerateRandomImage<float>(100, 100, 100, 1, 0.2, 0.3, 0.4);
152 planegeometry->InitializeStandardPlane(100, 100, right, bottom, &spacing);
153 planegeometry->SetOrigin(origin);
154 planegeometry->ChangeImageGeometryConsideringOriginOffset(
true);
156 image->SetClonedGeometry(planegeometry);
160 MITK_ASSERT_EQUAL(imageGeometry, planegeometry,
"Matrix elements of cloned matrix equal original matrix");
168 mitkImageTestClass tester;
169 tester.SetClonedGeometry_None_ClonedEqualInput();
174 unsigned int dim[] = {100, 100, 20};
179 imgMem->Initialize(pt, 3, dim);
189 p = (
int *)imgMemAcc.
GetData();
198 const unsigned int size = dim[0] * dim[1] * dim[2];
199 for (
unsigned int i = 0; i < size; ++i, ++p)
206 p2 = (
int *)imgMemAcc.
GetData();
215 for (
unsigned int i = 0; i < size; ++i, ++p2)
217 if (*p2 != (
signed int)i)
222 MITK_TEST_CONDITION(isEqual,
"The values previously set as data are correct [pixelwise comparison].");
229 p2 = (
int *)imgMemAcc.
GetData();
237 unsigned int xy_size = dim[0] * dim[1];
238 unsigned int start_mid_slice = (dim[2] / 2) * xy_size;
240 for (
unsigned int i = 0; i < xy_size; ++i, ++p2)
242 if (*p2 != (
signed int)(i + start_mid_slice))
253 imgMem->Initialize(pType, 3, dim);
257 imgMem->GetDimension(0) == dim[0] && imgMem->GetDimension(1) == dim[1] && imgMem->GetDimension(2) == dim[2],
258 "Testing initialization of dimensions!");
265 imgMem->SetVolume(imgMemAcc.
GetData());
284 planegeometry->InitializeStandardPlane(100, 100, right, bottom, &spacing);
285 planegeometry->SetOrigin(origin);
286 planegeometry->SetImageGeometry(
true);
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!");
298 p = (
int *)imgMemAcc.
GetData();
307 imgMem->Initialize(mitk::MakePixelType<int, int, 1>(), 40, *planegeometry);
312 p = (
int *)imgMemAcc.
GetData();
323 "Testing correctness of origin via GetGeometry()->GetOrigin(): ");
327 imgMem->SetOrigin(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(): ");
339 "Testing correct spacing from Geometry3D!");
342 imgMem->SetSpacing(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(): ");
353 vecImg->Initialize(imgMem->GetPixelType(), *imgMem->GetGeometry(), 2 , 0 );
362 "Testing set and return of channel data!");
379 vtkimage->Initialize();
380 vtkimage->SetDimensions(2, 3, 4);
381 double vtkorigin[] = {-350, -358.203, -1363.5};
382 vtkimage->SetOrigin(vtkorigin);
385 double vtkspacing[] = {1.367, 1.367, 2};
386 vtkimage->SetSpacing(vtkspacing);
387 vtkimage->AllocateScalars(VTK_SHORT, 1);
388 std::cout <<
"[PASSED]" << std::endl;
390 MITK_TEST_OUTPUT(<<
" Testing mitk::Image::Initialize(vtkImageData*, ...)");
392 mitkByVtkImage->Initialize(vtkimage);
396 MITK_TEST_OUTPUT(<<
" Testing whether spacing has been correctly initialized from vtkImageData");
397 mitk::Vector3D spacing2 = mitkByVtkImage->GetGeometry()->GetSpacing();
403 <<
" Testing whether GetSlicedGeometry(0)->GetOrigin() has been correctly initialized from vtkImageData");
404 mitk::Point3D origin2 = mitkByVtkImage->GetSlicedGeometry(0)->GetOrigin();
407 MITK_TEST_OUTPUT(<<
" Testing whether GetGeometry()->GetOrigin() has been correctly initialized from vtkImageData");
408 origin2 = mitkByVtkImage->GetGeometry()->GetOrigin();
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();
436 const std::string
filename = std::string(argv[1]);
462 "Clone (testing origin)");
464 "Clone (testing spacing)");
467 image->GetGeometry()->GetIndexToWorldTransform()->GetMatrix()),
468 "Clone (testing transformation matrix)");
471 ->GetGeometryForTimeStep(cloneImage->GetDimension(3) - 1)
472 ->GetIndexToWorldTransform()
474 cloneImage->GetTimeGeometry()
475 ->GetGeometryForTimeStep(image->GetDimension(3) - 1)
476 ->GetIndexToWorldTransform()
478 "Clone(testing time sliced geometry)");
480 for (
unsigned int i = 0u; i < cloneImage->GetDimension(); ++i)
483 "Clone (testing dimension " << i <<
")");
487 if (image->GetDimension() > 3)
490 selector->SetTimeNr(0);
491 selector->SetInput(image);
493 image = selector->GetOutput();
496 if (image->GetDimension() == 3)
498 typedef itk::Image<double, 3> ItkFloatImage3D;
505 catch (std::exception &e)
510 image->GetGeometry()->WorldToItkPhysicalPoint(point, itkPhysicalPoint);
511 MITK_INFO <<
"ITKPoint " << itkPhysicalPoint[0] <<
" " << itkPhysicalPoint[1] <<
" " << itkPhysicalPoint[2] <<
"";
514 image->GetGeometry()->ItkPhysicalPointToWorld(itkPhysicalPoint, backTransformedPoint);
517 "Testing world->itk-physical->world consistency");
520 bool status = itkimage->TransformPhysicalPointToIndex(itkPhysicalPoint, idx);
522 MITK_INFO <<
"ITK Index " << idx[0] <<
" " << idx[1] <<
" " << idx[2] <<
"";
524 if (status && value != -1.)
526 float valByItk = itkimage->GetPixel(idx);
528 "Compare value of pixel returned by mitk in comparison to itk");
532 MITK_WARN <<
"Index is out buffered region!";
537 MITK_INFO <<
"Image does not contain three dimensions, some test cases are skipped!";
541 unsigned int *threeDdim =
new unsigned int[3];
546 threeDImage->Initialize(mitk::MakeScalarPixelType<float>(), 3, threeDdim);
550 "Testing if the clone image initializes with 3D!");
553 "Checking reference count of Image after using GetVtkImageData()");
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.
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)
#define MITK_TEST_OUTPUT(x)
Output some text.
#define mitkPixelTypeMultiplex3(function, ptype, param1, param2, param3)
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
#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)
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.
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.
BaseGeometry Describes the geometry of a data object.
Class for defining the data type of pixels.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.