20. canvas — This implements an OpenGL drawing widget for painting 3D scenes.

This implements an OpenGL drawing widget for painting 3D scenes.

class canvas.ActorList(canvas)

ActorList objects have the following methods:

add(actor)
Add an actor to an actorlist.
delete(actor)
Remove an actor from an actorlist.
redraw()

Redraw (some) actors in the scene.

This redraws the specified actors (recreating their display list). This should e.g. be used after changing an actor’s properties.

class canvas.CanvasSettings(dict={})

A collection of settings for an OpenGL Canvas.

Methods

Create a new set of CanvasSettings, possibly changing defaults.

Methods

CanvasSettings objects have the following methods:

classmethod checkDict(clas, dict)
Transform a dict to acceptable settings.
items()
reset(dict={})

Reset to defaults

If a dict is specified, these settings will override defaults.

update(dict)

Update current values with the specified settings

Returns the sanitized update values.

class canvas.Light(nr, **kargs)

Light objects have the following methods:

set()
set_value(key, value)
enable()
disable()
class canvas.Lights(nlights)

An array of OpenGL lights.

Methods

Lights objects have the following methods:

set_value(i, key, value)
Set an attribute of light i
set(i)
Set all attributes of light i
enable()
Enable the lights
disable()
class canvas.Canvas

A canvas for OpenGL rendering.

Methods

Initialize an empty canvas with default settings.

Methods

Canvas objects have the following methods:

Size()
glLightSpec()
glLight(onoff)
Toggle lights on/off.
hasLight()
Return the status of the lighting.
resetDefaults(dict={})
Return all the settings to their default values.
resetLighting()
resetLights()
setRenderMode(rm)

Set the rendermode.

This changes the rendermode and redraws everything with the new mode.

setTransparency(mode)
setLighting(mode)
setAveragedNormals(mode)
setLineWidth(lw)
Set the linewidth for line rendering.
setPointSize(sz)
Set the size for point drawing.
setBgColor(color1, color2=None)

Set the background color.

If one color is specified, a solid background is set. If two colors are specified, a graded background is set and an object is created to display the background.

createBackground()
Create the background object.
setFgColor(color)
Set the default foreground color.
setSlColor(color)
Set the highlight color.
updateSettings(settings)
Update the viewport settings
setLightValue(nr, key, val)
(Re)Define a light on the scene.
enableLight(nr)
Enable an existing light.
disableLight(nr)
Disable an existing light.
setTriade(on=None, pos='lb', siz=100)

Toggle the display of the global axes on or off.

If on is True, a triade of global axes is displayed, if False it is removed. The default (None) toggles between on and off.

initCamera()
glinit(mode=None)
glupdate()
Flush all OpenGL commands, making sure the display is updated.
clear()
Clear the canvas to the background color.
setDefaults()
Activate the canvas settings in the GL machine.
setSize(w, h)
display()

(Re)display all the actors in the scene.

This should e.g. be used when actors are added to the scene, or after changing camera position/orientation or lens.

zoom_2D(zoom=None)
begin_2D_drawing()

Set up the canvas for 2D drawing on top of 3D canvas.

The 2D drawing operation should be ended by calling end_2D_drawing. It is assumed that you will not try to change/refresh the normal 3D drawing cycle during this operation.

end_2D_drawing()
Cancel the 2D drawing mode initiated by begin_2D_drawing.
setBbox(bbox=None)
Set the bounding box of the scene you want to be visible.
addActor(actor)
Add a 3D actor to the 3D scene.
removeActor(actor)
Remove a 3D actor from the 3D scene.
addHighlight(actor)
Add a 3D actor highlight to the 3D scene.
removeHighlight(actor)
Remove a 3D actor highlight from the 3D scene.
addAnnotation(actor)
Add an annotation to the 3D scene.
removeAnnotation(actor)
Remove an annotation from the 3D scene.
addDecoration(actor)
Add a 2D decoration to the canvas.
removeDecoration(actor)
Remove a 2D decoration from the canvas.
remove(itemlist)

Remove a list of any actor/highlights/annotation/decoration items.

This will remove the items from any of the canvas lists in which the item appears. itemlist can also be a single item instead of a list.

removeActors(actorlist=None)
Remove all actors in actorlist (default = all) from the scene.
removeHighlights(actorlist=None)
Remove all highlights in actorlist (default = all) from the scene.
removeAnnotations(actorlist=None)
Remove all annotations in actorlist (default = all) from the scene.
removeDecorations(actorlist=None)
Remove all decorations in actorlist (default = all) from the scene.
removeAll()
Remove all actors and decorations
redrawAll()
Redraw all actors in the scene.
setCamera(bbox=None, angles=None)

Sets the camera looking under angles at bbox.

This function sets the camera angles and adjusts the zooming. The camera distance remains unchanged.

If a bbox is specified, the camera will be zoomed to make the whole bbox visible. If no bbox is specified, the current scene bbox will be used. If no current bbox has been set, it will be calculated as the bbox of the whole scene.

If no camera angles are given, the camera orientation is kept. angles can be a set of 3 angles, or a string

zoom(f, dolly=True)
Dolly zooming.
project(x, y, z, locked=False)
Map the object coordinates (x,y,z) to window coordinates.
unProject(x, y, z, locked=False)
Map the window coordinates (x,y,z) to object coordinates.
zoomRectangle(x0, y0, x1, y1)

Rectangle zooming

x0,y0,x1,y1 are pixel coordinates of the lower left and upper right corners of the area to zoom to the full window

zoomAll()

Rectangle zooming

x0,y0,x1,y1 are relative corners in (0,0)..(1,1) space

saveBuffer()
Save the current OpenGL buffer
showBuffer()
Show the saved buffer
draw_focus_rectangle(width=2)

Draw the focus rectangle.

The specified width is HALF of the line width

draw_cursor(x, y)
draw the cursor
draw_rectangle(x, y)

Functions defined in the module canvas

canvas.gl_pickbuffer()
Return a list of the 2nd numbers in the openGL pick buffer.
canvas.glFillMode(mode)
canvas.glFrontFill()
canvas.glBackFill()
canvas.glBothFill()
canvas.glFill()
canvas.glLine()
canvas.glLineSmooth(onoff)
canvas.glSmooth()
Enable smooth shading
canvas.glFlat()
Disable smooth shading
canvas.onOff(onoff)
Convert On/Off strings to a boolean
canvas.glEnable(facility, onoff)

Enable/Disable an OpenGL facility, depending on onoff value

facility is an OpenGL facility. onoff can be True or False to enable, resp. disable the facility, or None to leave it unchanged.

canvas.glCulling(onoff=True)
canvas.glNoCulling()
canvas.glLighting(onoff)
canvas.glPolygonFillMode(mode)
canvas.glPolygonMode(mode)
canvas.glShadeModel(model)
canvas.glSettings(settings)

Documentation

Previous topic

19. gluttext — 2D text decorations using GLUT fonts

Next topic

21. viewport — Interactive OpenGL Canvas embedded in a Qt4 widget.

This Page