wolfhece.opengl.py3d

Author: HECE - University of Liege, Pierre Archambeau Date: 2024

Copyright (c) 2024 University of Liege. All rights reserved.

This script and its content are protected by copyright law. Unauthorized copying or distribution of this file, via any medium, is strictly prohibited.

Module Contents

wolfhece.opengl.py3d.print_program_resource_names(program, verbose=False)[source]

Print the active resources in the program

class wolfhece.opengl.py3d.TypeOfView[source]

Bases: enum.Enum

Inheritance diagram of wolfhece.opengl.py3d.TypeOfView

Type of view

PERSPECTIVE = 0[source]
ORTHOGRAPHIC = 1[source]
ORTHOGRAPHIC_2D = 2[source]
class wolfhece.opengl.py3d.Cache_WolfArray_plot3D(parent: WolfArray_plot3D, context: wx.glcanvas.GLContext, canvas: CanvasOGL, idx: int = 0)[source]

Cache for the WolfArray_plot3D class

A cache is created for each canvas. The cache is responsible for the OpenGL resources associated to context.

property sunposition[source]
property sunintensity[source]
initialize_color_palette()[source]

Initialize the color palette

init_GL(quad_centers: numpy.ndarray, ztexture: numpy.ndarray)[source]
init_shader()[source]
loc_uniforms(which_prog=0)[source]

Initialize the uniforms

set_uniforms(which_prog=0)[source]

Set the uniforms

update_quads(data: numpy.ndarray)[source]

Update the buffer with new data

update_mvp(mvp: glm.mat4x4)[source]

Update the model view projection matrix

update_ztexture(ztexture: numpy.ndarray)[source]

Update the ztexture

update_palette(color_palette: numpy.ndarray, color_values: numpy.ndarray)[source]

Update the color palette

Draw()[source]
class wolfhece.opengl.py3d.WolfArray_plot3D(quad_centers: numpy.ndarray, dx: float = 1.0, dy: float = 1.0, origx: float = 0.0, origy: float = 0.0, zscale: float = 0.0, ztexture: numpy.ndarray = None, color_palette: numpy.ndarray = None, color_values: numpy.ndarray = None)[source]

Class to plot data in 3D viewer

reference for texture 2D : https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml

OPENGL

The first element corresponds to the lower left corner of the texture image. Subsequent elements progress left-to-right through the remaining texels in the lowest row of the texture image,

and then in successively higher rows of the texture image.

The final element corresponds to the upper right corner of the texture image.

void glTexImage2D( GLenum target,

GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void * data);

NUMPY

shape[0] is the number of rows and shape[1] is the number of columns.

The “data” buffer is row-major order or column-major order, depending on the value of the order parameter.
  • row-major order : C order

  • column-major order : ‘F’ order (Fortran)

So, in row-major order :
  • OpenGL Texture width = shape[1]

  • OpenGL Texture height = shape[0]

and in column-major order :
  • OpenGL Texture width = shape[0]

  • OpenGL Texture height = shape[1]

++ IMPORTANT

We assume that if data is row-major order, the indexing [i,j] is (y, x) and if data is column-major order, the indexing is (x, y)

Example :
  • array[m,n] in row-major order is the element at the coordinate (n * dx + dx/2. + origx, m * dy + dy/2. + origy)

  • array[m,n] in column-major order is the element at the coordinate (m * dx + dx/2. + origx, n * dy + dy/2. + origy)

So:
  • the data buffer is the same as it is contiguous in memory. We ** don’t need to transpose ** the data buffer.

  • Transposition is done by changing the indexing convention.

  • “texture” calls in shaders is the same for both row-major and column-major order.

– IMPORTANT

property boundingbox[source]

Return the bounding box of the quads

property cache: Cache_WolfArray_plot3D[source]
property sunposition[source]
property sunintensity[source]
remove_parent(parent: CanvasOGL)[source]

Remove the parent from the object

add_parent(parent: CanvasOGL, idx: int = 0)[source]

Add the parent to the object

update_mvp(mvp: glm.mat4x4)[source]

Update the model view projection matrix

update_ztexture(ztexture: numpy.ndarray)[source]

Update the ztexture

update_palette(color_palette: numpy.ndarray, color_values: numpy.ndarray)[source]

Update the color palette

Draw()[source]
class wolfhece.opengl.py3d.CanvasOGL(parent)[source]

Bases: wx.glcanvas.GLCanvas

