3
ÐÆ‘[ŽE ã               @   sŽ  d Z ddlmZ ddlZddlZddlZddl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mZmZmZ ddl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& ddl'm(Z( da)dd„ Z*dd„ Z+dd„ Z,dd„ Z-dd„ Z.dd„ Z/dd„ Z0dd„ Z1dd„ Z2dd „ Z3d!d"„ Z4d#d$„ Z5d%d&„ Z6d'd(„ Z7G d)d*„ d*e&ƒZ8G d+d,„ d,eƒZ9G d-d.„ d.ej:ƒZ;G d/d0„ d0eƒZ<G d1d2„ d2eƒZ=G d3d4„ d4eƒZ>G d5d6„ d6eƒZ?G d7d8„ d8eƒZ@G d9d:„ d:eƒZAG d;d<„ d<eƒZBG d=d>„ d>eƒZCG d?d@„ d@eƒZDG dAdB„ dBeƒZEe@ZFe;ZGe<ZHe=ZIe>ZJe?ZKeAZLeBZMeCZNeDZOeEZPejQjRZSdCdD„ ZTdEdF„ ZUdGdH„ ZVdIdJ„ ZWdKdL„ ZXdMdN„ ZYdOdP„ ZZdS )Qa~  A module that provides VPython like capabilities.  For more
details about VPython, refer the official website.
VPython : http://www.vpython.org/index.html

The API is based on VPython, but instead of using OpenGL and other C
libraries, this is based completly on TVTK, and Traits and Numpy.
All of the demos are also translated from VPython examples.

The implementation is done using object oriented design, and each
visualization capability is implemented as a seperate traits class.
The attributes of each class could be independently edited.

The API is kept as similar to VPython as much as possible.

This module offers the following classes :

 Display actors
 sphere, cylinder, cone, box, arrow, curve, ring, helix, ellipsoid

 Functionality classes
 frame, vector, animator

 Utility functions
 iterator, remove_actor, show

To see examples of classes and functions look at the `test_*`
functions at the end of this file. Here is a quick example
demonstrating how to use visual.

Note: The visual module should be interactively used in ipython only when
--gui=qt is enabled. `visual` will not work properly in an interactive mode
with the vanilla python interpretor.  ::

    $ ipython --gui=qt

    In [1]: from tvtk.tools import visual
    In [2]: visual.test_sphere()
    In [3]: s = visual.sphere() # Create a sphere actor
    In [4]: s.edit_traits() # Edit sphere actor's properties via GUI

é    )Úprint_functionN)ÚsinÚcosÚpiÚsqrtÚacos)Ú	HasTraitsÚTraitÚInstanceÚTupleÚIntÚRangeÚButtonÚArrayÚBoolÚAnyÚListÚEnum)ÚViewÚItemÚGroup)Útvtk)Úivtk)Úconfigure_input)ÚGUI)ÚTimer)Úvtk_color_traitc              C   s    t jdd�} d| j_tjƒ  | S )z<Creates and retunrs the ivtk viewer to get_viewer() functionF)Zbrowserr   )r   r   r   )r   ÚviewerÚsceneÚ
backgroundr   Úprocess_events)Úv© r"   úT/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/tvtk/tools/visual.pyÚ_create_viewerM   s    r$   c             C   s   | a dS )z¥Set the global viewer.  Handy if you need to use visual from your
    own viewer.  Pass an object that has a `scene` trait containing a
    tvtk scene instance.
    N)Ú_viewer)r   r"   r"   r#   Ú
set_viewerT   s    r&   c            	   C   s6   t dkrtƒ a n"yt jjƒ  W n   tƒ a Y nX t S )zî Creates and returns an ivtk viewer. If the fuction is called
    1st time than creates and returns the viewer, otherwise the
    originally created viewer itself is returned. Checking is done
    through the global variable _viewer.
    N)r%   r$   r   Úrenderr"   r"   r"   r#   Ú
get_viewer\   s    r(   c              G   s    t ƒ }|jj| ƒ |jjƒ  dS )zn Gets an ivtk viewer from the function get_viewer() and adds
    all the actors given, to the ivtk scene.
    N)r(   r   Z
add_actorsÚ
reset_zoom)Útvtk_actorsr!   r"   r"   r#   Ú
show_actorq   s    r+   c              G   s0   t ƒ }x$| D ]}|jj|jƒ |jjƒ  qW dS )zo Gets the ivtk viewer from the function get_viewer() and
    removes all the actors given, from the ivtk scene.N)r(   r   Zremove_actorsÚactorr)   )r*   r!   Úxr"   r"   r#   Úremove_actory   s    
r.   c              C   s(   dt jks$dt jkrntƒ } | jƒ  dS )zºThis function has to be called at the end in a stand alone
    visual program. Note - Don't call this function when running
    visual from ipython iterpretor in an interactive mode
    z-wthreadz--guiN)ÚsysÚargvr   Zstart_event_loop)Úguir"   r"   r#   Úshow�   s    r2   c             O   s   t | |f|ž|ŽS )zˆCreates an instance of utility class Animator and returns it,
    used for programs with animations, see examples for demonstration
    )ÚAnimator)ÚmillisecÚcallableÚargsÚkwargsr"   r"   r#   ÚiterateŒ   s    r8   c             C   s   ||  }|| |dd…< |S )z±Translate function takes 3 arguments the old position, new
    position and the points. The function translates all the points to
    the new position and returns the new pointsNr"   )ÚoldÚnewÚpointsÚdiffr"   r"   r#   Ú	translate’   s    r=   c             C   s   ||  |dd…< |S )zÎTranslate function takes 2 arguments the with which the points
    are required to be translated and the points. The function
    translates all the points to the new position and returns the new
    pointsNr"   )r<   r;   r"   r"   r#   Útranslate_pointsš   s    r>   c       	      C   sz  t j| td�} | tt j| | ƒƒ } | d }| d }| d }|t d }t|ƒ}t|ƒ}t jdtƒ}|d| ||   |d d< d| | | ||  |d d< d| | | ||  |d d< d| | | ||  |d d< |d| ||   |d d< d| | | ||  |d d< d| | | ||  |d d< d| | | ||  |d d< |d| ||   |d d< |S )zWCreate a rotation matrix given an axis and an angle (in
    degrees) to rotate by.
    )Údtyper   é   é   é´   é   )rC   rC   )	ÚnumpyÚasarrayÚfloatr   Úinnerr   r   r   Úzeros)	ÚaxisÚangler-   ÚyÚzÚtÚcostZsintZrotatorr"   r"   r#   Ú_create_rotation_matrix¢   s&          rO   c             C   s  | t ttj| | ƒƒƒ }|ttj||ƒƒ }tj||ƒ}tt|ƒd ƒdk rˆ|dk r„| }t||ƒ}| |dd…< |}t||ƒ}|S |S t|ƒ}tj||ƒ}	t	|	d| t
 ƒ}
tj|dƒrÔtj||
jƒ|dd…< |S | }t||ƒ}tj||
jƒ|dd…< |}t||ƒ}|S dS )a  The function takes 4 arguments, the old and the new axis, the
    position and points. All arguments should be given as a numpy
    array, The first 3 can also be given in form of a tuple. The
    function rotates all the points so that they become aligned with
    the new axisg      ð?g»½×Ùß|Û=r   Ng     €f@g        )rF   r   rD   rG   ÚdotÚabsr>   r   ÚcrossrO   r   ÚallcloseÚT)r9   r:   Úposr;   ÚoÚnZdpdtr<   ÚalphaÚraxisÚdatar"   r"   r#   Úaxis_changed¼   s0    



r[   c       	      C   sì   t | |ƒ}tj|dƒrPtj|dƒrPtj||jƒ|dd…< tj||jƒ}|||fS d|d  d|d  d|d  f}|| }t||ƒ}tj||jƒ|dd…< tj||jƒ}|d |d |d f}t||ƒ}|| }tj||jƒ}|||fS dS )	a]  Rotate function takes 6 arguments the axis about which the
    actor has to be rotated, the angle with which the actor has to be
    rotated, the point (origin) about which actor has to be rotated
    and posistion, points and current axis of the actor. The function
    returns the new position, points and axis of the actor after the
    rotation.g        Nr@   r   rA   éÿÿÿÿr\   r\   )rO   rD   rS   rP   rT   r>   )	rI   rJ   ÚoriginrU   r;   ÚmaxisrZ   rY   r<   r"   r"   r#   Úrotateæ   s    

"

r_   c             C   sx   t j| td�} t| |ƒ}t j|dƒr:t j||jƒ}||fS || }t j||jƒ}|| }|tt j||ƒƒ }||fS dS )aN  Rotate function takes 5 arguments the axis about which the
    actor has to be rotated, the angle with which the actor has to be
    rotated, the point (origin) about which actor has to be rotated
    and posistion, and current axis of the actor. The function returns
    the new position and new axis of the actor after the rotation.)r?   g        N)	rD   rE   rF   rO   rS   rP   rT   r   rG   )rI   rJ   r]   rU   r^   rZ   rY   r"   r"   r#   Úrotate_single_pointÿ   s    
