[vtkusers] Scrolling a vtkTkImageViewerWidget
Erin McKay
MckayEr at SESAHS.NSW.GOV.AU
Sun Nov 21 23:20:40 EST 2004
Hi all:
I'm building my first Tk/VTK utility and have run into a problem. I want to display a large image at full resolution in a scrollable panel. I created a scrolling frame in a canvas and placed a vtkTkImageViewerWidget inside it (see code below). Problem is that the image ignores the scroll frame bounds and renders itself out to the edge of the toplevel window. And it won't scroll, although the scrollbars seem to pick up the image bounds correctly. Other widgets placed in the scrollframe (lists of buttons, etc) scroll correctly.
Any suggestions?
------------------------------Sample Code---------------------------------
# run from the cmd line with: wish TkImageScroller.tcl
lappend auto_path /usr/local/lib/vtk/tcl
package require vtk
package require vtkinteraction
#=======================================================================
# CreateScrollFrame
#-----------------------------------------------------------------------
proc CreateScrollFrame {win} {
frame $win -class ScrollFrame
scrollbar $win.xscroll -orient horizontal -command "$win.vport xview"
scrollbar $win.yscroll -orient vertical -command "$win.vport yview"
canvas $win.vport \
-xscrollcommand "$win.xscroll set" \
-yscrollcommand "$win.yscroll set"
grid $win.vport -row 0 -column 0 -sticky news
grid $win.yscroll -row 0 -column 1 -sticky ns
grid $win.xscroll -row 1 -column 0 -sticky ew
grid rowconfigure $win 0 -weight 1
grid columnconfigure $win 0 -weight 1
frame $win.vport.interior
$win.vport create window 0 0 -anchor nw -window $win.vport.interior
bind $win.vport.interior <Configure> "ScrollFrameResize $win"
return $win
}
#=======================================================================
# ScrollFrameResize
#-----------------------------------------------------------------------
proc ScrollFrameResize {win} {
set bbox [$win.vport bbox all]
set wd [winfo width $win.vport.interior]
$win.vport configure -width $wd -scrollregion $bbox \
-yscrollincrement 0.1i
}
#=======================================================================
# ScrollFrameInterior
#-----------------------------------------------------------------------
proc ScrollFrameInterior {win} {
return $win.vport.interior
}
#=======================================================================
# main
#-----------------------------------------------------------------------
# Create the image reader
vtkImageReader reader
reader SetDataScalarType 4
reader SetDataExtent 0 511 0 511 0 0
reader SetFileName "test.img"
reader Update
scan [[reader GetOutput] GetWholeExtent] "%d %d %d %d %d %d" \
xMin xMax yMin yMax zMin zMax
vtkImageViewer viewer
viewer SetInput [reader GetOutput]
viewer SetZSlice 0
viewer SetColorWindow 300
viewer SetColorLevel 2150
wm withdraw .
toplevel .top
wm protocol .top WM_DELETE_WINDOW ::vtk::cb_exit
set scroller [CreateScrollFrame .top.scroller]
set interior [ScrollFrameInterior $scroller]
# Create the vtkTkImageViewerWidget
#---------------------------------------
set vtkiw [vtkTkImageViewerWidget $interior.viewPane \
-width [expr ($xMax - $xMin + 1)] \
-height [expr ($yMax - $yMin + 1)] \
-iv viewer]
# Setup some Tk bindings, a generic renwin
# interactor and observers for the widget
#---------------------------------------
::vtk::bind_tk_imageviewer_widget $vtkiw
pack $vtkiw -anchor nw -padx 3 -pady 3 -fill both -expand true
pack $scroller -fill both -expand true
SOUTH EAST HEALTH CONFIDENTIALITY NOTICE
This email, and the files transmitted with it, are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient, you are not permitted to distribute or use this email or any of its attachments in any way. We also request that you advise the sender of
the incorrect addressing.
This email message has been virus-scanned. Although no computer viruses were detected, South East Health accepts no liability for any consequential damage resulting from email containing any computer viruses.
More information about the vtkusers
mailing list