Example #1
0
def toggle3d(state=True, nb_backend=None, **kwds):
    """
    Switch on/off the mayavi backend.
    
    **Parameters**

    state: bool | True
        on/off state of the mayavi backend
    nb_backend: | None
        type of rendering engine choose from 'x3d' (interactive) and 'png' (static).
    **kwds: keyword arguments
        additional arguments to be passed into ``mayavi.mlab.init_notebook()``.
    """

    global PLOT3D
    PLOT3D = state
    if PLOT3D == True:
        global mlab
        from mayavi import mlab
        if nb_backend:
            mlab.init_notebook(nb_backend, **kwds)
    else:
        try:
            mlab = None
        except:
            pass
Example #2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if self._get_mode() == 0:
            mlab.init_notebook()

        size = (600, 400)
        if self.size:
            size = self.size
        self._fig = mlab.figure(
            size=size,
            bgcolor=cfg["mayavi"]["bg_color"],
            fgcolor=cfg["mayavi"]["fg_color"],
        )
Example #3
0
def show_fem(u, local=False, show_volume=True, show_plane=True):
    global fem_counter
    fem_counter = fem_counter + 1
    mlab.init_notebook()
    mlab.clf()
    name_base = "./tmp_u_" + str(fem_counter)
    dolfin.File(name_base + ".pvd") << u
    time.sleep(1)
    s = mlab.pipeline.open(name_base + '000000.vtu')
    #mlab.pipeline.volume(s)
    #mlab.contour3d(s)
    if show_volume:
        scp = mlab.pipeline.volume(s)
    if show_plane:
        scp = mlab.pipeline.scalar_cut_plane(s, view_controls=True)
    return scp
Example #4
0
def show_geom(g, local=False, step=0.6, show_surface=True):
    if not local:
        stl_file = getStl(g, step=step)
        time.sleep(3)
        print(stl_file)
        mlab.init_notebook()
        mlab.clf()

        s = mlab.pipeline.open(stl_file)

        if show_surface:
            s = mlab.pipeline.surface(s)
        return s
    else:
        result = DisplayShape(trans_box,
                              export_edges=True,
                              color=rnd_color,
                              transparency=random.random())
        return display(result)
    def postprocessing(self):
        import mayavi, vtk, os
        from mayavi import mlab
        mlab.init_notebook()

        from mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader
        from mayavi.sources.vrml_importer import VRMLImporter
        from mayavi.modules.outline import Outline
        from mayavi.modules.streamline import Streamline
        from mayavi.modules.iso_surface import IsoSurface
        from mayavi.sources.vtk_file_reader import VTKFileReader

        print('Mayavi {}, {}, DISPLAY {}'.format(mayavi.__version__, vtk.vtkVersion.GetVTKSourceVersion(), os.environ['DISPLAY']))
        

        # fetch the results
        
        fname='Composition_00010000.vtk'
        oc_proj_base = self.wJobPath.value.strip(' /')

        oc=DavProxy()
        oc.set_token()
        oc.get(oc_proj_base + '/OP/VTK/'+fname, './' + fname)
        
        # run mlab pipeline
        
        
        
        mlab.clf() # clear figure
        r = VTKFileReader()
        r.initialize(fname)
        r.point_scalars_name = 'TotalComposition_Li'
        
        scp=mlab.pipeline.scalar_cut_plane(r, view_controls=False,plane_orientation='y_axes')
        scpx=mlab.pipeline.scalar_cut_plane(r, view_controls=False,plane_orientation='x_axes')
        mlab.pipeline.outline(r)
        col_cp=mlab.scalarbar(scp, title='C(Li)', orientation='vertical')
        return mlab.gcf() # plot
Example #6
0
# <markdowncell>
# ![interpolation](figures/interpolation_discrete.png)
# ![exact solution](figures/interpolation_exact.png)
# ![interpolation error](figures/interpolation_error.png)
# <codecell>

# <markdowncell>
# Mayavi can also be used to plot grid function in Python. This approach
# relies on methods to extract `numpy` representations of the grid data
# structure and values of a given grid function.
#
# __Note__: mayavi is not installed in the Docker image and, therefore,
# this feature is not available the Docker container.
# <codecell>

level = 3
triangulation = f.grid.triangulation(level)
z = f.pointData(level)[:, 0]
try:
    from mayavi import mlab
    from mayavi.tools.notebook import display
    mlab.init_notebook("png")
    mlab.figure(bgcolor=(1, 1, 1))
    s = mlab.triangular_mesh(triangulation.x, triangulation.y, z * 0.5,
                             triangulation.triangles)
    display(s)
    # mlab.savefig("mayavi.png", size=(400,300))
    mlab.close(all=True)
except ImportError:
    pass
Example #7
0

import os
import sys
import re
import pickle  # todo: current pickle file are using format 3 witch is not compatible with python2
from meshpy.obj_file import ObjFile
from meshpy.sdf_file import SdfFile
from dexnet.grasping import GraspableObject3D
import numpy as np
from dexnet.visualization.visualizer3d import DexNetVisualizer3D as Vis
from dexnet.grasping import RobotGripper
from autolab_core import YamlConfig
try:
    from mayavi import mlab
    mlab.init_notebook('x3d', 800, 800)
