a
    «ˆcõ¡  ã                   @   sz  d 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mZmZmZmZmZmZmZmZ ddl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!m"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.m/Z/ ddl0Z1dd„ Z2G dd„ de*ƒZ3G dd„ de3ƒZ4e2e4ƒ ƒZ5dd„ Z6edjdd„ƒZ7dd„ Z8G dd„ de4ƒZ9e2e9ƒ ƒZ:dd„ Z;dd„ Z<dd„ Z=G d d!„ d!e3ƒZ>e2e>ƒ ƒZ?d"d#„ Z@d$d%„ ZAedkd&d'„ƒZBd(d)„ ZCG d*d+„ d+e3ƒZDe2eDƒ ƒZEd,d-„ ZFedld.d/„ƒZGG d0d1„ d1e3ƒZHe2eHƒ ƒZId2d3„ ZJedmd4d5„ƒZKG d6d7„ d7e3ƒZLe2eLƒ ƒZMd8d9„ ZNednd:d;„ƒZOG d<d=„ d=e3ƒZPe2ePƒ ƒZQd>d?„ ZRG d@dA„ dAe3ƒZSe2eSƒ ƒZTdBdC„ ZUedodDdE„ƒZVdFdG„ ZWdHdI„ ZXG dJdK„ dKe3ƒZYe2eYƒ ƒZZdLdM„ Z[dpdQdR„Z\edqdSdT„ƒZ]drdUdV„Z^dWdX„ Z_G dYdZ„ dZe3ƒZ`e2e`ƒ ƒZad[d\„ Zbecƒ Zdd]D ]Zee
ee edee< �qG d^d_„ d_e3ƒZfe2efƒ ƒZgd`da„ ZhG dbdc„ dceYƒZie2eiƒ ƒZjddde„ Zkdsdhdi„ZldS )ta¬  
Helper functions for mlab. These combine creation of the data sources,
and applying the modules to them to make standard visualization
operation. They should always return the module object created, for
consistency, and because retrieving the vtk data source from a module object
is possible via tools.get_vtk_src

Each helper function should have a test function associated with it,
both for testing and to ilustrate its use.
é   )	ÚVectorsFactoryÚStreamlineFactoryÚGlyphFactoryÚIsoSurfaceFactoryÚSurfaceFactoryÚContourSurfaceFactoryÚImageActorFactoryÚImagePlaneWidgetFactoryÚglyph_mode_dict)	Úvector_scatterÚvector_fieldÚscalar_scatterÚscalar_fieldÚline_sourceÚarray2d_sourceÚgrid_sourceÚtriangular_mesh_sourceÚvertical_vectors_source)ÚExtractVectorNormFactoryÚWarpScalarFactoryÚTubeFactoryÚExtractEdgesFactoryÚPolyDataNormalsFactoryÚStripperFactory)Úanimateé    )ÚScene)Ú
traits_docÚdedent)Útools)
ÚArrayÚBoolÚCallableÚCFloatÚ	HasTraitsÚListÚTraitÚAnyÚInstanceÚ
TraitErrorNc                    sV   ‡ fdd„}t ˆ dƒrˆ j}nˆ jd ur0ˆ j}nd}tdƒt|ƒtˆ  ¡ ƒf |_|S )Nc                     s   ˆ | i |¤ŽS ©N© )ÚargsÚkwargs©Úpipeliner+   ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/tools/helper_functions.pyÚthe_function%   s    z'document_pipeline.<locals>.the_functionÚdocÚ z%%s

    **Keyword arguments:**
    %s)Úhasattrr2   Ú__doc__r   r   Úget_all_traits)r/   r1   r2   r+   r.   r0   Údocument_pipeline#   s    


ÿýr7   c                   @   sP   e Zd ZdZeƒ Zeƒ Zeddd�Z	dd„ Z
dd„ Zd	d
„ Zdd„ Zdd„ ZdS )ÚPipelinez7 Function used to build pipelines for helper functions zmayavi.core.scene.ScenezFigure to populate.©Úhelpc                 O   s|   d|v r4|d }t |tƒs&|du s&J ‚t|ddƒ}n
t ¡ j}|durV|j | _d|_| j|i |¤Ž}|durx| j |_|S )ze Calls the logics of the factory, but only after disabling
            rendering, if needed.
        ÚfigureNÚsceneT)	Ú
isinstancer   Úgetattrr   Úgcfr<   Zdisable_renderZ
_do_redrawÚ__call_internal__)Úselfr,   r-   r;   r<   Úoutputr+   r+   r0   Ú__call__D   s    


zPipeline.__call__c                 O   s4   |   |¡ | j|i |¤Ž| _| jdd… | _|  ¡ S )zl Builds the source and runs through the pipeline, returning
        the last object created by the pipeline.N)Ústore_kwargsÚ_source_functionÚsourceÚ	_pipeliner/   Úbuild_pipeline©rA   r,   r-   r+   r+   r0   r@   Y   s    
zPipeline.__call_internal__c              
      s˜   |  ¡ }|  ¡ }t| ¡ ƒ t| ¡ ƒ¡s\tdd dd„ t| ¡ ƒ t| ¡ ƒ¡D ƒ¡ ƒ‚|  	|  
¡ ¡‰ ‡ fdd„tˆ  ¡ ƒD ƒ ˆ  |¡ ˆ | _dS )zv Merges the given keyword argument, with traits default and
            store the resulting dictionary in self.kwargs.zInvalid keyword arguments : %sz, c                 s   s   | ]}t |ƒV  qd S r*   )Ústr)Ú.0Úkr+   r+   r0   Ú	<genexpr>i   s   z(Pipeline.store_kwargs.<locals>.<genexpr>c                    s"   g | ]}|d  dkrˆ   |¡‘qS )r   Ú_)Úpop)rK   Úkey©Útraitsr+   r0   Ú
<listcomp>m   ó    z)Pipeline.store_kwargs.<locals>.<listcomp>N)Úcopyr6   ÚsetÚkeysÚissubsetÚlistÚ
ValueErrorÚjoinÚ
differenceZ	trait_getÚclass_trait_namesÚupdater-   )rA   r-   Z
all_traitsr+   rQ   r0   rD   b   s    
þÿ
zPipeline.store_kwargsc                 C   sp   | j }| jD ]^}t| ¡ ƒ}| d¡ | d¡ i }| j ¡ D ]\}}||v r>|||< q>||fi |¤Žj}q|S )z6 Runs through the pipeline, applying pipe after pipe. Útrait_addedÚtrait_modified)rF   r/   rV   r]   Úremover-   ÚitemsÚ_target)rA   ÚobjectÚpipeÚkeywordsZthis_kwargsrP   Úvaluer+   r+   r0   rH   q   s    



zPipeline.build_pipelinec                 C   sD   i }| j D ]}| | ¡ ¡ q
| |  ¡ ¡ | d¡ | d¡ |S )zK Returns all the traits of class, and the classes in the pipeline.
        r_   r`   )rG   r^   Zclass_traitsrO   )rA   rR   re   r+   r+   r0   r6      s    


