3.9. GLDisplay

Summary:

Frameless window to display images using OpenGL

Type:

DataIO

License:

LGPL

Platforms:

Windows, Linux

Devices:

OpenGL based widget to show any textures given by dataObjects

Author:

M. Gronle, ITO, University Stuttgart

3.9.1. Overview

This plugin displays a frameless window that displays one or multiple arrays using OpenGL technology. Each array is then created as texture, where the horizontal and vertical wrap property can be chosen individually. OpenGL allows a fast switch between all created textures.

Per default, the window is either displayed in a second screen (fullscreen) or if only one screen is available - placed as small window in the top left corner of the main screen. Otherwise chose an appropriate x0, y0, xsize and ysize parameter at initialization.

In order to assign textures, use the exec-function ‘addTextures’ and pass a 2d or 3d dataObject, where in the latter case every plane of the 3d dataObject is registered as single texture. Create the tags ‘wrapT’, ‘wrapS’, ‘MinFilter’ or ‘MagFilter’ to control the repeatability of every texture or its interpolation method.

Allowed values for these tags are:

  • ‘MagFilter’ (interpolation used when the texture is smaller than the window size): ‘GL_NEAREST’ (default) or ‘GL_LINEAR’

  • ‘MinFilter’ (interpolation used when the texture is bigger than the window size): ‘GL_NEAREST’ (default), ‘GL_LINEAR’, ‘GL_LINEAR_MIPMAP_NEAREST’, ‘GL_NEAREST_MIPMAP_NEAREST’, ‘GL_LINEAR_MIPMAP_LINEAR’

  • ‘wrapT’ (vertical scaling mode): ‘GL_REPEAT’ (default), ‘SCALED’, ‘GL_MIRRORED_REPEAT, ‘GL_CLAMP_TO_EDGE’

  • ‘wrapS’ (horizontal scaling mode): ‘GL_REPEAT’ (default), ‘SCALED’, ‘GL_MIRRORED_REPEAT’, ‘GL_CLAMP_TO_EDGE’

3.9.2. Initialization

The following parameters are mandatory or optional for initializing an instance of this plugin:

  • x0: int, optional

    x0 position of window

    Value range: [-4096, 4096], Default: 0

  • y0: int, optional

    y0 position of window

    Value range: [-4096, 4096], Default: 0

  • xsize: int, optional

    width of window, if 0 (default) the window is positioned in the second screen or gets a default width of 100px if no second screen is available.

    Value range: [0, 4096], Default: 0

  • ysize: int, optional

    height of window, if 0 (default) the window is positioned in the second screen or gets a default height of 100px if no second screen is available.

    Value range: [0, 4096], Default: 0

  • lut: Sequence[int] (char), optional

    Lookup table for a gamma correction with 256 values. If given, the gamma correction will be enabled (default: off) and the projected values are then modified with lut[value].

3.9.3. Parameters

An instance of this plugin has the following parameters:

color: {int}

0: Red, 1: Green, 2: Blue, 3: White

currentIdx: {int}

Index of currently displayed image [0..)

gamma: {int}

0: disable gamma correction, 1: enable gamma correction; default disable (see also ‘lut’)

lut: {seq. of int (char)}

Lookup table for a gamma correction with 256 values. The gamma correction itself is en-/disabled via parameter ‘gamma’. If enabled, the value to display is modified by lut[value]. Per default the lut is a 1:1 relation.

name: {str}, read-only

name of the plugin

numImages: {int}, read-only

Number of different images

x0: {int}

x0 position of display window [px]

xsize: {int}

width of window [px]

y0: {int}

y0 position of display window [px]

ysize: {int}

height of window [px]

3.9.4. Example

The following example shows how to project different vertical and horizontal sine textures as well as random maps that are either horizontally or vertically repeated or spread to the real size of the display:

import numpy as np

gl = dataIO("GLDisplay")

#4-phase shifted sine (8px width), repeated
s1 = [127*(1+np.sin(j*2*np.pi/8)) for j in range(0,8)]
s2 = [127*(1+np.sin(np.pi/4 + j*2*np.pi/8)) for j in range(0,8)]
s3 = [127*(1+np.sin(np.pi/2 + j*2*np.pi/8)) for j in range(0,8)]
s4 = [127*(1+np.sin(3*np.pi/4 + j*2*np.pi/8)) for j in range(0,8)]
sine = dataObject([4,1,8],'uint8',data=s1+s2+s3+s4)
sine.setTag("wrapT","GL_REPEAT")
sine.setTag("wrapS","GL_REPEAT")
gl.exec("addTextures",sine)

#4-phase shifted sine (8px width), scaled
sine2 = dataObject([4,8,1],'uint8',data=s1+s2+s3+s4)
sine2.setTag("wrapT","SCALED")
sine2.setTag("wrapS","SCALED")
gl.exec("addTextures",sine2)

#random value, repeated
ra = dataObject.randN([4,1024,768],'uint8')
ra.setTag("wrapT","SCALED")
ra.setTag("wrapS","SCALED")
gl.exec("addTextures",ra)

It is also possible to display coloured dataObjects (type: rgba32). If so, make sure that the gamma correction parameter is set to False. Else, the red-channel of the coloured data object is used for lookup in the gamma correction LUT:

a = dataObject([10,10],'rgba32')
a[0:3,:] = rgba(255,0,0) #first three lines are red
a[3:6,:] = rgba(0,255,0) #next three lines are green
a[6:9,:] = rgba(0,0,255) #three lines blue
a[9:10,:] = rgba(255,255,255) #...and one line in white
gl.exec("addTextures",a)

Another feature is to edit one or a sequence of texture(s). This work in the same way than adding texture, however by the function ‘editTextures’. This function requires the texture data object as first argument and the texture index that is replaced (zero-based). If the given data object is 3D and has more than one plane, the following textures are replaced as well:

gl.exec("editTextures",dataObject.randN([100,100]), firstTextureIndex=0)