Exemplo n.º 1
0
def plot_cartesian(traj,
                   xaxis=None,
                   yaxis=None,
                   zaxis=None,
                   color='b',
                   label='_nolegend_',
                   linewidth=2,
                   scatter_size=20):
    ''' xaxis - x axis for the graph (0,1 or 2)
        zaxis - for a 3d plot. not implemented.
    '''

    import arm_trajectories as at
    #if traj.__class__ == at.JointTrajectory:
    if isinstance(traj, at.JointTrajectory):
        traj = joint_to_cartesian(traj)

    pts = np.matrix(traj.p_list).T
    label_list = ['X coord (m)', 'Y coord (m)', 'Z coord (m)']
    x = pts[xaxis, :].A1.tolist()
    y = pts[yaxis, :].A1.tolist()

    if zaxis == None:
        pl.plot(x, y, c=color, linewidth=linewidth, label=label)
        pl.scatter(
            x, y, c=color, s=scatter_size, label='_nolegend_', linewidths=0)
        pl.xlabel(label_list[xaxis])
        pl.ylabel(label_list[yaxis])
        pl.legend(loc='best')
        pl.axis('equal')
    else:
        from numpy import array
        from enthought.mayavi.api import Engine
        engine = Engine()
        engine.start()
        if len(engine.scenes) == 0:
            engine.new_scene()

        z = pts[zaxis, :].A1.tolist()
        time_list = [t - traj.time_list[0] for t in traj.time_list]
        mlab.plot3d(x, y, z, time_list, tube_radius=None, line_width=4)
        mlab.axes()
        mlab.xlabel(label_list[xaxis])
        mlab.ylabel(label_list[yaxis])
        mlab.zlabel(label_list[zaxis])
        mlab.colorbar(title='Time')

        # -------------------------------------------
        axes = engine.scenes[0].children[0].children[0].children[1]
        axes.axes.position = array([0., 0.])
        axes.axes.label_format = '%-#6.2g'
        axes.title_text_property.font_size = 4
Exemplo n.º 2
0
def plot_cartesian(traj, xaxis=None, yaxis=None, zaxis=None, color='b',label='_nolegend_',
                   linewidth=2, scatter_size=10, plot_velocity=False):

    import arm_trajectories as at
    #if traj.__class__ == at.JointTrajectory:
    if isinstance(traj,at.JointTrajectory):
        traj = joint_to_cartesian(traj)

    pts = np.matrix(traj.p_list).T
    label_list = ['X coord (m)', 'Y coord (m)', 'Z coord (m)']
    x = pts[xaxis,:].A1.tolist()
    y = pts[yaxis,:].A1.tolist()

    if plot_velocity:
        vels = np.matrix(traj.v_list).T
        xvel = vels[xaxis,:].A1.tolist()
        yvel = vels[yaxis,:].A1.tolist()

    if zaxis == None:
        mpu.plot_yx(y, x, color, linewidth, '-', scatter_size, label,
                    axis = 'equal', xlabel = label_list[xaxis],
                    ylabel = label_list[yaxis],)
        if plot_velocity:
            mpu.plot_quiver_yxv(y, x, np.matrix([xvel,yvel]),
                                width = 0.001, scale = 1.)
        mpu.legend()
    else:
        from numpy import array
        from enthought.mayavi.api import Engine
        engine = Engine()
        engine.start()
        if len(engine.scenes) == 0:
            engine.new_scene()

        z = pts[zaxis,:].A1.tolist()
        time_list = [t-traj.time_list[0] for t in traj.time_list]
        mlab.plot3d(x,y,z,time_list,tube_radius=None,line_width=4)
        mlab.axes()
        mlab.xlabel(label_list[xaxis])
        mlab.ylabel(label_list[yaxis])
        mlab.zlabel(label_list[zaxis])
        mlab.colorbar(title='Time')

        # ------------------------------------------- 
        axes = engine.scenes[0].children[0].children[0].children[1]
        axes.axes.position = array([ 0.,  0.])
        axes.axes.label_format = '%-#6.2g'
        axes.title_text_property.font_size=4
