1. fieldanimation Package

fieldanimation classes:

Inheritance diagram of fieldanimation.FieldAnimation
fieldanimation.glInfo()[source]

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

Parameters:None
Returns:OpenGL information dict
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.modulus(field)[source]

Return normalized modulus of 2D field image

Returns:normalized modulus of 2D field image (i.e. scaled in [0, 1.])
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) –
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
resetRenderingTarget()[source]

Bind first (default) framebuffer and reset the viewport.

tracersCount

Return tracers count

Returns:number of tracers
_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.

drawScreen()[source]

Draw background texture and tracers on screen framebuffer texture

drawModulus(opacity)[source]

Draw the modulus texture.

Parameters:opacity (float) – opacity (alpha) of the texture: 0 –> transparent 1 –> opaque
drawImage()[source]

Draw an image texture in background.

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

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.

1.1. shader Module

shader classes:

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

Bases: object

Base shader class

__init__(path=None, **kargs)[source]
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]
_build_shader(sourceCode, shader_type)[source]

Actual building of the shader

delete()[source]

Link the program

bind()[source]

Bind the program, i.e. use it

unbind()[source]

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

setUniform(name, value)[source]
setUniforms(nameandvalue)[source]
code(shader='v', lineno=False)[source]

Return shader code.

Keyword Arguments:
 
  • shader (string) – v for vertex, f for fragment, g for geometry
  • lineno (boolean) – add line numbers to code
Returns:

shader source code

vertex_code(lineno=False)[source]

Return vertex shader code with optional line numbers

fragment_code(lineno=False)[source]

Return fragment shader code with optional line numbers

geometry_code(lineno=False)[source]

Return geometry shader code with optional line numbers

1.2. texture Module

texture classes:

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]