scene
¶
This module provides a 3D graphics scene graph structure.
axes
: Bounding Box with axes ticks and labels¶
Primitive displaying a text field in the scene.
-
class
silx.gui.plot3d.scene.axes.
LabelledAxes
[source]¶ A group displaying a bounding box with axes labels around its children.
-
tickColor
¶ Color of ticks and text labels.
This does NOT set bounding box color. Use
color
for the bounding box.
-
font
¶ Font of axes text labels (Font)
-
xlabel
¶ Text label of the X axis (str)
-
ylabel
¶ Text label of the Y axis (str)
-
zlabel
¶ Text label of the Z axis (str)
-
boxVisible
¶ Returns bounding box, axes labels and grid visibility.
-
camera
: Projection management classes¶
This module provides classes to handle a perspective projection in 3D.
-
class
silx.gui.plot3d.scene.camera.
CameraExtrinsic
(position=(0.0, 0.0, 0.0), direction=(0.0, 0.0, -1.0), up=(0.0, 1.0, 0.0))[source]¶ Transform matrix to handle camera position and orientation.
Parameters: - position (numpy.ndarray-like of 3 float32.) – Coordinates of the point of view.
- direction (numpy.ndarray-like of 3 float32.) – Sight direction vector.
- up (numpy.ndarray-like of 3 float32.) – Vector pointing upward in the image plane.
-
setOrientation
(direction=None, up=None)[source]¶ Set the rotation of the point of view.
Parameters: - direction (numpy.ndarray-like of 3 float32 or None.) – Sight direction vector or None to keep the current one.
- up (numpy.ndarray-like of 3 float32 or None.) – Vector pointing upward in the image plane or None to keep the current one.
Raises: RuntimeError – if the direction and up are parallel.
-
position
¶ Coordinates of the point of view as a numpy.ndarray of 3 float32.
-
direction
¶ Sight direction (ndarray of 3 float32).
-
up
¶ Vector pointing upward in the image plane (ndarray of 3 float32).
-
side
¶ Vector pointing towards the side of the image plane.
ndarray of 3 float32
-
move
(direction, step=1.0)[source]¶ Move the camera relative to the image plane.
Parameters: - direction (str) – Direction relative to image plane. One of: ‘up’, ‘down’, ‘left’, ‘right’, ‘forward’, ‘backward’.
- step (float) – The step of the pan to perform in the coordinate in which the camera position is defined.
-
rotate
(direction, angle=1.0)[source]¶ First-person rotation of the camera towards the direction.
Parameters: - direction (str) – Direction of movement relative to image plane. In: ‘up’, ‘down’, ‘left’, ‘right’.
- angle (float) – The angle in degrees of the rotation.
-
orbit
(direction, center=(0.0, 0.0, 0.0), angle=1.0)[source]¶ Rotate the camera around a point.
Parameters: - direction (str) – Direction of movement relative to image plane. In: ‘up’, ‘down’, ‘left’, ‘right’.
- center (numpy.ndarray-like of 3 float32.) – Position around which to rotate the point of view.
- angle (float) – he angle in degrees of the rotation.
-
class
silx.gui.plot3d.scene.camera.
Camera
(fovy=30.0, near=0.1, far=1.0, size=(1.0, 1.0), position=(0.0, 0.0, 0.0), direction=(0.0, 0.0, -1.0), up=(0.0, 1.0, 0.0))[source]¶ Combination of camera projection and position.
See
Perspective
andCameraExtrinsic
.Parameters: - fovy (float) – Vertical field-of-view in degrees.
- near (float) – The near clipping plane Z coord (strictly positive).
- far (float) – The far clipping plane Z coord (> near).
- size (2-tuple of float (width, height).) – Viewport’s size used to compute the aspect ratio.
- position (numpy.ndarray-like of 3 float32.) – Coordinates of the point of view.
- direction (numpy.ndarray-like of 3 float32.) – Sight direction vector.
- up (numpy.ndarray-like of 3 float32.) – Vector pointing upward in the image plane.
-
resetCamera
(bounds)[source]¶ Change camera to have the bounds in the viewing frustum.
It updates the camera position and depth extent. Camera sight direction and up are not affected.
Parameters: bounds (numpy.ndarray: ((xMin, yMin, zMin), (xMax, yMax, zMax))) – The axes-aligned bounds to include.
-
intrinsic
¶ Intrinsic camera parameters, i.e., projection matrix.
-
extrinsic
¶ Extrinsic camera parameters, i.e., position and orientation.
core
: Base class of the scene nodes¶
This module provides the base scene structure.
This module provides the classes for describing a tree structure with
rendering and picking API.
All nodes inherit from Base
.
Nodes with children are provided with PrivateGroup
and
Group
classes.
Leaf rendering nodes should inherit from Elem
.
-
class
silx.gui.plot3d.scene.core.
Base
[source]¶ A scene node with common features.
-
visible
¶ Visibility flag of the node
-
pickable
¶ True to make node pickable
-
parent
¶ Parent or None if no parent
-
path
¶ Tuple of scene nodes, from the tip of the tree down to this node.
If this tree is attached to a
Viewport
, then theViewport
is the first element of path.
-
viewport
¶ The viewport this node is attached to or None.
-
objectToNDCTransform
¶ Transform from object to normalized device coordinates.
Do not forget perspective divide.
-
objectToSceneTransform
¶ Transform from object to scene.
Combine transforms up to the Viewport (not including it).
-
transforms
¶ List of transforms defining the frame of this node relative to its parent.
-
bounds
(transformed=False, dataBounds=False)[source]¶ Returns the bounds of this node aligned with the axis, with or without transform applied.
Parameters: - transformed (bool) – False to give bounds in object coordinates (the default), True to apply this object’s transforms.
- dataBounds (bool) – False to give bounds of vertices (the default), True to give bounds of the represented data.
Returns: The bounds: ((xMin, yMin, zMin), (xMax, yMax, zMax)) or None if no bounds.
Return type: numpy.ndarray of float
-
prepareGL2
(ctx)[source]¶ Called before the rendering to prepare OpenGL resources.
Override in subclass.
-
cutplane
: Cutting plane primitive¶
A cut plane in a 3D texture: hackish implementation...
-
class
silx.gui.plot3d.scene.cutplane.
ColormapMesh3D
(position, normal, data, copy=True, mode=u'triangles', indices=None, colormap=None)[source]¶ A 3D mesh with color from a 3D texture.
-
interpolation
¶ The texture interpolation mode: ‘linear’ or ‘nearest’
-
alpha
¶ Transparency of the plane, float in [0, 1]
-
colormap
¶ The colormap used by this primitive
-
event
: Scene event system¶
This module provides a simple generic notification system.
-
class
silx.gui.plot3d.scene.event.
Notifier
[source]¶ Base class for object with notification mechanism.
-
addListener
(listener)[source]¶ Register a listener.
Adding an already registered listener has no effect.
Parameters: listener (callable) – The function or method to register.
-
-
silx.gui.plot3d.scene.event.
notifyProperty
(attrName, copy=False, converter=None, doc=None)[source]¶ Create a property that adds notification to an attribute.
Parameters: - attrName (str) – The name of the attribute to wrap.
- copy (bool) – Whether to return a copy of the attribute or not (the default).
- converter – Function converting input value to appropriate type This function takes a single argument and return the converted value. It can be used to perform some asserts.
- doc (str) – The docstring of the property
Returns: A property with getter and setter
function
: OpenGL shader functions¶
This module provides functions to add to shaders.
-
class
silx.gui.plot3d.scene.function.
ProgramFunction
[source]¶ Class providing a function to add to a GLProgram shaders.
-
setupProgram
(context, program)[source]¶ Sets-up uniforms of a program using this shader function.
Parameters: - context (RenderContext) – The current rendering context
- program (GLProgram) – The program to set-up. It MUST be in use and using this function.
-
-
class
silx.gui.plot3d.scene.function.
ClippingPlane
(point=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 0.0))[source]¶ Description of a clipping plane and rendering.
Convention: Clipping is performed in camera/eye space.
Parameters: - point (numpy.ndarray-like of 3 float32) – Local coordinates of a point on the plane.
- normal (numpy.ndarray-like of 3 float32) – Local coordinates of the plane normal.
-
plane
¶ Plane parameters in camera space.
-
setupProgram
(context, program)[source]¶ Sets-up uniforms of a program using this shader function.
Parameters: - context (RenderContext) – The current rendering context
- program (GLProgram) – The program to set-up. It MUST be in use and using this function.
-
class
silx.gui.plot3d.scene.function.
DirectionalLight
(direction=None, ambient=(1.0, 1.0, 1.0), diffuse=(0.0, 0.0, 0.0), specular=(1.0, 1.0, 1.0), shininess=0)[source]¶ Description of a directional Phong light.
Parameters: - direction (ndarray of 3 floats or None) – The direction of the light or None to disable light
- ambient (ndarray of 3 floats in [0, 1], default: (1., 1., 1.)) – RGB ambient light
- diffuse (ndarray of 3 floats in [0, 1], default: (0., 0., 0.)) – RGB diffuse light parameter
- specular (ndarray of 3 floats in [0, 1], default: (1., 1., 1.)) – RGB specular light parameter
- shininess (int) – The shininess of the material for specular term, default: 0 which disables specular component.
-
isOn
¶ True if light is on, False otherwise.
-
turnOff
(*args, **kwds)[source]¶ Context manager to temporary turn off lighting during rendering.
>>> with light.turnOff(): ... # Do some rendering without lighting
-
direction
¶ The direction of the light, or None if light is not on.
-
fragmentDef
¶ Definition to add to fragment shader
-
fragmentCall
¶ Function name to call in fragment shader
-
setupProgram
(context, program)[source]¶ Sets-up uniforms of a program using this shader function.
Parameters: - context (RenderContext) – The current rendering context
- program (GLProgram) – The program to set-up. It MUST be in use and using this function.
interaction
: User interaction implementation¶
This module provides interaction to plug on the scene graph.
-
class
silx.gui.plot3d.scene.interaction.
ClickOrDrag
(button='left')[source]¶ Click or drag interaction for a given button.
-
class
silx.gui.plot3d.scene.interaction.
CameraRotate
(viewport, orbitAroundCenter=True, button='right')[source]¶ Camera rotation using an arcball-like interaction.
-
class
silx.gui.plot3d.scene.interaction.
CameraSelectPan
(viewport, button='left', selectCB=None)[source]¶ Picking on click and pan camera on drag.
-
class
silx.gui.plot3d.scene.interaction.
CameraWheel
(viewport, mode='center', scaleTransform=None)[source]¶ StateMachine like class, just handling wheel events.
-
class
silx.gui.plot3d.scene.interaction.
FocusManager
(eventHandlers=())[source]¶ Manages focus across multiple event handlers
On press an event handler can acquire focus. By default it looses focus when all buttons are released.
-
class
silx.gui.plot3d.scene.interaction.
RotateCameraControl
(viewport, orbitAroundCenter=False, mode='center', scaleTransform=None)[source]¶ Combine wheel and rotate state machine.
-
class
silx.gui.plot3d.scene.interaction.
PanCameraControl
(viewport, mode='center', scaleTransform=None, selectCB=None)[source]¶ Combine wheel, selectPan and rotate state machine.
-
class
silx.gui.plot3d.scene.interaction.
CameraControl
(viewport, orbitAroundCenter=False, mode='center', scaleTransform=None, selectCB=None)[source]¶ Combine wheel, selectPan and rotate state machine.
-
class
silx.gui.plot3d.scene.interaction.
PlaneRotate
(viewport, plane, button='right')[source]¶ Plane rotation using arcball interaction.
Arcball ref.: Ken Shoemake. ARCBALL: A user interface for specifying three-dimensional orientation using a mouse. In Proc. GI ‘92. (1992). pp. 151-156.
-
class
silx.gui.plot3d.scene.interaction.
PlanePan
(viewport, plane, button='left')[source]¶ Pan a plane along its normal on drag.
-
class
silx.gui.plot3d.scene.interaction.
PlaneControl
(viewport, plane, mode='center', scaleTransform=None)[source]¶ Combine wheel, selectPan and rotate state machine for plane control.
primitives
: Base rendering primitives¶
-
class
silx.gui.plot3d.scene.primitives.
Geometry
(mode, indices=None, copy=True, **attributes)[source]¶ Set of vertices with normals and colors.
Parameters: - mode (str) – OpenGL drawing mode: lines, line_strip, loop, triangles, triangle_strip, fan
- indices – Array of vertex indices or None
- copy (bool) – True (default) to copy the data, False to use as is.
- attributes – Provide list of attributes as extra parameters.
-
nbVertices
¶ Returns the number of vertices of current attributes.
It returns None if there is no attributes.
-
setAttribute
(name, array, copy=True)[source]¶ Set attribute with provided array.
Parameters: - name (str) – The name of the attribute
- array – Array-like attribute data or None to remove attribute
- copy (bool) – True (default) to copy the data, False to use as is
-
getAttribute
(name, copy=True)[source]¶ Returns the numpy.ndarray corresponding to the name attribute.
Parameters: - name (str) – The name of the attribute to get.
- copy (bool) – True to get a copy (default), False to get internal array (DO NOT MODIFY)
Returns: The corresponding array or None if no corresponding attribute.
Return type: numpy.ndarray
-
useAttribute
(program, name=None)[source]¶ Enable and bind attribute(s) for a specific program.
This MUST be called with OpenGL context active and after prepareGL2 has been called.
Parameters: - program (GLProgram) – The program for which to set the attributes
- name (str) – The attribute name to set or None to set then all
-
class
silx.gui.plot3d.scene.primitives.
Lines
(positions, normals=None, colors=(1.0, 1.0, 1.0, 1.0), indices=None, mode=u'lines', width=1.0)[source]¶ A set of segments
-
width
¶ Width of the line in pixels.
-
smooth
¶ Smooth line rendering enabled (bool, default: True)
-
-
class
silx.gui.plot3d.scene.primitives.
DashedLines
(positions, colors=(1.0, 1.0, 1.0, 1.0), indices=None, width=1.0)[source]¶ Set of dashed lines
This MUST be defined as a set of lines (no strip or loop).
-
dash
¶ Dash of the line as a 2-tuple of lengths in pixels: (on, off)
-
-
class
silx.gui.plot3d.scene.primitives.
Box
(size=(1.0, 1.0, 1.0), stroke=(1.0, 1.0, 1.0, 1.0), fill=(1.0, 1.0, 1.0, 0.0))[source]¶ Rectangular box
-
size
¶ Size of the box (sx, sy, sz)
-
strokeSmooth
¶ True to draw smooth stroke, False otherwise
-
strokeWidth
¶ Width of the stroke (float)
-
strokeColor
¶ RGBA color of the box lines (4-tuple of float in [0, 1])
-
fillColor
¶ RGBA color of the box faces (4-tuple of float in [0, 1])
-
-
class
silx.gui.plot3d.scene.primitives.
BoxWithAxes
(color=(1.0, 1.0, 1.0, 1.0))[source]¶ Rectangular box with RGB OX, OY, OZ axes
Parameters: color – RGBA color of the box -
color
¶ The RGBA color to use for the box: 4 float in [0, 1]
-
-
class
silx.gui.plot3d.scene.primitives.
PlaneInGroup
(point=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0))[source]¶ A plane using its parent bounds to display a contour.
If plane is outside the bounds of its parent, it is not visible.
Cannot set the transform attribute of this primitive. This primitive never has any bounds.
-
color
¶ Plane outline color (array of 4 float in [0, 1]).
-
width
¶ Width of the plane stroke in pixels
-
plane
¶ The plane parameters in the frame of the object.
-
contourVertices
¶ The vertices of the contour of the plane/bounds intersection.
-
center
¶ The center of the plane/bounds intersection points.
-
isValid
¶ True if a contour is defined, False otherwise.
-
-
class
silx.gui.plot3d.scene.primitives.
Points
(vertices, values=0.0, sizes=1.0, indices=None, symbols=0.0, minValue=None, maxValue=None)[source]¶ A set of data points with an associated value and size.
-
class
silx.gui.plot3d.scene.primitives.
ColorPoints
(vertices, colors=(1.0, 1.0, 1.0, 1.0), sizes=1.0, indices=None, symbols=0.0, minValue=None, maxValue=None)[source]¶ A set of points with an associated color and size.
-
class
silx.gui.plot3d.scene.primitives.
GridPoints
(values=0.0, shape=None, sizes=1.0, indices=None, minValue=None, maxValue=None)[source]¶ Data points on a regular grid with an associated value and size.
-
class
silx.gui.plot3d.scene.primitives.
Spheres
(positions, radius=1.0, colors=(1.0, 1.0, 1.0, 1.0))[source]¶ A set of spheres.
Spheres are rendered as circles using points. This brings some limitations: - Do not support non-uniform scaling. - Assume the projection keeps ratio. - Do not render distorion by perspective projection. - If the sphere center is clipped, the whole sphere is not displayed.
-
class
silx.gui.plot3d.scene.primitives.
Mesh3D
(positions, colors, normals=None, mode=u'triangles', indices=None)[source]¶ A conventional 3D mesh
-
culling
¶ Face culling (str)
One of ‘back’, ‘front’ or None.
-
-
class
silx.gui.plot3d.scene.primitives.
GroupDepthOffset
(children=(), epsilon=None)[source]¶ A group using 2-pass rendering and glDepthRange to avoid Z-fighting
text
: Text field rendering primitives¶
Primitive displaying a text field in the scene.
-
class
silx.gui.plot3d.scene.text.
Font
(name=None, size=-1, weight=-1, italic=False)[source]¶ Description of a font.
Parameters: - name (str) – Family of the font
- size (int) – Size of the font in points
- weight (int) – Font weight
- italic (bool) – True for italic font, False (default) otherwise
-
name
¶ Name of the font (str)
-
size
¶ Font size in points (int)
-
weight
¶ Font size in points (int)
-
italic
¶ True for italic (bool)
-
class
silx.gui.plot3d.scene.text.
Text2D
(text=u'', font=None)[source]¶ Text field as a 2D texture displayed with bill-boarding
Parameters: - text (str) – Text to display
- font (Font) – The font to use
-
text
¶ Text displayed by this primitive (str)
-
font
¶ Font to use to raster text (Font)
-
foreground
¶ RGBA color of the text: 4 float in [0, 1]
-
background
¶ RGBA background color of the text field: 4 float in [0, 1]
-
overlay
¶ True to always display text on top of the scene (default: False)
-
align
¶ Horizontal anchor position of the text field (str).
Either ‘left’ (default), ‘center’ or ‘right’.
-
valign
¶ Vertical anchor position of the text field (str).
Either ‘top’, ‘baseline’ (default), ‘center’ or ‘bottom’
transform
: Transformation matrix system¶
This module provides 4x4 matrix operation and classes to handle them.
-
silx.gui.plot3d.scene.transform.
mat4LookAtDir
(position, direction, up)[source]¶ Creates matrix to look in direction from position.
Parameters: - position – Array-like 3 coordinates of the point of view position.
- direction – Array-like 3 coordinates of the sight direction vector.
- up – Array-like 3 coordinates of the upward direction in the image plane.
Returns: Corresponding matrix.
Return type: numpy.ndarray of shape (4, 4)
-
silx.gui.plot3d.scene.transform.
mat4LookAt
(position, center, up)[source]¶ Creates matrix to look at center from position.
See gluLookAt.
Parameters: - position – Array-like 3 coordinates of the point of view position.
- center – Array-like 3 coordinates of the center of the scene.
- up – Array-like 3 coordinates of the upward direction in the image plane.
Returns: Corresponding matrix.
Return type: numpy.ndarray of shape (4, 4)
-
silx.gui.plot3d.scene.transform.
mat4Frustum
(left, right, bottom, top, near, far)[source]¶ Creates a frustum projection matrix.
See glFrustum.
-
silx.gui.plot3d.scene.transform.
mat4Perspective
(fovy, width, height, near, far)[source]¶ Creates a perspective projection matrix.
Similar to gluPerspective.
Parameters: - fovy (float) – Field of view angle in degrees in the y direction.
- width (float) – Width of the viewport.
- height (float) – Height of the viewport.
- near (float) – Distance to the near plane (strictly positive).
- far (float) – Distance to the far plane (strictly positive).
Returns: Corresponding matrix.
Return type: numpy.ndarray of shape (4, 4)
-
silx.gui.plot3d.scene.transform.
mat4Orthographic
(left, right, bottom, top, near, far)[source]¶ Creates an orthographic (i.e., parallel) projection matrix.
See glOrtho.
-
silx.gui.plot3d.scene.transform.
mat4RotateFromAngleAxis
(angle, x=0.0, y=0.0, z=1.0)[source]¶ 4x4 rotation matrix from angle and axis.
Parameters: - angle (float) – The rotation angle in radians.
- x (float) – The rotation vector x coordinate.
- y (float) – The rotation vector y coordinate.
- z (float) – The rotation vector z coordinate.
-
silx.gui.plot3d.scene.transform.
mat4RotateFromQuaternion
(quaternion)[source]¶ 4x4 rotation matrix from quaternion.
Parameters: quaternion – Array-like unit quaternion stored as (x, y, z, w)
-
silx.gui.plot3d.scene.transform.
mat4Shear
(axis, sx=0.0, sy=0.0, sz=0.0)[source]¶ 4x4 shear matrix: Skew two axes relative to a third fixed one.
shearFactor = tan(shearAngle)
Parameters: - axis (str) – The axis to keep constant and shear against. In ‘x’, ‘y’, ‘z’.
- sx (float) – The shear factor for the X axis relative to axis.
- sy (float) – The shear factor for the Y axis relative to axis.
- sz (float) – The shear factor for the Z axis relative to axis.
-
class
silx.gui.plot3d.scene.transform.
Inverse
(transform)[source]¶ Transform which is the inverse of another one.
Static: It never gets updated.
-
class
silx.gui.plot3d.scene.transform.
StaticTransformList
(iterable=())[source]¶ Transform that is a snapshot of a list of Transforms
It does not keep reference to the list of Transforms.
Parameters: iterable – Iterable of Transform used for initialization
-
class
silx.gui.plot3d.scene.transform.
Translate
(tx=0.0, ty=0.0, tz=0.0)[source]¶ 4x4 translation matrix.
-
class
silx.gui.plot3d.scene.transform.
Orthographic
(left=0.0, right=1.0, bottom=1.0, top=0.0, near=-1.0, far=1.0, size=(1.0, 1.0))[source]¶ Orthographic (i.e., parallel) projection which keeps aspect ratio.
Clipping planes are adjusted to match the aspect ratio of the
size
attribute.The left, right, bottom and top parameters defines the area which must always remain visible. Effective clipping planes are adjusted to keep the aspect ratio.
Parameters: - left (float) – Coord of the left clipping plane.
- right (float) – Coord of the right clipping plane.
- bottom (float) – Coord of the bottom clipping plane.
- top (float) – Coord of the top clipping plane.
- near (float) – Distance to the near plane.
- far (float) – Distance to the far plane.
- size (2-tuple of float (width, height).) – Viewport’s size used to compute the aspect ratio.
-
setClipping
(left=None, right=None, bottom=None, top=None)[source]¶ Set the clipping planes of the projection.
Parameters are adjusted to keep aspect ratio. If a clipping plane coord is not provided, it uses its current value
Parameters: - left (float) – Coord of the left clipping plane.
- right (float) – Coord of the right clipping plane.
- bottom (float) – Coord of the bottom clipping plane.
- top (float) – Coord of the top clipping plane.
-
left
¶ Coord of the left clipping plane.
-
right
¶ Coord of the right clipping plane.
-
bottom
¶ Coord of the bottom clipping plane.
-
top
¶ Coord of the top clipping plane.
-
size
¶ Viewport size as a 2-tuple of float (width, height) or None.
-
class
silx.gui.plot3d.scene.transform.
Ortho2DWidget
(near=-1.0, far=1.0, size=(1.0, 1.0))[source]¶ Orthographic projection with pixel as unit.
Provides same coordinates as widgets: origin: top left, X axis goes left, Y axis goes down.
Parameters: - near (float) – Z coordinate of the near clipping plane.
- far (float) – Z coordinante of the far clipping plane.
- size (2-tuple of float (width, height).) – Viewport’s size used to compute the aspect ratio.
-
class
silx.gui.plot3d.scene.transform.
Perspective
(fovy=90.0, near=0.1, far=1.0, size=(1.0, 1.0))[source]¶ Perspective projection matrix defined by FOV and aspect ratio.
Parameters: - fovy (float) – Vertical field-of-view in degrees.
- near (float) – The near clipping plane Z coord (stricly positive).
- far (float) – The far clipping plane Z coord (> near).
- size (2-tuple of float (width, height).) – Viewport’s size used to compute the aspect ratio.
-
fovy
¶ Vertical field-of-view in degrees.
utils
: Miscellaneous¶
This module provides functions to generate indices, to check intersection and to handle planes.
-
silx.gui.plot3d.scene.utils.
triangleToLineIndices
(triangleIndices, unicity=False)[source]¶ Generates lines indices from triangle indices.
This is generating lines indices for the edges of the triangles.
Parameters: - triangleIndices (numpy.ndarray) – The indices to draw a set of vertices as triangles.
- unicity (bool) – If True remove duplicated lines, else (the default) returns all lines.
Returns: The indices to draw the edges of the triangles as lines.
Return type: 1D numpy.ndarray of uint16 or uint32.
-
silx.gui.plot3d.scene.utils.
verticesNormalsToLines
(vertices, normals, scale=1.0)[source]¶ Return vertices of lines representing normals at given positions.
Parameters: - vertices (numpy.ndarray with shape: (nbPoints, 3)) – Positions of the points.
- normals (numpy.ndarray with shape: (nbPoints, 3)) – Corresponding normals at the points.
- scale (float) – The scale factor to apply to normals.
Returns: Array of vertices to draw corresponding lines.
Return type: numpy.ndarray with shape: (nbPoints * 2, 3)
-
silx.gui.plot3d.scene.utils.
unindexArrays
(mode, indices, *arrays)[source]¶ Convert indexed GL primitives to unindexed ones.
Given indices in arrays and the OpenGL primitive they represent, return the unindexed equivalent.
Parameters: - mode (str) – Kind of primitive represented by indices. In: points, lines, line_strip, loop, triangles, triangle_strip, fan.
- indices (numpy.ndarray of dimension 1.) – Indices in other arrays
- arrays – Remaining arguments are arrays to convert
Returns: Converted arrays
Return type: tuple of numpy.ndarray
-
silx.gui.plot3d.scene.utils.
trianglesNormal
(positions)[source]¶ Return normal for each triangle.
Parameters: positions (numpy.ndarray of shape (NbTriangles*3, 3)) – Serie of triangle’s corners Returns: Normals corresponding to each position. Return type: numpy.ndarray of shape (NbTriangles, 3)
-
silx.gui.plot3d.scene.utils.
gridVertices
(dim0Array, dim1Array, dtype)[source]¶ Generate an array of 2D positions from 2 arrays of 1D coordinates.
Parameters: - dim0Array – 1D array-like of coordinates along the first dimension.
- dim1Array – 1D array-like of coordinates along the second dimension.
- dtype (numpy.dtype) – Data type of the output array.
Returns: Array of grid coordinates.
Return type: numpy.ndarray with shape: (len(dim0Array), len(dim1Array), 2)
-
silx.gui.plot3d.scene.utils.
triangleStripGridIndices
(dim0, dim1)[source]¶ Generate indices to draw a grid of vertices as a triangle strip.
Vertices are expected to be stored as row-major (i.e., C contiguous).
Parameters: - dim0 (int) – The number of rows of vertices.
- dim1 (int) – The number of columns of vertices.
Returns: The vertex indices
Return type: 1D numpy.ndarray of uint32
-
silx.gui.plot3d.scene.utils.
linesGridIndices
(dim0, dim1)[source]¶ Generate indices to draw a grid of vertices as lines.
Vertices are expected to be stored as row-major (i.e., C contiguous).
Parameters: - dim0 (int) – The number of rows of vertices.
- dim1 (int) – The number of columns of vertices.
Returns: The vertex indices.
Return type: 1D numpy.ndarray of uint32
-
silx.gui.plot3d.scene.utils.
angleBetweenVectors
(refVector, vectors, norm=None)[source]¶ Return the angle between 2 vectors.
Parameters: - refVector (numpy.ndarray of shape: (NCoords,)) – Coordinates of the reference vector.
- vectors (numpy.ndarray of shape: (NCoords,) or (NbVector, NCoords)) – Coordinates of the vector(s) to get angle from reference.
- norm – A direction vector giving an orientation to the angles or None.
Returns: The angles in radians in [0, pi] if norm is None else in [0, 2pi].
Return type: float or numpy.ndarray of shape (NbVectors,)
-
silx.gui.plot3d.scene.utils.
segmentPlaneIntersect
(s0, s1, planeNorm, planePt)[source]¶ Compute the intersection of a segment with a plane.
Parameters: - s0 (1D numpy.ndarray-like of length 3) – First end of the segment
- s1 (1D numpy.ndarray-like of length 3) – Second end of the segment
- planeNorm (numpy.ndarray of shape: (3,)) – Normal vector of the plane.
- planePt (numpy.ndarray of shape: (3,)) – A point of the plane.
Returns: The intersection points. The number of points goes from 0 (no intersection) to 2 (segment in the plane)
Return type: list of numpy.ndarray
-
silx.gui.plot3d.scene.utils.
boxPlaneIntersect
(boxVertices, boxLineIndices, planeNorm, planePt)[source]¶ Return intersection points between a box and a plane.
Parameters: - boxVertices (numpy.ndarray with shape: (8, 3)) – Position of the corners of the box.
- boxLineIndices (numpy.ndarray-like with shape: (12, 2)) – Indices of the box edges.
- planeNorm (numpy.ndarray of shape: (3,)) – Normal vector of the plane.
- planePt (numpy.ndarray of shape: (3,)) – A point of the plane.
Returns: The found intersection points
Return type: numpy.ndarray with 2 dimensions
-
class
silx.gui.plot3d.scene.utils.
Plane
(point=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0))[source]¶ Object handling a plane and notifying plane changes.
Parameters: - point (3-tuple of float.) – A point on the plane.
- normal (3-tuple of float.) – Normal of the plane.
-
setPlane
(point=None, normal=None)[source]¶ Set plane point and normal and notify.
Parameters: - point (3-tuple of float or None.) – A point on the plane.
- normal (3-tuple of float or None.) – Normal of the plane.
-
point
¶ A point on the plane.
-
normal
¶ The (normalized) normal of the plane.
-
parameters
¶ Plane equation parameters: a*x + b*y + c*z + d = 0.
-
isPlane
¶ True if a plane is defined (i.e., ||normal|| != 0).
viewport
: Root of a scene tree¶
This module provides a class to control a viewport on the rendering window.
The Viewport
describes a Viewport rendering a scene.
The attribute scene
is the root group of the scene tree.
RenderContext
handles the current state during rendering.
-
class
silx.gui.plot3d.scene.viewport.
RenderContext
(viewport, glContext)[source]¶ Handle a current rendering context.
An instance of this class is passed to rendering method through the scene during render.
User should NEVER use an instance of this class beyond the method it is passed to as an argument (i.e., do not keep a reference to it).
Parameters: -
viewport
¶ Viewport doing the current rendering
-
glCtx
¶ The OpenGL context in use
-
objectToCamera
¶ The current transform from object to camera coords.
Do not modify.
-
projection
¶ Projection transform.
Do not modify.
-
objectToNDC
¶ The transform from object to NDC (this includes projection).
Do not modify.
-
pushTransform
(transform_, multiply=True)[source]¶ Push a
Transform
on the transform stack.Parameters: - transform (Transform) – The transform to add to the stack.
- multiply (bool) – True (the default) to multiply with the top of the stack, False to push the transform as is without multiplication.
-
popTransform
()[source]¶ Pop the transform on top of the stack.
Returns: The Transform that is popped from the stack.
-
clipper
¶ The current clipping plane
-
-
class
silx.gui.plot3d.scene.viewport.
Viewport
(framebuffer=0)[source]¶ Rendering a single scene through a camera in part of a framebuffer.
Parameters: framebuffer (int) – The framebuffer ID this viewport is rendering into -
transforms
¶ Proxy of camera transforms.
Do not modify the list.
-
dirty
¶ True if scene is dirty and needs redisplay.
-
background
¶ Background color of the viewport (4-tuple of float in [0, 1]
-
camera
¶ The camera used to render the scene.
-
light
¶ The light used to render the scene.
-
origin
¶ Origin (ox, oy) of the viewport in pixels
-
size
¶ Size (width, height) of the viewport in pixels
-
shape
¶ Shape (height, width) of the viewport in pixels.
This is a convenient wrapper to the inverse of size.
-
framebuffer
¶ The framebuffer ID this viewport is rendering into (int)
-
render
(glContext)[source]¶ Perform the rendering of the viewport
Parameters: glContext (Context) – The context used for rendering
-
adjustCameraDepthExtent
()[source]¶ Update camera depth extent to fit the scene bounds.
Only near and far planes are updated. The scene might still not be fully visible (e.g., if spanning behind the viewpoint with perspective projection).
-
resetCamera
()[source]¶ Change camera to have the whole scene in the viewing frustum.
It updates the camera position and depth extent. Camera sight direction and up are not affected.
-
orbitCamera
(direction, angle=1.0)[source]¶ Rotate the camera around center of the scene.
Parameters: - direction (str) – Direction of movement relative to image plane. In: ‘up’, ‘down’, ‘left’, ‘right’.
- angle (float) – he angle in degrees of the rotation.
-
moveCamera
(direction, step=0.1)[source]¶ Move the camera relative to the image plane.
Parameters: - direction (str) – Direction relative to image plane. One of: ‘up’, ‘down’, ‘left’, ‘right’, ‘forward’, ‘backward’.
- step (float) – The ratio of data to step for each pan.
-
windowToNdc
(winX, winY, checkInside=True)[source]¶ Convert position from window to normalized device coordinates.
If window coordinates are int, they are moved half a pixel to be positioned at the center of pixel.
Parameters: - winX – X window coord, origin left.
- winY – Y window coord, origin top.
- checkInside (bool) – If True, returns None if position is outside viewport.
Returns: (x, y) Normalize device coordinates in [-1, 1] or None. Origin center, x to the right, y goes upward.
-
ndcToWindow
(ndcX, ndcY, checkInside=True)[source]¶ Convert position from normalized device coordinates (NDC) to window.
Parameters: - ndcX (float) – X NDC coord.
- ndcY (float) – Y NDC coord.
- checkInside (bool) – If True, returns None if position is outside viewport.
Returns: (x, y) window coordinates or None. Origin top-left, x to the right, y goes downward.
-
window
: On-screen window¶
This module provides a class for Viewports rendering on the screen.
The Window
renders a list of Viewports in the current framebuffer.
The rendering can be performed in an off-screen framebuffer that is only
updated when the scene has changed and not each time Qt is requiring a repaint.
The Context
and ContextGL2
represent the operating system
OpenGL context and handle OpenGL resources.
-
class
silx.gui.plot3d.scene.window.
Context
(glContextHandle)[source]¶ Correspond to an operating system OpenGL context.
User should NEVER use an instance of this class beyond the method it is passed to as an argument (i.e., do not keep a reference to it).
Parameters: glContextHandle – System specific OpenGL context handle. -
isCurrent
¶ Whether this OpenGL context is the current one or not.
-
setCurrent
(isCurrent=True)[source]¶ Set the state of the OpenGL context to reflect OpenGL state.
This should not be called from the scene graph, only in the wrapper that handle the OpenGL context to reflect its state.
Parameters: isCurrent (bool) – The state of the system OpenGL context.
-
devicePixelRatio
¶ Ratio between device and device independent pixels (float)
This is useful for font rendering.
-
glContext
¶ The handle to the OpenGL context provided by the system.
-
-
class
silx.gui.plot3d.scene.window.
ContextGL2
(glContextHandle)[source]¶ Handle a system GL2 context.
User should NEVER use an instance of this class beyond the method it is passed to as an argument (i.e., do not keep a reference to it).
Parameters: glContextHandle – System specific OpenGL context handle. -
prog
(vertexShaderSrc, fragmentShaderSrc)[source]¶ Cache program within context.
WARNING: No clean-up.
-
makeVbo
(data=None, sizeInBytes=None, usage=None, target=None)[source]¶ Create a VBO in this context with the data.
Current limitations:
- One array per VBO
- Do not support sharing VertexBuffer across VboAttrib
Automatically discards the VBO when the returned
VertexBuffer
istance is deleted.Parameters: - data (numpy.ndarray) – 2D array of data to store in VBO or None.
- sizeInBytes (int) – Size of the VBO or None. It should be <= data.nbytes if both are given.
- usage – OpenGL usage define in VertexBuffer._USAGES.
- target – OpenGL target in VertexBuffer._TARGETS.
Returns: The VertexBuffer created in this context.
-
makeVboAttrib
(data, usage=None, target=None)[source]¶ Create a VBO from data and returns the associated VBOAttrib.
Automatically discards the VBO when the returned
VBOAttrib
istance is deleted.Parameters: - data (numpy.ndarray) – 2D array of data to store in VBO or None.
- usage – OpenGL usage define in VertexBuffer._USAGES.
- target – OpenGL target in VertexBuffer._TARGETS.
Returns: A VBOAttrib instance created in this context.
-
-
class
silx.gui.plot3d.scene.window.
Window
(mode=u'framebuffer')[source]¶ OpenGL Framebuffer where to render viewports
Parameters: mode (str) – Rendering mode to use:
- ‘direct’ to render everything for each render call
- ‘framebuffer’ to cache viewport rendering in a texture and update the texture only when needed.
-
dirty
¶ True if this object or any attached viewports is dirty.
-
size
¶ Size (width, height) of the window in pixels
-
shape
¶ Shape (height, width) of the window in pixels.
This is a convenient wrapper to the reverse of size.
-
viewports
¶ List of viewports to render in the corresponding framebuffer
-
framebufferid
¶ Framebuffer ID used to perform rendering