Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef PCL_VISUALIZER_WINDOW_H__
00041 #define PCL_VISUALIZER_WINDOW_H__
00042
00043 #include <pcl/pcl_macros.h>
00044 #include <pcl/console/print.h>
00045 #include <pcl/visualization/vtk.h>
00046 #include <pcl/visualization/interactor_style.h>
00047
00048 namespace pcl
00049 {
00050 namespace visualization
00051 {
00052 class MouseEvent;
00053 class KeyboardEvent;
00054
00055 class PCL_EXPORTS Window
00056 {
00057 public:
00058 Window (const std::string& window_name = "");
00059 Window (const Window &src);
00060 Window& operator = (const Window &src);
00061
00062 virtual ~Window ();
00063
00065 void
00066 spin ();
00067
00073 void
00074 spinOnce (int time = 1, bool force_redraw = false);
00075
00077 bool
00078 wasStopped () const { return (stopped_); }
00079
00086 boost::signals2::connection
00087 registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*),
00088 void* cookie = NULL)
00089 {
00090 return registerKeyboardCallback (boost::bind (callback, _1, cookie));
00091 }
00092
00100 template<typename T> boost::signals2::connection
00101 registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*),
00102 T& instance, void* cookie = NULL)
00103 {
00104 return registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie));
00105 }
00106
00113 boost::signals2::connection
00114 registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*),
00115 void* cookie = NULL)
00116 {
00117 return registerMouseCallback (boost::bind (callback, _1, cookie));
00118 }
00119
00127 template<typename T> boost::signals2::connection
00128 registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*),
00129 T& instance, void* cookie = NULL)
00130 {
00131 return registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie));
00132 }
00133
00134 protected:
00135
00137 void
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
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:
00169 struct ExitMainLoopTimerCallback : public vtkCommand
00170 {
00171 static ExitMainLoopTimerCallback* New()
00172 {
00173 return (new ExitMainLoopTimerCallback);
00174 }
00175
00176 ExitMainLoopTimerCallback () : right_timer_id (), window () {}
00177 ExitMainLoopTimerCallback (const ExitMainLoopTimerCallback& src) : vtkCommand (), right_timer_id (src.right_timer_id), window (src.window) {}
00178 ExitMainLoopTimerCallback& operator = (const ExitMainLoopTimerCallback& src) { right_timer_id = src.right_timer_id; window = src.window; return (*this); }
00179
00180 virtual void
00181 Execute (vtkObject*, unsigned long event_id, void* call_data)
00182 {
00183 if (event_id != vtkCommand::TimerEvent)
00184 return;
00185 int timer_id = *static_cast<int*> (call_data);
00186
00187 if (timer_id != right_timer_id)
00188 return;
00189 window->interactor_->TerminateApp ();
00190
00191 }
00192 int right_timer_id;
00193 Window* window;
00194 };
00195
00196 struct ExitCallback : public vtkCommand
00197 {
00198 static ExitCallback* New ()
00199 {
00200 return (new ExitCallback);
00201 }
00202
00203 ExitCallback () : window () {}
00204 ExitCallback (const ExitCallback &src) : vtkCommand (), window (src.window) {}
00205 ExitCallback& operator = (const ExitCallback &src) { window = src.window; return (*this); }
00206
00207 virtual void
00208 Execute (vtkObject*, unsigned long event_id, void*)
00209 {
00210 if (event_id != vtkCommand::ExitEvent)
00211 return;
00212 window->interactor_->TerminateApp ();
00213 window->stopped_ = true;
00214 }
00215 Window* window;
00216 };
00217
00218 bool stopped_;
00219 int timer_id_;
00220
00221 protected:
00222 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
00223 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
00224
00225 vtkSmartPointer<vtkRenderWindow> win_;
00226 vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
00227 vtkCallbackCommand* mouse_command_;
00228 vtkCallbackCommand* keyboard_command_;
00230 vtkSmartPointer<PCLVisualizerInteractorStyle> style_;
00232 vtkSmartPointer<vtkRendererCollection> rens_;
00233 vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
00234 vtkSmartPointer<ExitCallback> exit_callback_;
00235 };
00236 }
00237 }
00238
00239 #endif
00240