[vtkusers] using VTK with keyboard interaction

Jonas cv Fan work2compilation at gmail.com
Tue Mar 27 05:08:07 EDT 2012


Dear vtk users,

I'm newbie in VTK library. I decided to use it as a renderer of a content
captured by the Kinect sensor. I grab first the depth maps using opencv
after that I render it by VTK. All working fine until now. However I wanna
add some keyboard buttons to interact easily with the displayed content (3D
cloud): it's really basic:

1-Push '*d*' to display the 3D point cloud by VTK.
2-Push *'k*' to return to default camera settings.
3-Push '*q*' to quite.

here is a snapping code that I wrote:

// VTK headers
*#include <vtkSmartPointer.h>
.... etc*
*int main()
{*

// 3D rendering rotines

               //VTK Pipeline
               *vtkSmartPointer<vtkRenderer> ren =
vtkSmartPointer<vtkRenderer>::
New();
               renwin = vtkSmartPointer<vtkRenderWindow>::New();
               renwin1 = vtkSmartPointer<vtkRenderWindow>::New();

               vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();

               renwin->AddRenderer(ren);
               renwin->SetInteractor(iren);
               renwin->SetSize(1280,800);
               iren->Initialize();*

// Main loop
       while (1)
// To capture the content from the kinect
.....
key= cvWaitKey(1);  // for opencv capture

*if (key == 'q')* break;            // To quite
               switch(key) {
           /* '1' pressed, display the original image */
         *  case 'd':*
               cout<<"The decomposition is running..."<<endl;

                       Display_cloud( renwin,pDepthMap);  // a function to
display a cloud
points
                        renwin->Render();

                       //Set up camera
                       ren->ResetCamera();
                       ren->GetActiveCamera()->Roll(180.0);
                       ren->GetActiveCamera()->Azimuth(180.0);
                       ren->GetActiveCamera()->Zoom(2.0);

                       iren->Start();

      *case 'k':*           //  to return to default camera settings.
               ren->ResetCamera();
                       ren->GetActiveCamera()->Roll(180.0);
                       ren->GetActiveCamera()->Azimuth(180.0);
                       ren->GetActiveCamera()->Zoom(2.0);

                       iren->Start();
               break;
}
}

So I have two problems:
1-When I push *'q'* the program doesn't close correctly, visual studio send
me to the vtkInformation.cxx to the line " *i->first->Report(this,
collector);*"  in "void
*vtkInformation::ReportReferences(vtkGarbageCollector* collector)"*
function?!
How can I avoid that?

2-When push 'k' to return to default camera paramters it doesn't work..
could you help me please?
Thank you so much and sorry if my post is very long for you .

Cheers for everyone
Jo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120327/fb1bde2f/attachment.htm>


More information about the vtkusers mailing list