def rotate():
    mlab.figure(3)
    for tt in linspace(30,160,14):
        mlab.view(0,tt)
        mlab.draw()
        mlab.savefig('sphere-rotate%s.png' % str(int(tt)).zfill(3))
    os.system("convert sphere-rotate*.png sphere.gif")
Example #2
0
def show_votegrid(vg, color=(1, 0, 0), opacity=1):
    from enthought.mayavi import mlab
    mlab.clf()
    x, y, z = np.nonzero(vg > 0)
    if not color is None:
        mlab.points3d(x,
                      y,
                      z,
                      opacity=opacity,
                      color=color,
                      scale_factor=1,
                      scale_mode='none',
                      mode='cube')
    else:
        mlab.points3d(x,
                      y,
                      z,
                      vg[vg > 0],
                      opacity=opacity,
                      scale_factor=1,
                      scale_mode='none',
                      mode='cube')

    gridmin, gridmax = config.bounds
    X, Y, Z = np.array(gridmax) - gridmin
    #mlab.axes(extent=[0,0,0,X,Y,Z])
    mlab.draw()
Example #3
0
def view_surface():
    from enthought.mayavi import mlab
    g = Grid(surface_param)
    xyz_grid = g[-1:1:201j, -1:1:101j]
    x, y, z = xyz_grid.transposed_values
    mlab.mesh(x, y, z)
    mlab.draw()
def view_surface():
    from enthought.mayavi import mlab
    g = Grid(surface_param)
    xyz_grid = g[-1:1:201j,-1:1:101j]
    x, y, z = xyz_grid.transposed_values
    mlab.mesh(x, y, z)
    mlab.draw()
Example #5
0
    def animateVTKFiles_2D(folder):
        if not os.path.isdir(folder):
            return

        vtkFiles = []
        for f in sorted(os.listdir(folder)):
            if f.endswith(".vtk"):
                vtkFiles.append(os.path.join(folder, f))

        if len(vtkFiles) == 0:
            return

        figure = mlab.figure(size=(800, 600))
        figure.scene.disable_render = True
        vtkSource = VTKFileReader()
        vtk_file = vtkFiles[0]
        vtkSource.initialize(vtk_file)
        surface = mlab.pipeline.surface(vtkSource)
        axes = mlab.axes()
        colorbar = mlab.colorbar(object=surface, orientation='horizontal')
        mlab.view(0, 0)
        figure.scene.disable_render = False
        mlab.draw()

        a = animateVTKFiles(figure, vtkSource, vtkFiles)
Example #6
0
def show_votegrid(vg, color=(1, 0, 0), opacity=1):
    from enthought.mayavi import mlab

    mlab.clf()
    x, y, z = np.nonzero(vg > 0)
    if not color is None:
        mlab.points3d(x, y, z, opacity=opacity, color=color, scale_factor=1, scale_mode="none", mode="cube")
    else:
        mlab.points3d(x, y, z, vg[vg > 0], opacity=opacity, scale_factor=1, scale_mode="none", mode="cube")

    gridmin, gridmax = config.bounds
    X, Y, Z = np.array(gridmax) - gridmin
    # mlab.axes(extent=[0,0,0,X,Y,Z])
    mlab.draw()
Example #7
0
    def saveVTKFilesAsImages_2D(sourceFolder, destinationFolder):
        if not os.path.isdir(sourceFolder) or not os.path.isdir(
                destinationFolder):
            return

        vtkFiles = []
        for f in sorted(os.listdir(sourceFolder)):
            if f.endswith(".vtk"):
                vtkFiles.append(f)

        if len(vtkFiles) == 0:
            return

        figure = mlab.figure(size=(800, 600))
        figure.scene.disable_render = True
        vtkSource = VTKFileReader()
        vtk_file = os.path.join(sourceFolder, vtkFiles[0])
        vtkSource.initialize(vtk_file)
        surface = mlab.pipeline.surface(vtkSource)
        axes = mlab.axes()
        colorbar = mlab.colorbar(object=surface, orientation='horizontal')
        mlab.view(0, 0)
        figure.scene.disable_render = False
        mlab.draw()
        png_file = os.path.join(destinationFolder,
                                vtkFiles[0]).replace('.vtk', '.png')
        mlab.savefig(png_file)

        for f in vtkFiles[1:-1]:
            vtk_file = os.path.join(sourceFolder, f)
            vtkSource.initialize(vtk_file)
            png_file = os.path.join(destinationFolder,
                                    f).replace('.vtk', '.png')
            mlab.savefig(png_file)
            app = QtCore.QCoreApplication.instance()
            if app:
                app.processEvents()
