[vtkusers] Re: vtkImagePlaneWidgets texture update
dean.inglis at camris.ca
dean.inglis at camris.ca
Tue Feb 22 15:39:53 EST 2005
Stefan,
I was tinkering a bit and came up with
this tcl demo. For your purposes, you
will likely want to control the camera
in the 2nd (follower window) differently.
good luck,
Dean
#-------------------------------------------
package require vtk
package require vtkinteraction
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
v16 Update
# An outline is shown for context.
#
vtkOutlineFilter outline
outline SetInput [v16 GetOutput]
vtkPolyDataMapper outlineMapper
outlineMapper SetInput [outline GetOutput]
vtkActor outlineActor
outlineActor SetMapper outlineMapper
# create two image plane widgets: one to lead, one to follow
#
vtkImagePlaneWidget ipw
ipw DisplayTextOn
ipw SetInput [v16 GetOutput]
ipw SetPlaneOrientationToXAxes
ipw SetSliceIndex 32
set prop1 [ipw GetPlaneProperty]
$prop1 SetColor 1 0 0
vtkImagePlaneWidget ipw2
ipw2 DisplayTextOn
ipw2 SetInput [v16 GetOutput]
ipw2 SetPlaneOrientationToXAxes
ipw2 SetSliceIndex 32
set prop2 [ipw2 GetPlaneProperty]
$prop2 SetColor 1 0 0
# share window level
#
ipw2 SetLookupTable [ipw GetLookupTable]
vtkRenderWindowInteractor iren
vtkInteractorStyleTrackballCamera style
iren SetInteractorStyle style
ipw SetInteractor iren
ipw2 SetInteractor iren
# Create the RenderWindow and Renderer
#
vtkRenderer ren1
ren1 SetViewport 0 0 0.5 1
ren1 SetBackground 0.2 0.2 0.6
vtkRenderer ren2
ren2 SetViewport 0.5 0 1 1
ren2 SetBackground 0.1 0.5 0.6
vtkRenderWindow renWin
renWin AddRenderer ren1
renWin AddRenderer ren2
iren SetRenderWindow renWin
ren1 AddActor outlineActor
ipw SetDefaultRenderer ren1
ipw SetCurrentRenderer ren1
ipw On
ipw2 SetDefaultRenderer ren2
ipw2 SetCurrentRenderer ren2
ipw2 On
# trick to stop 2nd widget from pushing
#
ipw2 SetLeftButtonAction 0
ipw2 SetMiddleButtonAction 0
ipw2 SetRightButtonAction 2
# control the position of 2nd widget based on first + some camera tricks
#
ipw AddObserver InteractionEvent Update
# Add the outline actor to the renderer, set the background color and size
#
ren1 AddActor outlineActor
renWin SetSize 800 400
renWin Render
set cam1 [ren1 GetActiveCamera]
$cam1 Azimuth 90
$cam1 Roll 90
set cam2 [ren2 GetActiveCamera]
$cam2 Azimuth 90
$cam2 Roll 90
ipw InvokeEvent InterctionEvent
# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize
# prevent the tk window from showing up then start the event loop
wm withdraw .
proc Update { } {
scan [ipw GetOrigin] "%f %f %f" \
ox oy oz
scan [ipw GetPoint1] "%f %f %f" \
p1x p1y p1z
scan [ipw GetPoint2] "%f %f %f" \
p2x p2y p2z
set ax [expr $p1x - $ox]
set ay [expr $p1y - $oy]
set az [expr $p1z - $oz]
set bx [expr $p2x - $ox]
set by [expr $p2y - $oy]
set bz [expr $p2z - $oz]
set nx [expr $ay*$bz - $az*$by]
set ny [expr $az*$bx - $ax*$bz]
set nz [expr $ax*$by - $ay*$bx]
set n [expr sqrt($nx*$nx + $ny*$ny + $nz*$nz)]
set nx [expr $nx/$n]
set ny [expr $ny/$n]
set nz [expr $nz/$n]
ipw2 SetOrigin $ox $oy $oz
ipw2 SetPoint1 $p1x $p1y $p1z
ipw2 SetPoint2 $p2x $p2y $p2z
ipw2 UpdatePlacement
set vx [expr $ox - $p2x]
set vy [expr $oy - $p2y]
set vz [expr $oz - $p2z]
set fx [expr $p2x*0.5 + $p1x*0.5]
set fy [expr $p2y*0.5 + $p1y*0.5]
set fz [expr $p2z*0.5 + $p1z*0.5]
set camera [ ren2 GetActiveCamera ]
set d [$camera GetDistance]
set px [expr $fx + $d*$nx]
set py [expr $fy + $d*$ny]
set pz [expr $fz + $d*$nz]
$camera SetViewUp $vx $vy $vz
$camera SetFocalPoint $fx $fy $fz
$camera SetPosition $px $py $pz
$camera OrthogonalizeViewUp
ren2 ResetCamera
}
More information about the vtkusers
mailing list