Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <pcl/visualization/point_picking_event.h>
00041 #include <pcl/visualization/interactor_style.h>
00042 #include <vtkPointPicker.h>
00043 #include <vtkRendererCollection.h>
00044
00046 void
00047 pcl::visualization::PointPickingCallback::Execute (vtkObject *caller, unsigned long eventid, void*)
00048 {
00049 vtkRenderWindowInteractor* iren = reinterpret_cast<pcl::visualization::PCLVisualizerInteractorStyle*>(caller)->GetInteractor ();
00050
00051 if ((eventid == vtkCommand::LeftButtonPressEvent) && (iren->GetShiftKey () > 0))
00052 {
00053 float x = 0, y = 0, z = 0;
00054 int idx = performSinglePick (iren, x, y, z);
00055
00056 PointPickingEvent event (idx, x, y, z);
00057 reinterpret_cast<pcl::visualization::PCLVisualizerInteractorStyle*>(caller)->point_picking_signal_ (event);
00058 }
00059 else if ((eventid == vtkCommand::LeftButtonPressEvent) && (iren->GetAltKey () == 1))
00060 {
00061 pick_first_ = !pick_first_;
00062 float x = 0, y = 0, z = 0;
00063 int idx = -1;
00064 if (pick_first_)
00065 idx_ = performSinglePick (iren, x_, y_, z_);
00066 else
00067 idx = performSinglePick (iren, x, y, z);
00068
00069 PointPickingEvent event (idx_, idx, x_, y_, z_, x, y, z);
00070 reinterpret_cast<pcl::visualization::PCLVisualizerInteractorStyle*>(caller)->point_picking_signal_ (event);
00071 }
00072
00073 reinterpret_cast<pcl::visualization::PCLVisualizerInteractorStyle*>(caller)->OnLeftButtonDown ();
00074 }
00075
00077 int
00078 pcl::visualization::PointPickingCallback::performSinglePick (vtkRenderWindowInteractor *iren)
00079 {
00080 int mouse_x, mouse_y;
00081 vtkPointPicker *picker = (vtkPointPicker*)iren->GetPicker ();
00082
00083 mouse_x = iren->GetEventPosition ()[0];
00084 mouse_y = iren->GetEventPosition ()[1];
00085 iren->StartPickCallback ();
00086
00087 vtkRenderer *ren = iren->FindPokedRenderer (iren->GetEventPosition ()[0], iren->GetEventPosition ()[1]);
00088 picker->Pick (mouse_x, mouse_y, 0.0, ren);
00089 return ((int)picker->GetPointId ());
00090 }
00091
00093 int
00094 pcl::visualization::PointPickingCallback::performSinglePick (
00095 vtkRenderWindowInteractor *iren,
00096 float &x, float &y, float &z)
00097 {
00098 int mouse_x, mouse_y;
00099 vtkPointPicker *picker = (vtkPointPicker*)iren->GetPicker ();
00100
00101 mouse_x = iren->GetEventPosition ()[0];
00102 mouse_y = iren->GetEventPosition ()[1];
00103 iren->StartPickCallback ();
00104
00105 vtkRenderer *ren = iren->FindPokedRenderer (iren->GetEventPosition ()[0], iren->GetEventPosition ()[1]);
00106 picker->Pick (mouse_x, mouse_y, 0.0, ren);
00107
00108 int idx = picker->GetPointId ();
00109 if (picker->GetDataSet () != NULL)
00110 {
00111 double p[3];
00112 picker->GetDataSet ()->GetPoint (idx, p);
00113 x = p[0]; y = p[1]; z = p[2];
00114 }
00115 return (idx);
00116 }
00117