Point Cloud Library (PCL)
1.3.1
|
00001 00037 #ifndef PCL_VISUALIZER_WINDOW_H__ 00038 #define PCL_VISUALIZER_WINDOW_H__ 00039 #include <pcl/pcl_macros.h> 00040 #include <pcl/console/print.h> 00041 #include <vtkRenderWindow.h> 00042 #include <vtkSmartPointer.h> 00043 #include <boost/signals2.hpp> 00044 #include <vtkCallbackCommand.h> 00045 #include <vtkInteractorStyle.h> 00046 #include <vtkRenderWindowInteractor.h> 00047 #include <pcl/visualization/interactor_style.h> 00048 00049 namespace pcl 00050 { 00051 namespace visualization 00052 { 00053 class MouseEvent; 00054 class KeyboardEvent; 00055 00056 class PCL_EXPORTS Window 00057 { 00058 public: 00059 Window (const std::string& window_name = ""); 00060 virtual ~Window (); 00061 00063 void 00064 spin (); 00065 00071 void 00072 spinOnce (int time = 1, bool force_redraw = false); 00073 00075 bool 00076 //wasStopped () const { return (interactor_->stopped); } 00077 wasStopped () const { return (stopped); } 00078 00085 boost::signals2::connection 00086 registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*), 00087 void* cookie = NULL) 00088 { 00089 return registerKeyboardCallback (boost::bind (callback, _1, cookie)); 00090 } 00091 00099 template<typename T> boost::signals2::connection 00100 registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*), 00101 T& instance, void* cookie = NULL) 00102 { 00103 return registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)); 00104 } 00105 00112 boost::signals2::connection 00113 registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*), 00114 void* cookie = NULL) 00115 { 00116 return registerMouseCallback (boost::bind (callback, _1, cookie)); 00117 } 00118 00126 template<typename T> boost::signals2::connection 00127 registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*), 00128 T& instance, void* cookie = NULL) 00129 { 00130 return registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)); 00131 } 00132 00133 protected: // methods 00134 00136 void 00137 //resetStoppedFlag () { interactor_->stopped = false; } 00138 resetStoppedFlag () { stopped = false; } 00139 00145 boost::signals2::connection 00146 registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)> ); 00147 00153 boost::signals2::connection 00154 registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)> ); 00155 00156 void 00157 emitMouseEvent (unsigned long event_id); 00158 00159 void 00160 emitKeyboardEvent (unsigned long event_id); 00161 00162 // Callbacks used to register for vtk command 00163 static void 00164 MouseCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata); 00165 static void 00166 KeyboardCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata); 00167 00168 protected: // types 00169 struct ExitMainLoopTimerCallback : public vtkCommand 00170 { 00171 static ExitMainLoopTimerCallback* New() 00172 { 00173 return new ExitMainLoopTimerCallback; 00174 } 00175 virtual void Execute(vtkObject* vtkNotUsed(caller), unsigned long event_id, void* call_data) 00176 { 00177 if (event_id != vtkCommand::TimerEvent) 00178 return; 00179 int timer_id = *(int*)call_data; 00180 //PCL_WARN ("[pcl::visualization::Window::ExitMainLoopTimerCallback] Timer %d called.\n", timer_id); 00181 if (timer_id != right_timer_id) 00182 return; 00183 window->interactor_->TerminateApp (); 00184 // window->interactor_->stopLoop (); 00185 } 00186 int right_timer_id; 00187 Window* window; 00188 }; 00189 struct ExitCallback : public vtkCommand 00190 { 00191 static ExitCallback* New () 00192 { 00193 return new ExitCallback; 00194 } 00195 virtual void Execute (vtkObject* caller, unsigned long event_id, void* call_data) 00196 { 00197 if (event_id != vtkCommand::ExitEvent) 00198 return; 00199 window->interactor_->TerminateApp (); 00200 //window->interactor_->stopped = true; 00201 window->stopped = true; 00202 // This tends to close the window... 00203 //window->interactor_->stopLoop (); 00204 } 00205 Window* window; 00206 }; 00207 00208 bool stopped; 00209 int timer_id_; 00210 00211 protected: // member fields 00212 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_; 00213 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_; 00214 00215 vtkSmartPointer<vtkRenderWindow> win_; 00216 vtkSmartPointer<vtkRenderWindowInteractor> interactor_; 00217 vtkCallbackCommand* mouse_command_; 00218 vtkCallbackCommand* keyboard_command_; 00220 vtkSmartPointer<PCLVisualizerInteractorStyle> style_; 00222 vtkSmartPointer<vtkRendererCollection> rens_; 00223 vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_; 00224 vtkSmartPointer<ExitCallback> exit_callback_; 00225 }; 00226 } 00227 } 00228 00229 #endif /* __WINDOW_H__ */ 00230