zPipeline.get_all_traitsN)Ú__name__Ú
__module__Ú__qualname__r5   r"   rE   r%   rG   r(   r;   rC   r@   rD   rH   r6   r+   r+   r+   r0   r8   9   s   ÿ	r8   c                   @   s2   e Zd ZdZeeƒZegZe	ddd�Z
dd„ ZdS )ÚPoints3da­  
    Plots glyphs (like points) at the position of the supplied data.

    **Function signatures**::

        points3d(x, y, z...)
        points3d(x, y, z, s, ...)
        points3d(x, y, z, f, ...)

    x, y and z are numpy arrays, or lists, all of the same shape, giving
    the positions of the points.

    If only 3 arrays x, y, z are given, all the points are drawn with the
    same size and color.

    In addition, you can pass a fourth array s of the same
    shape as x, y, and z giving an associated scalar value for each
    point, or a function f(x, y, z) returning the scalar value. This
    scalar value can be used to modulate the color and the size of the
    points.Úautoz¯The scaling applied to the glyphs. the size of the glyph is by default calculated from the inter-glyph spacing. Specify a float to give the maximum glyph size in drawing unitsr9   c                 O   sj   |  dd¡}|dkrd|d< tj| g|¢R i |¤Ž}|dkr\t |jj¡|jj_d|jj_	n
d|jj_	|S )zI Override the call to be able to scale automatically the glyphs.
        Úscale_factorrl   r   TF)
Úgetr8   r@   r   Z_typical_distanceÚmlab_sourceZdatasetÚglyphrm   Úclamping)rA   r,   r-   rm   Úgr+   r+   r0   r@   ¬   s    ÿ
zPoints3d.__call_internal__N)rh   ri   rj   r5   r"   r   rE   r   rG   r'   rm   r@   r+   r+   r+   r0   rk   Œ   s
   rk   c                  C   s\   t  ddt j d¡} t  d|  ¡}t  | ¡}t  d|  ¡}dt  | ¡ }t||||ddd�S )Nr   é   é   é   Zcopperç      Ð?)Úcolormaprm   )ÚnpÚlinspaceÚpiÚsinÚcosÚpoints3d)ÚtÚxÚyÚzÚsr+   r+   r0   Útest_points3d¾   s    
