KWWidgets/Examples/Simple Medical Image Viewer
From KitwarePublic
The following Tcl code is a complete example showing how to create a very simple image viewer supporting user-interaction like pan/zoom/window-level and a slice scale. The C++ version would be only slightly longer.
| Tcl | ||
|---|---|---|
| package require kwwidgets | Load the KWWidgets package in Tcl | |
|
set app [vtkKWApplication New] | Create an application object, restore previous application settings like the window position, set where the help page should point to | |
|
set win [vtkKWWindowBase New] | Create a window object, provide a Help menu, let the application know about our window | |
|
set rw [vtkKWRenderWidget New] | Create a render widget object (i.e. a 2D or 3D scene) inside the window, turn on its corner annotation, pack it inside the window | |
|
set reader [vtkXMLImageDataReader New] | Create a VTK file reader, and point it to our data file. | |
|
set viewer [vtkImageViewer2 New] | Create a VTK image viewer, set it up so that it uses our render widget, set its input to the output of the reader, reset the camera to center the whole slice | |
|
set ca [$rw GetCornerAnnotation] | Retrieve the corner annotation object from the render widget, point it to the viewer actor and window/level filter, and let it display both slice and window/level in different corners using tags | |
|
set slice_scale [vtkKWScale New] | Create a scale object in our window, set its range to match the number of slices, set its callback to use its value to set the slice in the viewer, pack the scale in our window below the render widget | |
| $app Start | Start the application; this pops up the window and start the event loop, until the user quits | |
|
$rw Delete | Delete our objects | |
| exit | Exit Tcl/Tk |
| |

