def viewer_refresh(self, q): while not q.empty(): self.state = q.get() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.0, 0.0, 0.0, 1.0) self.dcam.Activate(self.scam) if self.state is not None: if self.state[0].shape[0] >= 2: # draw poses gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0][:-1]) if self.state[0].shape[0] >= 1: # draw current pose as yellow gl.glColor3f(1.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0][-1:]) if self.state[1].shape[0] != 0: # draw keypoints gl.glPointSize(5) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(self.state[1], self.state[2]) pangolin.FinishFrame()
def main(): pangolin.CreateWindowAndBind('Main', 640, 480) gl.glEnable(gl.GL_DEPTH_TEST) # Define Projection and initial ModelView matrix scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.2, 100), pangolin.ModelViewLookAt(-2, 2, -2, 0, 0, 0, pangolin.AxisDirection.AxisY)) handler = pangolin.Handler3D(scam) # Create Interactive View in window dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 / 480.0) dcam.SetHandler(handler) while not pangolin.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) dcam.Activate(scam) # Render OpenGL Cube pangolin.glDrawColouredCube() # Draw Point Cloud points = np.random.random((100000, 3)) * 10 colors = np.zeros((len(points), 3)) colors[:, 1] = 1 - points[:, 0] / 10. colors[:, 2] = 1 - points[:, 1] / 10. colors[:, 0] = 1 - points[:, 2] / 10. gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) # access numpy array directly(without copying data), array should be contiguous. pangolin.DrawPoints(points, colors) pangolin.FinishFrame()
def viewer_refresh(self, qmap, qvo, is_paused): while not qmap.empty(): self.map_state = qmap.get() while not qvo.empty(): self.vo_state = qvo.get() # if pangolin.Pushed(self.button): # print('You Pushed a button!') self.do_follow = self.checkboxFollow.Get() self.is_grid = self.checkboxGrid.Get() self.draw_cameras = self.checkboxCams.Get() self.draw_covisibility = self.checkboxCovisibility.Get() self.draw_spanning_tree = self.checkboxSpanningTree.Get() #if pangolin.Pushed(self.checkboxPause): if self.checkboxPause.Get(): is_paused.value = 0 else: is_paused.value = 1 # self.int_slider.SetVal(int(self.float_slider)) self.pointSize = self.int_slider.Get() if self.do_follow and self.is_following: self.scam.Follow(self.Twc, True) elif self.do_follow and not self.is_following: self.scam.SetModelViewMatrix(self.look_view) self.scam.Follow(self.Twc, True) self.is_following = True elif not self.do_follow and self.is_following: self.is_following = False gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) if self.is_grid: Viewer3D.drawPlane() # ============================== # draw map if self.map_state is not None: if self.map_state.cur_pose is not None: # draw current pose in blue gl.glColor3f(0.0, 0.0, 1.0) gl.glLineWidth(2) pangolin.DrawCamera(self.map_state.cur_pose) gl.glLineWidth(1) self.updateTwc(self.map_state.cur_pose) if self.map_state.predicted_pose is not None and kDrawCameraPrediction: # draw predicted pose in red gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawCamera(self.map_state.predicted_pose) if len(self.map_state.poses) > 1: # draw keyframe poses in green if self.draw_cameras: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.map_state.poses[:]) if len(self.map_state.points) > 0: # draw keypoints with their color gl.glPointSize(self.pointSize) #gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(self.map_state.points, self.map_state.colors) if self.map_state.reference_pose is not None and kDrawReferenceCamera: # draw predicted pose in purple gl.glColor3f(0.5, 0.0, 0.5) gl.glLineWidth(2) pangolin.DrawCamera(self.map_state.reference_pose) gl.glLineWidth(1) if len(self.map_state.covisibility_graph) > 0: if self.draw_covisibility: gl.glLineWidth(1) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLines(self.map_state.covisibility_graph, 3) if len(self.map_state.spanning_tree) > 0: if self.draw_spanning_tree: gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawLines(self.map_state.spanning_tree, 3) if len(self.map_state.loops) > 0: if self.draw_spanning_tree: gl.glLineWidth(2) gl.glColor3f(0.5, 0.0, 0.5) pangolin.DrawLines(self.map_state.loops, 3) gl.glLineWidth(1) # ============================== # draw vo if self.vo_state is not None: if self.vo_state.poses.shape[0] >= 2: # draw poses in green if self.draw_cameras: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.vo_state.poses[:-1]) if self.vo_state.poses.shape[0] >= 1: # draw current pose in blue gl.glColor3f(0.0, 0.0, 1.0) current_pose = self.vo_state.poses[-1:] pangolin.DrawCameras(current_pose) self.updateTwc(current_pose[0]) if self.vo_state.traj3d_est.shape[0] != 0: # draw blue estimated trajectory gl.glPointSize(self.pointSize) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawLine(self.vo_state.traj3d_est) if self.vo_state.traj3d_gt.shape[0] != 0: # draw red ground-truth trajectory gl.glPointSize(self.pointSize) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawLine(self.vo_state.traj3d_gt) pangolin.FinishFrame()