Beispiel #1
0
 def chooseTemplate(self):
     if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
     # make sure we are not already in a newlist
     if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
         GL.glNewList(self.templateDSPL[0], GL.GL_COMPILE)
         #print '+%d'%self.templateDSPL[0], "glNewList Spheres0"
         if self.invertNormals:
             #print "GLU_INSIDE reversed normals"
             #print '#%d'%(self.templateDSPL[0]+2), "glCallList Spheres2"
             GL.glCallList(self.templateDSPL[0] + 2)
         else:
             #print "GLU_OUTSIDE regular normals"
             #print '#%d'%(self.templateDSPL[0]+1), "glCallList Spheres1"
             GL.glCallList(self.templateDSPL[0] + 1)
         #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres0"
         GL.glEndList()
 def chooseTemplate(self):
     if __debug__:
      if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
     # make sure we are not already in a newlist
     if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
         GL.glNewList(self.templateDSPL[0], GL.GL_COMPILE)
         #print '+%d'%self.templateDSPL[0], "glNewList Spheres0"
         if self.invertNormals:
             #print "GLU_INSIDE reversed normals"
             #print '#%d'%(self.templateDSPL[0]+2), "glCallList Spheres2"
             GL.glCallList(self.templateDSPL[0]+2)
         else:
             #print "GLU_OUTSIDE regular normals"
             #print '#%d'%(self.templateDSPL[0]+1), "glCallList Spheres1"
             GL.glCallList(self.templateDSPL[0]+1)
         #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres0"
         GL.glEndList()
 def deleteTemplate(self):
     if __debug__:
      if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
     #print "Spheres.deleteTemplate", self.templateDSPL
     # it is asumed the right OpenGL context is active
     if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
         assert self.templateDSPL is not None
         currentcontext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
         if currentcontext != self.templateDSPL[1]:
             import traceback;traceback.print_stack()
             warnings.warn('deleteTemplate failed because the current context is the wrong one')
             print "currentcontext != self.templateDSPL[1]", currentcontext, self.templateDSPL[1]
         else:
             #print '-%d'%self.templateDSPL[0], currentcontext, "glDeleteLists Spheres0"
             #print '-%d'%(self.templateDSPL[0]+1), currentcontext, "glDeleteLists Spheres1"
             #print '-%d'%(self.templateDSPL[0]+2), currentcontext, "glDeleteLists Spheres2"
             GL.glDeleteLists(self.templateDSPL[0], 3)
             self.templateDSPL = None