r`   c             C   s¨   t j| td�}t j|ƒ}t j|dƒr>t j||jƒ|dd…< |S d|d  d|d  d	|d  f}t||ƒ}t j||jƒ|dd…< |d |d |d f}t||ƒ}|S dS )
zÇScale function takes 2 arguments the scaling_factor in a form
    of list, or a tuple giving the scale factor for x,y and z
    axis. The function returns the new points ofthe actor after
    scaling)r?   g        Nr@   r   rA   r\   r\   r\   )rD   rE   rF   ÚdiagrS   rP   rT   r>   )Úscale_factorr;   rU   ÚscrZ   r<   r"   r"   r#   Úscale  s    
"

rd   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚVTimerc             O   s2   t j| ||f|ž|Ž tƒ | _| jj| jdƒ d S )NÚclosing)r   Ú__init__r(   r   Úon_trait_changeÚ_close)ÚselfÚ	millisecsr5   r6   Úkw_argsr"   r"   r#   rg   +  s    zVTimer.__init__c             C   s   | j ƒ  tdƒ d S )Nz5Stopping iterations since the viewer has been closed.)ÚStopÚprint)rj   r"   r"   r#   ri   1  s    zVTimer._closec             C   sJ   y| j | j| jŽ W n0 tk
r0   | jƒ  Y n   | jƒ  ‚ Y nX dS )z/Overridden to call the given callable.
        N)r5   r6   rl   ÚStopIterationrm   )rj   r"   r"   r#   ÚNotify5  s    zVTimer.NotifyN)Ú__name__Ú
__module__Ú__qualname__rg   ri   rp   r"   r"   r"   r#   re   *  s   re   c               @   s˜   e Zd ZedƒZedƒZeddddd�Zee	ƒZ
eedd	d
�edƒedd	d
�edƒdd�Zeeedd�ddgdd�Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r3   zStart AnimationzStop Animationr@   i † éd   z.Specifies frequency with which timer is called)ÚdescÚstart_animationÚsimple)ÚstyleÚ_Ústop_animationF)Úshow_labelsÚtime_period)ÚnamezAnimation ControlerÚOKéú   )ÚtitleÚbuttonsÚwidthc             O   s   || _ t||f|ž|Ž| _d S )N)r|   re   Úitimer)rj   r4   r5   r6   r7   r"   r"   r#   rg   [  s    zAnimator.__init__c             C   s   | j jƒ  d S )N)rƒ   ÚStart)rj   r"   r"   r#   Ú_start_animation_fireda  s    zAnimator._start_animation_firedc             C   s   | j jƒ  d S )N)rƒ   rm   )rj   r"   r"   r#   Ú_stop_animation_firedd  s    zAnimator._stop_animation_firedc             C   s6   | j }|d krd S ||_|jƒ r2|jƒ  |j|ƒ d S )N)rƒ   r4   Ú	IsRunningrm   r„   )rj   ÚvaluerM   r"   r"   r#   Ú_time_period_changedg  s    zAnimator._time_period_changedN)rq   rr   rs   r   rv   rz   r   r|   r
   re   rƒ   r   r   Zevent_groupr   Útraits_viewrg   r…   r†   r‰   r"   r"   r"   r#   r3   @  s"   
r3   c               @   sˆ   e Zd ZdZddd„Zdd„ Zdd„ ZeeeƒZd	d
„ Z	dd„ Z
ee	e
ƒZdd„ Zdd„ ZeeeƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚMVectorzNMVector class gives many of the functionalities given by Vector
    of VPythonç        c             C   s0   t j|||ftƒ}t jj| d|tdd�}|jƒ S )NrC   F)ÚshapeÚbufferr?   Úorder)rC   )rD   ÚarrayrF   ÚndarrayÚ__new__Úcopy)Úsubtyper-   rK   rL   rZ   Úretr"   r"   r#   r’   s  s
    
zMVector.__new__c             C   s   | d S )Nr   r"   )rj   r"   r"   r#   Ú_get_xz  s    zMVector._get_xc             C   s   || d< d S )Nr   r"   )rj   Úvalr"   r"   r#   Ú_set_x}  s    zMVector._set_xc             C   s   | d S )Nr@   r"   )rj   r"   r"   r#   Ú_get_y‚  s    zMVector._get_yc             C   s   || d< d S )Nr@   r"   )rj   r—   r"   r"   r#   Ú_set_y…  s    zMVector._set_yc             C   s   | d S )NrA   r"   )rj   r"   r"   r#   Ú_get_zŠ  s    zMVector._get_zc             C   s   || d< d S )NrA   r"   )rj   r—   r"   r"   r#   Ú_set_z�  s    zMVector._set_zc             C   s4   | j |j  }| j|j }| j|j }|| | }|S )z¤ Function performs the dot vector multiplication of 2
        vector instances and returning a new vector instance equal to
        the dot product of given vectors)r-   rK   rL   )Úvec1Úvec2ÚiÚjÚkrP   r"   r"   r#   rP   ’  s
    zMVector.dotc             C   sX   | j |j | j|j   }| j|j | j|j  }| j|j  | j |j  }t|||ƒ}|S )zª Function performing the cross vector multiplication of 2
        vector instances and returning a new vector instance equal to
        the cross product of given vectors)rK   rL   r-   r‹   )r�   rž   rŸ   r    r¡   rR   r"   r"   r#   rR   œ  s
    zMVector.crossc             C   s,   t | d d | d d  | d d  ƒ}|S )z8 Function computes and returns the magnitude of a vectorr   rA   r@   )r   )ÚvecÚmagr"   r"   r#   r£   ¦  s    (zMVector.magc             C   s   | t tj| | ƒƒ }|S )zL Function computes and returns the normalized form of a
        given vector)r   rD   rG   )r¢   Únormr"   r"   r#   r¤   «  s    zMVector.normN)rŒ   rŒ   rŒ   )rq   rr   rs   Ú__doc__r’   r–   r˜   Úpropertyr-   r™   rš   rK   r›   rœ   rL   rP   rR   r£   r¤   r"   r"   r"   r#   r‹   p  s   





r‹   c            	   @   sô   e Zd ZdZed+dd�Zed,dddd�Zed-ddd	d�Zed.ddd
d�Z	ed/dd�Z
eZedƒZeZeeeddd�eddd�eddd�edd�ddd�dgd�Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zejdddgƒfd(d)„Zd*S )0ÚFramez~Frame groups together all the actors given to it into a single
    unit, so that they can be manipulated as a combined entity.ç      ð?ç        zthe frame axis)rˆ   ru   g°÷™9ý~z!the X coordinate of frame objects)ru   z!the Y coordinate of frame objectsz!the Z coordinate of frame objectszthe frame posTr-   zPos X)r}   ÚlabelrK   zPos YrL   zPos ZÚ
visibility)r}   zFrame Properties)rª   Úshow_borderr~   )r�   c             O   sn   t |ƒ| _tj| f|Ž t |jƒ ƒ| _| jtjdddgƒ| jƒ | j	d| j
ƒ | jd| jƒ | jd| jƒ d S )Ng        )ÚlistÚargr   rg   ÚkeysÚ_pos_changedrD   r�   rU   Ú
_x_changedr-   Ú
_y_changedrK   Ú
_z_changedrL   )rj   Ú	argumentsÚtraitsr"   r"   r#   rg   Ì  s    
zFrame.__init__c             C   s(   || }x| j D ]}|j| |_qW d S )N)r®   rU   )rj   r9   r:   r<   Úar"   r"   r#   r°   Ú  s    zFrame._pos_changedc             C   s(   || }x| j D ]}|j| |_qW d S )N)r®   r-   )rj   r9   r:   r<   r¶   r"   r"   r#   r±   ß  s    zFrame._x_changedc             C   s(   || }x| j D ]}|j| |_qW d S )N)r®   rK   )rj   r9   r:   r<   r¶   r"   r"   r#   r²   ä  s    zFrame._y_changedc             C   s(   || }x| j D ]}|j| |_qW d S )N)r®   rL   )rj   r9   r:   r<   r¶   r"   r"   r#   r³   é  s    zFrame._z_changedc             C   s‚   t j||ƒrnp|tt j||ƒƒ }|tt j||ƒƒ }t j||ƒ}tt j||ƒƒ}d| t }x| jD ]}|j	||| j
ƒ qfW d S )Ng     €f@)rD   rS   r   rG   rR   r   rP   r   r®   r_   rU   )rj   r9   r:   rV   rW   rY   rX   r¶   r"   r"   r#   Ú_axis_changedî  s    zFrame._axis_changedc             C   sF   t |ƒ}|dkr*x0| jD ]}d|j_qW nx| jD ]}d|j_q2W d S )Nr@   r   )Úintr®   r,   r«   )rj   rˆ   r—   r¶   r"   r"   r#   Ú_visibility_changedý  s    zFrame._visibility_changedc             C   s^   x| j D ]}|j|||ƒ qW tjdddgƒ}t|||| j|| jƒ\}}}| j||dd� d S )Ng      ð?g        F)rU   rI   Útrait_change_notify)r®   r_   rD   r�   rU   rI   Ú	trait_set)rj   rJ   rI   r]   r¶   ÚptsrU   Zfaxisr"   r"   r#   r_     s
    zFrame.rotateN)r¨   r©   r©   g°÷™9ýþg°÷™9ýþg°÷™9ýþ)r©   r©   r©   )rq   rr   rs   r¥   r   rI   r   r-   rK   rL   rU   r   Úobjectsr   r«   r   r   r   r   r   rŠ   rg   r°   r±   r²   r³   r·   r¹   rD   r�   r_   r"   r"   r"   r#   r§   ±  s0   


r§   c               @   s¼  e Zd ZdZeedGdd�ZedHdd�Zedd	d
dd�Z	edIdd�Z
edJd	ddd�ZedKd	ddd�ZedLd	ddd�ZedMƒZedddƒZedƒZeejf d�ZeejƒZeejf d�Zeejf d�Zeejf d�Ze Z!e"e#e$dd�e$dd�e$dd�e$ddd�e$ddd�e$d d!d�e$d"d�d#dd$�	d%gd&�Z%d'd(„ Z&d)d*„ Z'd+d,„ Z(d-d.„ Z)e*j+dddgƒfd/d0„Z,d1d2„ Z-d3d4„ Z.d5d6„ Z/d7d8„ Z0d9d:„ Z1d;d<„ Z2d=d>„ Z3d?d@„ Z4dAdB„ Z5dCdD„ Z6dEdF„ Z7dS )NÚCurvez”Curve class creates a polydata source using point and
    connectivity arrays given by the user, which inturn is used to
    create a polydata actorNrC   zthe points of the curve)r?   r�   ru   ç        zthe curve pos)rˆ   ru   g°÷™9ý~g{®Gáz„?zthe radius of curve tubeç      ð?zthe curve axiszthe X coordinate of curve)ru   zthe Y coordinate of curvezthe Z coordinate of curveÚsÚwÚpT)r6   Úcolor)r}   r«   Úradiusr-   zPos X)r}   rª   rK   zPos YrL   zPos ZÚrepresentationzCurve Properties)rª   r¬   r~   )r�   c             K   s6  | j j| _t| j| jƒ t| j| jƒ d| j_d| j_tj	ƒ }t|| jƒ || j _
| jjƒ  | jjƒ  | j j| _| j| j_t| j ƒ tƒ | _| jj| jjjƒ | j j| jjjƒ | jj| jjjƒ |jdd ƒ}tj| f|Ž | j| jƒ | j| jƒ | j| jƒ | j| jƒ |d k	�r2| jtj dƒtj!|t"d�ƒ d S )Né   r@   rI   ç      ð?ç        )r?   )rÈ   rÉ   rÉ   )#r,   r¦   r   ÚstripperÚpolydataÚtubeÚnumber_of_sidesÚcappingr   ÚPolyDataMapperÚmapperÚupdaterÆ   r+   r(   r   rh   r   r'   Úpopr   rg   Ú_points_changedr;   Ú_color_changedrÄ   r¹   r«   Ú_radius_changedrÅ   r·   rD   r�   rE   rF   )rj   rµ   ÚmrI   r"   r"   r#   rg   =  s4    






zCurve.__init__c             C   s   | j |gƒ dS )zMFunction appeneds new points given as arguments to the
        current pointsN)Úextend)rj   Zpntr"   r"   r#   Úappenda  s    zCurve.appendc             C   sb   | j d kr|}n@| j jd }tj| j |t|ƒ dfƒ}| j |d |…< |||d …< || _ | jƒ  d S )Nr   rC   )r;   r�   rD   ÚresizeÚlenrÑ   )rj   r¼   rÃ   rW   r"   r"   r#   r×   f  s    
zCurve.extendc             C   s.   | j jƒ  | jjƒ  | jjƒ  | jjjƒ  d S )N)rË   ÚmodifiedrÊ   rÑ   rÌ   r   r   r'   )rj   r"   r"   r#   rÑ   q  s    


zCurve.updatec          
   C   s†   t |||| j| jtjdddgƒƒ\}}}| j|dd� | j|dd� | j|dd� | j| j_| jjƒ  | jj	ƒ  | j
j	ƒ  | jƒ  dS )zÿFunction takes atleast 2 arguments: axis about which to
        rotate the actor and angle with which to rotate the actor, the
        3rd agrument is origin i.e. the point about which to rotate
        the actor, by default it is set to the global origing        F)rU   rº   )r;   rº   )rI   rº   N)r_   rU   r;   rD   r�   r»   rË   rÛ   rÊ   rÑ   rÌ   r'   )rj   rJ   rI   r]   rÃ   r   Úaxr"   r"   r#   r_   w  s    (



zCurve.rotatec             C   s   | j }|dk	r|jjƒ  dS )z1Function redraws/refreshs the ivtk viewer's sceneN)r   r   r'   )rj   r!   r"   r"   r#   r'   †  s    zCurve.renderc             C   sÂ   d | j _|| j _|d kr"d}d }n^t| jƒd }tj|dfdƒ}tjd|d ddƒ|d d …df< tjd|d ddƒ|d d …df< || j _| j jƒ  | jj	ƒ  | j
j	ƒ  | j}|d k	r¾|jjƒ  d S )Nr   r@   rA   Úlg      à?)rË   Úlinesr;   rÚ   rD   rH   ÚarangerÛ   rÊ   rÑ   rÌ   r   r   r'   )rj   rˆ   ÚnprÞ   r!   r"   r"   r#   rÓ   Ž  s       


zCurve._points_changedc             C   s$   || _ | j | jd | jd f| _d S )Nr@   rA   )r-   rU   )rj   rˆ   r"   r"   r#   r±   ¡  s    zCurve._x_changedc             C   s$   || _ | jd | j | jd f| _d S )Nr   rA   )rK   rU   )rj   rˆ   r"   r"   r#   r²   ¥  s    zCurve._y_changedc             C   s$   || _ | jd | jd | j f| _d S )Nr   r@   )rL   rU   )rj   rˆ   r"   r"   r#   r³   ©  s    zCurve._z_changedc             C   s†   | j |d dd� | j |d dd� | j |d dd� t||| jƒ}| j |dd� | j| j_| jjƒ  | jjƒ  | jjƒ  | jƒ  d S )	Nr   F)r-   rº   r@   )rK   rº   rA   )rL   rº   )r;   rº   )	r»   r=   r;   rË   rÛ   rÊ   rÑ   rÌ   r'   )rj   r9   r:   rÃ   r"   r"   r#   r°   ­  s    



zCurve._pos_changedc             C   s    t ||| j| jƒ}|jƒ | _d S )N)r[   rU   r;   r“   )rj   r9   r:   r¼   r"   r"   r#   r·   ¹  s    zCurve._axis_changedc             C   s   || j j_d S )N)r,   r¦   rÄ   )rj   rˆ   r"   r"   r#   rÔ   ½  s    zCurve._color_changedc             C   s   | j | j_ d S )N)rÅ   rÌ   )rj   rˆ   r"   r"   r#   rÕ   À  s    zCurve._radius_changedc             C   s    | j | j_ | jjƒ  | jƒ  d S )N)rÆ   r¦   rÛ   r'   )rj   rˆ   r"   r"   r#   Ú_representation_changedÃ  s    

zCurve._representation_changedc             C   s&   t |ƒ}|dkrd| j_nd| j_d S )Nr@   r   )r¸   r,   r«   )rj   rˆ   r—   r"   r"   r#   r¹   È  s    
zCurve._visibility_changed)NrC   )r¿   r¿   r¿   )rÀ   r¿   r¿   g°÷™9ýþg°÷™9ýþg°÷™9ýþ)rÀ   rÀ   rÀ   )8rq   rr   rs   r¥   r   rF   r;   rU   r   rÅ   rI   r-   rK   rL   r   rÄ   r   rÆ   r   r«   r
   r   ÚPolyDatarË   ÚPropertyr¦   ZStripperrÊ   Ú
TubeFilterrÌ   ÚActorr,   r   r   r   r   r   rŠ   rg   rØ   r×   rÑ   rD   r�   r_   r'   rÓ   r±   r²   r³   r°   r·   rÔ   rÕ   rá   r¹   r"   r"   r"   r#   r¾     sV   




$r¾   c               @   s¼  e Zd ZdZeddGd�ZedHdddd	�ZedIdd	�ZedJdd	�Z	e
dKƒZedLdd
dd�ZedMdd
dd�ZedNdd
dd�ZedddƒZeddddd	�ZedƒZeZeejf ƒZeejƒZeejf ƒZeejf ƒZeej ƒ f ƒZ!e"e#e$dd�e$dd�e$ddd�e$dd d�e$d!d"d�e$d#d�e$d$d�e$d%d�d&dd'�
d(gd)�Z%d*d+„ Z&d,d-„ Z'd.d/„ Z(d0d1„ Z)d2d3„ Z*d4d5„ Z+d6d7„ Z,d8d9„ Z-d:d;„ Z.d<d=„ Z/d>d?„ Z0d@dA„ Z1e2j3d
d
d
gƒfdBdC„Z4dDdE„ Z5dFS )OÚRingzjRing class creates a Ring form tvtk polydata, follows
    the usual VTK pipeline and creates a ring actor.Údéh  rC   )r�   g°÷™9ý~g      à?zthe ring radius)rˆ   ru   ç        zthe ring posç      ð?zthe ring axiszthe X coordinate of ring center)ru   zthe Y coordinate of ring centerzthe Z coordinate of ring centerrÁ   rÂ   rÃ   r   g{®Gáz„?zthe ring thicknessTrÅ   )r}   Ú	thicknessr-   zPos X)r}   rª   rK   zPos YrL   zPos ZrÄ   r«   rÆ   zRing Properties)rª   r¬   r~   )r�   c             K   s2  | j j| _tjƒ | _t| j| jƒ t| j| jƒ | jjƒ  | jjƒ  d| j_	d| j_
tjƒ }t|| jƒ || j _| j j| _| j| j_tƒ | _| jj| jjjƒ | j j| jjjƒ | jj| jjjƒ tj| f|Ž | jƒ  | jdddg| jƒ | j| jƒ | j| jƒ | j| jƒ | jtj dƒ| j!ƒ t"| j ƒ d S )NrÇ   r@   ç        ç      ð?)rí   rì   rì   )#r,   r¦   r   ÚPolyDataNormalsÚnormalsr   rË   rÌ   rÑ   rÍ   rÎ   rÏ   rÐ   rÆ   r(   r   rh   r   r'   r   rg   Ú_create_pointsr°   rU   rÔ   rÄ   r¹   r«   Ú_thickness_changedrë   r·   rD   r�   rI   r+   )rj   rµ   rÖ   r"   r"   r#   rg   ø  s2    





zRing.__init__c             C   sì   x^t dddƒD ]N}|t d }d| j| d< | jt|ƒ | j| d< | jt|ƒ | j| d< qW t| jƒd }tj|dfdƒ}tj	d|d ddƒ|d d …df< tj	d|d ddƒ|d d …df< | j| j
_|| j
_| j}|d k	rè|jjƒ  d S )	Nr   ih  r@   rB   g        rA   rÝ   g      à?)Úranger   r;   rÅ   r   r   rÚ   rD   rH   rß   rË   rÞ   r   r   r'   )rj   rŸ   Úthetarà   rÞ   r!   r"   r"   r#   rð     s      
zRing._create_pointsc             C   s   || j j_d S )N)r,   r¦   rÄ   )rj   rˆ   r"   r"   r#   rÔ   ,  s    zRing._color_changedc             C   sØ   || }t j| jdƒrZ|| jd d …  | jd d …< | jjƒ  | jjƒ  | jjƒ  | j	ƒ  nz| j}d| }t
|| jƒ| _|| jd d …  | jd d …< |}t
|| jƒ| _| j| j_| jjƒ  | jjƒ  | jjƒ  | j	ƒ  d S )Nç        )rô   rô   rô   )rD   rS   rU   r;   rË   rÛ   rï   rÑ   rÌ   r'   r>   )rj   r9   r:   ZfactorÚcr<   r"   r"   r#   rÕ   /  s$    







zRing._radius_changedc             C   s$   || _ | j | jd | jd f| _d S )Nr@   rA   )r-   rU   )rj   rˆ   r"   r"   r#   r±   E  s    zRing._x_changedc             C   s$   || _ | jd | j | jd f| _d S )Nr   rA   )rK   rU   )rj   rˆ   r"   r"   r#   r²   I  s    zRing._y_changedc             C   s$   || _ | jd | jd | j f| _d S )Nr   r@   )rL   rU   )rj   rˆ   r"   r"   r#   r³   M  s    zRing._z_changedc             C   sz   | j |d dd� | j |d dd� | j |d dd� t||| jƒ| _| j| j_| jjƒ  | jjƒ  | jjƒ  | jƒ  d S )Nr   F)r-   rº   r@   )rK   rº   rA   )rL   rº   )	r»   r=   r;   rË   rÛ   rï   rÑ   rÌ   r'   )rj   r9   r:   r"   r"   r#   r°   Q  s    



zRing._pos_changedc             C   sH   t ||| j| jƒ| _| j| j_| jjƒ  | jjƒ  | jjƒ  | jƒ  d S )N)	r[   rU   r;   rË   rÛ   rï   rÑ   rÌ   r'   )rj   r9   r:   r"   r"   r#   r·   \  s    



zRing._axis_changedc             C   s    | j | j_ | jjƒ  | jƒ  d S )N)rÆ   r¦   rÛ   r'   )rj   rˆ   r"   r"   r#   rá   d  s    

zRing._representation_changedc             C   s   || j _d S )N)r,   r«   )rj   rˆ   r"   r"   r#   r¹   i  s    zRing._visibility_changedc             C   s   || j _d S )N)rÌ   rÅ   )rj   rˆ   r"   r"   r#   rñ   l  s    zRing._thickness_changedc             C   st   t |||| j| j| jƒ\}}}| j|dd� || _| j|dd� | j| j_| jjƒ  | jjƒ  | j	jƒ  | j
ƒ  dS )a  Function takes atleast 2 arguments: angle with which to
        rotate the actor, and the axis about which to rotate the
        actor, the 3rd agrument is origin i.e. the point about which
        to rotate the actor, by default it is set to the global originF)rU   rº   )rI   rº   N)r_   rU   r;   rI   r»   rË   rÛ   rï   rÑ   rÌ   r'   )rj   rJ   rI   r]   rÃ   r   rÜ   r"   r"   r#   r_   q  s    



zRing.rotatec             C   s   | j }|d k	r|jjƒ  d S )N)r   r   r'   )rj   r!   r"   r"   r#   r'   €  s    zRing.renderN)rè   rC   g°÷™9ýþ)ré   ré   ré   )rê   ré   ré   )rê   rê   rê   g°÷™9ýþg°÷™9ýþg°÷™9ýþ)6rq   rr   rs   r¥   r   r;   r   rÅ   rU   rI   r   rÄ   r-   rK   rL   r   rÆ   rë   r   r«   r   r   r
   r   râ   rË   rã   r¦   rä   rÌ   rå   r,   rî   rï   r   r   r   rŠ   rg   rð   rÔ   rÕ   r±   r²   r³   r°   r·   rá   r¹   rñ   rD   r�   r_   r'   r"   r"   r"   r#   ræ   Ï  sV   




#ræ   c               @   s¢  e Zd ZdZeddFd�Zedddd	d
�Zeddddd
�ZedGdd
�Z	edHdd
�Z
edIƒZedJdddd�ZedKdddd�ZedLdddd�ZedddƒZedƒZeZeejf ƒZeejƒZeejf ƒZeee dd�e dd�e ddd�e ddd�e d d!d�e d"d�e d#d�e d$d�d%dd&�
d'g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-e.j/dddgƒfdAdB„Z0dCdD„ Z1dES )MÚConezËCone class creates Cone from polydata obtained from tvtk
    ConeSource, follows the usual VTK pipeline and creates a Cone
    actor, which is passed to the show_actor() function as an
    argument.
    rç   é   rC   )r�   ç        g      Y@g      à?zthe cone radius)rˆ   ru   ç      ð?zthe cone heightzthe cone poszthe cone axisg°÷™9ý~zthe X coordinate of cone center)ru   zthe Y coordinate of cone centerzthe Z coordinate of cone centerrÁ   rÂ   rÃ   TrÅ   )r}   Úheightr-   zPos X)r}   rª   rK   zPos YrL   zPos ZrÄ   r«   rÆ   zCone Properties)rª   r¬   r~   )r�   c             K   sÀ   | j j| _tjƒ }t|| jƒ || j _| j j| _| j| j_tƒ | _	| jj
| j	jjƒ | j j
| j	jjƒ tj| f|Ž | j| j| j| j| jƒ | jtjdddgƒ| jƒ | j| jƒ t| j ƒ d S )Ng        )r,   r¦   r   rÏ   r   rË   rÐ   rÆ   r(   r   rh   r   r'   r   rg   rð   rÅ   rú   rU   rI   r°   rD   r�   rÔ   rÄ   r+   )rj   rµ   rÖ   r"   r"   r#   rg   °  s    


zCone.__init__c             C   sV   t j||t|ƒt|ƒd�}|jƒ  |j}|jjƒ }|| _| j| j_|j| j_||jfS )N)rÅ   rú   ÚcenterÚ	direction)	r   Z
ConeSourceÚtuplerÑ   Úoutputr;   Úto_arrayrË   Úpolys)rj   ÚrÚhrõ   rç   ÚcsÚpsr;   r"   r"   r#   rð   Ç  s    


zCone._create_pointsc             C   s   || j j_d S )N)r,   r¦   rÄ   )rj   rˆ   r"   r"   r#   rÔ   Ó  s    zCone._color_changedc             C   s:   | j | j| j| j| jƒ\}}|| j_| jjƒ  | jƒ  d S )N)	rð   rÅ   rú   rU   rI   rË   r;   rÛ   r'   )rj   r;   rÞ   r"   r"   r#   rÕ   Ö  s    
zCone._radius_changedc             C   s:   | j | j| j| j| jƒ\}}|| j_| jjƒ  | jƒ  d S )N)	rð   rÅ   rú   rU   rI   rË   r;   rÛ   r'   )rj   r;   rÞ   r"   r"   r#   Ú_height_changedÜ  s    
zCone._height_changedc             C   sn   | j |d dd� | j |d dd� | j |d dd� | j| j| j| j| jƒ\}}|| _| jjƒ  | j	ƒ  d S )Nr   F)r-   rº   r@   )rK   rº   rA   )rL   rº   )
r»   rð   rÅ   rú   rU   rI   r;   rË   rÛ   r'   )rj   r9   r:   r;   rÞ   r"   r"   r#   r°   â  s    
zCone._pos_changedc             C   s:   | j | j| j| j| jƒ\}}|| j_| jjƒ  | jƒ  d S )N)	rð   rÅ   rú   rU   rI   rË   r;   rÛ   r'   )rj   r;   rÞ   r"   r"   r#   r·   ë  s    
zCone._axis_changedc             C   s$   || _ | j | jd | jd f| _d S )Nr@   rA   )r-   rU   )rj   rˆ   r"   r"   r#   r±   ñ  s    zCone._x_changedc             C   s$   || _ | jd | j | jd f| _d S )Nr   rA   )rK   rU   )rj   rˆ   r"   r"   r#   r²   õ  s    zCone._y_changedc             C   s$   || _ | jd | jd | j f| _d S )Nr   r@   )rL   rU   )rj   rˆ   r"   r"   r#   r³   ù  s    zCone._z_changedc             C   s    | j | j_ | jjƒ  | jƒ  d S )N)rÆ   r¦   rÛ   r'   )rj   rˆ   r"   r"   r#   rá   ý  s    

zCone._representation_changedc             C   s&   t |ƒ}|dkrd| j_nd| j_d S )Nr@   r   )r¸   r,   r«   )rj   rˆ   r—   r"   r"   r#   r¹     s    
zCone._visibility_changedc             C   s`   t |||| j| j| jƒ\}}}| j|dd� || _| j|dd� | j| j_| jjƒ  | jƒ  dS )zÿFunction takes atleast 2 arguments: axis about which to
        rotate the actor and angle with which to rotate the actor, the
        3rd agrument is origin i.e. the point about which to rotate
        the actor, by default it is set to the global originF)rU   rº   )rI   rº   N)r_   rU   r;   rI   r»   rË   rÛ   r'   )rj   rJ   rI   r]   rÃ   r   rÜ   r"   r"   r#   r_     s    

