def __init__(self, skeleton, pose, transform, viewport, linewidth=2.0): children = [[] for k in _side_index] parents = [[] for k in _side_index] for c in range(skeleton.n_joints): p = skeleton.parent_index(c) if p is not None: side = joint_side(skeleton.joint(c)) index = _side_index[side] children[index].append(c) parents[index].append(p) self.children = children self.parents = parents self.body_segments = [ SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth='local', color='local') for _ in range(3) ] for i, segment in enumerate(self.body_segments): c = children[i] if len(c) > 0: p = parents[i] segment.append(pose[c], pose[p], linewidth=linewidth) self.body_segments[_side_index['l']]['color'] = 0, 0, 1, 1 self.body_segments[_side_index['r']]['color'] = 1, 0, 0, 1 # self.body_segments[side_index['c']]['color'] = 0, 0, 0, 1 super(LimbCollection, self).__init__(pose)
def on_key_press(key, modifiers): if key == app.window.key.SPACE: reset() def reset(): transform.theta = 0 transform.phi = 0 transform.zoom = 16.5 transform = Trackball(Position()) viewport = Viewport() labels = GlyphCollection(transform=transform, viewport=viewport) paths = PathCollection(mode="agg+", transform=transform, viewport=viewport) ticks = SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth="local", color="local") # xmin,xmax = 0,800 # ymin,ymax = 0,800 xmin, xmax = -1, 1 ymin, ymax = -1, 1 z = 0 regular = FontManager.get("OpenSans-Regular.ttf") bold = FontManager.get("OpenSans-Bold.ttf") n = 11 scale = 0.001 for i, y in enumerate(np.linspace(xmin, xmax, n)):
# ----------------------------------------------------------------------------- import numpy as np from glumpy import app, glm from glumpy.graphics.collections import SegmentCollection from glumpy.transforms import Position, OrthographicProjection, PanZoom window = app.Window(width=1200, height=600, color=(1,1,1,1)) @window.event def on_draw(dt): window.clear() segments.draw() @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() n = 100 P0 = np.dstack((np.linspace(100,1100,n),np.ones(n)* 50,np.zeros(n))).reshape(n,3) P1 = np.dstack((np.linspace(110,1110,n),np.ones(n)*550,np.zeros(n))).reshape(n,3) transform = PanZoom(OrthographicProjection(Position())) segments = SegmentCollection(mode="agg", linewidth='local', transform=transform) segments.append(P0, P1, linewidth = np.linspace(1, 8, n)) segments['antialias'] = 1 window.attach(segments["transform"]) window.attach(segments["viewport"]) app.run()
reset() def reset(): transform.theta = 0 transform.phi = 0 transform.zoom = 16.5 transform = Trackball(Position()) viewport = Viewport() labels = GlyphCollection(transform=transform, viewport=viewport) paths = PathCollection(mode="agg+", transform=transform, viewport=viewport) ticks = SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth='local', color='local') # xmin,xmax = 0,800 # ymin,ymax = 0,800 xmin, xmax = -1, 1 ymin, ymax = -1, 1 z = 0 regular = FontManager.get("OpenSans-Regular.ttf") bold = FontManager.get("OpenSans-Bold.ttf") n = 11 scale = 0.001 for i, y in enumerate(np.linspace(xmin, xmax, n)):
def grid(transform, viewport, scale=1.0): ticks = SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth='local', color='local') labels = GlyphCollection(transform=transform, viewport=viewport) # xmin,xmax = 0,800 # ymin,ymax = 0,800 xmin, xmax = -1, 1 nx = 11 dx = (xmax - xmin) / (nx - 1) ymin, ymax = -1, 1 ny = 11 dy = (ymax - ymin) / (ny - 1) z = 0 regular = FontManager.get("OpenSans-Regular.ttf") bold = FontManager.get("OpenSans-Bold.ttf") labels_scale = 0.001 for x in np.linspace(xmin, xmax, nx): text = "%.2f" % (x * scale) labels.append(text, regular, origin=(x, ymin - dy / 2, z), scale=labels_scale, direction=(1, 0, 0), anchor_x="center", anchor_y="top") for y in np.linspace(ymin, ymax, ny): text = "%.2f" % (y * scale) labels.append(text, regular, origin=(xmin - dx / 2, y, z), scale=labels_scale, direction=(1, 0, 0), anchor_x="right", anchor_y="center") title = "H3M example" labels.append(title, bold, origin=(0, xmax + dx, z), scale=2 * labels_scale, direction=(1, 0, 0), anchor_x="center", anchor_y="center") # Frame # ------------------------------------- P0 = [(xmin, ymin, z), (xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z)] P1 = [(xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z), (xmin, ymin, z)] ticks.append(P0, P1, linewidth=2) # Grids # ------------------------------------- n = 11 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymax P1[:, 2] = z ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, .25)) P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = xmin P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P0[:, 2] = z P1[:, 0] = xmax P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P1[:, 2] = z ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, .25)) # Majors # ------------------------------------- n = 11 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin - 0.015 P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymin + 0.025 * (ymax - ymin) P1[:, 2] = z ticks.append(P0, P1, linewidth=1.5) P0[:, 1] = ymax + 0.015 P1[:, 1] = ymax - 0.025 * (ymax - ymin) ticks.append(P0, P1, linewidth=1.5) P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = xmin - 0.015 P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P0[:, 2] = z P1[:, 0] = xmin + 0.025 * (xmax - xmin) P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P1[:, 2] = z ticks.append(P0, P1, linewidth=1.5) P0[:, 0] = xmax + 0.015 P1[:, 0] = xmax - 0.025 * (xmax - xmin) ticks.append(P0, P1, linewidth=1.5) # Minors # ------------------------------------- n = 111 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymin + 0.0125 * (ymax - ymin) P1[:, 2] = z ticks.append(P0, P1, linewidth=1) P0[:, 1] = ymax P1[:, 1] = ymax - 0.0125 * (ymax - ymin) ticks.append(P0, P1, linewidth=1) P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = xmin P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P0[:, 2] = z P1[:, 0] = xmin + 0.0125 * (xmax - xmin) P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P1[:, 2] = z ticks.append(P0, P1, linewidth=1) P0[:, 0] = xmax P1[:, 0] = xmax - 0.0125 * (xmax - xmin) ticks.append(P0, P1, linewidth=1) return ticks
def on_draw(dt): window.clear() segments.draw() @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() n = 100 P0 = np.dstack((np.linspace(100, 1100, n), np.ones(n) * 50, np.zeros(n))).reshape(n, 3) P1 = np.dstack((np.linspace(110, 1110, n), np.ones(n) * 550, np.zeros(n))).reshape(n, 3) transform = PanZoom(OrthographicProjection(Position())) segments = SegmentCollection(mode="agg", linewidth='local', transform=transform) segments.append(P0, P1, linewidth=np.linspace(1, 8, n)) segments['antialias'] = 1 #collection = SegmentCollection(mode="raw", transform=transform) #collection.append(P0, P1) window.attach(segments["transform"]) window.attach(segments["viewport"]) app.run()
rmax = r.max() rmin = r.min() if rmax == rmin: s = r + 5.0 else: s = (r - rmin) / (rmax - rmin) * 10.0 + 2.0 return s if __name__ == "__main__": # window = app.Window(width=2048, height=1024, color=(1, 1, 1, 1)) window = app.Window(width=800, height=800, color=(1, 1, 1, 1)) # window = app.Window(color=(1, 1, 1, 1)) points1 = PointCollection("agg", color="local", size="local") points2 = PointCollection("agg", color="local", size="local") coord = SegmentCollection("agg+", color="local", linewidth="local") framebuffer = np.zeros((window.height, window.width * 3), dtype=np.uint8) toggleStop = False time = 0 save_flag = False # prepare pt data if len(sys.argv) < 3: print("... Usage: 3DViewer.py file1 file2 [-save]") exit(1) if len(sys.argv) == 4: if sys.argv[-1].find("save"): print("... save as movie") save_flag = True else: