[vtkusers] Live updating volume properties using KWWidgets and Tcl

Jason K Wang jkwang01 at syr.edu
Tue Apr 12 09:41:12 EDT 2011


Hello all,

I am an undergraduate student in a rush to create a project for my professor who will flunk me if I don't finish. I am attempting to use VTK in conjunction with Tcl and KWWidgets in order to display a volume of medical image data. I use the vtkKWVolumePropertyWidget to update the volume properties, like color and opacity transfer functions, but, in order for the properties to be updated, the render widget needs to be clicked on. Is some sort of local variable or callback function needed? In addition, I need to create a directory browser. I can again use a KWWidget to add a directory browser representation, but, how do I have actions placed on the widget directly effect the properties of the volume in real-time. Any help is appreciated! The code I have so far is at the bottom of this message.

Thanks in advance for your help,
Jason

# Load the KWWidgets package

package require kwwidgets

# Create the application
# If --test was provided, ignore all registry settings, and exit silently
# Restore the settings that have been saved to the registry, like
# the geometry of the user interface so far.

set app [vtkKWApplication New]
$app SetName "Brain Viewer"

# Set a help link. Can be a remote link (URL), or a local file

$app SetHelpDialogStartingPage "http://www.kwwidgets.org"

# Add a window
# Set 'SupportHelp' to automatically add a menu entry for the help link

set win [vtkKWWindow New]
$win SupportHelpOn
$app AddWindow $win
$win Create
$win SecondaryPanelVisibilityOff

# Add a render widget, attach it to the view frame, and pack

# Create a render widget,

set rw [vtkKWRenderWidget New]
$rw SetParent [$win GetViewFrame]
$rw Create

pack [$rw GetWidgetName] -side top -expand y -fill both -padx 0 -pady 0

# Create a volume reader
vtkVolume16Reader v16
  v16 SetDataDimensions 64 64
  v16 SetDataByteOrderToLittleEndian
  v16 SetFilePrefix  "$VTK_DATA_ROOT/Data/headsq/quarter"
  v16 SetImageRange 1 93
  v16 SetDataSpacing  3.2 3.2 1.5

vtkVolumeRayCastCompositeFunction rayCastFunction

vtkVolumeRayCastMapper volumeMapper
  volumeMapper SetInput [v16 GetOutput]
  volumeMapper SetVolumeRayCastFunction rayCastFunction

  # Create frame for widget

 set vpw_frame [vtkKWFrameWithScrollbar New]
  $vpw_frame SetParent [$win GetMainPanelFrame]
  $vpw_frame Create

  pack [$vpw_frame GetWidgetName] -side top -fill both -expand y

  # -----------------------------------------------------------------------

  # Create a volume property widget

  set vpw [vtkKWVolumePropertyWidget New]
  $vpw SetParent [$vpw_frame GetFrame]
  $vpw Create

  pack [$vpw GetWidgetName] -side top -anchor nw -expand y -padx 2 -pady 2

  # Create a volume property and assign it
  # We need color tfuncs opacity and gradient

  set vpw_vp [vtkVolumeProperty New]
  $vpw_vp SetIndependentComponents 1

  set vpw_cfun [vtkColorTransferFunction New]
  $vpw_cfun SetColorSpaceToRGB
  $vpw_cfun AddRGBPoint 0    0.0 0.0 0.0
  $vpw_cfun AddRGBPoint 500  1.0 0.5 0.3
  $vpw_cfun AddRGBPoint 1000 1.0 0.5 0.3
  $vpw_cfun AddRGBPoint 1150 1.0 1.0 0.9

  set vpw_ofun [vtkPiecewiseFunction New]
  $vpw_ofun AddSegment 0.0 0.2 255.0 0.8
  $vpw_ofun AddSegment 40 0.9 120.0 0.1

  set vpw_gfun [vtkPiecewiseFunction New]
  $vpw_gfun AddSegment 0.0 0.2 60.0 0.4

  $vpw_vp SetColor 0 $vpw_cfun
  $vpw_vp SetScalarOpacity 0 $vpw_ofun
  $vpw_vp SetGradientOpacity 0 $vpw_gfun

  $vpw SetVolumeProperty $vpw_vp
  $vpw SetWindowLevel 565 565

vtkVolume volume
  volume SetMapper volumeMapper
  volume SetProperty $vpw_vp

set ren [$rw GetRenderer]
$ren AddViewProp volume

$rw ResetCamera
set camera [$ren GetActiveCamera]
set c [volume GetCenter]
$camera SetFocalPoint [lindex $c 0] [lindex $c 1] [lindex $c 2]
$camera SetPosition [expr [lindex $c 0] + 400] [lindex $c 1] [lindex $c 2]
$camera SetViewUp 0 0 -1

# Start the application
set ret 0
$win Display
$app Start
set ret [$app GetExitStatus]
$win Close

# Deallocate and exit

$rw Delete
$win Delete
$app Delete

exit $ret
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110412/4a96bb26/attachment.htm>


More information about the vtkusers mailing list