3
îÈ‘[·,  ã               @   s|   d Z ddlmZmZmZmZmZmZ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mZ G dd	„ d	eƒZd
S )av  A contour component.  This component wraps around the
tvtk.ContourFilter and provides convenient options to either
automatically generate a specified number of contours between a given
minimum and maximum value or explicitly specify the contours.  This
component may be used for any input data.  The component also provides
a convenient option to create "filled contours".

é    )ÚInstanceÚListÚTupleÚBoolÚRangeÚFloatÚProperty)Útvtk)ÚDataSetHelper)Ú	Component)Úerror)Úget_module_sourceÚconvert_to_poly_datac                   sŠ  e Zd ZdZeZeddd�Zeddd�Ze	ddddd	d
�Z
e	ddddddd�Ze	ddddddd�Zee	dddddd�ddd�ZedƒZeddd�ZeZedEddd�Zedddd�ZeeƒZeejf d�Zeejf dddœd�Z‡ f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/d0„ Z&d1d2„ Z'd3d4„ Z(d5d6„ Z)d7d8„ Z*d9d:„ Z+d;d<„ Z,d=d>„ Z-d?d@„ Z.dAdB„ Z/dCdD„ Z0‡  Z1S )FÚContourr   Fz&if filled contours are to be generated)Údescz:if contours are given explicitly or automatically computedé   i † Tznumber of contours to generate)Ú	enter_setÚauto_setr   g        Ú	_data_minÚ	_data_maxzthe starting contour value)ÚvalueÚlowÚhighr   r   r   zthe ending contour valueÚ_default_contour)r   r   r   r   r   é   z'explicitly the contours to be generated)Úrowsr   z-if the contour range is updated automaticallyg@Œµx¯D)r   r   )Úargsr   )ZclippingZscalar_mode)r   Úkwc                s,   t t| ƒjƒ }xdD ]}|j|d ƒ qW |S )Nr   r   r   )r   r   r   )Úsuperr   Ú__get_pure_state__Úpop)ÚselfÚdÚname)Ú	__class__© ú\/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/mayavi/components/contour.pyr   �   s    
zContour.__get_pure_state__c             C   st   | j ƒ sdS | jƒ }d}t| jƒdkr*d}| jƒ  |rh| j}|d |d  d g| _|d | _|d | _|g| _dS )zâOverride this method so that it *updates* the tvtk pipeline
        when data upstream is known to have changed.

        This method is invoked (automatically) when the input fires a
        `pipeline_changed` event.
        NFr   Tr   é   )	Ú
_has_inputÚ_set_contour_inputÚlenÚ_current_rangeÚ_update_rangesÚcontoursÚminimum_contourÚmaximum_contourÚoutputs)r!   ÚcfÚfirstZcrr%   r%   r&   Úupdate_pipelineŒ   s    

zContour.update_pipelinec             C   s   | j ƒ  d| _dS )zÆOverride this method to do what is necessary when upstream
        data changes.

        This method is invoked (automatically) when any of the inputs
        sends a `data_changed` event.
        TN)r,   Údata_changed)r!   r%   r%   r&   Úupdate_data¢   s    zContour.update_datac             C   s   dS )z' The contour filter has an output port.Tr%   )r!   r%   r%   r&   Úhas_output_port­   s    zContour.has_output_portc             C   s   | j jS )z Returns the output port.)Úcontour_filterÚoutput_port)r!   r%   r%   r&   Úget_output_object±   s    zContour.get_output_objectc             C   sp   | j s| jƒ  rd S | j}|j|j|j  }}}t|ƒt|ƒkr`|j||d ƒ |jƒ  d| _	n| j
| jƒ d S )Nr   T)Úauto_contoursr(   r7   ÚaddedÚremovedÚindexr*   Ú	set_valueÚupdater4   Ú_contours_changedr-   )r!   Z
list_eventr1   r;   r<   r=   r%   r%   r&   Ú_contours_items_changed¸   s    zContour._contours_items_changedc             C   sX   | j s| jƒ  rd S | j}t|ƒ|_x t|ƒD ]\}}|j||ƒ q.W |jƒ  d| _d S )NT)	r:   r(   r7   r*   Únumber_of_contoursÚ	enumerater>   r?   r4   )r!   Úvaluesr1   ÚiÚxr%   r%   r&   r@   Å   s    
zContour._contours_changedc             C   s€   | j s
d S t| jd ƒ}t|jd ƒ}|jddƒ\}}|d krJtdƒ d
}|| jkr|| j|d |d dd	� | j	|ƒ || _d S )Nr   ÚscalarsÚpointz)Cannot contour: No scalars in input data!ç        ç      ð?r   F)r   r   Útrait_change_notify)rI   rJ   )
Úauto_update_ranger   Úinputsr
   r0   Ú	get_ranger   r+   Ú	trait_setÚ_clip_contours)r!   ÚsrcZdshr#   Úrngr%   r%   r&   r,   Ï   s    

