3
y<ï[®�  ã               @   sÒ   d Z ddlmZ ddlZddl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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 ejƒ jZdd„ ZG dd„ deƒZ G dd„ deƒZ!dS )ay  A TVTK interactor scene widget.  This class only uses TVTK and
Traits.  It does not even use any Pyface widgets.  This is nice when
you want to create a raw TVTK window but with some nice funcationality
that is similar to the widgets.  It is also the base class for the
toolkit specific classes since it implements the core
functionality. See the class docs for more details.

é    )Úprint_functionN)Ústate_pickler)Útvtk)Ú	messenger)Úvtk_color_trait)Úconfigure_input)ÚHasPrivateTraitsÚ	HasTraitsÚAnyÚIntÚPropertyÚInstanceÚEventÚRangeÚBoolÚTraitÚStr)Úlight_managerc             C   s    t | dƒr|| _n
||f| _d S )NÚmagnification)Úhasattrr   Úscale)Úw2ifr   © r   úY/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/tvtk/pyface/tvtk_scene.pyÚset_magnification"   s    
r   c                   sr  e Zd ZdZdZedƒZedƒZedƒZedƒZ	eddd�Z
eddd�Zeddd�Zeed‰ƒd	d�Ze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ejdd�Zeddd�Zeedd�Zedd�Zedd�Zedd�Zedd�Z eee!j"ƒƒZ#eee!j$ƒƒZ%eee!j&ƒƒZ'eee!j(ƒƒZ)e*Z+ee,ddd�Z-e*dd�Z.e/dd�Z0e1dd�Z2e*dd�Z3ee!j&ƒZ4ee!j$ƒZ5ee!j6ƒZ7ee!j(ƒZ8e/dƒZ9d‹‡ fdd„	Z:dd „ Z;d!d"„ Z<d#d$„ Z=d%d&„ Z>d'd(„ Z?d)d*„ Z@d+d,„ ZAe@ZBeAZCdŒd-d.„ZDd/d0„ ZEd1d2„ ZFd3d4„ ZGd5d6„ ZHd7d8„ ZId9d:„ ZJd;d<„ ZKd=d>„ ZLd?d@„ ZMdAdB„ ZNd�dCdD„ZOdEdF„ ZPdGdH„ ZQdIdJ„ ZRdKdL„ ZSdŽdMdN„ZTdOdP„ ZUdQdR„ ZVdSdT„ ZWd�dUdV„ZXdWdX„ ZYd�dYdZ„ZZd[d\„ Z[d]d^„ Z\d_d`„ Z]dadb„ Z^dcdd„ Z_dedf„ Z`dgdh„ Zadidj„ Zbdkdl„ Zcdmdn„ Zddodp„ Zedqdr„ Zfdsdt„ Zgdudv„ Zhdwdx„ Zidydz„ Zjd{d|„ Zkd}d~„ Zld‘dd€„Zmd�d‚„ Zndƒd„„ Zod…d†„ Zpd‡dˆ„ Zq‡  ZrS )’Ú	TVTKSceneaÎ  A TVTK interactor scene widget.

    This widget uses a RenderWindowInteractor and therefore supports
    interaction with VTK widgets.  The widget uses TVTK.  The widget
    also supports the following:

    - Save the scene to a bunch of common (and not so common) image
      formats.

    - save the rendered scene to the clipboard.

    - adding/removing lists/tuples of actors

    - setting the view to useful predefined views (just like in
      MayaVi).

    - If one passes `stereo=1` to the constructor, stereo rendering is
      enabled.  By default this is disabled.  Changing the stereo trait
      has no effect during runtime.

    - One can disable rendering by setting `disable_render` to True.

    r   Fz&if the camera uses parallel projection)Údesczif rendering is to be disabledz"if off-screen rendering is enabledç      à?z"the background color of the windowç      ð?z&the default foreground color of actorsé   i   z;the magnification used when the screen is saved to an imageé   é   z=number of frames to use for anti-aliasing when saving a sceneé
   éd   é_   z(the quality of the JPEG image to produceTz+if the generated JPEG should be progressive)Úrecordz"tvtk.pyface.movie_maker.MovieMaker)r%   Ú	transient)r&   Nc                s2   t t| ƒjf |Ž d| _| j|ƒ| _| jjƒ  dS )z Initializes the object. r   N)Úsuperr   Ú__init__Ú_def_posÚ_create_controlÚcontrolÚ_renwinZupdate_traits)ÚselfÚparentÚtraits)Ú	__class__r   r   r(   Ö   s    zTVTKScene.__init__c             C   s2   | j jƒ }xdD ]}|j|dƒ qW | j|d< |S )zAllows us to pickle the scene.r+   r,   Ú_interactorÚ_cameraÚ_busy_countÚ__sync_trait__ÚrecorderÚ_last_camera_stateÚ_camera_observer_idÚ_saved_light_manager_stateÚ