zCone.rotatec             C   s   | j }|d k	r|jjƒ  d S )N)r   r   r'   )rj   r!   r"   r"   r#   r'     s    zCone.renderN)r÷   rC   )rø   rø   rø   )rù   rø   rø   )rù   rù   rù   g°÷™9ýþg°÷™9ýþg°÷™9ýþ)2rq   rr   rs   r¥   r   r;   r   rÅ   rú   rU   rI   r   rÄ   r-   rK   rL   r   rÆ   r   r«   r   r   r
   r   râ   rË   rã   r¦   rå   r,   r   r   r   rŠ   rg   rð   rÔ   rÕ   r  r°   r·   r±   r²   r³   rá   r¹   rD   r�   r_   r'   r"   r"   r"   r#   rö   †  sR   




		rö   c               @   s„  e Zd ZdZeddddd�Zed?dd�Zed@d	d�Ze	dAƒZ
edBddd
d�ZedCdddd�ZedDdddd�ZedddƒZedƒZeZeejf ƒZeejƒZeejf ƒZeejf ƒZeee ddd�e ddd�e ddd�e ddd�e dd�e dd�e dd�d dd!�	d"gd#�Z!d$d%„ Z"d&d'„ Z#d(d)„ Z$d*d+„ Z%d,d-„ Z&d.d/„ Z'd0d1„ Z(d2d3„ Z)d4d5„ Z*d6d7„ Z+d8d9„ Z,d:d;„ Z-e.j/dddgƒfd<d=„Z0d>S )EÚSpherez¸Sphere class creates Sphere from tvtk SphereSource, follows the
    usual VTK pipeline and creates a Sphere actor, which is passed to
    the show_actor() function as an argument.
    ç        g°÷™9ý~g      à?zthe sphere radius)rˆ   ru   zthe sphere posç      ð?zthe sphere axisz!the X coordinate of sphere center)ru   z!the Y coordinate of sphere centerz!the Z coordinate of sphere centerrÁ   rÂ   rÃ   TrÅ   rw   )r}   rx   r-   zPos X)r}   rª   rK   zPos YrL   zPos ZrÄ   )r}   r«   rÆ   zSphere Properties)rª   r¬   r~   )r�   c             K   sð   | j j| _tjƒ | _t| j| jƒ | jjƒ  tjƒ }t|| jƒ || j _	| j j| _| j
