示例#1
0
    def createFramebufferObject(self, size):
        format = QOpenGLFramebufferObjectFormat()
        format.setAttachment(QOpenGLFramebufferObject.CombinedDepthStencil)
        format.setSamples(4)

        self._qfbo = QOpenGLFramebufferObject(size, format)
        return self._qfbo
示例#2
0
    def __init__(self, width, height):
        super().__init__()

        buffer_format = QOpenGLFramebufferObjectFormat()
        buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
        self._fbo = QOpenGLFramebufferObject(width, height, buffer_format)

        self._contents = None
示例#3
0
 def createFramebufferObject(self, size):
     #print("\n\nLogoInFboRenderer.createFramebufferObject", size)#, QApplication.instance()
     format = QOpenGLFramebufferObjectFormat()
     format.setAttachment(QOpenGLFramebufferObject.CombinedDepthStencil)
     format.setSamples(4)
     self.frmBuffer = QOpenGLFramebufferObject(size, format)
     #print("hola3", self.frmBuffer)
     return self.frmBuffer
示例#4
0
    def animate(self):
        #print("OpenGL Version: ",GL.glGetString(GL.GL_VERSION))
        #print("OpenGL Vendor: ",GL.glGetString(GL.GL_VENDOR))
        #print("OpenGL Renderer: ",GL.glGetString(GL.GL_RENDERER))

        # build a new frame number self.frameid

        self.an += 0.05

        self.counter += 1

        self.frameid += 1

        sid = 0

        #MY ATTEMPT TO SAVE TO HIGHER RESOLUTION THAN SCREEN in other frame buffer
        #GL.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
        tempw = 2000
        temph = 2000

        print("OpenGL MAX TEXTURE SIZE: ",
              GL.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE))
        print("OpenGL VIEWPORT DIMS: ", GL.glGetIntegerv(GL.GL_VIEWPORT))
        attachment = 2  # default =< try 2 for depth
        self.fbo = QOpenGLFramebufferObject(
            QtCore.QSize(tempw, temph), attachment, GL.GL_TEXTURE_2D,
            GL.GL_RGB8)  #,GL.GL_COLOR_ATTACHMENT0)#,GL.GL_RGB)

        self.fbo.bind()
        self.resizeGL(tempw, temph)
        self.paintGL()

        buffer = GL.glReadPixels(0, 0, tempw, temph, GL.GL_RGB,
                                 GL.GL_UNSIGNED_BYTE, None)

        print('buffer', len(buffer), tempw, temph)
        image = Image.frombytes(mode="RGB", size=(tempw, temph), data=buffer)
        image = image.transpose(Image.FLIP_TOP_BOTTOM)
        fname = 'D:/Users/Antoine/Documents/copenhague-1/togit/gaussian_forAntoine/doughnut/frame_nb_' + str(
            self.counter) + '.png'
        image.save(fname)
        self.fbo.release()

        self.resizeGL(self.width, self.height)

        self.update()
示例#5
0
 def get_frame_cv(self, width, height):
     fmt = QOpenGLFramebufferObjectFormat()
     fmt.setSamples(self.fmt.samples())
     fbo = QOpenGLFramebufferObject(width, height)
     fbo.setAttachment(fbo.Depth)
     fbo.bind()
     GL.glFinish()
     # resize framebuffer to desired resolution
     self.resizeGL(width, height)
     # draw the scene
     self.update_scene()
     self.glDraw()
     GL.glFinish()
     # read the raw image data
     img = GL.glReadPixels(0, 0, width, height, GL.GL_RGB,
                           GL.GL_UNSIGNED_BYTE)
     # convert raw image data to cv2 format
     img = np.reshape(np.frombuffer(img, np.ubyte), (height, width, 3))
     img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
     img = cv2.flip(img, 0)
     fbo.release()
     return img
示例#6
0
 def createFrameBuffer(self, width, height):
     buffer_format = QOpenGLFramebufferObjectFormat()
     buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
     return QOpenGLFramebufferObject(width, height, buffer_format)
示例#7
0
    def animate(self):
        #print("OpenGL Version: ",GL.glGetString(GL.GL_VERSION))
        #print("OpenGL Vendor: ",GL.glGetString(GL.GL_VENDOR))
        #print("OpenGL Renderer: ",GL.glGetString(GL.GL_RENDERER))

        # build a new frame number self.frameid

        self.an += 0.05

        self.counter += 1

        self.frameid += 1

        sid = 0

        zarr = np.linspace(
            self.center_mass[self.counter % self.nbframes] + self.ZL,
            self.center_mass[self.counter % self.nbframes] + self.ZR,
            2 * 64 * 2,
            endpoint=True
        )  #z axis #defined with normalized length #for real axis *L
        xarr = np.linspace(
            self.YB, self.YT, 64 * 2, endpoint=True
        )  #x axis #defined with normalizad length #for real axis *L

        data = np.array([
            [It0((zi + z0 / L) * L, xi * L, 0.0) for zi in zarr] for xi in xarr
        ])  #stores the information about the intensity profile

        # map the normalized data to colors
        # image is now RGBA
        cmap = plt.cm.viridis  #hot#viridis
        norm = plt.Normalize(vmin=0.0, vmax=np.max(data))  #
        image = cmap(norm(data))

        #image = cmap(data)
        # save the image
        plt.imsave('tmp.png', image)

        #something misterious
        i = self.lasti0
        self.texture_id.append(i)

        img = Image.open('tmp.png').convert("RGBA")
        d = ImageDraw.Draw(img)
        d.text(
            (0, 0),
            str('%.6f' % (self.center_mass[self.counter % self.nbframes] * L)),
            fill=(255, 255, 255, 255))
        itm = np.asarray(img)
        itm2 = itm.copy()
        #itm2[:,:,0] = data[:,:]
        self.pixels.append(itm2)
        print('done')
        self.lasti0 = i + 1

        #MY ATTEMPT TO SAVE TO HIGHER RESOLUTION THAN SCREEN in other frame buffer
        #GL.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
        tempw = 2000
        temph = 2000

        #print("OpenGL MAX TEXTURE SIZE: ", GL.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE))
        #print("OpenGL VIEWPORT DIMS: ",GL.glGetIntegerv(GL.GL_VIEWPORT))
        attachment = 2  # default =< try 2 for depth
        self.fbo = QOpenGLFramebufferObject(
            QtCore.QSize(tempw, temph), attachment, GL.GL_TEXTURE_2D,
            GL.GL_RGB8)  #,GL.GL_COLOR_ATTACHMENT0)#,GL.GL_RGB)

        self.fbo.bind()
        self.resizeGL(tempw, temph)
        self.paintGL()

        buffer = GL.glReadPixels(0, 0, tempw, temph, GL.GL_RGB,
                                 GL.GL_UNSIGNED_BYTE, None)

        #print('buffer',len(buffer), tempw,temph)
        image = Image.frombytes(mode="RGB", size=(tempw, temph), data=buffer)
        image = image.transpose(Image.FLIP_TOP_BOTTOM)
        fname = 'D:/Users/Antoine/Documents/copenhague-1/togit/MyMCPython/doughnut_' + simulation_name + '_frame_nb_' + str(
            self.counter) + '.png'
        image.save(fname)
        self.fbo.release()

        self.resizeGL(self.width, self.height)

        self.update()
示例#8
0
 def createFrameBufferObject(self, size):
     f = QOpenGLFramebufferObjectFormat()
     f.setAttachment(QOpenGLFramebufferObject.CombinedDepthStencil)
     f.setSamples(4)
     return QOpenGLFramebufferObject(size, f)