_script_idÚ__traits_listener__NÚcamera)r+   r,   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   )Ú__dict__ÚcopyÚpopr;   )r-   ÚdÚxr   r   r   Ú__get_pure_state__á   s    
   
zTVTKScene.__get_pure_state__c             C   s
   t j| ƒS )N)r   Údumps)r-   r   r   r   Ú__getstate__ð   s    zTVTKScene.__getstate__c             C   s   t j| t j|ƒƒ d S )N)r   Ú	set_stateÚloads_state)r-   Z	str_stater   r   r   Ú__setstate__ó   s    zTVTKScene.__setstate__c             C   s   d | _ d | _d | _d S )N)r   r1   Úmovie_maker)r-   r   r   r   Ú_closed_firedþ   s    zTVTKScene._closed_firedc             C   s   | j s| jjƒ  dS )zf Force the scene to be rendered. Nothing is done if the
        `disable_render` trait is set to True.N)Údisable_renderr,   Úrender)r-   r   r   r   rJ     s    zTVTKScene.renderc             C   sr   t | jjƒdkot | jjƒdk}t|dƒrFx&|D ]}| jj|ƒ q0W n| jj|ƒ || _|rf| jƒ  n| jƒ  dS )zJ Adds a single actor or a tuple or list of actors to the
        renderer.r   Ú__iter__N)	ÚlenÚ	_rendererÚactorsZvolumesr   Ú	add_actorÚactor_addedÚ
reset_zoomrJ   )r-   rN   rQ   Úactorr   r   r   Ú
add_actors  s     


zTVTKScene.add_actorsc             C   sD   t |dƒr&x&|D ]}| jj|ƒ qW n| jj|ƒ || _| jƒ  dS )zO Removes a single actor or a tuple or list of actors from
        the renderer.rK   N)r   rM   Úremove_actorÚactor_removedrJ   )r-   rN   rR   r   r   r   Úremove_actors  s    

zTVTKScene.remove_actorsc             C   s<   t |dƒs|g}| j}x|D ]}||_||_qW | jƒ  dS )z‹Adds a single 3D widget or a sequence of widgets to the renderer.
        If `enabled` is True the widget is also enabled once it is added.rK   N)r   r1   Ú
interactorÚenabledrJ   )r-   ÚwidgetsrX   ÚirenÚwidgetr   r   r   Úadd_widgets,  s    


