def test_load2(): t1 = Thread() t1.load(np.random.randn(3, 11), 2) xyz = t1.getXYZ() t2 = Thread() t2.load(xyz, 0) t1.minimizeEnergy() xyz1 = t1.getXYZ() t2.minimizeEnergy() xyz2 = t2.getXYZ() print xyz1 - xyz2
def test_load(): t = Thread() print "before:" t.printVertices() t.load(np.random.randn(3, 11), 2) print "after:" t.printVertices()
def test_bend_ends(): thread = Thread() mlab.figure(3); mlab.clf() T = 16 colors = colorSeq(25) for (t,cons) in enumerate(C.bend_ends(thread,1,.1)): thread.setConstraints(cons) x,y,z = thread.getXYZ() mlab.plot3d(x,y,z,tube_radius=.1,color=colors.next())
def test_move_ends(): thread = Thread() mlab.figure(1); mlab.clf() colors = colorSeq(25) cons_new = thread.getConstraints() cons_new[0:3] += 4 cons_new[6:9] += 4 for (t,cons) in enumerate(C.match_cons(thread,cons_new)): thread.setConstraints(cons) x,y,z = thread.getXYZ() mlab.plot3d(x,y,z,tube_radius=.1,color=colors.next())
def test_jumprope(): thread = Thread() mlab.figure(1); mlab.clf() colors = colorSeq(100) cons_new = thread.getConstraints() for cons in C.bend_ends(thread,.25,.1): thread.setConstraints(cons) for (t,cons) in enumerate(C.jumprope(thread,pi,.1)): thread.setConstraints(cons) x,y,z = thread.getXYZ() mlab.plot3d(x,y,z,tube_radius=.1,color=colors.next())
def test_rotate_until_planes_aligned(): mlab.figure(1); mlab.clf() thread = Thread() thread_target = thread.clone() for cons in C.seq_controllers(C.translate_ends(thread_target,[0,30,0],20), C.bend_ends(thread_target,pi/4,.1), C.jumprope(thread_target,pi/3,.1)): thread_target.setConstraints(cons) x,y,z = thread_target.getXYZ() mlab.plot3d(x,y,z,tube_radius=.1,color=(1,1,1)) colors = colorSeq(100) for cons in C.match_cons(thread,thread_target.getConstraints()): thread.setConstraints(cons) x,y,z = thread.getXYZ() mlab.plot3d(x,y,z,tube_radius=.1,color=colors.next(),opacity=.5)
def test_running_jumprope(): thread = Thread() mlab.figure(1); mlab.clf() colors = colorSeq(100) cons_new = thread.getConstraints() cons_new[0:3] += 25 cons_new[6:9] += 25 for cons in C.bend_ends(thread,.25,.1): thread.setConstraints(cons) rj = C.add_controllers(thread,C.translate_ends(thread,[0,0,30],20), C.jumprope(thread,pi,.25)) for (t,cons) in enumerate(rj): thread.setConstraints(cons) x,y,z = thread.getXYZ() mlab.plot3d(x,y,z,tube_radius=.1,color=colors.next())
import scipy.optimize as opt from pylab import * from time import time from doo import * from doo.doo import Thread from sqp import frPath, calcStates, evalDiff from numpy.random import randn from utils import upsample2D T = 15 start_thread = Thread() scale = .25 cons_start = start_thread.getConstraints() n_wp = 1 def randCons(n): return cons_start + scale * USCALE[None, :] * randn(n, 12) cons_end = randCons(1) def makeTraj(cons_mid): cons_t = upsample2D( np.r_[atleast_2d(cons_start), atleast_2d(cons_mid), atleast_2d(cons_end)], T) return cons_t
from doo.doo import Thread from mp.utils import upsample2D import numpy as np from numpy import pi from numpy.random import randn import mayavi.mlab as mlab import sys from nibabel.eulerangles import angle_axis2euler import twists BEND = pi/6 TWIST = 2*pi thread = Thread() xyz0 = thread.getXYZ() #mlab.plot3d(x,y,z,tube_radius=.4,color=(1,1,1)) mlab.figure(1); mlab.clf() T = 16 for (t,cons) in enumerate(twists.jumprope2(thread,pi)): #twists.twist_ctrl(thread,2*np.pi/T,0) thread.setConstraints(cons) x,y,z = thread.getXYZ() mlab.plot3d(x,y,z,tube_radius=.1,color=(1-t/T,0,t/T)) xyz = np.array([x,y,z]) print twists.opt_rot(xyz,xyz0) #x,y,z = tips
import sys try: seed = int(sys.argv[-1]) np.random.seed(seed) print "using seed", seed except Exception: print "not using seed" # seed with 0 and final config is the same # seed with 1 and it's way different scale = .25 T = 10 thread_start = Thread() n_clones = 3 threads = [thread_start.clone() for _ in xrange(n_clones)] cons_start = thread_start.getConstraints() cons_end = cons_start + scale * np.r_[ randn(3) * 10, randn(3) * .5, randn(3) * 10, randn(3) * .5] tip1_start, tip2_start = cons_start[0:3], cons_start[6:9] tip1_end, tip2_end = cons_end[0:3], cons_end[6:9] tips = np.c_[tip1_start, tip2_start, tip1_end, tip2_end] colors = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] mlab.clf()