ITK  6.0.0
Insight Toolkit
itkPyImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef itkPyImageFilter_h
20 #define itkPyImageFilter_h
21 
22 #include "itkImageToImageFilter.h"
23 
24 // The python header defines _POSIX_C_SOURCE without a preceding #undef
25 #undef _POSIX_C_SOURCE
26 #undef _XOPEN_SOURCE
27 #include "Python.h"
28 
29 namespace itk
30 {
31 
41 template <class TInputImage, class TOutputImage>
42 class ITK_TEMPLATE_EXPORT PyImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
43 {
44 public:
45  ITK_DISALLOW_COPY_AND_MOVE(PyImageFilter);
46 
52 
54  itkNewMacro(Self);
55 
57  itkOverrideGetNameOfClassMacro(PyImageFilter);
58 
60  using InputImageType = TInputImage;
63  using InputImagePixelType = typename InputImageType::PixelType;
64  using OutputImageType = TOutputImage;
67  using OutputImagePixelType = typename OutputImageType::PixelType;
68 
70  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
71  static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
72 
76  void
77  SetPyGenerateInputRequestedRegion(PyObject * obj);
78 
82  void
83  SetPyGenerateOutputInformation(PyObject * obj);
84 
88  void
89  SetPyEnlargeOutputRequestedRegion(PyObject * obj);
90 
94  void
95  SetPyGenerateData(PyObject * obj);
96 
98  void
99  _SetSelf(PyObject * self)
100  {
101  this->m_Self = self;
102  }
103 
104 protected:
105  PyImageFilter();
106  virtual ~PyImageFilter();
107 
108  void
109  GenerateInputRequestedRegion() override;
110 
111  void
112  GenerateOutputInformation() override;
113 
114  void
115  EnlargeOutputRequestedRegion(DataObject * dataObject) override;
116 
117  void
118  GenerateData() override;
119 
120 private:
121  PyObject * m_Self;
122  PyObject * m_GenerateInputRequestedRegionCallable{ nullptr };
123  PyObject * m_GenerateOutputInformationCallable{ nullptr };
124  PyObject * m_EnlargeOutputRequestedRegionCallable{ nullptr };
125  PyObject * m_GenerateDataCallable{ nullptr };
126 };
127 
128 } // end namespace itk
129 
130 
131 #ifndef ITK_MANUAL_INSTANTIATION
132 # include "itkPyImageFilter.hxx"
133 #endif
134 
135 #endif // _itkPyImageFilter_h
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::ImageSource::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkImageSource.h:91
itk::PyImageFilter
ImageToImageFilter subclass that calls a Python callable object, e.g. a Python function or a class wi...
Definition: itkPyImageFilter.h:42
itk::PyImageFilter::m_Self
PyObject * m_Self
Definition: itkPyImageFilter.h:121
itk::SmartPointer< Self >
itk::ImageToImageFilter::InputImagePixelType
typename InputImageType::PixelType InputImagePixelType
Definition: itkImageToImageFilter.h:133
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::ImageToImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkImageToImageFilter.h:130
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itkImageToImageFilter.h
itk::PyImageFilter::_SetSelf
void _SetSelf(PyObject *self)
Definition: itkPyImageFilter.h:99
itk::ImageSource::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::ImageSource::OutputImagePixelType
typename OutputImageType::PixelType OutputImagePixelType
Definition: itkImageSource.h:93
itk::ImageToImageFilter::InputImageRegionType
typename InputImageType::RegionType InputImageRegionType
Definition: itkImageToImageFilter.h:132
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293