Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 3771 2012-01-01 06:58:14Z 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 
00103         inline CloudActorMapPtr 
00104         getCloudActorMap () { return (actors_); }
00105 
00109         void 
00110         setRendererCollection (vtkSmartPointer<vtkRendererCollection> &rens) { rens_ = rens; }
00111 
00116         boost::signals2::connection 
00117         registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)> cb);
00118 
00123         boost::signals2::connection 
00124         registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)> cb);
00125 
00130         boost::signals2::connection 
00131         registerPointPickingCallback (boost::function<void (const pcl::visualization::PointPickingEvent&)> cb);
00132 
00136         void
00137         saveScreenshot (const std::string &file);
00138 
00139        protected:
00141         bool init_;
00142 
00144         vtkSmartPointer<vtkRendererCollection> rens_;
00145 
00147         CloudActorMapPtr actors_;
00148 
00150         int win_height_, win_width_;
00151 
00153         int win_pos_x_, win_pos_y_;
00154 
00156         int max_win_height_, max_win_width_;
00157 
00159         bool grid_enabled_;
00161         vtkSmartPointer<vtkLegendScaleActor> grid_actor_;
00162 
00164         bool lut_enabled_;
00166         vtkSmartPointer<vtkScalarBarActor> lut_actor_;
00167 
00169         vtkSmartPointer<vtkPNGWriter> snapshot_writer_;
00171         vtkSmartPointer<vtkWindowToImageFilter> wif_;
00172 
00173         boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
00174         boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
00175         boost::signals2::signal<void (const pcl::visualization::PointPickingEvent&)> point_picking_signal_;
00176 
00178         virtual void 
00179         OnChar ();
00180 
00181         // Keyboard events
00182         virtual void 
00183         OnKeyDown ();
00184         virtual void 
00185         OnKeyUp ();
00186         
00187         // mouse button events
00188         virtual void  
00189         OnMouseMove ();
00190         virtual void  
00191         OnLeftButtonDown ();
00192         virtual void  
00193         OnLeftButtonUp ();
00194         virtual void  
00195         OnMiddleButtonDown ();
00196         virtual void  
00197         OnMiddleButtonUp ();
00198         virtual void  
00199         OnRightButtonDown ();
00200         virtual void  
00201         OnRightButtonUp ();
00202         virtual void  
00203         OnMouseWheelForward ();
00204         virtual void  
00205         OnMouseWheelBackward ();
00206         
00207         // mouse move event
00209         virtual void 
00210         OnTimer ();
00211 
00213         void 
00214         zoomIn ();
00215 
00217         void 
00218         zoomOut ();
00219 
00221         bool stereo_anaglyph_mask_default_;
00222 
00224         vtkSmartPointer<PointPickingCallback> mouse_callback_;
00225 
00226         friend class PointPickingCallback;
00227     };
00228 
00232     class PCLHistogramVisualizerInteractorStyle : public vtkInteractorStyleTrackballCamera
00233     {
00234       public:
00235         static PCLHistogramVisualizerInteractorStyle *New ();
00236 
00238         void 
00239         Initialize ();
00240         
00244         void 
00245         setRenWinInteractMap (const RenWinInteractMap &wins) { wins_ = wins; }
00246 
00247       private:
00249         RenWinInteractMap wins_;
00250 
00252         bool init_;
00253 
00255         void OnKeyDown ();
00256 
00258         void OnTimer ();
00259     };
00260   }
00261 }
00262 
00263 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines