def draw_boundingbox(self, model, pose, thickness=3.): # View matrix (transforming the coordinate system from OpenCV to OpenGL camera space) mv = (self.yz_flip.dot(pose)).T # OpenCV to OpenGL camera system (flipped, column-wise) mvp = mv.dot(self.mat_proj) self.program_bbox.bind(model.bb_vbuffer) self.program_bbox['u_mv'] = mv self.program_bbox['u_mvp'] = mvp gloo.set_line_width(thickness) self.program_bbox.draw('lines', model.bb_ibuffer)
def draw_coordinate_system(self, model, pose): self.clear(color=False) # View matrix (transforming the coordinate system from OpenCV to OpenGL camera space) mv = (self.yz_flip.dot(pose)).T # OpenCV to OpenGL camera system (flipped, column-wise) mvp = mv.dot(self.mat_proj) self.program_bbox.bind(model.cs_vbuffer) self.program_bbox['u_mv'] = mv self.program_bbox['u_mvp'] = mvp gloo.set_line_width(width=3.0) self.program_bbox.draw('lines', model.cs_ibuffer) gloo.set_line_width(width=1.0)
def screenshot(self, linewidth=26, start=0): with self.fbo: gloo.set_line_width(linewidth) gloo.set_viewport(0, 0, 2048, 2048) gloo.set_state(blend=True, depth_test=True) gloo.clear(color="white", depth=True) self.program.draw("lines", self.index_buffer) im = _screenshot((0, 0, 2048, 2048))[:, :, :3] for i in range(start, 9999): if not osp.exists(f"{self.prefix}_s{i:04d}.png"): print(f"Save to {self.prefix}_s{i:04d}.png") cv2.imwrite(f"{self.prefix}_s{i:04d}.png", im[:, :, ::-1]) break
def __init__(self, data, theta=30.0, phi=90.0, z=6.0): """ initialize data for plotting Parameters ---------- data : array_like 3D data, Nx3 theta : float rotation around y axis phi : float rotation around z axis z : float view depth """ app.Canvas.__init__(self, size=(800, 400), title='plot3d', keys='interactive') # build shader program program = gloo.Program(vert=vertex, frag=fragment) # initialize 3D view view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) # update program program['u_model'] = model program['u_view'] = view program['u_projection'] = projection program['a_position'] = data # bind self.program = program self.theta = theta self.phi = phi self.z = z # config gloo.set_viewport(0, 0, *self.physical_size) gloo.set_clear_color('white') gloo.set_state('translucent') # config your lines gloo.set_line_width(2.0) # show the canvas self.show()
def draw(self, event): #Turn on additive blending gloo.set_state('additive') gloo.set_state(cull_face = False) gloo.set_cull_face('front') gloo.clear() #Summary render to main screen if self.state == 'texture' or self.state == 'raw': self._program.draw('triangles', self.indices_buffer) elif self.state == 'flow': self._program_flow.bind(self._vbo) self._program_flow.draw('triangles', self.indices_buffer) elif self.state == 'mask': self._program_mask.bind(self._vbo) #self._updatemaskpalette(np.squeeze(self.randfacecolors[:,:,0])) #self._updatemaskpalette(np.squeeze(self.randhessfacecolors[:,:,1])) self._updatemaskpalette(np.squeeze(self.hessfacecolors[:,:,1])) #print self._program_mask['u_colors']#self.randfacecolors[:,:,0] self._program_mask.draw('triangles', self.indices_buffer) elif self.state == 'overlay': self._program_red['texture1'] = self.current_texture self._program_red.bind(self._quad) self._program_red.draw('triangles', self.quad_buffer) self._program_green.bind(self._vbo) self._program_green['texture1'] = self.init_texture self._program_green.draw('triangles', self.indices_buffer) elif self.state == 'wireframe': self._program_wireframe['texture1'] = self.current_texture self._program_wireframe.bind(self._quad) self._program_wireframe.draw('triangles', self.quad_buffer) elif self.state == 'inverse': #Load current frame as texture self._program_inverse['texture1'] = self.current_texture #Set UV coords of texture to current state coords #self._vbo_inverse['asdf'] #Set coords of rendered object to initial state coords self._program_inverse.bind(self._vbo_inverse) self._program_inverse.draw('triangles', self.indices_buffer) else: self._program_outline.bind(self._vbo) self._program_outline.draw('lines', self.outline_buffer) #Draw wireframe, too if self.state != 'raw' and self.state != 'outline': gloo.set_state('opaque') if self.state == 'wireframe': gloo.set_line_width(3) self._program_lines.draw('lines', self.outline_buffer) gloo.set_line_width(1)
def __init__(self, V, C, I, E, figsize=(512, 512), title='tetplot'): """ initialize the canvas """ app.Canvas.__init__(self, size=figsize, title=title, keys='interactive') # shader program tet = gloo.Program(vert=vertex, frag=fragment) # bind to data tet['a_position'] = V tet['a_color'] = C self.I = gloo.IndexBuffer(I) self.E = gloo.IndexBuffer(E) # intialize transformation matrix view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) tet['u_model'] = model tet['u_view'] = view tet['u_projection'] = projection # bind your program self.program = tet # config and set viewport gloo.set_viewport(0, 0, *self.physical_size) gloo.set_clear_color('white') gloo.set_state('translucent') gloo.set_polygon_offset(0.0, 0.0) # update parameters self.theta = 0.0 self.phi = 0.0 self.z = 5.0 # bind a timer self.timer = app.Timer('auto', self.on_timer) self.timer.start() # control plots gloo.set_line_width(1.0) # show the canvas self.show()
def draw(self): gloo.set_line_width(self._linewidth) self._shader.draw('line_strip')
def on_draw(self, event): gloo.set_line_width(13) gloo.set_viewport(0, 0, self.size[0], self.size[1]) gloo.set_state(blend=True, depth_test=True) gloo.clear(color="white", depth=True) self.program.draw("lines", self.index_buffer)
def __init__(self, measurement_ref, parent_window, theta=0, phi=45, z=6.0): self.parent_window = parent_window self.calibrationPosition = np.empty([3, 4]) #self.tracker = tracker_ref self.measurement_ref = measurement_ref app.Canvas.__init__(self, size=(200, 200), title='plot3d', keys='interactive') self.sphereradius = 1.5 self.boxsize = 0.4 self.sphere = Sphere(self.sphereradius, 15, 20) self.speaker = Speaker(self.boxsize) self.meas_points = SpherePoints(radius=self.sphereradius, pointcolor=np.array( [1.0, 0.0, 0.0, 1.0])) self.ref_points = SpherePoints(radius=0, pointcolor=np.array( [0.0, 0.0, 1.0, 1.0])) self.recommendation_points = SpherePoints(radius=self.sphereradius, pointcolor=np.array( [0.0, 1.0, 0.0, 1.0])) #self.tracker_orientation = TrackerOrientation(self.tracker) self.azimuthdisplay = AzimuthAngleDisplay(self.sphereradius) self.elevationdisplay = ElevationAngleDisplay(self.sphereradius) program = gloo.Program(vert=vertex, frag=fragment) # initialize 3D view view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) # update program program['u_model'] = model program['u_view'] = view program['u_projection'] = projection # program['a_position'] = gloo.VertexBuffer(self.data) self.program = program self.theta = theta self.phi = phi self.z = z # config gloo.set_viewport(0, 0, *self.physical_size) gloo.set_clear_color('white') gloo.set_state('translucent') # config your lines gloo.set_line_width(2.0) # show the canvas self.show() self.current_azimuth = 0.0 self.current_elevation = 0.0 self.timer = app.Timer(interval=0.05, connect=self.timer_callback, start=True)