70. opengl.decors — Decorations for the OpenGL canvas.

This module contains a collection of predefined decorations that can be useful additions to a geometry scene rendering.

70.1. Classes defined in module opengl.decors

class opengl.decors.BboxActor(bbox, **kargs)[source]

Draws a bounding bbox.

A bounding box is a hexaeder in global axes. The hexaeder is drawn in wireframe mode with default color black.

class opengl.decors.Rectangle(x1, y1, x2, y2, **kargs)[source]

A 2D-rectangle on the canvas.

class opengl.decors.Line(x1, y1, x2, y2, **kargs)[source]

A 2D-line on the canvas.

Parameters:

  • x1, y1, x2, y2: floats: the viewport coordinates of the endpoints of the line
  • kargs: keyword arguments to be passed to the Actor.
class opengl.decors.Lines(data, color=None, linewidth=None, **kargs)[source]

A collection of straight lines on the canvas.

Parameters:

  • data: data that can initialize a 2-plex Formex: the viewport coordinates of the 2 endpoints of the n lines. The third coordinate is ignored.
  • kargs: keyword arguments to be passed to the Actor.
class opengl.decors.Grid2D(x1, y1, x2, y2, nx=1, ny=1, lighting=False, rendertype=2, **kargs)[source]

A 2D-grid on the canvas.

class opengl.decors.ColorLegend(colorscale, ncolors, x, y, w, h, ngrid=0, linewidth=None, nlabel=-1, size=18, font=None, textcolor=None, dec=2, scale=0, lefttext=False, **kargs)[source]

A labeled colorscale legend.

When showing the distribution of some variable over a domain by means of a color encoding, the viewer expects some labeled colorscale as a guide to decode the colors. The ColorLegend decoration provides such a color legend. This class only provides the visual details of the scale. The conversion of the numerical values to the matching colors is provided by the colorscale.ColorScale class.

Parameters:

  • colorscale: a colorscale.ColorScale instance providing conversion between numerical values and colors
  • ncolors: int: the number of different colors to use.
  • x,y,w,h: four integers specifying the position and size of the color bar rectangle
  • ngrid: int: number of intervals for the grid lines to be shown. If > 0, grid lines are drawn around the color bar and between the ngrid intervals. If = 0, no grid lines are drawn. If < 0 (default), the value is set equal to the number of colors or to 0 if this number is higher than 50.
  • linewidth: float: width of the grid lines. If not specified, the current canvas line width is used.
  • nlabel: int: number of intervals for the labels to be shown. If > 0, labels will be displayed at nlabel interval borders, if possible. The number of labels displayed thus will be nlabel+1, or less if the labels would otherwise be too close or overlapping. If 0, no labels are shown. If < 0 (default), a default number of labels is shown.
  • size: font size to be used for the labels
  • font: font to be used for the labels. It can be a textext.FontTexture or a string with the path to a monospace .ttf font. If unspecified, the default font is used.
  • dec: int: number of decimals to be used in the labels
  • scale: int: exponent of 10 for the scaling factor of the label values. The displayed values will be equal to the real values multiplied with 10**scale.
  • lefttext: bool: if True, the labels will be drawn to the left of the color bar. The default is to draw the labels at the right.

Some practical guidelines:

  • Large numbers of colors result in a quasi continuous color scheme.
  • With a high number of colors, grid lines disturb the image, so either use ngrid=0 or ngrid= to only draw a border around the colors.
  • With a small number of colors, set ngrid = len(colorlegend.colors) to add gridlines between each color. Without it, the individual colors in the color bar may seem to be not constant, due to an optical illusion. Adding the grid lines reduces this illusion.
  • When using both grid lines and labels, set both ngrid and nlabel to the same number or make one a multiple of the other. Not doing so may result in a very confusing picture.
  • The best practice is to either use a low number of colors (<=20) and the default ngrid and nlabel, or to use a high number of colors (>=200) and the default values or a low value for nlabel.

The ColorScale example script provides opportunity to experiment with different settings.

70.2. Functions defined in module opengl.decors

opengl.decors.Grid(nx=(1, 1, 1), ox=(0.0, 0.0, 0.0), dx=(1.0, 1.0, 1.0), lines='b', planes='b', linecolor=(0.0, 0.0, 0.0), planecolor=(1.0, 1.0, 1.0), alpha=0.3, **kargs)[source]

Creates a (set of) grid(s) in (some of) the coordinate planes.

Parameters:

  • nx: a list of 3 integers, specifying the number of divisions of the grid in the three coordinate directions. A zero value may be specified to avoid the grid to extend in that direction. Thus, setting the last value to zero will result in a planar grid in the xy-plane.
  • ox: a list of 3 floats: the origin of the grid.
  • dx: a list of 3 floats: the step size in each coordinate direction.
  • planes: one of ‘first’, ‘box’, ‘all’, ‘no’ (the string can be shortened to the first chartacter): specifies how many planes are drawn in each direction: ‘f’ only draws the first, ‘b’ draws the first and the last, resulting in a box, ‘a’ draws all planes, ‘n’ draws no planes.

Returns a list with up to two Meshes: the planes, and the lines.