rƒ   c                 c   s`   | dur| nt ƒ }t ddtj d¡}|j}tdƒD ]&}t d| d |d  ¡|_dV  q4dS )	z#Animates the test_points3d example.Nr   rs   rt   é
   ru   çš™™™™™¹?r   )rƒ   rx   ry   rz   ro   Úranger|   r�   )Úobjrr   r~   ÚmsÚir+   r+   r0   Útest_points3d_animÈ   s    rŠ   c                  C   st  g d¢g d¢g} t ttjt| Ž ƒƒ\}}}g d¢g d¢g d¢g d¢g}t ttjt|Ž ƒƒ\}}}g d¢g d¢g d	¢g d
¢g d¢g d¢g d¢g d¢g}t ttjt|Ž ƒƒ\}	}
}g d¢g d¢g d¢g d¢g d¢g d¢g d¢g d¢g d¢g d¢g
}t ttjt|Ž ƒƒ\}}}t|||dddddd�}t|||ddddd d�}t|	|
|dddd!d"d�}t|||d#ddd$d%d�}||||fS )&z(Generates and shows a Caffeine molecule.)é   é>   é   )é   é   r„   )é   r�   é   )é   é*   é   )é7   é.   é   )é8   é   é   )é   é1   é   )r‹   é2   é   )r“   r“   r�   )é+   é   rš   )r’   é   é   )é    é   rŽ   )é?   é$   r�   )é;   é<   rt   )é   r›   é   )r¤   r   rŸ   )é%   r›   r   )éI   r§   rŸ   )éE   r©   rt   )é6   rŒ   r¢   )é9   éB   r£   )r¥   r¨   rŸ   )r   é,   é   )r   rœ   r¥   rŸ   Únonert   )r   r   r   ZOxygen)rm   Ú
scale_modeÚ
resolutionÚcolorÚname)r   r   r   ZNitrogen)r   r   r   ZCarbonr„   )r   r   r   ZHydrogen)rY   Úmaprx   ÚarrayÚzipr}   )ÚoZoxZoyZozÚnZnxÚnyZnzÚcZcxÚcyÚczÚhÚhxZhyÚhzZoxygenZnitrogenZcarbonZhydrogenr+   r+   r0   Útest_moleculeÔ   s6    ÿÿÿþÿþrÅ   c                   @   s(   e Zd ZdZedd�ZeeƒZe	gZ
dS )ÚQuiver3DaI  
    Plots glyphs (like arrows) indicating the direction of the vectors
    at the positions supplied.

    **Function signatures**::

        quiver3d(u, v, w, ...)
        quiver3d(x, y, z, u, v, w, ...)
        quiver3d(x, y, z, f, ...)

    u, v, w are numpy arrays giving the components of the vectors.

    If only 3 arrays, u, v, and w are passed, they must be 3D arrays, and
    the positions of the arrows are assumed to be the indices of the
    corresponding points in the (u, v, w) arrays.

    If 6 arrays, (x, y, z, u, v, w) are passed, the 3 first arrays give
    the position of the arrows, and the 3 last the components. They
    can be of any shape.

    If 4 positional arguments, (x, y, z, f) are passed, the last one must be
    a callable, f, that returns vectors components (u, v, w) given the
    positions (x, y, z).úoptional scalar data.r9   N)rh   ri   rj   r5   r    Úscalarsr"   r   rE   r   rG   r+   r+   r+   r0   rÆ   ñ   s   
rÆ   c               
   C   s”   t jdd…dd…dd…f \} }}t  | d |d  |d  ¡}|t  |¡ |d  }|  t  |¡ |d  }t  |¡}t| |||||ddd�}|S )Néþÿÿÿé   ru   rs   gü©ñÒMbP?r   )Ú
line_widthrm   )rx   ÚmgridÚsqrtr{   Ú
zeros_likeÚquiver3d©r   r€   r�   ÚrÚuÚvÚwr‡   r+   r+   r0   Útest_quiver3d  s    "
rÕ   c                  C   sš   g d¢\} }}}}}t jddd…ddd…ddd…f \}}}| d¡}| d¡}| d¡}t  |¡}	t  |¡}
t  || ¡}t||||	|
|dddd	�	}|S )
N©éûÿÿÿr›   r×   r›   r×   r›   r×   r›   y               @ÚfZcone)r   r   r   r   r   r   çÍÌÌÌÌÌì?)ÚmodeÚextentrm   )rx   rÌ   Úastyper|   r{   rÏ   )ÚxminÚxmaxÚyminÚymaxÚzminÚzmaxr   r€   r�   rÒ   rÓ   rÔ   r‡   r+   r+   r0   Útest_quiver3d_cone  s    (




ÿrã   c            
      C   s’   ddg} g d¢\}}}}t j||| d d …||| d d …f \}}| d¡}| d¡}t  |¡}t  |¡}t  |¡}	t|||	|||	ddd	d
�	S )Nr¤   )r×   r›   r×   r›   r   ù              ð?r   rØ   ZPurplesç      à?Z2dthick_arrow)rw   rm   rÚ   )rx   rÌ   rÜ   r|   r{   rÎ   rÏ   )
ÚdimsrÝ   rÞ   rß   rà   r   r€   rÒ   rÓ   rÔ   r+   r+   r0   Útest_quiver3d_2d_data/  s    ÿ





ÿrç   c                   @   s2   e Zd ZdZedd�ZeeƒZe	e
gZdd„ ZdS )ÚFlowai  
    Creates a trajectory of particles following the flow of a vector field.

    **Function signatures**::

        flow(u, v, w, ...)
        flow(x, y, z, u, v, w, ...)
        flow(x, y, z, f, ...)

    u, v, w are numpy arrays giving the components of the vectors.

    If only 3 arrays, u, v, and w are passed, they must be 3D arrays, and
    the positions of the arrows are assumed to be the indices of the
    corresponding points in the (u, v, w) arrays.

    If 6 arrays, (x, y, z, u, v, w) are passed, the 3 first arrays give
    the position of the arrows, and the 3 last the components. The x, y
    and z arrays are then supposed to have been generated by
    `numpy.mgrid`, in other words, they are 3D arrays, with positions
    lying on a 3D orthogonal and regularly spaced grid with nearest
    neighbor in space matching nearest neighbor in the array. The
    function builds a vector field assuming  the points are regularly
    spaced.

    If 4 positional arguments, (x, y, z, f) are passed, the last one must be
    a callable, f, that returns vectors components (u, v, w) given the
    positions (x, y, z).rÇ   r9   c                 O   sX   | j |i |¤Ž| _| dd¡ |  |¡ | jdd… | _t | j¡rP| j d¡ |  ¡ S )zf Override the call to be able to choose whether to apply an
        ExtractVectorNorm filter.
        r¸   Nr   )	rE   rF   rO   rD   rG   r/   r   Z_has_scalar_datarH   rI   r+   r+   r0   r@   c  s    
zFlow.__call_internal__N)rh   ri   rj   r5   r    rÈ   r"   r   rE   r   r   rG   r@   r+   r+   r+   r0   rè   @  s
   
rè   c                  C   sŽ   t jddd…ddd…ddd…f \} }}t  | d |d  |d  d ¡}|t  |¡ | }|  t  |¡ | }t  |¡d }t|||ƒ}|S )	Néüÿÿÿrs   y              D@r   y              4@ru   r…   çš™™™™™©?)rx   rÌ   rÍ   r{   Z	ones_likeÚflowrÐ   r+   r+   r0   Ú	test_flows  s    ("rì   c               	   C   sÂ   g d¢} g d¢\}}}}}}t j||| d d …||| d d …||| d d …f \}}}	| d¡}| d¡}|	 d¡}	t  |d ¡}
t  |d ¡}t  ||	 d	 ¡}t|||	|
||d
d�}|S )N©r¤   r¤   r¤   rÖ   r   rä   r   ru   rØ   ç       @ç      @Útube)Úlinetype©rx   rÌ   rÜ   r|   r{   rë   )ræ   rÝ   rÞ   rß   rà   rá   râ   r   r€   r�   rÒ   rÓ   rÔ   r‡   r+   r+   r0   Útest_flow_tubes}  s    þ


ró   c                 c   s˜   | d ur| nt ƒ } | j}|j|j|j  }}}tdƒD ]\}t |d tj|d  d  ¡}t 	|| d tj|d  d  ¡}|j
||d� d V  q6d S )Nr„   rî   r   g      $@rï   )rÒ   rÔ   )ró   ro   r   r€   r�   r†   rx   r|   rz   r{   Ú	trait_set)r‡   rˆ   r   r€   r�   r‰   rÒ   rÔ   r+   r+   r0   Útest_flow_anim�  s     $rõ   c               	   C   sÊ   g d¢} g d¢\}}}}}}t j||| d d …||| d d …||| d d …f \}}}	| d¡}| d¡}|	 d¡}	t  |d ¡}
t  |d ¡}t  ||	 d	 ¡}||	 }t|
|||d
ddd�}|S )Nrí   rÖ   r   rä   r   ru   rØ   rî   g       @Zplanerð   ÚSpectral)rÈ   Zseedtyperñ   rw   rò   )ræ   rÝ   rÞ   rß   rà   rá   râ   r   r€   r�   rÒ   rÓ   rÔ   r~   r‡   r+   r+   r0   Útest_flow_scalarsœ  s"    þ


ÿr÷   c                   @   s   e Zd ZdZeeƒZegZdS )Ú	Contour3daÆ  
    Plots iso-surfaces for a 3D volume of data supplied as arguments.

    **Function signatures**::

        contour3d(scalars, ...)
        contour3d(x, y, z, scalars, ...)

    scalars is a 3D numpy arrays giving the data on a grid.

    If 4 arrays, (x, y, z, scalars) are passed, the 3 first arrays give the
    position, and the last the scalar value. The x, y and z arrays are then
    supposed to have been generated by `numpy.mgrid`, in other words, they are
    3D arrays, with positions lying on a 3D orthogonal and regularly spaced
    grid with nearest neighbor in space matching nearest neighbor in the array.
    The function builds a scalar field assuming  the points are regularly
    spaced.N)	rh   ri   rj   r5   r"   r   rE   r   rG   r+   r+   r+   r0   rø   ²  s   rø   c                  C   sZ   t jddd…ddd…ddd…f \} }}| |  d ||  || d  }t|ddd�}|S )	Nr×   r›   ù              P@rå   rî   rs   T)ZcontoursZtransparent)rx   ÚogridÚ	contour3d©r   r€   r�   rÈ   r‡   r+   r+   r0   Útest_contour3dÍ  s    ( rý   c                 c   sˆ   | d ur| nt ƒ } tjddd…ddd…ddd…f \}}}| j}tddƒD ]8}|| d || d |d   || d  |_d V  qJd S ©	Nr×   r›   rù   r   r„   rå   r…   rv   )rý   rx   rú   ro   r†   rÈ   ©r‡   r   r€   r�   rˆ   r‰   r+   r+   r0   Útest_contour3d_animÖ  s    (.r   c                   @   s   e Zd ZdZeeƒZegZdS )ÚVolumeSliceaè  
    Plots an interactive image plane sliced through a 3D volume of data
    supplied as argument.

    **Function signatures**::

        volume_slice(scalars, ...)
        volume_slice(x, y, z, scalars, ...)

    scalars is a 3D numpy arrays giving the data on a grid.

    If 4 arrays, (x, y, z, scalars) are passed, the 3 first arrays give the
    position, and the last the scalar value. The x, y and z arrays are then
    supposed to have been generated by `numpy.mgrid`, in other words, they are
    3D arrays, with positions lying on a 3D orthogonal and regularly spaced
    grid with nearest neighbor in space matching nearest neighbor in the array.
    The function builds a scalar field assuming  the points are regularly
    spaced.N)	rh   ri   rj   r5   r"   r   rE   r	   rG   r+   r+   r+   r0   r  â  s   r  c                  C   sX   t jddd…ddd…ddd…f \} }}| |  d ||  || d  }t|dd�}|S )Nr×   r›   rù   rå   rî   Zx_axes)Zplane_orientation)rx   rú   Úvolume_slicerü   r+   r+   r0   Útest_volume_sliceþ  s    ( r  c                 c   sˆ   | d ur| nt ƒ } tjddd…ddd…ddd…f \}}}| j}tddƒD ]8}|| d || d |d   || d  |_d V  qJd S rþ   )r  rx   rú   ro   r†   rÈ   rÿ   r+   r+   r0   Útest_volume_slice_anim  s    (.r  c                   @   s<   e Zd ZdZededddd�ZeeƒZ	e
eegZdd„ ZdS )	ÚPlot3daC  
    Draws lines between points.

    **Function signatures**::

        plot3d(x, y, z, ...)
        plot3d(x, y, z, s, ...)

    x, y, z and s are numpy arrays or lists of the same shape. x, y and z
    give the positions of the successive points of the line. s is an
    optional scalar value associated with each point.çš™™™™™™?Nzfilter.radiusz�radius of the tubes used to represent the
                        lines, If None, simple lines are used.
                        )Zadaptsr:   c                 O   sf   | j |i |¤Ž| _| dd¡ |  |¡ | jdd… | _| jd du r^| j t¡ | j t	¡ |  
¡ S )úR Override the call to be able to choose whether to apply
        filters.
        r¸   NÚtube_radius)rE   rF   rO   rD   rG   r/   r-   ra   r   r   rH   rI   r+   r+   r0   r@   *  s    
zPlot3d.__call_internal__)rh   ri   rj   r5   r&   r#   r  r"   r   rE   r   r   r   rG   r@   r+   r+   r+   r0   r    s   þ
r  c            	      C   s²   d\} }t jd }t  ddt j d|  |¡}||  }t  |¡dt  || |  ¡d   }t  |¡dt  || |  ¡d   }t  || |  ¡d }t|||t  |¡ddd	�}|S )
z Generates a pretty set of lines.©r¥   r‘   ç     @�@ç        ru   rå   r   r  rö   )r  rw   )rx   rz   Úaranger|   r{   Úplot3d)	Ún_merÚn_longÚdphiÚphiÚmur   r€   r�   Úlr+   r+   r0   Útest_plot3d<  s    
$$r  c           
   	   c   sÈ   | dur| nt ƒ } d\}}tjd }t ddtj d|  |d¡}|| }| j}tdƒD ]j}t |¡d	t || | tj|d	  d
  ¡d   }t |tj|d	  d  ¡}	|j||	d� dV  qXdS )z0Generates a pretty set of lines and animates it.Nr	  r
  r  ru   rå   Údr„   r   g      @r›   )r   rÈ   )	r  rx   rz   r  ro   r†   r|   r{   rô   )
r‡   r  r  r  r  r  rˆ   r‰   r   rÈ   r+   r+   r0   Útest_plot3d_animI  s    
ÿÿr  c                   @   s   e Zd ZdZeeƒZegZdS )ÚImShowzµ
    View a 2D array as an image.

    **Function signatures**::

        imshow(s, ...)

    s is a 2 dimension array. The values of s are mapped to a color using
    the colormap.N)	rh   ri   rj   r5   r"   r   rE   r   rG   r+   r+   r+   r0   r  `  s   
