[vtk-developers] Widgets within Widgets & vtkHandleWidget

Dean Inglis dean.inglis at camris.ca
Fri Dec 12 09:47:45 EST 2003


Well, coincidently, I also was thinking about a separate
widget handle class that one could plug in to existing
and new widgets.  The limitiations of spherical handled widgets
prompted me to try do the 2D glyph thing: prior to that
I formed a 2D ring at the intersection of a spherical handle
and whatever plane I was wanting my widget on, which led to a
not so elegant pipeline.  So, I'm all for breaking and
restarting so that something more powerful could be created.

>> vtkButtonWidget. I was thinking that a class like
>> vtkHandleWidget could be
>> created to be used by all widgets to create handles. This
>> thing could have

We could also have vtkHandleWidgetCollection,
vtkHandleWidgetCollectionIterator for widgets like, for example,
vtkSplineWidget, and now vtkImageTracerWidget, wherein the number
of handles is dynamic.  I think another advantage to this would
be that you could have any number of different widgets in a
renderer and do away with SetPriority: the handles pass on the
message to the appropriate widget...

>> this stuff. Thoughts? My major concern is that if adopted, it
>> would affect
>> the API of the current widget set.

>OK, but the widget development is early enough on in it's development
>for us to do some breaking, because those using it are a managable
>subset of everyone I guess.
>However, the ideal solution from my point of view is simply...
>Create a widget Directory parallel to imaging/filtering/graphics/etc,
>start creating a new set of widgets from the base up which form a new
>API. Deprecate all the widgets in Hybrid, but leave them there until 5.0
>and start moving the functionality into the a new architecture/framework
>based around the new classes.

I'm all for this...

>There seem to be distinct of families of widgets...

Yes and there are probably many others waiting to pop out of our
thought bubbles.  This is another good reason the start the API over
along some ptoential new lines: vtkControllerWidget, vtkGeometryWidget...

Attached within is a simple tcl example ( Ken says no commits today :< )
using
vtkImageTracerWidget for anyone wanting to edit /VTK/Hybrid/CMakeLists.txt
and compile the widget into VTK.

Dean

.................................................


package require vtk
package require vtkinteraction

# This example demonstrates how to use the vtkImageTracerWidget
# to trace on a slice of a 3D image dataset on one of its orthogonal planes.
# The button actions and key modifiers are as follows for controlling the
widget:
# 1) left button click over the image, hold and drag draws a free hand line.
# 2) left button click and release erases the widget line,
# if it exists, and repositions the handle
# 3) middle button click starts a snap line.  The snap line can be
terminated
# by clicking the middle button while depressing the ctrl key
# 4) when tracing or snap drawing a line, if the last cursor position is
within
# specified tolerance to the first handle, the widget line will form a
closed
# loop with only one handle
# 5) right button clicking and holding on any handle that is part of a snap
line
# allows handle dragging.  Any existing line segments are updated
accordingly.
# 6) ctrl key + right button down on any handle will erase it. Any existing
snap line
# segments are updated accordingly.  If the line was formed by continous
tracing,
# the line is deleted leaving one handle.
# 7) shift key + right button down on any snap line segment will insert a
handle at
# the cursor position.  The snap line segment is split accordingly.
#

# Start by loading some data.
#

vtkVolume16Reader v16
  v16 SetDataDimensions 64 64
  v16 SetDataByteOrderToLittleEndian
  v16 SetImageRange 1 93
  v16 SetDataSpacing 3.2 3.2 1.5
  v16 SetFilePrefix "$VTK_DATA_ROOT/Data/headsq/quarter"
  v16 Update

  set range [[v16 GetOutput] GetScalarRange]
  set min [lindex $range 0]
  set max [lindex $range 1]
  set diff [expr $max - $min]
  set slope [expr 255.0/$diff]
  set inter [expr -$slope*$min]
  set shift [expr $inter/$slope]

vtkImageShiftScale shifter
  shifter SetShift $shift
  shifter SetScale $slope
  shifter SetOutputScalarTypeToUnsignedChar
  shifter SetInput [v16 GetOutput]
  shifter Update

vtkImageActor imageActor
  imageActor SetInput [shifter GetOutput]
  imageActor VisibilityOn
  imageActor SetDisplayExtent  31 31 0 63 0 92
  imageActor InterpolateOff

  set spc  [[shifter GetOutput] GetSpacing]
  set orig [[shifter GetOutput] GetOrigin]
  set x0   [lindex $orig 0]
  set xspc [lindex $spc 0]
  set pos  [expr $x0 + $xspc*31.0]

# An alternative would be to formulate position in this case by:
# set bounds [imageActor GetBounds]
# set pos [lindex $bounds 0]
#

vtkRenderer ren1
    ren SetBackground 0.4 0.4 0.5

vtkRenderWindow renWin
  renWin AddRenderer ren
  renWin SetSize 400 400

vtkInteractorStyleImage interactor

vtkRenderWindowInteractor iren
  iren SetInteractorStyle interactor
  iren SetRenderWindow renWin

ren AddActor imageActor

# Set up the image tracer widget
#

vtkImageTracerWidget itw
#
# Set the tolerance for capturing last handle when near first handle
# to form closed paths.
#
  itw SetCaptureRadius 1.5
  [itw GetGlyphSource] SetColor 1 0 0
#
# Set the size of the glyph handle
#
  [itw GetGlyphSource] SetScale 1.5
#
# Set the initial rotation of the glyph if desired.  The default glyph
# set internally by the widget is 'a' + so rotating 45 deg. gives a 'x'
#
  itw SetGlyphAngle 45.0
  [itw GetGlyphSource] Modified
  itw ProjectToPlaneOn
  itw SetProjectionNormalToXAxes
  itw SetProjectionPosition $pos
  itw SetProp imageActor
  itw SetInput [shifter GetOutput]
  itw SetInteractor iren
  itw PlaceWidget
#
# When the underlying vtkDataSet is a vtkImageData, the widget can be
# forced to snap to either nearest pixel points, or pixel centers.  Here
# it is turned off.
#
  itw SnapToImageOff
#
# Automatically form closed paths.
#
  itw AutoCloseOn
  itw AddObserver EndInteractionEvent MakeMask
  itw On

# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
renWin Render

[ren GetActiveCamera] SetViewUp 0 1 0
[ren GetActiveCamera] Azimuth 270
[ren GetActiveCamera] Roll 270
ren ResetCameraClippingRange

renWin Render

# Prevent the tk window from showing up then start the event loop.
wm withdraw .





More information about the vtk-developers mailing list