diff --git a/Core/Code/Testing/CMakeLists.txt b/Core/Code/Testing/CMakeLists.txt index 4095a1e48c..5614d771a6 100644 --- a/Core/Code/Testing/CMakeLists.txt +++ b/Core/Code/Testing/CMakeLists.txt @@ -1,11 +1,12 @@ MITK_CREATE_MODULE_TESTS(LABELS MITK-Core) # MITK_INSTALL_TARGETS(EXECUTABLES MitkTestDriver) ADD_TEST(mitkPicFileReaderTest_emptyFile ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkPicFileReaderTest ${CMAKE_CURRENT_SOURCE_DIR}/Data/emptyFile.pic) SET_PROPERTY(TEST mitkPicFileReaderTest_emptyFile PROPERTY LABELS MITK-Core) ADD_TEST(mitkPicFileReaderTest_emptyGzipFile ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkPicFileReaderTest ${CMAKE_CURRENT_SOURCE_DIR}/Data/emptyFile.pic.gz) SET_PROPERTY(TEST mitkPicFileReaderTest_emptyGzipFile PROPERTY LABELS MITK-Core) +message( ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} ) ADD_TEST(mitkImageTest_brainImage ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkImageTest ${MITK_DATA_DIR}/brain.mhd) SET_PROPERTY(TEST mitkImageTest_brainImage PROPERTY LABELS MITK-Core) \ No newline at end of file diff --git a/Core/Code/Testing/mitkImageTest.cpp b/Core/Code/Testing/mitkImageTest.cpp index 19e04cd06a..976c0185e0 100644 --- a/Core/Code/Testing/mitkImageTest.cpp +++ b/Core/Code/Testing/mitkImageTest.cpp @@ -1,489 +1,486 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include #include #include #include #include #include -#include #include #include int mitkImageTest(int argc, char* argv[]) { MITK_TEST_BEGIN(mitkImageTest); //Create Image out of nowhere mitk::Image::Pointer imgMem; mitk::PixelType pt(typeid(int)); unsigned int dim[]={100,100,20}; std::cout << "Testing creation of Image: "; imgMem=mitk::Image::New(); if(imgMem.IsNull()) { std::cout<<"[FAILED]"<Initialize(mitk::PixelType(typeid(int)), 3, dim); std::cout<<"[PASSED]"<IsInitialized()==false) { std::cout<<"[FAILED]"<GetData(); if(p==NULL) { std::cout<<"[FAILED]"<GetData(); if(p2==NULL) { std::cout<<"[FAILED]"<IsInitialized()==false) { std::cout<<"[FAILED]"<GetSliceData(dim[2]/2)->GetData(); unsigned int xy_size = dim[0]*dim[1]; unsigned int start_mid_slice = (dim[2]/2)*xy_size; for(i=0; iGetSliceData(dim[2]/2)->GetPicDescriptor()); imgMem=mitk::Image::New(); std::cout << "Testing reinitializing via Initialize(const mitk::PixelType& type, unsigned int dimension, unsigned int *dimensions): "; imgMem->Initialize(mitk::PixelType(typeid(int)), 3, dim); std::cout<<"[PASSED]"<SetPicSlice(pic_slice, i, 0, 0); } std::cout<<"[PASSED]"<GetData(); if(p2==NULL) { std::cout<<"[FAILED]"<IsInitialized()==false) { std::cout<<"[FAILED]"<SetPicVolume(mitkIpPicClone(imgMem->GetVolumeData(0)->GetPicDescriptor()),0); std::cout<<"[PASSED]"<data,0,xy_size*sizeof(int)); imgMem->SetPicSlice(pic_slice, 1); std::cout << "Getting the volume again and compare the check the changed slice: "; p2 = (int*)imgMem->GetData(); if(p2==NULL) { std::cout<<"[FAILED]"<SetVolume(imgMem->GetData()); std::cout<<"[PASSED]"<data,0,xy_size*sizeof(int)); imgMem->SetSlice(pic_slice->data, 0); std::cout << "Getting the volume again and compare the check the changed slice: "; p2 = (int*)imgMem->GetData(); if(p2==NULL) { std::cout<<"[FAILED]"<SetVolume(data); //std::cout<<"[PASSED]"<InitializeStandardPlane(100, 100, right, bottom, &spacing); planegeometry->SetOrigin(origin); std::cout << "done" << std::endl; std::cout << "Testing Initialize(const mitk::PixelType& type, const mitk::Geometry3D& geometry, unsigned int slices) with PlaneGeometry and GetData(): "; imgMem->Initialize(mitk::PixelType(typeid(int)), *planegeometry); p = (int*)imgMem->GetData(); if(p==NULL) { std::cout<<"[FAILED]"<Initialize(mitk::PixelType(typeid(int)), 40, *planegeometry); p = (int*)imgMem->GetData(); if(p==NULL) { std::cout<<"[FAILED]"<GetOrigin(): "; if( mitk::Equal(imgMem->GetGeometry()->GetOrigin(), origin) == false) { std::cout<<"[FAILED]"<GetOrigin(): "; if( mitk::Equal(imgMem->GetTimeSlicedGeometry()->GetOrigin(), origin) == false) { std::cout<<"[FAILED]"<SetOrigin(origin); std::cout<<"[PASSED]"<GetOrigin(): "; if( mitk::Equal(imgMem->GetGeometry()->GetOrigin(), origin) == false) { std::cout<<"[FAILED]"<GetOrigin(): "; if( mitk::Equal(imgMem->GetTimeSlicedGeometry()->GetOrigin(), origin) == false) { std::cout<<"[FAILED]"<GetGeometry2D(0)->GetOrigin(): "; if( mitk::Equal(imgMem->GetSlicedGeometry()->GetGeometry2D(0)->GetOrigin(), origin) == false) { std::cout<<"[FAILED]"<GetSpacing(): "; if( mitk::Equal(imgMem->GetGeometry()->GetSpacing(), spacing) == false) { std::cout<<"[FAILED]"<GetSpacing(): "; if( mitk::Equal(imgMem->GetTimeSlicedGeometry()->GetSpacing(), spacing) == false) { std::cout<<"[FAILED]"<SetSpacing(spacing); std::cout<<"[PASSED]"<GetSpacing(): "; if( mitk::Equal(imgMem->GetGeometry()->GetSpacing(), spacing) == false) { std::cout<<"[FAILED]"<GetSpacing(): "; if( mitk::Equal(imgMem->GetTimeSlicedGeometry()->GetSpacing(), spacing) == false) { std::cout<<"[FAILED]"<GetGeometry2D(0)->GetSpacing(): "; if( mitk::Equal(imgMem->GetSlicedGeometry()->GetGeometry2D(0)->GetSpacing(), spacing) == false) { std::cout<<"[FAILED]"<Initialize(*imgMem->GetPixelType().GetTypeId(), *imgMem->GetGeometry(), 2 /* #channels */, 0 /*tDim*/ ); vecImg->SetImportChannel(imgMem->GetData(), 0, mitk::Image::CopyMemory ); vecImg->SetImportChannel(imgMem->GetData(), 1, mitk::Image::CopyMemory ); std::cout<<"[PASSED]"<IsValidSlice(0,0,1) , ""); MITK_TEST_OUTPUT(<< " Testing whether CopyMemory worked"); MITK_TEST_CONDITION_REQUIRED(imgMem->GetData() != vecImg->GetData(), ""); MITK_TEST_OUTPUT(<< " Testing destruction after SetImportChannel"); vecImg = NULL; std::cout<<"[PASSED]"<Initialize(); vtkimage->SetDimensions( 2, 3, 4); double vtkorigin[] = {-350,-358.203, -1363.5}; vtkimage->SetOrigin(vtkorigin); mitk::Point3D vtkoriginAsMitkPoint; mitk::vtk2itk(vtkorigin, vtkoriginAsMitkPoint); double vtkspacing[] = {1.367, 1.367, 2}; vtkimage->SetSpacing(vtkspacing); vtkimage->SetScalarType( VTK_SHORT ); vtkimage->AllocateScalars(); std::cout<<"[PASSED]"<Initialize(vtkimage); MITK_TEST_CONDITION_REQUIRED(mitkByVtkImage->IsInitialized(), ""); MITK_TEST_OUTPUT(<< " vtkimage->Delete"); vtkimage->Delete(); std::cout<<"[PASSED]"<GetGeometry()->GetSpacing(); mitk::Vector3D vtkspacingAsMitkVector; mitk::vtk2itk(vtkspacing, vtkspacingAsMitkVector); MITK_TEST_CONDITION_REQUIRED(mitk::Equal(spacing2,vtkspacingAsMitkVector), ""); MITK_TEST_OUTPUT(<< " Testing whether GetSlicedGeometry(0)->GetOrigin() has been correctly initialized from vtkImageData"); mitk::Point3D origin2 = mitkByVtkImage->GetSlicedGeometry(0)->GetOrigin(); MITK_TEST_CONDITION_REQUIRED(mitk::Equal(origin2,vtkoriginAsMitkPoint), ""); MITK_TEST_OUTPUT(<< " Testing whether GetGeometry()->GetOrigin() has been correctly initialized from vtkImageData"); origin2 = mitkByVtkImage->GetGeometry()->GetOrigin(); MITK_TEST_CONDITION_REQUIRED(mitk::Equal(origin2,vtkoriginAsMitkPoint), ""); MITK_TEST_OUTPUT(<< " Testing whether GetTimeSlicedGeometry()->GetOrigin() has been correctly initialized from vtkImageData"); origin2 = mitkByVtkImage->GetTimeSlicedGeometry()->GetOrigin(); MITK_TEST_CONDITION_REQUIRED(mitk::Equal(origin2,vtkoriginAsMitkPoint), ""); // TODO test the following initializers on channel-incorporation // void mitk::Image::Initialize(const mitk::PixelType& type, unsigned int dimension, unsigned int *dimensions, unsigned int channels) // void mitk::Image::Initialize(const mitk::PixelType& type, int sDim, const mitk::Geometry2D& geometry2d, bool flipped, unsigned int channels, int tDim ) // void mitk::Image::Initialize(const mitk::Image* image) // void mitk::Image::Initialize(const mitkIpPicDescriptor* pic, int channels, int tDim, int sDim) //mitk::Image::Pointer vecImg = mitk::Image::New(); //vecImg->Initialize(PixelType(typeid(float), 6, itk::ImageIOBase::SYMMETRICSECONDRANKTENSOR), *imgMem->GetGeometry(), 2 /* #channels */, 0 /*tDim*/, false /*shiftBoundingBoxMinimumToZero*/ ); //vecImg->Initialize(PixelType(typeid(itk::Vector)), *imgMem->GetGeometry(), 2 /* #channels */, 0 /*tDim*/, false /*shiftBoundingBoxMinimumToZero*/ ); - // testing access by index coordinates and by world coordinates mitk::DataNode::Pointer node; mitk::DataNodeFactory::Pointer nodeReader = mitk::DataNodeFactory::New(); - //mitk::StandardFileLocations::Pointer locator = mitk::StandardFileLocations::GetInstance(); - //MITK_TEST_CONDITION_REQUIRED(locator.IsNotNull(),"Instantiating StandardFileLocations") + MITK_TEST_CONDITION_REQUIRED(argc == 2, "Check if test image is accessible!"); try { const std::string filename = std::string(argv[1]); nodeReader->SetFileName(filename); nodeReader->Update(); node = nodeReader->GetOutput(); } catch(...) { MITK_TEST_FAILED_MSG(<< "Could not read file for testing: " << "brain.mhd"); return NULL; } mitk::Image::Pointer image = dynamic_cast(node->GetData()); // test by index coordinates mitk::Index3D index; mitk::FillVector3D(index, 55, 39, 50); MITK_TEST_OUTPUT(<< "Testing mitk::Image::GetPixelValueByIndex"); double val = image->GetPixelValueByIndex(index); MITK_TEST_CONDITION_REQUIRED( mitk::Equal(val,112.22475433349609), ""); //test by world coordinates MITK_TEST_OUTPUT(<< "Testing mitk::Image::GetPixelValueByWorldCoordinate"); mitk::Point3D point; mitk::FillVector3D(point, -5.93752, 18.7199, 6.74218); val = image->GetPixelValueByWorldCoordinate(point); MITK_TEST_CONDITION_REQUIRED( mitk::Equal(val,94.456184387207031), ""); MITK_TEST_OUTPUT(<< "Convert to index and access value by mitk::Image::GetPixelValueByIndex again"); mitk::Index3D index2; image->GetGeometry()->WorldToIndex(point, index2); float val2 = image->GetPixelValueByIndex(index2); MITK_TEST_CONDITION_REQUIRED( mitk::Equal(val2,94.456184387207031), ""); //access via itk MITK_TEST_OUTPUT(<< "Test conversion to itk::Image"); typedef itk::Image ItkFloatImage3D; ItkFloatImage3D::Pointer itkimage; mitk::CastToItkImage(image, itkimage); std::cout<<"[PASSED]"<itk-physical->world consistency"); mitk::Point3D itkPhysicalPoint; image->GetGeometry()->WorldToItkPhysicalPoint(point, itkPhysicalPoint); mitk::Point3D backTransformedPoint; image->GetGeometry()->ItkPhysicalPointToWorld(itkPhysicalPoint, backTransformedPoint); MITK_TEST_CONDITION_REQUIRED( mitk::Equal(point,backTransformedPoint), ""); MITK_TEST_OUTPUT(<< "Compare value of pixel returned by mitk in comparison to itk"); itk::Index<3> idx; itkimage->TransformPhysicalPointToIndex(itkPhysicalPoint, idx); float valByItk = itkimage->GetPixel(idx); MITK_TEST_CONDITION_REQUIRED( mitk::Equal(valByItk,94.456184387207031), ""); MITK_TEST_END(); return EXIT_SUCCESS; }