r  c                  C   s   t j d¡} t| dd�S )z6 Use imshow to visualize a 2D 10x10 random array.
    )r„   r„   Z
gist_earth©rw   )rx   ÚrandomÚimshow©r‚   r+   r+   r0   Útest_imshows  s    r  c                   @   s@   e Zd ZdZeeƒZeee	gZ
eddd�Zedd�Zdd„ ZdS )	ÚSurfaª  
    Plots a surface using regularly-spaced elevation data supplied as a 2D
    array.

    **Function signatures**::

        surf(s, ...)
        surf(x, y, s, ...)
        surf(x, y, f, ...)

    s is the elevation matrix, a 2D array, where indices along the first
    array axis represent x locations, and indices along the second array
    axis represent y locations.

    x and y can be 1D or 2D arrays such as returned by numpy.ogrid or
    numpy.mgrid. Arrays returned by numpy.meshgrid require a transpose
    first to obtain correct indexing order.
    The points should be located on an orthogonal grid (possibly
    non-uniform). In other words, all the points sharing a same
    index in the s array need to have the same x or y value. For
    arbitrary-shaped position arrays (non-orthogonal grids), see the mesh
    function.

    If only 1 array s is passed, the x and y arrays are assumed to be
    made from the indices of arrays, and an uniformly-spaced data set is
    created.

    If 3 positional arguments are passed the last one must be an array s,
    or a callable, f, that returns an array. x and y give the
    coordinates of positions corresponding to the s values.r   a'  scale of the z axis (warped from
                        the value of the scalar). By default this scale
                        is a float value.

                        If you specify 'auto', the scale is calculated to
                        give a pleasant aspect ratio to the plot,
                        whatever the bounds of the data.

                        If you specify a value for warp_scale in
                        addition to an extent, the warp scale will be
                        determined by the warp_scale, and the plot be
                        positioned along the z axis with the zero of the
                        data centered on the center of the extent. If you
                        are using explicit extents, this is the best way
                        to control the vertical scale of your plots.

                        If you want to control the extent (or range)
                        of the surface object, rather than its scale,
                        see the `extent` keyword argument.
                        r9   úßboolean mask array to suppress some data points.
                 Note: this works based on colormapping of scalars and will
                 not work if you specify a solid color using the
                 `color` keyword.c              	   O   sœ  | j |i |¤Ž| _| dd¡ d|vrÎd|vrÎz(| jjj\}}}}}}| jjj\}}	W n6 tyŒ   | jjj\}}}}}}| jjj\}}	Y n0 |	| ||  |	| ||  g}
