How to use the mayavi.mlab function in mayavi

To help you get started, we’ve selected a few mayavi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lambdaloop / anipose / anipose / label_videos_3d.py View on Github external
points = np.copy(all_points[:, 20])
    points[0] = low
    points[1] = high

    s = np.arange(points.shape[0])
    good = ~np.isnan(points[:, 0])

    fig = mlab.figure(bgcolor=(1,1,1), size=(500,500))
    fig.scene.anti_aliasing_frames = 2

    low, high = np.percentile(points[good, 0], [10,90])
    scale_factor = (high - low) / 10.0

    mlab.clf()
    pts = mlab.points3d(points[:, 0], -points[:, 1], points[:, 2], s,
                        scale_mode='none', scale_factor=scale_factor)
    lines = connect_all(points, scheme, bp_dict, cmap)
    mlab.orientation_axes()

    view = list(mlab.view())

    mlab.view(focalpoint='auto', distance='auto')

    for framenum in trange(data.shape[0], ncols=70):
        fig.scene.disable_render = True

        if framenum in framedict:
            points = all_points[:, framenum]
        else:
            points = np.ones((nparts, 3))*np.nan
github enthought / mayavi / examples / mayavi / mlab / boy.py View on Github external
The boy surface is a mathematical parametric surface, see
http://en.wikipedia.org/wiki/Boy%27s_surface . We display it by sampling
the two parameters of the surface on a grid and using the mlab's mesh
function: :func:`mayavi.mlab.mesh`.
"""

# Author: Gael Varoquaux 
# Copyright (c) 2007, Enthought, Inc.
# License: BSD Style.


from numpy import sin, cos, mgrid, pi, sqrt
from mayavi import mlab

mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))
u, v = mgrid[- 0.035:pi:0.01, - 0.035:pi:0.01]

X = 2 / 3. * (cos(u) * cos(2 * v)
        + sqrt(2) * sin(u) * cos(v)) * cos(u) / (sqrt(2) -
                                                 sin(2 * u) * sin(3 * v))
Y = 2 / 3. * (cos(u) * sin(2 * v) -
        sqrt(2) * sin(u) * sin(v)) * cos(u) / (sqrt(2)
        - sin(2 * u) * sin(3 * v))
Z = -sqrt(2) * cos(u) * cos(u) / (sqrt(2) - sin(2 * u) * sin(3 * v))
S = sin(u)

mlab.mesh(X, Y, Z, scalars=S, colormap='YlGnBu', )

# Nice view from the front
mlab.view(.0, - 5.0, 4)
mlab.show()
github jeremiedecock / snippets / python / mayavi / plot3d / demo_mayavi.py View on Github external
# Build datas ###############

x = np.arange(-5, 5, 0.25)
y = np.arange(-5, 5, 0.25)
x,y = np.meshgrid(x, y)
#x,y = np.mgrid[-5:5, -5:5]

r = np.sqrt(x**2 + y**2)
z = np.sin(r)

# Plot data #################

s = mlab.mesh(x, y, z)
#s = mlab.surf(z)

mlab.show()
github julienr / meshcut / examples / utils.py View on Github external
def points3d(verts, point_size=3, **kwargs):
    if 'mode' not in kwargs:
        kwargs['mode'] = 'point'
    p = mlab.points3d(verts[:, 0], verts[:, 1], verts[:, 2], **kwargs)
    p.actor.property.point_size = point_size
github sfepy / sfepy / sfepy / postprocess / utils.py View on Github external
return_only : boolean
        If True, do not print the information, just return it to the caller.

    use_names : list of strings
        Consider only data with names in the list.

    filter_names : list of strings
        Consider only data with names not in the list.

    Returns
    -------
    ranges : dict
        The requested data ranges.
    """
    if isinstance(obj, basestr):
        mlab.options.offscreen = True
        scene = mlab.figure(bgcolor=(1,1,1), fgcolor=(0, 0, 0), size=(1, 1))
        obj = mlab.pipeline.open(obj)

    if filter_names is None:
        filter_names = []

    source = obj
    while not (isinstance(source, Source)
               and not isinstance(source, Filter)):
        source = source.parent

    try:
        dm = dataset_manager.DatasetManager(dataset=source.outputs[0].output)

    except AttributeError:
        # Prior to Mayavi 4.6.2.
