Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkCompressedImageContainer.h"
00019 #include "mitkCoreObjectFactory.h"
00020 #include "mitkDataNodeFactory.h"
00021 #include "mitkImageDataItem.h"
00022 #include "itkSmartPointerForwardReference.txx"
00023
00024 class mitkCompressedImageContainerTestClass
00025 {
00026 public:
00027
00028 static void Test( mitk::CompressedImageContainer* container, mitk::Image* image, unsigned int& numberFailed )
00029 {
00030 container->SetImage( image );
00031 mitk::Image::Pointer uncompressedImage = container->GetImage();
00032
00033
00034 if (image->GetDimension() != uncompressedImage->GetDimension())
00035 {
00036 ++numberFailed;
00037 std::cerr << " (EE) Number of image dimensions wrong after uncompression (was: " << image->GetDimension() << ", now: " << uncompressedImage->GetDimension() << ")" << std::endl;
00038 }
00039
00040 for (unsigned int dim = 0; dim < image->GetDimension(); ++dim)
00041 {
00042 if (image->GetDimension(dim) != uncompressedImage->GetDimension(dim))
00043 {
00044 ++numberFailed;
00045 std::cerr << " (EE) Image dimension " << dim << " differs after uncompression (was: " << image->GetDimension(dim) << ", now: " << uncompressedImage->GetDimension(dim) << ")" << std::endl;
00046 }
00047 }
00048
00049
00050 if (image->GetPixelType() != uncompressedImage->GetPixelType())
00051 {
00052 ++numberFailed;
00053 std::cerr << " (EE) Pixel type wrong after uncompression:" << std::endl;
00054
00055 mitk::PixelType m_PixelType = image->GetPixelType();
00056 std::cout << "Original pixel type:" << std::endl;
00057 std::cout << " PixelType: " << m_PixelType.GetTypeId()->name() << std::endl;
00058 std::cout << " BitsPerElement: " << m_PixelType.GetBpe() << std::endl;
00059 std::cout << " NumberOfComponents: " << m_PixelType.GetNumberOfComponents() << std::endl;
00060 std::cout << " BitsPerComponent: " << m_PixelType.GetBitsPerComponent() << std::endl;
00061
00062 m_PixelType = uncompressedImage->GetPixelType();
00063 std::cout << "Uncompressed pixel type:" << std::endl;
00064 std::cout << " PixelType: " << m_PixelType.GetTypeId()->name() << std::endl;
00065 std::cout << " BitsPerElement: " << m_PixelType.GetBpe() << std::endl;
00066 std::cout << " NumberOfComponents: " << m_PixelType.GetNumberOfComponents() << std::endl;
00067 std::cout << " BitsPerComponent: " << m_PixelType.GetBitsPerComponent() << std::endl;
00068 }
00069
00070
00071 mitk::PixelType m_PixelType = image->GetPixelType();
00072 unsigned long oneTimeStepSizeInBytes = m_PixelType.GetBpe() >> 3;
00073 for (unsigned int dim = 0; dim < image->GetDimension(); ++dim)
00074 {
00075 if (dim < 3)
00076 {
00077 oneTimeStepSizeInBytes *= image->GetDimension(dim);
00078 }
00079 }
00080
00081 unsigned int numberOfTimeSteps(1);
00082 if (image->GetDimension() > 3)
00083 {
00084 numberOfTimeSteps = image->GetDimension(3);
00085 }
00086
00087 for (unsigned int timeStep = 0; timeStep < numberOfTimeSteps; ++timeStep)
00088 {
00089 unsigned char* originalData( static_cast<unsigned char*>(image->GetVolumeData(timeStep)->GetData()) );
00090 unsigned char* uncompressedData( static_cast<unsigned char*>(uncompressedImage->GetVolumeData(timeStep)->GetData()) );
00091
00092 unsigned long difference(0);
00093 for (unsigned long byte = 0; byte < oneTimeStepSizeInBytes; ++byte)
00094 {
00095 if ( originalData[byte] != uncompressedData[byte] )
00096 {
00097 ++difference;
00098 }
00099 }
00100
00101 if ( difference > 0 )
00102 {
00103 ++numberFailed;
00104 std::cerr << " (EE) Pixel data in timestep " << timeStep << " not identical after uncompression. " << difference << " pixels different." << std::endl;
00105 break;
00106 }
00107 }
00108
00109 }
00110
00111 };
00112
00114 int mitkCompressedImageContainerTest(int argc, char* argv[])
00115 {
00116
00117 unsigned int numberFailed(0);
00118
00119
00120 if(argc==0)
00121 {
00122 std::cerr<<"No file specified [FAILED]"<<std::endl;
00123 return EXIT_FAILURE;
00124 }
00125
00126
00127
00128 mitk::Image::Pointer image = NULL;
00129 mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New();
00130 try
00131 {
00132 std::cout << "Testing with parameter '" << argv[1] << "'" << std::endl;
00133 factory->SetFileName( argv[1] );
00134 factory->Update();
00135
00136 if(factory->GetNumberOfOutputs()<1)
00137 {
00138 std::cerr<<"File could not be loaded [FAILED]"<<std::endl;
00139 return EXIT_FAILURE;
00140 }
00141 mitk::DataNode::Pointer node = factory->GetOutput( 0 );
00142 image = dynamic_cast<mitk::Image*>(node->GetData());
00143 if(image.IsNull())
00144 {
00145 std::cout<<"File not an image - test will not be applied [PASSED]"<<std::endl;
00146 std::cout<<"[TEST DONE]"<<std::endl;
00147 return EXIT_SUCCESS;
00148 }
00149 }
00150 catch ( itk::ExceptionObject & ex )
00151 {
00152 ++numberFailed;
00153 std::cerr << "Exception: " << ex << "[FAILED]" << std::endl;
00154 return EXIT_FAILURE;
00155 }
00156
00157 std::cout << " (II) Could load image." << std::endl;
00158 std::cout << "Testing instantiation" << std::endl;
00159
00160
00161 mitk::CompressedImageContainer::Pointer container = mitk::CompressedImageContainer::New();
00162 if (container.IsNotNull())
00163 {
00164 std::cout << " (II) Instantiation works." << std::endl;
00165 }
00166 else
00167 {
00168 ++numberFailed;
00169 std::cout << "Test failed, and it's the ugliest one!" << std::endl;
00170 return EXIT_FAILURE;
00171 }
00172
00173
00174 mitkCompressedImageContainerTestClass::Test( container, image, numberFailed );
00175
00176 std::cout << "Testing destruction" << std::endl;
00177
00178
00179 container = NULL;
00180
00181 std::cout << " (II) Freeing works." << std::endl;
00182
00183 if (numberFailed > 0)
00184 {
00185 std::cerr << numberFailed << " tests failed." << std::endl;
00186 return EXIT_FAILURE;
00187 }
00188 else
00189 {
00190 std::cout << "PASSED all tests." << std::endl;
00191 return EXIT_SUCCESS;
00192 }
00193 }
00194
00195