| j_
t| j ƒ tƒ | _| jj| jjjƒ | j j| jjjƒ tj| f|Ž | j| j| jƒ | j| jƒ | j| jƒ | j| jƒ | j| jƒ | j| jƒ d S )N) r,   r¦   r   rî   rï   r   rË   rÑ   rÏ   rÐ   rÆ   r+   r(   r   rh   r   r'   r   rg   rð   rÅ   rU   rÔ   rÄ   r¹   r«   r±   r-   r²   rK   r³   rL   )rj   rµ   rÖ   r"   r"   r#   rg   D  s(    





zSphere.__init__c             C   sR   t j|t|ƒddd�}|jƒ  |j}|jjƒ }|| _| j| j_|j| j_||jfS )Né   )rÅ   rû   Úphi_resolutionÚtheta_resolution)	r   ÚSphereSourcerý   rÑ   rþ   r;   rÿ   rË   r   )rj   r  rõ   Úspr  r;   r"   r"   r#   rð   a  s    


zSphere._create_pointsc             C   s2   | j | j| jƒ\}}|| j_| jjƒ  | jƒ  d S )N)rð   rÅ   rU   rË   r;   rÛ   r'   )rj   rˆ   r;   r   r"   r"   r#   rÕ   n  s    
zSphere._radius_changedc             C   s   || j j_d S )N)r,   r¦   rÄ   )rj   rˆ   r"   r"   r#   rÔ   t  s    zSphere._color_changedc             C   sr   | j |d dd� | j |d dd� | j |d dd� | j| j| jƒ\}}|| j_| jjƒ  | jjƒ  | j	ƒ  d S )Nr   F)r-   rº   r@   )rK   rº   rA   )rL   rº   )
r»   rð   rÅ   rU   rË   r;   rÛ   rï   rÑ   r'   )rj   r9   r:   r;   rÞ   r"   r"   r#   r°   w  s    

zSphere._pos_changedc             C   s>   t ||| j| jƒ| _| j| j_| jjƒ  | jjƒ  | jƒ  d S )N)r[   rU   r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r"   r"   r#   r·   �  s
    


zSphere._axis_changedc             C   s$   || _ | j | jd | jd f| _d S )Nr@   rA   )r-   rU   )rj   rˆ   r"   r"   r#   r±   ˆ  s    zSphere._x_changedc             C   s$   || _ | jd | j | jd f| _d S )Nr   rA   )rK   rU   )rj   rˆ   r"   r"   r#   r²   Œ  s    zSphere._y_changedc             C   s$   || _ | jd | jd | j f| _d S )Nr   r@   )rL   rU   )rj   rˆ   r"   r"   r#   r³   �  s    zSphere._z_changedc             C   s    | j | j_ | jjƒ  | jƒ  d S )N)rÆ   r¦   rÛ   r'   )rj   rˆ   r"   r"   r#   rá   ”  s    

