Point Cloud Library (PCL)  1.3.1
interactor_style.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) 2010-2011, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id: interactor_style.h 2750 2011-10-13 18:26:22Z rusu $
00037  *
00038  */
00039 #ifndef PCL_PCL_VISUALIZER_INTERACTOR_STYLE_H_
00040 #define PCL_PCL_VISUALIZER_INTERACTOR_STYLE_H_
00041 
00042 // VTK includes
00043 #include <vtkSmartPointer.h>
00044 #include <vtkRendererCollection.h>
00045 #include <vtkLegendScaleActor.h>
00046 #include <vtkPNGWriter.h>
00047 #include <vtkWindowToImageFilter.h>
00048 #include <vtkInteractorStyleTrackballCamera.h>
00049 #include <vtkRenderWindowInteractor.h>
00050 #include <vtkRenderWindow.h>
00051 #include <vtkAssemblyPath.h>
00052 #include <vtkCommand.h>
00053 #include <vtkProperty.h>
00054 #include <vtkCamera.h>
00055 #include <vtkObjectFactory.h>
00056 #include <vtkScalarBarActor.h>
00057 #include <vtkScalarsToColors.h>
00058 #include <vtkBoxRepresentation.h>
00059 #include <vtkBoxWidget.h>
00060 #include <vtkBoxWidget2.h>
00061 #include <vtkClipPolyData.h>
00062 #include <vtkPlanes.h>
00063 
00064 #include <boost/shared_ptr.hpp>
00065 #include <pcl/console/print.h>
00066 #include <pcl/visualization/common/actor_map.h>
00067 #include <pcl/visualization/common/ren_win_interact_map.h>
00068 #include <boost/shared_ptr.hpp>
00069 #include <boost/signals2.hpp>
00070 //#include <boost/signals2/slot.hpp>
00071 #include <pcl/visualization/keyboard_event.h>
00072 #include <pcl/visualization/mouse_event.h>
00073 #include <pcl/visualization/point_picking_event.h>
00074 
00075 namespace pcl
00076 {
00077   namespace visualization
00078   {
00083     class PCL_EXPORTS PCLVisualizerInteractorStyle : public vtkInteractorStyleTrackballCamera
00084     {
00085       typedef boost::shared_ptr<CloudActorMap> CloudActorMapPtr;
00086 
00087       public:
00088         static PCLVisualizerInteractorStyle *New ();
00089         // this macro defines Superclass, the isA functionality and the safe downcast method
00090         vtkTypeMacro(PCLVisualizerInteractorStyle,vtkInteractorStyleTrackballCamera);
00091         
00093         virtual void 
00094         Initialize ();
00095         
00099         inline void 
00100         setCloudActorMap (const CloudActorMapPtr &actors) { actors_ = actors; }
00101         inline CloudActorMapPtr 
00102         getCloudActorMap () { return (actors_); }
00103 
00107         void 
00108         setRendererCollection (vtkSmartPointer<vtkRendererCollection> &rens) { rens_ = rens; }
00109 
00114         boost::signals2::connection 
00115         registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)> );
00116 
00121         boost::signals2::connection 
00122         registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)> );
00123 
00128         boost::signals2::connection 
00129         registerPointPickingCallback (boost::function<void (const pcl::visualization::PointPickingEvent&)>);
00130 
00134         void
00135         saveScreenshot (const std::string &file);
00136 
00137        protected:
00139         bool init_;
00140 
00142         vtkSmartPointer<vtkRendererCollection> rens_;
00143 
00145         CloudActorMapPtr actors_;
00146 
00148         int win_height_, win_width_;
00149 
00151         int win_pos_x_, win_pos_y_;
00152 
00154         int max_win_height_, max_win_width_;
00155 
00157         bool grid_enabled_;
00159         vtkSmartPointer<vtkLegendScaleActor> grid_actor_;
00160 
00162         bool lut_enabled_;
00164         vtkSmartPointer<vtkScalarBarActor> lut_actor_;
00165 
00167         vtkSmartPointer<vtkPNGWriter> snapshot_writer_;
00169         vtkSmartPointer<vtkWindowToImageFilter> wif_;
00170 
00171         boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
00172         boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
00173         boost::signals2::signal<void (const pcl::visualization::PointPickingEvent&)> point_picking_signal_;
00174 
00176         virtual void 
00177         OnChar ();
00178 
00179         // Keyboard events
00180         virtual void 
00181         OnKeyDown ();
00182         virtual void 
00183         OnKeyUp ();
00184         
00185         // mouse button events
00186         virtual void  
00187         OnMouseMove ();
00188         virtual void  
00189         OnLeftButtonDown ();
00190         virtual void  
00191         OnLeftButtonUp ();
00192         virtual void  
00193         OnMiddleButtonDown ();
00194         virtual void  
00195         OnMiddleButtonUp ();
00196         virtual void  
00197         OnRightButtonDown ();
00198         virtual void  
00199         OnRightButtonUp ();
00200         virtual void  
00201         OnMouseWheelForward ();
00202         virtual void  
00203         OnMouseWheelBackward ();
00204         
00205         // mouse move event
00207         virtual void 
00208         OnTimer ();
00209 
00211         void 
00212         zoomIn ();
00213 
00215         void 
00216         zoomOut ();
00217 
00219         bool stereo_anaglyph_mask_default_;
00220 
00222         vtkSmartPointer<PointPickingCallback> mouse_callback_;
00223 
00224         friend class PointPickingCallback;
00225     };
00226 
00230     class PCLHistogramVisualizerInteractorStyle : public vtkInteractorStyleTrackballCamera
00231     {
00232       public:
00233         static PCLHistogramVisualizerInteractorStyle *New ();
00234 
00236         void 
00237         Initialize ();
00238         
00242         void 
00243         setRenWinInteractMap (const RenWinInteractMap &wins) { wins_ = wins; }
00244 
00245       private:
00247         RenWinInteractMap wins_;
00248 
00250         bool init_;
00251 
00253         void OnKeyDown ();
00254 
00256         void OnTimer ();
00257     };
00258   }
00259 }
00260 
00261 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines