yt.visualization.volume_rendering.interactive_vr module

Interactive Data Visualization classes for Scene, Camera and BlockCollection

class yt.visualization.volume_rendering.interactive_vr.BlockCollection(scale=False)[source]

Bases: yt.visualization.volume_rendering.interactive_vr.SceneComponent

add_data(data_source, field, log_field=True)[source]

Adds a source of data for the block collection.

Given a data_source and a field to populate from, adds the data to the block collection so that is able to be rendered.

Parameters:
  • data_source (YTRegion) – A YTRegion object to use as a data source.
  • field (string) – A field to populate from.
  • log_field (boolean, optional) – If set to True log10 will be applied to data before passing it to GPU.
add_vert_attrib(name, arr, each)
draw()[source]

Runs a given shader program on the block collection. It is assumed that the GL Context has been set up, which is typically handled by the run_program method.

fragment_shader = None
name = 'block_collection'
program
run_program()
set_camera(camera)[source]

Sets the camera for the block collection.

Parameters:camera (IDVCamera) – A simple camera object.
set_fields_log(log_field)[source]

Switch between a logarithmic and a linear scale for the data.

Parameters:log_field (boolean) – If set to True log10 will be applied to data before passing it to GPU.
set_shader(name)

Compiles and links a fragment shader from a set of known shaders.

Parameters:name (String) – The name of the fragment shader to use.
vertex_shader = None
class yt.visualization.volume_rendering.interactive_vr.ColorBarSceneComponent[source]

Bases: yt.visualization.volume_rendering.interactive_vr.SceneComponent

A class for scene components that apply colorbars using a 1D texture.

add_vert_attrib(name, arr, each)
fragment_shader = None
name = None
program
run_program()
set_camera(camera)[source]
set_shader(name)

Compiles and links a fragment shader from a set of known shaders.

Parameters:name (String) – The name of the fragment shader to use.
setup_cmap_tex()[source]

Creates 1D texture that will hold colormap in framebuffer

update_cmap_tex()[source]

Updates 1D texture with colormap that’s used in framebuffer

update_minmax()[source]
vertex_shader = None
class yt.visualization.volume_rendering.interactive_vr.IDVCamera(position=(0.0, 0.0, 1.0), focus=(0.0, 0.0, 0.0), up=(0.0, 1.0, 0.0), fov=45.0, near_plane=0.01, far_plane=20.0, aspect_ratio=1.3333333333333333)[source]

Bases: object

Camera object used in the Interactive Data Visualization

Parameters:
  • position (iterable, or 3 element array in code_length) – The initial position of the camera.
  • focus (iterable, or 3 element array in code_length) – A point in space that the camera is looking at.
  • up (iterable, or 3 element array in code_length) – The ‘up’ direction for the camera.
  • fov (float, optional) – An angle defining field of view in degrees.
  • near_plane (float, optional) – The distance to the near plane of the perspective camera.
  • far_plane (float, optional) – The distance to the far plane of the perspective camera.
  • aspect_ratio (float, optional) – The ratio between the height and the width of the camera’s fov.
compute_matrices()[source]

Regenerate all position, view and projection matrices of the camera.

get_projection_matrix()[source]
get_view_matrix()[source]
get_viewpoint()[source]
update_cmap_minmax(minval, maxval, iflog)[source]

Update camera’s colormap bounds

Parameters:
  • minval (float) – min color limit used for image scaling
  • maxval (float) – max color limit used for image scaling
  • iflog (boolean) – Set to True if colormap is using log scale, False for linear scale.
update_orientation(start_x, start_y, end_x, end_y)[source]

Change camera orientation matrix using delta of mouse’s cursor position

Parameters:
  • start_x (float) – initial cursor position in x direction
  • start_y (float) – initial cursor position in y direction
  • end_x (float) – final cursor position in x direction
  • end_y (float) – final cursor position in y direction
class yt.visualization.volume_rendering.interactive_vr.MeshSceneComponent(data_source, field)[source]

Bases: yt.visualization.volume_rendering.interactive_vr.ColorBarSceneComponent

A scene component for representing unstructured mesh data.

add_vert_attrib(name, arr, each)
fragment_shader = None
get_mesh_data(data_source, field)[source]

This reads the mesh data into a form that can be fed in to OpenGL.

