<div class="gmail_quote">On Thu, Feb 11, 2010 at 6:38 PM, Liam Kurmos <span dir="ltr">&lt;<a href="mailto:quantum.leaf@googlemail.com">quantum.leaf@googlemail.com</a>&gt;</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&#39;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&#39;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(&lt;unresolved<br>
overloaded function type&gt;)’<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-&gt;SetCallback ( this-&gt;KeypressCallbackFunction );<br>
<br>
i can&#39;t see whats wrong with my call back function, why it is deemed<br>
&#39;&lt;unresolved overloaded function type&gt;&#39; it&#39;s the same as the example<br>
except it&#39;s now a class method called with this-&gt;<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 &lt;<a href="mailto:quantum.leaf@googlemail.com">quantum.leaf@googlemail.com</a>&gt; wrote:<br>
&gt; Hi All,<br>
&gt;<br>
&gt; I&#39;m trying to implement key press detection.<br>
&gt;<br>
&gt; I followed <a href="http://vtk.org/Wiki/VTK/Examples/Interaction/KeypressEvents" target="_blank">http://vtk.org/Wiki/VTK/Examples/Interaction/KeypressEvents</a><br>
&gt; and made an external class KeyPressInteractorStyle.<br>
&gt;<br>
&gt; I have no problem getting the OnKeyPress event to fire as per the<br>
&gt; example, but I can&#39;t seem to get a reference to the calling class (i<br>
&gt; want to change an isovalue on keypress).<br>
&gt;<br>
&gt; I can&#39;t include the calling class (#include &quot;vasFrame.h&quot;) as this<br>
&gt; would create a cyclic dependency, so I tried making a forward<br>
&gt; declaration of the class and using a function to pass the value.<br>
&gt;<br>
&gt; class vasFrame;<br>
&gt; class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera<br>
&gt; {<br>
&gt;  public:<br>
&gt;    static KeyPressInteractorStyle* New();<br>
&gt;    virtual void OnKeyPress();<br>
&gt;    void passFrameRef(vasFrame* frame);<br>
&gt;    vasFrame* frame;<br>
&gt; };<br>
&gt;<br>
&gt; But this class won&#39;t compile, complaining of a forward declaration to<br>
&gt; incomplete struct vasFrame.<br>
&gt;<br>
&gt; This is probably trivial and a straight forward c++ pattern but i<br>
&gt; can&#39;t seem to get.<br>
&gt; Can anyone tell me the normal vtk way to do this?<br>
&gt;<br>
&gt; regards,<br>
&gt;<br>
&gt; 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&lt;vtkContourFilter&gt; filter) {this-&gt;Filter = filter;}</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">  private:  </div><div class="gmail_quote">    vtkSmartPointer&lt;vtkContourFilter&gt; 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&lt;vtkContourFilter&gt; filter = vtkSmartPointer&lt;vtkContourFilter&gt;::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&lt;KeyPressInteractorStyle&gt; style = </div><div class="gmail_quote">
    vtkSmartPointer&lt;KeyPressInteractorStyle&gt;::New();</div><div class="gmail_quote">style-&gt;SetContourFilter(filter);</div><div class="gmail_quote"><br></div><div class="gmail_quote">renderWindowInteractor-&gt;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>