zSphere._representation_changedc             C   s&   t |ƒ}|dkrd| j_nd| j_d S )Nr@   r   )r¸   r,   r«   )rj   rˆ   r—   r"   r"   r#   r¹   ™  s    
zSphere._visibility_changedc             C   s   | j }|d k	r|jjƒ  d S )N)r   r   r'   )rj   r!   r"   r"   r#   r'   ¢  s    zSphere.renderc             C   s`   t |||| j| j| jƒ\}}}| j|dd� || _| j|dd� | j| j_| jjƒ  | jƒ  dS )zÿFunction takes atleast 2 arguments: axis about which to
        rotate the actor and angle with which to rotate the actor, the
        3rd agrument is origin i.e. the point about which to rotate
        the actor, by default it is set to the global originF)rU   rº   )rI   rº   N)r_   rU   r;   rI   r»   rË   rÛ   r'   )rj   rJ   rI   r]   rÃ   r   rÜ   r"   r"   r#   r_   §  s    

zSphere.rotateN)r  r  r  )r  r  r  )r  r  r  g°÷™9ýþg°÷™9ýþg°÷™9ýþ)1rq   rr   rs   r¥   r   rÅ   r   rU   rI   r   rÄ   r-   rK   rL   r   rÆ   r   r«   r   r   r
   r   râ   rË   rã   r¦   rå   r,   rî   rï   r   r   r   rŠ   rg   rð   rÕ   rÔ   r°   r·   r±   r²   r³   rá   r¹   r'   rD   r�   r_   r"   r"   r"   r#   r    sL   





	r  c               @   s´  e Zd ZdZeddddd�Zeddddd�ZedFdd�ZedGd	d�Z	ed
dHd�Z
edIƒZedJdddd�ZedKdddd�ZedLdddd�ZedddƒZedƒZeZeejf ƒZeejf ƒZeejƒZeejƒ f ƒZe e!e"ddd�e"ddd�e"ddd�e"ddd�e"dd d�e"d!d"�e"d#d"�e"d$d"�d%dd&�
d'g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/e0j1dddgƒfdAdB„Z2dCdD„ Z3dES )MÚCylinderz¾Cylinder class creates Cylinder from tvtk CylinderSource,
    follows the usual VTK pipeline and creates a Sphere actor, which
    is passed to the show_actor() function as an argument.
    ç        g°÷™9ý~ç      ð?zthe cylinder radius)rˆ   ru   zthe cylinder lengthzthe cylinder poszthe cylinder axisrç   é<   rC   )r�   z#the X coordinate of cylinder center)ru   z#the Y coordinate of cylinder centerz#the Z coordinate of cylinder centerrÁ   rÂ   rÃ   TrÅ   rw   )r}   rx   Úlengthr-   zPos X)r}   rª   rK   zPos YrL   zPos ZrÄ   )r}   r«   rÆ   zCylinder Properties)rª   r¬   r~   )r�   c             K   s  | j j| _tjƒ | _t| j| jƒ tjƒ }t|| jƒ || j _| j j| _| j	| j_	t
| j ƒ tƒ | _| jj| jjjƒ | j j| jjjƒ tj| f|Ž | j| j| j| jƒ | j| jƒ | j| jƒ | jtjdddgƒ| jƒ | j| jƒ | j | j!ƒ | j"| j#ƒ d S )Ng      ð?g        )$r,   r¦   r   rî   rï   r   rË   rÏ   rÐ   rÆ   r+   r(   r   rh   r   r'   r   rg   rð   rÅ   rU   r  rÔ   rÄ   r¹   r«   r·   rD   r�   rI   r±   r-   r²   rK   r³   rL   )rj   rµ   rÖ   r"   r"   r#   rg   ß  s(    




zCylinder.__init__c       	      C   sÒ   t j||dd�}|jƒ  |j}|jjƒ }t|ƒ}x0td|dƒD ] }|| d |d  || d< q>W tt	j
dddgƒt	j
dddgƒt	j
dddgƒ|ƒ}tt	j
dddgƒ| j|ƒ}|| _| j| j_|j| j_||jfS )Né   )rÅ   rú   Ú
resolutionr   r@   g       @g        g      ð?)r   ZCylinderSourcerÑ   rþ   r;   rÿ   rÚ   rò   r[   rD   r�   r=   rU   rË   r   )	rj   r  rõ   r  Úcpr  r;   rÝ   rŸ   r"   r"   r#   rð   û  s    
 2

zCylinder._create_pointsc             C   sD   | j | j| j| jƒ\| _}| j| j_| jjƒ  | jjƒ  | j	ƒ  d S )N)
rð   rÅ   rU   r  r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r   r"   r"   r#   rÕ   
  s
    


zCylinder._radius_changedc             C   sD   | j | j| j| jƒ\| _}| j| j_| jjƒ  | jjƒ  | j	ƒ  d S )N)
rð   rÅ   rU   r  r;   rË   rÛ   rï   rÑ   r'   )rj   rˆ   r   r"   r"   r#   Ú_length_changed  s
    


zCylinder._length_changedc             C   s>   t ||| j| jƒ| _| j| j_| jjƒ  | jjƒ  | jƒ  d S )N)r[   rU   r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r"   r"   r#   r·     s
    


zCylinder._axis_changedc             C   sp   | j |d dd� | j |d dd� | j |d dd� t||| jƒ| _| j| j_| jjƒ  | jjƒ  | jƒ  d S )Nr   F)r-   rº   r@   )rK   rº   rA   )rL   rº   )r»   r=   r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r"   r"   r#   r°     s    


zCylinder._pos_changedc             C   s   || j j_d S )N)r,   r¦   rÄ   )rj   rˆ   r"   r"   r#   rÔ   )  s    zCylinder._color_changedc             C   s$   || _ | j | jd | jd f| _d S )Nr@   rA   )r-   rU   )rj   rˆ   r"   r"   r#   r±   ,  s    zCylinder._x_changedc             C   s$   || _ | jd | j | jd f| _d S )Nr   rA   )rK   rU   )rj   rˆ   r"   r"   r#   r²   0  s    zCylinder._y_changedc             C   s$   || _ | jd | jd | j f| _d S )Nr   r@   )rL   rU   )rj   rˆ   r"   r"   r#   r³   4  s    zCylinder._z_changedc             C   s    | j | j_ | jjƒ  | jƒ  d S )N)rÆ   r¦   rÛ   r'   )rj   rˆ   r"   r"   r#   rá   8  s    

z Cylinder._representation_changedc             C   s&   t |ƒ}|dkrd| j_nd| j_d S )Nr@   r   )r¸   r,   r«   )rj   rˆ   r—   r"   r"   r#   r¹   =  s    
zCylinder._visibility_changedc             C   sj   t |||| j| j| jƒ\}}}| j|dd� || _| j|dd� | j| j_| jjƒ  | jjƒ  | j	ƒ  dS )zÿFunction takes atleast 2 arguments: axis about which to
        rotate the actor and angle with which to rotate the actor, the
        3rd agrument is origin i.e. the point about which to rotate
        the actor, by default it is set to the global originF)rU   rº   )rI   rº   N)
r_   rU   r;   rI   r»   rË   rÛ   rï   rÑ   r'   )rj   rJ   rI   r]   rÃ   r   rÜ   r"   r"   r#   r_   F  s    


zCylinder.rotatec             C   s   | j }|d k	r|jjƒ  d S )N)r   r   r'   )rj   r!   r"   r"   r#   r'   T  s    zCylinder.renderN)r  r  r  )r  r  r  )r  rC   )r  r  r  g°÷™9ýþg°÷™9ýþg°÷™9ýþ)4rq   rr   rs   r¥   r   rÅ   r  r   rU   rI   r;   r   rÄ   r-   rK   rL   r   rÆ   r   r«   r   r   r
   r   râ   rË   rå   r,   rã   r¦   rî   rï   r   r   r   rŠ   rg   rð   rÕ   r  r·   r°   rÔ   r±   r²   r³   rá   r¹   rD   r�   r_   r'   r"   r"   r"   r#   r  ´  sT   






	r  c               @   sÖ  e Zd ZdZedLdd�ZedMdd�ZedNƒZ	e
dOddd	d�Ze
dPddd
d�Ze
dQdddd�ZedddƒZe
ddddd�Ze
ddddd�Ze
ddddd�ZedRdd�ZeddSd�ZedƒZeZeejf ƒZeejf ƒZeejƒZ e!e"e#dd�e#dd�e#dd�e#ddd�e#d d!d�e#d"d#d�e#d$d�e#d%d�e#d&d�d'dd(�d)g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„ Z0dCdD„ Z1dEdF„ Z2e3j4dddgƒfdGdH„Z5dIdJ„ Z6dKS )TÚBoxz®Box class creates Box from tvtk CubeSource, follows the usual
    VTK pipeline and creates a Cube actor, which is passed to the
    show_actor() function as an argument.
    ç      ð?zthe box size)ru   ç        zthe Box pos)rˆ   ru   g°÷™9ý~zthe X coordinate of box centerzthe Y coordinate of box centerzthe Z coordinate of box centerrÁ   rÂ   rÃ   r   zthe box lengthzthe box heightzthe box widthzthe box axisrç   é   rC   )r�   Tr  )r}   rú   r‚   r-   zPos X)r}   rª   rK   zPos YrL   zPos ZrÄ   r«   rÆ   zBox Properties)rª   r¬   r~   )r�   c             K   s  | j j| _tjƒ }t|| jƒ || j _| j j| _| j| j_t| j ƒ t	ƒ | _
| jj| j
jjƒ | j j| j
jjƒ tj| f|Ž | j| j| jƒ | j| jƒ | j| jƒ | jtjdddgƒ| jƒ | j| jƒ | j| jƒ | j| j ƒ | j!| j"ƒ | j#| j$ƒ | j%| j&ƒ d S )Ng      ð?g        )'r,   r¦   r   rÏ   r   rË   rÐ   rÆ   r+   r(   r   rh   r   r'   r   rg   rð   ÚsizerU   rÔ   rÄ   r¹   r«   r·   rD   r�   rI   r±   r-   r²   rK   r³   rL   r  r  r  rú   Ú_width_changedr‚   )rj   rµ   rÖ   r"   r"   r#   rg   …  s*    



zBox.__init__c             C   s^   t j|d |d |d t|ƒd�}|jƒ  |j}|jjƒ }|| _| j| j_|j| j_||jfS )Nr   r@   rA   )Zx_lengthZy_lengthZz_lengthrû   )	r   Z
CubeSourcerý   rÑ   rþ   r;   rÿ   rË   r   )rj   rÁ   rõ   r  r  r;   r"   r"   r#   rð   ¢  s    "


zBox._create_pointsc             C   sl   | j |d dd� | j |d dd� | j |d dd� | j| j| jƒ\| _}| j| j_| jjƒ  | jƒ  d S )Nr   F)r  rº   r@   )rú   rº   rA   )r‚   rº   )r»   rð   r  rU   r;   rË   rÛ   r'   )rj   r9   r:   rÞ   r"   r"   r#   Ú_size_changed­  s    

zBox._size_changedc             C   s\   | j |d dd� | j |d dd� | j |d dd� t||| jƒ| _| jjƒ  | jƒ  d S )Nr   F)r-   rº   r@   )rK   rº   rA   )rL   rº   )r»   r=   r;   rË   rÛ   r'   )rj   r9   r:   r"   r"   r#   r°   ¶  s    
zBox._pos_changedc             C   s*   t ||| j| jƒ| _| jjƒ  | jƒ  d S )N)r[   rU   r;   rË   rÛ   r'   )rj   r9   r:   r"   r"   r#   r·   ¿  s    
zBox._axis_changedc             C   s   || j j_d S )N)r,   r¦   rÄ   )rj   rˆ   r"   r"   r#   rÔ   Å  s    zBox._color_changedc             C   s$   || _ | j | jd | jd f| _d S )Nr@   rA   )r-   rU   )rj   rˆ   r"   r"   r#   r±   È  s    zBox._x_changedc             C   s$   || _ | jd | j | jd f| _d S )Nr   rA   )rK   rU   )rj   rˆ   r"   r"   r#   r²   Ì  s    zBox._y_changedc             C   s$   || _ | jd | jd | j f| _d S )Nr   r@   )rL   rU   )rj   rˆ   r"   r"   r#   r³   Ð  s    zBox._z_changedc             C   s    | j | j_ | jjƒ  | jƒ  d S )N)rÆ   r¦   rÛ   r'   )rj   rˆ   r"   r"   r#   rá   Ô  s    

zBox._representation_changedc             C   s   | j | jd | jd f| _d S )Nr@   rA   )r  r  )rj   rˆ   r"   r"   r#   r  Ù  s    zBox._length_changedc             C   s   | j d | j| j d f| _ d S )Nr   rA   )r  rú   )rj   rˆ   r"   r"   r#   r  Ü  s    zBox._height_changedc             C   s   | j d | j d | jf| _ d S )Nr   r@   )r  r‚   )rj   rˆ   r"   r"   r#   r  ß  s    zBox._width_changedc             C   s&   t |ƒ}|dkrd| j_nd| j_d S )Nr@   r   )r¸   r,   r«   )rj   rˆ   r—   r"   r"   r#   r¹   â  s    
zBox._visibility_changedc             C   sV   t |||| j| j| jƒ\}}}| j|dd� || _| j|dd� | jjƒ  | jƒ  dS )zÿFunction takes atleast 2 arguments: axis about which to
        rotate the actor and angle with which to rotate the actor, the
        3rd agrument is origin i.e. the point about which to rotate
        the actor, by default it is set to the global originF)rU   rº   )rI   rº   N)r_   rU   r;   rI   r»   rË   rÛ   r'   )rj   rJ   rI   r]   rÃ   r   rÜ   r"   r"   r#   r_   ë  s    
z
Box.rotatec             C   s   | j }|d k	r|jjƒ  d S )N)r   r   r'   )rj   r!   r"   r"   r#   r'   ø  s    z
Box.renderN)r  r  r  )r  r  r  )r  r  r  g°÷™9ýþg°÷™9ýþg°÷™9ýþ)r  r  r  )r  rC   )7rq   rr   rs   r¥   r   r  r   rU   r   rÄ   r   r-   rK   rL   r   rÆ   r  rú   r‚   rI   r;   r   r«   r   r   r
   r   râ   rË   rå   r,   rã   r¦   r   r   r   rŠ   rg   rð   r  r°   r·   rÔ   r±   r²   r³   rá   r  r  r  r¹   rD   r�   r_   r'   r"   r"   r"   r#   r  Y  s\   




			r  c               @   sÐ  e Zd ZdZeddMd�Zedddd	d
�Zeddddd
�Zeddddd
�Z	edNdd
�Z
edOƒZedPdd
�ZedQdddd�ZedRdddd�ZedSdddd�ZedddƒZedƒZeZeejf ƒZeejƒZeejf ƒZeejƒ f ƒZ e!e"e#dd�e#dd�e#dd�e#d d!d"�e#d#d$d"�e#d%d&d"�e#d'd�e#d(d�e#d)d�d*dd+�d,gd-�Z$d.d/„ Z%d0d1„ Z&d2d3„ Z'd4d5„ Z(d6d7„ Z)d8d9„ Z*d:d;„ Z+d<d=„ Z,d>d?„ Z-d@dA„ Z.dBdC„ Z/dDdE„ Z0dFdG„ Z1e2j3dddgƒfdHdI„Z4dJdK„ Z5dLS )TÚArrowz´Arrow class creates Arrow from tvtk ArrowSource, follows the
    usual VTK pipeline and creates a Arrow actor, which is passed to
    the show_actor() function as an argument.
    rç   é   rC   )r�   ç        g      $@g{®Gáz´?z#the radius of cone portion of arrow)rˆ   ru   g      @g¸…ëQ¸ž?z$the radius of shaft portion of arrowç      ð?gffffffÖ?zshaft length of arrowzthe arrow axiszthe Arrow posg°÷™9ý~z the X coordinate of arrow center)ru   z the Y coordinate of arrow centerz the Z coordinate of arrow centerrÁ   rÂ   rÃ   TÚradius_cone)r}   Úlength_coneÚradius_shaftr-   zPos X)r}   rª   rK   zPos YrL   zPos ZrÄ   r«   rÆ   zArrow Properties)rª   r¬   r~   )r�   c             K   s  | j j| _tjƒ | _t| j| jƒ | jjƒ  tjƒ }t|| jƒ || j _	| j j| _| j
| j_
t| j ƒ tƒ | _| jj| jjjƒ | j j| jjjƒ tj| f|Ž | j| j| j| j| jƒ | j| jƒ | j| jƒ | j| jƒ | j| jƒ | j | j!ƒ | j"t#j$dƒ| j%ƒ d S )Nç      ð?ç        )r%  r&  r&  )&r,   r¦   r   rî   rï   r   rË   rÑ   rÏ   rÐ   rÆ   r+   r(   r   rh   r   r'   r   rg   rð   r"  r#  r$  rU   rÔ   rÄ   r¹   r«   r±   r-   r²   rK   r³   rL   r·   rD   r�   rI   )rj   rµ   rÖ   r"   r"   r#   rg   '  s*    





zArrow.__init__c             C   sf   t j|||d�}|jƒ  |j}|jjƒ }ttjdddgƒ| j	|ƒ}|| _| j| j
_|j| j
_||jfS )N)Z
tip_radiusZ
tip_lengthZshaft_radiusg        )r   ZArrowSourcerÑ   rþ   r;   rÿ   r=   rD   r�   rU   rË   r   )rj   ÚrcZlcÚrsr  Zasrcr;   r"   r"   r#   rð   D  s    


zArrow._create_pointsc             C   sH   | j | j| j| j| jƒ\| _}| j| j_| jjƒ  | jj	ƒ  | j
ƒ  d S )N)rð   r"  r#  r$  rU   r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r   r"   r"   r#   Ú_radius_cone_changedO  s
    


zArrow._radius_cone_changedc             C   sH   | j | j| j| j| jƒ\| _}| j| j_| jjƒ  | jj	ƒ  | j
ƒ  d S )N)rð   r"  r#  r$  rU   r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r   r"   r"   r#   Ú_length_cone_changedV  s
    


zArrow._length_cone_changedc             C   sH   | j | j| j| j| jƒ\| _}| j| j_| jjƒ  | jj	ƒ  | j
ƒ  d S )N)rð   r"  r#  r$  rU   r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r   r"   r"   r#   Ú_radius_shaft_changed]  s
    


zArrow._radius_shaft_changedc             C   sp   | j |d dd� | j |d dd� | j |d dd� t||| jƒ| _| j| j_| jjƒ  | jjƒ  | jƒ  d S )Nr   F)r-   rº   r@   )rK   rº   rA   )rL   rº   )r»   r=   r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r"   r"   r#   r°   d  s    


zArrow._pos_changedc             C   s>   t ||| j| jƒ| _| j| j_| jjƒ  | jjƒ  | jƒ  d S )N)r[   rU   r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r"   r"   r#   r·   n  s
    


zArrow._axis_changedc             C   s   || j j_d S )N)r,   r¦   rÄ   )rj   rˆ   r"   r"   r#   rÔ   u  s    zArrow._color_changedc             C   s$   || _ | j | jd | jd f| _d S )Nr@   rA   )r-   rU   )rj   rˆ   r"   r"   r#   r±   x  s    zArrow._x_changedc             C   s$   || _ | jd | j | jd f| _d S )Nr   rA   )rK   rU   )rj   rˆ   r"   r"   r#   r²   |  s    zArrow._y_changedc             C   s$   || _ | jd | jd | j f| _d S )Nr   r@   )rL   rU   )rj   rˆ   r"   r"   r#   r³   €  s    zArrow._z_changedc             C   s    | j | j_ | jjƒ  | jƒ  d S )N)rÆ   r¦   rÛ   r'   )rj   rˆ   r"   r"   r#   rá   „  s    

zArrow._representation_changedc             C   s&   t |ƒ}|dkrd| j_nd| j_d S )Nr@   r   )r¸   r,   r«   )rj   rˆ   r—   r"   r"   r#   r¹   ‰  s    
zArrow._visibility_changedc             C   sj   t |||| j| j| jƒ\}}}| j|dd� || _| j|dd� | j| j_| jjƒ  | jjƒ  | j	ƒ  dS )zÿFunction takes atleast 2 arguments: axis about which to
        rotate the actor and angle with which to rotate the actor, the
        3rd agrument is origin i.e. the point about which to rotate
        the actor, by default it is set to the global originF)rU   rº   )rI   rº   N)
r_   rU   r;   rI   r»   rË   rÛ   rï   rÑ   r'   )rj   rJ   rI   r]   rÃ   r   rÜ   r"   r"   r#   r_   ’  s    


zArrow.rotatec             C   s   | j }|d k	r|jjƒ  d S )N)r   r   r'   )rj   r!   r"   r"   r#   r'      s    zArrow.renderN)r  rC   )r!  r   r   )r!  r!  r!  )r   r   r   g°÷™9ýþg°÷™9ýþg°÷™9ýþ)6rq   rr   rs   r¥   r   r;   r   r"  r$  r#  rI   r   rÄ   rU   r-   rK   rL   r   rÆ   r   r«   r   r   r
   r   rå   r,   rã   r¦   râ   rË   rî   rï   r   r   r   rŠ   rg   rð   r)  r*  r+  r°   r·   rÔ   r±   r²   r³   rá   r¹   rD   r�   r_   r'   r"   r"   r"   r#   r  ý  sX   




	r  c               @   sô  e Zd ZdZedƒZeddOd�Zeddd	d
d�Z	eddddd�Z
edPdd�ZedQdd�ZedRƒZedSdddd�ZedTdddd�ZedUdddd�ZedddƒZeddddd�ZedƒZeZeejf ƒZeejƒZeejf ƒZ eej!f ƒZ"eej#ƒ f ƒZ$e%e&e'dd�e'dd�e'dd�e'dd d!�e'd"d#d!�e'd$d%d!�e'd&d�e'd'd�e'd(d�d)dd*�d+gd,�Z(d-d.„ Z)d/d0„ Z*d1d2„ Z+d3d4„ Z,d5d6„ Z-d7d8„ Z.d9d:„ Z/d;d<„ Z0d=d>„ Z1d?d@„ Z2dAdB„ Z3dCdD„ Z4dEdF„ Z5dGdH„ Z6dIdJ„ Z7e8j9dddgƒfdKdL„Z:dMdN„ Z;dS )VÚHelixz¹Helix class creates Helix/Spring from tvtk polydata, follows the
    usual VTK pipeline and creates an Helix actor, which is passed to
    the show_actor() function as an argument.
    é   rç   NrC   )r�   g{®Gáz„?g°÷™9ý~gš™™™™™É?zthe helix radius)rˆ   ru   ç      ð?zthe helix lengthç        zthe helix positionzthe helix axisz the X coordinate of helix center)ru   z the Y coordinate of helix centerz the Z coordinate of helix centerrÁ   rÂ   rÃ   r   zthe helix thicknessTrÅ   )r}   r  rë   r-   zPos X)r}   rª   rK   zPos YrL   zPos ZrÄ   r«   rÆ   zHelix Properties)rª   r¬   r~   )r�   c             K   sH  | j j| _tjƒ | _t| j| jƒ t| j| jƒ d| j_d| j_	tj
ƒ }t|| jƒ || j _| j j| _| j| j_t| j ƒ tƒ | _| jj| jjjƒ | j j| jjjƒ | jj| jjjƒ tj| f|Ž | jƒ  | jtjdddgƒ| jƒ | j| jƒ | j| jƒ | j| jƒ | j | j!ƒ | j"| j#ƒ | j$| j%ƒ | j&tjdƒ| j'ƒ d S )NrÇ   r@   ç        ç      ð?)r1  r0  r0  )(r,   r¦   r   rî   rï   r   rË   rÌ   rÍ   rÎ   rÏ   rÐ   rÆ   r+   r(   r   rh   r   r'   r   rg   rð   r°   rD   r�   rU   r±   r-   r²   rK   r³   rL   rÔ   rÄ   r¹   r«   rñ   rë   r·   rI   )rj   rµ   rÖ   r"   r"   r#   rg   Ò  s4    




zHelix.__init__c             C   s6  | j | jd  }| j | jd  }d}| jj| jd dƒ xttd| jd dƒD ]^}|t d }|| j| d< | jt|ƒ | j| d< | jt|ƒ | j| d< |d }|| }qLW t	| jƒd }t
j|dfd	ƒ}t
jd|d
 dd	ƒ|d d …df< t
jd|d
 dd	ƒ|d d …df< | j| j_|| j_| jjƒ  | jjƒ  d S )Né
   r   rC   ih  é$   rB   r@   rA   rÝ   g      à?)r  Úcoilsr;   rÙ   rò   r   rÅ   r   r   rÚ   rD   rH   rß   rË   rÞ   rï   rÑ   rÌ   )rj   r  Úconsr    rŸ   ró   rà   rÞ   r"   r"   r#   rð   õ  s&      

zHelix._create_pointsc             C   s   || j j_d S )N)r,   r¦   rÄ   )rj   rˆ   r"   r"   r#   rÔ     s    zHelix._color_changedc             C   sj   | j ƒ  | jtjdddgƒ| jƒ | jtjdƒ| jƒ | j| j_| jj	ƒ  | j
jƒ  | jjƒ  | jƒ  d S )Nç        ç      ð?)r7  r6  r6  )rð   r°   rD   r�   rU   Úchange_axisrI   r;   rË   rÛ   rï   rÑ   rÌ   r'   )rj   r9   r:   r"   r"   r#   rÕ     s    



zHelix._radius_changedc             C   sˆ  t j| jd d td�}|j| jd dƒ}| j| jd  }| j| jd  }d}xntd| jd dƒD ]X}|t d }||| d< | jt	|ƒ || d< | jt
|ƒ || d	< |d }|| }qbW t|ƒd }	t j|	d	fd
ƒ}
t jd|	d dd
ƒ|
d d …df< t jd|	d dd
ƒ|
d d …df< || j_|
| j_|| _| jt jdddgƒ| jƒ | jt jdƒ| jƒ | jjƒ  | jjƒ  | jjƒ  | jƒ  d S )Nr2  rC   )r?   r   ih  r3  rB   r@   rA   rÝ   g      à?ç        ç      ð?)r:  r9  r9  )rD   rß   r4  rF   Úreshaper  rò   r   rÅ   r   r   rÚ   rH   rË   r;   rÞ   r°   r�   rU   r8  rI   rÛ   rï   rÑ   rÌ   r'   )rj   r9   r:   rÃ   r  r5  r    rŸ   ró   rà   rÞ   r"   r"   r#   Ú_coils_changed  s2      


zHelix._coils_changedc             C   s$   || _ | j | jd | jd f| _d S )Nr@   rA   )r-   rU   )rj   rˆ   r"   r"   r#   r±   4  s    zHelix._x_changedc             C   s$   || _ | jd | j | jd f| _d S )Nr   rA   )rK   rU   )rj   rˆ   r"   r"   r#   r²   8  s    zHelix._y_changedc             C   s$   || _ | jd | jd | j f| _d S )Nr   r@   )rL   rU   )rj   rˆ   r"   r"   r#   r³   <  s    zHelix._z_changedc             C   s    | j | j_ | jjƒ  | jƒ  d S )N)rÆ   r¦   rÛ   r'   )rj   rˆ   r"   r"   r#   rá   @  s    

zHelix._representation_changedc             C   sp   | j |d dd� | j |d dd� | j |d dd� t||| jƒ| _| jjƒ  | jjƒ  | jjƒ  | jƒ  d S )Nr   F)r-   rº   r@   )rK   rº   rA   )rL   rº   )	r»   r=   r;   rË   rÛ   rï   rÑ   rÌ   r'   )rj   r9   r:   r"   r"   r#   r°   E  s    


zHelix._pos_changedc             C   s>   t ||| j| jƒ| _| jjƒ  | jjƒ  | jjƒ  | jƒ  d S )N)	r[   rU   r;   rË   rÛ   rï   rÑ   rÌ   r'   )rj   r9   r:   r"   r"   r#   r·   P  s
    


zHelix._axis_changedc             C   s"   t ||| j| jƒ| _| j| j_d S )N)r[   rU   r;   rË   )rj   r9   r:   r"   r"   r#   r8  X  s    zHelix.change_axisc             C   sˆ   | j ƒ  | j}|rd|j_| jtjdddgƒ| jƒ | jtjdƒ| j	ƒ |rTd|j_| j
| j_
| jjƒ  | jjƒ  | jjƒ  | jƒ  d S )NTç        ç      ð?F)r>  r=  r=  )rð   r   r   Údisable_renderr°   rD   r�   rU   r8  rI   r;   rË   rÛ   rï   rÑ   rÌ   r'   )rj   r9   r:   r!   r"   r"   r#   r  \  s    



zHelix._length_changedc             C   s&   t |ƒ}|dkrd| j_nd| j_d S )Nr@   r   )r¸   r,   r«   )rj   rˆ   r—   r"   r"   r#   r¹   k  s    
zHelix._visibility_changedc             C   s   || j _d S )N)rÌ   rÅ   )rj   rˆ   r"   r"   r#   rñ   r  s    zHelix._thickness_changedc             C   st   t |||| j| j| jƒ\}}}| j|dd� || _| j|dd� | j| j_| jjƒ  | jjƒ  | j	jƒ  | j
ƒ  dS )zÿFunction takes atleast 2 arguments: axis about which to
        rotate the actor and angle with which to rotate the actor, the
        3rd agrument is origin i.e. the point about which to rotate
        the actor, by default it is set to the global originF)rU   rº   )rI   rº   N)r_   rU   r;   rI   r»   rË   rÛ   rï   rÑ   rÌ   r'   )rj   rJ   rI   r]   rÃ   r   rÜ   r"   r"   r#   r_   w  s    



zHelix.rotatec             C   s   | j }|d k	r|jjƒ  d S )N)r   r   r'   )rj   r!   r"   r"   r#   r'   †  s    zHelix.render)NrC   )r/  r/  r/  )r.  r/  r/  )r.  r.  r.  g°÷™9ýþg°÷™9ýþg°÷™9ýþ)<rq   rr   rs   r¥   r   r4  r   r;   r   rÅ   r  rU   rI   r   rÄ   r-   rK   rL   r   rÆ   rë   r   r«   r   r   r
   r   râ   rË   rã   r¦   rä   rÌ   rå   r,   rî   rï   r   r   r   rŠ   rg   rð   rÔ   rÕ   r<  r±   r²   r³   rá   r°   r·   r8  r  r¹   rñ   rD   r�   r_   r'   r"   r"   r"   r#   r,  ¥  s`   