t|
ƒdk sÆt	|
ƒdkrÎt
dƒ d|v �r˜|d dk�s˜d|v �r˜t
d	ƒ |d \}}}}}}	d
||	  }z| jjj\}}W n" t�yL   | jjj\}}Y n0 |d t|| ƒ }|||d   }|| }	||||||	f|d< d|d< nâ| dd¡dk�rzd|v �rÈd|v �rrt
dƒ nªz(| jjj\}}}}}}| jjj\}}	W n8 t�y(   | jjj\}}}}}}| jjj\}}	Y n0 |	| }d|| ||   }|d
|  }|d
|  }	||||||	f|d< d|d< |  |¡ | jdd… | _|  ¡ S )úG Override the call to be able to scale automatically the axis.
        r¸   NÚ
warp_scalerÛ   ç{®Gáz„?éd   z³Warning: the range of your scalar values differs by more than a factor 100 than the range of the grid values and you did not specify a warp_scale. You could try warp_scale="auto".rl   znWarning: both warp_scale and extent keyword argument specified, the z bounds of the extents will be overriddenrå   r   z5Warning: extent specified, warp_scale='auto' ignored.g333333Ó?ç      ð?)rE   rF   rO   ÚdataZboundsZscalar_rangeÚAttributeErrorZ
image_dataÚminÚmaxÚprintÚabsrn   rD   rG   r/   rH   )rA   r,   r-   ÚxiZxfÚyiZyfrN   ZziÚzfZaspect_ratiosZzoÚsiZsfZz_spanZz0Zdzr+   r+   r0   r@   ¹  s\     ÿ




