Example #1
0
    def test_curve(self):
        # Given/When
        c = visual.curve(points=[[0.,0.,0.],[1.,1.,1.]], pos=(1.,1.,1.))

        # Then
        bounds = get_bounds((1.5, 1.5, 1.5), (1.0, 1.0, 1.0))
        assert_allclose(c.polydata.bounds, bounds)

        # When
        c = visual.curve(points=[[0.,0,0],[1.,1,1]], axis=(0., 1, 0))
        # Then
        bounds = get_bounds((-0.5, 0.5, 0.5), (1.0, 1.0, 1.0))
        assert_allclose(c.polydata.bounds, bounds)
Example #2
0
    def test_curve(self):
        # Given/When
        c = visual.curve(points=[[0.,0.,0.],[1.,1.,1.]], pos=(1.,1.,1.))

        # Then
        bounds = get_bounds((1.5, 1.5, 1.5), (1.0, 1.0, 1.0))
        assert_allclose(c.polydata.bounds, bounds)

        # When
        c = visual.curve(points=[[0.,0,0],[1.,1,1]], axis=(0., 1, 0))
        # Then
        bounds = get_bounds((-0.5, 0.5, 0.5), (1.0, 1.0, 1.0))
        assert_allclose(c.polydata.bounds, bounds)
Example #3
0
def wirecube(s):
    c = curve(color=(1, 1, 1), radius=1)
    pts = [(-s, -s, -s), (-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s),
           (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s),
           (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s),
           (s, -s, -s)]
    for pt in pts:
        c.append(pt)
Example #4
0
def wirecube(s):
    c = curve(color = (1,1,1), radius=1)
    pts = [(-s, -s, -s),(-s, -s, s), (-s, s, s),
           (-s, s, -s), (-s, -s, -s), (s, -s, -s),
           (s, s, -s), (-s, s, -s), (s, s, -s),
           (s, s, s), (-s, s, s), (s, s, s),
           (s, -s, s), (-s, -s, s), (s, -s, s),(s, -s, -s)]
    for pt in pts:
        c.append(pt)
Example #5
0
    def __init__(self,
                 wp_list,
                 np_file='/tmp/magnetic_ground_truth.np',
                 width=800,
                 height=600):
        self.debug = True

        self.width = width
        self.height = height

        self.wp_list = wp_list

        self.f = mlab.figure(size=(self.width, self.height))
        visual.set_viewer(self.f)

        v = mlab.view(135, 180)

        self.balls = []
        self.trajectories = []

        colors = list(RoiSimulator.color_codes)
        color_black = colors.pop(0)
        color_red = colors.pop(0)

        wp_curve = visual.curve(color=color_red,
                                radius=RoiSimulator.curve_radius)
        hist_pos = []

        for i in xrange(len(self.wp_list)):
            ball = visual.sphere(color=color_black,
                                 radius=RoiSimulator.ball_radius)
            wp = self.wp_list[i]

            ball.x = wp[1]
            ball.y = wp[0]
            ball.z = wp[2]

            self.balls.append(ball)

            arr = visual.vector(float(wp[1]), float(wp[0]), float(wp[2]))
            hist_pos.append(arr)

        wp_curve.extend(hist_pos)

        x = np.linspace(0, self.width, 1)
        y = np.linspace(0, self.height, 1)

        z = np.loadtxt(np_file)
        z *= 255.0 / z.max()

        # HARDCODED
        # Todo: REMOVE THIS CODE ON THE FINAL RELEASE
        for xx in xrange(0, 200):
            for yy in xrange(400, 600):
                z[yy][xx] = 0
        mlab.surf(x, y, z)
