fieldanimation package reference

Inheritance diagram of fieldanimation.FieldAnimation
class fieldanimation.FieldAnimation(width, height, field, computeSahder=False, image=None)[source]

Bases: object

Field Animation with OpenGL

  1. draw the modulus of the vector field or a user defined image

    if requested;

  2. set a framebuffer texture (screen texture) as the main
    rendering target:
    1. draw the background texture on the screen texture with a fixed opacity;

    2. decode the particles positions from the currentTracersPosition texture and draw them on the screen texture;

  3. set the rendering target to the active window;

  4. draw screen texture on the active window;

  5. swap screen texture and background texture;

  6. calculate the new particles positions

    (in the update shader) and encode them in the nextTracersPosition texture;

  7. swap nextTracersPosition texture and

    currentTracersPosition texture;

__init__(width, height, field, computeSahder=False, image=None)[source]

Animate 2D vector field

Parameters
  • width (int) – width in pixels

  • height (int) – height in pixels

  • field (np.ndarray) – 2D vector field

  • = True selects the compute shader version (cs) –

  • = Optional background image (image) –

_initTracers()[source]

Initialize the tracers positions

draw()[source]

Render the OpenGL scene. This method is called automatically when the scene has to be rendered and is responsible for the animation.

drawImage()[source]

Draw an image texture in background.

drawModulus(opacity)[source]

Draw the modulus texture.

Parameters

opacity (float) – opacity (alpha) of the texture: 0 –> transparent 1 –> opaque

drawScreen()[source]

Draw background texture and tracers on screen framebuffer texture

drawTexture(texture, opacity)[source]

Draw texture on the screen.

Parameters
  • ( (texture) – class:Texture): texture instance

  • opacity (float) – opacity (alpha) of the texture 0 –> transparent 1 –> opaque

drawTracers()[source]

Draw the tracers on the screen

resetRenderingTarget()[source]

Bind first (default) framebuffer and reset the viewport.

setField(field)[source]

Set the 2D vector field. Must be called every time a new vetor field is selected.

Parameters

field (np.ndarray) – 2D vector field

setRenderingTarget(texture)[source]

Set texture as rendering target

Parameters

(class (texture) – texture instance): 2D vector field

setSize(width, height)[source]

Set instance size. Must be called when the window is resized.

Parameters
  • width (int) – window width in pixels

  • height (int) – window height in pixels

property tracersCount

Return tracers count

Returns

number of tracers

updateTracers()[source]

Update tracers position using the fragment shader provided by the graphic card for computing.

updateTracersCS()[source]

Update tracers position using the compute shader provided by the graphic card for computing.

fieldanimation.field2RGB(field)[source]

Return 2D field converted to uint8 RGB image (i.e. scaled in [0, 255])

Parameters

field (numpy.ndarray) – (u, v) 2D vector field instance

Returns

( rgb (numpy.ndarray): uint8 RGB image, uMin (float): u min, uMax (float): u max, vMin (float): v min, vMax (float): v max, ) (tuple): Return value

fieldanimation.glInfo()[source]

Return OpenGL information dict WARNING: OpenGL context MUST be initialized !!!

Parameters

None

Returns

OpenGL information dict

fieldanimation.modulus(field)[source]

Return normalized modulus of 2D field image

Returns

normalized modulus of 2D field image (i.e. scaled in [0, 1.])

fieldanimation.shader

Inheritance diagram of fieldanimation.shader.Shader
class fieldanimation.shader.Shader(path=None, **kargs)[source]

Bases: object

Base shader class

__init__(path=None, **kargs)[source]

Initialize self. See help(type(self)) for accurate signature.

_build_shader(sourceCode, shader_type)[source]

Actual building of the shader

Link the program

addUniform(uniform, utype=None)[source]

Add a uniform variable to the shader. If utype is not none it defines the setter function. Valid utypes are i, b, f, 2f, 4fv

addUniforms(uniformlist)[source]
bind()[source]

Bind the program, i.e. use it

delete()[source]
setUniform(name, value)[source]
setUniforms(nameandvalue)[source]
unbind()[source]

Unbind whatever program is currently bound - not necessarily this program, so this should probably be a class method instead.

fieldanimation.texture Module

Inheritance diagram of fieldanimation.texture.Texture
class fieldanimation.texture.Texture(data=None, width=None, height=None, filt=GL_NEAREST, dtype=GL_UNSIGNED_BYTE)[source]

Bases: object

__init__(data=None, width=None, height=None, filt=GL_NEAREST, dtype=GL_UNSIGNED_BYTE)[source]

Texture object. If data is None an empty texture will be created

bind(texUnit=0)[source]
handle()[source]
unbind()[source]