Exemplo n.º 3
0
def plot_cartesian(traj, xaxis=None, yaxis=None, zaxis=None, color='b',label='_nolegend_',
                   linewidth=2, scatter_size=10, plot_velocity=False):
    import matplotlib_util.util as mpu
    import arm_trajectories as at
    #if traj.__class__ == at.JointTrajectory:
    if isinstance(traj,at.JointTrajectory):
        traj = joint_to_cartesian(traj)

    pts = np.matrix(traj.p_list).T
    label_list = ['X coord (m)', 'Y coord (m)', 'Z coord (m)']
    x = pts[xaxis,:].A1.tolist()
    y = pts[yaxis,:].A1.tolist()

    if plot_velocity:
        vels = np.matrix(traj.v_list).T
        xvel = vels[xaxis,:].A1.tolist()
        yvel = vels[yaxis,:].A1.tolist()

    if zaxis == None:
        mpu.plot_yx(y, x, color, linewidth, '-', scatter_size, label,
                    axis = 'equal', xlabel = label_list[xaxis],
                    ylabel = label_list[yaxis],)
        if plot_velocity:
            mpu.plot_quiver_yxv(y, x, np.matrix([xvel,yvel]),
                                width = 0.001, scale = 1.)
        mpu.legend()
    else:
        from numpy import array
        from enthought.mayavi.api import Engine
        engine = Engine()
        engine.start()
        if len(engine.scenes) == 0:
            engine.new_scene()

        z = pts[zaxis,:].A1.tolist()
        time_list = [t-traj.time_list[0] for t in traj.time_list]
        mlab.plot3d(x,y,z,time_list,tube_radius=None,line_width=4)
        mlab.axes()
        mlab.xlabel(label_list[xaxis])
        mlab.ylabel(label_list[yaxis])
        mlab.zlabel(label_list[zaxis])
        mlab.colorbar(title='Time')

        # ------------------------------------------- 
        axes = engine.scenes[0].children[0].children[0].children[1]
        axes.axes.position = array([ 0.,  0.])
        axes.axes.label_format = '%-#6.2g'
        axes.title_text_property.font_size=4
Exemplo n.º 4
0
 def __init__(self, data, scene, minv, maxv, warp=1, scalarbar=False,
              points=True, surf=True):
     self.data, self.min, self.max, self.warp = data, minv, maxv, warp
     self.scalarbar = scalarbar
     global engine
     if engine is None: # If Mayavi is not running already
         from enthought.mayavi.api import Engine
         engine = Engine()
         engine.start() # start Mayavi (only works in ipython)
     self.scene = engine.new_scene() if scene is None else scene
     self.source = sapi.VTKDataSource()
     engine.add_source(self.source, scene=self.scene)
     self.update_data()
     if points: self.plot_points()
     if surf: self.plot_surf()
     self.scene.scene.isometric_view()
# Recorded script from Mayavi2
from numpy import array

import os
import fnmatch
from enthought.mayavi.modules.orientation_axes import OrientationAxes
import enthought.mayavi.mlab
from enthought.mayavi.api import OffScreenEngine

try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# -------------------------------------------
dir = os.getcwd()

for file0 in os.listdir('.'):
    if fnmatch.fnmatch(file0, '*AMP.rec'):
        filename = file0
        print filename
        savename = filename

        ##
        scene1 = engine.new_scene()
        scene1.scene.off_screen_rendering = True

        jesse_mat_lab_coord_source1 = engine.open(filename, scene1)
Exemplo n.º 6
0
# Recorded script from Mayavi2
from numpy import array
try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# ------------------------------------------- 
scene = engine.scenes[0]
vtkxml_file_reader = engine.open(u'/Users/prabhu/work/MEDIA/m2/data/solution.vtp', scene)
from enthought.mayavi.modules.surface import Surface
surface = Surface()
engine.add_filter(surface, vtkxml_file_reader)
scene.scene.camera.position = [-5.0805380472988206, -22.772737120755238, 27.951999647518075]
scene.scene.camera.focal_point = [-0.30313491821289062, 0.0, 1.4027749300003052]
scene.scene.camera.view_angle = 30.0
scene.scene.camera.view_up = [-0.1142423672711194, 0.76412329986979977, 0.63487342369670707]
scene.scene.camera.clipping_range = [22.838642391722981, 51.077591804257452]
scene.scene.camera.compute_view_plane_normal()
scene.scene.render()
scene.scene.camera.position = [-26.79814746753679, -17.616423028517339, 16.698474306673273]
scene.scene.camera.focal_point = [-0.30313491821289062, 0.0, 1.4027749300003052]
scene.scene.camera.view_angle = 30.0
scene.scene.camera.view_up = [0.117668827287714, 0.54423876670086724, 0.83063723243342136]
scene.scene.camera.clipping_range = [16.95271984178639, 58.486755617116714]
scene.scene.camera.compute_view_plane_normal()
scene.scene.render()
surface.actor.property.edge_visibility = True
Exemplo n.º 7
0
'''
Created on Apr 28, 2009

@author: jakub
'''
import numpy as np
a = np.random.random((4, 4))
from enthought.mayavi.api import Engine
e = Engine()
e.start()
s = e.new_scene()
from enthought.mayavi.sources.api import ArraySource
src = ArraySource(scalar_data=a)
e.add_source(src)
from enthought.mayavi.filters.api import WarpScalar, PolyDataNormals
warp = WarpScalar()
e.add_filter(warp, obj=src)
normals = PolyDataNormals()
e.add_filter(normals, obj=warp)
from enthought.mayavi.modules.api import Surface
surf = Surface()
e.add_module(surf, obj=normals)