[vtkusers] obtaining reference to calling class in KeyPressInteractorStyle class
David Doria
daviddoria+vtk at gmail.com
Fri Feb 12 09:23:35 EST 2010
On Thu, Feb 11, 2010 at 6:38 PM, Liam Kurmos <quantum.leaf at googlemail.com>wrote:
> I gave up trying to implement a seperate KeyPressInteractorStyle class
> to detect keypresses as i couldn't get a reference to the calling
> class.
>
> instead I looked at
> http://vtk.org/Wiki/VTK/Examples/KeypressObserver
>
> and trying to make a local call back function in my class. The example
> doesn't use classes so i adapted it by making the callback function a
> local function in my class.
> However when i do this i get a compile error:
>
> In member function ‘void vasFrame::interact()’:
> /home/zoizoi/sunLoom/psyforge/VAS/vasFrame.cpp:432: error: no matching
> function for call to ‘vtkCallbackCommand::SetCallback(<unresolved
> overloaded function type>)’
> /usr/local/include/vtk-5.4/vtkCallbackCommand.h:61: note: candidates
> are: virtual void vtkCallbackCommand::SetCallback(void (*)(vtkObject*,
> long unsigned int, void*, void*))
>
> from the line:
> keypressCallback->SetCallback ( this->KeypressCallbackFunction );
>
> i can't see whats wrong with my call back function, why it is deemed
> '<unresolved overloaded function type>' it's the same as the example
> except it's now a class method called with this->
>
> Can anyone help?
> if this is a general c++ issue any guidance on what to google would be
> appreciated too.
>
> Liam
>
>
> On Tue, Feb 9, 2010 at 7:34 PM, Liam Kurmos <quantum.leaf at googlemail.com>
> wrote:
> > Hi All,
> >
> > I'm trying to implement key press detection.
> >
> > I followed http://vtk.org/Wiki/VTK/Examples/Interaction/KeypressEvents
> > and made an external class KeyPressInteractorStyle.
> >
> > I have no problem getting the OnKeyPress event to fire as per the
> > example, but I can't seem to get a reference to the calling class (i
> > want to change an isovalue on keypress).
> >
> > I can't include the calling class (#include "vasFrame.h") as this
> > would create a cyclic dependency, so I tried making a forward
> > declaration of the class and using a function to pass the value.
> >
> > class vasFrame;
> > class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
> > {
> > public:
> > static KeyPressInteractorStyle* New();
> > virtual void OnKeyPress();
> > void passFrameRef(vasFrame* frame);
> > vasFrame* frame;
> > };
> >
> > But this class won't compile, complaining of a forward declaration to
> > incomplete struct vasFrame.
> >
> > This is probably trivial and a straight forward c++ pattern but i
> > can't seem to get.
> > Can anyone tell me the normal vtk way to do this?
> >
> > regards,
> >
> > Liam
>
>
Liam,
I believe you are really never supposed to #include a cpp file.
The way that you get a reference to the calling class is to add a member
variable to the interactor style.
class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static KeyPressInteractorStyle* New();
virtual void OnKeyPress();
void SetContourFilter(vtkSmartPointer<vtkContourFilter> filter)
{this->Filter = filter;}
private:
vtkSmartPointer<vtkContourFilter> Filter;
};
Then when you instantiate the style, you set that ivar:
vtkSmartPointer<vtkContourFilter> filter =
vtkSmartPointer<vtkContourFilter>::New();
... use the filter ...
vtkSmartPointer<KeyPressInteractorStyle> style =
vtkSmartPointer<KeyPressInteractorStyle>::New();
style->SetContourFilter(filter);
renderWindowInteractor->SetInteractorStyle( style );
Now you have a pointer inside the Interactor that you can use inside the
OnKeyPress function.
Hope that helps.
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100212/13cb95bc/attachment.htm>
More information about the vtkusers
mailing list