[vtkusers] location of movable component

Podariu, Silviu spodariu at unmc.edu
Wed Dec 25 13:40:01 EST 2013


Jorge,
I managed, with help from a few other sources, to get that idea written into python. It's exactly what i need, thanks again!

Greg,
Here is a piece of python code in which you can move an object within the renderer and get/write its position ( this helps me because i can move to the point whose coordinates i am wondering about, thereby figuring its location ). I don't know if this helps you, but you were asking about it...

import vtk

def main():

    # -- Jorge Perez's advice, following right after std setup block below,
    # combined with insights about the main tool, vtkFixedSizeHandleRepresentation3D, from
    # http://vtk.org/gitweb?p=VTK.git;a=blob;f=Interaction/Widgets/Testing/Cxx/TestFixedSizeHandleRepresentation3D.Cxx

    # -- std setup part --
    ren=vtk.vtkRenderer()
    # -- add here whatever objects you like to this renderer,
    #    or proceed with an empty scenery and place only the
    #    movable handle.

    windowSize=(800,800)
    title="whatever title here"

    renWind=vtk.vtkRenderWindow()
    renWind.SetWindowName( title )
    renWind.AddRenderer( ren )
    renWind.SetSize( windowSize[0], windowSize[1] )

    iren=vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow( renWind )

    style=vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle( style )
    # -- end std things, before display --

    # -----------------------------------------------
    # -- main part, after all other components ( not
    #    included ) have been added to the renderer,
    #    we place the movable handle and define a
    #    call-back function object to report location
    # -----------------------------------------------
    rep=vtk.vtkFixedSizeHandleRepresentation3D()
    rep.SetHandleSizeInPixels( 10 )
    rep.GetProperty().SetColor( (0.4,0,0) )
    rep.SetWorldPosition( (0,0,0) )

    widget=vtk.vtkHandleWidget()
    widget.SetInteractor( renWind.GetInteractor() )
    widget.SetDefaultRenderer( ren )
    widget.SetRepresentation( rep )

    # -- here we need the callback function object, like 'mcbk' at line
    #    628-631 in the C++ example ( see Execute() defined at lines
    #    566-577, which needs to know about rep. )
    #    A simple python class to serve this purpose is used below
    hcb=HandleCallback( rep )
    widget.AddObserver( 'InteractionEvent', hcb)
    widget.On()

    # -- start the show --
    iren.Initialize()
    iren.Start()

    return


class HandleCallback():
    def __init__(self, rep):
        self.rep=rep
        print "HandleCallback obj built"
    def __call__(self, obj, ev):
        loc=self.rep.GetWorldPosition()
        print "left at: ( %7.2f , %7.2f, %7.2f )" % ( loc )
        return


main()



________________________________
From: vtkusers-bounces at vtk.org [vtkusers-bounces at vtk.org] on behalf of Podariu, Silviu [spodariu at unmc.edu]
Sent: Thursday, December 19, 2013 8:07 PM
To: Jorge Perez
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] location of movable component


Thank you Jorge,

I have been trying to convert the Tcl to Python; still working on it...  :)

Silviu

________________________________
From: Jorge Perez [josp.jorge at gmail.com]
Sent: Monday, December 16, 2013 3:46 AM
To: Podariu, Silviu
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] location of movable component

Hi, you can use vtkHandleWidget

http://www.vtk.org/doc/nightly/html/classvtkHandleWidget.html#details

below is a simple example in Tcl, the position is printed in standard output.

package require vtk
package require vtkinteraction

# this proc will be invoked during widget interaction
proc OnInteraction { r } {
  set pos [$r GetWorldPosition]
  puts "pos = $pos"
}

vtkTkRenderWidget .tkrw
::vtk::bind_tk_render_widget .tkrw

set renWin [.tkrw GetRenderWindow]

vtkRenderer ren
ren SetBackground 0.0 0.4 0.5

$renWin AddRenderer ren

# create the widget representation
vtkFixedSizeHandleRepresentation3D rep
rep SetHandleSizeInPixels 10
[rep GetProperty] SetColor 1 0 0
rep SetWorldPosition 0 0 0

# create the widget
vtkHandleWidget widget
widget SetInteractor [$renWin GetInteractor]
widget SetDefaultRenderer ren
widget SetRepresentation rep
# add the interaction observer
widget AddObserver InteractionEvent {OnInteraction rep}
after idle {widget On}

pack .tkrw -fill both -expand yes



2013/12/13 Podariu, Silviu <spodariu at unmc.edu<mailto:spodariu at unmc.edu>>

Hello,

Is there a way of adding a little component in space ( point, sphere, cube ), which can be moved interactively ( with the mouse/arrows/keys ) and whose location at any time can be displayed in the terminal ( or on the renderer window itself )?

Thanks,
Silviu



The information in this e-mail may be privileged and confidential, intended only for the use of the addressee(s) above. Any unauthorized use or disclosure of this information is prohibited. If you have received this e-mail by mistake, please delete it and immediately contact the sender.

_______________________________________________
Powered by www.kitware.com<http://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/20131225/1bd7a33f/attachment.htm>


More information about the vtkusers mailing list