Пример #1
0
    def draw(self):
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()

        Scale = 50
        Offset = -0.5
        gl.glPushMatrix()

        gl.glRotate(self.RotateAngle, 0, 1, 0)
        gl.glScale(Scale, Scale, Scale)
        gl.glTranslate(Offset, Offset, Offset)

        for Idx, m in enumerate(self.Models):
            if self.activeModelIdx != self.nModels:
                if Idx != self.activeModelIdx:
                    continue
            if self.isDrawMesh:
                self.OBJLoaders[Idx].draw(self.PointSize)
            if self.isDrawPoints:
                self.Models[Idx].draw(self.PointSize)
            if self.isDrawBB:
                self.Models[Idx].drawBB()

        if self.isDrawNOCSCube:
            drawing.drawUnitWireCube(5.0, True)
        gl.glPopMatrix()

        gl.glPopMatrix()
Пример #2
0
    def drawNOCS(self, lineWidth=2.0, ScaleX=1, ScaleY=1, ScaleZ=1, OffsetX=0, OffsetY=0, OffsetZ=0):
        gl.glPushMatrix()

        gl.glScale(ScaleX, ScaleY, ScaleZ)
        gl.glTranslate(OffsetX, OffsetY, OffsetZ)  # Center on cube center
        drawing.drawUnitWireCube(lineWidth, True)

        gl.glPopMatrix()
Пример #3
0
    def drawBB(self, LineWidth = 1):
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()

        gl.glTranslate(self.BBCenter[0], self.BBCenter[1], self.BBCenter[2])
        gl.glScale(self.BBSize[0], self.BBSize[1], self.BBSize[2])
        gl.glTranslate(-0.5, -0.5, -0.5) # Move box origin to center
        drawing.drawUnitWireCube(LineWidth, False)

        gl.glPopMatrix()
Пример #4
0
    def draw(self):
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()

        Scale = 50
        Offset = -0.5
        gl.glPushMatrix()

        gl.glRotate(self.RotateAngle, 0, 1, 0)
        gl.glScale(Scale, Scale, Scale)
        gl.glTranslate(Offset, Offset, Offset)

        if self.isDrawMesh:
            self.OBJLoader.draw(self.PointSize)
        if self.isDrawPoints:
            self.ModelPoints.draw(self.PointSize)
        if self.isDrawNOCSCube:
            drawing.drawUnitWireCube(5.0, True)
        gl.glPopMatrix()

        gl.glPopMatrix()
Пример #5
0
    def drawCamera(self, R, C, isF = False, Color=None):
        gl.glPushMatrix()

        ScaleRotMat = np.identity(4)
        ScaleRotMat[:3, :3] = R

        gl.glTranslate(C[0], C[1], C[2])
        gl.glMultMatrixf(ScaleRotMat)
        if isF:
            gl.glRotate(180, 1, 0, 0)

        Length = 5
        CubeSide = 0.1
        
        gl.glPushMatrix()
        gl.glScale(CubeSide, CubeSide, CubeSide/2)
        gl.glTranslate(-0.5, -0.5, -0.5)
        drawing.drawUnitWireCube(1.0, WireColor=(0, 0, 0))
        gl.glPopMatrix()
        
        gl.glPushAttrib(gl.GL_LINE_BIT)
        gl.glLineWidth(1.0)
        gl.glPushAttrib(gl.GL_ENABLE_BIT)
        gl.glLineStipple(1, 0xAAAA)  # [1]
        gl.glEnable(gl.GL_LINE_STIPPLE)      
        
        gl.glBegin(gl.GL_LINES)
        gl.glColor3f(1.0, 0.0, 0.0)
        gl.glVertex3f(0.0, 0.0, 0.0)
        gl.glVertex3f(0.0, 0.0, Length) # Always in the negative z

        gl.glEnd()

        gl.glPopAttrib()
        gl.glPopAttrib()
    
        # Offset = 5
        #drawing.drawAxes(Offset + 0.2, Color=Color)
        gl.glPopMatrix()
Пример #6
0
    def draw(self):
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()

        ScaleFact = 1000
        gl.glScale(ScaleFact, ScaleFact, ScaleFact)

        if self.draw_cubes:
            drawing.drawUnitWireCube(2.0, False, WireColor=(0.0, 1.0, 0.0))

            gl.glPushMatrix()
            gl.glTranslate(1.0, 0.0, 0.0)
            drawing.drawUnitWireCube(2.0, False, WireColor=(1.0, 0.0, 0.0))
            gl.glPopMatrix()

        if self.draw_all:
            for frame_idx in range(self.num_frames_per_seq):
                for seq_idx in range(self.num_seq):
                    self.pt_set_seq[seq_idx][frame_idx].draw(self.PointSize)
        else:
            if self.cur_seq == self.num_seq:
                for seq_idx in range(self.num_seq):
                    self.pt_set_seq[seq_idx][self.cur_frame].draw(
                        self.PointSize)
            elif self.cur_seq < self.num_seq:
                self.pt_set_seq[self.cur_seq][self.cur_frame].draw(
                    self.PointSize)

        if self.cameras is not None:
            draw_frames = [self.cur_frame]
            if self.draw_all:
                draw_frames = range(self.num_frames_per_seq)
            for cam_frame_idx in draw_frames:
                for cam_idx in range(len(self.cameras)):
                    self.cameras[cam_idx][cam_frame_idx].draw(
                        Color=self.cam_colors[cam_idx % len(self.cam_colors)],
                        CubeSide=-0.2,
                        isDrawDir=True,
                        Length=0.3)

            # draw cam traj
            for cam_idx in range(len(self.cameras)):
                for cam_frame_idx in range(len(self.cameras[cam_idx]) - 1):
                    self.drawLine(self.cameras[cam_idx][cam_frame_idx].Extrinsics.Translation, self.cameras[cam_idx][cam_frame_idx+1].Extrinsics.Translation, \
                            Color=self.cam_colors[cam_idx % len(self.cam_colors)], LineWidth=1.0)

        gl.glPopMatrix()

        if self.take_ss:
            x, y, width, height = gl.glGetIntegerv(gl.GL_VIEWPORT)
            # print("Screenshot viewport:", x, y, width, height)
            gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1)

            data = gl.glReadPixels(x, y, width, height, gl.GL_RGBA,
                                   gl.GL_UNSIGNED_BYTE)
            SS = np.frombuffer(data, dtype=np.uint8)
            SS = np.reshape(SS, (height, width, 4))
            SS = cv2.flip(SS, 0)
            SS = cv2.cvtColor(SS, cv2.COLOR_BGRA2RGBA)
            ss_out_path = os.path.join(
                self.out_path,
                'screenshot_' + str(self.ss_ctr).zfill(6) + '.png')
            cv2.imwrite(ss_out_path, SS)
            self.ss_ctr = self.ss_ctr + 1
            self.take_ss = False

            print('[ INFO ]: Done saving.')
            sys.stdout.flush()