File: TestWindowToImageTransparency.tcl

package info (click to toggle)
paraview 3.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 124,600 kB
  • ctags: 133,728
  • sloc: cpp: 958,817; ansic: 509,658; tcl: 45,787; xml: 23,401; python: 19,574; perl: 3,112; yacc: 1,787; java: 1,517; sh: 665; asm: 471; lex: 400; makefile: 168; objc: 28
file content (63 lines) | stat: -rw-r--r-- 1,573 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package require vtk
package require vtkinteraction

# Create the RenderWindow and Renderer 
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# create a default polygonal sphere
vtkSphereSource sphere
vtkPolyDataMapper sphmapper
   sphmapper SetInputConnection [sphere GetOutputPort]
vtkActor sphactor
   sphactor SetMapper sphmapper

# Add the actors to the renderer, set the background to initial
# color (which is also transparent), set size.
ren1 AddActor sphactor
ren1 SetBackground 0.1 0.2 0.4
renWin SetSize 256 256

# render first image
renWin Render

# create window to image filter, grabbing RGB and alpha
vtkWindowToImageFilter w2i
   w2i SetInput renWin
   w2i SetInputBufferTypeToRGBA

# grab window
w2i Update

# set up mappers and actors to display the image
vtkImageMapper im
   im SetColorWindow 255
   im SetColorLevel 127.5
   im SetInputConnection [w2i GetOutputPort]
vtkActor2D ia2
   ia2 SetMapper im

# now, change the image (background is now green)
sphactor SetScale 2 2 2
ren1 SetBackground 0 1 0 

# add the image of the sphere (keeping the original sphere too)
ren1 AddActor ia2
ren1 SetViewport 0 0 1 1

# render result (the polygonal sphere appears behind a smaller image
# of itself).  Background of original image is transparent, so you
# can see through it back to the larger sphere and new background.

renWin Render

iren AddObserver UserEvent {wm deiconify .vtkInteract}
# prevent the tk window from showing up then start the event loop
wm withdraw .