U
    f»{jJ-  ã                   @   s  d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZmZ dadadZed	d
d�Zdadd„ Zdd„ Zdd„ Zed.dd„ƒZdd„ Zdd„ Zedd„ ƒZed/dd„ƒZedd„ ƒZed0dd „ƒZd1d"d#„Zd2ddd%œd&d'„Zd(d)„ Zd*d+„ Z d,d-„ Z!dS )3zCore visualization operations.é    )ÚcontextmanagerNé   )ÚVALID_3D_BACKENDSé   )ÚloggerÚverboseÚ
get_configÚ_check_optionÚfill_docÚ_validate_typeFz._qtz
._notebook)Ú	pyvistaqtÚnotebookc                 C   s$   t jt|  dd�at d|  ¡ d S )Nzmne.viz.backends)ÚnameÚpackagezUsing %s 3d backend.
)Ú	importlibÚimport_moduleÚ_backend_name_mapÚbackendr   Úinfo©Úbackend_name© r   úX/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/viz/backends/renderer.pyÚ_reload_backend   s    
ÿr   c                  O   s   t ƒ  tj| |ŽS )N)Ú_get_3d_backendr   Z	_Renderer)ÚargsÚkwargsr   r   r   Ú_get_renderer$   s    r   c                 C   s,   t | tdƒ | dkrdn| } td| tƒ | S )Nr   Zpyvistar   )r   Ústrr	   r   r   r   r   r   Ú_check_3d_backend_name)   s    r   c                 C   s$   t }t| ƒ} t | kr t| ƒ | a |S )uõ  Set the 3D backend for MNE.

    The backend will be set as specified and operations will use
    that backend.

    Parameters
    ----------
    backend_name : str
        The 3d backend to select. See Notes for the capabilities of each
        backend (``'pyvistaqt'`` and ``'notebook'``).

        .. versionchanged:: 0.24
           The ``'pyvista'`` backend was renamed ``'pyvistaqt'``.
    %(verbose)s

    Returns
    -------
    old_backend_name : str | None
        The old backend that was in use.

    Notes
    -----
    To use PyVista, set ``backend_name`` to ``pyvistaqt`` but the value
    ``pyvista`` is still supported for backward compatibility.

    This table shows the capabilities of each backend ("âœ“" for full support,
    and "-" for partial support):

    .. table::
       :widths: auto

       +--------------------------------------+-----------+----------+
       | **3D function:**                     | pyvistaqt | notebook |
       +======================================+===========+==========+
       | :func:`plot_vector_source_estimates` | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | :func:`plot_source_estimates`        | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | :func:`plot_alignment`               | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | :func:`plot_sparse_source_estimates` | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | :func:`plot_evoked_field`            | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | :func:`snapshot_brain_montage`       | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | :func:`link_brains`                  | âœ“         |          |
       +--------------------------------------+-----------+----------+
       +--------------------------------------+-----------+----------+
       | **Feature:**                                                |
       +--------------------------------------+-----------+----------+
       | Large data                           | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | Opacity/transparency                 | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | Support geometric glyph              | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | Smooth shading                       | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | Subplotting                          | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
       | Inline plot in Jupyter Notebook      |           | âœ“        |
       +--------------------------------------+-----------+----------+
       | Inline plot in JupyterLab            |           | âœ“        |
       +--------------------------------------+-----------+----------+
       | Inline plot in Google Colab          |           |          |
       +--------------------------------------+-----------+----------+
       | Toolbar                              | âœ“         | âœ“        |
       +--------------------------------------+-----------+----------+
    )ÚMNE_3D_BACKENDr   r   )r   r   Zold_backend_namer   r   r   Úset_3d_backend0   s    Ir!   c               
   C   sD   z
t ƒ } W n4 tk
r> } zd} t t|ƒ¡ W 5 d}~X Y nX | S )ai  Return the 3D backend currently used.

    Returns
    -------
    backend_used : str | None
        The 3d backend currently in use. If no backend is found,
        returns ``None``.

        .. versionchanged:: 0.24
           The ``'pyvista'`` backend has been renamed ``'pyvistaqt'``, so
           ``'pyvista'`` is no longer returned by this function.
    N)r   ÚRuntimeErrorr   r   r   )r   Úexcr   r   r   Úget_3d_backend�   s    
 r$   c                  C   s¸   t dkr¬tddd�a t dkrœtƒ } tD ]H}zt|ƒ W n. tk
rd } zt|ƒ| |< W 5 d}~X Y q&X |a  q¬q&tdd dd„ |  	¡ D ƒ¡ d d¡ ƒ‚nt
t ƒa tt ƒ t
t ƒa t S )	z'Load and return the current 3d backend.Nr    )ÚkeyÚdefaultz$Could not load any valid 3D backend
Ú
c                 s   s    | ]\}}|› d |› �V  qdS )z: Nr   )Ú.0r%   Úvalr   r   r   Ú	<genexpr>©   s     z"_get_3d_backend.<locals>.<genexpr>)z)

 install pyvistaqt, using pip or conda:z'pip install pyvistaqt'z('conda install -c conda-forge pyvistaqt'z4
 or install ipywidgets, if using a notebook backendz'pip install ipywidgets'z)'conda install -c conda-forge ipywidgets')r    r   Údictr   r   ÚImportErrorr   r"   ÚjoinÚitemsr   )Úerrorsr   r#   r   r   r   r   –   s,    ÿþÿr   c                 c   sD   t | ƒ}z