zSurf.__call_internal__N)rh   ri   rj   r5   r"   r   rE   r   r   r   rG   r'   r   r    Úmaskr@   r+   r+   r+   r0   r  {  s   

r  c                  C   s2   t jddd…ddd…f \} }t| |t  | d¡ƒS )z-Test Surf with a simple collection of points.r   rÊ   r   r  )rx   rÌ   ÚsurfÚasarray)r   r€   r+   r+   r0   Útest_simple_surfú  s    r1  c                 c   sP   | dur| nt ƒ } | j}|j}tdƒD ]$}t |d |d  d¡|_dV  q&dS )z<Test Surf with a simple collection of points and animate it.Nr„   r…   r   r  )r1  ro   r   r†   rx   r0  rÈ   )r‡   rˆ   r   r‰   r+   r+   r0   Útest_simple_surf_animÿ  s    r2  c                  C   s6   dd„ } t jddd…ddd…f \}}t||| ƒ}|S )	z7Test surf on regularly spaced co-ordinates like MayaVi.c                 S   s>   t jt j }}|| | ƒ|d|  | ƒ |d|  d|  ƒ S ©Nru   rÊ   rs   ©rx   r{   r|   ©r   r€   r{   r|   r+   r+   r0   rØ     s    ztest_surf.<locals>.fç      Àç333333@r…   ç      Àç333333@rê   ©rx   rÌ   r/  ©rØ   r   r€   r‚   r+   r+   r0   Ú	test_surf  s    r<  c                  C   s4   ddd„} t jddd…ddd…f \}}t||| ƒS )	Nru   r   c                 S   s�   t j}t j}d||| d  || d  ƒ|| d  || d  ƒ d| || d  |d  ƒ |d| |  ƒ   dd||d  ƒ    d S )zY Multiphoton shrodinger cat. eta is the fidelity, alpha the number
            of photonsr   ru   )rx   r|   Úexp)r   r€   ÚalphaÚetaZpurityr|   r=  r+   r+   r0   Úcat  s    ÿÿþýýztest_surf_wigner.<locals>.catr×   r›   r…   )ru   r   r   r:  )r@  r   r€   r+   r+   r0   Útest_surf_wigner  s    
	rA  c                   @   s†   e Zd ZdZedddddœdd�Zed	d
d�Zededdd�Ze	dd�Z
e	dd�Zeddddddd�ZeeƒZeeeegZdd„ ZdS )ÚMeshaC  
    Plots a surface using grid-spaced data supplied as 2D arrays.

    **Function signatures**::

        mesh(x, y, z, ...)

    x, y, z are 2D arrays, all of the same shape, giving the positions of
    the vertices of the surface. The connectivity between these points is
    implied by the connectivity on the arrays.

    For simple structures (such as orthogonal grids) prefer the `surf`
    function, as it will create more efficient data structures. For mesh
    defined by triangles rather than regular implicit connectivity, see the
    `triangular_mesh` function.
    r´   Zdata_scaling_offZscale_by_scalarZscale_by_vector)r´   ZscalarZvectorz\the scaling mode for the glyphs
                            ('vector', 'scalar', or 'none').r9   rê   zgscale factor of the glyphs used to represent
                        the vertices, in fancy_mesh mode. ©Údescr  Nz�radius of the tubes used to represent the
                        lines, in mesh mode. If None, simple lines are used.
                        rÇ   r  ÚsurfaceZ	wireframeZpointsÚmeshÚ	fancymeshz-the representation type used for the surface.c                 O   sÀ   | j |i |¤Ž| _| dd¡ |  |¡ | jdd… | _| jd dvrz| j t¡ | j t	¡ | j t
¡ tg| j | _n>| jd du r”| j t	¡ | jd dks®| j t
¡ d| jd< |  ¡ S )r  r¸   NÚrepresentation)rF  rG  r  rG  rE  )rE   rF   rO   rD   rG   r/   r-   ra   r   r   r   r   rH   rI   r+   r+   r0   r@   W  s    

zMesh.__call_internal__)rh   ri   rj   r5   r&   rµ   r#   rm   r  r    rÈ   r.  rH  r"   r   rE   r   r   r   r   rG   r@   r+   r+   r+   r0   rB  &  s0   þýÿÿ


þÿrB  c                  C   sú   t j} t j}t j}| d | d  }}t jd| |d  |…dd|  |d  |…f \}}d}d}d}	d}
d}d}d}d}||| ƒ| ||	| ƒ|
  ||| ƒ|  ||| ƒ|  }|||ƒ ||ƒ }|||ƒ }|||ƒ ||ƒ }t|||dd	�S )