zContour._update_rangesc             C   s   | j ƒ  d S )N)Ú_do_auto_contours)r!   r   r%   r%   r&   Ú_minimum_contour_changedà   s    z Contour._minimum_contour_changedc             C   s   | j ƒ  d S )N)rS   )r!   r   r%   r%   r&   Ú_maximum_contour_changedã   s    z Contour._maximum_contour_changedc             C   s   | j ƒ  d S )N)rS   )r!   r   r%   r%   r&   Ú_number_of_contours_changedæ   s    z#Contour._number_of_contours_changedc             C   s   |r| j ƒ  n| j| jƒ d S )N)rS   r@   r-   )r!   r   r%   r%   r&   Ú_auto_contours_changedé   s    
zContour._auto_contours_changedc             C   sJ   |rF| j | jf}|| _| jƒ  | jd|d | j ƒ | jd|d | jƒ d S )Nr   r   r   r   )r   r   r+   r,   Útrait_property_changed)r!   r   rR   r%   r%   r&   Ú_auto_update_range_changedï   s    z"Contour._auto_update_range_changedc             C   sH   | j ƒ sd S | jrD| j| j }}| jj| jt||ƒt||ƒƒ d| _	d S )NT)
r(   r:   r.   r/   r7   Zgenerate_valuesrB   ÚminÚmaxr4   )r!   ZmincZmaxcr%   r%   r&   rS   ù   s    
zContour._do_auto_contoursc             C   s,   | j ƒ sd S | jƒ }| j| jƒ |g| _d S )N)r(   r)   rW   r:   r0   )r!   Úvalr1   r%   r%   r&   Ú_filled_contours_changed  s
    z Contour._filled_contours_changedc             C   s   | j r| jS | jS d S )N)Úfilled_contoursÚ_fill_cont_filtÚ
_cont_filt)r!   r%   r%   r&   Ú_get_contour_filter  s    zContour._get_contour_filterc             C   sJ   | j d jd }| j}| jr2t|ƒ}| j||ƒ n| j||ƒ |jƒ  |S )zpSets the input to the appropriate contour filter and
        returns the currently used contour filter.
        r   )rM   r0   r7   r^   r   Úconfigure_inputr?   )r!   Úinpr1   r%   r%   r&   r)     s    zContour._set_contour_inputc             C   s.   t | jƒdkr&t | jd jƒdkr&dS dS dS )z,Returns if this component has a valid input.r   TFN)r*   rM   r0   )r!   r%   r%   r&   r(     s    zContour._has_inputc                sX   g }|\‰‰ ‡ ‡fdd„| j D ƒ}| js2|| j krT|| _ | j| j| jdd� | jƒ  dS )z{Clips the contour related values when the data range has
        changed.  The new range is given as the argument.
        c                s   g | ]}t t|ˆƒˆ ƒ‘qS r%   )rZ   r[   )Ú.0rF   )ÚdmaxÚdminr%   r&   ú
<listcomp>-  s    z*Contour._clip_contours.<locals>.<listcomp>F)r.   r/   rK   N)r-   r:   rO   r   r   rS   )r!   rR   Zctrr%   )re   rf   r&   rP   '  s    zContour._clip_contoursc             C   s   | j | j d S )Ng      à?)r   r   )r!   r%   r%   r&   Ú_get__default_contour5  s    zContour._get__default_contourg@Œµx¯Ä)2Ú__name__Ú
__module__Ú__qualname__Ú__version__r   r7   r   r^   r:   r   rB   r.   r/   r   r-   Zshow_filled_contoursrL   r   r+   r   r   r   r   r   r	   ZContourFilterr`   ZBandedPolyDataContourFilterr_   r   r3   r5   r6   r9   rA   r@   r,   rT   rU   rV   rW   rY   rS   r]   ra   r)   r(   rP   rh   Ú__classcell__r%   r%   )r$   r&   r      sv   

	


r   N)Ú__doc__Ú
traits.apir   r   r   r   r   r   r   Útvtk.apir	   Zmayavi.core.module_managerr
   Zmayavi.core.componentr   Úmayavi.core.commonr   Zmayavi.components.commonr   r   r   r%   r%   r%   r&   Ú<module>   s   $