Thank you so much David for your help and your generous explanations :).<br>Well I follow the code to define a style to interact with the point cloud that I render. I made a simple example of a style class which if I press 'a' button the camera parameters restores to default parameter, but I don't see any change :(, here is my class: <br>
<br><br>// Define interaction style<br>class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera<br>{<br> public:<br> static KeyPressInteractorStyle* New();<br> vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyleTrackballCamera);<br>
<br> virtual void OnKeyPress() <br> {<br> // Get the keypress<br> vtkRenderWindowInteractor *rwi = this->Interactor;<br> char key = rwi->GetKeyCode() ;<br> <br> switch (key)<br> {<br> case 'a':<br>
ren->ResetCamera(); // To restore the camera parameters <br> break;<br> }<br> <br> // Forward events<br> vtkInteractorStyleTrackballCamera::OnKeyPress();<br>
}<br> <br>};<br>vtkStandardNewMacro(KeyPressInteractorStyle);<br><br><br>int main()<br>{<br><br>//I use this class to define my style of interaction <br><br><br>}<br><br>Thank you so much<br><br><br><br><div class="gmail_quote">
On Tue, Mar 27, 2012 at 2:19 PM, David Doria-2-3 [via VTK] <span dir="ltr"><<a href="/user/SendEmail.jtp?type=node&node=5597967&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">
        On Tue, Mar 27, 2012 at 5:08 AM, Jonas cv Fan
<br></div><div><div class="h5"><<a href="http://user/SendEmail.jtp?type=node&node=5597676&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>> wrote:
<div><div class='shrinkable-quote'><br>> Dear vtk users,
<br>>
<br>> I'm newbie in VTK library. I decided to use it as a renderer of a content
<br>> captured by the Kinect sensor. I grab first the depth maps using opencv
<br>> after that I render it by VTK. All working fine until now. However I wanna
<br>> add some keyboard buttons to interact easily with the displayed content (3D
<br>> cloud): it's really basic:
<br>>
<br>> 1-Push '*d*' to display the 3D point cloud by VTK.
<br>> 2-Push *'k*' to return to default camera settings.
<br>> 3-Push '*q*' to quite.
<br>>
<br>> here is a snapping code that I wrote:
<br>>
<br>> // VTK headers
<br>> *#include <vtkSmartPointer.h>
<br>> .... etc*
<br>> *int main()
<br>> {*
<br>>
<br>> // 3D rendering rotines
<br>>
<br>> //VTK Pipeline
<br>> *vtkSmartPointer<vtkRenderer> ren =
<br>> vtkSmartPointer<vtkRenderer>::
<br>> New();
<br>> renwin = vtkSmartPointer<vtkRenderWindow>::New();
<br>> renwin1 = vtkSmartPointer<vtkRenderWindow>::New();
<br>>
<br>> vtkSmartPointer<vtkRenderWindowInteractor> iren =
<br>> vtkSmartPointer<vtkRenderWindowInteractor>::New();
<br>>
<br>> renwin->AddRenderer(ren);
<br>> renwin->SetInteractor(iren);
<br>> renwin->SetSize(1280,800);
<br>> iren->Initialize();*
<br>>
<br>> // Main loop
<br>> while (1)
<br>> // To capture the content from the kinect
<br>> .....
<br>> key= cvWaitKey(1); // for opencv capture
<br>>
<br>> *if (key == 'q')* break; // To quite
<br>> switch(key) {
<br>> /* '1' pressed, display the original image */
<br>> * case 'd':*
<br>> cout<<"The decomposition is running..."<<endl;
<br>>
<br>> Display_cloud( renwin,pDepthMap); // a function to
<br>> display a cloud
<br>> points
<br>> renwin->Render();
<br>>
<br>> //Set up camera
<br>> ren->ResetCamera();
<br>> ren->GetActiveCamera()->Roll(180.0);
<br>> ren->GetActiveCamera()->Azimuth(180.0);
<br>> ren->GetActiveCamera()->Zoom(2.0);
<br>>
<br>> iren->Start();
<br>>
<br>> *case 'k':* // to return to default camera settings.
<br>> ren->ResetCamera();
<br>> ren->GetActiveCamera()->Roll(180.0);
<br>> ren->GetActiveCamera()->Azimuth(180.0);
<br>> ren->GetActiveCamera()->Zoom(2.0);
<br>>
<br>> iren->Start();
<br>> break;
<br>> }
<br>> }
<br>>
<br>> So I have two problems:
<br>> 1-When I push *'q'* the program doesn't close correctly, visual studio send
<br>> me to the vtkInformation.cxx to the line " *i->first->Report(this,
<br>> collector);*" in "void
<br>> *vtkInformation::ReportReferences(vtkGarbageCollector* collector)"*
<br>> function?!
<br>> How can I avoid that?
<br>>
<br>> 2-When push 'k' to return to default camera paramters it doesn't work..
<br>> could you help me please?
<br>> Thank you so much and sorry if my post is very long for you .
<br>>
<br>> Cheers for everyone
<br>> Jo
</div></div></div></div><div class="im">I wrote something similar for a different time of flight camera:
<br><a href="https://github.com/daviddoria/vtkHokuyo" rel="nofollow" link="external" target="_blank">https://github.com/daviddoria/vtkHokuyo</a><br><br>I'm not sure if there is any benefit of using a VTK timer like I did
<br>versus your while(1) loop.
<br><br>Also, it looks like you have taken a "get the data, then draw it"
<br>approach. In VTK the idea would change to "display the data always,
<br>and update it when necessary". You use an "InteractorStyle" to handle
<br>the keypress events:
<br><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/KeypressEvents" rel="nofollow" link="external" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/KeypressEvents</a><br><br>To update the display once you get new data, you would just update the
<br>PolyData that is already attached to a mapper->actor->renderer (and
<br>call Modified() on it if necessary) and the renderer would
<br>automatically display the new points.
<br><br>Additionally, you could check out PCL (<a href="http://pointclouds.org" target="_blank" rel="nofollow" link="external">pointclouds.org</a>) - I think they
<br>already have this sort of thing written for the Kinect.
<br><br>Good luck,
<br><br>David
<br></div>_______________________________________________
<br>Powered by <a href="http://www.kitware.com" target="_blank" rel="nofollow" link="external">www.kitware.com</a>
<br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="nofollow" link="external" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="nofollow" link="external" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:
<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" rel="nofollow" link="external" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
        
        <br>
        <br>
        <hr color="#cccccc" noshade size="1">
        <div style="color:#444;font:12px tahoma,geneva,helvetica,arial,sans-serif">
                <div style="font-weight:bold">If you reply to this email, your message will be added to the discussion below:</div>
                <a href="http://vtk.1045678.n5.nabble.com/using-VTK-with-keyboard-interaction-tp5597328p5597676.html" target="_blank" rel="nofollow" link="external">http://vtk.1045678.n5.nabble.com/using-VTK-with-keyboard-interaction-tp5597328p5597676.html</a>
        </div>
        <div style="color:#666;font:11px tahoma,geneva,helvetica,arial,sans-serif;margin-top:.4em;line-height:1.5em">
                
                To unsubscribe from using VTK with keyboard interaction, <a href="" target="_blank" rel="nofollow" link="external">click here</a>.<br>
                <a href="http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" rel="nofollow" style="font:9px serif" target="_blank" link="external">NAML</a>
        </div></blockquote></div><br>
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/using-VTK-with-keyboard-interaction-tp5597328p5597967.html">Re: using VTK with keyboard interaction</a><br/>
Sent from the <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html">VTK - Users mailing list archive</a> at Nabble.com.<br/>