[vtkusers] magnifier

fernando hierro spanish_vtk at hotmail.com
Sun Feb 24 12:36:25 EST 2002


I am using vtk with tcl

How I can capture with the cursor of the mouse the parts of an image
and remove them to see extended them in widget???.

In widget of the right I want to see the zoom lens of all slice when I
do click with middleMouse (or Shift-LeftMouse) on the image of the left.


pleasepleasepleasepleasepleasepleasepleasepleasepleasepleasepleaseplease

I have this:

set CURSOR_X 20
set CURSOR_Y 20
set CURSOR_Z 20

set IMAGE_MAG_X 4
set IMAGE_MAG_Y 4
set IMAGE_MAG_Z 1

wm withdraw .
toplevel .top

set help [label .top.help -text "MiddleMouse (or shift-LeftMouse) in image 
viewer to place cursor"]
set displayFrame [frame .top.f1]
set quitButton [button .top.btn  -text Quit -command exit]
pack $help
pack $displayFrame -fill both -expand t
pack $quitButton -fill x
set viewerFrame [frame $displayFrame.vFm]
set rendererFrame [frame $displayFrame.rFm]
pack $viewerFrame -padx 3 -pady 3 -side left -fill both -expand f    pack 
$rendererFrame -padx 3 -pady 3 -side left -fill both -expand t
set viewerWidget [vtkTkImageViewerWidget $viewerFrame.v -width 264 -height 
264]
set viewerControls [frame $viewerFrame.c]
pack $viewerControls $viewerWidget -side bottom -fill both -expand f
set downButton [button $viewerControls.down -text "Down" -command 
"ViewerDown"]
set upButton [button $viewerControls.up -text "Up" -command "ViewerUp"]
set sliceLabel [label $viewerControls.slice -text "slice: [expr $CURSOR_Z * 
$IMAGE_MAG_Z]"]
pack $downButton $upButton $sliceLabel -side left -expand t -fill both

vtkRenderWindow renWinx
set renderWidget [vtkTkRenderWidget $rendererFrame.r -width 264 -height 264 
-rw renWinx]
pack $renderWidget -side top

vtkImageReader reader
[reader GetOutput] ReleaseDataFlagOff
reader SetDataByteOrderToLittleEndian
reader SetDataExtent 0 63 0 63 1 93
reader SetFilePrefix "/../../vtkdata/Data/headsq/quarter"
reader SetDataMask 0x7fff

vtkImageCursor3D imageCursor
imageCursor SetInput [magnify GetOutput]
imageCursor SetCursorPosition [expr $CURSOR_X * $IMAGE_MAG_X] \
    [expr $CURSOR_Y * $IMAGE_MAG_Y] [expr $CURSOR_Z * $IMAGE_MAG_Z]
imageCursor SetCursorValue 255
imageCursor SetCursorRadius [expr 50 * $IMAGE_MAG_X]

vtkAxes axes
axes SymmetricOn
axes SetOrigin $CURSOR_X $CURSOR_Y $CURSOR_Z
axes SetScaleFactor 50.0;

vtkPolyDataMapper axesMapper
axesMapper SetInput [axes GetOutput]

vtkActor axesActor
axesActor SetMapper axesMapper
[axesActor GetProperty] SetAmbient 0.5

set viewer [$viewerWidget GetImageViewer]
$viewer SetInput [imageCursor GetOutput]
$viewer SetZSlice [expr $CURSOR_Z * $IMAGE_MAG_Z]
$viewer SetColorWindow 256
$viewer SetColorLevel 128

vtkRenderer ren1
set renWin [$renderWidget GetRenderWindow]
    $renWin AddRenderer ren1
    $renWin SetSize 256 256

proc TkCheckAbort {} {
  global renWin
  set foo [$renWin GetEventPending]
  if {$foo != 0} {$renWin SetAbortRender 1}
}
$renWin AddObserver AbortCheckEvent {TkCheckAbort}



BindTkImageViewer $viewerWidget
BindTkRenderWidget $renderWidget

# lets ass an extra binding of the middle button in the image viewer
# to set the cursor location
bind $viewerWidget <Button-2> {SetCursorFromViewer %x %y}
bind $viewerWidget <Shift-Button-1> {SetCursorFromViewer %x %y}



# supporting procedures



proc ViewerDown {} {
    global viewer
    set z [$viewer GetZSlice]
    ViewerSetZSlice $viewer [expr $z - 1]
}

proc ViewerUp {} {
    global viewer
    set z [$viewer GetZSlice]
    ViewerSetZSlice $viewer [expr $z + 1]
}

proc ViewerSetZSlice {viewer z} {
    global sliceLabel
    $viewer SetZSlice $z
    $sliceLabel configure -text "slice: $z"
    $viewer Render
}


proc SetCursorFromViewer {x y} {
    global viewer viewerWidget
    global IMAGE_MAG_X IMAGE_MAG_Y IMAGE_MAG_Z

    # we have to flip y axis because tk uses upper right origin.
    set height [lindex [$viewerWidget configure -height] 4]
    set y [expr $height - $y]
    set z [$viewer GetZSlice]
    SetCursor [expr $x / $IMAGE_MAG_X] [expr $y / $IMAGE_MAG_Y] \
	[expr $z / $IMAGE_MAG_Z]
}

proc SetCursor {x y z} {
    global viewer renWin
    global CURSOR_X CURSOR_Y CURSOR_Z IMAGE_MAG_X IMAGE_MAG_Y IMAGE_MAG_Z

    set CURSOR_X $x
    set CURSOR_Y $y
    set CURSOR_Z $z
    axes SetOrigin $CURSOR_X $CURSOR_Y $CURSOR_Z
    imageCursor SetCursorPosition [expr $CURSOR_X * $IMAGE_MAG_X] \
	[expr $CURSOR_Y * $IMAGE_MAG_Y] [expr $CURSOR_Z * $IMAGE_MAG_Z]
    $viewer Render
    $renWin Render
}

pleasepleasepleasepleasepleasepleasepleasepleasepleasepleasepleaseplease





_________________________________________________________________
Hable con sus amigos en línea, pruebe MSN Messenger: http://messenger.msn.es




More information about the vtkusers mailing list