zTVTKScene.add_widgetsc             C   sF   t |dƒs|g}| j}x"|D ]}|jdk	rd|_d|_qW | jƒ  dS )zNRemoves a single 3D widget or a sequence of widgets from the
        renderer.rK   NF)r   r1   rW   rX   rJ   )r-   rY   rZ   r[   r   r   r   Úremove_widgets7  s    



zTVTKScene.remove_widgetsc             C   sz   | j dkrdS d| _d| _| jd| jdd� | jd| jdd� | jd| j dd� | jjƒ  | j jƒ  d| j_	| ` d| _
dS )aH  Close the scene cleanly.  This ensures that the scene is
        shutdown cleanly.  This should be called if you are getting
        async errors when closing a scene from a UI.  This is based on
        the observations of Charl Botha here:

          http://public.kitware.com/pipermail/vtkusers/2008-May/095291.html

        NTÚ
background)ÚremoveÚparallel_projectionÚoff_screen_rendering)r,   ÚclosingrI   Ú
sync_traitrM   r;   Zremove_all_view_propsÚfinalizer1   Úrender_windowÚclosed)r-   r   r   r   ÚcloseC  s    



zTVTKScene.closec             C   s$   | j | jdddddƒ | jdƒ dS )zView scene down the +X axis. r   r   zx_plus_view()N)Ú_update_viewr)   Ú_record_methods)r-   r   r   r   Úx_plus_viewe  s    zTVTKScene.x_plus_viewc             C   s&   | j | j dddddƒ | jdƒ dS )zView scene down the -X axis. r   r   zx_minus_view()N)rh   r)   ri   )r-   r   r   r   Úx_minus_viewj  s    zTVTKScene.x_minus_viewc             C   s$   | j dd| jdddƒ | jdƒ dS )zView scene down the +Z axis. r   r   zz_plus_view()N)rh   r)   ri   )r-   r   r   r   Úz_plus_viewo  s    zTVTKScene.z_plus_viewc             C   s&   | j dd| j dddƒ | jdƒ dS )zView scene down the -Z axis. r   r   zz_minus_view()N)rh   r)   ri   )r-   r   r   r   Úz_minus_viewt  s    zTVTKScene.z_minus_viewc             C   s$   | j d| jddddƒ | jdƒ dS )zView scene down the +Y axis. r   r   zy_plus_view()N)rh   r)   ri   )r-   r   r   r   Úy_plus_viewy  s    zTVTKScene.y_plus_viewc             C   s&   | j d| j ddddƒ | jdƒ dS )zView scene down the -Y axis. r   r   zy_minus_view()N)rh   r)   ri   )r-   r   r   r   Úy_minus_view~  s    zTVTKScene.y_minus_viewc             C   s(   | j | j| j| jdddƒ | jdƒ dS )z$Set the view to an iso-metric view. r   r   zisometric_view()N)rh   r)   ri   )r-   r   r   r   Úisometric_viewƒ  s    
zTVTKScene.isometric_viewc             C   s    | j jƒ  | jƒ  | jdƒ dS )z1Reset the camera so everything in the scene fits.zreset_zoom()N)rM   Úreset_camerarJ   ri   )r-   r   r   r   rQ   ‰  s    
zTVTKScene.reset_zoomc             K   sÄ   t jj|ƒd }dddddddddd	d
dddddddœ}|jƒ |krLtdƒ‚t| d||jƒ   ƒ}|dk	r¦| jƒ }| j|ƒ ||f|Ž | j|ƒ | jd||f ƒ n||f|Ž | jd| ƒ dS )aw  Saves rendered scene to one of several image formats
        depending on the specified extension of the filename.

        If an additional size (2-tuple) argument is passed the window
        is resized to the specified size in order to produce a
        suitably sized output image.  Please note that when the window
        is resized, the window may be obscured by other widgets and
        the camera zoom is not reset which is likely to produce an
        image that does not reflect what is seen on screen.

        Any extra keyword arguments are passed along to the respective
        image format's save method.
        r   ÚpsÚbmpZtiffZpngZjpgZivZvrmlZooglZribZ	wavefrontZgl2psZx3dZpovray)z.psz.bmpz.tiffz.pngz.jpgz.jpegz.ivz.wrlz.vrmlz.ooglz.ribz.objz.epsz.pdfz.texz.x3dz.povz<Unable to find suitable image type for given file extension.Zsave_Nzsave(%r, %r)zsave(%r))	ÚosÚpathÚsplitextÚlowerÚ
ValueErrorÚgetattrÚget_sizeÚset_sizeri   )r-   Ú	file_nameÚsizeÚkw_argsÚextZmeth_mapÚmethZ	orig_sizer   r   r   Úsave�  s&    


zTVTKScene.savec             C   s:   t |ƒdkr6| jƒ }tjƒ }||_t||ƒ | j|ƒ dS )zqSaves the rendered scene to a rasterized PostScript image.
        For vector graphics use the save_gl2ps method.r   N)rL   Ú_get_window_to_imager   ZPostScriptWriterr|   r   Ú_exporter_write)r-   r|   r   Úexr   r   r   Úsave_ps³  s    
zTVTKScene.save_psc             C   s:   t |ƒdkr6| jƒ }tjƒ }||_t||ƒ | j|ƒ dS )zSave to a BMP image file.r   N)rL   r‚   r   Z	BMPWriterr|   r   rƒ   )r-   r|   r   r„   r   r   r   Úsave_bmp½  s    
zTVTKScene.save_bmpc             C   s:   t |ƒdkr6| jƒ }tjƒ }||_t||ƒ | j|ƒ dS )zSave to a TIFF image file.r   N)rL   r‚   r   Z
TIFFWriterr|   r   rƒ   )r-   r|   r   r„   r   r   r   Ú	save_tiffÆ  s    
zTVTKScene.save_tiffc             C   s:   t |ƒdkr6| jƒ }tjƒ }||_t||ƒ | j|ƒ dS )zSave to a PNG image file.r   N)rL   r‚   r   Z	PNGWriterr|   r   rƒ   )r-   r|   r   r„   r   r   r   Úsave_pngÏ  s    
zTVTKScene.save_pngc             C   s`   t |ƒdkr\| r&| r&| j| j }}| jƒ }tjƒ }||_||_||_t	||ƒ | j
|ƒ dS )z§Arguments: file_name if passed will be used, quality is the
        quality of the JPEG(10-100) are valid, the progressive
        arguments toggles progressive jpegs.r   N)rL   Újpeg_qualityÚjpeg_progressiver‚   r   Z
