a
    «ˆcv  ã                   @   sÀ   d Z ddlZddlm  mZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ ddl	mZ ddl	mZ dd	l	mZ dd
l	mZ ddl	mZ ddl	mZ ddl	mZ ddl	mZ G dd„ dƒZdS )aA  
vtkImageExportToArray - a NumPy front-end to vtkImageExport

This class converts a VTK image to a numpy array.  The output
array will always have 3 dimensions (or 4, if the image had
multiple scalar components).

To use this class, you must have numpy installed (http://numpy.scipy.org)

Methods

  SetInputConnection(vtkAlgorithmOutput) -- connect to VTK image pipeline
  SetInputData(vtkImageData) -- set an vtkImageData to export
  GetArray() -- execute pipeline and return a numpy array

Methods from vtkImageExport

  GetDataExtent()
  GetDataSpacing()
  GetDataOrigin()
é    N)ÚvtkImageExport)Ú vtkStreamingDemandDrivenPipeline)ÚVTK_SIGNED_CHAR)ÚVTK_UNSIGNED_CHAR)Ú	VTK_SHORT)ÚVTK_UNSIGNED_SHORT)ÚVTK_INT)ÚVTK_UNSIGNED_INT)ÚVTK_LONG)ÚVTK_UNSIGNED_LONG)Ú	VTK_FLOAT)Ú
VTK_DOUBLEc                   @   s´   e Zd Zdd„ Zededededede	de
d	ed
iZededededede	de
dediZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%S )&ÚvtkImageExportToArrayc                 C   s   t ƒ | _d| _d S ©NF)r   Ú_vtkImageExportToArray__exportÚ1_vtkImageExportToArray__ConvertUnsignedShortToInt©Úself© r   úh/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/vtkmodules/util/vtkImageExportToArray.pyÚ__init__)   s    zvtkImageExportToArray.__init__ÚbÚBÚhÚHÚiÚIÚfÚdé   é   é   é   c                 C   s
   || _ d S ©N©r   )r   Zyesnor   r   r   ÚSetConvertUnsignedShortToIntB   s    z2vtkImageExportToArray.SetConvertUnsignedShortToIntc                 C   s   | j S r#   r$   r   r   r   r   ÚGetConvertUnsignedShortToIntE   s    z2vtkImageExportToArray.GetConvertUnsignedShortToIntc                 C   s
   d| _ d S )NTr$   r   r   r   r   ÚConvertUnsignedShortToIntOnH   s    z1vtkImageExportToArray.ConvertUnsignedShortToIntOnc                 C   s
   d| _ d S r   r$   r   r   r   r   ÚConvertUnsignedShortToIntOffK   s    z2vtkImageExportToArray.ConvertUnsignedShortToIntOffc                 C   s   | j  |¡S r#   )r   ÚSetInputConnection©r   Úinputr   r   r   r)   O   s    z(vtkImageExportToArray.SetInputConnectionc                 C   s   | j  |¡S r#   )r   ÚSetInputDatar*   r   r   r   r,   R   s    z"vtkImageExportToArray.SetInputDatac                 C   s
   | j  ¡ S r#   )r   ÚGetInputr   r   r   r   r-   U   s    zvtkImageExportToArray.GetInputc                 C   sº   | j  ¡  | j  ¡ }| ¡ }| ¡ }| ¡ }|d |d  d |d |d  d |d |d  d f}|dkrx||f }t || j| ¡}| j  	|¡ |t
kr¶| jr¶t | d¡d¡}|S )	Né   r!   r   é   r    r   r   iÿÿ  )r   ZUpdater-   Z	GetExtentZGetScalarTypeZGetNumberOfScalarComponentsÚnumpyÚzerosÚ _vtkImageExportToArray__typeDictZExportr   r   ÚumathZbitwise_andZastype)r   r+   ZextentÚtypeZnumComponentsZdimZimArrayr   r   r   ÚGetArrayX   s     

þ
zvtkImageExportToArray.GetArrayc                 C   s
   | j  ¡ S r#   )r   ÚGetDataExtentr   r   r   r   r6   m   s    z#vtkImageExportToArray.GetDataExtentc                 C   s
   | j  ¡ S r#   )r   ÚGetDataSpacingr   r   r   r   r7   p   s    z$vtkImageExportToArray.GetDataSpacingc                 C   s
   | j  ¡ S r#   )r   ÚGetDataOriginr   r   r   r   r8   s   s    z#vtkImageExportToArray.GetDataOriginN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r	   r   r   r2   Z _vtkImageExportToArray__sizeDictr%   r&   r'   r(   r)   r,   r-   r5   r6   r7   r8   r   r   r   r   r   (   s<   ù	ù
r   )Ú__doc__r0   Znumpy.core.umathÚcorer3   Zvtkmodules.vtkIOImager   Z"vtkmodules.vtkCommonExecutionModelr   Zvtkmodules.vtkCommonCorer   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   Ú<module>   s   