How to use the mayavi.mlab.gcf 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 enthought / enable / examples / enable / vtk_example.py View on Github external
def main():
    from basic_move import Box
    from enable.api import Container
    container = Container()
    box = Box(bounds=[30,30], position=[20,20], padding=5)
    container.add(box)

    # Create the mlab test mesh and get references to various parts of the
    # VTK pipeline
    m = mlab.test_mesh()
    scene = mlab.gcf().scene
    render_window = scene.render_window
    renderer = scene.renderer
    rwi = scene.interactor

    # Create the Enable Window
    window = EnableVTKWindow(rwi, renderer,
            component=container,
            #istyle_class = tvtk.InteractorStyleSwitch,
            istyle_class = tvtk.InteractorStyle,
            resizable = "v",
            bounds = [100, 100],
            padding_top = 20,
            padding_bottom = 20,
            padding_left = 20,
            )
github martinling / imusim / imusim / visualisation / video.py View on Github external
The video is created using the current MayaVi figure, which should be setup
    beforehand to correctly position the camera and any other elements that
    should be rendered.

    @param filename: Name of the video file to create.
    @param renderers: List of L{AnimatedRenderer} objects to use.
    @param tMin: Time from which to begin rendering.
    @param tMax: Time at which to stop rendering.
    @param framerate: Framerate of the video in frames per second.
    @param resolution: Resolution of the video (width, height). If not
        specified, the resolution of the current figure is used.
    """
    if not isinstance(renderers, collections.Iterable):
        renderers = [renderers]

    figure = mlab.gcf()
    if resolution is not None:
        originalResolution = figure.scene.get_size()
        figure.scene.set_size(resolution)
    figure.scene.off_screen_rendering = True
    figure.scene.disable_render = True

    frameTimes = np.arange(tMin, tMax, 1.0/framerate)

    try:
        imageDir = tempfile.mkdtemp()
        for f,t in enumerate(frameTimes):
            for r in renderers:
                r.renderUpdate(t)
            framefile = os.path.join(imageDir, '%06d.png'%(f))
            mlab.savefig(framefile, size=resolution)
            assert os.path.exists(framefile)
github menpo / menpo / tosort / face.py View on Github external
def _render_model(self):
    figure = mlab.gcf()
    mlab.clf()
    s = mlab.triangular_mesh(self.coords[:,0], self.coords[:,1],
                             self.coords[:,2], self.tri_index,
                             color=(0.5,0.5,0.5))
    return s.scene
github enthought / chaco / examples / demo / vtk / spectrum.py View on Github external
def main():
    from tvtk.api import tvtk
    from mayavi import mlab
    from enable.vtk_backend.vtk_window import EnableVTKWindow
    f = mlab.figure(size=(900,850))
    m = mlab.test_mesh()
    scene = mlab.gcf().scene
    render_window = scene.render_window
    renderer = scene.renderer
    rwi = scene.interactor

    # Create the plot
    timer_controller = TimerController()
    plots = create_plot_component(timer_controller)
    specplot, timeplot, spectrogram = plots

    for i, p in enumerate(plots):
        p.resizable = ""
        p.bgcolor = "transparent"
        p.bounds = [200,200]
        p.outer_x = 0
        p.outer_y = i*250
        p.tools.append(MoveTool(p, drag_button="right"))
github ofringer / suntanspy / SUNTANS / sundepths.py View on Github external
from mayavi import mlab
        # Plot the data on a 3D grid
        xy = np.column_stack((self.grd.xp,self.grd.yp))
        dvp = self.F(xy)
        vertexag = 50.0
        
        points = np.column_stack((self.grd.xp,self.grd.yp,dvp*vertexag))
        tri_type = tvtk.Triangle().cell_type
        #tet_type = tvtk.Tetra().cell_type
        ug = tvtk.UnstructuredGrid(points=points)
        ug.set_cells(tri_type, self.grd.cells)
        
        ug.cell_data.scalars = self.grd.dv
        ug.cell_data.scalars.name = 'depths'
        
        f=mlab.gcf()
        f.scene.background = (0.,0.,0.)
        d = mlab.pipeline.add_dataset(ug)
        h=mlab.pipeline.surface(d,colormap='gist_earth')
        mlab.colorbar(object=h,orientation='vertical')
        mlab.view(0,0)
        
        outfile = self.suntanspath+'/depths.png'
        f.scene.save(outfile)      
        print 'Figure saved to %s.'%outfile
github ruoyu0088 / scpy2 / tvtk / numpy_array_index_demo.py View on Github external
x, y, z = np.mgrid[:6,:7,:8]
c = np.zeros((6, 7, 8), dtype=np.int)
c.fill(1)
k = np.random.randint(2,5,size=(6, 7))

idx_i, idx_j, _ = np.ogrid[:6, :7, :8]
idx_k = k[:,:, np.newaxis] + np.arange(3)
c[idx_i, idx_j, idx_k] = np.random.randint(2,6, size=(6,7,3))

mlab.points3d(x[c>1], y[c>1], z[c>1], c[c>1], mode="cube", scale_factor=0.8, 
    scale_mode="none", transparent=True, vmin=0, vmax=8, colormap="Greys")

mlab.points3d(x[c==1], y[c==1], z[c==1], c[c==1], mode="cube", scale_factor=0.8,
    scale_mode="none", transparent=True, vmin=0, vmax=8, colormap="Greys", opacity = 0.2)
mlab.gcf().scene.background = (1,1,1)

mlab.figure()
x, y, z = np.mgrid[:6,:7,:3]
mlab.points3d(x, y, z, c[idx_i, idx_j, idx_k], mode="cube", scale_factor=0.8, 
    scale_mode="none", transparent=True, vmin=0, vmax=8, colormap="Greys", opacity = 1)
mlab.gcf().scene.background = (1,1,1)
mlab.show()
github nipy / nipy / nipy / labs / viz_tools / maps_3d.py View on Github external
global off_screen_engine
        if off_screen_engine is None:
            try:
                from mayavi.core.off_screen_engine import OffScreenEngine
            except ImportError:
                # Try out old install of Mayavi, with namespace packages
                from enthought.mayavi.core.off_screen_engine import OffScreenEngine
            off_screen_engine = OffScreenEngine()
        off_screen_engine.start()
        fig = mlab.figure('__private_plot_map_3d__', 
                                bgcolor=(1, 1, 1), fgcolor=(0, 0, 0),
                                size=(400, 330),
                                engine=off_screen_engine)
        mlab.clf(figure=fig)
    else:
        fig = mlab.gcf()
        fig = mlab.figure(fig, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0),
                                                     size=(400, 350))
    disable_render = fig.scene.disable_render
    fig.scene.disable_render = True
    if threshold is None:
        threshold = stats.scoreatpercentile(
                                np.abs(map).ravel(), 80)
    contours = []
    lower_map = map[map <= -threshold]
    if np.any(lower_map):
        contours.append(lower_map.max())
    upper_map = map[map >= threshold]
    if np.any(upper_map):
        contours.append(map[map > threshold].min())
github leon-nn / face-fitting / bin / speech-video-hmm.py View on Github external
# Render the mesh
    if t is None:
        tmesh = mlab.triangular_mesh(v[0, 0, :], v[0, 1, :], v[0, 2, :], f-1, scalars = np.arange(v.shape[2]), color = (1, 1, 1))
    
    # Add texture if given
    else:
        tmesh = mlab.triangular_mesh(v[0, 0, :], v[0, 1, :], v[0, 2, :], f-1, scalars = np.arange(v.shape[2]))
        if t.shape[1] is not 3:
            t = t.T
        tmesh.module_manager.scalar_lut_manager.lut.table = np.c_[(t * 255), alpha * 255 * np.ones(v.shape[2])].astype(np.uint8)
#        tmesh.actor.pro2perty.lighting = False
        
    # Change viewport to x-y plane and enforce orthographic projection
    mlab.view(0, 0, 'auto', 'auto')
    
    mlab.gcf().scene.parallel_projection = True
    
    # Save the first frame, then loop through the rest and save them
    mlab.savefig(saveDir + '00001.png', figure = mlab.gcf())
    tms = tmesh.mlab_source
    for i in range(1, v.shape[0]):
        fName = '{:0>5}'.format(i + 1)
        tms.set(x = v[i, 0, :], y = v[i, 1, :], z = v[i, 2, :])
        mlab.savefig(saveDir + fName + '.png', figure = mlab.gcf())
github boutproject / BOUT-dev / tools / pylib / boututils / View3D.py View on Github external
if x[i].size>1 :
          s.seed.widget = s.seed.widget_list[3]
          s.seed.widget.position=[x[i][0],0.,y[i][0]]
          s.seed.widget.enabled = False


  # A trick to make transparency look better: cull the front face
  iso.actor.property.frontface_culling = True

  #mlab.view(39, 74, 0.59, [.008, .0007, -.005])
  out=mlab.outline(extent=[-rd, rd, -rd, rd, -zd, zd], line_width=.5 )
  out.outline_mode = 'cornered'
  out.outline_filter.corner_factor = 0.0897222


  w = mlab.gcf()
  w.scene.camera.position = [13.296429046581462, 13.296429046581462, 12.979811259697154]
  w.scene.camera.focal_point = [0.0, 0.0, -0.31661778688430786]
  w.scene.camera.view_angle = 30.0
  w.scene.camera.view_up = [0.0, 0.0, 1.0]
  w.scene.camera.clipping_range = [13.220595435695394, 35.020427055647517]
  w.scene.camera.compute_view_plane_normal()
  w.scene.render()
  w.scene.show_axes = True

  mlab.show()

  if(path is not None):
  #BOUT data
  #path='../Aiba/'
  #
  #gb = file_import(path+'aiba.bout.grd.nc')