#
r,  c               @   s   e Zd ZdZeddddd�ZedQdd�ZedRƒZ	edSd	d�Z
edTd
d�Zeddddd�Zeddddd�Zeddddd�ZedUdddd�ZedVdddd�ZedWdddd�ZedddƒZedƒZeZeejf ƒZeejƒZeejf ƒZeej ƒ f ƒZ!e"e#e$ddd�e$ddd�e$ddd�e$ddd�e$d d!d�e$d"d#d�e$d$d%d�e$d&d'�e$d(d'�e$d)d'�d*dd+�d,gd-�Z%d.d/„ Z&d0d1„ Z'd2d3„ Z(d4d5„ Z)d6d7„ Z*d8d9„ Z+d:d;„ Z,d<d=„ Z-d>d?„ Z.d@dA„ Z/dBdC„ Z0dDdE„ Z1dFdG„ Z2dHdI„ Z3dJdK„ Z4dLdM„ Z5e6j7dddgƒfdNdO„Z8dPS )XÚ	EllipsoidzÜEllipsoid class creates Ellipsoid from tvtk SphereSource by
    suitably scaling it, follows the usual VTK pipeline and creates a
    Ellipsoid actor, which is passed to the show_actor() function as
    an argument.
    ç        g°÷™9ý~ç      à?zUndistorted ellipsoid radius)rˆ   ru   zEllipsoid posç      ð?zEllipsoid axiszEllipsoid size_factorzScaling factor in X direction)ru   zSscaling factor in Y directionzScaling factor in Z directionz X coordinate of ellipsoid centerz Y coordinate of ellipsoid centerz Z coordinate of ellipsoid centerrÁ   rÂ   rÃ   TrÅ   rw   )r}   rx   r-   zPos X)r}   rª   rK   zPos YrL   zPos Zr  ÚLengthrú   ÚHeightr‚   ÚWidthrÄ   )r}   r«   rÆ   zEllipsoid Properties)rª   r¬   r~   )r�   c             K   sú   | j j| _tjƒ | _t| j| jƒ tjƒ }t|| jƒ || j _| j j| _| j	| j_	t
