[vtkusers] regardind button for boxwidget

Shivam Agarwal shivamzone at gmail.com
Fri Oct 30 09:43:24 EDT 2009


HI members ,I am trying to implement a button in Tcl script in vtk so that on
pressing the button boxwidget become visible (rather than the default setting
in which boxwidget appers on pressing character "i" on keyboard but I am
getting some errors. PLZ HELP ME OUT

ERROR

Object  named iren could not find the requested method:Enter event

while executing
 "iren Enter Event"
[Procedure "::vtk_cb_vtkw_enter_binding line 5]
invoked from within
::vtk_cb_vtkw_enter_binding .ren renWin 291 188
[command bound to event]


Here is my complete code


package require vtk
package require vtkinteraction

# Next we create an instance of vtkSphereSource and set some of its
# properties

vtkSphereSource sphere
    sphere SetThetaResolution 60
    sphere SetPhiResolution 8

# We create an instance of vtkPolyDataMapper to map the polygonal data
# into graphics primitives. We connect the output of the sphere source
# to the input of this mapper

vtkPolyDataMapper sphereMapper
    sphereMapper SetInputConnection [sphere GetOutputPort]

# Create an actor to represent the sphere. The actor coordinates rendering of
# the graphics primitives for a mapper. We set this actor's mapper to be
# the mapper which we created above.

vtkLODActor sphereActor
    sphereActor SetMapper sphereMapper

# Create the Renderer and assign actors to it. A renderer is like a
# viewport. It is part or all of a window on the screen and it is responsible
# for drawing the actors it has. We also set the background color here.

vtkRenderer renderer
    renderer AddActor sphereActor
   renderer SetBackground 1 1 1


# We create the render window which will show up on the screen
# We put our renderer into the render window using AddRenderer.
# Do not set the size of the window here.

vtkRenderWindow renWin
    renWin AddRenderer renderer

vtkRenderWindowInteractor iren
iren SetRenderWindow renWin

vtkBoxWidget boxWidget
boxWidget SetInteractor iren
boxWidget SetPlaceFactor 3.25

# Place the interactor initially. The input to a 3D widget is used to
# initially position and scale the widget. The EndInteractionEvent is
# observed which invokes the SelectPolygons callback.

boxWidget SetInput [sphere GetOutput]
boxWidget PlaceWidget
boxWidget AddObserver InteractionEvent TransformActor

# Normally the user presses the "i" key to bring a 3D widget to life. Here
# we will manually enable it so it appears with the cone.

#boxWidget On
#iren Initialize

# vtkTkRenderWidget is a Tk widget that we can render into. It has a
# GetRenderWindow method that returns a vtkRenderWindow. This can then
# be used to create a vtkRenderer and etc. We can also specify a
# vtkRenderWindow to be used when creating the widget by using the -rw
# option, which is what we do here by using renWin. It also takes
# -width and -height options that can be used to specify the widget
# size, hence the render window size: we set the size to be 300
# pixels by 300.

# Setup Tk bindings and VTK observers for that widget.
set vtkw [vtkTkRenderWidget .ren \
        -width 250 \
        -height 300 \
        -rw renWin]

::vtk::bind_tk_render_widget $vtkw


# We first create a .params Tk frame .
frame .params


button .params.quit -text "Quit" -command ::vtk::cb_exit
button .params.run -text "Execute" -command {
boxWidget On
}

pack .params.quit .params.run -side top -anchor nw -fill both
pack $vtkw .params -side top -fill both -expand yes


# We set the window manager (wm command) so that it registers a
# command to handle the WM_DELETE_WINDOW protocal request. This
# request is triggered when the widget is closed using the standard
# window manager icons or buttons. In this case the exit callback
# will be called and it will free up any objects we created then exit
# the application.

wm protocol . WM_DELETE_WINDOW ::vtk::cb_exit


# You only need this line if you run this script from a Tcl shell
# (tclsh) instead of a Tk shell (wish)

tkwait window .



More information about the vtkusers mailing list