[vtkusers] RE: Question for C++ Gurus
Hentschel, Bernd
hentschel at rz.rwth-aachen.de
Thu Mar 23 04:01:41 EST 2006
Hi Jessica,
I see two possible solutions for your problem (NOTE: I didn't try them
for myself, so I'm not all that sure they work):
1) Use the void *ClientData ivar to pass a pointer to your CSdiogl2View
object along to your callback. In VTK4.2 the ivar is public, in VTK5
there're dedicated access methods for it. From what I see in the code,
the ClientData pointer is always passed to the callback upon invocation.
Since you exactly know what it is, you can static_cast<>() it to
CSdiogl2View and call whatever you need.
2) Write an own vtkCommand implementation altogether, i.e. a concrete
class derived from vtkCommand, which implements all the necessary
behavior. It's not all that tricky, since you just have to redefine the
Execute(...) method according to your needs. I think this would be the
"clean" way to play it.
Regards,
Bernd
------------------------------
Message: 27
Date: Wed, 22 Mar 2006 10:45:05 -0600
From: "Jessica Weiner" <suspended at gmail.com>
Subject: [vtkusers] Question for C++ Gurus!
To: <vtkusers at vtk.org>
Message-ID: <000101c64dcf$f9785620$4701a8c0 at death>
Content-Type: text/plain; charset="us-ascii"
I am capturing left mouse click events in my vtk scene. Whenever the
left
mouse button is released I want to change the vtk scene somehow. My
event
handler method (myKeyPressCallback) is a static method and therefor it
does
not have access to the variables of the class it belongs to. I would
like to
have a pointer to the parent class (CSdiogl2View) inside the event
handler
which has all the actors. How can this be done? I have written my code
like
this:
vtkCallbackCommand * keypressCB = vtkCallbackCommand::New();
keypressCB->SetCallback(&CSdiogl2View::myKeyPressCallback);
style = vtkInteractorStyleTrackballActor::New();
style->AddObserver(vtkCommand::LeftButtonReleaseEvent,keypressCB);
iren->SetInteractorStyle(style);
Thanks.
Jess
More information about the vtkusers
mailing list