Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
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 IMAGETOITK_H_HEADER_INCLUDED_C1C2FCD2
14 #define IMAGETOITK_H_HEADER_INCLUDED_C1C2FCD2
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  {
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  {
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 // IMAGETOITK_H_HEADER_INCLUDED_C1C2FCD2
TOutputImage::SizeType SizeType
ImageTypeTrait< TPixel, VDimension >::ImageType::Pointer ImageToItkImage(mitk::Image *mitkImage)
Convert a MITK image to an ITK image.
TOutputImage::RegionType RegionType
~ImageToItk() override
void GenerateData() override
itk::Image< unsigned char, 3 > ImageType
itk::SmartPointer< const Self > ConstPointer
TOutputImage::InternalPixelType InternalPixelType
DataCollection - Class to facilitate loading/accessing structured data.
mitk::Image InputImageType
itk::Image< TPixelType, VDimension > ImageType
mitk::Image * GetInput(void)
void GenerateOutputInformation() override
InputImageType::Pointer InputImagePointer
mitk::Image::Pointer m_MitkImage
itk::SmartPointer< Self > Pointer
itk::ImageRegion< RegionDimension > RegionType
Image class for storing images.
Definition: mitkImage.h:72
TOutputImage::PixelType PixelType
mitk::ImageDataItem::Pointer m_ImageDataItem
void PrintSelf(std::ostream &os, itk::Indent indent) const override
mitk::Image::Pointer image
TOutputImage::IndexType IndexType
void UpdateOutputInformation() override
TOutputImage::PixelContainer PixelContainer
virtual void SetInput(mitk::Image *input)
InputImageType::ConstPointer InputImageConstPointer
SlicedData::RegionType InputImageRegionType
itk::ImageSource< TOutputImage > Superclass
Superclass::OutputImageRegionType OutputImageRegionType