Esempio n. 1
0
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)
  {
    //vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New() ;
    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, actor_);
        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
      //std::cout<< "druhe zjisteni actor: " << actor <<std::endl;
      PointPickingEvent event (idx_, idx, x_, y_, z_, x, y, z, actor_);
      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< std::vector<int> >indices;
      vtkActorCollection* actors = vtkActorCollection::New();
      int nb_points = performAreaPick (iren, indices,actors);
      AreaPickingEvent event (nb_points, indices, actors);
      style->area_picking_signal_ (event);
      actors->Delete();

    }
  }
}
Esempio n. 2
0
void
pcl::visualization::PointPickingCallback::Execute (vtkObject *caller, unsigned long eventid, void*)
{
  vtkRenderWindowInteractor* iren = reinterpret_cast<pcl::visualization::PCLVisualizerInteractorStyle*>(caller)->GetInteractor ();

  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);
      reinterpret_cast<pcl::visualization::PCLVisualizerInteractorStyle*>(caller)->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);
    reinterpret_cast<pcl::visualization::PCLVisualizerInteractorStyle*>(caller)->point_picking_signal_ (event);
  }
  // Call the parent's class mouse events
  reinterpret_cast<pcl::visualization::PCLVisualizerInteractorStyle*>(caller)->OnLeftButtonDown ();
}