zUA very pretty picture of spherical harmonics translated from
    the octaviz example.g     @o@r   ç      ø?ru   rs   rÊ   r¥   Zboner  ©rx   rz   r|   r{   rÌ   rF  )rz   r|   r{   r  Zdthetar  ÚthetaZm0Úm1Úm2Zm3Zm4Zm5Zm6Zm7rÑ   r   r€   r�   r+   r+   r0   Ú	test_meshq  s0    ÿ
ÿÿrN  r#  ©r"  r"  Újetc                 C   s�   t j}t j}t j}|d d }|d d }t jd||…dd| |…f \}}	| ||ƒ ||	ƒ }
| ||ƒ ||	ƒ }| ||ƒ }t|
|||d�S )zCreate a simple sphere.r   rä   r   ru   r  rJ  )rÑ   Únptsrw   rz   r|   r{   Únp_phiÚnp_thetar  rK  r   r€   r�   r+   r+   r0   Útest_mesh_sphere‹  s    "rT  c                 c   s    | dur| n
t |||ƒ} tj}tj}|d d }|d d }tjd||…dd| |…f \}}	| j}
tddƒD ],}||d  ||ƒ }|
j||d� dV  qndS )	z&Create a simple sphere and animate it.Nr   rä   r   ru   r„   rv   )r�   rÈ   )rT  rx   rz   r|   rÌ   ro   r†   rô   )r‡   rÑ   rQ  rw   rz   r|   rR  rS  r  rK  rˆ   r‰   r�   r+   r+   r0   Útest_mesh_sphere_anim˜  s    "rU  c                 C   s  t j}t j}t j}|d d }|d d }t jd||…dd| |…f \}}| ||ƒ ||ƒ }	| ||ƒ ||ƒ }
| ||ƒ }t  |	¡ t¡}d|ddd…< d|dd…ddd…f< t|	|
|||d�}t j	d	d
d�}d|d< d|d< d|dd…df< ||j
jj_|S )a  Create a sphere with masking and using a custom colormap.

    Note that masking works only when scalars are set.  The custom colormap
    illustrates how one can completely customize the colors with numpy arrays.
    In this case we use a simple 2 color colormap.
    r   rä   r   ru   TNr›   )rÈ   r.  )ru   rs   Zuint8)Zdtypeéÿ   )r   ru   )r   r   rÊ   )rx   rz   r|   r{   rÌ   rÎ   rÜ   ÚboolrF  ÚzerosZmodule_managerZscalar_lut_managerZlutÚtable)rÑ   rQ  rz   r|   r{   rR  rS  r  rK  r   r€   r�   r.  ÚmÚcolorsr+   r+   r0   Útest_mesh_mask_custom_colors¨  s&    "r\  c            
      C   sî   t j} t j}| d | d  }}t jd| |d  |…dd|  |d  |…f \}}d||ƒ ||d|  d  ƒ ||d|  d  ƒ d	 }d||ƒ ||d|  d  ƒ ||d|  d  ƒ d	 }||d|  d  ƒ }t|||d
ddd�}	|	S )zDCreate a fancy looking mesh using mesh (example taken from octaviz).g      4@r!  rI  r   ru   r   rÊ   g      @rå   rG  g¸…ëQ¸~?ZRdYlGn)rH  r  rw   )rx   rz   r|   rÌ   rF  )
rz   r|   ZduZdvrÒ   rÓ   r   r€   r�   rZ  r+   r+   r0   Útest_fancy_meshÐ  s    288
ÿr]  c                   @   s    e Zd ZdZeeƒZeegZ	dS )ÚContourSurfa&  
    Plots a the contours of a surface using grid-spaced data for
    elevation supplied as a 2D array.

    **Function signatures**::

        contour_surf(s, ...)
        contour_surf(x, y, s, ...)
        contour_surf(x, y, f, ...)

    s is the elevation matrix, a 2D array. The contour lines plotted
    are lines of equal s value.

    x and y can be 1D or 2D arrays (such as returned by numpy.ogrid or
    numpy.mgrid), but the points should be located on an orthogonal grid
    (possibly non-uniform). In other words, all the points sharing a same
    index in the s array need to have the same x or y value. For
    arbitrary-shaped position arrays (non-orthogonal grids), see the mesh
    function.

    If only 1 array s is passed, the x and y arrays are assumed to be
    made from the indices of arrays, and an uniformly-spaced data set is
    created.

    If 3 positional arguments are passed the last one must be an array s,
    or a callable, f, that returns an array. x and y give the
    coordinates of positions corresponding to the s values.N)