Example #6
0
    def __init__(self,
                 hex_list,
                 np_file='/tmp/magnetic_ground_truth.np',
                 robot_height=40,
                 width=800,
                 height=600,
                 start_point=(0, 0, 0)):
        self.debug = False
        self.animator = None
        self.movement_mode = 0
        self.start_point = start_point
        self.robot_height = robot_height

        self.width = width
        self.height = height

        self.f = mlab.figure(size=(self.width, self.height))
        visual.set_viewer(self.f)

        v = mlab.view(270, 180)
        #print v

        engine = mlab.get_engine()
        s = engine.current_scene
        s.scene.interactor.add_observer('KeyPressEvent',
                                        self.keypress_callback)

        self.robots = []

        colors = list(PathRobustSimulator.color_codes)

        for key, local_hex_list in sorted(hex_list['internal_routes'].items()):
            color = colors.pop(0)

            ball = visual.sphere(color=color,
                                 radius=PathRobustSimulator.ball_radius)
            ball.x = self.start_point[0]
            ball.y = self.start_point[1]
            ball.z = self.start_point[2]

            curve = visual.curve(color=color,
                                 radius=PathRobustSimulator.curve_radius)

            r_ball = RobotBall(key, local_hex_list,
                               hex_list['external_routes'][key], ball, curve)
            self.robots.append(r_ball)

        x = np.linspace(0, self.width, 1)
        y = np.linspace(0, self.height, 1)

        z = np.loadtxt(np_file)
        z *= 255.0 / z.max()
        mlab.surf(x, y, z)

        self.master_cmd = MasterCommand(self.robots)
    def __init__(self, hex_list, np_file='/tmp/magnetic_ground_truth.np', robot_height=40, width=800, height=600,
                 start_point=(0, 0, 0), message='experiment default message...'):
        self.debug = False
        self.animator = None
        self.movement_mode = 0
        self.start_point = start_point
        self.robot_height = robot_height
        self.message = message

        self.start_time = int(time.time() * 1000)

        self.width = width
        self.height = height

        self.f = mlab.figure(size=(self.width, self.height))
        visual.set_viewer(self.f)

        v = mlab.view(270, 180)
        #print v

        engine = mlab.get_engine()
        self.s = engine.current_scene
        self.s.scene.interactor.add_observer('KeyPressEvent', self.keypress_callback)

        self.robots = []

        colors = list(PathBatterySimulator.color_codes)

        for key, local_hex_list in sorted(hex_list['internal_routes'].items()):
            color = colors.pop(0)

            ball = visual.sphere(color=color, radius=PathBatterySimulator.ball_radius)
            ball.x = self.start_point[0]
            ball.y = self.start_point[1]
            ball.z = self.start_point[2]

            r, g, b = color
            rt = r + (0.25 * (1 - r))
            gt = g + (0.25 * (1 - g))
            bt = b + (0.25 * (1 - b))
            curve_color = (rt, gt, bt)

            curve = visual.curve(color=curve_color, radius=PathBatterySimulator.curve_radius)

            r_ball = RobotBall(key, local_hex_list, hex_list['external_routes'][key], ball, curve)
            self.robots.append(r_ball)

        x = np.linspace(0, self.width, 1)
        y = np.linspace(0, self.height, 1)

        z = np.loadtxt(np_file)
        z *= 255.0/z.max()
        mlab.surf(x, y, z)

        self.master_cmd = MasterCommand(self.robots)
