window.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2009-2012, Willow Garage, Inc.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  */
00038 
00039 #ifndef PCL_VISUALIZER_WINDOW_H__
00040 #define PCL_VISUALIZER_WINDOW_H__
00041 
00042 #include <pcl/pcl_macros.h>
00043 #include <boost/signals2/signal.hpp>
00044 
00045 #include <vtkCommand.h>
00046 
00047 template <typename T> class vtkSmartPointer;
00048 class vtkObject;
00049 class vtkRenderWindow;
00050 class vtkRenderWindowInteractor;
00051 class vtkCallbackCommand;
00052 class vtkRendererCollection;
00053 class PCLVisualizerInteractorStyle;
00054 
00055 namespace pcl
00056 {
00057   namespace visualization
00058   {
00059     class MouseEvent;
00060     class KeyboardEvent;
00061 
00062     class PCL_EXPORTS Window
00063     {
00064       public:
00065         Window (const std::string& window_name = "");
00066         Window (const Window &src);
00067         Window& operator = (const Window &src);
00068 
00069         virtual ~Window ();
00070 
00072         void
00073         spin ();
00074 
00080         void
00081         spinOnce (int time = 1, bool force_redraw = false);
00082 
00084         bool
00085         wasStopped () const { return (stopped_); }
00086 
00093         boost::signals2::connection
00094         registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*),
00095                                   void* cookie = NULL)
00096         {
00097           return registerKeyboardCallback (boost::bind (callback, _1, cookie));
00098         }
00099 
00107         template<typename T> boost::signals2::connection
00108         registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*),
00109                                   T& instance, void* cookie = NULL)
00110         {
00111           return registerKeyboardCallback (boost::bind (callback,  boost::ref (instance), _1, cookie));
00112         }
00113 
00120         boost::signals2::connection
00121         registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*),
00122                                void* cookie = NULL)
00123         {
00124           return registerMouseCallback (boost::bind (callback, _1, cookie));
00125         }
00126 
00134         template<typename T> boost::signals2::connection
00135         registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*),
00136                                T& instance, void* cookie = NULL)
00137         {
00138           return registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie));
00139         }
00140 
00141       protected: // methods
00142 
00144         void
00145         resetStoppedFlag () { stopped_ = false; }
00146 
00152         boost::signals2::connection
00153         registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)> );
00154 
00160         boost::signals2::connection
00161         registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)> );
00162 
00163         void
00164         emitMouseEvent (unsigned long event_id);
00165 
00166         void
00167         emitKeyboardEvent (unsigned long event_id);
00168 
00169         // Callbacks used to register for vtk command
00170         static void
00171         MouseCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata);
00172         static void
00173         KeyboardCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata);
00174 
00175       protected: // types
00176         struct ExitMainLoopTimerCallback : public vtkCommand
00177         {
00178           static ExitMainLoopTimerCallback* New ()
00179           {
00180             return (new ExitMainLoopTimerCallback);
00181           }
00182 
00183           ExitMainLoopTimerCallback ();
00184           ExitMainLoopTimerCallback (const ExitMainLoopTimerCallback& src);
00185           ExitMainLoopTimerCallback& operator = (const ExitMainLoopTimerCallback& src);
00186 
00187           virtual void 
00188           Execute (vtkObject*, unsigned long event_id, void* call_data);
00189 
00190           int right_timer_id;
00191           Window* window;
00192         };
00193 
00194         struct ExitCallback : public vtkCommand
00195         {
00196           static ExitCallback* New ()
00197           {
00198             return (new ExitCallback);
00199           }
00200 
00201           ExitCallback ();
00202           ExitCallback (const ExitCallback &src);
00203           ExitCallback& operator = (const ExitCallback &src);
00204  
00205           virtual void 
00206           Execute (vtkObject*, unsigned long event_id, void*);
00207 
00208           Window* window;
00209         };
00210 
00211         bool stopped_;
00212         int timer_id_;
00213 
00214     protected: // member fields
00215         boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
00216         boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
00217 
00218         vtkSmartPointer<vtkRenderWindow> win_;
00219         vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
00220         vtkCallbackCommand* mouse_command_;
00221         vtkCallbackCommand* keyboard_command_;
00223         vtkSmartPointer<PCLVisualizerInteractorStyle> style_;
00225         vtkSmartPointer<vtkRendererCollection> rens_;
00226         vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
00227         vtkSmartPointer<ExitCallback> exit_callback_;
00228     };
00229   }
00230 }
00231 
00232 #endif  /* __WINDOW_H__ */
00233 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:38:43