ITK  4.13.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  typedef PyBuffer Self;
54 
56  typedef TImage ImageType;
57  typedef typename ImageType::PixelType PixelType;
58  typedef typename ImageType::SizeType SizeType;
59  typedef typename ImageType::IndexType IndexType;
60  typedef typename ImageType::RegionType RegionType;
61  typedef typename ImageType::PointType PointType;
62  typedef typename ImageType::SpacingType SpacingType;
63  typedef typename ImageType::Pointer ImagePointer;
65 
67  itkStaticConstMacro(ImageDimension, unsigned int, 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
void operator=(const Self &)
ImageType::RegionType RegionType
Definition: itkPyBuffer.h:60
static PyObject * _GetArrayViewFromImage(ImageType *image)
static const OutputImagePointer _GetImageViewFromArray(PyObject *arr, PyObject *shape, PyObject *numOfComponent)
ImageType::PointType PointType
Definition: itkPyBuffer.h:61
PyBuffer(const Self &)
PyBuffer Self
Definition: itkPyBuffer.h:53
DefaultConvertPixelTraits< PixelType >::ComponentType ComponentType
Definition: itkPyBuffer.h:64
static const unsigned int ImageDimension
Definition: itkPyBuffer.h:67
TImage ImageType
Definition: itkPyBuffer.h:56
ImageType::SizeType SizeType
Definition: itkPyBuffer.h:58
Helper class to get ITK image views into python arrays and back.
Definition: itkPyBuffer.h:49
ImageType::Pointer ImagePointer
Definition: itkPyBuffer.h:63
ImageType::PixelType PixelType
Definition: itkPyBuffer.h:57
Image< ComponentType, ImageDimension >::Pointer OutputImagePointer
Definition: itkPyBuffer.h:69
ImageType::IndexType IndexType
Definition: itkPyBuffer.h:59
ImageType::SpacingType SpacingType
Definition: itkPyBuffer.h:62