:py:mod:`wolfhece.opengl.py3d` ============================== .. py:module:: wolfhece.opengl.py3d .. autoapi-nested-parse:: 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 --------------- .. py:function:: print_program_resource_names(program, verbose=False) Print the active resources in the program .. py:class:: TypeOfView Bases: :py:obj:`enum.Enum` .. autoapi-inheritance-diagram:: wolfhece.opengl.py3d.TypeOfView :parts: 1 :private-bases: Type of view .. py:attribute:: PERSPECTIVE :value: 0 .. py:attribute:: ORTHOGRAPHIC :value: 1 .. py:attribute:: ORTHOGRAPHIC_2D :value: 2 .. py:class:: Cache_WolfArray_plot3D(parent: WolfArray_plot3D, context: wx.glcanvas.GLContext, canvas: CanvasOGL, idx: int = 0) Cache for the WolfArray_plot3D class A cache is created for each canvas. The cache is responsible for the OpenGL resources associated to context. .. py:property:: sunposition .. py:property:: sunintensity .. py:method:: initialize_color_palette() Initialize the color palette .. py:method:: init_GL(quad_centers: numpy.ndarray, ztexture: numpy.ndarray) .. py:method:: init_shader() .. py:method:: loc_uniforms(which_prog=0) Initialize the uniforms .. py:method:: set_uniforms(which_prog=0) Set the uniforms .. py:method:: update_quads(data: numpy.ndarray) Update the buffer with new data .. py:method:: update_mvp(mvp: glm.mat4x4) Update the model view projection matrix .. py:method:: update_ztexture(ztexture: numpy.ndarray) Update the ztexture .. py:method:: update_palette(color_palette: numpy.ndarray, color_values: numpy.ndarray) Update the color palette .. py:method:: Draw() .. py:class:: 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) 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 .. py:property:: boundingbox Return the bounding box of the quads .. py:property:: cache :type: Cache_WolfArray_plot3D .. py:property:: sunposition .. py:property:: sunintensity .. py:method:: remove_parent(parent: CanvasOGL) Remove the parent from the object .. py:method:: add_parent(parent: CanvasOGL, idx: int = 0) Add the parent to the object .. py:method:: update_mvp(mvp: glm.mat4x4) Update the model view projection matrix .. py:method:: update_ztexture(ztexture: numpy.ndarray) Update the ztexture .. py:method:: update_palette(color_palette: numpy.ndarray, color_values: numpy.ndarray) Update the color palette .. py:method:: Draw() .. py:class:: CanvasOGL(parent) Bases: :py:obj:`wx.glcanvas.GLCanvas` .. autoapi-inheritance-diagram:: wolfhece.opengl.py3d.CanvasOGL :parts: 1 :private-bases: .. py:property:: sunposition .. py:property:: sunaltitude .. py:property:: sunx .. py:property:: suny .. py:property:: sunintensity .. py:property:: mvp Return the model view projection matrix as np.array in column major order .. py:property:: moves_matrix4x4 Return the list of moves as a list of glm.mat4 .. py:property:: mvp_glm Return the model view projection matrix as glm.mat4 .. py:property:: right Return the right vector of the camera .. py:property:: distance Return the distance between the eye and the center of the view .. py:property:: ppi Return the pixels per inch of the view .. py:property:: boundingbox Return the bounding box of the view .. py:property:: z_extrema Return the extrema of the ztexture .. py:method:: force_view(x: float, y: float, z: float) Force the view to a specific position .. py:method:: init_gizmo_shader() .. py:method:: draw_gizmo() .. py:method:: draw_plane(a, b, c, d, e, f, g, h, i, j, k, l, colr, colg, colb) .. py:method:: add_array(name: str, array: WolfArray_plot3D) Add an array to the canvas .. py:method:: ray_pick(x, y) Get the ray direction from the camera to the mouse position .. py:method:: intersect_ray_plane(ray_direction, plane_point) Calculer l'intersection entre un rayon et un plan horizontal .. py:method:: intersect_ray_quad(ray_direction, quad_lowerleft, quad_upperright) Calculer l'intersection entre un rayon et un quad .. py:method:: update_view() .. py:method:: _direction() .. py:method:: _normalize(v) .. py:method:: _cross(v1, v2) .. py:method:: _dot(v1, v2) .. py:method:: _rotate(angle, axis) Rotation matrix around axis by angle degrees .. py:method:: closer(factor=1.0) Move the camera closer to the center of the view .. py:method:: further_away(factor=1.0) Move the camera further away from the center of the view .. py:method:: rotate_up(angle) Rotate the camera up by angle degrees .. py:method:: rotate_z_center(angle) Rotate the camera around the z axis, passing at center, by angle degrees .. py:method:: rotate_x_center(angle) Rotate the camera around the x axis, passing at center, by angle degrees .. py:method:: rotate_y_center(angle) Rotate the camera around the y axis, passing at center, by angle degrees .. py:method:: add_move_rotation(angle: float, axis: glm.vec3, center: glm.vec3) Add a rotation to the list of moves .. py:method:: add_move_translation(translation: glm.vec3) Add a translation to the list of moves .. py:method:: rotate_right_eye(angle) Rotate the camera to the right by angle degrees .. py:method:: rotate_right_center(angle) Rotate the camera to the right by angle degrees .. py:method:: translate(amplitude, orient) Translate the camera by amplitude in the direction of the vector orient .. py:method:: OnPaint(event) Called when the window is exposed. .. py:method:: OnSize(event) Called when the window is resized .. py:method:: OnWheel(event: wx.MouseEvent) Called when the mouse wheel is scrolled. .. py:method:: OnLeftDown(event: wx.MouseEvent) Called when the left mouse button is pressed. .. py:method:: OnRightDown(event: wx.MouseEvent) Called when the right mouse button is pressed. .. py:method:: OnRightUp(event: wx.MouseEvent) Called when the right mouse button is released. .. py:method:: OnLeftUp(event: wx.MouseEvent) Called when the left mouse button is released. .. py:method:: OnMouseMove(event: wx.MouseEvent) Called when the mouse is in motion. .. py:method:: autoscale() Auto scale the view to fit all the arrays .. py:method:: copy_to_clipboard() Copy the image to the clipboard .. py:method:: save_to_file() Save the image to a file .. py:method:: print_shortcuts() -> str Print shortcuts .. py:method:: OnKeyDown(event) Called when a key is pressed. .. py:method:: OnKeyUp(event) .. py:method:: InitGL() .. py:method:: create_fbo() Create a framebuffer object .. py:method:: Draw() .. py:method:: update_palette(idx, color_palette, color_values) Update the color palette of the array .. py:class:: Wolf_Viewer3D(parent, title) Bases: :py:obj:`wx.Frame` .. autoapi-inheritance-diagram:: wolfhece.opengl.py3d.Wolf_Viewer3D :parts: 1 :private-bases: .. py:property:: context .. py:property:: xmin .. py:property:: xmax .. py:property:: ymin .. py:property:: ymax .. py:method:: GetSize() .. py:method:: add_array(name: str, array: WolfArray_plot3D) Add an array to the canvas .. py:method:: force_view(x, y, z=-1) Force the view to the specified coordinates. if z == -1, the z value is the same as the current z value. .. py:method:: autoscale() Auto scale the view to fit all the arrays .. py:method:: update_palette(idx, color_palette, color_values) Update the color palette of the array .. py:function:: main_test() 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.