Medical Imaging Interaction Toolkit  2023.12.99-63768887
Medical Imaging Interaction Toolkit
mitkImageToItk.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkImageToItk_h
14 #define mitkImageToItk_h
15 
16 #include "mitkImage.h"
17 #include "mitkImageDataItem.h"
18 #include "mitkImageWriteAccessor.h"
19 
20 #include <itkImage.h>
21 #include <itkImageSource.h>
22 
23 namespace mitk
24 {
32  template <class TOutputImage>
33  class ImageToItk : public itk::ImageSource<TOutputImage>
34  {
35  protected:
38 
39  public:
40  typedef ImageToItk Self;
41  typedef itk::ImageSource<TOutputImage> Superclass;
44 
46  itkFactorylessNewMacro(Self);
47  itkCloneMacro(Self);
48 
50  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
51 
57  typedef typename TOutputImage::SizeType SizeType;
58  typedef typename TOutputImage::IndexType IndexType;
59  typedef typename TOutputImage::RegionType RegionType;
60  typedef typename TOutputImage::PixelType PixelType;
61  typedef typename TOutputImage::InternalPixelType InternalPixelType;
62  typedef typename TOutputImage::PixelContainer PixelContainer;
63 
64  virtual void SetInput(mitk::Image *input);
65  virtual void SetInput(const mitk::Image *input);
66  // virtual void SetInput(unsigned int index, mitk::Image * image);
67  // virtual void SetInput(unsigned int index, const mitk::Image * image);
68 
69  void UpdateOutputInformation() override;
70 
71  itkGetMacro(Channel, int);
72  itkSetMacro(Channel, int);
73 
74  itkSetMacro(CopyMemFlag, bool);
75  itkGetMacro(CopyMemFlag, bool);
76  itkBooleanMacro(CopyMemFlag);
77 
78  itkSetMacro(Options, int);
79  itkGetMacro(Options, int);
80 
81  protected:
82  using itk::ProcessObject::SetInput;
83  mitk::Image *GetInput(void);
84  const mitk::Image *GetInput() const;
85 
86  ImageToItk() : m_CopyMemFlag(false), m_Channel(0), m_Options(mitk::ImageAccessorBase::DefaultBehavior) {}
87  ~ImageToItk() override {}
88  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
89 
90  void GenerateData() override;
91 
92  void GenerateOutputInformation() override;
93 
94  private:
95  bool m_CopyMemFlag;
96  int m_Channel;
97  int m_Options;
98 
99  bool m_ConstInput;
100 
101  // ImageToItk(const Self&); //purposely not implemented
102  void operator=(const Self &); // purposely not implemented
103 
104  void CheckInput(const mitk::Image *image) const;
105  };
106 
131  template <typename TPixel, unsigned int VDimension>
133  {
134  typedef typename ImageTypeTrait<TPixel, VDimension>::ImageType ImageType;
135  typedef mitk::ImageToItk<ImageType> ImageToItkType;
136  itk::SmartPointer<ImageToItkType> imagetoitk = ImageToItkType::New();
137  imagetoitk->SetInput(mitkImage);
138  imagetoitk->Update();
139  return imagetoitk->GetOutput();
140  }
141 
166  template <typename TPixel, unsigned int VDimension>
168  {
169  typedef typename ImageTypeTrait<TPixel, VDimension>::ImageType ImageType;
170  typedef mitk::ImageToItk<ImageType> ImageToItkType;
171  itk::SmartPointer<ImageToItkType> imagetoitk = ImageToItkType::New();
172  imagetoitk->SetInput(mitkImage);
173  imagetoitk->Update();
174  return imagetoitk->GetOutput();
175  }
176 
177 } // end namespace mitk
178 
179 #ifndef ITK_MANUAL_INSTANTIATION
180 #include "mitkImageToItk.txx"
181 #endif
182 
183 #endif
mitk::ImageToItk::SizeType
TOutputImage::SizeType SizeType
Definition: mitkImageToItk.h:57
mitk::ImageToItk::InputImagePointer
InputImageType::Pointer InputImagePointer
Definition: mitkImageToItk.h:54
mitk::ImageToItk::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: mitkImageToItk.h:43
mitk::ImageToItk::InputImageType
mitk::Image InputImageType
Definition: mitkImageToItk.h:53
mitkImage.h
mitk::ImageToItk::Self
ImageToItk Self
Definition: mitkImageToItk.h:40
mitk::ImageToItk::ImageToItk
ImageToItk()
Definition: mitkImageToItk.h:86
mitk::ImageToItk::Pointer
itk::SmartPointer< Self > Pointer
Definition: mitkImageToItk.h:42
mitk::ImageToItk::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
mitk::ImageToItk::Superclass
itk::ImageSource< TOutputImage > Superclass
Definition: mitkImageToItk.h:41
mitk::ImageAccessorBase
Definition: mitkImageAccessorBase.h:48
mitk::ImageToItk::OutputImageRegionType
Superclass::OutputImageRegionType OutputImageRegionType
Definition: mitkImageToItk.h:47
mitk::Image
Image class for storing images.
Definition: mitkImage.h:69
mitk::ImageToItk::IndexType
TOutputImage::IndexType IndexType
Definition: mitkImageToItk.h:58
itk::SmartPointer< Self >
mitk::SlicedData::RegionType
itk::ImageRegion< RegionDimension > RegionType
Definition: mitkSlicedData.h:45
mitkImageWriteAccessor.h
mitk::ImageToItk::GetInput
mitk::Image * GetInput(void)
mitk::ImageToItk::m_MitkImage
mitk::Image::Pointer m_MitkImage
Definition: mitkImageToItk.h:36
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::ImageTypeTrait::ImageType
itk::Image< TPixelType, VDimension > ImageType
Definition: mitkPixelTypeTraits.h:108
mitk::ImageToItk::GenerateData
void GenerateData() override
mitk::ImageToItk::InternalPixelType
TOutputImage::InternalPixelType InternalPixelType
Definition: mitkImageToItk.h:61
mitk::ImageToItk::InputImageRegionType
SlicedData::RegionType InputImageRegionType
Definition: mitkImageToItk.h:56
mitk::ImageToItk::~ImageToItk
~ImageToItk() override
Definition: mitkImageToItk.h:87
mitkImageDataItem.h
mitk::ImageToItk::PixelType
TOutputImage::PixelType PixelType
Definition: mitkImageToItk.h:60
mitk::ImageToItk::SetInput
virtual void SetInput(mitk::Image *input)
mitk::ImageToItkImage
ImageTypeTrait< TPixel, VDimension >::ImageType::Pointer ImageToItkImage(mitk::Image *mitkImage)
Convert a MITK image to an ITK image.
Definition: mitkImageToItk.h:132
mitk::ImageToItk::InputImageConstPointer
InputImageType::ConstPointer InputImageConstPointer
Definition: mitkImageToItk.h:55
mitk::ImageToItk::RegionType
TOutputImage::RegionType RegionType
Definition: mitkImageToItk.h:59
mitk::ImageToItk::PixelContainer
TOutputImage::PixelContainer PixelContainer
Definition: mitkImageToItk.h:62
mitk::ImageTypeTrait
Definition: mitkPixelTypeTraits.h:106
mitk::ImageToItk
Definition: mitkImageToItk.h:33
mitk::ImageToItk::m_ImageDataItem
mitk::ImageDataItem::Pointer m_ImageDataItem
Definition: mitkImageToItk.h:37
mitk::ImageToItk::GenerateOutputInformation
void GenerateOutputInformation() override
mitk::ImageToItk::UpdateOutputInformation
void UpdateOutputInformation() override