B
    	Z\+                 @   s   d Z ddlmZmZmZ ddlmZ ddlmZm	Z	 da
dd Zd	Zed
 ZG dd deZdZedededZee dS )z, Storage of image data in multiple formats.
    )absolute_importprint_functiondivision   )formats)Format
has_moduleNc               C   sh   ydd l atjatjaW nJ tk
rb   ydd latjatj	aW n tk
r\   tdY nX Y nX tS )Nr   zitk could not be found. Please try   python -m pip install itk or   python -m pip install simpleitk or refer to   https://itkpythonpackage.readthedocs.io/ for further instructions.)
itk_itkZimread_read_functionZimwrite_write_functionImportError	SimpleITKZ	ReadImageZ
WriteImage r   r   8lib/python3.7/site-packages/imageio/plugins/simpleitk.pyload_lib   s    

	r   )z.giplz.iplz.mhaz.mhdz.nhdrZniaZhdrz.nrrdz.niiz.vtkZhdf5ZlsmmncZmnc2Zmghr   Zpic)	z.bmpz.jpegz.jpgz.pngz.tiffz.tifz.dicomz.dcmz.gdcmc               @   sD   e Zd ZdZdd Zdd ZG dd dejZG dd	 d	ejZd
S )	ItkFormata   The ItkFormat uses the ITK or SimpleITK library to support a range of
    ITK-related formats. It also supports a few common formats that are
    also supported by the freeimage plugin (e.g. PNG and JPEG).

    This format requires the ``itk`` or ``SimpleITK`` package.

    Parameters for reading
    ----------------------
    None.

    Parameters for saving
    ---------------------
    None.

    c             C   s,   |j tkrdS tdstdr(|j tkS d S )NTzitk.ImageIOBaser   )	extensionITK_FORMATSr   ALL_FORMATS)selfrequestr   r   r   	_can_read\   s    
zItkFormat._can_readc             C   s,   |j tkrdS tdstdr(|j tkS d S )NTzitk.ImageIOBaser   )r   r   r   r   )r   r   r   r   r   
_can_writef   s    
zItkFormat._can_writec               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )zItkFormat.Readerc             K   s   t s
t  t| j | _d S )N)r
   r   r   r   get_local_filename_img)r   kwargsr   r   r   _openo   s    zItkFormat.Reader._openc             C   s   dS )N   r   )r   r   r   r   _get_lengtht   s    zItkFormat.Reader._get_lengthc             C   s   d S )Nr   )r   r   r   r   _closew   s    zItkFormat.Reader._closec             C   s$   |dkrd}t |t| ji fS )Nr   z.Index out of range while reading from itk file)
IndexErrorr
   ZGetArrayFromImager   )r   index	error_msgr   r   r   	_get_dataz   s    zItkFormat.Reader._get_datac             C   s   d}t |d S )Nz5The itk plugin does not support meta data, currently.)RuntimeError)r   r#   r$   r   r   r   _get_meta_data   s    zItkFormat.Reader._get_meta_dataN)__name__
__module____qualname__r   r    r!   r%   r'   r   r   r   r   Readern   s
   	r+   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
zItkFormat.Writerc             C   s   t s
t  d S )N)r
   r   )r   r   r   r   r      s    zItkFormat.Writer._openc             C   s   d S )Nr   )r   r   r   r   r!      s    zItkFormat.Writer._closec             C   s   t |}t|| j  d S )N)r
   ZGetImageFromArrayr   r   r   )r   ZimmetaZ_itk_imgr   r   r   _append_data   s    
zItkFormat.Writer._append_datac             C   s   d}t |d S )Nz5The itk plugin does not support meta data, currently.)r&   )r   r,   r$   r   r   r   set_meta_data   s    zItkFormat.Writer.set_meta_dataN)r(   r)   r*   r   r!   r-   r.   r   r   r   r   Writer   s   r/   N)	r(   r)   r*   __doc__r   r   r   r+   r/   r   r   r   r   r   K   s
   
r   z:Insight Segmentation and Registration Toolkit (ITK) formatr	    ZiIvV)r0   Z
__future__r   r   r    r   Zcorer   r   r
   r   r   r   r   titlejoinformatZ
add_formatr   r   r   r   <module>   s   O