18. 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, atype)
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.
Create a new set of CanvasSettings, possibly changing defaults.
CanvasSettings objects have the following methods:
-
classmethod checkDict(clas, dict)
- Transform a dict to acceptable settings.
-
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, *args, **kargs)
Light objects have the following methods:
-
set(ambient=0.5, diffuse=0.5, specular=0.5, position=(!!(319, (303, (304, (305, (306, (307, (309, (310, (311, (312, (313, (314, (315, (316, (317, (2, '0.'))))))))))))))), (12, ', '), (303, (304, (305, (306, (307, (309, (310, (311, (312, (313, (314, (315, (316, (317, (2, '0.'))))))))))))))), (12, ', '), (303, (304, (305, (306, (307, (309, (310, (311, (312, (313, (314, (315, (316, (317, (2, '1.'))))))))))))))), (12, ', '), (303, (304, (305, (306, (307, (309, (310, (311, (312, (313, (314, (315, (316, (317, (2, '0.'))))))))))))))))!!))
-
enable()
-
disable()
-
class canvas.Canvas
A canvas for OpenGL rendering.
Initialize an empty canvas with default settings.
Canvas objects have the following methods:
-
Size()
-
glMatSpec()
-
glLightSpec()
-
glLight(onoff)
- Toggle lights on/off.
-
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.
-
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
-
setLight(nr, ambient, diffuse, specular, position)
- (Re)Define a light on the scene.
-
enableLight(nr)
- Enable an existing light.
-
disableLight(nr)
- Disable an existing light.
-
setTriade(on=None, size=1.0, pos=[, 0.0, 0.0, 0.0])
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 actors 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.
-
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.glSmooth()
- Enable smooth shading
-
canvas.glFlat()
- Disable smooth shading
-
canvas.glCulling()
- Enable culling
-
canvas.glNoCulling()
- Disable culling