github enthought / mayavi / examples / mayavi / mlab / lucy.py View on Github external
# Extract the data
import tarfile
lucy_tar_file = tarfile.open('lucy.tar.gz')
try:
    os.mkdir('lucy_data')
except:
    pass
lucy_tar_file.extractall('lucy_data')
lucy_tar_file.close()

# Path to the lucy ply file
lucy_ply_file = join('lucy_data', 'lucy.ply')

# Render the lucy ply file
mlab.pipeline.surface(mlab.pipeline.open(lucy_ply_file))
mlab.show()

import shutil
shutil.rmtree('lucy_data')
github lambdaloop / anipose / anipose / label_videos_3d.py View on Github external
if framenum in framedict:
            points = all_points[:, framenum]
        else:
            points = np.ones((nparts, 3))*np.nan

        s = np.arange(points.shape[0])
        good = ~np.isnan(points[:, 0])

        new = np.vstack([points[:, 0], -points[:, 1], points[:, 2]]).T
        pts.mlab_source.points = new
        update_all_lines(lines, points, scheme, bp_dict)

        fig.scene.disable_render = False

        img = mlab.screenshot()

        mlab.view(*view, reset_roll=False)

        writer.writeFrame(img)

    mlab.close(all=True)
    writer.close()
github stanford-iprl-lab / sceneflownet / segNet2 / tf_libs / experiment.py View on Github external
pred_rot = self.predv['rot_masked'][0][frame2_model_id] 
            pred_rot = np.mean(pred_rot,axis=0)

            gt_rot = self.gtv['rot'][0][frame2_model_id] 
            gt_rot = np.mean(gt_rot,axis=0)
            print('gt_rot')
            print(gt_rot)
            print(np.linalg.norm(gt_rot))

            pred_rot = angleaxis_rotmatrix(pred_rot)        
            pred_frame1_xyz_ = pred_rot.dot(pred_frame1_xyz_.T).T + frame1_center
                
            frame1_model_id = self.gtv['frame1_id'][0] == frame_id_
            input_frame1_xyz = self.inputv['frame1_xyz'][0][frame1_model_id]
            input_frame2_xyz = self.inputv['frame2_xyz'][0][frame2_model_id]  
            mayalab.points3d(pred_frame1_xyz_[:,0], pred_frame1_xyz_[:,1], pred_frame1_xyz_[:,2], color=(0,1,0),mode='sphere',scale_factor=0.01)
        
            mayalab.points3d(input_frame1_xyz[:,0],input_frame1_xyz[:,1],input_frame1_xyz[:,2], color=(1,0,0),mode='sphere',scale_factor=0.01) 
            mayalab.points3d(input_frame2_xyz[:,0],input_frame2_xyz[:,1],input_frame2_xyz[:,2], color=(0,0,1),mode='sphere',scale_factor=0.01) 
 
        mayalab.show()
 
         
        #mayalab.points3d(input_frame2_xyz[:,0],input_frame2_xyz[:,1],input_frame2_xyz[:,2],color=(0,1,0),mode='point')
        #mayalab.points3d(predxyz[:,0],predxyz[:,1],predxyz[:,2],mode='point')
        #mayalab.points3d(gtxyz[:,0],gtxyz[:,1],gtxyz[:,2],color=(0,0,1),mode='point')
        #for jj in xrange(num_):
        #  mayalab.points3d(center[jj:jj+1,0],center[jj:jj+1,1],center[jj:jj+1,2],color=(1,0,0),mode='sphere',opacity=0.1,scale_mode='vector',scale_factor=r[jj])
          #mayalab.points3d(center[jj:jj+1,0],center[jj:jj+1,1],center[jj:jj+1,2],color=(1,0,0),mode='sphere',opacity=1.0,scale_mode='vector',scale_factor=0.001)

        #mayalab.quiver3d(flow_xyz[:,0], flow_xyz[:,1], flow_xyz[:,2], flow_dir[:,0], flow_dir[:,1], flow_dir[:,2],scale_mode='vector',scale_factor=0.9)
         #direction = predxyz-inputxyz