[vtkusers] using VTK with keyboard interaction
dev
work2compilation at gmail.com
Tue Mar 27 10:12:12 EDT 2012
Thank you so much David for your help and your generous explanations :).
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:
// Define interaction style
class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static KeyPressInteractorStyle* New();
vtkTypeMacro(KeyPressInteractorStyle,
vtkInteractorStyleTrackballCamera);
virtual void OnKeyPress()
{
// Get the keypress
vtkRenderWindowInteractor *rwi = this->Interactor;
char key = rwi->GetKeyCode() ;
switch (key)
{
case 'a':
ren->ResetCamera(); // To
restore the camera parameters
break;
}
// Forward events
vtkInteractorStyleTrackballCamera::OnKeyPress();
}
};
vtkStandardNewMacro(KeyPressInteractorStyle);
int main()
{
//I use this class to define my style of interaction
}
Thank you so much
On Tue, Mar 27, 2012 at 2:19 PM, David Doria-2-3 [via VTK] <
ml-node+s1045678n5597676h41 at n5.nabble.com> wrote:
> On Tue, Mar 27, 2012 at 5:08 AM, Jonas cv Fan
> <[hidden email] <http://user/SendEmail.jtp?type=node&node=5597676&i=0>>
> wrote:
>
> > 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
>
> I wrote something similar for a different time of flight camera:
> https://github.com/daviddoria/vtkHokuyo
>
> I'm not sure if there is any benefit of using a VTK timer like I did
> versus your while(1) loop.
>
> Also, it looks like you have taken a "get the data, then draw it"
> approach. In VTK the idea would change to "display the data always,
> and update it when necessary". You use an "InteractorStyle" to handle
> the keypress events:
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/KeypressEvents
>
> To update the display once you get new data, you would just update the
> PolyData that is already attached to a mapper->actor->renderer (and
> call Modified() on it if necessary) and the renderer would
> automatically display the new points.
>
> Additionally, you could check out PCL (pointclouds.org) - I think they
> already have this sort of thing written for the Kinect.
>
> Good luck,
>
> David
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://vtk.1045678.n5.nabble.com/using-VTK-with-keyboard-interaction-tp5597328p5597676.html
> To unsubscribe from using VTK with keyboard interaction, click here<http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5597328&code=d29yazJjb21waWxhdGlvbkBnbWFpbC5jb218NTU5NzMyOHwxOTg0NjI3NDAx>
> .
> NAML<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>
>
--
View this message in context: http://vtk.1045678.n5.nabble.com/using-VTK-with-keyboard-interaction-tp5597328p5597967.html
Sent from the VTK - Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120327/8fbb64e4/attachment.htm>
More information about the vtkusers
mailing list