dV  W 5 |dk	r>zt |ƒ W n tk
r<   Y nX X dS )a0  Create a 3d visualization context using the designated backend.

    See :func:`mne.viz.set_3d_backend` for more details on the available
    3d backends and their capabilities.

    Parameters
    ----------
    backend_name : {'pyvistaqt', 'notebook'}
        The 3d backend to use in the context.
    N)r!   Ú	Exception)r   Zold_backendr   r   r   Úuse_3d_backend¹   s    
r1   c                 c   sF   t ƒ �6 t| ƒ�" t |¡� dV  W 5 Q R X W 5 Q R X W 5 Q R X dS )zÚCreate a testing viz context.

    Parameters
    ----------
    backend_name : str
        The 3d backend to use in the context.
    interactive : bool
        If True, ensure interactive elements are accessible.
    N)Ú_actors_invisibler1   r   Z_testing_context)r   Úinteractiver   r   r   Ú_use_test_3d_backendÐ   s    
r4   c                  c   s   t } da z
d V  W 5 | a X d S )NT)ÚMNE_3D_BACKEND_TESTING)Zorig_testingr   r   r   r2   á   s
    
r2   Tc              	   C   s   t j| ||||||d� dS )a&  Configure the view of the given scene.

    Parameters
    ----------
    figure : object
        The scene which is modified.
    %(azimuth)s
    %(elevation)s
    %(focalpoint)s
    %(distance)s
    %(roll)s
    reset_camera : bool
       If True, reset the camera properties beforehand.
    ©ÚfigureZazimuthZ	elevationZ
focalpointZdistanceZrollZreset_cameraN)r   Z_set_3d_viewr6   r   r   r   Úset_3d_viewì   s      ýr8   é(   c                 C   s   t j| ||d� dS )zâConfigure the title of the given scene.

    Parameters
    ----------
    figure : object
        The scene which is modified.
    title : str
        The title of the scene.
    size : int
        The size of the title.
    ©r7   ÚtitleÚsizeN)r   Z_set_3d_titler:   r   r   r   Úset_3d_title  s    r=   ©r   r   r   )ÚsceneÚshowc                C   s&   t || |||d�}|r| ¡ S |S dS )aH  Return an empty figure based on the current 3d backend.

    .. warning:: Proceed with caution when the renderer object is
                 returned (with ``scene=False``) because the _Renderer
                 API is not necessarily stable enough for production,
                 it's still actively in development.

    Parameters
    ----------
    size : tuple
        The dimensions of the 3d figure (width, height).
    bgcolor : tuple
        The color of the background.
    smooth_shading : bool
        If True, smooth shading is enabled. Defaults to True.
    handle : int | None
        The figure identifier.
    scene : bool
        If True (default), the returned object is the Figure3D. If False,
        an advanced, undocumented Renderer object is returned (the API is not
        stable or documented, so this is not recommended).
    show : bool
        If True, show the renderer immediately.

        .. versionadded:: 1.0

    Returns
    -------
    figure : instance of Figure3D or ``Renderer``
        The requested empty figure or renderer, depending on ``scene``.
    )Zfigr<   ÚbgcolorÚsmooth_shadingr@   N)r   r?   )r<   rA   rB   Úhandler?   r@   Úrendererr   r   r   Úcreate_3d_figure  s    !ûrE   c                 C   s   t  | ¡ dS )zzClose the given scene.

    Parameters
    ----------
    figure : object
        The scene which needs to be closed.
    N)r   Z_close_3d_figure)r7   r   r   r   Úclose_3d_figureA  s    rF   c                   C   s   t  ¡  dS )z/Close all the scenes of the current 3d backend.N)r   Z
_close_allr   r   r   r   Úclose_all_3d_figuresL  s    rG   c                  C   s   ddl m}  | S )z°Return the proper Brain class based on the current 3d backend.

    Returns
    -------
    brain : object
        The Brain class corresponding to the current 3d backend.
    r   ©ÚBrain)Z
viz._brainrI   rH   r   r   r   Úget_brain_classQ  s    rJ   )N)F)NNNNNT)r9   )r>   TN)"Ú__doc__Ú
contextlibr   r   Z_utilsr   Úutilsr   r   r   r	   r
   r   r    r5   ZMNE_3D_BACKEND_INTERACTIVEr+   r   r   r   r   r   r!   r$   r   r1   r4   r2   r8   r=   rE   rF   rG   rJ   r   r   r   r   Ú<module>   sT   	 þP#


       þ
  ÿ ÿ.