j| f|Ž | j| j| jƒ | j| jƒ | j| jƒ | j| jƒ | j| jƒ | j| jƒ | jtjdƒ| jƒ t| j ƒ tƒ | _| jj | jj!j"ƒ | j j | jj!j"ƒ d S )Nç      ð?ç        )rG  rH  rH  )#r,   r¦   r   rî   rï   r   rË   rÏ   rÐ   rÆ   r   rg   rð   rÅ   rU   rÔ   rÄ   r¹   r«   r±   r-   r²   rK   r³   rL   r·   rD   r�   rI   r+   r(   r   rh   r   r'   )rj   rµ   rÖ   r"   r"   r#   rg   ¸  s(    




zEllipsoid.__init__c             C   sb   t j|t|ƒddd�}|jƒ  |j}|jjƒ }t| j|| j	ƒ}|| _| j| j
_|j| j
_||jfS )Nr	  )rÅ   rû   r
  r  )r   r  rý   rÑ   rþ   r;   rÿ   rd   r  rU   rË   r   )rj   r  rõ   r  r  r;   r"   r"   r#   rð   Ô  s    



zEllipsoid._create_pointsc             C   s<   | j | j| jƒ\}}|| j_| jjƒ  | jjƒ  | jƒ  d S )N)	rð   rÅ   rU   rË   r;   rÛ   rï   rÑ   r'   )rj   rˆ   r;   r   r"   r"   r#   rÕ   á  s
    

