def create_path(self, npoints, path_time=None, tension=0.5, shortest_path=False): r"""Create a interpolated camera path from keyframes. Parameters ---------- npoints : integer Number of points to interpolate from keyframes path_time : array_like, optional Times of interpolated points. Default: Linearly spaced tension : float, optional Controls how sharp of a curve the spline takes. A higher tension allows for more sharp turns. Default: 0.5 shortest_path : boolean, optional If true, estimate the shortest path between the keyframes. Default: False Returns ------- path : dict Dictionary (time, position, north_vectors, up_vectors) of camera path. Also saved to self.path. """ self.npoints = npoints self.path = { "time": np.zeros(npoints), "position": np.zeros((npoints, 3)), "north_vectors": np.zeros((npoints, 3)), "up_vectors": np.zeros((npoints, 3)), } if shortest_path: self.get_shortest_path() if path_time is None: path_time = np.linspace(0, self.nframes, npoints) self.path["time"] = path_time for dim in range(3): self.path["position"][:, dim] = create_spline(self.times, self.pos[:, dim], path_time, tension=tension) if self.north_vectors is not None: self.path["north_vectors"][:, dim] = create_spline( self.times, self.north_vectors[:, dim], path_time, tension=tension) if self.up_vectors is not None: self.path["up_vectors"][:, dim] = create_spline( self.times, self.up_vectors[:, dim], path_time, tension=tension) return self.path
def render_path(self, views, times, N): # Assume that path comes in as a list of matrice # Assume original vector is (0., 0., 1.), up is (0., 1., 0.) views = [np.array(view).transpose() for view in views] times = np.linspace(0.0, 1.0, len(times)) # This is wrong. reflect = np.array([[1, 0, 0], [0, 1, 0], [0, 0, -1]]) rots = np.array([R[0:3, 0:3] for R in views]) rots = np.array([np.dot(reflect, rot) for rot in rots]) centers = np.array( [np.dot(rot, R[0:3, 3]) for R, rot in zip(views, rots)]) ups = np.array([np.dot(rot, R[0:3, 1]) for R, rot in zip(views, rots)]) #print 'views' #for view in views: print view #print 'rots' #for rot in rots: print rot #print 'centers' #for center in centers: print center #print 'ups' #for up in ups: print up pos = np.empty((N, 3), dtype="float64") uv = np.empty((N, 3), dtype="float64") f = np.zeros((N, 3), dtype="float64") for i in range(3): pos[:, i] = create_spline(times, centers[:, i], np.linspace(0.0, 1.0, N)) uv[:, i] = create_spline(times, ups[:, i], np.linspace(0.0, 1.0, N)) path = [pos.tolist(), f.tolist(), uv.tolist()] ph = PayloadHandler() ph.widget_payload(self, { 'ptype': 'camerapath', 'data': path, }) return
def render_path(self, views, times, N): # Assume that path comes in as a list of matrice # Assume original vector is (0., 0., 1.), up is (0., 1., 0.) views = [np.array(view).transpose() for view in views] times = np.linspace(0.0,1.0,len(times)) # This is wrong. reflect = np.array([[1,0,0],[0,1,0],[0,0,-1]]) rots = np.array([R[0:3,0:3] for R in views]) rots = np.array([np.dot(reflect,rot) for rot in rots]) centers = np.array([np.dot(rot,R[0:3,3]) for R,rot in zip(views,rots)]) ups = np.array([np.dot(rot,R[0:3,1]) for R,rot in zip(views,rots)]) #print 'views' #for view in views: print view #print 'rots' #for rot in rots: print rot #print 'centers' #for center in centers: print center #print 'ups' #for up in ups: print up pos = np.empty((N,3), dtype="float64") uv = np.empty((N,3), dtype="float64") f = np.zeros((N,3), dtype="float64") for i in range(3): pos[:,i] = create_spline(times, centers[:,i], np.linspace(0.0,1.0,N)) uv[:,i] = create_spline(times, ups[:,i], np.linspace(0.0,1.0,N)) path = [pos.tolist(), f.tolist(), uv.tolist()] ph = PayloadHandler() ph.widget_payload(self, {'ptype':'camerapath', 'data':path,}) return