[vtkusers] Question for C++ Gurus!

Obada Mahdi omahdi at gmx.de
Wed Mar 22 13:32:52 EST 2006


Hi Jess,

all callback handlers are passed the "void* clientdata" parameter, which is a
means to provide some kind of context to such handlers.  For every callback
instance, you can set what this pointer should be using the
"SetClientData(void*)" function of vtkCallbackCommand.

Assuming that the code snippet below is from an instance method of
"CSdiogl2View" and "this" being the pointer you would like to access in your
callback handler, you could do something like this:

On Wed, 22 Mar 2006, Jessica Weiner wrote:
> vtkCallbackCommand * keypressCB = vtkCallbackCommand::New();
> keypressCB->SetCallback(&CSdiogl2View::myKeyPressCallback);

keypressCB->SetClientData(this);

>
> style = vtkInteractorStyleTrackballActor::New();
> style->AddObserver(vtkCommand::LeftButtonReleaseEvent,keypressCB);
> iren->SetInteractorStyle(style);

And within the callback handler:

void
CSdiogl2View::myKeyPressCallback(
 	vtkObject *caller, unsigned long eid,
 	void *clientdata, void *calldata)
{
 	CSdiogl2View* parentView = static_cast<CSdiogl2View*>(clientdata);
 	// ...
}


HTH,

Obada



More information about the vtkusers mailing list