zEllipsoid._radius_changedc             C   sZ   | j | j| jƒ\}}| j|d |d |d dd� || j_| jjƒ  | jjƒ  | j	ƒ  d S )Nr   r@   rA   F)r  rú   r‚   rº   )
rð   rÅ   rU   r»   rË   r;   rÛ   rï   rÑ   r'   )rj   rˆ   r;   r   r"   r"   r#   r  è  s    

zEllipsoid._size_changedc             C   s   || j j_d S )N)r,   r¦   rÄ   )rj   rˆ   r"   r"   r#   rÔ   ñ  s    zEllipsoid._color_changedc             C   sr   | j |d dd� | j |d dd� | j |d dd� | j| j| jƒ\}}|| j_| jjƒ  | jjƒ  | j	ƒ  d S )Nr   F)r-   rº   r@   )rK   rº   rA   )rL   rº   )
r»   rð   rÅ   rU   rË   r;   rÛ   rï   rÑ   r'   )rj   r9   r:   r;   rÞ   r"   r"   r#   r°   ô  s    

zEllipsoid._pos_changedc             C   sB   t ||| j| jƒ}|| _| j| j_| jjƒ  | jjƒ  | jƒ  d S )N)r[   rU   r;   rË   rÛ   rï   rÑ   r'   )rj   r9   r:   r;   r"   r"   r#   r·   þ  s    


zEllipsoid._axis_changedc             C   s$   || _ | j | jd | jd f| _d S )Nr@   rA   )r-   rU   )rj   rˆ   r"   r"   r#   r±     s    zEllipsoid._x_changedc             C   s$   || _ | jd | j | jd f| _d S )Nr   rA   )rK   rU   )rj   rˆ   r"   r"   r#   r²   
  s    zEllipsoid._y_changedc             C   s$   || _ | jd | jd | j f| _d S )Nr   r@   )rL   rU   )rj   rˆ   r"   r"   r#   r³     s    zEllipsoid._z_changedc             C   s    | j | j_ | jjƒ  | jƒ  d S )N)rÆ   r¦   rÛ   r'   )rj   rˆ   r"   r"   r#   rá     s    

z!Ellipsoid._representation_changedc             C   s$   || _ | j| jd | jd f| _d S )Nr@   rA   )Zx_scaler  r  )rj   rˆ   r"   r"   r#   r    s    zEllipsoid._length_changedc             C   s$   || _ | jd | j| jd f| _d S )Nr   rA   )Zy_scaler  rú   )rj   rˆ   r"   r"   r#   r    s    zEllipsoid._height_changedc             C   s$   || _ | jd | jd | jf| _d S )Nr   r@   )Zz_scaler  r‚   )rj   rˆ   r"   r"   r#   r    s    zEllipsoid._width_changedc             C   s&   t |ƒ}|dkrd| j_nd| j_d S )Nr@   r   )r¸   r,   r«   )rj   rˆ   r—   r"   r"   r#   r¹   #  s    
zEllipsoid._visibility_changedc             C   s   | j }|d k	r|jjƒ  d S )N)r   r   r'   )rj   r!   r"   r"   r#   r'   ,  s    zEllipsoid.renderc             C   s`   t |||| j| j| jƒ\}}}| j|dd� || _| j|dd� | j| j_| jjƒ  | jƒ  dS )zÿFunction takes atleast 2 arguments: axis about which to
        rotate the actor and angle with which to rotate the actor, the
        3rd agrument is origin i.e. the point about which to rotate
        the actor, by default it is set to the global originF)rU   rº   )rI   rº   N)r_   rU   r;   rI   r»   rË   rÛ   r'   )rj   rJ   rI   r]   rÃ   r   rÜ   r"   r"   r#   r_   1  s    

zEllipsoid.rotateN)rA  rA  rA  )rC  rC  rC  )rC  rA  rA  )rC  rB  rC  g°÷™9ýþg°÷™9ýþg°÷™9ýþ)9rq   rr   rs   r¥   r   rÅ   r   rU   r   rÄ   rI   r  r  rú   r‚   r-   rK   rL   r   rÆ   r   r«   r   r   r
   r   râ   rË   rã   r¦   rå   r,   rî   rï   r   r   r   rŠ   rg   rð   rÕ   r  rÔ   r°   r·   r±   r²   r³   rá   r  r  r  r¹   r'   rD   r�   r_   r"   r"   r"   r#   r@  ‹  s`   






	
	r@  c             C   s(   d}t dd ƒ t |ƒ t dd ƒ d S )NzàDo not use rate, instead use the iterate() function.
    Iterate should be called with a callback.  This callback will be
    periodically called via a timer.  This will make your script's UI
    completely interactive.
    Ú*éP   )rn   )r®   Úmsgr"   r"   r#   ÚrateP  s    rL  c              C   sp   t dddd�} tdddd�}td	ddd
�}td	ddd
�}tjdƒ tdƒ t| ƒ tjdƒ tdƒ t|ƒ dS )zDTest fuction for testing integrity of remove function for
    actorsg      ø?r   r@   )rÅ   rU   rÄ   rA   ç      à?ç      ð?)rû   r  rÄ   rt   )r  rU   rÄ   rC   zRemoved sphere from scenezRemoved cone from coneN)r   r   r   )r@   r   r   )r@   r   r   )rA   r@   r@   )rM  rM  rN  )rA   r   r   )r   r@   r   )rC   r   r   )r   r   r@   )ÚsphereÚboxÚconeÚcylinderÚtimeÚsleeprn   r.   )rÁ   ÚbÚcoÚcyr"   r"   r#   Útest_remove_actors^  s    

rX  c              C   s&   t dd�} tƒ }t|| ƒ}|jƒ  |S )Nç      @ç        )rU   )rY  rZ  rZ  )rQ  ÚringÚframeÚedit_traits)Úc1Úr1Úfr"   r"   r#   Ú
test_framen  s
    

ra  c                 sR   t dd�} td	d�}t| |ƒ‰ d
ˆ _dˆ _d‰‡ ‡fdd„}td|ƒ}|jƒ  |S )zDTest fuction for testing integrity of rotation function of
    framer@   r   )rU   rA   c                  s   ˆ j ˆdddgƒ d S )Ng        g      ð?)r_   r"   )r`  r    r"   r#   Úanim~  s    zrotate_frame.<locals>.animéÈ   )r@   r   r   )r@   r   r   )rA   r   r   )r@   r@   r@   )r[  Úhelixr\  rU   rI   r8   r]  )r_  Zh1rb  Útir"   )r`  r    r#   Úrotate_frameu  s    



rf  c              C   sx   t ƒ } d| _t d	d�}|j}| jddddgdddgƒ | jd
dddgdddgƒ | j}tj||ƒrltdƒ ntdƒ | S )zETest fuction for testing integrity of rotation function of
    actorsrC   r   )rU   éZ   r@   z	All clearzTest failed)rC   r   r   )rC   r   r   i¦ÿÿÿ)r[  rU   r;   r_   rD   rS   rn   )r  Úr2Zpoints1Zpoints2r"   r"   r#   Útest_rotate„  s    

ri  c                 sD   t ƒ } d‰tˆddfd�‰ d
ˆ _‡ ‡fdd„}td|ƒ}|jƒ  dS )z«This is a basic examples function demonstrating the creating
    simple animation from visual actors.  Note the show function has
    to be called in stand alone programs.r2  r   )rU   r@   c                 s8   ˆ j } | dk rdˆ _n| ˆkr$dˆ _| ˆ jd  ˆ _ d S )Nr@   r   )r@   r   r   r\   )r\   r   r   )r-   Úvelocity)r-   )rÁ   Úxlenr"   r#   rb  �  s    ztest_translate.<locals>.animé2   Nr\   )r\   r   r   )rP  rO  rj  r8   r]  )rU  rb  re  r"   )rÁ   rk  r#   Útest_translate”  s    
rm  c                 sb   d‰t ddd�} t ddˆddfd�}tdˆddfdd�‰ dˆ _‡ ‡fd	d
„}td|ƒ}|jƒ  |S )zEThis is a basic example function, extending the previous
    example.r2  r@   rÇ   r   )r  rÄ   )r  rÄ   rU   g      à?)rÅ   rU   rÄ   c                 s<   ˆ j } | dkrdˆ _n| ˆd kr(dˆ _| ˆ jd  ˆ _ d S )Nr@   r   )r@   r   r   r\   )r\   r   r   )r-   rj  )r-   )rÁ   rk  r"   r#   rb  ±  s    ztest_bounce.<locals>.animr  )r@   rÇ   rÇ   )r   r@   r   )r@   rÇ   rÇ   )r   r@   r   )r@   r   r   r\   )r\   r   r   )rP  rO  rj  r8   r]  )Úb1Úb2rb  rM   r"   )rÁ   rk  r#   Útest_bounce¨  s    
rp  )[r¥   Ú
__future__r   r/   rD   rS  Úmathr   r   r   r   r   Ú
traits.apir   r	   r
   r   r   r   r   r   r   r   r   r   Útraitsui.apir   r   r   Útvtk.apir   Z
tvtk.toolsr   Ztvtk.commonr   Ú
pyface.apir   Úpyface.timer.apir   Útvtk.tvtk_baser   r%   r$   r&   r(   r+   r.   r2   r8   r=   r>   rO   r[   r_   r`   rd   re   r3   r‘   r‹   r§   r¾   ræ   rö   r  r  r  r  r,  r@  rO  Úvectorr\  Zcurver[  rQ  rR  rP  Zarrowrd  Ú	ellipsoidÚlinalgr¤   r£   rL  rX  ra  rf  ri  rm  rp  r"   r"   r"   r#   Ú<module>)   sŠ   8*0Ac < 8   & % ) g 9