Beispiel #4
0
    def makeTemplate(self):
        if __debug__:
            if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "Spheres.makeTemplate", self.quality
        # it is asumed the right OpenGL context is active
        # make sure we are not already in a newlist
        if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
            assert self.templateDSPL is None
            lFirstList = GL.glGenLists(3)
            #lFirstList = self.firstList
            #print "Spheres.makeTemplate", lFirstList
            #print "lFirstList Spheres.makeTemplate", lFirstList, self.name
            lCurrentContext = self.viewer.currentCamera.tk.call(
                self.viewer.currentCamera._w, 'contexttag')
            self.templateDSPL = (lFirstList, lCurrentContext)

            if (hasattr(DejaVu, 'enableVBO') and DejaVu.enableVBO) \
              or DejaVu.enableVertexArrayNonVBO is True :
                lSphereGeom = self.asIndexedPolygons(run=1,
                                                     quality=self.quality - 1,
                                                     centers=((0, 0, 0), ),
                                                     radii=((1., ), ))
                GL.glNewList(lFirstList + 1, GL.GL_COMPILE)
                lSphereGeom.Draw()
                GL.glEndList()
                lSphereGeom.Set(invertNormals=True)
                GL.glNewList(lFirstList + 2, GL.GL_COMPILE)
                lSphereGeom.Draw()
                GL.glEndList()
            else:
                quality = self.quality * 5
                GL.glNewList(lFirstList + 1, GL.GL_COMPILE)
                #print '+%d'%(lFirstList+1), lCurrentContext, "glNewList Spheres1"
                extractedGlutSolidSphere(1, quality, quality, 0)
                #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres1"
                GL.glEndList()
                GL.glNewList(lFirstList + 2, GL.GL_COMPILE)
                #print '+%d'%(lFirstList+2), lCurrentContext, "glNewList Spheres2"
                extractedGlutSolidSphere(1, quality, quality, 1)
                #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres2"
                GL.glEndList()

            self.chooseTemplate()
    def makeTemplate(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "Spheres.makeTemplate", self.quality
        # it is asumed the right OpenGL context is active
        # make sure we are not already in a newlist
        if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
            assert self.templateDSPL is None
            lFirstList = GL.glGenLists(3)
            #lFirstList = self.firstList
            #print "Spheres.makeTemplate", lFirstList
            #print "lFirstList Spheres.makeTemplate", lFirstList, self.name
            lCurrentContext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w,
                                                        'contexttag')
            self.templateDSPL = ( lFirstList, lCurrentContext )

            if (hasattr(DejaVu, 'enableVBO') and DejaVu.enableVBO) \
              or DejaVu.enableVertexArrayNonVBO is True :
                lSphereGeom = self.asIndexedPolygons(run=1, quality=self.quality-1,
                                                     centers=((0,0,0),), radii=((1.,),) )
                GL.glNewList(lFirstList+1, GL.GL_COMPILE)
                lSphereGeom.Draw()
                GL.glEndList()
                lSphereGeom.Set(invertNormals=True)
                GL.glNewList(lFirstList+2, GL.GL_COMPILE)
                lSphereGeom.Draw()
                GL.glEndList()
            else:
                quality = self.quality * 5
                GL.glNewList(lFirstList+1, GL.GL_COMPILE)
                #print '+%d'%(lFirstList+1), lCurrentContext, "glNewList Spheres1"
                extractedGlutSolidSphere(1, quality, quality, 0)
                #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres1"
                GL.glEndList()
                GL.glNewList(lFirstList+2, GL.GL_COMPILE)
                #print '+%d'%(lFirstList+2), lCurrentContext, "glNewList Spheres2"
                extractedGlutSolidSphere(1, quality, quality, 1)
                #print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Spheres2"
                GL.glEndList()

            self.chooseTemplate()
Beispiel #6
0
 def deleteTemplate(self):
     if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
     #print "Spheres.deleteTemplate", self.templateDSPL
     # it is asumed the right OpenGL context is active
     if GL.glGetIntegerv(GL.GL_LIST_INDEX) == [0]:
         assert self.templateDSPL is not None
         currentcontext = self.viewer.currentCamera.tk.call(
             self.viewer.currentCamera._w, 'contexttag')
         if currentcontext != self.templateDSPL[1]:
             import traceback
             traceback.print_stack()
             warnings.warn(
                 'deleteTemplate failed because the current context is the wrong one'
             )
             print "currentcontext != self.templateDSPL[1]", currentcontext, self.templateDSPL[
                 1]
         else:
             #print '-%d'%self.templateDSPL[0], currentcontext, "glDeleteLists Spheres0"
             #print '-%d'%(self.templateDSPL[0]+1), currentcontext, "glDeleteLists Spheres1"
             #print '-%d'%(self.templateDSPL[0]+2), currentcontext, "glDeleteLists Spheres2"
             GL.glDeleteLists(self.templateDSPL[0], 3)
             self.templateDSPL = None