JPEGWriterÚqualityÚprogressiver|   r   rƒ   )r-   r|   r‹   rŒ   r   r„   r   r   r   Úsave_jpgØ  s    
zTVTKScene.save_jpgc             C   s8   t |ƒdkr4tjƒ }| jƒ  | j|_||_| j|ƒ dS )zSave to an OpenInventor file.r   N)rL   r   Z
IVExporterÚ_liftr,   Úinputr|   rƒ   )r-   r|   r„   r   r   r   Úsave_ivç  s    zTVTKScene.save_ivc             C   s8   t |ƒdkr4tjƒ }| jƒ  | j|_||_| j|ƒ dS )zSave to a VRML file.r   N)rL   r   ZVRMLExporterrŽ   r,   r�   r|   rƒ   )r-   r|   r„   r   r   r   Ú	save_vrmlð  s    zTVTKScene.save_vrmlc             C   s8   t |ƒdkr4tjƒ }| jƒ  | j|_||_| j|ƒ dS )zHSaves the scene to a Geomview OOGL file. Requires VTK 4 to
        work.r   N)rL   r   ZOOGLExporterrŽ   r,   r�   r|   rƒ   )r-   r|   r„   r   r   r   Ú	save_ooglù  s    zTVTKScene.save_ooglc                s   |dkr| j j\}}n.y|\}}W n  tk
