diff --git a/Core/Code/Testing/mitkImageToItkTest.cpp b/Core/Code/Testing/mitkImageToItkTest.cpp index 5ac76c1c02..df403c3a1b 100644 --- a/Core/Code/Testing/mitkImageToItkTest.cpp +++ b/Core/Code/Testing/mitkImageToItkTest.cpp @@ -1,272 +1,271 @@ /*========================================================================= 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 "mitkImage.h" -#include "mitkImageAccessByItk.h" #include "mitkITKImageImport.h" #include "mitkReferenceCountWatcher.h" #include "itkDiffusionTensor3D.h" #include "itkConfidenceDiffusionTensor3D.h" #include #include int compareGeometries(mitk::Geometry3D* geometry1, mitk::Geometry3D* geometry2) { std::cout << "Testing transfer of GetGeometry()->GetOrigin(): " << std::flush; if(mitk::Equal(geometry1->GetOrigin(), geometry2->GetOrigin()) == false) { std::cout<<"[FAILED]"<GetSpacing(): " << std::flush; if(mitk::Equal(geometry1->GetSpacing(), geometry2->GetSpacing()) == false) { std::cout<<"[FAILED]"<GetAxisVector(" << i << "): " << std::flush; if(mitk::Equal(geometry1->GetAxisVector(i), geometry2->GetAxisVector(i)) == false) { std::cout<<"[FAILED]"< int testBackCasting(mitk::Image* imgMem, typename ImageType::Pointer & itkImage, bool disconnectAfterImport) { int result; if(itkImage.IsNull()) { std::cout<<"[FAILED]"<GetBufferPointer(); if(p==NULL) { std::cout<<"[FAILED]"<GetGeometry(), mitkImage->GetGeometry()); if(result != EXIT_SUCCESS) return result; std::cout << "Testing whether data after mitk::CastToMitkImage is available: " << std::flush; if(mitkImage->IsChannelSet()==false) { std::cout<<"[FAILED]"<DisconnectPipeline(); std::cout<<"[PASSED]"<GetGeometry(), mitkImage->GetGeometry()); if(result != EXIT_SUCCESS) return result; std::cout << "Testing whether data after mitk::ImportItkImage is available: " << std::flush; if(mitkImage->IsChannelSet()==false) { std::cout<<"[FAILED]"< int testImageToItkAndBack(mitk::Image* imgMem) { int result; int *p = (int*)imgMem->GetData(); if(p==NULL) { std::cout<<"[FAILED]"< ImageType; typename mitk::ImageToItk::Pointer toItkFilter = mitk::ImageToItk::New(); toItkFilter->SetInput(imgMem); toItkFilter->Update(); typename ImageType::Pointer itkImage = toItkFilter->GetOutput(); result = testBackCasting(imgMem, itkImage, false); if(result != EXIT_SUCCESS) return result; std::cout << "Testing mitk::ImageToItk (with subsequent DisconnectPipeline, see below): " << std::flush; result = testBackCasting(imgMem, itkImage, true); if(result != EXIT_SUCCESS) return result; return EXIT_SUCCESS; } int mitkImageToItkTest(int /*argc*/, char* /*argv*/[]) { int result; //Create Image out of nowhere mitk::Image::Pointer imgMem; mitk::PixelType pt(typeid(int)); std::cout << "Testing creation of Image: "; imgMem=mitk::Image::New(); if(imgMem.IsNull()) { std::cout<<"[FAILED]"<InitializeStandardPlane(100, 100, right, bottom, &spacing); planegeometry->SetOrigin(origin); std::cout << "done" << std::endl; std::cout << "Testing Initialize(const mitk::PixelType& type, int sDim, const mitk::PlaneGeometry& geometry) and GetData(): "; imgMem->Initialize(mitk::PixelType(typeid(int)), 40, *planegeometry); //XXXXXXXXXXXXXXXXXXXXXCHANGE! result = testImageToItkAndBack<3>(imgMem); if(result != EXIT_SUCCESS) return result; std::cout << "Testing mitk::CastToItkImage with casting (mitk int to itk float): " << std::flush; typedef itk::Image ImageType; ImageType::Pointer itkImage; mitk::CastToItkImage( imgMem, itkImage ); result = testBackCasting(imgMem, itkImage, false); if(result != EXIT_SUCCESS) return result; result = testBackCasting(imgMem, itkImage, true); if(result != EXIT_SUCCESS) return result; std::cout << "Testing Initialize(const mitk::PixelType& type, int sDim, const mitk::PlaneGeometry& geometry) and GetData(): "; imgMem->Initialize(mitk::PixelType(typeid(int)), 40, *planegeometry, false, 1, 6); result = testImageToItkAndBack<4>(imgMem); if(result != EXIT_SUCCESS) return result; std::cout << "Testing mitk::CastToItkImage again (mitk float to itk float): " << std::flush; imgMem->Initialize(mitk::PixelType(typeid(float)), 40, *planegeometry); mitk::CastToItkImage( imgMem, itkImage ); std::cout<<"[PASSED]"<GetChannelData().GetPointer(); std::cout << "Testing destruction of original mitk::Image: " << std::flush; imgMem = NULL; std::cout<<"[PASSED]"<GetReferenceCount()-1 != 1) // 1 count by imageDataItem itself { std::cout<< imageDataItem->GetReferenceCount()-1 << " != 1. [FAILED]" << std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<GetReferenceCount()-1 != 0) // 1 count by imageDataItem itself { std::cout<< imageDataItem->GetReferenceCount()-1 << " != 0. [FAILED]" << std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<,3>::Pointer diffImage; imgMem->Initialize(mitk::PixelType(typeid(itk::DiffusionTensor3D)), 40, *planegeometry); mitk::CastToItkImage( imgMem, diffImage ); imgMem->InitializeByItk(diffImage.GetPointer()); std::cout<<"[PASSED]"<,3>::Pointer diffImage2; imgMem->Initialize(mitk::PixelType(typeid(itk::DiffusionTensor3D)), 40, *planegeometry); mitk::CastToItkImage( imgMem, diffImage2 ); imgMem->InitializeByItk(diffImage2.GetPointer()); std::cout<<"[PASSED]"<,3>::Pointer confDiffImage; imgMem->Initialize(mitk::PixelType(typeid(itk::ConfidenceDiffusionTensor3D)), 40, *planegeometry); mitk::CastToItkImage( imgMem, confDiffImage ); imgMem->InitializeByItk(confDiffImage.GetPointer()); std::cout<<"[PASSED]"<,3>::Pointer confDiffImage2; imgMem->Initialize(mitk::PixelType(typeid(itk::ConfidenceDiffusionTensor3D)), 40, *planegeometry); mitk::CastToItkImage( imgMem, confDiffImage2 ); imgMem->InitializeByItk(confDiffImage2.GetPointer()); std::cout<<"[PASSED]"<