Beispiel #7
0
    def endTile(self):
        assert (self.CurrentTile >= 0)

        # be sure OpenGL rendering is finished
        GL.glFinish()  #was glFlush()

        # save current glPixelStore values
        prevRowLength = GL.glGetIntegerv(GL.GL_PACK_ROW_LENGTH)[0]
        prevSkipRows = GL.glGetIntegerv(GL.GL_PACK_SKIP_ROWS)[0]
        prevSkipPixels = GL.glGetIntegerv(GL.GL_PACK_SKIP_PIXELS)[0]
        #prevAlignment = GL.glGetIntegerv(GL_PACK_ALIGNMENT)[0]

        if self.TileBuffer is not None:
            srcX = self.TileBorder
            srcY = self.TileBorder
            srcWidth = self.TileWidthNB
            srcHeight = self.TileHeightNB
            GL.glReadPixels(srcX, srcY, srcWidth, srcHeight, self.TileFormat,
                            self.TileType, self.TileBuffer)

        if self.ImageBuffer is not None:
            srcX = self.TileBorder
            srcY = self.TileBorder
            srcWidth = self.CurrentTileWidth - 2 * self.TileBorder
            srcHeight = self.CurrentTileHeight - 2 * self.TileBorder
            destX = self.TileWidthNB * self.CurrentColumn
            destY = self.TileHeightNB * self.CurrentRow

            ##          #save single tile
            ##          # setup pixel store for glReadPixels
            ##          GL.glPixelStorei(GL.GL_PACK_ROW_LENGTH, self.CurrentTileWidth)
            ##          GL.glPixelStorei(GL.GL_PACK_SKIP_ROWS, 0)
            ##          GL.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, 0)
            ##          #GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1)

            ##          # read the tile into buffer
            ##          gllib.glReadPixels(srcX, srcY, srcWidth, srcHeight,
            ##                             self.ImageFormat, self.ImageType, self.oneTileRenderBuffer)
            ##          import Image, sys
            ##          im = Image.fromstring('RGB', (srcWidth, srcHeight),
            ##                                self.oneTileRenderBuffer)
            ##          if sys.platform!='win32':
            ##             im = im.transpose(Image.FLIP_TOP_BOTTOM)
            ##          im.save('tile%d_%d.tif'%(self.CurrentRow, self.CurrentColumn))

            # setup pixel store for glReadPixels
            GL.glPixelStorei(GL.GL_PACK_ROW_LENGTH, self.ImageWidth)
            GL.glPixelStorei(GL.GL_PACK_SKIP_ROWS, destY)
            GL.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, destX)
            #GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1)

            # read the tile into the final image
            #print 'DEBUG Tile renderer'
            #print 'column, row:', self.CurrentColumn, self.CurrentRow
            #print 'srcWidth,srcHeight,destX, destY',srcWidth,srcHeight,destX, destY
            gllib.glReadPixels(srcX, srcY, srcWidth, srcHeight,
                               self.ImageFormat, self.ImageType,
                               self.ImageBuffer)

        # restore previous glPixelStore values
        GL.glPixelStorei(GL.GL_PACK_ROW_LENGTH, int(prevRowLength))
        GL.glPixelStorei(GL.GL_PACK_SKIP_ROWS, int(prevSkipRows))
        GL.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, int(prevSkipPixels))
        #GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, prevAlignment)

        # increment tile counter, return 1 if more tiles left to render
        self.CurrentTile += 1
        if self.CurrentTile >= self.Rows * self.Columns:
            # restore user's viewport
            GL.glViewport(int(self.ViewportSave[0]), int(self.ViewportSave[1]),
                          int(self.ViewportSave[2]), int(self.ViewportSave[3]))
            self.CurrentTile = -1  # all done
            return 0
        else:
            return 1