Example #8
0
"""

# Create some data
import numpy as np

x, y = np.mgrid[-10:10:200j, -10:10:200j]
z = 100 * np.sin(x * y) / (x * y)

# Visualize it with mlab.surf
from enthought.mayavi import mlab
mlab.figure(bgcolor=(1, 1, 1))
surf = mlab.surf(z, colormap='cool')

# Retrieve the LUT of the surf object.
lut = surf.module_manager.scalar_lut_manager.lut.table.to_array()

# The lut is a 255x4 array, with the columns representing RGBA
# (red, green, blue, alpha) coded with integers going from 0 to 255.

# We modify the alpha channel to add a transparency gradient
lut[:, -1] = np.linspace(0, 255, 256)
# and finally we put this LUT back in the surface object. We could have
# added any 255*4 array rather than modifying an existing LUT.
surf.module_manager.scalar_lut_manager.lut.table = lut

# We need to force update of the figure now that we have changed the LUT.
mlab.draw()
mlab.view(40, 85)

mlab.show()
Example #9
0
def draw_camera (R, t, scale = 0.1, opt = 'fancy', figure = None):
    """ Draw a camera in world coords according to its pose 
    If R = id and t = [0 0 0]' show a camera in the world 
    center pointing towards the +Z axis.

    Usage: draw_camera (R, t, scale, opt);

    Input:
    R - 3x3 Rotation matrix or 3x1 Rodrigues rotation vector (camera to
       world rotation)
    t - 3x1 Translation vector (camera to world translation)
    scale - (optional) scaling parameter, in meters. Default: 0.1.
    opt - Visualization option: (default: 'pyr') 
         'pyr' shows an inverted pyramid in the camera direction
         'axis' shows the 3 axis (red for X, green for Y, blue for Z)
    """

    # Generate figure if none given
    if figure == None:
        figure = mlab.figure()

    # Enforce 2d column vector of translation
    t = np.atleast_2d(t.ravel()).T

    # Five points that define the pyramid
    # Careful, because np.c_ somehow transposes this matrix, this is 3x6.
    pyr_points = scale * np.c_[[   0,    0, 0], \
                               [-0.4, -0.4, 1], \
                               [ 0.4, -0.4, 1], \
                               [ 0.4,  0.4, 1], \
                               [-0.4,  0.4, 1], \
                               [np.nan, np.nan, np.nan]]

    pyr_tri_side = np.c_[[0, 1, 2], \
                         [0, 2, 3], \
                         [0, 3, 4], \
                         [0, 1, 4]].T

    pyr_tri_front = np.c_[[1, 2, 3], \
                          [1, 3, 4]].T

    # Four points that define the axis in 3-space
    axis_points = scale * np.c_[[0, 0, 0], \
                                [1, 0, 0], \
                                [0, 1, 0], \
                                [0, 0, 1]]

    # Order in which to draw the points, so that it looks like 3 axis
    axis_idx_x = np.r_[1, 2] - 1
    axis_idx_y = np.r_[1, 3] - 1
    axis_idx_z = np.r_[1, 4] - 1

    # Some color constants
    RED   = (1,0,0)
    GREEN = (0,1,0)
    BLUE  = (0,0,1)
    
    if opt == 'pyr':  
        # Rotate pyramid and plot it
        tx_pyr = np.dot(R, pyr_points) + \
                 np.tile( t, (1, pyr_points.shape[1]) )

        mlab.triangular_mesh(tx_pyr[0, :],  \
                             tx_pyr[1, :],  \
                             tx_pyr[2, :],  \
                             pyr_tri_side,        \
                             color = BLUE,        \
                             figure = figure)
        mlab.draw() 
        mlab.triangular_mesh(tx_pyr[0, :],  \
                             tx_pyr[1, :],  \
                             tx_pyr[2, :],  \
                             pyr_tri_front,       \
                             color = GREEN,       \
                             figure = figure)       


    elif opt == 'axis':
        # Rotate the 3 axis and plot them
        tx_axis = np.dot(R, axis_points) + \
                  np.tile( t, (1, axis_points.shape[1]) )

        mlab.plot3d(tx_axis[0, axis_idx_x], \
                    tx_axis[1, axis_idx_x], \
                    tx_axis[2, axis_idx_x], \
                    color = RED, \
                    tube_radius = .003, \
                    figure = figure)
        
        mlab.plot3d(tx_axis[0, axis_idx_y], \
                    tx_axis[1, axis_idx_y], \
                    tx_axis[2, axis_idx_y], \
                    color = GREEN, \
                    tube_radius = .003, \
                    figure = figure)

        mlab.plot3d(tx_axis[0, axis_idx_z], \
                    tx_axis[1, axis_idx_z], \
                    tx_axis[2, axis_idx_z], \
                    color = BLUE, \
                    tube_radius = .003, \
                    figure = figure)

    elif opt == 'fancy':
        # Rotate pyramid and plot it
        tx_pyr = np.dot(R, pyr_points) + \
                 np.tile( t, (1, pyr_points.shape[1]) )

        mlab.triangular_mesh(tx_pyr[0, :],  \
                             tx_pyr[1, :],  \
                             tx_pyr[2, :],  \
                             pyr_tri_side,        \
                             color = BLUE,        \
                             figure = figure)

        mlab.triangular_mesh(tx_pyr[0, :],  \
                             tx_pyr[1, :],  \
                             tx_pyr[2, :],  \
                             pyr_tri_front,       \
                             color = GREEN,       \
                             figure = figure)     
        
        # Rotate the 3 axis and plot them
        tx_axis = np.dot(R, axis_points) + \
                  np.tile( t, (1, axis_points.shape[1]) )

        mlab.plot3d(tx_axis[0, axis_idx_x], \
                    tx_axis[1, axis_idx_x], \
                    tx_axis[2, axis_idx_x], \
                    color = RED, \
                    tube_radius = .003, \
                    figure = figure)
        
        mlab.plot3d(tx_axis[0, axis_idx_y], \
                    tx_axis[1, axis_idx_y], \
                    tx_axis[2, axis_idx_y], \
                    color = GREEN, \
                    tube_radius = .003, \
                    figure = figure)


    else: 
        print('Unrecognized option');
Example #10
0
f = mlab.figure(size=(800,600))
# Tell visual to use this as the viewer.
visual.set_viewer(f)

########################################################
# Do the appropriate graph

#s = mlab.contour_surf(r,z,fun, contours=30, line_width=.5, transparent=True)
#s=mlab.surf(r,z,fun, colormap='Spectral')
s = mlab.mesh(r,z,fm[0,:,:], scalars=fm[0,:,:], colormap='PuOr')#, wrap_scale='true')#, representation='wireframe')
s.enable_contours=True
s.contour.filled_contours=True

# Define perspective and optional attributes. You can also implement from the window afterwards

mlab.view(0,0)
#mlab.view(-94.159958841373324,
# 53.777002382688906,
# 8.2311808018087582)
mlab.draw(f)
mlab.colorbar(orientation="vertical")
#mlab.axes()
#mlab.outline()


########################################################
# mlab animation 

anim(s,fm, save=True)
Example #11
0
f = mlab.figure(size=(800,600))
# Tell visual to use this as the viewer.
visual.set_viewer(f)

########################################################
# Do the appropriate graph

#s = mlab.contour_surf(r,z,fun, contours=30, line_width=.5, transparent=True)
#s=mlab.surf(r,z,fun, colormap='Spectral')
s = mlab.mesh(r,z,fm[0,:,:], scalars=fm[0,:,:], colormap='PuOr')#, wrap_scale='true')#, representation='wireframe')
s.enable_contours=True
s.contour.filled_contours=True

# Define perspective and optional attributes. You can also implement from the window afterwards

mlab.view(0,0)
#mlab.view(-94.159958841373324,
# 53.777002382688906,
# 8.2311808018087582)
mlab.draw(f)
mlab.colorbar(orientation="vertical")
#mlab.axes()
#mlab.outline()


########################################################
# mlab animation

anim(s,fm, save=True)
Example #12
0
right_ys = []

for line in data:
    cm = line.split()
    top_xs.append(float(cm[0]))
    left_zs.append(float(cm[2]))
    right_ys.append(float(cm[1]))

    dms.append(float(cm[9]))

# diameters
mlab.options.offscreen = True

mlab.figure(1, bgcolor=(1, 1, 1), size=(1280, 720))
dms = [x / 2.0 for x in dms]
q = mlab.quiver3d(top_xs, right_ys, left_zs, dms, dms, dms, mode='sphere', scale_factor=1)
mlab.orientation_axes()
mlab.outline(color=(0,0,0), line_width=1.0)
a = mlab.axes(color=(0.1,0.1,0.1), nb_labels=3, line_width=1.0)
a.axes.axis_label_text_property.color = (0,0,0)

q.scene.isometric_view()

count = 1
while count < 360:
    q.scene.camera.azimuth(1)
    mlab.draw()
    mlab.savefig('animate/' + stage + '-dms-animated-' + str(count).zfill(3) + '.png')
    count += 1
    print(count)