[vtkusers] KWWidgets: How do you use the vtkKWFileBrowserDialog widget?
Jason K Wang
jkwang01 at syr.edu
Mon May 9 01:38:38 EDT 2011
Hello VTK users,
I'm a student in desperate need of some assistance. I'm volume rendering
DICOM images and writing an extensive report for a project that I need to
finish in one day. First of all, does anybody know where to find resources
on the use of VTK in clinical practice and any kind of helpful sources which
I can put in my report?
Secondly, how do I use the KWWidgets File Browser Dialog widget?
It is described here:
http://www.kwwidgets.org/doc/nightly/html/classvtkKWFileBrowserDialog.html
The below code creates the widget, but, how do I make the file browser
dialog functional so that it selects a DICOM image to read.
set dir_browser [vtkKWFileBrowserDialog New]
$dir_browser SetParent [$win GetMainPanelFrame]
$dir_browser Create
pack [$dir_browser GetWidgetName] -side top -anchor nw -expand n -fill x
I'm asking: which events and commands do I use to link the selection of a
file directory to the DICOM image reader? Any and all help is greatly
appreciated.
I'm using Tcl. The following is my complete pipeline:
# 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 "3d dicom 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 directory browser, attach it to the main panel frame
set dir_browser [vtkKWFileBrowserDialog New]
$dir_browser SetParent [$win GetMainPanelFrame]
$dir_browser Create
pack [$dir_browser GetWidgetName] -side top -anchor nw -expand n -fill x
# Create a volume reader
vtkDICOMImageReader v16
v16 SetDirectoryName INSERT FILE DIRECTORY NAME HERE
vtkVolumeRayCastCompositeFunction rayCastFunction
vtkVolumeRayCastMapper volumeMapper
volumeMapper SetInput [v16 GetOutput]
volumeMapper SetVolumeRayCastFunction rayCastFunction
# Use the render window and renderer of the renderwidget
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
$vpw_cfun AddRGBPoint 3150 1.0 1.0 0.9
#$vpw_cfun AddHSVSegment 0.0 0.2 1.0 1.0 255.0 0.8 1.0 1.0
#$vpw_cfun AddHSVSegment 80 0.8 1.0 1.0 130.0 0.1 1.0 1.0
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 volumeProperty
$vpw SetVolumeProperty $vpw_vp
$vpw SetWindowLevel 565 565
#Create volume
vtkVolume volume
volume SetMapper volumeMapper
volume SetProperty $vpw_vp
#Render volume
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
#Command linked to volume property widget used in order to update volume
property in real-time
$vpw SetVolumePropertyChangedCommand $rw "Render"
$vpw SetVolumePropertyChangingCommand $rw "Render"
# 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/20110509/cae86af1/attachment.htm>
More information about the vtkusers
mailing list