3
d^                 @   s   d Z ddlZddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZmZ ddlmZ ddlmZ ejd	ZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )zVConvert3D is a command-line tool for converting 3D images between common file formats.    N)glob   )	CommandLineInputSpectraitsTraitedSpecFileSEMLikeCommandLineInputMultiPathOutputMultiPathCommandLine	isdefined   )split_filename)loggingZ	interfacec               @   s^   e Zd ZeddddZeddddZeddddZejej	e d	d
dddZ
ej	dddZdS )C3dAffineToolInputSpecTz-ref %sr   )existsargstrpositionz-src %sr   z%s   FzExport ITK transform.z-oitk %s   )Z
hash_filesdescr   r   z-fsl2ras   )r   r   N)__name__
__module____qualname__r   Zreference_fileZsource_fileZtransform_filer   EitherBoolitk_transformZfsl2ras r   r   6/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/c3.pyr      s   r   c               @   s   e Zd ZeddZdS )C3dAffineToolOutputSpecT)r   N)r   r   r   r   r   r   r   r   r   r    &   s   r    c               @   s$   e Zd ZdZeZeZdZddiZ	dS )C3dAffineToola  Converts fsl-style Affine registration into ANTS compatible itk format

    Example
    =======

    >>> from nipype.interfaces.c3 import C3dAffineTool
    >>> c3 = C3dAffineTool()
    >>> c3.inputs.source_file = 'cmatrix.mat'
    >>> c3.inputs.itk_transform = 'affine.txt'
    >>> c3.inputs.fsl2ras = True
    >>> c3.cmdline
    'c3d_affine_tool -src cmatrix.mat -fsl2ras -oitk affine.txt'
    Zc3d_affine_toolr   z
affine.txtN)
r   r   r   __doc__r   
input_specr    output_spec_cmdZ_outputs_filenamesr   r   r   r   r!   *   s
   r!   c               @   s   e Zd Zee dddddZeddd0dgd	d
Zee ddgd1ddZej	ddddddddddd
Z
ejej ej dddZejej ej dddZej	ddd d!d"d#d$dZejd%d&dZejd'd(dZejddd)d*d+d,Zejddd-d.Zd/S )2C3dInputSpecr   z%sTz1Input file (wildcard and multiple are supported).)r   r   	mandatoryr   Fz-o %s	out_filesz'Output file of last image on the stack.)r   r   r   xorr   z-oo %sout_filezWrite all images on the convert3d stack as multiple files. Supports both list of output files or a pattern for the output filenames (using %d substituion).)r   r)   r   r   floatcharZucharshortZushortintZuintdoublez-type %sznSpecifies the pixel type for the output image. By default, images are written in floating point (float) format)r   r   z	-scale %szZMultiplies the intensity of each voxel in the last image on the stack by the given factor.z	-shift %sz'Adds the given constant to every voxel.ZLinearZNearestNeighborZCubicZSincZGaussianz-interpolation %szVSpecifies the interpolation used with -resample and other commands. Default is Linear.z-resample %sa  Resamples the image, keeping the bounding box the same, but changing the number of voxels in the image. The dimensions can be specified as a percentage, for example to double the number of voxels in each direction. The -interpolation flag affects how sampling is performed.z
-smooth %szvApplies Gaussian smoothing to the image. The parameter vector specifies the standard deviation of the Gaussian kernel.z-mcrr   z)Enable reading of multi-component images.)
usedefaultr   r   r   zAChanges command to support 4D file operations (default is false).)r0   r   Nr1   )r   r   r   r	   r   in_filer*   r(   r   EnumZpix_typer   ZIntZFloatZscaleshiftZinterpStrZresampleZsmoothr   Zmulticomp_splitis_4dr   r   r   r   r&   @   s~   r&   c               @   s   e Zd ZeeddZdS )C3dOutputSpecF)r   N)r   r   r   r
   r   r(   r   r   r   r   r7      s   r7   c                   sP   e Zd ZdZeZeZdZ fddZ	dd Z
 fddZd	d
 Zdd Z  ZS )C3daF  
    Convert3d is a command-line tool for converting 3D (or 4D) images between
    common file formats. The tool also includes a growing list of commands for
    image manipulation, such as thresholding and resampling. The tool can also
    be used to obtain information about image files. More information on
    Convert3d can be found at:
    https://sourceforge.net/p/c3d/git/ci/master/tree/doc/c3d.md


    Example
    =======

    >>> from nipype.interfaces.c3 import C3d
    >>> c3 = C3d()
    >>> c3.inputs.in_file = "T1.nii"
    >>> c3.inputs.pix_type = "short"
    >>> c3.inputs.out_file = "T1.img"
    >>> c3.cmdline
    'c3d T1.nii -type short -o T1.img'
    >>> c3.inputs.is_4d = True
    >>> c3.inputs.in_file = "epi.nii"
    >>> c3.inputs.out_file = "epi.img"
    >>> c3.cmdline
    'c4d epi.nii -type short -o epi.img'
    c3dc                s6   t t| jf | | jj| jd | jjr2| j  d S )Nr6   )superr8   __init__inputsZon_trait_change_is_4dr6   )selfr<   )	__class__r   r   r;      s    zC3d.__init__c             C   s   | j jrdnd| _d S )NZc4dr9   )r<   r6   r%   )r>   r   r   r   r=      s    z
C3d._is_4dc                sD   | j }t| jj r*t| jj r*| j  tt| j|}|| _ |S )N)	r%   r   r<   r*   r(   _gen_outfiler:   r8   _run_interface)r>   Zruntimecmd)r?   r   r   rA      s    zC3d._run_interfacec             C   s|   t | jjdks d| jjd kr(tdt| jjd \}}}|d | | j_tjjtjj	| jjrnt
dtjd d S )Nr   *r   zCMultiple in_files found - specify either `out_file` or `out_files`.Z
_generatedz2File already found - to overwrite, use `out_file`.zGenerating `out_file`.)lenr<   r2   AttributeErrorr   r*   ospathr   abspathIOErrorifloggerinfo)r>   _fnextr   r   r   r@      s     zC3d._gen_outfilec             C   s   | j  j }t| jjr,tjj| jj|d< t| jjr|t	| jjdkrbt
tjj| jjd }ndd | jjD }||d< |S )Nr(   r   r   c             S   s,   g | ]$}t jjt jj|rt jj|qS r   )rF   rG   r   rH   ).0fr   r   r   
<listcomp>   s   z%C3d._list_outputs.<locals>.<listcomp>)r$   getr   r<   r*   rF   rG   rH   r(   rD   r   )r>   outputsZ
_out_filesr   r   r   _list_outputs   s    zC3d._list_outputs)r   r   r   r"   r&   r#   r7   r$   r%   r;   r=   rA   r@   rT   __classcell__r   r   )r?   r   r8      s   
r8   )r"   rF   r   baser   r   r   r   r   r	   r
   r   r   Zutils.filemanipr    r   	getLoggerrJ   r   r    r!   r&   r7   r8   r   r   r   r   <module>   s   ,
c