Example #8
0
    def __init__(self,
                 wp_list,
                 hex_list,
                 robot_height=40,
                 np_file='/tmp/magnetic_ground_truth.np',
                 width=800,
                 height=600,
                 start_point=(0, 0, 0)):
        self.debug = True
        self.movement_mode = 0
        self.start_point = start_point
        self.robot_height = robot_height

        self.width = width
        self.height = height

        self.wp_list = wp_list
        self.index_list = []
        self.history = []
        self.last_positions = []

        self.f = mlab.figure(size=(self.width, self.height))
        visual.set_viewer(self.f)

        self.balls = []
        self.trajectories = []

        colors = list(PathSimulator.color_codes)

        for i in xrange(len(self.wp_list)):
            color = colors.pop(0)
            ball = visual.sphere(color=color, radius=PathSimulator.ball_radius)
            ball.x = self.start_point[0]
            ball.y = self.start_point[1]
            ball.z = self.start_point[2]

            self.balls.append(ball)
            self.trajectories.append(
                visual.curve(color=color, radius=PathSimulator.curve_radius))
            self.index_list.append(0)
            self.history.append([])
            self.last_positions.append(self.start_point)

        x = np.linspace(0, self.width, 1)
        y = np.linspace(0, self.height, 1)

        self.z = np.loadtxt(np_file)
        self.z *= 255.0 / self.z.max()
        mlab.surf(x, y, self.z)
    def __init__(self, wp_list, np_file='/tmp/magnetic_ground_truth.np', width=800, height=600):
        self.debug = True

        self.width = width
        self.height = height

        self.wp_list = wp_list

        self.f = mlab.figure(size=(self.width, self.height))
        visual.set_viewer(self.f)

        self.balls = []
        self.trajectories = []

        colors = list(RoiSimulator.color_codes)
        color_black = colors.pop(0)
        color_red = colors.pop(0)

        wp_curve = visual.curve(color=color_red, radius=RoiSimulator.curve_radius)
        hist_pos = []

        for i in xrange(len(self.wp_list)):
            ball = visual.sphere(color=color_black, radius=RoiSimulator.ball_radius)
            wp = self.wp_list[i]

            ball.x = wp[1]
            ball.y = wp[0]
            ball.z = wp[2]

            self.balls.append(ball)

            arr = visual.vector(float(wp[1]), float(wp[0]), float(wp[2]))
            hist_pos.append(arr)

        wp_curve.extend(hist_pos)

        x = np.linspace(0, self.width, 1)
        y = np.linspace(0, self.height, 1)

        z = np.loadtxt(np_file)
        z *= 255.0/z.max()
        mlab.surf(x, y, z)
Example #10
0
    box (pos = (xx,yy,zz), length=x, height=y, width=z,
         color=(red,green,blue))

def wirecube(s):
    c = curve(color = (1,1,1), radius=1)
    pts = [(-s, -s, -s),(-s, -s, s), (-s, s, s),
           (-s, s, -s), (-s, -s, -s), (s, -s, -s),
           (s, s, -s), (-s, s, -s), (s, s, -s),
           (s, s, s), (-s, s, s), (s, s, s),
           (s, -s, s), (-s, -s, s), (s, -s, s),(s, -s, -s)]
    for pt in pts:
        c.append(pt)

side = 150.0
cube = box(size = (side,side,side), representation = 'w' )
i = 0
while i < 100:
    random_box()
    i = i + 1

arrow(axis=(0,12,0), radius_shaft=3.5, color = (1,0,0))

ball = sphere(pos=(-side/2.,-side/2.,-side/2.),color=(1,1,0),radius=3)
disk = cylinder(pos=(side/2.,side/2.,-side/2.),color=(.3,.3,1),axis=(1,1,0),radius=5)
xx = arange(0,4*pi,pi/10.)
spring=curve(color=(1,.7,.1), radius=0.4)
for y in xx:
    spring.append([20+cos(2*y), y/2.-30, -20+sin(2*y)+30])

show()
Example #11
0
#!/usr/bin/env python

# Author: Raashid Baig <*****@*****.**>
# License: BSD Style.

from tvtk.tools.visual import curve, box, vector, show
from numpy import arange, array

lorenz = curve( color = (1,1,1), radius=0.3 )

# Draw grid
for x in xrange(0,51,10):
    curve(points = [[x,0,-25],[x,0,25]], color = (0,0.5,0), radius = 0.3 )
    box(pos=(x,0,0), axis=(0,0,50), height=0.4, width=0.4, length = 50)

for z in xrange(-25,26,10):
    curve(points = [[0,0,z], [50,0,z]] , color = (0,0.5,0), radius = 0.3 )
    box(pos=(25,0,z), axis=(50,0,0), height=0.4, width=0.4, length = 50)