Beispiel #8
0
    def beginTile(self):

        if self.CurrentTile <= 0:
            self.setup()
        # Save user's viewport, will be restored after last tile rendered
        self.ViewportSave = GL.glGetIntegerv(GL.GL_VIEWPORT)

        # which tile (by row and column) we're about to render
        if self.RowOrder == TR_BOTTOM_TO_TOP:
            self.CurrentRow = self.CurrentTile / self.Columns
            self.CurrentColumn = self.CurrentTile % self.Columns
        elif self.RowOrder == TR_TOP_TO_BOTTOM:
            self.CurrentRow = self.Rows - (self.CurrentTile / self.Columns) - 1
            self.CurrentColumn = self.CurrentTile % self.Columns
        else:
            raise RuntimeError

        assert (self.CurrentRow < self.Rows)
        assert (self.CurrentColumn < self.Columns)

        border = self.TileBorder

        # Compute actual size of this tile with border
        if self.CurrentRow < self.Rows - 1:
            tileHeight = self.TileHeight
        else:
            tileHeight = self.ImageHeight - (self.Rows-1) * \
                         (self.TileHeightNB) + 2 * border

        if self.CurrentColumn < self.Columns - 1:
            tileWidth = self.TileWidth
        else:
            tileWidth = self.ImageWidth - (self.Columns-1) * \
                        (self.TileWidthNB) + 2 * border

        # Save tile size, with border
        self.CurrentTileWidth = tileWidth
        self.CurrentTileHeight = tileHeight

        GL.glViewport(0, 0, tileWidth, tileHeight)  #tile size including border

        # save current matrix mode
        matrixMode = GL.glGetIntegerv(GL.GL_MATRIX_MODE)[0]
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()

        # compute projection parameters
        self.tileleft = left = self.Left + (self.Right - self.Left) \
                        * (self.CurrentColumn * self.TileWidthNB - border) \
                        / self.ImageWidth
        self.tileright = right = left + (self.Right - self.Left) * \
                         self.TileWidth / self.ImageWidth
        self.tilebottom = bottom = self.Bottom + (self.Top - self.Bottom) \
                          * (self.CurrentRow * self.TileHeightNB - border) / \
                          self.ImageHeight
        self.tiletop = top = bottom + (self.Top - self.Bottom) * self.TileHeight / \
                       self.ImageHeight

        if self.Perspective:
            GL.glFrustum(float(left), float(right), float(bottom), float(top),
                         float(self.Near), float(self.Far))
        else:
            GL.glOrtho(float(left), float(right), float(bottom), float(top),
                       float(self.Near), float(self.Far))

        # restore user's matrix mode
        GL.glMatrixMode(int(matrixMode))
   def endTile(self):
      assert(self.CurrentTile>=0)

      # be sure OpenGL rendering is finished
      GL.glFinish() #was glFlush()

      # save current glPixelStore values
      prevRowLength = GL.glGetIntegerv(GL.GL_PACK_ROW_LENGTH)[0]
      prevSkipRows = GL.glGetIntegerv(GL.GL_PACK_SKIP_ROWS)[0]
      prevSkipPixels = GL.glGetIntegerv(GL.GL_PACK_SKIP_PIXELS)[0]
      #prevAlignment = GL.glGetIntegerv(GL_PACK_ALIGNMENT)[0]

      if self.TileBuffer is not None:
         srcX = self.TileBorder
         srcY = self.TileBorder
         srcWidth = self.TileWidthNB
         srcHeight = self.TileHeightNB
         GL.glReadPixels(srcX, srcY, srcWidth, srcHeight,
                         self.TileFormat, self.TileType, self.TileBuffer)

      if self.ImageBuffer is not None:
         srcX = self.TileBorder
         srcY = self.TileBorder
         srcWidth = self.CurrentTileWidth - 2 * self.TileBorder
         srcHeight = self.CurrentTileHeight - 2 * self.TileBorder
         destX = self.TileWidthNB * self.CurrentColumn
         destY = self.TileHeightNB * self.CurrentRow

##          #save single tile
##          # setup pixel store for glReadPixels
##          GL.glPixelStorei(GL.GL_PACK_ROW_LENGTH, self.CurrentTileWidth)
##          GL.glPixelStorei(GL.GL_PACK_SKIP_ROWS, 0)
##          GL.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, 0)
##          #GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1)

