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