1 /* 2 * Software License Agreement (BSD License) 3 * 4 * Point Cloud Library (PCL) - www.pointclouds.org 5 * Copyright (c) 2012, Jeremie Papon. 6 * 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * * Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * * Redistributions in binary form must reproduce the above 16 * copyright notice, this list of conditions and the following 17 * disclaimer in the documentation and/or other materials provided 18 * with the distribution. 19 * * Neither the name of Willow Garage, Inc. nor the names of its 20 * contributors may be used to endorse or promote products derived 21 * from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 * 36 */ 37 38 #pragma once 39 40 #include <QMap> 41 42 #include <pcl/visualization/interactor_style.h> 43 #include <pcl/visualization/common/actor_map.h> 44 #include <pcl/visualization/common/ren_win_interact_map.h> 45 #include <pcl/visualization/pcl_visualizer.h> 46 47 #include <vtkSmartPointer.h> 48 #include <vtkAreaPicker.h> 49 #include <vtkPointPicker.h> 50 #include <vtkRenderWindowInteractor.h> 51 #include <vtkCommand.h> 52 #include <vtkRendererCollection.h> 53 #include <vtkInteractorStyle.h> 54 55 class QVTKWidget; 56 57 namespace pcl 58 { 59 namespace cloud_composer 60 { 61 namespace interactor_styles 62 { 63 enum INTERACTOR_STYLES 64 { 65 PCL_VISUALIZER = 0, 66 RECTANGULAR_FRUSTUM, 67 SELECTED_TRACKBALL, 68 CLICK_TRACKBALL 69 }; 70 } 71 namespace interactor_events 72 { 73 enum 74 { 75 SELECTION_COMPLETE_EVENT = vtkCommand::UserEvent + 1, 76 MANIPULATION_COMPLETE_EVENT 77 }; 78 }; 79 80 class RectangularFrustumSelector; 81 class SelectedTrackballStyleInteractor; 82 class ClickTrackballStyleInteractor; 83 class ProjectModel; 84 85 class InteractorStyleSwitch : public vtkInteractorStyle 86 { 87 public: 88 static InteractorStyleSwitch *New(); 89 vtkTypeMacro(InteractorStyleSwitch, vtkInteractorStyle); 90 91 InteractorStyleSwitch(); 92 ~InteractorStyleSwitch(); 93 94 void 95 SetInteractor(vtkRenderWindowInteractor *iren) override; 96 97 vtkGetObjectMacro(current_style_, vtkInteractorStyle); 98 99 void 100 initializeInteractorStyles (pcl::visualization::PCLVisualizer::Ptr vis, ProjectModel* model); 101 102 inline void setQVTKWidget(QVTKWidget * qvtk)103 setQVTKWidget (QVTKWidget* qvtk) { qvtk_ = qvtk; } 104 105 void 106 setCurrentInteractorStyle (interactor_styles::INTERACTOR_STYLES interactor_style); 107 108 // vtkSmartPointer<pcl::visualization::PCLVisualizerInteractorStyle> 109 // getPCLVisInteractorStyle () { return pcl_vis_style_; } 110 111 inline vtkSmartPointer <vtkInteractorStyle> getInteractorStyle(const interactor_styles::INTERACTOR_STYLES interactor_style)112 getInteractorStyle (const interactor_styles::INTERACTOR_STYLES interactor_style) const 113 { return name_to_style_map_.value (interactor_style); } 114 115 116 void SetDefaultRenderer(vtkRenderer*) override; 117 118 void SetCurrentRenderer(vtkRenderer*) override; 119 120 void 121 OnLeave () override; 122 123 protected: 124 void 125 setCurrentStyle(); 126 127 QMap <interactor_styles::INTERACTOR_STYLES, vtkSmartPointer <vtkInteractorStyle> > name_to_style_map_; 128 129 130 vtkRenderWindowInteractor* render_window_interactor_; 131 vtkSmartPointer<vtkRendererCollection> rens_; 132 133 vtkInteractorStyle* current_style_; 134 vtkSmartPointer<pcl::visualization::PCLVisualizerInteractorStyle> pcl_vis_style_; 135 vtkSmartPointer<RectangularFrustumSelector> rectangular_frustum_selector_; 136 137 vtkSmartPointer<SelectedTrackballStyleInteractor> selected_trackball_interactor_style_; 138 139 vtkSmartPointer<ClickTrackballStyleInteractor> click_trackball_interactor_style_; 140 vtkSmartPointer<vtkAreaPicker> area_picker_; 141 vtkSmartPointer<vtkPointPicker> point_picker_; 142 143 /** \brief Internal pointer to QVTKWidget that this Switch works with */ 144 QVTKWidget* qvtk_; 145 /** \brief Internal pointer to PCLVisualizer that this Switch works with */ 146 pcl::visualization::PCLVisualizer::Ptr vis_; 147 private: 148 InteractorStyleSwitch(const InteractorStyleSwitch&); // Not implemented. 149 void operator=(const InteractorStyleSwitch&); // Not implemented. 150 ProjectModel* project_model_; 151 }; 152 153 } 154 155 } 156