00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 00019 #ifndef MITKITKIMAGEIMPORT_H_HEADER_INCLUDED_C1E4861D 00020 #define MITKITKIMAGEIMPORT_H_HEADER_INCLUDED_C1E4861D 00021 00022 #include "mitkCommon.h" 00023 #include "mitkImageSource.h" 00024 #include "itkImageToImageFilterDetail.h" 00025 00026 namespace mitk { 00027 00028 //##Documentation 00029 //## @brief Pipelined import of itk::Image 00030 //## 00031 //## The image data contained in the itk::Image is referenced, 00032 //## not copied. 00033 //## The easiest way of use is by the function 00034 //## mitk::ImportItkImage 00035 //## \code 00036 //## mitkImage = mitk::ImportItkImage(itkImage); 00037 //## \endcode 00038 //## \sa ImportItkImage 00039 //## @ingroup Adaptor 00040 template <class TInputImage> 00041 class MITK_EXPORT ITKImageImport : public ImageSource 00042 { 00043 public: 00044 mitkClassMacro(ITKImageImport,ImageSource); 00045 00046 itkNewMacro(Self); 00047 00048 //##Documentation 00049 //## \brief The type of the input image. 00050 typedef TInputImage InputImageType; 00051 typedef typename InputImageType::Pointer InputImagePointer; 00052 typedef typename InputImageType::ConstPointer InputImageConstPointer; 00053 typedef typename InputImageType::RegionType InputImageRegionType; 00054 typedef typename InputImageType::PixelType InputImagePixelType; 00055 00057 itkStaticConstMacro(InputImageDimension, unsigned int, 00058 TInputImage::ImageDimension); 00059 itkStaticConstMacro(RegionDimension, unsigned int, 00060 mitk::SlicedData::RegionDimension); 00061 00062 //##Documentation 00063 //## \brief Set the input itk::Image of this image importer. 00064 InputImageType * GetInput(void); 00065 00066 //##Documentation 00067 //## \brief Set the input itk::Image of this image importer. 00068 void SetInput(const InputImageType*); 00069 00070 //##Documentation 00071 //## \brief Set the Geometry of the result image (optional) 00072 //## 00073 //## The Geometry has to fit the dimension and size of 00074 //## the input image. The Geometry will be cloned, not 00075 //## referenced! 00076 //## 00077 //## Providing the Geometry is optional. 00078 //## The default behavior is to set the geometry by 00079 //## the itk::Image::GetDirection() information. 00080 void SetGeometry(const Geometry3D* geometry); 00081 00082 protected: 00083 ITKImageImport(); 00084 00085 virtual ~ITKImageImport(); 00086 00087 virtual void GenerateOutputInformation(); 00088 00089 virtual void GenerateInputRequestedRegion(); 00090 00091 virtual void GenerateData(); 00092 00093 virtual void SetNthOutput(unsigned int num, itk::DataObject *output); 00094 00097 typedef itk::ImageToImageFilterDetail::ImageRegionCopier<itkGetStaticConstMacro(InputImageDimension), 00098 itkGetStaticConstMacro(RegionDimension)> OutputToInputRegionCopierType; 00099 00100 Geometry3D::Pointer m_Geometry; 00101 }; 00102 00103 //##Documentation 00104 //## @brief Imports an itk::Image (with a specific type) as an mitk::Image. 00105 //## @ingroup Adaptor 00106 //## 00107 //## Instantiates instance of ITKImageImport. 00108 //## mitk::ITKImageImport does not cast pixel types etc., it just imports 00109 //## image data. If you get a compile error, try image.GetPointer(). 00110 //## 00111 //## \param update: if \a true, fill mitk::Image, which will execute the 00112 //## up-stream pipeline connected to the input itk::Image. Otherwise you 00113 //## need to make sure that Update() is called on the mitk::Image before 00114 //## its data is being used, e.g., by connecting it to an mitk-pipeline 00115 //## and call Update of a downstream filter at some time. 00116 //## \sa itk::Image::CastToMitkImage 00117 template <typename ItkOutputImageType> 00118 Image::Pointer ImportItkImage(const itk::SmartPointer<ItkOutputImageType>& itkimage, const Geometry3D* geometry = NULL, bool update = true); 00119 00120 //##Documentation 00121 //## @brief Imports an itk::Image (with a specific type) as an mitk::Image. 00122 //## @ingroup Adaptor 00123 //## 00124 //## Instantiates instance of ITKImageImport 00125 //## mitk::ITKImageImport does not cast pixel types etc., it just imports 00126 //## image data. If you get a compile error, try image.GetPointer(). 00127 //## 00128 //## \param update: if \a true, fill mitk::Image, which will execute the 00129 //## up-stream pipeline connected to the input itk::Image. Otherwise you 00130 //## need to make sure that Update() is called on the mitk::Image before 00131 //## its data is being used, e.g., by connecting it to an mitk-pipeline 00132 //## and call Update of a downstream filter at some time. 00133 //## \sa itk::Image::CastToMitkImage 00134 //## \sa GrabItkImageMemory 00135 template <typename ItkOutputImageType> 00136 Image::Pointer ImportItkImage(const ItkOutputImageType* itkimage, const Geometry3D* geometry = NULL, bool update = true); 00137 00138 //##Documentation 00139 //## @brief Grabs the memory of an itk::Image (with a specific type) 00140 //## and puts it into an mitk::Image. 00141 //## @ingroup Adaptor 00142 //## 00143 //## The memory is managed by the mitk::Image after calling this 00144 //## function. The itk::Image remains valid until the mitk::Image 00145 //## decides to free the memory. 00146 //## \param update: if \a true, fill mitk::Image, which will execute the 00147 //## up-stream pipeline connected to the input itk::Image. Otherwise you 00148 //## need to make sure that Update() is called on the mitk::Image before 00149 //## its data is being used, e.g., by connecting it to an mitk-pipeline 00150 //## and call Update of a downstream filter at some time. 00151 //## \sa ImportItkImage 00152 template <typename ItkOutputImageType> 00153 Image::Pointer GrabItkImageMemory(itk::SmartPointer<ItkOutputImageType>& itkimage, mitk::Image* mitkImage = NULL, const Geometry3D* geometry = NULL, bool update = true); 00154 00155 //##Documentation 00156 //## @brief Grabs the memory of an itk::Image (with a specific type) 00157 //## and puts it into an mitk::Image. 00158 //## @ingroup Adaptor 00159 //## 00160 //## The memory is managed by the mitk::Image after calling this 00161 //## function. The itk::Image remains valid until the mitk::Image 00162 //## decides to free the memory. 00163 //## \param update: if \a true, fill mitk::Image, which will execute the 00164 //## up-stream pipeline connected to the input itk::Image. Otherwise you 00165 //## need to make sure that Update() is called on the mitk::Image before 00166 //## its data is being used, e.g., by connecting it to an mitk-pipeline 00167 //## and call Update of a downstream filter at some time. 00168 //## \sa ImportItkImage 00169 template <typename ItkOutputImageType> 00170 Image::Pointer GrabItkImageMemory(ItkOutputImageType* itkimage, mitk::Image* mitkImage = NULL, const Geometry3D* geometry = NULL, bool update = true); 00171 00172 } // namespace mitk 00173 00174 #ifndef MITK_MANUAL_INSTANTIATION 00175 #include "mitkITKImageImport.txx" 00176 #endif 00177 00178 #endif /* MITKITKIMAGEIMPORT_H_HEADER_INCLUDED_C1E4861D */