Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.63 KB | None | 0 0
  1. void
  2. pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown ()
  3. {
  4.   if (!init_)
  5.   {
  6.     pcl::console::print_error ("[PCLVisualizerInteractorStyle] Interactor style not initialized. Please call Initialize () before continuing.\n");
  7.     return;
  8.   }
  9.  
  10.   if (!rens_)
  11.   {
  12.     pcl::console::print_error ("[PCLVisualizerInteractorStyle] No renderer collection given! Use SetRendererCollection () before continuing.\n");
  13.     return;
  14.   }
  15.  
  16.   FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]);
  17.  
  18.   if (wif_->GetInput () == NULL)
  19.   {
  20.     wif_->SetInput (Interactor->GetRenderWindow ());
  21.     wif_->Modified ();
  22.     snapshot_writer_->Modified ();
  23.   }
  24.  
  25.   // Save the initial windows width/height
  26.   if (win_height_ == -1 || win_width_ == -1)
  27.   {
  28.     int *win_size = Interactor->GetRenderWindow ()->GetSize ();
  29.     win_height_ = win_size[0];
  30.     win_width_  = win_size[1];
  31.   }
  32.  
  33.   // Get the status of special keys (Cltr+Alt+Shift)
  34.   bool shift = Interactor->GetShiftKey   ();
  35.   bool ctrl  = Interactor->GetControlKey ();
  36.   bool alt   = Interactor->GetAltKey ();
  37.  
  38.   bool keymod = false;
  39.   switch (modifier_)
  40.   {
  41.     case INTERACTOR_KB_MOD_ALT:
  42.     {
  43.       keymod = alt;
  44.       break;
  45.     }
  46.     case INTERACTOR_KB_MOD_CTRL:
  47.     {
  48.       keymod = ctrl;
  49.       break;
  50.     }
  51.     case INTERACTOR_KB_MOD_SHIFT:
  52.     {
  53.       keymod = shift;
  54.       break;
  55.     }
  56.   }
  57.  
  58.   // ---[ Check the rest of the key codes
  59.  
  60.   // Save camera parameters
  61.   if ((Interactor->GetKeySym ()[0] == 'S' || Interactor->GetKeySym ()[0] == 's') && ctrl && !alt && !shift)
  62.   {
  63.     if (camera_file_.empty ())
  64.     {
  65.       getCameraParameters (camera_);
  66.       camera_saved_ = true;
  67.       pcl::console::print_info ("Camera parameters saved, you can press CTRL + R to restore.\n");
  68.     }
  69.     else
  70.     {
  71.       if (saveCameraParameters (camera_file_))
  72.       {
  73.         pcl::console::print_info ("Save camera parameters to %s, you can press CTRL + R to restore.\n", camera_file_.c_str ());
  74.       }
  75.       else
  76.       {
  77.         pcl::console::print_error ("[PCLVisualizerInteractorStyle] Can't save camera parameters to file: %s.\n", camera_file_.c_str ());
  78.       }
  79.     }
  80.   }
  81.  
  82.   // Restore camera parameters
  83.   if ((Interactor->GetKeySym ()[0] == 'R' || Interactor->GetKeySym ()[0] == 'r') && ctrl && !alt && !shift)
  84.   {
  85.     if (camera_file_.empty ())
  86.     {
  87.       if (camera_saved_)
  88.       {
  89.         setCameraParameters (camera_);
  90.         pcl::console::print_info ("Camera parameters restored.\n");
  91.       }
  92.       else
  93.       {
  94.         pcl::console::print_info ("No camera parameters saved for restoring.\n");
  95.       }
  96.     }
  97.     else
  98.     {
  99.       if (boost::filesystem::exists (camera_file_))
  100.       {
  101.         if (loadCameraParameters (camera_file_))
  102.         {
  103.           pcl::console::print_info ("Restore camera parameters from %s.\n", camera_file_.c_str ());
  104.         }
  105.         else
  106.         {
  107.           pcl::console::print_error ("Can't restore camera parameters from file: %s.\n", camera_file_.c_str ());
  108.         }
  109.       }
  110.       else
  111.       {
  112.         pcl::console::print_info ("No camera parameters saved in %s for restoring.\n", camera_file_.c_str ());
  113.       }
  114.     }
  115.   }
  116.  
  117.   // Switch between point color/geometry handlers
  118.   if (Interactor->GetKeySym () && Interactor->GetKeySym ()[0]  >= '0' && Interactor->GetKeySym ()[0] <= '9')
  119.   {
  120.     CloudActorMap::iterator it;
  121.     int index = Interactor->GetKeySym ()[0] - '0' - 1;
  122.     if (index == -1) index = 9;
  123.  
  124.     // Add 10 more for CTRL+0..9 keys
  125.     if (ctrl)
  126.       index += 10;
  127.  
  128.     // Geometry ?
  129.     if (keymod)
  130.     {
  131.       for (it = cloud_actors_->begin (); it != cloud_actors_->end (); ++it)
  132.       {
  133.         CloudActor *act = &(*it).second;
  134.         if (index >= static_cast<int> (act->geometry_handlers.size ()))
  135.           continue;
  136.  
  137.         // Save the geometry handler index for later usage
  138.         act->geometry_handler_index_ = index;
  139.  
  140.         // Create the new geometry
  141.         PointCloudGeometryHandler<pcl::PCLPointCloud2>::ConstPtr geometry_handler = act->geometry_handlers[index];
  142.  
  143.         // Use the handler to obtain the geometry
  144.         vtkSmartPointer<vtkPoints> points;
  145.         geometry_handler->getGeometry (points);
  146.  
  147.         // Set the vertices
  148.         vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New ();
  149.         for (vtkIdType i = 0; i < static_cast<vtkIdType> (points->GetNumberOfPoints ()); ++i)
  150.           vertices->InsertNextCell (static_cast<vtkIdType>(1), &i);
  151.  
  152.         // Create the data
  153.         vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New ();
  154.         data->SetPoints (points);
  155.         data->SetVerts (vertices);
  156.         // Modify the mapper
  157. #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
  158.         if (use_vbos_)
  159.         {
  160.           vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(act->actor->GetMapper ());
  161.           mapper->SetInput (data);
  162.           // Modify the actor
  163.           act->actor->SetMapper (mapper);
  164.         }
  165.         else
  166. #endif
  167.         {
  168.           vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(act->actor->GetMapper ());
  169. #if VTK_MAJOR_VERSION < 6
  170.           mapper->SetInput (data);
  171. #else
  172.           mapper->SetInputData (data);
  173. #endif
  174.           // Modify the actor
  175.           act->actor->SetMapper (mapper);
  176.         }
  177.         act->actor->Modified ();
  178.       }
  179.     }
  180.     else
  181.     {
  182.       for (it = cloud_actors_->begin (); it != cloud_actors_->end (); ++it)
  183.       {
  184.         CloudActor *act = &(*it).second;
  185.         // Check for out of bounds
  186.         if (index >= static_cast<int> (act->color_handlers.size ()))
  187.           continue;
  188.  
  189.         // Save the color handler index for later usage
  190.         act->color_handler_index_ = index;
  191.  
  192.         // Get the new color
  193.         PointCloudColorHandler<pcl::PCLPointCloud2>::ConstPtr color_handler = act->color_handlers[index];
  194.  
  195.         vtkSmartPointer<vtkDataArray> scalars;
  196.         color_handler->getColor (scalars);
  197.         double minmax[2];
  198.         scalars->GetRange (minmax);
  199.         // Update the data
  200.         vtkPolyData *data = static_cast<vtkPolyData*>(act->actor->GetMapper ()->GetInput ());
  201.         data->GetPointData ()->SetScalars (scalars);
  202.         // Modify the mapper
  203. #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
  204.         if (use_vbos_)
  205.         {
  206.           vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(act->actor->GetMapper ());
  207.           mapper->SetScalarRange (minmax);
  208.           mapper->SetScalarModeToUsePointData ();
  209.           mapper->SetInput (data);
  210.           // Modify the actor
  211.           act->actor->SetMapper (mapper);
  212.         }
  213.         else
  214. #endif
  215.         {
  216.           vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(act->actor->GetMapper ());
  217.           mapper->SetScalarRange (minmax);
  218.           mapper->SetScalarModeToUsePointData ();
  219. #if VTK_MAJOR_VERSION < 6
  220.           mapper->SetInput (data);
  221. #else
  222.           mapper->SetInputData (data);
  223. #endif
  224.           // Modify the actor
  225.           act->actor->SetMapper (mapper);
  226.         }
  227.         act->actor->Modified ();
  228.       }
  229.     }
  230.  
  231.     Interactor->Render ();
  232.     return;
  233.   }
  234.  
  235.   std::string key (Interactor->GetKeySym ());
  236.   if (key.find ("XF86ZoomIn") != std::string::npos)
  237.     zoomIn ();
  238.   else if (key.find ("XF86ZoomOut") != std::string::npos)
  239.     zoomOut ();
  240.  
  241. //  switch (Interactor->GetKeyCode ())
  242. //  {
  243. //    case 'h': case 'H':
  244. //    {
  245. //      pcl::console::print_info ("| Help:\n"
  246. //                  "-------\n"
  247. //                  "          p, P   : switch to a point-based representation\n"
  248. //                  "          w, W   : switch to a wireframe-based representation (where available)\n"
  249. //                  "          s, S   : switch to a surface-based representation (where available)\n"
  250. //                  "\n"
  251. //                  "          j, J   : take a .PNG snapshot of the current window view\n"
  252. //                  "          c, C   : display current camera/window parameters\n"
  253. //                  "          f, F   : fly to point mode\n"
  254. //                  "\n"
  255. //                  "          e, E   : exit the interactor\n"
  256. //                  "          q, Q   : stop and call VTK's TerminateApp\n"
  257. //                  "\n"
  258. //                  "           +/-   : increment/decrement overall point size\n"
  259. //                  "     +/- [+ ALT] : zoom in/out \n"
  260. //                  "\n"
  261. //                  "          g, G   : display scale grid (on/off)\n"
  262. //                  "          u, U   : display lookup table (on/off)\n"
  263. //                  "\n"
  264. //                  "    o, O         : switch between perspective/parallel projection (default = perspective)\n"
  265. //                  "    r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]\n"
  266. //                  "    CTRL + s, S  : save camera parameters\n"
  267. //                  "    CTRL + r, R  : restore camera parameters\n"
  268. //                  "\n"
  269. //                  "    ALT + s, S   : turn stereo mode on/off\n"
  270. //                  "    ALT + f, F   : switch between maximized window mode and original size\n"
  271. //                  "\n"
  272. //                  "          l, L           : list all available geometric and color handlers for the current actor map\n"
  273. //                  "    ALT + 0..9 [+ CTRL]  : switch between different geometric handlers (where available)\n"
  274. //                  "          0..9 [+ CTRL]  : switch between different color handlers (where available)\n"
  275. //                  "\n"
  276. //                  "    SHIFT + left click   : select a point (start with -use_point_picking)\n"
  277. //                  "\n"
  278. //                  "          x, X   : toggle rubber band selection mode for left mouse button\n"
  279. //          );
  280. //      break;
  281. //    }
  282.  
  283. //    // Get the list of available handlers
  284. //    case 'l': case 'L':
  285. //    {
  286. //      // Iterate over the entire actors list and extract the geomotry/color handlers list
  287. //      for (CloudActorMap::iterator it = cloud_actors_->begin (); it != cloud_actors_->end (); ++it)
  288. //      {
  289. //        std::list<std::string> geometry_handlers_list, color_handlers_list;
  290. //        CloudActor *act = &(*it).second;
  291. //        for (size_t i = 0; i < act->geometry_handlers.size (); ++i)
  292. //          geometry_handlers_list.push_back (act->geometry_handlers[i]->getFieldName ());
  293. //        for (size_t i = 0; i < act->color_handlers.size (); ++i)
  294. //          color_handlers_list.push_back (act->color_handlers[i]->getFieldName ());
  295.  
  296. //        if (!geometry_handlers_list.empty ())
  297. //        {
  298. //          int i = 0;
  299. //          pcl::console::print_info ("List of available geometry handlers for actor "); pcl::console::print_value ("%s: ", (*it).first.c_str ());
  300. //          for (std::list<std::string>::iterator git = geometry_handlers_list.begin (); git != geometry_handlers_list.end (); ++git)
  301. //            pcl::console::print_value ("%s(%d) ", (*git).c_str (), ++i);
  302. //          pcl::console::print_info ("\n");
  303. //        }
  304. //        if (!color_handlers_list.empty ())
  305. //        {
  306. //          int i = 0;
  307. //          pcl::console::print_info ("List of available color handlers for actor "); pcl::console::print_value ("%s: ", (*it).first.c_str ());
  308. //          for (std::list<std::string>::iterator cit = color_handlers_list.begin (); cit != color_handlers_list.end (); ++cit)
  309. //            pcl::console::print_value ("%s(%d) ", (*cit).c_str (), ++i);
  310. //          pcl::console::print_info ("\n");
  311. //        }
  312. //      }
  313.  
  314. //      break;
  315. //    }
  316.  
  317. //    // Switch representation to points
  318. //    case 'p': case 'P':
  319. //    {
  320. //      vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors ();
  321. //      vtkCollectionSimpleIterator ait;
  322. //      for (ac->InitTraversal (ait); vtkActor* actor = ac->GetNextActor (ait); )
  323. //      {
  324. //        for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); )
  325. //        {
  326. //          vtkSmartPointer<vtkActor> apart = reinterpret_cast <vtkActor*> (path->GetLastNode ()->GetViewProp ());
  327. //          apart->GetProperty ()->SetRepresentationToPoints ();
  328. //        }
  329. //      }
  330. //      break;
  331. //    }
  332.  
  333. //    // Switch representation to wireframe (override default behavior)
  334. //    case 'w': case 'W':
  335. //    {
  336. //      vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors ();
  337. //      vtkCollectionSimpleIterator ait;
  338. //      for (ac->InitTraversal (ait); vtkActor* actor = ac->GetNextActor (ait); )
  339. //      {
  340. //        for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); )
  341. //        {
  342. //          vtkSmartPointer<vtkActor> apart = reinterpret_cast <vtkActor*> (path->GetLastNode ()->GetViewProp ());
  343. //          apart->GetProperty ()->SetRepresentationToWireframe ();
  344. //          apart->GetProperty ()->SetLighting (false);
  345. //        }
  346. //      }
  347. //      break;
  348. //    }
  349.  
  350. //    // Save a PNG snapshot with the current screen
  351. //    case 'j': case 'J':
  352. //    {
  353. //      char cam_fn[80], snapshot_fn[80];
  354. //      unsigned t = static_cast<unsigned> (time (0));
  355. //      sprintf (snapshot_fn, "screenshot-%d.png" , t);
  356. //      saveScreenshot (snapshot_fn);
  357.  
  358. //      sprintf (cam_fn, "screenshot-%d.cam", t);
  359. //      saveCameraParameters (cam_fn);
  360.  
  361. //      pcl::console::print_info ("Screenshot (%s) and camera information (%s) successfully captured.\n", snapshot_fn, cam_fn);
  362. //      break;
  363. //    }
  364. //    // display current camera settings/parameters
  365. //    case 'c': case 'C':
  366. //    {
  367. //      vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera ();
  368. //      double clip[2], focal[3], pos[3], view[3];
  369. //      cam->GetClippingRange (clip);
  370. //      cam->GetFocalPoint (focal);
  371. //      cam->GetPosition (pos);
  372. //      cam->GetViewUp (view);
  373. //      int *win_pos = Interactor->GetRenderWindow ()->GetPosition ();
  374. //      int *win_size = Interactor->GetRenderWindow ()->GetSize ();
  375. //      std::cerr <<  "Clipping plane [near,far] "  << clip[0] << ", " << clip[1] << endl <<
  376. //                    "Focal point [x,y,z] " << focal[0] << ", " << focal[1] << ", " << focal[2] << endl <<
  377. //                    "Position [x,y,z] " << pos[0] << ", " << pos[1] << ", " << pos[2] << endl <<
  378. //                    "View up [x,y,z] " << view[0]  << ", " << view[1]  << ", " << view[2] << endl <<
  379. //                    "Camera view angle [degrees] " << cam->GetViewAngle () << endl <<
  380. //                    "Window size [x,y] " << win_size[0] << ", " << win_size[1] << endl <<
  381. //                    "Window position [x,y] " << win_pos[0] << ", " << win_pos[1] << endl;
  382. //      break;
  383. //    }
  384. //    case '=':
  385. //    {
  386. //      zoomIn();
  387. //      break;
  388. //    }
  389. //    case 43:        // KEY_PLUS
  390. //    {
  391. //      if(alt)
  392. //        zoomIn ();
  393. //      else
  394. //      {
  395. //        vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors ();
  396. //        vtkCollectionSimpleIterator ait;
  397. //        for (ac->InitTraversal (ait); vtkActor* actor = ac->GetNextActor (ait); )
  398. //        {
  399. //          for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); )
  400. //          {
  401. //            vtkSmartPointer<vtkActor> apart = reinterpret_cast <vtkActor*> (path->GetLastNode ()->GetViewProp ());
  402. //            float psize = apart->GetProperty ()->GetPointSize ();
  403. //            if (psize < 63.0f)
  404. //              apart->GetProperty ()->SetPointSize (psize + 1.0f);
  405. //          }
  406. //        }
  407. //      }
  408. //      break;
  409. //    }
  410. //    case 45:        // KEY_MINUS
  411. //    {
  412. //      if(alt)
  413. //        zoomOut ();
  414. //      else
  415. //      {
  416. //        vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors ();
  417. //        vtkCollectionSimpleIterator ait;
  418. //        for (ac->InitTraversal (ait); vtkActor* actor = ac->GetNextActor (ait); )
  419. //        {
  420. //          for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); )
  421. //          {
  422. //            vtkSmartPointer<vtkActor> apart = static_cast<vtkActor*> (path->GetLastNode ()->GetViewProp ());
  423. //            float psize = apart->GetProperty ()->GetPointSize ();
  424. //            if (psize > 1.0f)
  425. //              apart->GetProperty ()->SetPointSize (psize - 1.0f);
  426. //          }
  427. //        }
  428. //      }
  429. //      break;
  430. //    }
  431. //    // Switch between maximize and original window size
  432. //    case 'f': case 'F':
  433. //    {
  434. //      if (keymod)
  435. //      {
  436. //        // Get screen size
  437. //        int *temp = Interactor->GetRenderWindow ()->GetScreenSize ();
  438. //        int scr_size[2]; scr_size[0] = temp[0]; scr_size[1] = temp[1];
  439.  
  440. //        // Get window size
  441. //        temp = Interactor->GetRenderWindow ()->GetSize ();
  442. //        int win_size[2]; win_size[0] = temp[0]; win_size[1] = temp[1];
  443. //        // Is window size = max?
  444. //        if (win_size[0] == max_win_height_ && win_size[1] == max_win_width_)
  445. //        {
  446. //          // Set the previously saved 'current' window size
  447. //          Interactor->GetRenderWindow ()->SetSize (win_height_, win_width_);
  448. //          // Set the previously saved window position
  449. //          Interactor->GetRenderWindow ()->SetPosition (win_pos_x_, win_pos_y_);
  450. //          Interactor->GetRenderWindow ()->Render ();
  451. //          Interactor->Render ();
  452. //        }
  453. //        // Set to max
  454. //        else
  455. //        {
  456. //          int *win_pos = Interactor->GetRenderWindow ()->GetPosition ();
  457. //          // Save the current window position
  458. //          win_pos_x_  = win_pos[0];
  459. //          win_pos_y_  = win_pos[1];
  460. //          // Save the current window size
  461. //          win_height_ = win_size[0];
  462. //          win_width_  = win_size[1];
  463. //          // Set the maximum window size
  464. //          Interactor->GetRenderWindow ()->SetSize (scr_size[0], scr_size[1]);
  465. //          Interactor->GetRenderWindow ()->Render ();
  466. //          Interactor->Render ();
  467. //          int *win_size = Interactor->GetRenderWindow ()->GetSize ();
  468. //          // Save the maximum window size
  469. //          max_win_height_ = win_size[0];
  470. //          max_win_width_  = win_size[1];
  471. //        }
  472. //      }
  473. //      else
  474. //      {
  475. //        AnimState = VTKIS_ANIM_ON;
  476. //        vtkAssemblyPath *path = NULL;
  477. //        Interactor->GetPicker ()->Pick (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1], 0.0, CurrentRenderer);
  478. //        vtkAbstractPropPicker *picker;
  479. //        if ((picker = vtkAbstractPropPicker::SafeDownCast (Interactor->GetPicker ())))
  480. //          path = picker->GetPath ();
  481. //        if (path != NULL)
  482. //          Interactor->FlyTo (CurrentRenderer, picker->GetPickPosition ());
  483. //        AnimState = VTKIS_ANIM_OFF;
  484. //      }
  485. //      break;
  486. //    }
  487. //    // 's'/'S' w/out ALT
  488. //    case 's': case 'S':
  489. //    {
  490. //      if (keymod)
  491. //      {
  492. //        int stereo_render = Interactor->GetRenderWindow ()->GetStereoRender ();
  493. //        if (!stereo_render)
  494. //        {
  495. //          if (stereo_anaglyph_mask_default_)
  496. //          {
  497. //            Interactor->GetRenderWindow ()->SetAnaglyphColorMask (4, 3);
  498. //            stereo_anaglyph_mask_default_ = false;
  499. //          }
  500. //          else
  501. //          {
  502. //            Interactor->GetRenderWindow ()->SetAnaglyphColorMask (2, 5);
  503. //            stereo_anaglyph_mask_default_ = true;
  504. //          }
  505. //        }
  506. //        Interactor->GetRenderWindow ()->SetStereoRender (!stereo_render);
  507. //        Interactor->GetRenderWindow ()->Render ();
  508. //        Interactor->Render ();
  509. //      }
  510. //      else
  511. //      {
  512. //        Superclass::OnKeyDown();
  513. //        vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
  514. //        vtkCollectionSimpleIterator ait;
  515. //        for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait);)
  516. //        {
  517. //          for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath();)
  518. //          {
  519. //            vtkSmartPointer<vtkActor> apart = reinterpret_cast<vtkActor*>(path->GetLastNode()->GetViewProp());
  520. //            apart->GetProperty()->SetRepresentationToSurface();
  521. //            apart->GetProperty()->SetLighting(true);
  522. //          }
  523. //        }
  524. //      }
  525. //      break;
  526. //    }
  527.  
  528. //    // Display a grid/scale over the screen
  529. //    case 'g': case 'G':
  530. //    {
  531. //      if (!grid_enabled_)
  532. //      {
  533. //        grid_actor_->TopAxisVisibilityOn ();
  534. //        CurrentRenderer->AddViewProp (grid_actor_);
  535. //        grid_enabled_ = true;
  536. //      }
  537. //      else
  538. //      {
  539. //        CurrentRenderer->RemoveViewProp (grid_actor_);
  540. //        grid_enabled_ = false;
  541. //      }
  542. //      break;
  543. //    }
  544.  
  545. //    case 'o': case 'O':
  546. //    {
  547. //      vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera ();
  548. //      int flag = cam->GetParallelProjection ();
  549. //      cam->SetParallelProjection (!flag);
  550.  
  551. //      CurrentRenderer->SetActiveCamera (cam);
  552. //      CurrentRenderer->Render ();
  553. //      break;
  554. //    }
  555. //    // Display a LUT actor on screen
  556. //    case 'u': case 'U':
  557. //    {
  558. //      updateLookUpTableDisplay (true);
  559. //      break;
  560. //    }
  561.  
  562. //    // Overwrite the camera reset
  563. //    case 'r': case 'R':
  564. //    {
  565. //      if (!keymod)
  566. //      {
  567. //        FindPokedRenderer(Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]);
  568. //        if(CurrentRenderer != 0)
  569. //          CurrentRenderer->ResetCamera ();
  570. //        else
  571. //          PCL_WARN ("no current renderer on the interactor style.");
  572.  
  573. //        CurrentRenderer->Render ();
  574. //        break;
  575. //      }
  576.  
  577. //      vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera ();
  578.      
  579. //      static CloudActorMap::iterator it = cloud_actors_->begin ();
  580. //      // it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault.
  581. //      bool found_transformation = false;
  582. //      for (unsigned idx = 0; idx < cloud_actors_->size (); ++idx, ++it)
  583. //      {
  584. //        if (it == cloud_actors_->end ())
  585. //          it = cloud_actors_->begin ();
  586.        
  587. //        const CloudActor& actor = it->second;
  588. //        if (actor.viewpoint_transformation_.GetPointer ())
  589. //        {
  590. //          found_transformation = true;
  591. //          break;
  592. //        }
  593. //      }
  594.      
  595. //      // if a valid transformation was found, use it otherwise fall back to default view point.
  596. //      if (found_transformation)
  597. //      {
  598. //        const CloudActor& actor = it->second;
  599. //        cam->SetPosition (actor.viewpoint_transformation_->GetElement (0, 3),
  600. //                          actor.viewpoint_transformation_->GetElement (1, 3),
  601. //                          actor.viewpoint_transformation_->GetElement (2, 3));
  602.  
  603. //        cam->SetFocalPoint (actor.viewpoint_transformation_->GetElement (0, 3) - actor.viewpoint_transformation_->GetElement (0, 2),
  604. //                            actor.viewpoint_transformation_->GetElement (1, 3) - actor.viewpoint_transformation_->GetElement (1, 2),
  605. //                            actor.viewpoint_transformation_->GetElement (2, 3) - actor.viewpoint_transformation_->GetElement (2, 2));
  606.  
  607. //        cam->SetViewUp (actor.viewpoint_transformation_->GetElement (0, 1),
  608. //                        actor.viewpoint_transformation_->GetElement (1, 1),
  609. //                        actor.viewpoint_transformation_->GetElement (2, 1));
  610. //      }
  611. //      else
  612. //      {
  613. //        cam->SetPosition (0, 0, 0);
  614. //        cam->SetFocalPoint (0, 0, 1);
  615. //        cam->SetViewUp (0, -1, 0);
  616. //      }
  617.  
  618. //      // go to the next actor for the next key-press event.
  619. //      if (it != cloud_actors_->end ())
  620. //        ++it;
  621. //      else
  622. //        it = cloud_actors_->begin ();
  623.      
  624. //      CurrentRenderer->SetActiveCamera (cam);
  625. //      CurrentRenderer->ResetCameraClippingRange ();
  626. //      CurrentRenderer->Render ();
  627. //      break;
  628. //    }
  629.  
  630. //    case 'x' : case 'X' :
  631. //    {
  632. //      CurrentMode = (CurrentMode == ORIENT_MODE) ? SELECT_MODE : ORIENT_MODE;
  633. //      if (CurrentMode == SELECT_MODE)
  634. //      {
  635. //        // Save the point picker
  636. //        point_picker_ = static_cast<vtkPointPicker*> (Interactor->GetPicker ());
  637. //        // Switch for an area picker
  638. //        vtkSmartPointer<vtkAreaPicker> area_picker = vtkSmartPointer<vtkAreaPicker>::New ();
  639. //        Interactor->SetPicker (area_picker);
  640. //      }
  641. //      else
  642. //      {
  643. //        // Restore point picker
  644. //        Interactor->SetPicker (point_picker_);
  645. //      }
  646. //      break;
  647. //    }
  648.  
  649. //    case 'q': case 'Q':
  650. //    {
  651. //      Interactor->ExitCallback ();
  652. //      return;
  653. //    }
  654. //    default:
  655. //    {
  656. //      Superclass::OnKeyDown ();
  657. //      break;
  658. //    }
  659. //  }
  660.  
  661.   KeyboardEvent event (true, Interactor->GetKeySym (), Interactor->GetKeyCode (), Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ());
  662.   keyboard_signal_ (event);
  663.  
  664.   rens_->Render ();
  665.   Interactor->Render ();
  666. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement