Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
interactor_style.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: interactor_style.h 5501 2012-04-04 07:08:51Z rusu $
37  *
38  */
39 #ifndef PCL_PCL_VISUALIZER_INTERACTOR_STYLE_H_
40 #define PCL_PCL_VISUALIZER_INTERACTOR_STYLE_H_
41 
42 #include <pcl/visualization/vtk.h>
43 #include <boost/shared_ptr.hpp>
44 #include <pcl/console/print.h>
47 #include <boost/shared_ptr.hpp>
48 #include <boost/signals2.hpp>
52 
53 namespace pcl
54 {
55  namespace visualization
56  {
57 
62  {
66  };
67 
96  class PCL_EXPORTS PCLVisualizerInteractorStyle : public vtkInteractorStyleTrackballCamera
97  {
98  typedef boost::shared_ptr<CloudActorMap> CloudActorMapPtr;
99 
100  public:
101  static PCLVisualizerInteractorStyle *New ();
102 
105  init_ (), rens_ (), actors_ (), win_height_ (), win_width_ (), win_pos_x_ (), win_pos_y_ (),
106  max_win_height_ (), max_win_width_ (), grid_enabled_ (), grid_actor_ (), lut_enabled_ (),
107  lut_actor_ (), snapshot_writer_ (), wif_ (), mouse_signal_ (), keyboard_signal_ (),
108  point_picking_signal_ (), stereo_anaglyph_mask_default_ (), mouse_callback_ (), modifier_ ()
109  {}
110 
111  // this macro defines Superclass, the isA functionality and the safe downcast method
112  vtkTypeMacro (PCLVisualizerInteractorStyle, vtkInteractorStyleTrackballCamera);
113 
115  virtual void
116  Initialize ();
117 
121  inline void
122  setCloudActorMap (const CloudActorMapPtr &actors) { actors_ = actors; }
123 
125  inline CloudActorMapPtr
126  getCloudActorMap () { return (actors_); }
127 
131  void
132  setRendererCollection (vtkSmartPointer<vtkRendererCollection> &rens) { rens_ = rens; }
133 
138  boost::signals2::connection
139  registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)> cb);
140 
145  boost::signals2::connection
146  registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)> cb);
147 
152  boost::signals2::connection
153  registerPointPickingCallback (boost::function<void (const pcl::visualization::PointPickingEvent&)> cb);
154 
158  void
159  saveScreenshot (const std::string &file);
160 
168  inline void
170  {
171  modifier_ = modifier;
172  }
173 
174  protected:
176  bool init_;
177 
179  vtkSmartPointer<vtkRendererCollection> rens_;
180 
182  CloudActorMapPtr actors_;
183 
185  int win_height_, win_width_;
186 
188  int win_pos_x_, win_pos_y_;
189 
191  int max_win_height_, max_win_width_;
192 
194  bool grid_enabled_;
196  vtkSmartPointer<vtkLegendScaleActor> grid_actor_;
197 
199  bool lut_enabled_;
201  vtkSmartPointer<vtkScalarBarActor> lut_actor_;
202 
204  vtkSmartPointer<vtkPNGWriter> snapshot_writer_;
206  vtkSmartPointer<vtkWindowToImageFilter> wif_;
207 
208  boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
209  boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
210  boost::signals2::signal<void (const pcl::visualization::PointPickingEvent&)> point_picking_signal_;
211 
213  virtual void
214  OnChar ();
215 
216  // Keyboard events
217  virtual void
218  OnKeyDown ();
219  virtual void
220  OnKeyUp ();
221 
222  // mouse button events
223  virtual void
224  OnMouseMove ();
225  virtual void
226  OnLeftButtonDown ();
227  virtual void
228  OnLeftButtonUp ();
229  virtual void
230  OnMiddleButtonDown ();
231  virtual void
232  OnMiddleButtonUp ();
233  virtual void
234  OnRightButtonDown ();
235  virtual void
236  OnRightButtonUp ();
237  virtual void
238  OnMouseWheelForward ();
239  virtual void
240  OnMouseWheelBackward ();
241 
242  // mouse move event
244  virtual void
245  OnTimer ();
246 
248  void
249  zoomIn ();
250 
252  void
253  zoomOut ();
254 
256  bool stereo_anaglyph_mask_default_;
257 
259  vtkSmartPointer<PointPickingCallback> mouse_callback_;
260 
262  InteractorKeyboardModifier modifier_;
263 
264  friend class PointPickingCallback;
265  vtkSmartPointer<vtkPolyData> full_data_;
266  };
267 
271  class PCLHistogramVisualizerInteractorStyle : public vtkInteractorStyleTrackballCamera
272  {
273  public:
275 
277  PCLHistogramVisualizerInteractorStyle () : wins_ (), init_ (false) {}
278 
280  void
281  Initialize ();
282 
286  void
287  setRenWinInteractMap (const RenWinInteractMap &wins) { wins_ = wins; }
288 
289  private:
291  RenWinInteractMap wins_;
292 
294  bool init_;
295 
297  void OnKeyDown ();
298 
300  void OnTimer ();
301  };
302  }
303 }
304 
305 #endif