interactor_style_switch.cpp
Go to the documentation of this file.
00001 #include <pcl/apps/cloud_composer/point_selectors/interactor_style_switch.h>
00002 #include <pcl/apps/cloud_composer/point_selectors/rectangular_frustum_selector.h>
00003 #include <pcl/apps/cloud_composer/point_selectors/selected_trackball_interactor_style.h>
00004 #include <pcl/apps/cloud_composer/point_selectors/click_trackball_interactor_style.h>
00005 #include <pcl/visualization/interactor_style.h>
00006 
00007 namespace pcl
00008 {
00009   namespace cloud_composer
00010   {
00011     vtkStandardNewMacro(InteractorStyleSwitch);
00012   }
00013 }
00014 
00015 pcl::cloud_composer::InteractorStyleSwitch::InteractorStyleSwitch ()
00016 {
00017   pcl_vis_style_ = vtkSmartPointer<pcl::visualization::PCLVisualizerInteractorStyle>::New ();
00018   name_to_style_map_.insert (interactor_styles::PCL_VISUALIZER, pcl_vis_style_);
00019   
00020   rectangular_frustum_selector_ = vtkSmartPointer<RectangularFrustumSelector>::New ();
00021   name_to_style_map_.insert (interactor_styles::RECTANGULAR_FRUSTUM, rectangular_frustum_selector_);
00022   
00023   selected_trackball_interactor_style_ = vtkSmartPointer <SelectedTrackballStyleInteractor>::New ();
00024   name_to_style_map_.insert (interactor_styles::SELECTED_TRACKBALL, selected_trackball_interactor_style_);
00025   
00026   click_trackball_interactor_style_ = vtkSmartPointer <ClickTrackballStyleInteractor>::New ();
00027   name_to_style_map_.insert (interactor_styles::CLICK_TRACKBALL, click_trackball_interactor_style_);
00028   
00029   area_picker_ = vtkSmartPointer<vtkAreaPicker>::New();
00030   point_picker_ = vtkSmartPointer<vtkPointPicker>::New ();
00031   
00032   current_style_ = 0;
00033   
00034 }
00035 
00036 pcl::cloud_composer::InteractorStyleSwitch::~InteractorStyleSwitch ()
00037 {
00038     
00039 }
00040 
00041 void
00042 pcl::cloud_composer::InteractorStyleSwitch::initializeInteractorStyles (boost::shared_ptr<pcl::visualization::PCLVisualizer> vis, ProjectModel* model)
00043 {
00044   qDebug () << "Initializing Interactor Styles";
00045   vis_ = vis;
00046   project_model_ = model;
00047   
00048   pcl_vis_style_->Initialize ();
00049   rens_ = vis_->getRendererCollection ();
00050   pcl_vis_style_->setRendererCollection (rens_);
00051   pcl_vis_style_->setCloudActorMap (vis_->getCloudActorMap ());
00052   
00053   rectangular_frustum_selector_->setCloudActorMap (vis_->getCloudActorMap ());
00054   
00055   selected_trackball_interactor_style_->setCloudActorMap (vis_->getCloudActorMap ());
00056   selected_trackball_interactor_style_->setProjectModel (project_model_);
00057   
00058   click_trackball_interactor_style_->setCloudActorMap (vis_->getCloudActorMap ());
00059   click_trackball_interactor_style_->setProjectModel (project_model_);
00060 }
00061 
00062 void
00063 pcl::cloud_composer::InteractorStyleSwitch::setCurrentInteractorStyle (interactor_styles::INTERACTOR_STYLES interactor_style)
00064 {
00065   qDebug () << "Setting interactor style";
00066   vtkSmartPointer <vtkInteractorStyle> style_ptr = name_to_style_map_.value (interactor_style);
00067   if (current_style_)
00068     current_style_->SetInteractor (0);
00069   current_style_= style_ptr;
00070   
00071   if (current_style_)
00072   {
00073     qDebug () << "Modifying current interactor of style!";
00074     current_style_->SetInteractor (this->Interactor);
00075     current_style_->SetTDxStyle (this->TDxStyle);
00076     
00077     if (interactor_style == interactor_styles::RECTANGULAR_FRUSTUM)
00078     {
00079       vtkInteractorStyleRubberBandPick* rubber_band_style = vtkInteractorStyleRubberBandPick::SafeDownCast (current_style_);
00080       if (rubber_band_style)
00081       {
00082         vis_->getRenderWindow ()->GetInteractor ()->SetPicker (area_picker_);
00083         rubber_band_style->StartSelect ();
00084       }
00085     }
00086     
00087     
00088   }
00089   
00090       
00091  
00092 }
00093 
00094 //----------------------------------------------------------------------------
00095 void 
00096 pcl::cloud_composer::InteractorStyleSwitch::SetInteractor (vtkRenderWindowInteractor *iren)
00097 {
00098   if(iren == this->Interactor)
00099   {
00100     return;
00101   }
00102   // if we already have an Interactor then stop observing it
00103   if(this->Interactor)
00104   {
00105     this->Interactor->RemoveObserver(this->EventCallbackCommand);
00106   }
00107   this->Interactor = iren;
00108   // add observers for each of the events handled in ProcessEvents
00109   if(iren)
00110   {
00111     iren->AddObserver(vtkCommand::CharEvent, 
00112                       this->EventCallbackCommand,
00113                       this->Priority);
00114 
00115     iren->AddObserver(vtkCommand::DeleteEvent, 
00116                       this->EventCallbackCommand,
00117                       this->Priority);
00118   }
00119 }
00120 
00121 //----------------------------------------------------------------------------
00122 void 
00123 pcl::cloud_composer::InteractorStyleSwitch::SetDefaultRenderer (vtkRenderer* renderer)
00124 {
00125   vtkInteractorStyle::SetDefaultRenderer(renderer);
00126   pcl_vis_style_->SetDefaultRenderer(renderer);
00127   rectangular_frustum_selector_->SetDefaultRenderer(renderer);
00128 }
00129 
00130 //----------------------------------------------------------------------------
00131 void 
00132 pcl::cloud_composer::InteractorStyleSwitch::SetCurrentRenderer (vtkRenderer* renderer)
00133 {
00134   this->vtkInteractorStyle::SetCurrentRenderer(renderer);
00135   pcl_vis_style_->SetCurrentRenderer(renderer);
00136   rectangular_frustum_selector_->SetCurrentRenderer(renderer);
00137 }
00138 
00139 void
00140 pcl::cloud_composer::InteractorStyleSwitch::OnLeave ()
00141 {
00142   qDebug () << "ON LEAVE";
00143 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:25:02