ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkPyBuffer.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 itkPyBuffer_h
20 #define itkPyBuffer_h
21 
22 #include "itkObject.h"
23 #include "itkObjectFactory.h"
24 #include "itkImportImageFilter.h"
26 
27 
28 // The python header defines _POSIX_C_SOURCE without a preceding #undef
29 #undef _POSIX_C_SOURCE
30 #undef _XOPEN_SOURCE
31 // For Python 2.7 hypot bug, see https://bugs.python.org/issue11566
32 #include "PatchedPython27pyconfig.h"
33 #include <Python.h>
34 
35 namespace itk
36 {
37 
48 template <typename TImage>
49 class PyBuffer
50 {
51 public:
53  using Self = PyBuffer;
54 
56  using ImageType = TImage;
57  using PixelType = typename ImageType::PixelType;
58  using SizeType = typename ImageType::SizeType;
59  using IndexType = typename ImageType::IndexType;
61  using PointType = typename ImageType::PointType;
62  using SpacingType = typename ImageType::SpacingType;
63  using ImagePointer = typename ImageType::Pointer;
65 
67  static constexpr unsigned int ImageDimension = ImageType::ImageDimension;
68 
70 
74  static PyObject * _GetArrayViewFromImage( ImageType * image);
75 
79  static const OutputImagePointer _GetImageViewFromArray( PyObject *arr, PyObject *shape, PyObject *numOfComponent);
80 
81 protected:
82 
83 private:
84  PyBuffer(const Self&); // Purposely not implemented.
85  void operator=(const Self&); // Purposely not implemented.
86 };
87 
88 } // namespace itk
89 
90 #ifndef ITK_MANUAL_INSTANTIATION
91 #include "itkPyBuffer.hxx"
92 #endif
93 
94 #endif // _itkPyBuffer_h
typename Image< ComponentType, ImageDimension >::Pointer OutputImagePointer
Definition: itkPyBuffer.h:69
typename ImageType::SpacingType SpacingType
Definition: itkPyBuffer.h:62
void operator=(const Self &)
static constexpr unsigned int ImageDimension
Definition: itkPyBuffer.h:67
typename ImageType::RegionType RegionType
Definition: itkPyBuffer.h:60
static PyObject * _GetArrayViewFromImage(ImageType *image)
static const OutputImagePointer _GetImageViewFromArray(PyObject *arr, PyObject *shape, PyObject *numOfComponent)
typename ImageType::Pointer ImagePointer
Definition: itkPyBuffer.h:63
PyBuffer(const Self &)
typename ImageType::SizeType SizeType
Definition: itkPyBuffer.h:58
typename ImageType::PointType PointType
Definition: itkPyBuffer.h:61
typename DefaultConvertPixelTraits< PixelType >::ComponentType ComponentType
Definition: itkPyBuffer.h:64
TImage ImageType
Definition: itkPyBuffer.h:56
Helper class to get ITK image views into python arrays and back.
Definition: itkPyBuffer.h:49
typename ImageType::PixelType PixelType
Definition: itkPyBuffer.h:57
typename ImageType::IndexType IndexType
Definition: itkPyBuffer.h:59
typename PixelType::ComponentType ComponentType