[vtkusers] Templated class members as callbacks for vtkCommand?

Parag Chandra pchandra at radonc.unc.edu
Thu Apr 17 12:25:00 EDT 2003


Hi all,

 

I'm trying to attach a templated member function as the callback for an
event in VTK. I searched the mailing list and found that I either had to
make the member static, or call the member function indirectly through a
plain C function. I chose the second approach because the first won't
work for my purposes, so my code looks something like this:

 

static void

HistogramInteractorProcessPickEvent(vtkObject *object, unsigned long
event, 

                                    void *clientData, void *callData)

{

    static_cast<HistogramInteractor<itk::Image<double,2>
>*>(object)->ProcessPickEvent(object,

        event, clientData, callData);

}

 

Then inside the class, I do the following:

 

 
m_PickEventCommand->SetCallback(&HistogramInteractorProcessPickEvent);

    this->RemoveObservers(vtkCommand::LeftButtonPressEvent);

    this->AddObserver(vtkCommand::LeftButtonPressEvent,
m_PickEventCommand);

 

where m_PickEventCommand is a vtkCallbackCommand. This works fine;
however, what I'd really like to do is have the C function above be
templated over the type of the itk Image, so something like:

 

template <class TInputImage>

static void

HistogramInteractorProcessPickEvent(vtkObject *object, unsigned long
event, 

                                    void *clientData, void *callData)

{

 
static_cast<HistogramInteractor<TInputImage>*>(object)->ProcessPickEvent
(object,

        event, clientData, callData);

}

 

This generates an error during compilation under both MSVC6 and Linux
gcc3.2, something akin to:

 

C:\development\aks\Code\Visualization\aksHistogramInteractor.cxx(68) :
error C2664: 'SetCallback' : cannot convert parameter 1 from 'void
(class vtkObject *,unsigned long,void *,void *)' to 'void (__cdecl
*)(class vtkObject *,unsigned long,void *,void *)'

 

Is there any way to make the scenario I described above work? I had a
much easier time defining callbacks under ITK, so it seems like there
should be some way to do it under VTK as well. Thanks in advance.

 

Best regards,

-Parag Chandra

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030417/36b7742e/attachment.htm>


More information about the vtkusers mailing list