/usr/lib/vtk-5.8/tcl/vtkinteraction/bindings-iw.tcl is in tcl-vtk 5.8.0-17.5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | namespace eval ::vtk {
namespace export *
# -------------------------------------------------------------------
# Specific vtkTkImageViewerWidget bindings
# Create a 2d text actor that can be used to display infos
# like window/level, pixel picking, etc
proc cb_vtkiw_create_text1 {vtkiw} {
set mapper [::vtk::get_widget_variable_value $vtkiw text1_mapper]
if {$mapper == ""} {
set mapper \
[::vtk::new_widget_object $vtkiw vtkTextMapper text1_mapper]
$mapper SetInput "none"
set tprop [$mapper GetTextProperty]
$tprop SetFontFamilyToArial
$tprop SetFontSize 12
$tprop BoldOn
$tprop ShadowOn
$tprop SetColor 1 1 0.5
}
set actor [::vtk::get_widget_variable_value $vtkiw text1_actor]
if {$actor == ""} {
set actor \
[::vtk::new_widget_object $vtkiw vtkActor2D text1_actor]
$actor SetMapper $mapper
$actor SetLayerNumber 1
[$actor GetPositionCoordinate] SetValue 5 4 0
$actor SetVisibility 0
[[$vtkiw GetImageViewer] GetRenderer] AddActor2D $actor
}
}
# Show/Hide the 2d text actor
# Ensure that it stays in the upper left corner of the window
proc cb_vtkiw_show_text1 {vtkiw} {
set actor [::vtk::get_widget_variable_value $vtkiw text1_actor]
if {![$actor GetVisibility]} {
set height [lindex [$vtkiw configure -height] 4]
set pos [$actor GetPositionCoordinate]
set value [$pos GetValue]
$pos SetValue \
[lindex $value 0] [expr $height - 15] [lindex $value 2]
$actor VisibilityOn
}
}
proc cb_vtkiw_hide_text1 {vtkiw} {
set actor [::vtk::get_widget_variable_value $vtkiw text1_actor]
if {[$actor GetVisibility]} {
$actor VisibilityOff
}
}
# -------------------------------------------------------------------
# vtkInteractorStyleImage callbacks/observers
# istyle: interactor style
# vtkiw: vtkTkImageRenderWindget
# StartWindowLevelEvent observer.
# Create the text actor, show it
proc cb_istyleimg_start_window_level_event {istyle vtkiw} {
::vtk::cb_vtkiw_create_text1 $vtkiw
::vtk::cb_vtkiw_show_text1 $vtkiw
}
# EndWindowLevelEvent observer.
# Hide the text actor.
proc cb_istyleimg_end_window_level_event {istyle vtkiw} {
::vtk::cb_vtkiw_hide_text1 $vtkiw
$vtkiw Render
}
# WindowLevelEvent observer.
# Update the text actor with the current window/level values.
proc cb_istyleimg_window_level_event {istyle vtkiw} {
set mapper [::vtk::get_widget_variable_value $vtkiw text1_mapper]
set viewer [$vtkiw GetImageViewer]
$mapper SetInput [format "W/L: %.0f/%.0f" \
[$viewer GetColorWindow] [$viewer GetColorLevel]]
}
# RightButtonPressEvent observer.
# Invert the 'shift' key. The usual vtkInteractorStyleImage
# behaviour is to enable picking mode with "Shift+Right button",
# whereas we want picking mode to be "Right button" (for backward
# compatibility).
proc cb_istyleimg_right_button_press_event {istyle} {
set iren [$istyle GetInteractor]
$iren SetShiftKey [expr [$iren GetShiftKey] ? 0 : 1]
$istyle OnRightButtonDown
}
proc cb_istyleimg_right_button_release_event {istyle} {
set iren [$istyle GetInteractor]
$iren SetShiftKey [expr [$iren GetShiftKey] ? 0 : 1]
$istyle OnRightButtonUp
}
# StartPickEvent observer.
# Create the text actor, show it
proc cb_istyleimg_start_pick_event {istyle vtkiw} {
::vtk::cb_vtkiw_create_text1 $vtkiw
::vtk::cb_vtkiw_show_text1 $vtkiw
}
# EndPickEvent observer.
# Hide the text actor.
proc cb_istyleimg_end_pick_event {istyle vtkiw} {
::vtk::cb_vtkiw_hide_text1 $vtkiw
$vtkiw Render
}
# PickEvent observer.
# Update the text actor with the current value of the picked pixel.
proc cb_istyleimg_pick_event {istyle vtkiw} {
set viewer [$vtkiw GetImageViewer]
set input [$viewer GetInput]
set pos [[$istyle GetInteractor] GetEventPosition]
set x [lindex $pos 0]
set y [lindex $pos 1]
set z [$viewer GetZSlice]
# Y is flipped upside down
set height [lindex [$vtkiw configure -height] 4]
set y [expr $height - $y]
# Make sure point is in the whole extent of the image.
scan [$input GetWholeExtent] "%d %d %d %d %d %d" \
xMin xMax yMin yMax zMin zMax
if {$x < $xMin || $x > $xMax || \
$y < $yMin || $y > $yMax || \
$z < $zMin || $z > $zMax} {
return
}
$input SetUpdateExtent $x $x $y $y $z $z
$input Update
set num_comps [$input GetNumberOfScalarComponents]
set str "($x, $y):"
for {set idx 0} {$idx < $num_comps} {incr idx} {
set str [format "%s %.0f" $str \
[$input GetScalarComponentAsDouble $x $y $z $idx]]
}
set mapper [::vtk::get_widget_variable_value $vtkiw text1_mapper]
$mapper SetInput "$str"
$vtkiw Render
}
# -------------------------------------------------------------------
# Create vtkTkImageViewerWidget bindings, setup observers
proc bind_tk_imageviewer_widget {vtkiw} {
bind_tk_widget $vtkiw [[$vtkiw GetImageViewer] GetRenderWindow]
set viewer [$vtkiw GetImageViewer]
set iren [[$viewer GetRenderWindow] GetInteractor]
# Ask the viewer to setup an image style interactor
$viewer SetupInteractor $iren
set istyle [$iren GetInteractorStyle]
# Window/Level observers
::vtk::set_widget_variable_value $istyle StartWindowLevelEventTag \
[$istyle AddObserver StartWindowLevelEvent \
"::vtk::cb_istyleimg_start_window_level_event $istyle $vtkiw"]
::vtk::set_widget_variable_value $istyle WindowLevelEventTag \
[$istyle AddObserver WindowLevelEvent \
"::vtk::cb_istyleimg_window_level_event $istyle $vtkiw"]
::vtk::set_widget_variable_value $istyle EndWindowLevelEventTag \
[$istyle AddObserver EndWindowLevelEvent \
"::vtk::cb_istyleimg_end_window_level_event $istyle $vtkiw"]
# Picking observers
::vtk::set_widget_variable_value $istyle RightButtonPressEventTag \
[$istyle AddObserver RightButtonPressEvent \
"::vtk::cb_istyleimg_right_button_press_event $istyle"]
::vtk::set_widget_variable_value $istyle RightButtonReleaseEventTag \
[$istyle AddObserver RightButtonReleaseEvent \
"::vtk::cb_istyleimg_right_button_release_event $istyle"]
::vtk::set_widget_variable_value $istyle StartPickEventTag \
[$istyle AddObserver StartPickEvent \
"::vtk::cb_istyleimg_start_pick_event $istyle $vtkiw"]
::vtk::set_widget_variable_value $istyle EndPickEventTag \
[$istyle AddObserver EndPickEvent \
"::vtk::cb_istyleimg_end_pick_event $istyle $vtkiw"]
::vtk::set_widget_variable_value $istyle PickEventTag \
[$istyle AddObserver PickEvent \
"::vtk::cb_istyleimg_pick_event $istyle $vtkiw"]
}
}
# Handle deprecated calls
proc BindTkImageViewer {widget} {
puts stderr "BindTkImageViewer is deprecated. Please use ::vtk::bind_tk_imageviewer_widget instead"
::vtk::bind_tk_imageviewer_widget $widget
}
|