##          # read the tile into buffer
##          gllib.glReadPixels(srcX, srcY, srcWidth, srcHeight,
##                             self.ImageFormat, self.ImageType, self.oneTileRenderBuffer)
##          import Image, sys
##          im = Image.fromstring('RGB', (srcWidth, srcHeight),
##                                self.oneTileRenderBuffer) 
##          if sys.platform!='win32':
##             im = im.transpose(Image.FLIP_TOP_BOTTOM)
##          im.save('tile%d_%d.tif'%(self.CurrentRow, self.CurrentColumn))
         
         # setup pixel store for glReadPixels
         GL.glPixelStorei(GL.GL_PACK_ROW_LENGTH, self.ImageWidth)
         GL.glPixelStorei(GL.GL_PACK_SKIP_ROWS, destY)
         GL.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, destX)
         #GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1)

         # read the tile into the final image
         #print 'DEBUG Tile renderer'
         #print 'column, row:', self.CurrentColumn, self.CurrentRow
         #print 'srcWidth,srcHeight,destX, destY',srcWidth,srcHeight,destX, destY
         gllib.glReadPixels(srcX, srcY, srcWidth, srcHeight,
                            self.ImageFormat, self.ImageType, self.ImageBuffer)

      # restore previous glPixelStore values
      GL.glPixelStorei(GL.GL_PACK_ROW_LENGTH, int(prevRowLength))
      GL.glPixelStorei(GL.GL_PACK_SKIP_ROWS, int(prevSkipRows))
      GL.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, int(prevSkipPixels))
      #GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, prevAlignment)

      # increment tile counter, return 1 if more tiles left to render
      self.CurrentTile+=1
      if self.CurrentTile >= self.Rows * self.Columns:
         # restore user's viewport
         GL.glViewport(int(self.ViewportSave[0]), int(self.ViewportSave[1]),
                       int(self.ViewportSave[2]), int(self.ViewportSave[3]))
         self.CurrentTile = -1  # all done
         return 0
      else:
         return 1
   def beginTile(self):

      if self.CurrentTile <= 0:
         self.setup()
      # Save user's viewport, will be restored after last tile rendered
      self.ViewportSave = GL.glGetIntegerv(GL.GL_VIEWPORT)

      # which tile (by row and column) we're about to render
      if self.RowOrder==TR_BOTTOM_TO_TOP:
         self.CurrentRow = self.CurrentTile / self.Columns
         self.CurrentColumn = self.CurrentTile % self.Columns
      elif self.RowOrder==TR_TOP_TO_BOTTOM:
         self.CurrentRow = self.Rows - (self.CurrentTile / self.Columns) - 1
         self.CurrentColumn = self.CurrentTile % self.Columns
      else:
         raise RuntimeError

      assert(self.CurrentRow < self.Rows)
      assert(self.CurrentColumn < self.Columns)

      border = self.TileBorder

      # Compute actual size of this tile with border
      if self.CurrentRow < self.Rows-1:
         tileHeight = self.TileHeight
      else:
         tileHeight = self.ImageHeight - (self.Rows-1) * \
                      (self.TileHeightNB) + 2 * border

      if self.CurrentColumn < self.Columns-1:
         tileWidth = self.TileWidth
      else:
         tileWidth = self.ImageWidth - (self.Columns-1) * \
                     (self.TileWidthNB) + 2 * border

      # Save tile size, with border
      self.CurrentTileWidth = tileWidth
      self.CurrentTileHeight = tileHeight

      GL.glViewport(0, 0, tileWidth, tileHeight) #tile size including border

      # save current matrix mode
      matrixMode = GL.glGetIntegerv(GL.GL_MATRIX_MODE)[0]
      GL.glMatrixMode(GL.GL_PROJECTION)
      GL.glLoadIdentity()

      # compute projection parameters
      self.tileleft = left = self.Left + (self.Right - self.Left) \
                      * (self.CurrentColumn * self.TileWidthNB - border) \
                      / self.ImageWidth
      self.tileright = right = left + (self.Right - self.Left) * \
                       self.TileWidth / self.ImageWidth
      self.tilebottom = bottom = self.Bottom + (self.Top - self.Bottom) \
                        * (self.CurrentRow * self.TileHeightNB - border) / \
                        self.ImageHeight
      self.tiletop = top = bottom + (self.Top - self.Bottom) * self.TileHeight / \
                     self.ImageHeight

      if self.Perspective:
         GL.glFrustum(float(left), float(right),
                      float(bottom), float(top),
                      float(self.Near), float(self.Far))
      else:
         GL.glOrtho(float(left), float(right),
                    float(bottom), float(top),
                    float(self.Near), float(self.Far))

      # restore user's matrix mode
      GL.glMatrixMode(int(matrixMode))