def executables(self): # Widget executable self.wexecutable = ui.Widget() self.wexecutable.resize(220, 300) self.wexecutable.move(App.width * 0.5, 150) self.wexecutable.setWindowTitle('Executables') x = 10 y = 10 inc = 20 ui.button( self.wexecutable , "Keyframes - Salient Poses" , ui.Geo(x=x, y=y, w=200, h=20 ) , self.exec_salientposes ); y += inc ui.button( self.wexecutable ,"Interp - One Shot" , ui.Geo(x=x, y=y, w=200, h=20) , self.exec_oneshot ); y += inc ui.button( self.wexecutable , "Interp - Coupled Solve" , ui.Geo(x=x, y=y, w=200, h=20) , self.exec_coupledsolve ); y += inc self.wexecutable.show()
def curve_chooser(self): self.wchooser = ui.Widget() self.wchooser.resize(300, App.height) self.wchooser.setWindowTitle('Curves') x = 20 y = 20 inc = 15 for layer in Motion.layers: for name in layer: ui.label(self.wchooser, name, ui.Geo(x = x, y = y)) x += 100 ui.button( self.wchooser, "x", ui.Geo(x = x, y = y, w = 20, h = 20) , self.create_display_toggle(self.dimensions[name], "rx") , checkable = True, checked = self.dimensions[name]["rx"]) x+=inc ui.button( self.wchooser, "y", ui.Geo(x = x, y = y, w = 20, h = 20) , self.create_display_toggle(self.dimensions[name], "ry") , checkable = True, checked = self.dimensions[name]["ry"]) x+=inc ui.button( self.wchooser, "z", ui.Geo(x = x, y = y, w = 20, h = 20) , self.create_display_toggle(self.dimensions[name], "rz") , checkable = True, checked = self.dimensions[name]["rz"]) x+=inc y += inc x = 20 y += inc self.wchooser.show()
def create_interface(self): self.app = ui.Widget() self.app.setGeometry(App.screen_x, App.screen_y, App.width, App.height) # -------------------------------------------------------------------- # # Sliders x = App.width-220 y = 40 h = 15 inc = 40 sliders = [ [ 0, "X-Axis, " , self.update_shift_x , Algorithm.shift_x ] , [ 0, "Y-Axis, " , self.update_shift_y , Algorithm.shift_y ] , [ 1, "scaling x, " , self.update_scaling_x , Algorithm.scaling_x ] , [ 1, "scaling y, " , self.update_scaling_y , Algorithm.scaling_y ] , [ 2, None, None, None] , [ 0, "Globals, " , self.update_n_globals , Algorithm.n_globals ] , [ 0, "Locals, " , self.update_n_locals , Algorithm.n_locals ] , [ 1, "max tangent length, " , self.update_m_length , Algorithm.m_length ] , [ 1, "max error, " , self.update_m_error , Algorithm.m_error ] ] for (slider_type, title, update_fn, alg_var) in sliders: if slider_type == 0: ui.slider( self.app, title , alg_var , ui.Geo(x=x, y=y, w=200, h=h) , update_fn ) elif slider_type == 1: ui.p_slider( self.app, title , alg_var[2] , ui.Geo(x=x, y=y, w=200, h=h) , update_fn ) else: # add a gap y += inc * 0.5 y += inc # -- # -------------------------------------------------------------------- # # Buttons y += inc * 0.5 x = App.width - 120 inc = 30 ui.button( self.app, "Globals", ui.Geo(x=x, y=y, w=100, h=20) , self.update_globals ); y += inc ui.button( self.app, "Interp, Use N", ui.Geo(x=x, y=y, w=100, h=20) , self.update_interp_using_n ); y += inc ui.button( self.app, "Interp, Iterative", ui.Geo(x=x, y=y, w=100, h=20) , self.update_interp_iterative ); y += inc ui.button( self.app, "Export", ui.Geo(x=x, y=y, w=100, h=20) , self.export_json ); y += inc # -- # -------------------------------------------------------------------- # # Toggles def create_display_toggle(change, name): def fn(value): change[name] = value self.app.update() return fn # Display x = App.width - 120 y = App.height - 200 inc = 20 self.display_toggles = App.display for key in App.display_order: ui.button( self.app, key, ui.Geo(x = x, y = y, w = 100, h = 20) , create_display_toggle(self.display_toggles, key) , checkable = True, checked = self.display_toggles[key]) y += inc # Curves x = 20 y = 20 inc = 20 self.curves = {} self.dimensions = {} for layer in Motion.layers: for name in layer: self.curves[name] = False ui.label(self.app, name, ui.Geo(x = x, y = y)) x += 100 self.dimensions[name] = {"rx":False, "ry":False, "rz":False} ui.button( self.app, "x", ui.Geo(x = x, y = y, w = 20, h = 20) , create_display_toggle(self.dimensions[name], "rx") , checkable = True, checked = False); x+=inc ui.button( self.app, "y", ui.Geo(x = x, y = y, w = 20, h = 20) , create_display_toggle(self.dimensions[name], "ry") , checkable = True, checked = False); x+=inc ui.button( self.app, "z", ui.Geo(x = x, y = y, w = 20, h = 20) , create_display_toggle(self.dimensions[name], "rz") , checkable = True, checked = False); x+=inc y += inc x = 20 y += inc # -- # -------------------------------------------------------------------- # # Complete self.app.setWindowTitle(App.title) self.app.show() self.app.setMouseTracking(True) # Drawing function def paintFn(e): def do_drawing(parent, active): # Get sizing, and adjust for slider offset ox = self.shift_x oy = self.shift_y sx = self.scaling_x sy = self.scaling_y # Display, setup drawing = ui.Drawing() drawer = ui.Drawer(drawing, ox, oy, sx, sy) drawing.begin(parent) drawing.setRenderHint(ui.Antialiasing, True) # Display, draw if active[0]: self.draw_zeroline(drawer) if active[1]: self.draw_mocap(drawer) if active[2]: self.draw_keyframes_global(drawer) if active[3]: self.draw_keyframes_local(drawer) if active[4]: self.draw_interpolation(drawer) # Display, cleanup drawing.end() # Drawing for display output do_drawing(self.app, [1, 1, 1, 1, 1]) # Drawing for image output if self.display_toggles["save_as_made"]: image = ui.Image(App.width, App.height, ui.ImageFormat) do_drawing(image, [0, 1, 1, 1, 1]) image.save("../logs/%d.png" % ( self.n_globals ) ) self.app.paintEvent = paintFn
def create_interface(self): self.app = ui.Widget() self.app.setGeometry(App.screen_x, App.screen_y, App.width, App.height) self.curves = {} self.dimensions = {} for layer in Motion.layers: for name in layer: self.curves[name] = False self.dimensions[name] = {"rx":False, "ry":False, "rz":False} self.display_toggles = App.display # # -------------------------------------------------------------------- # # Controls y = 20 x = App.width * 0.5 - 150 inc = 120 ui.button( self.app, "Curves", ui.Geo(x=x, y=y, w=100, h=20) , self.curve_chooser ); x += inc ui.button( self.app, "Exec", ui.Geo(x=x, y=y, w=100, h=20) , self.executables ); x += inc # ui.button( self.app, "Controls", ui.Geo(x=x, y=y, w=100, h=20) # , self.controls ); x += inc ui.button( self.app, "Quit", ui.Geo(x=x, y=y, w=100, h=20) , self.quitall ); x += inc # # -------------------------------------------------------------------- # # Complete self.controls() self.executables() self.curve_chooser() self.app.setWindowTitle(App.title) self.app.show() self.app.setMouseTracking(True) def paintFn(e): def do_drawing(parent, active): minsX = [0] maxsX = [0] minsY = [0] maxsY = [0] for name in self.curves.keys(): curve = Motion.mocap["single"][name] minsX.append(self.curve_min(0, curve)) maxsX.append(self.curve_max(0, curve)) for dim in self.dimensions[name].keys(): if not self.dimensions[name][dim]: continue index = -1 if dim == "rx": index = 1 if dim == "ry": index = 2 if dim == "rz": index = 3 minsY.append(self.curve_min(index, curve)) maxsY.append(self.curve_max(index, curve)) # Get sizing, and adjust for slider offset ox = self.shift_x + App.width * 0.5 oy = self.shift_y + App.height * 0.5 sx = self.scaling_x sy = self.scaling_y # Display, setup drawing = ui.Drawing() drawer = ui.Drawer( drawing , min(minsX), min(minsY) , max(maxsX), max(maxsY) , ox, oy, sx, sy ) drawing.begin(parent) drawing.setRenderHint(ui.Antialiasing, True) # Display, draw if active[0]: self.draw_zeroline(drawer) if active[1]: self.draw_mocap(drawer) if active[2]: self.draw_keyframes_global(drawer) # if active[3]: self.draw_keyframes_local(drawer) if active[4]: self.draw_interpolation(drawer) # Display, cleanup drawing.end() del drawing # Drawing for display output do_drawing(self.app, [1, 1, 1, 1, 1]) # Drawing for image output if self.display_toggles["save_as_made"]: # image = ui.Image(App.width, App.height, ui.ImageFormat) # do_drawing(image, [0, 1, 1, 1, 1]) # image.save("../logs/%d.png" % ( self.n_globals ) ) original_point_sets = [] keyframe_point_sets = [] fns = [] keyframes = self.global_extractor.get_n_keyframes(self.n_globals) for name in self.curves.keys(): for dim in self.dimensions[name].keys(): if not self.dimensions[name][dim]: continue index = -1 if dim == "rx": index = 1 if dim == "ry": index = 2 if dim == "rz": index = 3 original_points = [] keyframe_points = [] for i in range(len(Motion.mocap["single"][name])): p = [ Motion.mocap["single"][name].item(i, 0) , Motion.mocap["single"][name].item(i, index) ] original_points.append(p) if i in keyframes: keyframe_points.append(p) original_point_sets.append(np.array(original_points)) keyframe_point_sets.append(np.array(keyframe_points)) # Original for points in original_point_sets: fns += curve_renderer.polyline(points) # Keyframes for points in keyframe_point_sets: fns += curve_renderer.keyframes(points) # Interps beziers = [(i.get_a(), i.get_b(), i.get_c(), i.get_d()) for i in self.interps] fns += curve_renderer.bezier_chain_handles(beziers) # fns += curve_renderer.bezier_chain(beziers) curve_renderer.draw( "../logs/%s.svg" % self.filename.text() , 400 , 400 , original_point_sets , fns ) self.app.paintEvent = paintFn
def controls(self): self.wcontrols = ui.Widget() self.wcontrols.resize(300, App.height) self.wcontrols.move(App.width,0) self.wcontrols.setWindowTitle('Curves') self.filename = ui.TextIn(self.wcontrols) self.filename.move(20, 20) self.filename.setPlaceholderText("output") # -------------------------------------------------------------------- # # Sliders x = 20 y = 80 h = 15 inc = 40 sliders = [ [ 0, "X-Axis, " , self.update_shift_x , Algorithm.shift_x ] , [ 0, "Y-Axis, " , self.update_shift_y , Algorithm.shift_y ] , [ 1, "scaling x, " , self.update_scaling_x , Algorithm.scaling_x ] , [ 1, "scaling y, " , self.update_scaling_y , Algorithm.scaling_y ] , [ 0, "Globals, " , self.update_globals , Algorithm.n_globals ] , [ 1, "threshold alpha, " , self.update_alpha , Algorithm.alpha ] , [ 1, "threshold beta y, " , self.update_beta , Algorithm.beta ] ] for (slider_type, title, update_fn, alg_var) in sliders: if slider_type == 0: ui.slider( self.wcontrols, title , alg_var , ui.Geo(x=x, y=y, w=200, h=h) , update_fn ) elif slider_type == 1: ui.p_slider( self.wcontrols, title , alg_var[2] , ui.Geo(x=x, y=y, w=200, h=h) , update_fn ) else: y += inc * 0.5 y += inc # # -------------------------------------------------------------------- # # Toggles x = 20 inc = 20 y += 40 for key in App.display_order: ui.button( self.wcontrols, key, ui.Geo(x = x, y = y, w = 100, h = 20) , self.create_display_toggle(self.display_toggles, key) , checkable = True, checked = self.display_toggles[key]) y += inc # # -------------------------------------------------------------------- # self.wcontrols.show()