a
    «ˆc·,  ã                   @   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dddd�Zedddd�ZeeƒZeejdd�Zeejd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/d0„ Z%d1d2„ Z&d3d4„ Z'd5d6„ Z(d7d8„ Z)d9d:„ Z*d;d<„ Z+d=d>„ Z,d?d@„ Z-dAdB„ Z.dCdD„ Z/dEdF„ Z0‡  Z1S )GÚ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   ç        Ú	_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¯Ä)r   r   g@Œµx¯D© )Úargsr   )ZclippingZscalar_mode)r   Úkwc                    s(   t t| ƒ ¡ }dD ]}| |d ¡ q|S )N)r   r   r   )Úsuperr   Ú__get_pure_state__Úpop)ÚselfÚdÚname©Ú	__class__r   ú\/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/components/contour.pyr!   �   s    zContour.__get_pure_state__c                 C   st   |   ¡ sdS |  ¡ }d}t| jƒdkr*d}|  ¡  |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   |   ¡  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   r7   r   r   r(   Úhas_output_port­   s    zContour.has_output_portc                 C   s   | j jS )z Returns the output port.)Úcontour_filterZoutput_portr7   r   r   r(   Úget_output_object±   s    zContour.get_output_objectc                 C   sn   | j s|  ¡ sd S | j}|j|j|j  }}}t|ƒt|ƒkr^| ||d ¡ | ¡  d| _	n|  
| j¡ d S )Nr   T)Úauto_contoursr*   r:   ÚaddedÚremovedÚindexr,   Ú	set_valueÚupdater6   Ú_contours_changedr/   )r#   Z
list_eventr3   r=   r>   r?   r   r   r(   Ú_contours_items_changed¸   s    ÿ
zContour._contours_items_changedc                 C   sR   | j s|  ¡ sd S | j}t|ƒ|_t|ƒD ]\}}| ||¡ q*| ¡  d| _d S ©NT)	r<   r*   r:   r,   Únumber_of_contoursÚ	enumerater@   rA   r6   )r#   Úvaluesr3   ÚiÚxr   r   r(   rB   Å   s    
zContour._contours_changedc                 C   s€   | j s
d S t| jd ƒ}t|jd ƒ}| dd¡\}}|d u rJtdƒ d}|| jkr|| j|d |d dd� |  	|¡ || _d S )	Nr   ZscalarsZpointz)Cannot contour: No scalars in input data!)r   g      ð?r   F)r   r   Útrait_change_notify)
Úauto_update_ranger   Úinputsr
   r2   Z	get_ranger   r-   Ú	trait_setÚ_clip_contours)r#   ÚsrcZdshr%   Úrngr   r   r(   r.   Ï   s    
ÿ
zContour._update_rangesc                 C   s   |   ¡  d S ©N©Ú_do_auto_contours©r#   r   r   r   r(   Ú_minimum_contour_changedà   s    z Contour._minimum_contour_changedc                 C   s   |   ¡  d S rQ   rR   rT   r   r   r(   Ú_maximum_contour_changedã   s    z Contour._maximum_contour_changedc                 C   s   |   ¡  d S rQ   rR   rT   r   r   r(   Ú_number_of_contours_changedæ   s    z#Contour._number_of_contours_changedc                 C   s   |r|   ¡  n|  | j¡ d S rQ   )rS   rB   r/   rT   r   r   r(   Ú_auto_contours_changedé   s    
zContour._auto_contours_changedc                 C   sJ   |rF| j | jf}|| _|  ¡  |  d|d | j ¡ |  d|d | j¡ d S )Nr   r   r   r   )r   r   r-   r.   Ztrait_property_changed)r#   r   rP   r   r   r(   Ú_auto_update_range_changedï   s    ÿÿz"Contour._auto_update_range_changedc                 C   sH   |   ¡ sd S | jrD| j| j }}| j | jt||ƒt||ƒ¡ d| _	d S rD   )
r*   r<   r0   r1   r:   Zgenerate_valuesrE   ÚminÚmaxr6   )r#   ZmincZmaxcr   r   r(   rS   ù   s    
þzContour._do_auto_contoursc                 C   s,   |   ¡ sd S |  ¡ }|  | j¡ |g| _d S rQ   )r*   r+   rX   r<   r2   )r#   Úvalr3   r   r   r(   Ú_filled_contours_changed  s
    z Contour._filled_contours_changedc                 C   s   | j r| jS | jS d S rQ   )Úfilled_contoursÚ_fill_cont_filtÚ
_cont_filtr7   r   r   r(   Ú_get_contour_filter  s    zContour._get_contour_filterc                 C   sJ   | j d jd }| j}| jr2t|ƒ}|  ||¡ n|  ||¡ | ¡  |S )zpSets the input to the appropriate contour filter and
        returns the currently used contour filter.
        r   )rL   r2   r:   r^   r   Zconfigure_inputrA   )r#   Úinpr3   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,   rL   r2   r7   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� |  ¡  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[   )Ú.0rI   ©ZdmaxZdminr   r(   Ú
<listcomp>-  ó    z*Contour._clip_contours.<locals>.<listcomp>F)r0   r1   rJ   N)r/   r<   rM   r   r   rS   )r#   rP   Zctrr   rd   r(   rN   '  s    þzContour._clip_contoursc                 C   s   | j | j d S )Ng      à?)r   r   r7   r   r   r(   Ú_get__default_contour5  s    zContour._get__default_contour)2Ú__name__Ú
__module__Ú__qualname__Ú__version__r   r:   r   r^   r<   r   rE   r0   r1   r   r/   Zshow_filled_contoursrK   r   r-   r   r   r   r   r   r	   ZContourFilterr`   ZBandedPolyDataContourFilterr_   r!   r5   r8   r9   r;   rC   rB   r.   rU   rV   rW   rX   rY   rS   r]   ra   r+   r*   rN   rg   Ú__classcell__r   r   r&   r(   r      sˆ   ÿþ
ÿû	ûüùþÿ


r   N)Ú__doc__Z
traits.apir   r   r   r   r   r   r   Ztvtk.apir	   Zmayavi.core.module_managerr
   Zmayavi.core.componentr   Zmayavi.core.commonr   Zmayavi.components.commonr   r   r   r   r   r   r(   Ú<module>   s   $