3
dw!                 @   sn   d Z ddljZddlmZ ddlmZmZm	Z	m
Z
mZmZ G dd deZG d	d
 d
e
ZG dd deZdS )z8MeshFix corrects topological errors in polygonal meshes.    N   )split_filename   )CommandLineCommandLineInputSpectraitsTraitedSpec	isdefinedFilec               @   s  e Zd ZejdddZejdddddZejd	d
gddZ	ejdd
gddZ
ejdddZejdddZejddgdddZejdddgddZejdddgddZejdddZejdd gd!d"Zejd#d$gd%d"Zejd&d'dZejd&d(dZejd)d*dZejd+d,dZejd-d.dZejd/d0dZejd1d2dZejd3d4d5gdVd7d8Zejd9d4d5gdWd:gd;d<Zejd=d5gdXd?d8Zejd@d4gdYd?d8ZejdBdCdZejdDdEdZ e!dFdGdAdFdHZ"e!dFdGd>dIZ#ej$dJdKdLdMdNdOdJgdFdPdQZ%e!dFdRdSdTZ&dUS )ZMeshFixInputSpecz--shells %dz"Only the N biggest shells are kept)argstrdescz-a %fg        g       @z2Epsilon angle in degrees (must be between 0 and 2))r   lowhighr   z-jjoin_closest_componentsz;Join 2 biggest components if they overlap, remove the rest.)r   xorr   z-jcz$Join the closest pair of components.z-qz'Quiet mode, don't write much to stdout.z
--no-cleanzDon't Cleansave_as_vrmlsave_as_freesurfer_meshz--stlz3Result is saved in stereolithographic format (.stl))r   r   r   z--wrlsave_as_stlz(Result is saved in VRML1.0 format (.wrl)z--fsmeshz)Result is saved in freesurfer mesh formatz--remove-handleszRemove handlesz-u %duniform_remeshing_verticesz7Number of steps for uniform remeshing of the whole mesh)r   requiresr   z--vertices %duniform_remeshing_stepszKConstrains the number of vertices.Must be used with uniform_remeshing_stepsz--smooth %dz0The number of laplacian smoothing steps to applyzWShifts the coordinates of the vertices when saving. Output must be in FreeSurfer formatz--cut-outer %dz:Remove triangles of 1st that are outside of the 2nd shell.z--cut-inner %dzsRemove triangles of 1st that are inside of the 2nd shell. Dilate 2nd by N; Fill holes and keep only 1st afterwards.z--decouple-inin %dzTreat 1st file as inner, 2nd file as outer component.Resolve overlaps by moving inners triangles inwards. Constrain the min distance between the components > d.z--decouple-outin %dzTreat 1st file as outer, 2nd file as inner component.Resolve overlaps by moving outers triangles inwards. Constrain the min distance between the components > d.z--decouple-outout %dzTreat 1st file as outer, 2nd file as inner component.Resolve overlaps by moving outers triangles outwards. Constrain the min distance between the components > d.z--fineTuneIn finetuning_distancefinetuning_substeps   z8Used to fine-tune the minimal distance between surfaces.)r   r   positionr   z--fineTuneOut finetuning_inwardszRSimilar to finetuning_inwards, but ensures minimal distance in the other direction)r   r   r   r   r   z%fr   zUsed to fine-tune the minimal distance between surfaces.A minimal distance d is ensured, and reached in n substeps. When using the surfaces for subsequent volume meshing by gmsh, this step prevent too flat tetrahedra2)z%dr   z--dilate %dz/Dilate the surface by d. d < 0 means shrinking.z--intersectzpIf the mesh contains intersections, return value = 1.If saved in gmsh format, intersections will be highlighted.Tz%s)existsr   r   	mandatory)r   r   r   offstlmshwrlvrmlfsz$The output type to save the file as.)Z
usedefaultr   z-o %sz+The output filename for the fixed mesh file)Zgenfiler   r   Nr%   )'__name__
__module____qualname__r   ZIntZnumber_of_biggest_shellsZRangeZepsilon_angleZBoolZ#join_overlapping_largest_componentsr   Z
quiet_modeZ
dont_cleanr   r   r   Zremove_handlesr   r   Zlaplacian_smoothing_stepsZx_shiftZ	cut_outerZ	cut_innerZdecouple_ininZdecouple_outinZdecouple_outoutr   Zfinetuning_outwardsZFloatr   r   ZdilationZset_intersections_to_oner
   in_file1Zin_file2Enumoutput_typeout_filename r/   r/   ;/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/meshfix.pyr      s   



r   c               @   s   e Zd ZedddZdS )MeshFixOutputSpecTzThe output mesh file)r   r   N)r(   r)   r*   r
   	mesh_filer/   r/   r/   r0   r1      s   r1   c               @   s4   e Zd ZdZdZeZeZdd Z	dd Z
dd Zd	S )
MeshFixa  
    MeshFix v1.2-alpha - by Marco Attene, Mirko Windhoff, Axel Thielscher.

    .. seealso::

        http://jmeshlib.sourceforge.net
            Sourceforge page

        http://simnibs.de/installation/meshfixandgetfem
            Ubuntu installation instructions

    If MeshFix is used for research purposes, please cite the following paper:
    M. Attene - A lightweight approach to repairing digitized polygon meshes.
    The Visual Computer, 2010. (c) Springer.

    Accepted input formats are OFF, PLY and STL.
    Other formats (like .msh for gmsh) are supported only partially.

    Example
    -------

    >>> import nipype.interfaces.meshfix as mf
    >>> fix = mf.MeshFix()
    >>> fix.inputs.in_file1 = 'lh-pial.stl'
    >>> fix.inputs.in_file2 = 'rh-pial.stl'
    >>> fix.run()                                    # doctest: +SKIP
    >>> fix.cmdline
    'meshfix lh-pial.stl rh-pial.stl -o lh-pial_fixed.off'
    Zmeshfixc                s   | j  j }t| jjrt| jj\}}  jdd ddddddg}t fd	d
|D rptj	| jj|d< qtj	|d | jj
 |d< ntj	| j |d< |S )N. r    r!   r"   r#   r$   r   c             3   s   | ]} |j  kV  qd S )N)lower).0Zout_type)extr/   r0   	<genexpr>   s    z(MeshFix._list_outputs.<locals>.<genexpr>r2   )output_specgetr	   inputsr.   r   replaceanyopabspathr-   _gen_outfilename)selfoutputspathnameZ	out_typesr/   )r8   r0   _list_outputs   s    zMeshFix._list_outputsc             C   s   |dkr| j  S d S d S )Nr.   )rA   )rB   rE   r/   r/   r0   _gen_filename   s    zMeshFix._gen_filenamec             C   s   t | jj\}}}| jjs&| jjdkr6d| j_d| j_| jjsJ| jjdkrZd| j_d| j_| jjsn| jjdkr~d| j_d| j_|d | jj S )Nr$   Tr    r#   z_fixed.)r   r<   r+   r   r-   r   r   )rB   _rE   r/   r/   r0   rA      s    zMeshFix._gen_outfilenameN)r(   r)   r*   __doc__Z_cmdr   Z
input_specr1   r:   rF   rG   rA   r/   r/   r/   r0   r3      s   r3   )rI   os.pathrD   r?   Zutils.filemanipr   baser   r   r   r   r	   r
   r   r1   r3   r/   r/   r/   r0   <module>   s   
 
 