[vtkusers] Live updating volume properties using KWWidgets and Tcl

Georg Ziegler gziegler at mail.zserv.tuwien.ac.at
Tue Apr 12 17:03:42 EDT 2011


actually I think you only have to listen for modified events from vtkVolumeProperty or the piecewise functions or the vtkkwvolumepropertywidget (not sure at the moment, just try)

the following code listens for Modified events on your volume property. i'm no tcl expert, but maybe this helps you anyway.

proc RenderAfterChange {} {
	rw Render
}

vpw_vp AddObserver ModifiedEvent {RenderAfterChange}


take a look at this example where events are used at the very end.
http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/VolumeRendering/Tcl/SimpleRayCast.tcl

regards, georg

Am 12.04.2011 um 22:22 schrieb pablo p del castillo:

> You can use a socket to update in real time.
> 
> In google tcl socket
> 
> Pablo
> 
> --- El mar, 12/4/11, Jason K Wang <jkwang01 at syr.edu> escribió:
> 
> De: Jason K Wang <jkwang01 at syr.edu>
> Asunto: [vtkusers] Live updating volume properties using KWWidgets and Tcl
> Para: "vtkusers at vtk.org" <vtkusers at vtk.org>
> Fecha: martes, 12 de abril, 2011 18:23
> 
> Hello all,
> 
> Sorry for the multiple messages, but, to reiterate my problem: I would like to have the volume properties be updated in real-time as you are adjusting the sliders. Basically, how do I directly connect these KWWidgets to the data? I am new to Tcl and VTK, so, absolutely any help I can get is appreciated. What does the "set app" command do? Do I need to set the VTK volume property widget as an app?
> 
> Jason,
> From: Jason K Wang
> Sent: Tuesday, April 12, 2011 9:41 AM
> To: vtkusers at vtk.org
> Subject: Live updating volume properties using KWWidgets and Tcl
> 
> 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
> 
> -----Adjunto en línea a continuación-----
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110412/54e7ad68/attachment.htm>


More information about the vtkusers mailing list