dt = 0.01
y = vector(35.0, -10.0, -7.0)

pts = []
for i in xrange(2000):
    # Integrate a funny differential equation
    dydt = vector(      -8.0/3*y[0] + y[1]*y[2],
                          - 10*y[1] +   10*y[2],
                   - y[1]*y[0] + 28*y[1] - y[2])
    y = y + dydt * dt

    pts.append(y)
Example #12
0
#!/usr/bin/env python

# Author: Raashid Baig <*****@*****.**>
# License: BSD Style.

from tvtk.tools.visual import curve, box, vector, show
from numpy import arange, array

lorenz = curve(color=(1, 1, 1), radius=0.3)

# Draw grid
for x in xrange(0, 51, 10):
    curve(points=[[x, 0, -25], [x, 0, 25]], color=(0, 0.5, 0), radius=0.3)
    box(pos=(x, 0, 0), axis=(0, 0, 50), height=0.4, width=0.4, length=50)

for z in xrange(-25, 26, 10):
    curve(points=[[0, 0, z], [50, 0, z]], color=(0, 0.5, 0), radius=0.3)
    box(pos=(25, 0, z), axis=(50, 0, 0), height=0.4, width=0.4, length=50)

dt = 0.01
y = vector(35.0, -10.0, -7.0)

pts = []
for i in xrange(2000):
    # Integrate a funny differential equation
    dydt = vector(-8.0 / 3 * y[0] + y[1] * y[2], -10 * y[1] + 10 * y[2],
                  -y[1] * y[0] + 28 * y[1] - y[2])
    y = y + dydt * dt

    pts.append(y)
    if len(pts) > 20:
Example #13
0
           color=pedestal.color)

shaft = cylinder(axis=(Lshaft, 0, 0),
                 length=Lshaft,
                 radius=Rshaft,
                 color=(0, 1, 0))
rotor = cylinder(pos=(Lshaft / 2 - Drotor / 2, 0, 0),
                 axis=(Drotor, 0, 0),
                 length=Drotor,
                 radius=Rrotor,
                 color=(1, 0, 0))

gyro = frame(shaft, rotor)
gyro.axis = (sin(theta) * sin(phi), cos(theta), sin(theta) * cos(phi))

trail = curve(radius=Rshaft / 8., color=(1, 1, 0))

r = Lshaft / 2.
dt = 0.0001
t = 0.
Nsteps = 20  # number of calculational steps between graphics updates


def anim():
    global theta, phidot, alphadot, M, g, r, thetadot, phi, alpha, t
    for step in range(Nsteps):  # multiple calculation steps for accuracy
        # Calculate accelerations of the Lagrangian coordinates:
        atheta = (phidot**2 * sin(theta) * cos(theta) - 2. *
                  (alphadot + phidot * cos(theta)) * phidot * sin(theta) +
                  2. * M * g * r * sin(theta) / I)
        aphi = 2. * thetadot * (alphadot - phidot * cos(theta)) / sin(theta)
Example #14
0
giant = sphere(pos=(-1.0e11, 0, 0),
               radius=2e10,
               color=(1, 0, 0),
               mass=2e30)

dwarf = sphere(pos=(1.5e11, 0, 0),
               radius=1e10,
               color=(1, 1, 0),
               mass=1e30)

giant.p = vector(0, 0, -1e4) * giant.mass
dwarf.p = -1*giant.p

# creating the curve which will trace the paths of actors
for a in [giant, dwarf]:
    a.orbit = curve(radius=2e9, color=a.color)

dt = 86400

def anim():
    #Creating the animation function which will be called at
    #uniform timeperiod through the iterate function
    dist = dwarf.pos - giant.pos
    force = 6.7e-11 * giant.mass * dwarf.mass * \
        dist/(sqrt(dist[0]**2 + dist[1]**2 + dist[2]**2))**3
    giant.p = giant.p + force*dt
    dwarf.p = dwarf.p - force*dt

    for a in [giant, dwarf]:
        a.pos = a.pos + (a.p/a.mass)*dt
        a.orbit.append(a.pos)