rB   td| ƒ‚Y nX t|ƒdkrTdS tjj|ƒd }tjƒ }t	|| ƒt	|| ƒf|_||_
|d |_| jƒ  | j|_ ||_tdd… dk�r’dd	„ ‰ d
d„ ‰‡ ‡fdd„}	g }
x| jjD ]}|
j|jjƒ qêW | j}tjƒ }|j|jƒ x | jjD ]}|	|j|dƒ �q$W | j|ƒ |jƒ  x,t| jjƒD ]\}}|	|j||
| ƒ �q\W |jdƒ |jdƒ n
| j|ƒ dS )a  Save scene to a RenderMan RIB file.

        Keyword Arguments:

        file_name -- File name to save to.

        bg -- Optional background option.  If 0 then no background is
        saved.  If non-None then a background is saved.  If left alone
        (defaults to None) it will result in a pop-up window asking
        for yes/no.

        resolution -- Specify the resolution of the generated image in
        the form of a tuple (nx, ny).

        resfactor -- The resolution factor which scales the resolution.
        Nz6Resolution (%s) should be a sequence with two elementsr   Z_texé   ú4.2ú4.4c             S   s   | d | d | d dfS )Nr   r   é   g      ð?r   )r@   r   r   r   Úx3to43  s    z!TVTKScene.save_rib.<locals>.x3to4c             S   s   | d | d | d fS )Nr   r   r–   r   )r@   r   r   r   Úx4to36  s    z!TVTKScene.save_rib.<locals>.x4to3c                sF   ˆ | j ƒ}ˆ | jƒ}|j|ƒ}|j|ƒ}ˆ|ƒ| _ ˆ|ƒ| _|| _d S )N)ÚpositionÚfocal_pointZmultiply_pointÚ
light_type)ÚlightÚxformr›   ÚoriginZfocusZ	neworiginZnewfocus)r—   r˜   r   r   Úcameralight_transform:  s    





z1TVTKScene.save_rib.<locals>.cameralight_transformZscene_lightg      à?)r”   r•   g      à¿)re   r}   Ú	TypeErrorrL   rt   ru   rv   r   ZRIBExporterÚintÚfile_prefixZtexture_prefixrŽ   r,   r^   ÚVTK_VERr   ZlightsÚappendÚsourcer›   r;   Z	Matrix4x4Ú	deep_copyZcamera_light_transform_matrixrƒ   ÚinvertÚ	enumerateÚroll)r-   r|   ÚbgÚ
resolutionZ	resfactorÚNxZNyÚf_prefr„   rŸ   Zsave_lights_typerœ   Úcamr�   Úir   )r—   r˜   r   Úsave_rib  sH    


zTVTKScene.save_ribc             C   sH   t |ƒdkrDtjƒ }| jƒ  | j|_tjj|ƒd }||_	| j
|ƒ dS )a  Save scene to a Wavefront OBJ file.  Two files are
        generated.  One with a .obj extension and another with a .mtl
        extension which contains the material properties.

        Keyword Arguments:

        file_name -- File name to save to
        r   N)rL   r   ZOBJExporterrŽ   r,   r�   rt   ru   rv   r¢   rƒ   )r-   r|   r„   r­   r   r   r   Úsave_wavefront_  s    	zTVTKScene.save_wavefrontc             C   s"  t tdƒsd}t|ƒ dS t|ƒdk�rtjj|ƒ\}}d}|rl|}t|tjƒsdd|j	j
 }t|ƒ‚||_n\tjƒ }||_|dkrŠd|_n&|dkršd	|_n|d
krªd|_nd|_d|_d|_|jdd� | jƒ  | j|_|jrê| j|ƒ n|jƒ  |d
k�rtjj|d ƒ�rtj|d |ƒ dS )a  Save scene to a vector PostScript/EPS/PDF/TeX file using
        GL2PS.  If you choose to use a TeX file then note that only
        the text output is saved to the file.  You will need to save
        the graphics separately.

        Keyword Arguments:

        file_name -- File name to save to.

        exp -- Optionally configured vtkGL2PSExporter object.
        Defaults to None and this will use the default settings with
        the output file type chosen based on the extention of the file
        name.
        ÚGL2PSExporterzÍSaving as a vector PS/EPS/PDF/TeX file using GL2PS is either not supported by your version of VTK or you have not configured VTK to work with GL2PS -- read the documentation for the vtkGL2PSExporter class.Nr   z'Need a vtkGL2PSExporter you passed a %sz.psrr   z.texÚtexz.pdfZpdfÚepsZbspr   Ú	livemodal)Úkindz.pdf.gz)r   r   ÚprintrL   rt   ru   rv   Ú
