diff --git a/Core/Code/Algorithms/mitkImageAccessByItk.h b/Core/Code/Algorithms/mitkImageAccessByItk.h index 5605e98751..2b7359e6e5 100644 --- a/Core/Code/Algorithms/mitkImageAccessByItk.h +++ b/Core/Code/Algorithms/mitkImageAccessByItk.h @@ -1,708 +1,1068 @@ /*========================================================================= 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. =========================================================================*/ #ifndef MITKIMAGEACCESSBYITK_H_HEADER_INCLUDED #define MITKIMAGEACCESSBYITK_H_HEADER_INCLUDED #include #include +#include "mitkPixelTypeList.h" #ifndef DOXYGEN_SKIP #define _accessByItkWarning \ { \ itkGenericOutputMacro(<< "Pixel type " << pixelType.GetItkTypeAsString() \ << " not supported by AccessByItk") \ } #define _accessByItkWarningParam(pixelType, accessor) \ { \ itkGenericOutputMacro(<< "Pixel type " << pixelType.GetItkTypeAsString() \ << " not supported by " << accessor) \ } #define _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension) \ if ( pixelType == typeid(pixeltype) ) \ { \ typedef itk::Image ImageType; \ typedef mitk::ImageToItk ImageToItkType; \ itk::SmartPointer imagetoitk = ImageToItkType::New(); \ imagetoitk->SetInput(mitkImage); \ imagetoitk->Update(); \ itkImageTypeFunction(imagetoitk->GetOutput()); \ } \ #define _accessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension) \ _accessByItk(mitkImage, itkImageTypeFunction, double, dimension) else \ _accessByItk(mitkImage, itkImageTypeFunction, float, dimension) else \ _accessByItk(mitkImage, itkImageTypeFunction, int, dimension) else \ _accessByItk(mitkImage, itkImageTypeFunction, unsigned int, dimension) else \ _accessByItk(mitkImage, itkImageTypeFunction, short, dimension) else \ _accessByItk(mitkImage, itkImageTypeFunction, unsigned short, dimension) else \ _accessByItk(mitkImage, itkImageTypeFunction, char, dimension) else \ _accessByItk(mitkImage, itkImageTypeFunction, unsigned char, dimension) else \ _accessByItkWarning + +#define _accessSpecificTypesByItk(mitkImage, dimension, ...) \ +{ \ + typedef mitk::PixelTypeList<__VA_ARGS__> MyTypes; \ + mitk::PixelTypeSwitch typeSwitch; \ + mitk::AccessItkImageFunctor memberFunctor(this, mitkImage); \ + int i = 0; \ + int typeCount = mitk::PixelTypeLength::value; \ + for(; i < typeCount; ++i) \ + { \ + if (typeSwitch(i, memberFunctor)) break; \ + } \ + assert(i != typeCount); \ +} + #endif //DOXYGEN_SKIP /** * @brief Access an mitk-image by an itk-image * * Define a templated function or method (@a itkImageTypeFunction) * within which the mitk-image (@a mitkImage) is accessed: * \code * template < typename TPixel, unsigned int VImageDimension > * void ExampleFunction( itk::Image* itkImage, TPixel* dummy = NULL ); * \endcode * Instantiate the function using * \code * InstantiateAccessFunction(ExampleFunction); * \endcode * Within the itk::Image passed to the function/method has the same * data-pointer as the mitk-image. So you have full read- and write- * access to the data vector of the mitk-image using the itk-image. * Call by: * \code * inputMitkImage being of type mitk::Image* * AccessByItk(inputMitkImage, ExampleFunction); * \endcode * @note If your inputMitkImage is an mitk::Image::Pointer, use * inputMitkImage.GetPointer() * @note If you need to pass an additional parameter to your * access-function (@a itkImageTypeFunction), use AccessByItk. * @note If you know the dimension of your input mitk-image, * it is better to use AccessFixedDimensionByItk (less code * is generated). * \sa AccessFixedDimensionByItk * \sa AccessFixedTypeByItk * \sa AccessFixedPixelTypeByItk * \sa AccessByItk_1 * \sa AccessByItk_2 * @ingroup Adaptor */ #define AccessByItk(mitkImage, itkImageTypeFunction) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ if((mitkImage)->GetDimension()==2) \ { \ _accessAllTypesByItk(mitkImage, itkImageTypeFunction, 2); \ } \ else \ { \ _accessAllTypesByItk(mitkImage, itkImageTypeFunction, 3) \ } \ } +/** + * \brief Access an mitk image by an itk image + * + * This variadic macro allows you to define a set of allowed pixel types for + * your mitk::Image. You must use this macro inside a class member function and + * the class must contain a \em Self typedef and a public \em AccessItkImage template function. + * + * The following example accesses an mitk-image as an ITK image, restricting the + * allowed pixel types to signed integral datatypes: + * \code + * class MyClass + * { + * typedef MyClass Self; + * + * public: + * + * template + * void AccessItkImage(itk::Image* itkImage) + * { + * ... do something + * } + * + * void Calculate() + * { + * mitk::Image* mitkImage = ... + * AccessSpecificTypesByItk(mitkImage, int, short, char) + * } + * }; + * \endcode + * + * If you enable ITK_USE_STRICT_CONCEPT_CHECKING in your ITK build, you have to use this + * macro or its variants to avoid compiling ITK filters with incorrect types. + * + * \sa AccessIntegralTypesByItk + * \sa AccessFloatingTypesByItk + */ +#define AccessSpecificTypesByItk(mitkImage, ...) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk(mitkImage, 2, __VA_ARGS__); \ + } \ + else \ + { \ + _accessSpecificTypesByItk(mitkImage, 3, __VA_ARGS__); \ + } \ +} + +/** + * \brief Access an mitk::Image with an integral pixel type by an ITK image + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessIntegralTypesByItk(mitkImage) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk(mitkImage, 2, int, unsigned int, short, unsigned short, char, unsigned char); \ + } \ + else \ + { \ + _accessSpecificTypesByItk(mitkImage, 3, int, unsigned int, short, unsigned short, char, unsigned char); \ + } \ +} + +/** + * \brief Access an mitk::Image with a floating point pixel type by an ITK image + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessFloatingTypesByItk(mitkImage) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk(mitkImage, 2, double, float); \ + } \ + else \ + { \ + _accessSpecificTypesByItk(mitkImage, 3, double, float); \ + } \ +} + //##Documentation //## @brief Access an mitk-image with known dimension by an itk-image //## //## For usage, see AccessByItk. //## @param dimension dimension of the mitk-image. //## //## If the image has a different dimension, an exception is thrown //## (by assert). //## If you do not know the dimension for sure, use AccessByItk. //## \sa AccessByItk //## \sa AccessFixedDimensionByItk //## \sa AccessFixedTypeByItk //## \sa AccessFixedPixelTypeByItk //## @ingroup Adaptor #define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert((mitkImage)->GetDimension()==dimension); \ _accessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension) \ } //##Documentation //## @brief Access an mitk-image with known type (pixel type and dimension) //## by an itk-image //## //## For usage, see AccessByItk. //## @param dimension dimension of the mitk-image. If the image //## has a different dimension, an exception is thrown (by assert). //## If you do not know the dimension for sure, use AccessByItk. //## \sa AccessByItk //## \sa AccessFixedDimensionByItk //## \sa AccessFixedTypeByItk //## \sa AccessFixedPixelTypeByItk //## @ingroup Adaptor #define AccessFixedTypeByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert((mitkImage)->GetDimension()==dimension); \ _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension) else \ _accessByItkWarning \ } //##Documentation //## @brief Access an mitk-image with known pixeltype (but unknown dimension) //## by an itk-image and pass two additional parameters to the access-function //## //## For usage, see AccessByItk. //## @param pixeltype pixel type of the mitk-image. //## //## If the image has a different pixel type, an exception is //## thrown (by assert). //## If you do not know the pixel type for sure, use AccessByItk. //## \sa AccessByItk //## \sa AccessFixedDimensionByItk //## \sa AccessFixedTypeByItk //## \sa AccessFixedPixelTypeByItk //## @ingroup Adaptor #define AccessFixedPixelTypeByItk(mitkImage, itkImageTypeFunction, pixeltype) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ if((mitkImage)->GetDimension()==2) \ { \ _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, 2) else \ _accessByItkWarning \ } \ else \ { \ _accessByItk(mitkImage, itkImageTypeFunction, pixeltype, 3) else \ _accessByItkWarning \ } \ } //----------------------- version with 1 additional paramater ------------------ #ifndef DOXYGEN_SKIP #define _accessByItk_1(mitkImage, itkImageTypeFunction, pixeltype, dimension, param1) \ if ( pixelType == typeid(pixeltype) ) \ { \ typedef itk::Image ImageType; \ typedef mitk::ImageToItk ImageToItkType; \ itk::SmartPointer imagetoitk = ImageToItkType::New(); \ imagetoitk->SetInput(mitkImage); \ imagetoitk->Update(); \ itkImageTypeFunction(imagetoitk->GetOutput(), param1); \ } #define _accessAllTypesByItk_1(mitkImage, itkImageTypeFunction, dimension, param1) \ _accessByItk_1(mitkImage, itkImageTypeFunction, double, dimension, param1) else \ _accessByItk_1(mitkImage, itkImageTypeFunction, float, dimension, param1) else \ _accessByItk_1(mitkImage, itkImageTypeFunction, int, dimension, param1) else \ _accessByItk_1(mitkImage, itkImageTypeFunction, unsigned int, dimension, param1) else \ _accessByItk_1(mitkImage, itkImageTypeFunction, short, dimension, param1) else \ _accessByItk_1(mitkImage, itkImageTypeFunction, unsigned short, dimension, param1) else \ _accessByItk_1(mitkImage, itkImageTypeFunction, char, dimension, param1) else \ _accessByItk_1(mitkImage, itkImageTypeFunction, unsigned char, dimension, param1) else \ _accessByItkWarning \ +#define _accessSpecificTypesByItk_1(mitkImage, paramtype1, param1, dimension, ...) \ +{ \ + typedef mitk::PixelTypeList<__VA_ARGS__> MyTypes; \ + mitk::PixelTypeSwitch typeSwitch; \ + mitk::AccessItkImageFunctor memberFunctor(this, mitkImage, param1); \ + int i = 0; \ + int typeCount = mitk::PixelTypeLength::value; \ + for(; i < typeCount; ++i) \ + { \ + if (typeSwitch(i, memberFunctor)) break; \ + } \ + assert(i != typeCount); \ +} + #endif //DOXYGEN_SKIP //##Documentation //## @brief Access an mitk-image by an itk-image and pass one //## additional parameter to the access-function //## //## For usage, see AccessByItk. The only difference to AccessByItk //## is that an additional parameter (@a param1) is passed. //## @note If you know the dimension of your input mitk-image, //## it is better to use AccessFixedDimensionByItk_1 (less code //## is generated). //## \sa AccessByItk //## \sa AccessFixedDimensionByItk_1 //## \sa AccessFixedTypeByItk_1 //## \sa AccessFixedPixelTypeByItk_1 //## @ingroup Adaptor #define AccessByItk_1(mitkImage, itkImageTypeFunction, param1) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()>=2 && mitkImage->GetDimension()<=3); \ if(mitkImage->GetDimension()==2) \ { \ _accessAllTypesByItk_1(mitkImage, itkImageTypeFunction, 2, param1); \ } \ else \ { \ _accessAllTypesByItk_1(mitkImage, itkImageTypeFunction, 3, param1) \ } \ } +/** + * \brief Access an mitk-image by an itk-image and pass one + * additional parameter to the access-function. + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessSpecificTypesByItk_1(mitkImage, paramType1, param1, ...) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk_1(mitkImage, paramType1, param1, 2, __VA_ARGS__); \ + } \ + else \ + { \ + _accessSpecificTypesByItk_1(mitkImage, paramType1, param1, 3, __VA_ARGS__); \ + } \ +} + +/** + * \brief Access an mitk-image witn an integral pixel type by an itk-image and pass one + * additional parameter to the access-function. + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessIntegralTypesByItk_1(mitkImage, paramType1, param1) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk_1(mitkImage, paramType1, param1, 2, int, unsigned int, short, unsigned short, char, unsigned char); \ + } \ + else \ + { \ + _accessSpecificTypesByItk_1(mitkImage, paramType1, param1, 3, int, unsigned int, short, unsigned short, char, unsigned char); \ + } \ +} + +/** + * \brief Access an mitk-image with a floating point pixel type by an itk-image and pass one + * additional parameter to the access-function. + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessFloatingTypesByItk_1(mitkImage, paramType1, param1) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk_1(mitkImage, paramType1, param1, 2, double, float); \ + } \ + else \ + { \ + _accessSpecificTypesByItk_1(mitkImage, paramType1, param1, 3, double, float); \ + } \ +} + //##Documentation //## @brief Access an mitk-image with known dimension by an itk-image //## and pass one additional parameter to the access-function //## //## For usage, see AccessByItk_1 and AccessByItk. //## @param dimension dimension of the mitk-image. //## //## If the image has a different dimension, an exception is thrown //## (by assert). //## If you do not know the dimension for sure, use AccessByItk_1. //## \sa AccessByItk_2 //## \sa AccessByItk //## \sa AccessFixedDimensionByItk_1 //## \sa AccessFixedTypeByItk_1 //## \sa AccessFixedPixelTypeByItk_1 //## @ingroup Adaptor #define AccessFixedDimensionByItk_1(mitkImage, itkImageTypeFunction, dimension, param1) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()==dimension); \ _accessAllTypesByItk_1(mitkImage, itkImageTypeFunction, dimension, param1) \ } //##Documentation //## @brief Access an mitk-image with known type (pixel type and dimension) //## by an itk-image and pass one additional parameters to the access-function //## //## For usage, see AccessByItk_1 and AccessByItk. //## @param pixeltype pixel type of the mitk-image. //## @param dimension dimension of the mitk-image. //## //## If the image has a different pixel type or dimension, an exception is //## thrown (by assert). //## If you do not know the pixel type and dimension for sure, use AccessByItk_1. //## \sa AccessByItk_1 //## \sa AccessByItk //## \sa AccessFixedDimensionByItk_1 //## \sa AccessFixedTypeByItk_1 //## \sa AccessFixedPixelTypeByItk_1 //## @ingroup Adaptor #define AccessFixedTypeByItk_1(mitkImage, itkImageTypeFunction, pixeltype, dimension, param1) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()==dimension); \ _accessByItk_1(mitkImage, itkImageTypeFunction, pixeltype, dimension, param1) else \ _accessByItkWarning \ } //##Documentation //## @brief Access an mitk-image with known pixeltype (but unknown dimension) //## by an itk-image and pass one additional parameters to the access-function //## //## For usage, see AccessByItk_1 and AccessByItk. //## @param pixeltype pixel type of the mitk-image. //## //## If the image has a different pixel type, an exception is //## thrown (by assert). //## If you do not know the pixel type for sure, use AccessByItk_2. //## \sa AccessByItk_1 //## \sa AccessByItk //## \sa AccessFixedDimensionByItk //## \sa AccessFixedTypeByItk_1 //## \sa AccessFixedPixelTypeByItk_1 //## @ingroup Adaptor #define AccessFixedPixelTypeByItk_1(mitkImage, itkImageTypeFunction, pixeltype, param1) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()>=2 && mitkImage->GetDimension()<=3); \ if(mitkImage->GetDimension()==2) \ { \ _accessByItk_1(mitkImage, itkImageTypeFunction, pixeltype, 2, param1) else \ _accessByItkWarning \ } \ else \ { \ _accessByItk_1(mitkImage, itkImageTypeFunction, pixeltype, 3, param1) else \ _accessByItkWarning \ } \ } //----------------------- version with 2 additional paramaters ----------------- #ifndef DOXYGEN_SKIP #define _accessByItk_2(mitkImage, itkImageTypeFunction, pixeltype, dimension, param1, param2) \ if ( pixelType == typeid(pixeltype) ) \ { \ typedef itk::Image ImageType; \ typedef mitk::ImageToItk ImageToItkType; \ itk::SmartPointer imagetoitk = ImageToItkType::New(); \ imagetoitk->SetInput(mitkImage); \ imagetoitk->Update(); \ itkImageTypeFunction(imagetoitk->GetOutput(), param1, param2); \ } #define _accessAllTypesByItk_2(mitkImage, itkImageTypeFunction, dimension, param1, param2) \ _accessByItk_2(mitkImage, itkImageTypeFunction, double, dimension, param1, param2) else \ _accessByItk_2(mitkImage, itkImageTypeFunction, float, dimension, param1, param2) else \ _accessByItk_2(mitkImage, itkImageTypeFunction, int, dimension, param1, param2) else \ _accessByItk_2(mitkImage, itkImageTypeFunction, unsigned int, dimension, param1, param2) else \ _accessByItk_2(mitkImage, itkImageTypeFunction, short, dimension, param1, param2) else \ _accessByItk_2(mitkImage, itkImageTypeFunction, unsigned short, dimension, param1, param2) else \ _accessByItk_2(mitkImage, itkImageTypeFunction, char, dimension, param1, param2) else \ _accessByItk_2(mitkImage, itkImageTypeFunction, unsigned char, dimension, param1, param2) else \ _accessByItkWarning \ +#define _accessSpecificTypesByItk_2(mitkImage, paramtype1, param1, paramtype2, param2, dimension, ...) \ +{ \ + typedef mitk::PixelTypeList<__VA_ARGS__> MyTypes; \ + mitk::PixelTypeSwitch typeSwitch; \ + mitk::AccessItkImageFunctor memberFunctor(this, mitkImage, param1, param2); \ + int i = 0; \ + int typeCount = mitk::PixelTypeLength::value; \ + for(; i < typeCount; ++i) \ + { \ + if (typeSwitch(i, memberFunctor)) break; \ + } \ + assert(i != typeCount); \ +} + #endif //DOXYGEN_SKIP //##Documentation //## @brief Access an mitk-image by an itk-image and pass two //## additional parameters to the access-function //## //## For usage, see AccessByItk. The only difference to AccessByItk //## is that two additional parameters (@a param1, @a param2) are passed. //## @note If you know the dimension of your input mitk-image, //## it is better to use AccessFixedDimensionByItk_2 (less code //## is generated). //## \sa AccessByItk //## \sa AccessFixedDimensionByItk_2 //## \sa AccessFixedTypeByItk_2 //## \sa AccessFixedPixelTypeByItk_2 //## @ingroup Adaptor #define AccessByItk_2(mitkImage, itkImageTypeFunction, param1, param2) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()>=2 && mitkImage->GetDimension()<=3); \ if(mitkImage->GetDimension()==2) \ { \ _accessAllTypesByItk_2(mitkImage, itkImageTypeFunction, 2, param1, param2); \ } \ else \ { \ _accessAllTypesByItk_2(mitkImage, itkImageTypeFunction, 3, param1, param2) \ } \ } +/** + * \brief Access an mitk-image by an itk-image and pass two + * additional parameter to the access-function. + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessSpecificTypesByItk_2(mitkImage, paramType1, param1, paramType2, param2, ...) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk_2(mitkImage, paramType1, param1, paramType2, param2, 2, __VA_ARGS__); \ + } \ + else \ + { \ + _accessSpecificTypesByItk_2(mitkImage, paramType1, param1, paramType2, param2, 3, __VA_ARGS__); \ + } \ +} + +/** + * \brief Access an mitk-image with an integral pixel type by an itk-image and pass two + * additional parameter to the access-function. + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessIntegralTypesByItk_2(mitkImage, paramType1, param1, paramType2, param2) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk_2(mitkImage, paramType1, param1, paramType2, param2, 2, int, unsigned int, short, unsigned short, char, unsigned char); \ + } \ + else \ + { \ + _accessSpecificTypesByItk_2(mitkImage, paramType1, param1, paramType2, param2, 3, int, unsigned int, short, unsigned short, char, unsigned char); \ + } \ +} + +/** + * \brief Access an mitk-image with a floating point pixel type by an itk-image and pass two + * additional parameter to the access-function. + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessFloatingTypesByItk_2(mitkImage, paramType1, param1, paramType2, param2) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk_2(mitkImage, paramType1, param1, paramType2, param2, 2, double, float); \ + } \ + else \ + { \ + _accessSpecificTypesByItk_2(mitkImage, paramType1, param1, paramType2, param2, 3, double, float); \ + } \ +} + //##Documentation //## @brief Access an mitk-image with known dimension by an itk-image //## and pass two additional parameters to the access-function //## //## For usage, see AccessByItk_2 and AccessByItk. //## @param dimension dimension of the mitk-image. //## //## If the image has a different dimension, an exception is thrown //## (by assert). //## If you do not know the dimension for sure, use AccessByItk_2. //## \sa AccessByItk_2 //## \sa AccessByItk //## \sa AccessFixedDimensionByItk_2 //## \sa AccessFixedTypeByItk_2 //## \sa AccessFixedPixelTypeByItk_2 //## @ingroup Adaptor #define AccessFixedDimensionByItk_2(mitkImage, itkImageTypeFunction, dimension, param1, param2) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()==dimension); \ _accessAllTypesByItk_2(mitkImage, itkImageTypeFunction, dimension, param1, param2) \ } //##Documentation //## @brief Access an mitk-image with known type (pixel type and dimension) //## by an itk-image and pass two additional parameters to the access-function //## //## For usage, see AccessByItk_2 and AccessByItk. //## @param pixeltype pixel type of the mitk-image. //## @param dimension dimension of the mitk-image. //## //## If the image has a different pixel type or dimension, an exception is //## thrown (by assert). //## If you do not know the pixel type and dimension for sure, use AccessByItk_2. //## \sa AccessByItk_2 //## \sa AccessByItk //## \sa AccessFixedDimensionByItk //## \sa AccessFixedTypeByItk_2 //## \sa AccessFixedPixelTypeByItk_2 //## @ingroup Adaptor #define AccessFixedTypeByItk_2(mitkImage, itkImageTypeFunction, pixeltype, dimension, param1, param2) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()==dimension); \ _accessByItk_2(mitkImage, itkImageTypeFunction, pixeltype, dimension, param1, param2) else \ _accessByItkWarning \ } //##Documentation //## @brief Access an mitk-image with known pixel type (but unknown dimension) //## by an itk-image and pass two additional parameters to the access-function //## //## For usage, see AccessByItk_2 and AccessByItk. //## @param pixeltype pixel type of the mitk-image. //## //## If the image has a different pixel type, an exception is //## thrown (by assert). //## If you do not know the pixel type for sure, use AccessByItk_2. //## \sa AccessByItk_2 //## \sa AccessByItk //## \sa AccessFixedDimensionByItk //## \sa AccessFixedTypeByItk_2 //## \sa AccessFixedPixelTypeByItk_2 //## @ingroup Adaptor #define AccessFixedPixelTypeByItk_2(mitkImage, itkImageTypeFunction, pixeltype, param1, param2) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()>=2 && mitkImage->GetDimension()<=3); \ if(mitkImage->GetDimension()==2) \ { \ _accessByItk_2(mitkImage, itkImageTypeFunction, pixeltype, 2, param1, param2) else \ _accessByItkWarning \ } \ else \ { \ _accessByItk_2(mitkImage, itkImageTypeFunction, pixeltype, 3, param1, param2) else \ _accessByItkWarning \ } \ } #define _accessTwoImagesByItk2(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, pixeltype2, dimension) \ if ( pixelType2 == typeid(pixeltype2) ) \ { \ typedef itk::Image ImageType1; \ typedef itk::Image ImageType2; \ typedef mitk::ImageToItk ImageToItkType1; \ typedef mitk::ImageToItk ImageToItkType2; \ itk::SmartPointer imagetoitk1 = ImageToItkType1::New(); \ imagetoitk1->SetInput(mitkImage1); \ imagetoitk1->Update(); \ itk::SmartPointer imagetoitk2 = ImageToItkType2::New(); \ imagetoitk2->SetInput(mitkImage2); \ imagetoitk2->Update(); \ itkImageTypeFunction(imagetoitk1->GetOutput(), imagetoitk2->GetOutput()); \ } #define _accessTwoImagesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, dimension) \ if ( pixelType1 == typeid(pixeltype) ) \ { \ _accessTwoImagesByItk2(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, double, dimension) else \ _accessTwoImagesByItk2(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, float, dimension) else \ _accessTwoImagesByItk2(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, int, dimension) else \ _accessTwoImagesByItk2(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, unsigned int, dimension) else \ _accessTwoImagesByItk2(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, short, dimension) else \ _accessTwoImagesByItk2(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, unsigned short, dimension) else \ _accessTwoImagesByItk2(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, char, dimension) else \ _accessTwoImagesByItk2(mitkImage1, mitkImage2, itkImageTypeFunction, pixeltype, unsigned char, dimension) else \ _accessByItkWarningParam(pixelType2, "_accessTwoImagesByItk") \ } #define _accessTwoImagesAllTypesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, dimension) \ _accessTwoImagesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, double, dimension) else \ _accessTwoImagesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, float, dimension) else \ _accessTwoImagesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, int, dimension) else \ _accessTwoImagesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, unsigned int, dimension) else \ _accessTwoImagesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, short, dimension) else \ _accessTwoImagesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, unsigned short, dimension) else \ _accessTwoImagesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, char, dimension) else \ _accessTwoImagesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, unsigned char, dimension) else \ _accessByItkWarningParam(pixelType1, "_accessTwoImagesByItk") //----------------------- version with 3 additional parameters ----------------- #ifndef DOXYGEN_SKIP #define _accessByItk_3(mitkImage, itkImageTypeFunction, pixeltype, dimension, param1, param2, param3) \ if ( pixelType == typeid(pixeltype) ) \ { \ typedef itk::Image ImageType; \ typedef mitk::ImageToItk ImageToItkType; \ itk::SmartPointer imagetoitk = ImageToItkType::New(); \ imagetoitk->SetInput(mitkImage); \ imagetoitk->Update(); \ itkImageTypeFunction(imagetoitk->GetOutput(), param1, param2, param3); \ } #define _accessAllTypesByItk_3(mitkImage, itkImageTypeFunction, dimension, param1, param2, param3) \ _accessByItk_3(mitkImage, itkImageTypeFunction, double, dimension, param1, param2, param3) else \ _accessByItk_3(mitkImage, itkImageTypeFunction, float, dimension, param1, param2, param3) else \ _accessByItk_3(mitkImage, itkImageTypeFunction, int, dimension, param1, param2, param3) else \ _accessByItk_3(mitkImage, itkImageTypeFunction, unsigned int, dimension, param1, param2, param3) else \ _accessByItk_3(mitkImage, itkImageTypeFunction, short, dimension, param1, param2, param3) else \ _accessByItk_3(mitkImage, itkImageTypeFunction, unsigned short, dimension, param1, param2, param3) else \ _accessByItk_3(mitkImage, itkImageTypeFunction, char, dimension, param1, param2, param3) else \ _accessByItk_3(mitkImage, itkImageTypeFunction, unsigned char, dimension, param1, param2, param3) else \ _accessByItkWarning \ +#define _accessSpecificTypesByItk_3(mitkImage, paramtype1, param1, paramtype2, param2, paramtype3, param3, dimension, ...) \ +{ \ + typedef mitk::PixelTypeList<__VA_ARGS__> MyTypes; \ + mitk::PixelTypeSwitch typeSwitch; \ + mitk::AccessItkImageFunctor memberFunctor(this, mitkImage, param1, param2, param3); \ + int i = 0; \ + int typeCount = mitk::PixelTypeLength::value; \ + for(; i < typeCount; ++i) \ + { \ + if (typeSwitch(i, memberFunctor)) break; \ + } \ + assert(i != typeCount); \ +} + #endif //DOXYGEN_SKIP //##Documentation //## @brief Access an mitk-image by an itk-image and pass three //## additional parameters to the access-function //## //## For usage, see AccessByItk. The only difference to AccessByItk //## is that two additional parameters (@a param1, @a param2) are passed. //## @note If you know the dimension of your input mitk-image, //## it is better to use AccessFixedDimensionByItk_3 (less code //## is generated). //## \sa AccessByItk //## \sa AccessFixedDimensionByItk_3 //## \sa AccessFixedPixelTypeByItk_3 //## @ingroup Adaptor #define AccessByItk_3(mitkImage, itkImageTypeFunction, param1, param2, param3) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()>=2 && mitkImage->GetDimension()<=3); \ if(mitkImage->GetDimension()==2) \ { \ _accessAllTypesByItk_3(mitkImage, itkImageTypeFunction, 2, param1, param2, param3); \ } \ else \ { \ _accessAllTypesByItk_3(mitkImage, itkImageTypeFunction, 3, param1, param2, param3) \ } \ } +/** + * \brief Access an mitk-image by an itk-image and pass three + * additional parameter to the access-function. + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessSpecificTypesByItk_3(mitkImage, paramType1, param1, paramType2, param2, paramType3, param3, ...) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk_3(mitkImage, paramType1, param1, paramType2, param2, paramType3, param3, 2, __VA_ARGS__); \ + } \ + else \ + { \ + _accessSpecificTypesByItk_3(mitkImage, paramType1, param1, paramType2, param2, paramType3, param3, 3, __VA_ARGS__); \ + } \ +} + +/** + * \brief Access an mitk-image with an integral pixel type by an itk-image and pass three + * additional parameter to the access-function. + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessIntegralTypesByItk_3(mitkImage, paramType1, param1, paramType2, param2, paramType3, param3) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk_3(mitkImage, paramType1, param1, paramType2, param2, paramType3, param3, 2, int, unsigned int, short, unsigned short, char, unsigned char); \ + } \ + else \ + { \ + _accessSpecificTypesByItk_3(mitkImage, paramType1, param1, paramType2, param2, paramType3, param3, 3, int, unsigned int, short, unsigned short, char, unsigned char); \ + } \ +} + +/** + * \brief Access an mitk-image with a floating point pixel type by an itk-image and pass three + * additional parameter to the access-function. + * + * See AccessSpecificTypesByItk for details. + * + * \sa AccessSpecificTypesByItk + */ +#define AccessFloatingTypesByItk_3(mitkImage, paramType1, param1, paramType2, param2, paramType3, param3) \ +{ \ + const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ + mitkImage->Update(); \ + assert((mitkImage)->GetDimension()>=2 && (mitkImage)->GetDimension()<=3); \ + if((mitkImage)->GetDimension()==2) \ + { \ + _accessSpecificTypesByItk_3(mitkImage, paramType1, param1, paramType2, param2, paramType3, param3, 2, double, float); \ + } \ + else \ + { \ + _accessSpecificTypesByItk_3(mitkImage, paramType1, param1, paramType2, param2, paramType3, param3, 3, double, float); \ + } \ +} + //##Documentation //## @brief Access an mitk-image with known dimension by an itk-image //## and pass three additional parameters to the access-function //## //## For usage, see AccessByItk_3 and AccessByItk. //## @param dimension dimension of the mitk-image. //## //## If the image has a different dimension, an exception is thrown //## (by assert). //## If you do not know the dimension for sure, use AccessByItk_3. //## \sa AccessByItk_3 //## \sa AccessByItk //## \sa AccessFixedDimensionByItk_3 //## \sa AccessFixedTypeByItk_3 //## \sa AccessFixedPixelTypeByItk_3 //## @ingroup Adaptor #define AccessFixedDimensionByItk_3(mitkImage, itkImageTypeFunction, dimension, param1, param2, param3) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()==dimension); \ _accessAllTypesByItk_3(mitkImage, itkImageTypeFunction, dimension, param1, param2, param3) \ } //##Documentation //## @brief Access an mitk-image with known type (pixel type and dimension) //## by an itk-image and pass three additional parameters to the access-function //## //## For usage, see AccessByItk_3 and AccessByItk. //## @param pixeltype pixel type of the mitk-image. //## @param dimension dimension of the mitk-image. //## //## If the image has a different pixel type or dimension, an exception is //## thrown (by assert). //## If you do not know the pixel type and dimension for sure, use AccessByItk_3. //## \sa AccessByItk_3 //## \sa AccessByItk //## \sa AccessFixedDimensionByItk //## \sa AccessFixedPixelTypeByItk_3 //## @ingroup Adaptor #define AccessFixedTypeByItk_3(mitkImage, itkImageTypeFunction, pixeltype, dimension, param1, param2, param3) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()==dimension); \ _accessByItk_3(mitkImage, itkImageTypeFunction, pixeltype, dimension, param1, param2, param3) else \ _accessByItkWarning \ } //##Documentation //## @brief Access an mitk-image with known pixel type (but unknown dimension) //## by an itk-image and pass three additional parameters to the access-function //## //## For usage, see AccessByItk_3 and AccessByItk. //## @param pixeltype pixel type of the mitk-image. //## //## If the image has a different pixel type, an exception is //## thrown (by assert). //## If you do not know the pixel type for sure, use AccessByItk_3. //## \sa AccessByItk_3 //## \sa AccessByItk //## \sa AccessFixedDimensionByItk //## \sa AccessFixedTypeByItk_3 //## \sa AccessFixedPixelTypeByItk_3 //## @ingroup Adaptor #define AccessFixedPixelTypeByItk_3(mitkImage, itkImageTypeFunction, pixeltype, param1, param2, param3) \ { \ const mitk::PixelType& pixelType = mitkImage->GetPixelType(); \ const mitk::Image* constImage = mitkImage; \ const_cast(constImage)->Update(); \ assert(mitkImage->GetDimension()>=2 && mitkImage->GetDimension()<=3); \ if(mitkImage->GetDimension()==2) \ { \ _accessByItk_3(mitkImage, itkImageTypeFunction, pixeltype, 2, param1, param2, param3) else \ _accessByItkWarning \ } \ else \ { \ _accessByItk_3(mitkImage, itkImageTypeFunction, pixeltype, 3, param1, param2, param3) else \ _accessByItkWarning \ } \ } //##Documentation //## @brief Access two mitk-images with known dimension by itk-images //## //## For usage, see AccessByItk. //## @param dimension dimension of the mitk-image. //## //## If one of the images has a different dimension, an exception is thrown //## (by assert). //## If you do not know the dimension for sure, use AccessByItk. //## \sa AccessByItk //## \sa AccessFixedDimensionByItk //## \sa AccessFixedTypeByItk //## \sa AccessFixedPixelTypeByItk //## @ingroup Adaptor #define AccessTwoImagesFixedDimensionByItk(mitkImage1, mitkImage2, itkImageTypeFunction, dimension) \ { \ const mitk::PixelType& pixelType1 = mitkImage1->GetPixelType(); \ const mitk::PixelType& pixelType2 = mitkImage2->GetPixelType(); \ const mitk::Image* constImage1 = mitkImage1; \ const mitk::Image* constImage2 = mitkImage2; \ const_cast(constImage1)->Update(); \ const_cast(constImage2)->Update(); \ assert((mitkImage1)->GetDimension()==dimension); \ assert((mitkImage2)->GetDimension()==dimension); \ _accessTwoImagesAllTypesByItk(mitkImage1, mitkImage2, itkImageTypeFunction, dimension) \ } #ifdef mitkCore_EXPORTS #define MITK_CORE_EXPORT_EXTERN #else #define MITK_CORE_EXPORT_EXTERN extern #endif //----------------------- cast functions. Will be moved to mitkImageCast.h ----------------- namespace mitk { #ifndef DOXYGEN_SKIP template < typename TPixel, unsigned int VImageDimension, class ItkOutputImageType > void _CastToItkImage2Access( itk::Image* itkInputImage, itk::SmartPointer& itkOutputImage); #endif //DOXYGEN_SKIP //##Documentation //## @brief Cast an mitk::Image to an itk::Image with a specific type. You don't have to initialize the itk::Image<..>::Pointer. //## @ingroup Adaptor template extern void MITK_CORE_EXPORT CastToItkImage(const mitk::Image * mitkImage, itk::SmartPointer& itkOutputImage); } //----------------------- include to be removed ----------------------- #include #endif // of MITKIMAGEACCESSBYITK_H_HEADER_INCLUDED diff --git a/Core/Code/Algorithms/mitkPixelTypeList.h b/Core/Code/Algorithms/mitkPixelTypeList.h new file mode 100644 index 0000000000..f7982b1e65 --- /dev/null +++ b/Core/Code/Algorithms/mitkPixelTypeList.h @@ -0,0 +1,213 @@ +/*========================================================================= + +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 + +namespace mitk { + +struct EmptyType {}; + +template< + typename T0=EmptyType, + typename T1=EmptyType, + typename T2=EmptyType, + typename T3=EmptyType, + typename T4=EmptyType, + typename T5=EmptyType, + typename T6=EmptyType, + typename T7=EmptyType, + typename T8=EmptyType, + typename T9=EmptyType +> struct PixelTypeList; + +template< + typename T0, + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8, + typename T9 +> struct PixelTypeList +{ + typedef T0 head; + typedef PixelTypeList tail; + enum + { + length = tail::length+1 + }; +}; + +template<> +struct PixelTypeList +{ + enum + { + length = 0 + }; +}; + +template +struct PixelTypeLength +{ + enum + { + value = TypeList::length + }; +}; + +template< + typename TypeList, + int Index, //requested element index + int Step = 0, //current recusion step + bool Stop=(Index==Step), //stop recusion flag + bool OutOfRange = PixelTypeLength::value==0 //out of range flag +> struct GetPixelType +{ + typedef typename GetPixelType::type type; +}; + +//"out of range" specialization +template< + typename TypeList, + int Index, + int Step, + bool Stop +> +struct GetPixelType +{ + //if OutOfRange is 'true' the 'type' is undefined + //so we'll get a compile-time error +}; + +//"element found" specialization +template< + typename TypeList, + int Index, + int Step, + bool OutOfRange +> +struct GetPixelType +{ + //the index is equal to the recursion step + //so the result type is the head of the Typlist and stop! + typedef typename TypeList::head type; +}; + +//////////////////////////////////////////////////////////// +// run-time type switch +template< + typename TypeList, + int Index = 0, + bool Stop=(Index==PixelTypeLength::value) +> struct PixelTypeSwitch; + +template +struct PixelTypeSwitch +{ + template + bool operator() (int i, F& f) + { + if( i == Index) + { + return f.operator()::type>(); + } + else + { + PixelTypeSwitch next; + return next(i, f); + } + } +}; + +template +struct PixelTypeSwitch +{ + template + bool operator() (int, F&) + { + throw std::out_of_range("Index out of range"); + } +}; + +template +struct AccessItkImageFunctor +{ + + AccessItkImageFunctor(X* cl, mitk::Image::Pointer mitkImage, const T1& t1 = T1(), const T2& t2 = T2(), const T3& t3 = T3()) + : cl(cl), mitkImage(mitkImage), pixelType(mitkImage->GetPixelType()), + t1(t1), t2(t2), t3(t3) + { + mitkImage->Update(); + assert(mitkImage->GetDimension() == VDimension); + } + + template + bool operator() () + { + if (pixelType != typeid(PixelType)) return false; + + typedef itk::Image ImageType; + typedef mitk::ImageToItk ImageToItkType; + itk::SmartPointer imagetoitk = ImageToItkType::New(); + imagetoitk->SetInput(mitkImage); + imagetoitk->Update(); + callMember()(imagetoitk->GetOutput(), cl, t1, t2, t3); + return true; + } + +private: + + template + struct callMember + { + void operator()(ImageType* img, X* cl, A& a, B& b, C& c) { cl->AccessItkImage(img, a, b, c); } + }; + + template + struct callMember + { + void operator()(ImageType* img, X* cl, A& a, B& b, EmptyType&) { cl->AccessItkImage(img, a, b); } + }; + + template + struct callMember + { + void operator()(ImageType* img, X* cl, A& a, EmptyType&, EmptyType&) { cl->AccessItkImage(img, a); } + }; + + template + struct callMember + { + void operator()(ImageType* img, X* cl, EmptyType&, EmptyType&, EmptyType&) { cl->AccessItkImage(img); } + }; + + X* cl; + const mitk::Image::Pointer mitkImage; + const mitk::PixelType& pixelType; + T1 t1; + T2 t2; + T3 t3; +}; + + +} // namespace mitk + diff --git a/Core/Code/Testing/files.cmake b/Core/Code/Testing/files.cmake index f4d4aea409..2ca2ce7b04 100644 --- a/Core/Code/Testing/files.cmake +++ b/Core/Code/Testing/files.cmake @@ -1,91 +1,92 @@ # tests with no extra command line parameter SET(MODULE_TESTS + mitkAccessByItkTest.cpp mitkCoreObjectFactoryTest.cpp mitkPointSetWriterTest.cpp mitkMaterialTest.cpp mitkActionTest.cpp mitkEnumerationPropertyTest.cpp mitkEventTest.cpp mitkFocusManagerTest.cpp mitkGenericPropertyTest.cpp mitkGeometry3DTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkGlobalInteractionTest.cpp mitkImageDataItemTest.cpp #mitkImageMapper2DTest.cpp mitkImageGeneratorTest.cpp mitkBaseDataTest.cpp #mitkImageToItkTest.cpp mitkInteractorTest.cpp mitkITKThreadingTest.cpp # mitkLevelWindowManagerTest.cpp mitkLevelWindowTest.cpp mitkMessageTest.cpp #mitkPipelineSmartPointerCorrectnessTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp mitkPointSetFileIOTest.cpp mitkPointSetTest.cpp mitkPointSetInteractorTest.cpp mitkPropertyListTest.cpp #mitkRegistrationBaseTest.cpp #mitkSegmentationInterpolationTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp mitkStateMachineTest.cpp mitkStateTest.cpp mitkSurfaceTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeSlicedGeometryTest.cpp mitkTransitionTest.cpp mitkUndoControllerTest.cpp mitkVtkWidgetRenderingTest.cpp mitkVerboseLimitedLinearUndoTest.cpp mitkWeakPointerTest.cpp mitkTransferFunctionTest.cpp #mitkAbstractTransformGeometryTest.cpp #mitkPicFileIOTest.cpp mitkStepperTest.cpp itkTotalVariationDenoisingImageFilterTest.cpp mitkRenderingManagerTest.cpp vtkMitkThickSlicesFilterTest.cpp mitkNodePredicateSourceTest.cpp ) # test with image filename as an extra command line parameter SET(MODULE_IMAGE_TESTS mitkSurfaceVtkWriterTest.cpp mitkPicFileWriterTest.cpp #mitkImageSliceSelectorTest.cpp mitkImageTimeSelectorTest.cpp mitkPicFileReaderTest.cpp # mitkVtkPropRendererTest.cpp mitkDataNodeFactoryTest.cpp #mitkSTLFileReaderTest.cpp ) # list of images for which the tests are run SET(MODULE_TESTIMAGES US4DCyl.pic.gz Pic3D.pic.gz Pic2DplusT.pic.gz BallBinary30x30x30.pic.gz binary.stl ball.stl ) SET(MODULE_CUSTOM_TESTS #mitkLabeledImageToSurfaceFilterTest.cpp #mitkExternalToolsTest.cpp mitkDataStorageTest.cpp mitkDataNodeTest.cpp mitkDicomSeriesReaderTest.cpp mitkDICOMLocaleTest.cpp mitkEventMapperTest.cpp mitkNodeDependentPointSetInteractorTest.cpp mitkStateMachineFactoryTest.cpp mitkPointSetLocaleTest.cpp mitkImageTest.cpp mitkImageWriterTest.cpp ) diff --git a/Core/Code/Testing/mitkAccessByItkTest.cpp b/Core/Code/Testing/mitkAccessByItkTest.cpp new file mode 100644 index 0000000000..b96b4a518c --- /dev/null +++ b/Core/Code/Testing/mitkAccessByItkTest.cpp @@ -0,0 +1,370 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision: 17495 $ + +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 "mitkTestingMacros.h" + +#include + +#define assert(a) if(!(a)) throw std::runtime_error("Assertion " #a " failed"); + +#include + +#define TestImageType(type, dim) \ + MITK_TEST_CONDITION(typeid(type) == typeid(TPixel) && dim == VDimension, "Checking for correct type itk::Image<" #type "," #dim ">") + +class AccessByItkTest +{ +public: + + typedef AccessByItkTest Self; + + typedef itk::Image IntImage2D; + typedef itk::Image IntImage3D; + typedef itk::Image FloatImage2D; + typedef itk::Image FloatImage3D; + + enum EImageType { + Unknown = 0, + Int2D, + Int3D, + Float2D, + Float3D + }; + + void testAccessByItk() + { + mitk::Image::Pointer mitkIntImage2D = createMitkImage(); + mitk::Image::Pointer mitkIntImage3D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage2D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage3D = createMitkImage(); + + AccessByItk(mitkIntImage2D, AccessItkImage); + AccessByItk(mitkIntImage3D, AccessItkImage); + AccessByItk(mitkFloatImage2D, AccessItkImage); + AccessByItk(mitkFloatImage3D, AccessItkImage); + + AccessByItk_1(mitkIntImage2D, AccessItkImage, Int2D); + AccessByItk_1(mitkIntImage3D, AccessItkImage, Int3D); + AccessByItk_1(mitkFloatImage2D, AccessItkImage, Float2D); + AccessByItk_1(mitkFloatImage3D, AccessItkImage, Float3D); + + AccessByItk_2(mitkIntImage2D, AccessItkImage, Int2D, 2); + AccessByItk_2(mitkIntImage3D, AccessItkImage, Int3D, 2); + AccessByItk_2(mitkFloatImage2D, AccessItkImage, Float2D, 2); + AccessByItk_2(mitkFloatImage3D, AccessItkImage, Float3D, 2); + + AccessByItk_3(mitkIntImage2D, AccessItkImage, Int2D, 2, 3); + AccessByItk_3(mitkIntImage3D, AccessItkImage, Int3D, 2, 3); + AccessByItk_3(mitkFloatImage2D, AccessItkImage, Float2D, 2, 3); + AccessByItk_3(mitkFloatImage3D, AccessItkImage, Float3D, 2, 3); + } + + void testAccessFixedDimensionByItk() + { + mitk::Image::Pointer mitkIntImage2D = createMitkImage(); + mitk::Image::Pointer mitkIntImage3D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage2D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage3D = createMitkImage(); + + AccessFixedDimensionByItk(mitkIntImage2D, AccessItkImage, 2); + AccessFixedDimensionByItk(mitkIntImage3D, AccessItkImage, 3); + AccessFixedDimensionByItk(mitkFloatImage2D, AccessItkImage, 2); + AccessFixedDimensionByItk(mitkFloatImage3D, AccessItkImage, 3); + + AccessFixedDimensionByItk_1(mitkIntImage2D, AccessItkImage, 2, Int2D); + AccessFixedDimensionByItk_1(mitkIntImage3D, AccessItkImage, 3, Int3D); + AccessFixedDimensionByItk_1(mitkFloatImage2D, AccessItkImage, 2, Float2D); + AccessFixedDimensionByItk_1(mitkFloatImage3D, AccessItkImage, 3, Float3D); + + AccessFixedDimensionByItk_2(mitkIntImage2D, AccessItkImage, 2, Int2D, 2); + AccessFixedDimensionByItk_2(mitkIntImage3D, AccessItkImage, 3, Int3D, 2); + AccessFixedDimensionByItk_2(mitkFloatImage2D, AccessItkImage, 2, Float2D, 2); + AccessFixedDimensionByItk_2(mitkFloatImage3D, AccessItkImage, 3, Float3D, 2); + + AccessFixedDimensionByItk_3(mitkIntImage2D, AccessItkImage, 2, Int2D, 2, 3); + AccessFixedDimensionByItk_3(mitkIntImage3D, AccessItkImage, 3, Int3D, 2, 3); + AccessFixedDimensionByItk_3(mitkFloatImage2D, AccessItkImage, 2, Float2D, 2, 3); + AccessFixedDimensionByItk_3(mitkFloatImage3D, AccessItkImage, 3, Float3D, 2, 3); + + // Test for wrong dimension + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedDimensionByItk(mitkFloatImage3D, AccessItkImage, 2); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedDimensionByItk_1(mitkFloatImage3D, AccessItkImage, 2, Float3D); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedDimensionByItk_2(mitkFloatImage3D, AccessItkImage, 2, Float3D, 2); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedDimensionByItk_3(mitkFloatImage3D, AccessItkImage, 2, Float3D, 2, 3); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + } + + void testAccessFixedPixelTypeByItk() + { + mitk::Image::Pointer mitkIntImage2D = createMitkImage(); + mitk::Image::Pointer mitkIntImage3D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage2D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage3D = createMitkImage(); + + AccessFixedPixelTypeByItk(mitkIntImage2D, AccessItkImage, int); + AccessFixedPixelTypeByItk(mitkIntImage3D, AccessItkImage, int); + AccessFixedPixelTypeByItk(mitkFloatImage2D, AccessItkImage, float); + AccessFixedPixelTypeByItk(mitkFloatImage3D, AccessItkImage, float); + + AccessFixedPixelTypeByItk_1(mitkIntImage2D, AccessItkImage, int, Int2D); + AccessFixedPixelTypeByItk_1(mitkIntImage3D, AccessItkImage, int, Int3D); + AccessFixedPixelTypeByItk_1(mitkFloatImage2D, AccessItkImage, float, Float2D); + AccessFixedPixelTypeByItk_1(mitkFloatImage3D, AccessItkImage, float, Float3D); + + AccessFixedPixelTypeByItk_2(mitkIntImage2D, AccessItkImage, int, Int2D, 2); + AccessFixedPixelTypeByItk_2(mitkIntImage3D, AccessItkImage, int, Int3D, 2); + AccessFixedPixelTypeByItk_2(mitkFloatImage2D, AccessItkImage, float, Float2D, 2); + AccessFixedPixelTypeByItk_2(mitkFloatImage3D, AccessItkImage, float, Float3D, 2); + + AccessFixedPixelTypeByItk_3(mitkIntImage2D, AccessItkImage, int, Int2D, 2, 3); + AccessFixedPixelTypeByItk_3(mitkIntImage3D, AccessItkImage, int, Int3D, 2, 3); + AccessFixedPixelTypeByItk_3(mitkFloatImage2D, AccessItkImage, float, Float2D, 2, 3); + AccessFixedPixelTypeByItk_3(mitkFloatImage3D, AccessItkImage, float, Float3D, 2, 3); + + // Test for wrong dimension + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedPixelTypeByItk(mitkFloatImage3D, AccessItkImage, int); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedPixelTypeByItk_1(mitkFloatImage3D, AccessItkImage, int, Float3D); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedPixelTypeByItk_2(mitkFloatImage3D, AccessItkImage, int, Float3D, 2); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedPixelTypeByItk_3(mitkFloatImage3D, AccessItkImage, int, Float3D, 2, 3); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + } + + void testAccessFixedTypeByItk() + { + mitk::Image::Pointer mitkIntImage2D = createMitkImage(); + mitk::Image::Pointer mitkIntImage3D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage2D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage3D = createMitkImage(); + + AccessFixedTypeByItk(mitkIntImage2D, AccessItkImage, int, 2); + AccessFixedTypeByItk(mitkIntImage3D, AccessItkImage, int, 3); + AccessFixedTypeByItk(mitkFloatImage2D, AccessItkImage, float, 2); + AccessFixedTypeByItk(mitkFloatImage3D, AccessItkImage, float, 3); + + AccessFixedTypeByItk_1(mitkIntImage2D, AccessItkImage, int, 2, Int2D); + AccessFixedTypeByItk_1(mitkIntImage3D, AccessItkImage, int, 3, Int3D); + AccessFixedTypeByItk_1(mitkFloatImage2D, AccessItkImage, float, 2, Float2D); + AccessFixedTypeByItk_1(mitkFloatImage3D, AccessItkImage, float, 3, Float3D); + + AccessFixedTypeByItk_2(mitkIntImage2D, AccessItkImage, int, 2, Int2D, 2); + AccessFixedTypeByItk_2(mitkIntImage3D, AccessItkImage, int, 3, Int3D, 2); + AccessFixedTypeByItk_2(mitkFloatImage2D, AccessItkImage, float, 2, Float2D, 2); + AccessFixedTypeByItk_2(mitkFloatImage3D, AccessItkImage, float, 3, Float3D, 2); + + AccessFixedTypeByItk_3(mitkIntImage2D, AccessItkImage, int, 2, Int2D, 2, 3); + AccessFixedTypeByItk_3(mitkIntImage3D, AccessItkImage, int, 3, Int3D, 2, 3); + AccessFixedTypeByItk_3(mitkFloatImage2D, AccessItkImage, float, 2, Float2D, 2, 3); + AccessFixedTypeByItk_3(mitkFloatImage3D, AccessItkImage, float, 3, Float3D, 2, 3); + + // Test for wrong dimension + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedTypeByItk(mitkFloatImage3D, AccessItkImage, float, 2); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedTypeByItk_1(mitkFloatImage3D, AccessItkImage, float, 2, Float3D); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedTypeByItk_2(mitkFloatImage3D, AccessItkImage, float, 2, Float3D, 2); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedTypeByItk_3(mitkFloatImage3D, AccessItkImage, float, 2, Float3D, 2, 3); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + // Test for wrong type + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedTypeByItk(mitkFloatImage3D, AccessItkImage, int, 3); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedTypeByItk_1(mitkFloatImage3D, AccessItkImage, int, 3, Float3D); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedTypeByItk_2(mitkFloatImage3D, AccessItkImage, int, 3, Float3D, 2); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFixedTypeByItk_3(mitkFloatImage3D, AccessItkImage, int, 3, Float3D, 2, 3); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + } + + void testAccessSpecificPixelTypesByItk() + { + mitk::Image::Pointer mitkIntImage2D = createMitkImage(); + mitk::Image::Pointer mitkIntImage3D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage2D = createMitkImage(); + mitk::Image::Pointer mitkFloatImage3D = createMitkImage(); + + AccessIntegralTypesByItk(mitkIntImage2D); + AccessIntegralTypesByItk(mitkIntImage3D); + AccessIntegralTypesByItk_1(mitkIntImage2D, EImageType, Int2D); + AccessIntegralTypesByItk_1(mitkIntImage3D, EImageType, Int3D); + AccessIntegralTypesByItk_2(mitkIntImage2D, EImageType, Int2D, int, 2); + AccessIntegralTypesByItk_2(mitkIntImage3D, EImageType, Int3D, int, 2); + AccessIntegralTypesByItk_3(mitkIntImage2D, EImageType, Int2D, int, 2, int, 3); + AccessIntegralTypesByItk_3(mitkIntImage3D, EImageType, Int3D, int, 2, int, 3); + + AccessFloatingTypesByItk(mitkFloatImage2D); + AccessFloatingTypesByItk(mitkFloatImage3D); + AccessFloatingTypesByItk_1(mitkFloatImage2D, EImageType, Float2D); + AccessFloatingTypesByItk_1(mitkFloatImage3D, EImageType, Float3D); + AccessFloatingTypesByItk_2(mitkFloatImage2D, EImageType, Float2D, int, 2); + AccessFloatingTypesByItk_2(mitkFloatImage3D, EImageType, Float3D, int, 2); + AccessFloatingTypesByItk_3(mitkFloatImage2D, EImageType, Float2D, int, 2, int, 3); + AccessFloatingTypesByItk_3(mitkFloatImage3D, EImageType, Float3D, int, 2, int, 3); + + AccessSpecificTypesByItk(mitkIntImage2D, short, unsigned int, float, int, char); + AccessSpecificTypesByItk(mitkIntImage3D, short, unsigned int, float, int, char); + AccessSpecificTypesByItk_1(mitkIntImage2D, EImageType, Int2D, short, unsigned int, float, int, char); + AccessSpecificTypesByItk_1(mitkFloatImage3D, EImageType, Float3D, short, unsigned int, float, int, char); + AccessSpecificTypesByItk_2(mitkIntImage2D, EImageType, Int2D, int, 2, short, unsigned int, float, int, char); + AccessSpecificTypesByItk_2(mitkFloatImage3D, EImageType, Float3D, int, 2, short, unsigned int, float, int, char); + AccessSpecificTypesByItk_3(mitkIntImage2D, EImageType, Int2D, int, 2, int, 3, short, unsigned int, float, int, char); + AccessSpecificTypesByItk_3(mitkFloatImage3D, EImageType, Float3D, int, 2, int, 3, short, unsigned int, float, int, char); + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessIntegralTypesByItk(mitkFloatImage3D); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessIntegralTypesByItk_1(mitkFloatImage3D, EImageType, Float3D); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessIntegralTypesByItk_2(mitkFloatImage2D, EImageType, Float2D, int, 2); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessIntegralTypesByItk_3(mitkFloatImage3D, EImageType, Float3D, int, 2, int, 3); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFloatingTypesByItk(mitkIntImage3D); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFloatingTypesByItk_1(mitkIntImage3D, EImageType, Int3D); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFloatingTypesByItk_2(mitkIntImage2D, EImageType, Int2D, int, 2); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessFloatingTypesByItk_3(mitkIntImage3D, EImageType, Int3D, int, 2, int, 3); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessSpecificTypesByItk(mitkIntImage3D, float, double, short); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessSpecificTypesByItk_1(mitkIntImage3D, EImageType, Int3D, float, double, short); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessSpecificTypesByItk_2(mitkIntImage2D, EImageType, Int2D, int, 2, float, double, short); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + MITK_TEST_FOR_EXCEPTION_BEGIN(const std::runtime_error&) + AccessSpecificTypesByItk_3(mitkIntImage3D, EImageType, Int3D, int, 2, int, 3, float, double, short); + MITK_TEST_FOR_EXCEPTION_END(const std::runtime_error&) + } + + template + void AccessItkImage(itk::Image* itkImage, + EImageType param1 = Unknown, int param2 = 0, int param3 = 0) + { + switch (param1) + { + case Int2D: TestImageType(int , 2) break; + case Int3D: TestImageType(int, 3) break; + case Float2D: TestImageType(float, 2) break; + case Float3D: TestImageType(float, 3) break; + } + + if (param2) + { + MITK_TEST_CONDITION(param2 == 2, "Checking for correct second parameter") + } + if (param3) + { + MITK_TEST_CONDITION(param3 == 3, "Checking for correct third parameter") + } + } + + private: + + template + mitk::Image::Pointer createMitkImage() + { + typename ImageType::Pointer itkImage = ImageType::New(); + typename ImageType::IndexType start; + start.Fill(0); + typename ImageType::SizeType size; + size.Fill(3); + typename ImageType::RegionType region; + region.SetSize(size); + region.SetIndex(start); + itkImage->SetRegions(region); + itkImage->Allocate(); + return mitk::GrabItkImageMemory(itkImage); + } +}; + +int mitkAccessByItkTest(int /*argc*/, char* /*argv*/[]) +{ + + // MITK_TEST_BEGIN("AccessByItk") + + AccessByItkTest accessTest; + + MITK_TEST_OUTPUT(<< "Testing AccessByItk macro") + accessTest.testAccessByItk(); + + MITK_TEST_OUTPUT(<< "Testing AccessFixedDimensionByItk macro") + accessTest.testAccessFixedDimensionByItk(); + + MITK_TEST_OUTPUT(<< "Testing AccessFixedTypeByItk macro") + accessTest.testAccessFixedTypeByItk(); + + MITK_TEST_OUTPUT(<< "Testing AccessFixedPixelTypeByItk macro") + accessTest.testAccessFixedPixelTypeByItk(); + + MITK_TEST_OUTPUT(<< "Testing AccessSpecificPixelTypesByItk macro") + accessTest.testAccessSpecificPixelTypesByItk(); + +// MITK_TEST_END() + + return 0; +}