Example #15
0
    pprecess = -pprecess

support = Box(pos = top+MVector(0,0.01,0), size = (0.2,0.02,0.2), color = (0,1,0))
spring = Helix(pos = top, axis = vector(-0.161579, -0.98686, 0), radius = Rspring, color = (1,0.7,0.2))

gyro1 = Frame(pos = top+spring.axis) # gyro.pos at end of spring
gyro1.axis = MVector(1,0,0)

shaft = Cylinder(pos = gyro1.pos, axis = Lshaft*gyro1.axis, radius =
                 Rshaft, color = (0.85,0.85,0.85), length = 1.0)

rotor = Cylinder(pos = 0.5*gyro1.axis*(Lshaft-Drotor), axis =
                 gyro1.axis*Drotor, radius = Rrotor, color = (0.5,0.5,0.5), length = 0.1)

stripe1 = curve(color = color.green,
                points = [rotor.pos+1.03*rotor.axis+vector(0,Rrotor,0),
                rotor.pos+1.03*rotor.axis-vector(0,Rrotor,0)])
stripe2 = curve(color = color.green,
                points = [rotor.pos-0.03*rotor.axis+vector(0,Rrotor,0),
                rotor.pos-0.03*rotor.axis-vector(0,Rrotor,0)])

gyro = Frame(stripe1, stripe2) # gyro.pos at end of spring
gyro.pos = top+spring.axis # gyro.pos at end of spring
gyro.axis = vector(1,0,0)

gyro.rotate(axis=(0,1,0), angle = 180.0, origin = gyro.pos)

cm = gyro.pos+0.5*Lshaft*gyro.axis # center of mass of shaft
Lrot = I*omega*gyro.axis
p = pprecess
dt = 0.01
Example #16
0
from math import sqrt

from tvtk.tools.visual import sphere, iterate, show, vector, curve

#Creating the actors for the scene
giant = sphere(pos=(-1.0e11, 0, 0), radius=2e10, color=(1, 0, 0), mass=2e30)

dwarf = sphere(pos=(1.5e11, 0, 0), radius=1e10, color=(1, 1, 0), mass=1e30)

giant.p = vector(0, 0, -1e4) * giant.mass
dwarf.p = -1 * giant.p

# creating the curve which will trace the paths of actors
for a in [giant, dwarf]:
    a.orbit = curve(radius=2e9, color=a.color)

dt = 86400


def anim():
    #Creating the animation function which will be called at
    #uniform timeperiod through the iterate function
    dist = dwarf.pos - giant.pos
    force = 6.7e-11 * giant.mass * dwarf.mass * \
        dist/(sqrt(dist[0]**2 + dist[1]**2 + dist[2]**2))**3
    giant.p = giant.p + force * dt
    dwarf.p = dwarf.p - force * dt

    for a in [giant, dwarf]:
        a.pos = a.pos + (a.p / a.mass) * dt
Example #17
0
                 height=hpedestal, length=wpedestal, width=wpedestal,
                 color=(0.4,0.4,0.5))
base = box(pos=top-vector(0,hpedestal+tbase/2.,0),
                 height=tbase, length=wbase, width=wbase,
                 color=pedestal.color)

shaft = cylinder(axis=(Lshaft,0,0), length = Lshaft,
                 radius=Rshaft, color=(0,1,0))
rotor = cylinder(pos=(Lshaft/2 - Drotor/2, 0, 0),
                 axis=(Drotor, 0, 0), length = Drotor,
                 radius=Rrotor, color=(1,0,0))

gyro = frame(shaft, rotor)
gyro.axis = (sin(theta)*sin(phi),cos(theta),sin(theta)*cos(phi))

trail = curve(radius=Rshaft/8., color=(1,1,0))