except ImportError:
    print("can not import mayavi")
    mlab = None
from dexnet.grasping import GpgGraspSampler  # temporary way for show 3D gripper using mayavi
import pcl
import glob
from IPython.display import display


# In[2]:


# global configurations:
home_dir = os.environ['HOME']
yaml_config = YamlConfig(home_dir + "/code/grasp-pointnet/dex-net/test/config.yaml")
Example #8
0
def init():
    display = Xvfb(width=500, height=500)
    display.start()
    mlab.init_notebook()
Example #9
0
 def plot3d(uh,level):
     x, triangles = uh.space.grid.tesselate(level)
     mlab.init_notebook("png") # use x3d for interactive plotting in the notebook
     mlab.figure(bgcolor = (1,1,1))
     s = mlab.triangular_mesh(x[:,0],x[:,1],x[:,2],triangles)
     display( s )
Example #10
0
from mayavi import mlab
import numpy as np
mlab.init_notebook('x3d', 400, 200, local=False)

mlab.clf()

theta = np.linspace(0, 2 * np.pi, 100)
phi = np.linspace(0, 2 * np.pi, 100)

X = np.outer((20 + 4 * np.cos(phi)), np.cos(theta))
Y = np.outer((20 + 4 * np.cos(phi)), np.sin(theta))
Z = np.outer(np.sin(phi), 1.8 * np.ones(np.size(theta)))

#the position of the ball
x = np.array([2.5, 3.0, 3.0])
y = np.array([3.0, 2.5, 3.0])
z = np.array([3.0, 3.0, 2.5])

mlab.clf()
mlab.points3d(x[1:-1],
              y[1:-1],
              z[1:-1],
              color=(1, 1, 1),
              resolution=20,
              scale_factor=3)
mlab.mesh(X, Y, Z, representation='wireframe')
mlab.title('3D Torus Billiard')
Find closest trajectories
=========================
Finds the probe insertions that are closest a a specified probe insertion of interest and plots
their location in a 3D image. Additionally prints out the information of closeby sessions
"""

# Author: Mayo Faulkner
# import modules
import numpy as np
import ibllib.pipes.histology as histology
import ibllib.atlas as atlas
from oneibl.one import ONE
from mayavi import mlab
from atlaselectrophysiology import rendering

mlab.init_notebook()
# Instantiate brain atlas and one
brain_atlas = atlas.AllenAtlas(25)
one = ONE()

# Find all trajectories with histology tracing
all_hist = one.alyx.rest('trajectories', 'list', provenance='Histology track')
# Some do not have tracing, exclude these ones
sess_with_hist = [sess for sess in all_hist if sess['x'] is not None]
traj_ids = [sess['id'] for sess in sess_with_hist]
# Compute trajectory objects for each of the trajectories
trajectories = [atlas.Insertion.from_dict(sess) for sess in sess_with_hist]

# Find the trajectory of the id that you want to find closeby probe insertions for
subject = 'SWC_023'
date = '2020-02-13'
Example #12
0
label_title = Label(Mafenetre, text="Welcome to billiard game")
label_title.pack()
# Création d'un widget Canvas
Canevas = Canvas(Mafenetre, height=HAUTEUR, width=LARGEUR, bg='green')
Canevas.pack(padx=5, pady=5)
# Création d'un objet graphique
Balle = Canevas.create_oval(X - RAYON,
                            Y - RAYON,
                            X + RAYON,
                            Y + RAYON,
                            width=1,
                            fill='white')
#Bouton quitter
Bouton_Quitter = Button(Mafenetre, text='Quit', command=Mafenetre.destroy)
Bouton_Quitter.pack()

deplacement()
Mafenetre.mainloop()

from mayavi import mlab
mlab.init_notebook(backend='x3d', local=False)

theta = np.linspace(0, 2 * np.pi, 100)
phi = np.linspace(0, 2 * np.pi, 100)

X = np.outer((1 + 0.2 * np.cos(phi)), np.cos(theta))
Y = np.outer((1 + 0.2 * np.cos(phi)), np.sin(theta))
Z = np.outer(np.sin(phi), 0.09 * np.ones(np.size(theta)))

mlab.clf()
mlab.mesh(X, Y, Z, representation='wireframe')
# Linden Parkes, 2019
# [email protected]

import os
import numpy as np
import nibabel as nib
import mayavi as my
from mayavi import mlab
mlab.init_notebook(backend='png')
import surfer
import math

from matplotlib.pyplot import get_cmap


def roi_to_vtx(roi_data, parcel_names, parc_file):
    # roi_data      = (num_nodes,) array vector of node-level data to plot onto surface
    #
    #
    # parcel_names     = (num_nodes,) array vector of strings containg roi names
    #               corresponding to roi_data
    #
    # parc_file    = full path and file name to surface file
    #               Note, I used fsaverage/fsaverage5 surfaces

    # Load freesurfer file
    labels, ctab, surf_names = nib.freesurfer.read_annot(parc_file)

    # convert FS surf_names to array of strings
    if type(surf_names[0]) != str:
        for i in np.arange(0, len(surf_names)):