Point Cloud Library (PCL)
1.7.0
|
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 * 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 * $Id$ 00038 * 00039 */ 00040 #ifndef PCL_PCL_VISUALIZER_INTERACTOR_STYLE_H_ 00041 #define PCL_PCL_VISUALIZER_INTERACTOR_STYLE_H_ 00042 00043 #include <pcl/console/print.h> 00044 #include <pcl/visualization/common/actor_map.h> 00045 #include <pcl/visualization/common/ren_win_interact_map.h> 00046 #include <pcl/visualization/keyboard_event.h> 00047 #include <pcl/visualization/mouse_event.h> 00048 #include <pcl/visualization/point_picking_event.h> 00049 #include <pcl/visualization/area_picking_event.h> 00050 #include <boost/signals2/signal.hpp> 00051 00052 #include <vtkInteractorStyleRubberBandPick.h> 00053 00054 class vtkRendererCollection; 00055 class vtkLegendScaleActor; 00056 class vtkScalarBarActor; 00057 class vtkPNGWriter; 00058 class vtkWindowToImageFilter; 00059 class vtkPointPicker; 00060 00061 namespace pcl 00062 { 00063 namespace visualization 00064 { 00065 00066 /** \brief A list of potential keyboard modifiers for \ref PCLVisualizerInteractorStyle. 00067 * Defaults to Alt. 00068 */ 00069 enum InteractorKeyboardModifier 00070 { 00071 INTERACTOR_KB_MOD_ALT, 00072 INTERACTOR_KB_MOD_CTRL, 00073 INTERACTOR_KB_MOD_SHIFT 00074 }; 00075 00076 /** \brief PCLVisualizerInteractorStyle defines an unique, custom VTK 00077 * based interactory style for PCL Visualizer applications. Besides 00078 * defining the rendering style, we also create a list of custom actions 00079 * that are triggered on different keys being pressed: 00080 * 00081 * - p, P : switch to a point-based representation 00082 * - w, W : switch to a wireframe-based representation (where available) 00083 * - s, S : switch to a surface-based representation (where available) 00084 * - j, J : take a .PNG snapshot of the current window view 00085 * - c, C : display current camera/window parameters 00086 * - f, F : fly to point mode 00087 * - e, E : exit the interactor\ 00088 * - q, Q : stop and call VTK's TerminateApp 00089 * - + / - : increment/decrement overall point size 00090 * - g, G : display scale grid (on/off) 00091 * - u, U : display lookup table (on/off) 00092 * - r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}] 00093 * - ALT + s, S : turn stereo mode on/off 00094 * - ALT + f, F : switch between maximized window mode and original size 00095 * - l, L : list all available geometric and color handlers for the current actor map 00096 * - ALT + 0..9 [+ CTRL] : switch between different geometric handlers (where available) 00097 * - 0..9 [+ CTRL] : switch between different color handlers (where available) 00098 * - 00099 * - SHIFT + left click : select a point 00100 * - x, X : toggle rubber band selection mode for left mouse button 00101 * 00102 * \author Radu B. Rusu 00103 * \ingroup visualization 00104 */ 00105 class PCL_EXPORTS PCLVisualizerInteractorStyle : public vtkInteractorStyleRubberBandPick 00106 { 00107 typedef boost::shared_ptr<CloudActorMap> CloudActorMapPtr; 00108 00109 public: 00110 static PCLVisualizerInteractorStyle *New (); 00111 00112 /** \brief Empty constructor. */ 00113 PCLVisualizerInteractorStyle () : 00114 init_ (), rens_ (), actors_ (), win_height_ (), win_width_ (), win_pos_x_ (), win_pos_y_ (), 00115 max_win_height_ (), max_win_width_ (), grid_enabled_ (), grid_actor_ (), lut_enabled_ (), 00116 lut_actor_ (), snapshot_writer_ (), wif_ (), mouse_signal_ (), keyboard_signal_ (), 00117 point_picking_signal_ (), area_picking_signal_ (), stereo_anaglyph_mask_default_ (), 00118 mouse_callback_ (), modifier_ () 00119 {} 00120 00121 /** \brief Empty destructor */ 00122 virtual ~PCLVisualizerInteractorStyle () {} 00123 00124 // this macro defines Superclass, the isA functionality and the safe downcast method 00125 vtkTypeMacro (PCLVisualizerInteractorStyle, vtkInteractorStyleRubberBandPick); 00126 00127 /** \brief Initialization routine. Must be called before anything else. */ 00128 virtual void 00129 Initialize (); 00130 00131 /** \brief Pass a pointer to the actor map 00132 * \param[in] actors the actor map that will be used with this style 00133 */ 00134 inline void 00135 setCloudActorMap (const CloudActorMapPtr &actors) { actors_ = actors; } 00136 00137 /** \brief Get the cloud actor map pointer. */ 00138 inline CloudActorMapPtr 00139 getCloudActorMap () { return (actors_); } 00140 00141 /** \brief Pass a set of renderers to the interactor style. 00142 * \param[in] rens the vtkRendererCollection to use 00143 */ 00144 void 00145 setRendererCollection (vtkSmartPointer<vtkRendererCollection> &rens) { rens_ = rens; } 00146 00147 /** \brief Pass a pointer to the actor map 00148 * \param[in] actors the actor map that will be used with this style 00149 */ 00150 inline void 00151 setUseVbos (const bool use_vbos) { use_vbos_ = use_vbos; } 00152 00153 /** \brief Register a callback function for mouse events 00154 * \param[in] cb a boost function that will be registered as a callback for a mouse event 00155 * \return a connection object that allows to disconnect the callback function. 00156 */ 00157 boost::signals2::connection 00158 registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)> cb); 00159 00160 /** \brief Register a callback boost::function for keyboard events 00161 * \param[in] cb a boost function that will be registered as a callback for a keyboard event 00162 * \return a connection object that allows to disconnect the callback function. 00163 */ 00164 boost::signals2::connection 00165 registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)> cb); 00166 00167 /** \brief Register a callback function for point picking events 00168 * \param[in] cb a boost function that will be registered as a callback for a point picking event 00169 * \return a connection object that allows to disconnect the callback function. 00170 */ 00171 boost::signals2::connection 00172 registerPointPickingCallback (boost::function<void (const pcl::visualization::PointPickingEvent&)> cb); 00173 00174 /** \brief Register a callback function for area picking events 00175 * \param[in] cb a boost function that will be registered as a callback for a area picking event 00176 * \return a connection object that allows to disconnect the callback function. 00177 */ 00178 boost::signals2::connection 00179 registerAreaPickingCallback (boost::function<void (const pcl::visualization::AreaPickingEvent&)> cb); 00180 00181 /** \brief Save the current rendered image to disk, as a PNG screenshot. 00182 * \param[in] file the name of the PNG file 00183 */ 00184 void 00185 saveScreenshot (const std::string &file); 00186 00187 /** \brief Change the default keyboard modified from ALT to a different special key. 00188 * Allowed values are: 00189 * - INTERACTOR_KB_MOD_ALT 00190 * - INTERACTOR_KB_MOD_CTRL 00191 * - INTERACTOR_KB_MOD_SHIFT 00192 * \param[in] modifier the new keyboard modifier 00193 */ 00194 inline void 00195 setKeyboardModifier (const InteractorKeyboardModifier &modifier) 00196 { 00197 modifier_ = modifier; 00198 } 00199 00200 protected: 00201 /** \brief Set to true after initialization is complete. */ 00202 bool init_; 00203 00204 /** \brief Collection of vtkRenderers stored internally. */ 00205 vtkSmartPointer<vtkRendererCollection> rens_; 00206 00207 /** \brief Actor map stored internally. */ 00208 CloudActorMapPtr actors_; 00209 00210 /** \brief The current window width/height. */ 00211 int win_height_, win_width_; 00212 00213 /** \brief The current window position x/y. */ 00214 int win_pos_x_, win_pos_y_; 00215 00216 /** \brief The maximum resizeable window width/height. */ 00217 int max_win_height_, max_win_width_; 00218 00219 /** \brief The maximum resizeable window width/height. */ 00220 bool use_vbos_; 00221 00222 /** \brief Set to true if the grid actor is enabled. */ 00223 bool grid_enabled_; 00224 /** \brief Actor for 2D grid on screen. */ 00225 vtkSmartPointer<vtkLegendScaleActor> grid_actor_; 00226 00227 /** \brief Set to true if the LUT actor is enabled. */ 00228 bool lut_enabled_; 00229 /** \brief Actor for 2D lookup table on screen. */ 00230 vtkSmartPointer<vtkScalarBarActor> lut_actor_; 00231 00232 /** \brief A PNG writer for screenshot captures. */ 00233 vtkSmartPointer<vtkPNGWriter> snapshot_writer_; 00234 /** \brief Internal window to image filter. Needed by \a snapshot_writer_. */ 00235 vtkSmartPointer<vtkWindowToImageFilter> wif_; 00236 /** \brief Stores the point picker when switching to an area picker. */ 00237 vtkSmartPointer<vtkPointPicker> point_picker_; 00238 00239 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_; 00240 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_; 00241 boost::signals2::signal<void (const pcl::visualization::PointPickingEvent&)> point_picking_signal_; 00242 boost::signals2::signal<void (const pcl::visualization::AreaPickingEvent&)> area_picking_signal_; 00243 00244 /** \brief Interactor style internal method. Gets called whenever a key is pressed. */ 00245 virtual void 00246 OnChar (); 00247 00248 // Keyboard events 00249 virtual void 00250 OnKeyDown (); 00251 virtual void 00252 OnKeyUp (); 00253 00254 // mouse button events 00255 virtual void 00256 OnMouseMove (); 00257 virtual void 00258 OnLeftButtonDown (); 00259 virtual void 00260 OnLeftButtonUp (); 00261 virtual void 00262 OnMiddleButtonDown (); 00263 virtual void 00264 OnMiddleButtonUp (); 00265 virtual void 00266 OnRightButtonDown (); 00267 virtual void 00268 OnRightButtonUp (); 00269 virtual void 00270 OnMouseWheelForward (); 00271 virtual void 00272 OnMouseWheelBackward (); 00273 00274 // mouse move event 00275 /** \brief Interactor style internal method. Gets called periodically if a timer is set. */ 00276 virtual void 00277 OnTimer (); 00278 00279 /** \brief Interactor style internal method. Zoom in. */ 00280 void 00281 zoomIn (); 00282 00283 /** \brief Interactor style internal method. Zoom out. */ 00284 void 00285 zoomOut (); 00286 00287 /** \brief True if we're using red-blue colors for anaglyphic stereo, false if magenta-green. */ 00288 bool stereo_anaglyph_mask_default_; 00289 00290 /** \brief A VTK Mouse Callback object, used for point picking. */ 00291 vtkSmartPointer<PointPickingCallback> mouse_callback_; 00292 00293 /** \brief The keyboard modifier to use. Default: Alt. */ 00294 InteractorKeyboardModifier modifier_; 00295 00296 friend class PointPickingCallback; 00297 }; 00298 00299 /** \brief PCL histogram visualizer interactory style class. 00300 * \author Radu B. Rusu 00301 */ 00302 class PCLHistogramVisualizerInteractorStyle : public vtkInteractorStyleTrackballCamera 00303 { 00304 public: 00305 static PCLHistogramVisualizerInteractorStyle *New (); 00306 00307 /** \brief Empty constructor. */ 00308 PCLHistogramVisualizerInteractorStyle () : wins_ (), init_ (false) {} 00309 00310 /** \brief Initialization routine. Must be called before anything else. */ 00311 void 00312 Initialize (); 00313 00314 /** \brief Pass a map of render/window/interactors to the interactor style. 00315 * \param[in] wins the RenWinInteract map to use 00316 */ 00317 void 00318 setRenWinInteractMap (const RenWinInteractMap &wins) { wins_ = wins; } 00319 00320 private: 00321 /** \brief A map of all windows on screen (with their renderers and interactors). */ 00322 RenWinInteractMap wins_; 00323 00324 /** \brief Set to true after initialization is complete. */ 00325 bool init_; 00326 00327 /** \brief Interactor style internal method. Gets called whenever a key is pressed. */ 00328 void OnKeyDown (); 00329 00330 /** \brief Interactor style internal method. Gets called periodically if a timer is set. */ 00331 void OnTimer (); 00332 }; 00333 } 00334 } 00335 00336 #endif