name = None
program
render()

Renders one frame of the scene.

run_program()[source]

Renders one frame of the scene.

set_camera(camera)[source]

Sets the camera orientation for the entire scene.

Parameters:camera (IDVCamera) –
set_shader(name)

Compiles and links a fragment shader from a set of known shaders.

Parameters:name (String) – The name of the fragment shader to use.
setup_cmap_tex()

Creates 1D texture that will hold colormap in framebuffer

update_cmap_tex()

Updates 1D texture with colormap that’s used in framebuffer

update_minmax()
vertex_shader = None
class yt.visualization.volume_rendering.interactive_vr.SceneComponent[source]

Bases: object

A class that defines basic OpenGL object

This class contains the largest common set of features that every object in the OpenGL rendering uses: a set of vertices, a set of vertex attributes and a shader program to operate on them.

add_vert_attrib(name, arr, each)[source]
fragment_shader = None
name = None
program
run_program()[source]
set_shader(name)[source]

Compiles and links a fragment shader from a set of known shaders.

Parameters:name (String) – The name of the fragment shader to use.
vertex_shader = None
class yt.visualization.volume_rendering.interactive_vr.SceneGraph[source]

Bases: yt.visualization.volume_rendering.interactive_vr.ColorBarSceneComponent

A basic OpenGL render for IDV.

The SceneGraph class is the primary driver behind creating a IDV rendering. It is responsible for performing two pass volume rendering: firstly ray casting through the BlockCollection into 2D Texture that is stored into a framebuffer, secondly performing a fragment shader based modification of the 2D texture from the first pass before showing it in the interactive window.

Parameters:None
add_collection(collection)[source]

Adds a block collection to the scene. Collections must not overlap.

Although it hasn’t been tested, this should allow one to add multiple datasets to a single scene.

Parameters:collection (BlockCollection) – A block collection object representing a data-set. Behavior is undefined if any collection overlaps with another.
add_vert_attrib(name, arr, each)
fragment_shader = None
name = None
program
render()

Renders one frame of the scene.

Renders the scene using the current collection and camera set by calls to add_collection and set_camera respectively. Also uses the last shader provided to the add_shader_from_file function.

run_program()[source]

Renders one frame of the scene.

Renders the scene using the current collection and camera set by calls to add_collection and set_camera respectively. Also uses the last shader provided to the add_shader_from_file function.

set_camera(camera)[source]

Sets the camera orientation for the entire scene.

Upon calling this function a kd-tree is constructed for each collection. This function simply calls the BlockCollection set_camera function on each collection in the scene.

Parameters:camera (IDVCamera) –
set_shader(name)

Compiles and links a fragment shader from a set of known shaders.

Parameters:name (String) – The name of the fragment shader to use.
setup_cmap_tex()

Creates 1D texture that will hold colormap in framebuffer

setup_fb(width, height)[source]

Sets up FrameBuffer that will be used as container for 1 pass of rendering

update_cmap_tex()

Updates 1D texture with colormap that’s used in framebuffer

update_minmax()[source]
vertex_shader = None
class yt.visualization.volume_rendering.interactive_vr.TrackballCamera(position=(0.0, 0.0, 1.0), focus=(0.0, 0.0, 0.0), up=(0.0, 1.0, 0.0), fov=45.0, near_plane=0.01, far_plane=20.0, aspect_ratio=1.3333333333333333)[source]

Bases: yt.visualization.volume_rendering.interactive_vr.IDVCamera

This class implements a basic “Trackball” or “Arcball” camera control system that allows for unconstrained 3D rotations without suffering from Gimbal lock. Following Ken Shoemake’s original C implementation (Graphics Gems IV, III.1) we project mouse movements onto the unit sphere and use quaternions to represent the corresponding rotation.

See also: https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Arcball

compute_matrices()[source]
get_projection_matrix()
get_view_matrix()
get_viewpoint()
update_cmap_minmax(minval, maxval, iflog)

Update camera’s colormap bounds

Parameters:
  • minval (float) – min color limit used for image scaling
  • maxval (float) – max color limit used for image scaling
  • iflog (boolean) – Set to True if colormap is using log scale, False for linear scale.
update_orientation(start_x, start_y, end_x, end_y)[source]