<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">Hello,</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">I am trying to put at the example given by vtk: Examples/Image Processing/ Image Slicing.tcl a scroll bar and I don't know what I am missing in writing the procedure. I have attached my code. Thank you for helping me:</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><br></div><div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">package require vtk</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">package require
vtkinteraction</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># This example shows how to load a 3D image into VTK and then reformat</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># that image into a different orientation for viewing. It uses</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># vtkImageReslice for reformatting the image, and uses vtkImageActor</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># and vtkInteractorStyleImage to display the image. This InteractorStyle</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># forces the camera to stay perpendicular to the XY
plane.</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># Start by loading some data.</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkImageReader2 reader</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> reader SetFilePrefix "quarter"</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> reader SetDataExtent 0 63 0 63 1 93</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> reader SetDataSpacing 3.2 3.2 1.5</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> reader SetDataOrigin 0.0 0.0 0.0</font></div><div><font class="Apple-style-span"
face="'times new roman', 'new york', times, serif"> reader SetDataScalarTypeToUnsignedShort</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> reader UpdateWholeExtent</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># Calculate the center of the volume</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">[reader GetOutput] UpdateInformation</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set extent [[reader GetOutput] GetWholeExtent]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set spacing [[reader GetOutput] GetSpacing]</font></div><div><font class="Apple-style-span" face="'times new roman',
'new york', times, serif">set origin [[reader GetOutput] GetOrigin]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set xMin [lindex $extent 0]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set xMax [lindex $extent 1]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set yMin [lindex $extent 2]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set yMax [lindex $extent 3]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set zMin [lindex $extent 4]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set zMax [lindex $extent 5]</font></div><div><font
class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set xSpacing [lindex $spacing 0]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set ySpacing [lindex $spacing 1]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set zSpacing [lindex $spacing 2]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set x0 [lindex $origin 0]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set y0 [lindex $origin 1]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set z0 [lindex $origin
2]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set xCenter [expr $x0 + $xSpacing * 0.5 * ($xMin + $xMax)]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set yCenter [expr $y0 + $ySpacing * 0.5 * ($yMin + $yMax)]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set zCenter [expr $z0 + $zSpacing * 0.5 * ($zMin + $zMax)]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># Matrices for axial, coronal, sagittal, oblique view orientations</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkMatrix4x4
axial</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set elements { 1 0 0 $xCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> 0 1 0 $yCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> 0 0 1 $zCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> 0 0 0 1}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">for {set i 0} {$i < 16} {incr i} {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> axial SetElement
[expr $i / 4] [expr $i % 4] [expr [lindex $elements $i]] </font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkMatrix4x4 coronal</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set elements { 1 0 0 $xCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> 0 0 1 $yCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> 0 -1 0 $zCenter</font></div><div><font class="Apple-style-span" face="'times
new roman', 'new york', times, serif"> 0 0 0 1}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">for {set i 0} {$i < 16} {incr i} {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> coronal SetElement [expr $i / 4] [expr $i % 4] [expr [lindex $elements $i]] </font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkMatrix4x4 sagittal</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set elements { 0 0 -1 $xCenter</font></div><div><font class="Apple-style-span"
face="'times new roman', 'new york', times, serif"> 1 0 0 $yCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> 0 -1 0 $zCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> 0 0 0 1}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">for {set i 0} {$i < 16} {incr i} {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> sagittal SetElement [expr $i / 4] [expr $i % 4] [expr [lindex $elements $i]] </font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">}</font></div><div><font
class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkMatrix4x4 oblique</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set elements { 1 0 0 $xCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> 0 0.866025 -0.5 $yCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> 0 0.5 0.866025 $zCenter</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">
0 0 0 1 }</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">for {set i 0} {$i < 16} {incr i} {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> oblique SetElement [expr $i / 4] [expr $i % 4] [expr [lindex $elements $i]] </font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># Extract a slice in the desired orientation</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkImageReslice reslice</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> reslice
SetInputConnection [reader GetOutputPort]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> reslice SetOutputDimensionality 2 </font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> reslice SetResliceAxes sagittal </font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> reslice SetInterpolationModeToLinear</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># Create a greyscale lookup table</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkLookupTable table</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> table SetTableRange 0
2000 </font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> table SetValueRange 0.0 1.0</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> table SetSaturationRange 0.0 0.0</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> table SetRampToLinear</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> table Build</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># Map the image through the lookup table</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkImageMapToColors color</font></div><div><font class="Apple-style-span" face="'times new
roman', 'new york', times, serif"> color SetLookupTable table</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> color SetInputConnection [reslice GetOutputPort]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># Display the image</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkImageActor actor</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> actor SetInput [color GetOutput]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkRenderer renderer</font></div><div><font
class="Apple-style-span" face="'times new roman', 'new york', times, serif"> renderer AddActor actor</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkRenderWindow window</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> #window AddRenderer renderer</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> #Set up the interaction</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> vtkInteractorStyleImage imageStyle</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font
class="Apple-style-span" face="'times new roman', 'new york', times, serif">vtkRenderWindowInteractor interactor</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> interactor SetInteractorStyle imageStyle</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> window SetInteractor interactor </font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> window Render</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># Create callbacks for slicing the image</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">global action</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york',
times, serif">set action ""</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">proc ButtonPressCallback {} {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> global action</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> set action "Slicing"</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">proc ButtonReleaseCallback {} {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">
global action</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> set action ""</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">proc MouseMoveCallback {} {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> set lastPos [interactor GetLastEventPosition]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> set currPos [interactor GetEventPosition]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> global action</font></div><div><font
class="Apple-style-span" face="'times new roman', 'new york', times, serif"> if {$action == "Slicing"} {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> set deltaY [expr [lindex $currPos 1] - [lindex $lastPos 1]]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> [reslice GetOutput] UpdateInformation</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> set spacing [[reslice GetOutput] GetSpacing]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> set sliceSpacing [lindex $spacing 2]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> set matrix [reslice
GetResliceAxes]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> # move the center point that we are slicing through</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> set center [$matrix MultiplyPoint 0 0 [expr $sliceSpacing * $deltaY] 1]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> $matrix SetElement 0 3 [lindex $center 0]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> $matrix SetElement 1 3 [lindex $center 1]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> $matrix SetElement 2 3 [lindex $center 2]</font></div><div><font class="Apple-style-span" face="'times new
roman', 'new york', times, serif"> window Render</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> } else {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> imageStyle OnMouseMove</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> }</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">imageStyle AddObserver MouseMoveEvent MouseMoveCallback</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">imageStyle AddObserver LeftButtonPressEvent ButtonPressCallback</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york',
times, serif">imageStyle AddObserver LeftButtonReleaseEvent ButtonReleaseCallback</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">interactor AddObserver UserEvent {wm deiconify .vtkInteract}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">interactor AddObserver ExitEvent {exit}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">interactor Initialize</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set vtkw [vtkTkRenderWidget .ren \</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">
-width 800 \</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> -rw window]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">::vtk::bind_tk_render_widget $vtkw</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">set size_slider [scale .size \</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> -from 1 -to 93 -res 1 \</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> -orient horizontal \</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> -label
"Slice:" \</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> -command set_slice]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif" style="background-color: rgb(96, 191, 0);">proc set_slice {size} {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif" style="background-color: rgb(96, 191, 0);"> global reslice</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif" style="background-color: rgb(96, 191, 0);"> set i 0</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif" style="background-color: rgb(96, 191, 0);"> foreach reslice $reslice {</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif" style="background-color:
rgb(96, 191, 0);"> incr i</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif" style="background-color: rgb(96, 191, 0);"> #[[$actor GetMapper] GetTextProperty] SetFontSize $size</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif" style="background-color: rgb(96, 191, 0);"> #$actor SetDisplayPosition 10 [expr $i * ($size + 5)]</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif" style="background-color: rgb(96, 191, 0);"> }</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"> window SetSize 800 [expr 20 + $i * ($size + 5)]</font></div><div><font
class="Apple-style-span" face="'times new roman', 'new york', times, serif"> window Render</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">}</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">#pack $size_slider -side top -fill both</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">pack $vtkw -side top -fill both -expand yes</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">wm protocol . WM_DELETE_WINDOW ::vtk::cb_exit</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">#</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># Hide the default .
widget</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">#</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">wm withdraw .</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">#</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># You only need this line if you run this script from a Tcl shell</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"># (tclsh) instead of a Tk shell (wish)</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">#</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">tkwait window
.</font></div></div></div></body></html>