Exemple #1
0
 def _UploadTexture(self, data, *args):
     """ "Overloaded" method to upload texture data
     """
     
     # Set alignment to 1. It is 4 by default, but my data array has no
     # strides, so in order for the image not to be distorted, I set it 
     # to 1. I assume graphics cards can still render in hardware. If 
     # not, I would have to add one or two rows to my data instead.
     gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT,1)
     
     # init transferfunctions and set clim to full range
     self._ScaleBias_init(data.dtype.name)
     
     # create texture
     TextureObject._UploadTexture(self, data, *args)
     
     # set interpolation and extrapolation parameters            
     tmp1 = gl.GL_NEAREST
     tmp2 = {False:gl.GL_NEAREST, True:gl.GL_LINEAR}[self._interpolate]
     gl.glTexParameteri(self._texType, gl.GL_TEXTURE_MIN_FILTER, tmp1)
     gl.glTexParameteri(self._texType, gl.GL_TEXTURE_MAG_FILTER, tmp2)
     gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP)
     gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP)
     
     # reset transfer
     self._ScaleBias_afterUpload()
     
     # Set clamping. When testing the raycasting, comment these lines!
     if self._ndim==3:
         gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP)
         gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP)
         gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_R, gl.GL_CLAMP)
Exemple #2
0
    def _UploadTexture(self, data, *args):
        """ "Overloaded" method to upload texture data
        """

        # Set alignment to 1. It is 4 by default, but my data array has no
        # strides, so in order for the image not to be distorted, I set it
        # to 1. I assume graphics cards can still render in hardware. If
        # not, I would have to add one or two rows to my data instead.
        gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)

        # init transferfunctions and set clim to full range
        self._ScaleBias_init(data.dtype.name)

        # create texture
        TextureObject._UploadTexture(self, data, *args)

        # set interpolation and extrapolation parameters
        tmp1 = gl.GL_NEAREST
        tmp2 = {False: gl.GL_NEAREST, True: gl.GL_LINEAR}[self._interpolate]
        gl.glTexParameteri(self._texType, gl.GL_TEXTURE_MIN_FILTER, tmp1)
        gl.glTexParameteri(self._texType, gl.GL_TEXTURE_MAG_FILTER, tmp2)
        gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP)
        gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP)

        # reset transfer
        self._ScaleBias_afterUpload()

        # Set clamping. When testing the raycasting, comment these lines!
        if self._ndim == 3:
            gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_S,
                               gl.GL_CLAMP)
            gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_T,
                               gl.GL_CLAMP)
            gl.glTexParameteri(self._texType, gl.GL_TEXTURE_WRAP_R,
                               gl.GL_CLAMP)
Exemple #3
0
 def __init__(self, ndim, data, interpolate=False):
     TextureObject.__init__(self, ndim)
     
     # interpolate?
     self._interpolate = interpolate
     
     # the limits
     self._clim = Range(0,1)
     self._climCorrection = 1.0
     self._climRef = Range(0,1) # the "original" range
     
     # init clim and colormap
     self._climRef.Set(*minmax(data))
     self._clim = self._climRef.Copy()
Exemple #4
0
    def __init__(self, ndim, data, interpolate=False):
        TextureObject.__init__(self, ndim)

        # interpolate?
        self._interpolate = interpolate

        # the limits
        self._clim = Range(0, 1)
        self._climCorrection = 1.0
        self._climRef = Range(0, 1)  # the "original" range

        # init clim and colormap
        self._climRef.Set(*minmax(data))
        self._clim = self._climRef.Copy()
Exemple #5
0
 def _UpdateTexture(self, data, *args):
     """ "Overloaded" method to update texture data
     """
     
     # init transferfunctions and set clim to full range
     self._ScaleBias_init(data.dtype.name)
     
     # create texture
     TextureObject._UpdateTexture(self, data, *args)
     
     # Update interpolation
     tmp = {False:gl.GL_NEAREST, True:gl.GL_LINEAR}[self._interpolate]
     gl.glTexParameteri(self._texType, gl.GL_TEXTURE_MAG_FILTER, tmp)
     
     # reset transfer
     self._ScaleBias_afterUpload()
Exemple #6
0
    def _UpdateTexture(self, data, *args):
        """ "Overloaded" method to update texture data
        """

        # init transferfunctions and set clim to full range
        self._ScaleBias_init(data.dtype.name)

        # create texture
        TextureObject._UpdateTexture(self, data, *args)

        # Update interpolation
        tmp = {False: gl.GL_NEAREST, True: gl.GL_LINEAR}[self._interpolate]
        gl.glTexParameteri(self._texType, gl.GL_TEXTURE_MAG_FILTER, tmp)

        # reset transfer
        self._ScaleBias_afterUpload()
Exemple #7
0
    def __init__(self, parent, data1, data2):
        Texture3D.__init__(self, parent, data1)

        # create second texture and set data
        self._texture2 = TextureObject(gl.GL_TEXTURE_3D)
        self.SetData(data2)
Exemple #8
0
class MultiTexture3D(Texture3D):
    """ MultiTexture3D(parent, data1, data2)
    
    This is an example of what multi-texturing would look like
    in Visvis. Not tested.
    
    """
    def __init__(self, parent, data1, data2):
        Texture3D.__init__(self, parent, data1)

        # create second texture and set data
        self._texture2 = TextureObject(gl.GL_TEXTURE_3D)
        self.SetData(data2)

    def OnDraw(self, fast=False):
        # Draw the texture.

        # Enable texture, so that it has a corresponding OpenGl texture.
        # Binding is done by the shader
        self._texture1.Enable(-1)
        self.shader.SetUniform('texture', self._texture1)
        self.shader.SetUniform('texture2', self._texture2)

        # _texture._shape is a good indicator of a valid texture
        if not self._texture1._shape:
            return

        # Prepare by setting things to their defaults. This might release some
        # memory so result in a bigger chance that the shader is run in
        # hardware mode. On ATI, the line and point smoothing should be off
        # if you want to use gl_FragCoord. (Yeah, I do not see the connection
        # either...)
        gl.glPointSize(1)
        gl.glLineWidth(1)
        gl.glDisable(gl.GL_LINE_STIPPLE)
        gl.glDisable(gl.GL_LINE_SMOOTH)
        gl.glDisable(gl.GL_POINT_SMOOTH)

        # only draw front-facing parts
        gl.glEnable(gl.GL_CULL_FACE)
        gl.glCullFace(gl.GL_BACK)

        # Set step ratio
        if fast:
            self.shader.SetUniform('stepRatio', self._stepRatio * 0.5)
        else:
            self.shader.SetUniform('stepRatio', float(self._stepRatio))

        # fragment shader on
        if self.shader.isUsable and self.shader.hasCode:
            # turn glsl shader on
            self.shader.Enable()
        else:
            pass  # glsl not available, or someone cleared the code

        # do the actual drawing
        self._DrawQuads()

        # clean up
        gl.glFlush()
        self.shader.Disable()
        #
        gl.glDisable(gl.GL_CULL_FACE)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POINT_SMOOTH)

    def OnDestroyGl(self):
        # Clean up OpenGl resources.

        # remove texture from opengl memory
        self._texture1.DestroyGl()
        self._texture2.DestroyGl()

        # clear shaders
        self._shader.program.DestroyGl()

        # remove colormap's texture from memory
        if hasattr(self, '_colormap'):
            self._colormap.DestroyGl()

    def OnDestroy(self):
        # Clean up any resources.
        self._texture1.Destroy()
        self._texture2.Destroy()
        if hasattr(self, '_colormap'):
            self._colormap.Destroy()