r = Lshaft/2.
dt = 0.0001
t = 0.
Nsteps = 20 # number of calculational steps between graphics updates

def anim():
    global theta, phidot, alphadot, M, g, r, thetadot, phi, alpha, t
    for step in range(Nsteps): # multiple calculation steps for accuracy
        # Calculate accelerations of the Lagrangian coordinates:
        atheta = (phidot**2*sin(theta)*cos(theta)
                  -2.*(alphadot+phidot*cos(theta))*phidot*sin(theta)
                  +2.*M*g*r*sin(theta)/I)
        aphi = 2.*thetadot*(alphadot-phidot*cos(theta))/sin(theta)
        aalpha = phidot*thetadot*sin(theta)-aphi*cos(theta)
    def __init__(self,
                 hex_list,
                 np_file='/tmp/magnetic_ground_truth.np',
                 robot_height=40,
                 width=800,
                 height=600,
                 start_point=(0, 0, 0),
                 message='experiment default message...',
                 battery=99999):
        self.debug = False
        self.animator = None
        self.movement_mode = 0
        self.start_point = start_point
        self.robot_height = robot_height
        self.message = message

        self.start_time = int(time.time() * 1000)
        self.timestep = 0

        self.width = width
        self.height = height

        self.f = mlab.figure(size=(self.width, self.height))
        visual.set_viewer(self.f)

        v = mlab.view(270, 180)
        #print v

        engine = mlab.get_engine()
        self.s = engine.current_scene
        self.s.scene.interactor.add_observer('KeyPressEvent',
                                             self.keypress_callback)

        self.robots = []

        colors = list(PathBatterySimulator.color_codes)

        for key, local_hex_list in sorted(hex_list['internal_routes'].items()):
            color = colors.pop(0)

            ball = visual.sphere(color=color,
                                 radius=PathBatterySimulator.ball_radius)
            ball.x = self.start_point[0]
            ball.y = self.start_point[1]
            ball.z = self.start_point[2]

            r, g, b = color
            rt = r + (0.25 * (1 - r))
            gt = g + (0.25 * (1 - g))
            bt = b + (0.25 * (1 - b))
            curve_color = (rt, gt, bt)

            curve = visual.curve(color=curve_color,
                                 radius=PathBatterySimulator.curve_radius)

            r_ball = RobotBall(key,
                               local_hex_list,
                               hex_list['external_routes'][key],
                               ball,
                               curve,
                               battery=battery)
            self.robots.append(r_ball)

        x = np.linspace(0, self.width, 1)
        y = np.linspace(0, self.height, 1)

        z = np.loadtxt(np_file)
        z *= 255.0 / z.max()

        # HARDCODED
        # Todo: REMOVE THIS CODE ON THE FINAL RELEASE
        for xx in xrange(0, 200):
            for yy in xrange(400, 600):
                z[yy][xx] = 0

        mlab.surf(x, y, z)

        self.master_cmd = MasterCommand(self.robots)

        self.robot_pos = open('/tmp/robot_log.txt', 'a')
Example #19
0
    pts = [(-s, -s, -s), (-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s),
           (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s),
           (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s),
           (s, -s, -s)]
    for pt in pts:
        c.append(pt)


side = 150.0
cube = box(size=(side, side, side), representation='w')
i = 0
while i < 100:
    random_box()
    i = i + 1

arrow(axis=(0, 12, 0), radius_shaft=3.5, color=(1, 0, 0))

ball = sphere(pos=(-side / 2., -side / 2., -side / 2.),
              color=(1, 1, 0),
              radius=3)
disk = cylinder(pos=(side / 2., side / 2., -side / 2.),
                color=(.3, .3, 1),
                axis=(1, 1, 0),
                radius=5)
xx = arange(0, 4 * pi, pi / 10.)
spring = curve(color=(1, .7, .1), radius=0.4)
for y in xx:
    spring.append([20 + cos(2 * y), y / 2. - 30, -20 + sin(2 * y) + 30])

show()