1 /*===================================================================
3 The Medical Imaging Interaction Toolkit (MITK)
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 See LICENSE.txt or http://www.mitk.org for details.
15 ===================================================================*/
17 #include <mitkImageAccessByItk.h>
18 #include <mitkImageCast.h>
20 #include <itkCastImageFilter.h>
27 template <typename ItkOutputImageType>
28 void CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer<ItkOutputImageType> &itkOutputImage)
30 AccessFixedDimensionByItk_1(mitkImage, _CastToItkImage2Access, ItkOutputImageType::ImageDimension, itkOutputImage);
33 template <typename TPixelType, unsigned int VImageDimension>
34 void CastToItkImage(const mitk::Image *mitkImage,
35 itk::SmartPointer<itk::VectorImage<TPixelType, VImageDimension>> &itkOutputImage)
37 AccessVectorFixedDimensionByItk_n(mitkImage, _CastToItkImage2Access, VImageDimension, (itkOutputImage));
40 template <typename TPixel, unsigned int VImageDimension, class ItkOutputImageType>
41 void _CastToItkImage2Access(const itk::Image<TPixel, VImageDimension> *itkInputImage,
42 itk::SmartPointer<ItkOutputImageType> &itkOutputImage)
44 typedef itk::Image<TPixel, VImageDimension> ItkInputImageType;
45 if (typeid(ItkInputImageType) == typeid(ItkOutputImageType))
47 itkOutputImage = const_cast<ItkOutputImageType *>(reinterpret_cast<const ItkOutputImageType *>(itkInputImage));
50 typedef itk::CastImageFilter<ItkInputImageType, ItkOutputImageType> CastImageFilterType;
51 typename CastImageFilterType::Pointer castImageFilter = CastImageFilterType::New();
52 castImageFilter->SetInput(itkInputImage);
53 castImageFilter->Update();
54 itkOutputImage = castImageFilter->GetOutput();
57 template <typename TPixel, unsigned int VImageDimension, class ItkOutputImageType>
58 void _CastToItkImage2Access(const itk::VectorImage<TPixel, VImageDimension> *itkInputImage,
59 itk::SmartPointer<ItkOutputImageType> &itkOutputImage)
61 typedef itk::VectorImage<TPixel, VImageDimension> ItkInputImageType;
62 if (typeid(ItkInputImageType) == typeid(ItkOutputImageType))
64 itkOutputImage = const_cast<ItkOutputImageType *>(reinterpret_cast<const ItkOutputImageType *>(itkInputImage));
67 typedef itk::CastImageFilter<ItkInputImageType, ItkOutputImageType> CastImageFilterType;
68 typename CastImageFilterType::Pointer castImageFilter = CastImageFilterType::New();
69 castImageFilter->SetInput(itkInputImage);
70 castImageFilter->Update();
71 itkOutputImage = castImageFilter->GetOutput();
74 #endif // DOXYGEN_SKIP