rh   ri   rj   r5   r"   r   rE   r   r   rG   r+   r+   r+   r0   r^  à  s   r^  c                  C   s6   dd„ } t jddd…ddd…f \}}t||| ƒ}|S )	z?Test contour_surf on regularly spaced co-ordinates like MayaVi.c                 S   s>   t jt j }}|| | ƒ|d|  | ƒ |d|  d|  ƒ S r3  r4  r5  r+   r+   r0   rØ     s    ztest_contour_surf.<locals>.fr6  r7  r…   r8  r9  rê   )rx   rÌ   Úcontour_surfr;  r+   r+   r0   Útest_contour_surf  s    r`  )ÚcubeZ
2dtriangleZ2dsquareZ2dvertexZ2dthick_crossZ	2ddiamondZ2dcrossZ2dcirclec                   @   sL   e Zd ZdZeeƒZegZe	de
dd�Zeddd�Zeddd�Zd	d
„ ZdS )ÚBarCharta)  
    Plots vertical glyphs (like bars) scaled vertical, to do
    histogram-like plots.

    This functions accepts a wide variety of inputs, with positions given
    in 2-D or in 3-D.

    **Function signatures**::

        barchart(s, ...)
        barchart(x, y, s, ...)
        barchart(x, y, f, ...)
        barchart(x, y, z, s, ...)
        barchart(x, y, z, f, ...)

    If only one positional argument is passed, it can be a 1-D, 2-D, or 3-D
    array giving the length of the vectors. The positions of the data
    points are deducted from the indices of array, and an
    uniformly-spaced data set is created.

    If 3 positional arguments (x, y, s) are passed the last one must be
    an array s, or a callable, f, that returns an array. x and y give the
    2D coordinates of positions corresponding to the s values.

    If 4 positional arguments (x, y, z, s) are passed, the 3 first are
    arrays giving the 3D coordinates of the data points, and the last one
    is an array s, or a callable, f, that returns an array giving the
    data value.
    ra  z%The glyph used to represent the bars.rC  rÙ   zOThe lateral scale of the glyph, in units of the distance between nearest pointsTzlwhether to compute automatically the lateral scaling of the glyphs. This might be computationally expensive.c                 O   s  t j| g|¢R i |¤Ž}|jj}d|vr4|jd |_d|_d|j_d|jj_d|vr\d|j_d|vrld	|j_	d|jj_
t|ƒd
ksˆ| jrŽd
}n*|jj|jj|jj  }}}t |||¡}|jjj| }	| d| j¡}
z$|
|	 |jjj_|
|	 |jjj_W n t�y   Y n0 |S )r  rÚ   Zcube_sourceÚtail)r  r  rå   Fr·   Zcolor_by_scalarrµ   Zscale_by_vector_componentsr   Úlateral_scale)r8   r@   rp   Zglyph_sourceZ
glyph_dictZglyph_positionÚcenterZorientZ
color_moderµ   rq   ÚlenÚ
auto_scalero   r   r€   r�   r   Z_min_axis_distancerm   rO   rd  Zy_lengthZx_lengthr)   )rA   r,   r-   rr   ZgsZmin_axis_distancer   r€   r�   rm   rd  r+   r+   r0   r@   E  s6    

ÿÿ
ÿzBarChart.__call_internal__N)rh   ri   rj   r5   r"   r   rE   r   rG   r&   Úbar_mode_dictrÚ   r#   rd  r!   rg  r@   r+   r+   r+   r0   rb    s   ÿrb  c                  C   s   t  t j d¡¡} t| ƒS )z. Demo the bar chart plot with a 2D array.
    )rÊ   rÊ   )rx   r)  r  Úbarchartr  r+   r+   r0   Útest_barchartn  s    rj  c                   @   s   e Zd ZdZeeƒZdS )ÚTriangularMeshaJ  
    Plots a surface using a mesh defined by the position of its vertices
    and the triangles connecting them.

    **Function signatures**::

        triangular_mesh(x, y, z, triangles ...)

    x, y, z are arrays giving the positions of the vertices of the surface.
    triangles is a list of triplets (or an array) list the vertices in
    each triangle. Vertices are indexes by their appearance number in the
    position arrays.

    For simple structures (such as rectangular grids) prefer the surf or
    mesh functions, as they will create more efficient data structures.
    N)rh   ri   rj   r5   r"   r   rE   r+   r+   r+   r0   rk  v  s   rk  c                  C   s¢   d} t  t j t j| ¡}t  d| ¡}|j ¡ }|j ¡ }t  |¡}dd„ td| ƒD ƒ}t j	d|f }t j	d|f }t j	d|f }t j	d|f }t
|||||d�S )zRAn example of a cone, ie a non-regular mesh defined by its
        triangles.
    rŽ   rä   c                 S   s   g | ]}d ||d f‘qS )r   r   r+   )rK   r‰   r+   r+   r0   rS   ˜  rT   z(test_triangular_mesh.<locals>.<listcomp>r   r   )rÈ   )rx   ry   rz   r=  ÚrealrU   ÚimagrÎ   r†   Zr_Útriangular_mesh)r½   r~   r�   r   r€   Z	trianglesr+   r+   r0   Útest_triangular_mesh�  s    


ro  Úpoint_pickerr  c                 C   s&   | d u rt  ¡ } | jj |||¡ d S r*   )r   r?   r<   ZpickerÚset_picker_props)r;   Z	pick_typeZ	toleranceZ
text_colorr+   r+   r0   rq  ¡  s    rq  )N)N)N)N)N)N)r#  rO  rP  )Nr#  rO  rP  )r#  rO  )Nrp  r  N)mr5   Úmodulesr   r   r   r   r   r   r   r	   r
   Úsourcesr   r   r   r   r   r   r   r   r   Úfiltersr   r   r   r   r   r   Zanimatorr   Zmayavi.core.scener   Zauto_docr   r   r3   r   Z
traits.apir    r!   r"   r#   r$   r%   r&   r'   r(   r)   Únumpyrx   r7   r8   rk   r}   rƒ   rŠ   rÅ   rÆ   rÏ   rÕ   rã   rç   rè   rë   rì   ró   rõ   r÷   rø   rû   rý   r   r  r  r  r  r  r  r  r  r  r  r  r  r/  r1  r2  r<  rA  rB  rF  rN  rT  rU  r\  r]  r^  r_  r`  Údictrh  Úitemrb  ri  rj  rk  rn  ro  rq  r+   r+   r+   r0   Ú<module>   s–   ,, 0S/

 

0


	
	&

|
H


("
S