Inheritance diagram of wolfhece.opengl.py3d.CanvasOGL
property sunposition[source]
property sunaltitude[source]
property sunx[source]
property suny[source]
property sunintensity[source]
property mvp[source]

Return the model view projection matrix as np.array in column major order

property moves_matrix4x4[source]

Return the list of moves as a list of glm.mat4

property mvp_glm[source]

Return the model view projection matrix as glm.mat4

property right[source]

Return the right vector of the camera

property distance[source]

Return the distance between the eye and the center of the view

property ppi[source]

Return the pixels per inch of the view

property boundingbox[source]

Return the bounding box of the view

property z_extrema[source]

Return the extrema of the ztexture

force_view(x: float, y: float, z: float)[source]

Force the view to a specific position

init_gizmo_shader()[source]
draw_gizmo()[source]
draw_plane(a, b, c, d, e, f, g, h, i, j, k, l, colr, colg, colb)[source]
add_array(name: str, array: WolfArray_plot3D)[source]

Add an array to the canvas

ray_pick(x, y)[source]

Get the ray direction from the camera to the mouse position

intersect_ray_plane(ray_direction, plane_point)[source]

Calculer l’intersection entre un rayon et un plan horizontal

intersect_ray_quad(ray_direction, quad_lowerleft, quad_upperright)[source]

Calculer l’intersection entre un rayon et un quad

update_view()[source]
_direction()[source]
_normalize(v)[source]
_cross(v1, v2)[source]
_dot(v1, v2)[source]
_rotate(angle, axis)[source]

Rotation matrix around axis by angle degrees

closer(factor=1.0)[source]

Move the camera closer to the center of the view

further_away(factor=1.0)[source]

Move the camera further away from the center of the view

rotate_up(angle)[source]

Rotate the camera up by angle degrees

rotate_z_center(angle)[source]

Rotate the camera around the z axis, passing at center, by angle degrees

rotate_x_center(angle)[source]

Rotate the camera around the x axis, passing at center, by angle degrees

rotate_y_center(angle)[source]

Rotate the camera around the y axis, passing at center, by angle degrees

add_move_rotation(angle: float, axis: glm.vec3, center: glm.vec3)[source]

Add a rotation to the list of moves

add_move_translation(translation: glm.vec3)[source]

Add a translation to the list of moves

rotate_right_eye(angle)[source]

Rotate the camera to the right by angle degrees

rotate_right_center(angle)[source]

Rotate the camera to the right by angle degrees

translate(amplitude, orient)[source]

Translate the camera by amplitude in the direction of the vector orient

OnPaint(event)[source]

Called when the window is exposed.

OnSize(event)[source]

Called when the window is resized

OnWheel(event: wx.MouseEvent)[source]

Called when the mouse wheel is scrolled.

OnLeftDown(event: wx.MouseEvent)[source]

Called when the left mouse button is pressed.

OnRightDown(event: wx.MouseEvent)[source]

Called when the right mouse button is pressed.

OnRightUp(event: wx.MouseEvent)[source]

Called when the right mouse button is released.

OnLeftUp(event: wx.MouseEvent)[source]

Called when the left mouse button is released.

OnMouseMove(event: wx.MouseEvent)[source]

Called when the mouse is in motion.

autoscale()[source]

Auto scale the view to fit all the arrays

copy_to_clipboard()[source]

Copy the image to the clipboard

save_to_file()[source]

Save the image to a file

print_shortcuts() str[source]

Print shortcuts

OnKeyDown(event)[source]

Called when a key is pressed.

OnKeyUp(event)[source]
InitGL()[source]
create_fbo()[source]

Create a framebuffer object

Draw()[source]
update_palette(idx, color_palette, color_values)[source]

Update the color palette of the array

class wolfhece.opengl.py3d.Wolf_Viewer3D(parent, title)[source]

Bases: wx.Frame

Inheritance diagram of wolfhece.opengl.py3d.Wolf_Viewer3D
property context[source]
property xmin[source]
property xmax[source]
property ymin[source]
property ymax[source]
GetSize()[source]
add_array(name: str, array: WolfArray_plot3D)[source]

Add an array to the canvas

force_view(x, y, z)[source]

Force the view to the specified coordinates

autoscale()[source]

Auto scale the view to fit all the arrays

update_palette(idx, color_palette, color_values)[source]

Update the color palette of the array

wolfhece.opengl.py3d.main_test()[source]

Test the Wolf_Viewer3D class

2 arrays can be added to the canvas. The first one is in row major order and the second one is in column major order. The plt must be the same for both arrays.