isinstancer²   r0   Ú__name__r    r¢   Zfile_formatÚsortÚcompressÚedit_traitsrŽ   r,   re   Zwrite3d_props_as_raster_imagerƒ   ÚwriteÚexistsÚrename)r-   r|   ÚexpÚmsgZf_prefixÚf_extr„   r   r   r   Ú
save_gl2psp  sB    

zTVTKScene.save_gl2psc             C   sP   t tdƒsd}t|ƒ dS t|ƒdkrLtjƒ }| j|_||_|jƒ  |j	ƒ  dS )z‡Save scene to an X3D file (http://www.web3d.org/x3d/).

        Keyword Arguments:

        file_name -- File name to save to.
        ÚX3DExporterzMSaving as a X3D file does not appear to be  supported by your version of VTK.Nr   )
r   r   r·   rL   rÄ   r,   r�   r|   Úupdater½   )r-   r|   rÁ   r„   r   r   r   Úsave_x3d®  s    
zTVTKScene.save_x3dc             C   sn   t tdƒsd}t|ƒ dS t|ƒdkrjtjƒ }| j|_t |dƒrH||_ntj	j
|ƒd |_|jƒ  |jƒ  dS )z°Save scene to a POVRAY (Persistence of Vision Raytracer),
        file (http://www.povray.org).

        Keyword Arguments:

        file_name -- File name to save to.
        ÚPOVExporterzPSaving as a POVRAY file does not appear to be  supported by your version of VTK.Nr   r|   )r   r   r·   rL   rÇ   r,   r�   r|   rt   ru   rv   r¢   rÅ   r½   )r-   r|   rÁ   r„   r   r   r   Úsave_povrayÃ  s    	

