How to get PointPickingCallback to work without pressing shift key? PCLVisualizer

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get PointPickingCallback to work without pressing shift key? PCLVisualizer

Mike6000
This post was updated on .
I have got the PointPickingCallback to work with PCLVisualizer. However I
have to press shift!

This is a system without a keyboard and only a mouse emulating device is
available... There is no way to select shift.

Is there a way to get the PointPickingCallback to work without shift? Either
via inserting some shift key event when clicking with the mouse or via some other clever
tricks?



--
Sent from: http://www.pcl-users.org/
_______________________________________________
PCL-users@pointclouds.org / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to get PointPickingCallback to work without pressing shift key? PCLVisualizer

Sérgio Agostinho

Input event are handled by vtkInteractors. PCLVisualizer has creates one by default but it allows you to specify your custom interactor style through a specific constructor.

Have a look at the vtk documentation for more information on how to override things.

Cheers


On 05-03-2018 13:00, Mike6000 wrote:
I have got the PointPickingCallback to work with PCLVisualizer. However I
have to press shift! 

This is a system without a keyboard and only a mouse emulating device is
available... There is no way to select shift. 

Is there a way to get the PointPickingCallback to work without shift? Either
via inserting some shift when clicking with the mouse or via some other
tricks?



--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to get PointPickingCallback to work without pressing shift key? PCLVisualizer

Mike6000
I tried to put an event filter on the qt window and and modify the access
modifier on the mouse event, however that didn't seem to work.

I think that if I OVERRIDE the
pcl::visualization::PointPickingCallback::Execute member and change the
if ((eventid == vtkCommand::LeftButtonPressEvent) && (iren->GetShiftKey () >
0)) to purely
if ((eventid == vtkCommand::LeftButtonPressEvent))
It could work because then it doesn't check GetShiftKey() anymore.

QUESTION:  
I cant get the override and inheritance to work. Can someone give me a code
example on how I override this function below?:

void
pcl::visualization::PointPickingCallback::Execute (vtkObject *caller,
unsigned long eventid, void*)
{
  PCLVisualizerInteractorStyle *style =
reinterpret_cast<PCLVisualizerInteractorStyle*>(caller);
  vtkRenderWindowInteractor* iren =
reinterpret_cast<pcl::visualization::PCLVisualizerInteractorStyle*>(caller)->GetInteractor
();
  if (style->CurrentMode == 0)
  {
    if ((eventid == vtkCommand::LeftButtonPressEvent) && (iren->GetShiftKey
() > 0))
    {
      float x = 0, y = 0, z = 0;
      int idx = performSinglePick (iren, x, y, z);
      // Create a PointPickingEvent if a point was selected
      if (idx != -1)
      {
        PointPickingEvent event (idx, x, y, z);
        style->point_picking_signal_ (event);
      }
    }
    else if ((eventid == vtkCommand::LeftButtonPressEvent) &&
(iren->GetAltKey () == 1))
    {
      pick_first_ = !pick_first_;
      float x = 0, y = 0, z = 0;
      int idx = -1;
      if (pick_first_)
        idx_ = performSinglePick (iren, x_, y_, z_);
      else
        idx = performSinglePick (iren, x, y, z);
      // Create a PointPickingEvent
      PointPickingEvent event (idx_, idx, x_, y_, z_, x, y, z);
      style->point_picking_signal_ (event);
    }
    // Call the parent's class mouse events
    if (eventid == vtkCommand::LeftButtonPressEvent)
      style->OnLeftButtonDown ();
    else if (eventid == vtkCommand::LeftButtonReleaseEvent)
      style->OnLeftButtonUp ();
  }
  else
  {
    if (eventid == vtkCommand::LeftButtonPressEvent)
    {
      style->OnLeftButtonDown ();
      x_ = static_cast<float> (iren->GetEventPosition ()[0]);
      y_ = static_cast<float> (iren->GetEventPosition ()[1]);
    }
    else if (eventid == vtkCommand::LeftButtonReleaseEvent)
    {
      style->OnLeftButtonUp ();
      std::vector<int> indices;
      int nb_points = performAreaPick (iren, indices);
      AreaPickingEvent event (nb_points, indices);
      style->area_picking_signal_ (event);
    }
  }
}



--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to get PointPickingCallback to work without pressing shift key? PCLVisualizer

Sérgio Agostinho


On 08-03-2018 15:56, Mike6000 wrote:
> I think that if I OVERRIDE the
> pcl::visualization::PointPickingCallback::Execute member and change the
> if ((eventid == vtkCommand::LeftButtonPressEvent) && (iren->GetShiftKey () >
> 0)) to purely
> if ((eventid == vtkCommand::LeftButtonPressEvent))
> It could work because then it doesn't check GetShiftKey() anymore.
That sounds just about right. The Execute method is virtual so it's
begging for that override

> QUESTION:  
> I cant get the override and inheritance to work. Can someone give me a code
> example on how I override this function below?:
>

Why not, what's happening? What have you tried to far?


Cheers



_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to get PointPickingCallback to work without pressing shift key? PCLVisualizer

Mike6000
This post was updated on .
The problem at the moment is that I cant find out IF the checking of the SHIFT key is happening in an underlying VTK Interactor

OR

if the checking of the SHIFT key is happening in the pcl::visualization::PointPickingCallback::Execute (...) function (as I initially believed).


Here are the header and source files to what class / function I initially believed was checking the SHIFT key.

https://github.com/PointCloudLibrary/pcl/blob/master/visualization/include/pcl/visualization/point_picking_event.h

https://https://github.com/PointCloudLibrary/pcl/blob/master/visualization/src/point_picking_event.cpp 


I cannot actually find any instantiation the pcl::visualization::PointPickingCallback class

Nor can I find anything calling the pcl::visualization::PointPickingCallback::Execute(...) function.

First I need to find out what is atually handling the checking of SHIFT.

Can someone answer where the SHIFT key is actually checked when doing a point pick?

 




--
Sent from: http://www.pcl-users.org/
_______________________________________________
PCL-users@pointclouds.org / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to get PointPickingCallback to work without pressing shift key? PCLVisualizer

Sérgio Agostinho

The InteractorStyle classes are responsible for handling user input events. You can see that in this line, the callback gets registered in a PCLVisualizerInteractorStyle class. You can pass your own custom interactor style at construction of PCLVisualizer so this one you can override safely.

The PointPickingCallback class is added automatically as a mouse callback upon initializing the default interactor style.

So to override this behavior your gonna need to:

  1. Derive from PointPickingCallback a new class which overrides the check for the shift key inside the Execute method.
  2. Derive from PCLVisualizerInteractorStyle and override the Initialize method to register your new custom PointPickingCallback class which doesn't check for the shift key, as a mouse callback.
Cheers



On 11-03-2018 14:16, Mike6000 wrote:
The problem at the moment is that I cant find out IF the checking of the
SHIFT key is happening in an underlying VTK Interactor OR if the checking of
the SHIFT key is happening in the
pcl::visualization::PointPickingCallback::Execute (...) function as I
initially believed.

https://github.com/PointCloudLibrary/pcl/blob/master/visualization/include/pcl/visualization/point_picking_event.h

https://https://github.com/PointCloudLibrary/pcl/blob/master/visualization/src/point_picking_event.cpp 

I cannot actually find any instantiation the
pcl::visualization::PointPickingCallback 
Nor can I find anything calling
pcl::visualization::PointPickingCallback::Execute(...)

First I need to find out what is atuallt handling the checking of SHIFT. 
Can someone answer this?

 




--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users

signature.asc (836 bytes) Download Attachment