zTVTKScene.save_povrayc             C   s   | j jS )z!Return size of the render window.)r1   r}   )r-   r   r   r   rz   Ü  s    zTVTKScene.get_sizec             C   s   || j _|| j_dS )zSet the size of the window.N)r1   r}   r,   )r-   r}   r   r   r   r{   à  s    zTVTKScene.set_sizec             C   s   | j S )z9Returns the vtkRenderWindowInteractor of the parent class)r1   )r-   r   r   r   Ú_get_interactoré  s    zTVTKScene._get_interactorc             C   s$   | j d k	rd | j _|| _ | j|_d S )N)r1   re   r,   )r-   rZ   r   r   r   Ú_set_interactorí  s    
zTVTKScene._set_interactorc             C   s   | j S )z"Returns the scene's render window.)r,   )r-   r   r   r   Ú_get_render_windowó  s    zTVTKScene._get_render_windowc             C   s   | j S )zReturns the scene's renderer.)rM   )r-   r   r   r   Ú_get_renderer÷  s    zTVTKScene._get_rendererc             C   s   | j jS )z Returns the active camera. )rM   Zactive_camera)r-   r   r   r   Ú_get_cameraû  s    zTVTKScene._get_camerac             C   s
   | j dkS )Nr   )r3   )r-   r   r   r   Ú	_get_busyÿ  s    zTVTKScene._get_busyc             C   s\   | j }|r|d7 }n|d8 }td|ƒ}|| _ |dkrB| jdddƒ |dkrX| jdddƒ dS )aù  The `busy` trait is either `True` or `False`.  However,
        this could be problematic since we could have two methods
        `foo` and `bar that both set `scene.busy = True`.  As soon as
        `bar` is done it sets `busy` back to `False`.  This is wrong
        since the UI is still busy as `foo` is not done yet.  We
        therefore store the number of busy calls and either increment
        it or decrement it and change the state back to `False` only
        when the count is zero.
        r   r   ÚbusyFTN)r3   ÚmaxÚtrait_property_changed)r-   ÚvalueZbcr   r   r   Ú	_set_busy  s    


zTVTKScene._set_busyc             C   sl  | j rRttdƒrtjƒ }n"ttdƒr.tjƒ }ntjƒ }d|_|| _tj|d�| _	ntjƒ  }| _tj
|d�| _	|j| j| j| jd� tjƒ | _|j| jƒ | j| _| j| j_| jd| jƒ | jj| jdƒ | j| j_| jd| jƒ | j |_ | jd| jƒ | jj| jdƒ | jj| jd	ƒ | jj| jd
ƒ | jj| jdƒ | j	jƒ  | j	jƒ  tj| ƒ| _| j �rfd|_| j	S )zA Create the toolkit-specific control that represents the widget. ÚEGLRenderWindowÚOSOpenGLRenderWindowr   )re   )Úpoint_smoothingÚline_smoothingÚpolygon_smoothingr^   r`   ra   Zstereo_renderZstereo_typeé,  )r   r   )rÙ   rÙ   )ra   r   r   rÔ   rÕ   ÚRenderWindowr}   r,   ÚGenericRenderWindowInteractorr1   ÚRenderWindowInteractorÚ	trait_setrÖ   r×   rØ   ÚRendererrM   Zadd_rendererr;   r2   r^   rc   Úon_trait_changerJ   r`   re   Ú
initializer   ÚLightManager)r-   r.   Zrenwinr   r   r   r*     sH    










zTVTKScene._create_controlc             C   s0   t j| j d�}t|| jƒ | jƒ  | j|_|S )N)Zread_front_buffer)r   ZWindowToImageFilterra   r   r   rŽ   r,   r�   )r-   r   r   r   r   r‚   V  s    zTVTKScene._get_window_to_imagec             C   s   dS )zJLift the window to the top. Useful when saving screen to an
        image.Nr   )r-   r   r   r   rŽ   _  s    zTVTKScene._liftc             C   sj   | j }t|dƒr |j}| j|_n|j}| j|_|jƒ  |jƒ  |jƒ  t|dƒrX||_n||_|jƒ  dS )z&Abstracts the exporter's write method.Ú	aa_framesN)re   r   râ   Úanti_aliasing_framesZmulti_samplesrJ   rÅ   r½   )r-   r„   Úrwrâ   r   r   r   rƒ   d  s    


zTVTKScene._exporter_writec             C   s:   | j }d|_|||f|_|||f|_| jjƒ  | jƒ  dS )z Used internally to set the view.ç        N)rå   rå   rå   )r;   rš   r™   Úview_uprM   rq   rJ   )r-   r@   ÚyÚzÚvxÚvyÚvzr;   r   r   r   rh   y  s    
zTVTKScene._update_viewc             C   s   | r| j d k	r| jƒ  d S )N)r,   rJ   )r-   Úvalr   r   r   Ú_disable_render_changed‚  s    z!TVTKScene._disable_render_changedc             C   s>   | j }|dk	r:| j}x$|jdƒD ]}|jd||f ƒ q W dS )a  A method to record a simple method called on self.  We need a
        more powerful and less intrusive way like decorators to do this.
        Note that calls can be a string with new lines in which case we
        interpret this as multiple calls.
        NÚ
z%s.%s)r5   r9   Úsplitr%   )r-   ZcallsÚrÚsidÚcallr   r   r   ri   †  s
    zTVTKScene._record_methodsc       	      C   sv   | j }|dk	rr| jƒ }| j}||krr|| _| j}x$|D ]\}}|jd|||f ƒ q6W |jd| ƒ |jd| ƒ dS )z'Callback to record the camera position.Nz%s.camera.%s = %rz%%s.camera.compute_view_plane_normal()z%s.render())r5   Ú_get_camera_stater6   r9   r%   )	r-   Zvtk_objÚeventrð   ÚstateZlcsrñ   ÚkeyrÒ   r   r   r   Ú_record_camera_position’  s    z!TVTKScene._record_camera_positionc             C   sn   | j }g }|jdt|jƒfƒ |jdt|jƒfƒ |jd|jfƒ |jdt|jƒfƒ |jdt|jƒfƒ |S )Nr™   rš   Ú
view_angleræ   Úclipping_range)r;   r¤   Úlistr™   rš   rø   ræ   rù   )r-   Úcrõ   r   r   r   ró      s    zTVTKScene._get_camera_statec             C   sz   | j }|dk	rJ|j| ƒ| _|jdtjƒ}|| _tj|ƒ}tj	|d| j
ƒ n,d| _|j| jƒ tj|ƒ}tj|d| j
ƒ dS )z‹When the recorder is set we add an event handler so we can
        record the change to the camera position after the interaction.
        NÚEndInteractionEventÚ )r1   Zget_script_idr9   Zadd_observerr   Úsendr7   r   Úto_vtkÚconnectr÷   Zremove_observerZ
disconnect)r-   rð   rZ   ÚidZi_vtkr   r   r   Ú_recorder_changedª  s    


zTVTKScene._recorder_changedc             C   s(   |d k	r$| j d k	r$|j| j ƒ d | _ d S )N)r8   Ú__set_pure_state__)r-   Zlmr   r   r   Ú_light_manager_changed¾  s    
z TVTKScene._light_manager_changedc             C   s   ddl m} || d�S )Nr   )Ú
MovieMaker)Úscene)Ztvtk.pyface.movie_makerr  )r-   r  r   r   r   Ú_movie_maker_defaultÄ  s    zTVTKScene._movie_maker_default)r   r   r   )r   r   r   )N)T)N)NN)r   Nr   )N)NN)sr¹   Ú
__module__Ú__qualname__Ú__doc__Ú__version__r   Ústereor×   rÖ   rØ   r`   rI   ra   r   r   r^   Ú
foregroundr   r   rã   r‰   rŠ   r   r   rá   rG   r   rÏ   r   rb   rf   rP   rU   r   rÛ   rW   rÚ   re   rÞ   ÚrendererZCamerar;   r
   r+   r	   r5   r6   r   r7   r   r9   r8   rM   r,   rÜ   r1   r2   r3   r(   rA   rC   rF   rH   rJ   rS   rV   rO   rT   r\   r]   rg   rj   rk   rl   rm   rn   ro   rp   rQ   r�   r…   r†   r‡   rˆ   r�   r�   r‘   r’   r°   r±   rÃ   rÆ   rÈ   rz   r{   rÉ   rÊ   rË   rÌ   rÍ   rÎ   rÓ   r*   r‚   rŽ   rƒ   rh   rí   ri   r÷   ró   r  r  r  Ú__classcell__r   r   )r0   r   r   ,   sÄ   		












"
$
			
		

\
>	:		

r   c               @   s    e Zd ZdZeZeZdd„ ZdS )Ú
TVTKWindowa†  A basic TVTK window class that can be used in the MayaVi engine
    for visualization without envisage/pyface etc.  Technically we
    could just have used the `TVTKScene` class but we want to support
    the closing and activated events since they are used to notify the
    MayaVi engine if the window is closed or activated.  In this case
    we do nothing but honour the interface.
    c             K   s   t f |Ž| _dS )zTAll the keyword arguments are passed on to the `TVTKScene`
        instance created.N)r   r  )r-   r/   r   r   r   r(   ×  s    zTVTKWindow.__init__N)r¹   r  r	  r
  r   rb   Ú	activatedr(   r   r   r   r   r  Ì  s   r  )"r
  Ú
__future__r   rt   Úos.pathZapptools.persistencer   Útvtk.apir   r   Útvtk.tvtk_baser   Ztvtk.commonr   Ú
traits.apir   r	   r
   r   r   r   r   r   r   r   r   Ztvtk.pyfacer   ÚVersionÚvtk_versionr£   r   r   r  r   r   r   r   Ú<module>   s*   4

       '