Point Cloud Library (PCL)  1.9.1
cloud_viewer.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  */
36 #ifndef PCL_CLOUD_VIEWER_H_
37 #define PCL_CLOUD_VIEWER_H_
38 
39 #include <pcl/visualization/pcl_visualizer.h> //pcl vis
40 #include <boost/scoped_ptr.hpp> // scoped_ptr for pre-C++11
41 
42 #include <string>
43 
44 namespace pcl
45 {
46  namespace visualization
47  {
48  /** \brief Simple point cloud visualization class
49  * \author Ethan Rublee
50  * \ingroup visualization
51  */
52  class PCL_EXPORTS CloudViewer : boost::noncopyable
53  {
54  public:
59 
60  /** \brief Construct a cloud viewer, with a window name.
61  * \param window_name This is displayed at the top of the window
62  */
63  CloudViewer (const std::string& window_name);
64 
65  /** \brief Will quit the window,
66  * and release all resources held by the viewer.
67  * @return
68  */
69  ~CloudViewer ();
70 
71  /** \brief Show a cloud, with an optional key for multiple clouds.
72  * \param[in] cloud RGB point cloud
73  * \param[in] cloudname a key for the point cloud, use the same name if you would like to overwrite the existing cloud.
74  */
75  void
76  showCloud (const ColorCloud::ConstPtr &cloud, const std::string& cloudname = "cloud");
77 
78  /** \brief Show a cloud, with an optional key for multiple clouds.
79  * \param[in] cloud RGB point cloud
80  * \param[in] cloudname a key for the point cloud, use the same name if you would like to overwrite the existing cloud.
81  */
82  void
83  showCloud (const ColorACloud::ConstPtr &cloud, const std::string& cloudname = "cloud");
84 
85  /** \brief Show a cloud, with an optional key for multiple clouds.
86  * \param[in] cloud XYZI point cloud
87  * \param[in] cloudname a key for the point cloud, use the same name if you would like to overwrite the existing cloud.
88  */
89  void
90  showCloud (const GrayCloud::ConstPtr &cloud, const std::string& cloudname = "cloud");
91 
92 
93  /** \brief Show a cloud, with an optional key for multiple clouds.
94  * \param[in] cloud XYZ point cloud
95  * \param[in] cloudname a key for the point cloud, use the same name if you would like to overwrite the existing cloud.
96  */
97  void
98  showCloud (const MonochromeCloud::ConstPtr &cloud, const std::string& cloudname = "cloud");
99 
100  /** \brief Check if the gui was quit, you should quit also
101  * \param millis_to_wait This will request to "spin" for the number of milliseconds, before exiting.
102  * \return true if the user signaled the gui to stop
103  */
104  bool
105  wasStopped (int millis_to_wait = 1);
106 
107  /** Visualization callable function, may be used for running things on the UI thread.
108  */
109  typedef boost::function1<void, pcl::visualization::PCLVisualizer&> VizCallable;
110 
111  /** \brief Run a callbable object on the UI thread. Will persist until removed
112  * @param x Use boost::ref(x) for a function object that you would like to not copy
113  * \param key The key for the callable -- use the same key to overwrite.
114  */
115  void
116  runOnVisualizationThread (VizCallable x, const std::string& key = "callable");
117 
118  /** \brief Run a callbable object on the UI thread. This will run once and be removed
119  * @param x Use boost::ref(x) for a function object that you would like to not copy
120  */
121  void
122  runOnVisualizationThreadOnce (VizCallable x);
123 
124  /** \brief Remove a previously added callable object, NOP if it doesn't exist.
125  * @param key the key that was registered with the callable object.
126  */
127  void
128  removeVisualizationCallable (const std::string& key = "callable");
129 
130  /** \brief Register a callback function for keyboard events
131  * \param[in] callback the function that will be registered as a callback for a keyboard event
132  * \param[in] cookie user data that is passed to the callback
133  * \return connection object that allows to disconnect the callback function.
134  */
135  inline boost::signals2::connection
136  registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*), void* cookie = NULL)
137  {
138  return (registerKeyboardCallback (boost::bind (callback, _1, cookie)));
139  }
140 
141  /** \brief Register a callback function for keyboard events
142  * \param[in] callback the member function that will be registered as a callback for a keyboard event
143  * \param[in] instance instance to the class that implements the callback function
144  * \param[in] cookie user data that is passed to the callback
145  * \return connection object that allows to disconnect the callback function.
146  */
147  template<typename T> inline boost::signals2::connection
148  registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*), T& instance, void* cookie = NULL)
149  {
150  return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
151  }
152 
153  /** \brief Register a callback function for mouse events
154  * \param[in] callback the function that will be registered as a callback for a mouse event
155  * \param[in] cookie user data that is passed to the callback
156  * \return connection object that allows to disconnect the callback function.
157  */
158  inline boost::signals2::connection
159  registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*), void* cookie = NULL)
160  {
161  return (registerMouseCallback (boost::bind (callback, _1, cookie)));
162  }
163 
164  /** \brief Register a callback function for mouse events
165  * \param[in] callback the member function that will be registered as a callback for a mouse event
166  * \param[in] instance instance to the class that implements the callback function
167  * \param[in] cookie user data that is passed to the callback
168  * \return connection object that allows to disconnect the callback function.
169  */
170  template<typename T> inline boost::signals2::connection
171  registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*), T& instance, void* cookie = NULL)
172  {
173  return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
174  }
175 
176 
177  /** \brief Register a callback function for point picking events
178  * \param[in] callback the function that will be registered as a callback for a point picking event
179  * \param[in] cookie user data that is passed to the callback
180  * \return connection object that allows to disconnect the callback function.
181  */
182  inline boost::signals2::connection
183  registerPointPickingCallback (void (*callback) (const pcl::visualization::PointPickingEvent&, void*), void* cookie = NULL)
184  {
185  return (registerPointPickingCallback (boost::bind (callback, _1, cookie)));
186  }
187 
188  /** \brief Register a callback function for point picking events
189  * \param[in] callback the member function that will be registered as a callback for a point picking event
190  * \param[in] instance instance to the class that implements the callback function
191  * \param[in] cookie user data that is passed to the callback
192  * \return connection object that allows to disconnect the callback function.
193  */
194  template<typename T> inline boost::signals2::connection
195  registerPointPickingCallback (void (T::*callback) (const pcl::visualization::PointPickingEvent&, void*), T& instance, void* cookie = NULL)
196  {
197  return (registerPointPickingCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
198  }
199 
200  private:
201  /** \brief Private implementation. */
202  struct CloudViewer_impl;
203  boost::scoped_ptr<CloudViewer_impl> impl_;
204 
205  boost::signals2::connection
206  registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)>);
207 
208  boost::signals2::connection
209  registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)>);
210 
211  boost::signals2::connection
212  registerPointPickingCallback (boost::function<void (const pcl::visualization::PointPickingEvent&)>);
213  };
214  }
215 }
216 
217 #endif /* CLOUD_VIEWER_H_ */
boost::signals2::connection registerMouseCallback(void(T::*callback)(const pcl::visualization::MouseEvent &, void *), T &instance, void *cookie=NULL)
Register a callback function for mouse events.
Definition: cloud_viewer.h:171
boost::signals2::connection registerPointPickingCallback(void(T::*callback)(const pcl::visualization::PointPickingEvent &, void *), T &instance, void *cookie=NULL)
Register a callback function for point picking events.
Definition: cloud_viewer.h:195
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::PointCloud< pcl::PointXYZI > GrayCloud
Definition: cloud_viewer.h:57
/brief Class representing 3D point picking events.
pcl::PointCloud< pcl::PointXYZ > MonochromeCloud
Definition: cloud_viewer.h:58
pcl::PointCloud< pcl::PointXYZRGB > ColorCloud
Definition: cloud_viewer.h:56
boost::function1< void, pcl::visualization::PCLVisualizer & > VizCallable
Visualization callable function, may be used for running things on the UI thread. ...
Definition: cloud_viewer.h:109
boost::shared_ptr< const PointCloud< pcl::PointXYZRGB > > ConstPtr
Definition: point_cloud.h:429
Simple point cloud visualization class.
Definition: cloud_viewer.h:52
boost::signals2::connection registerKeyboardCallback(void(T::*callback)(const pcl::visualization::KeyboardEvent &, void *), T &instance, void *cookie=NULL)
Register a callback function for keyboard events.
Definition: cloud_viewer.h:148
boost::signals2::connection registerKeyboardCallback(void(*callback)(const pcl::visualization::KeyboardEvent &, void *), void *cookie=NULL)
Register a callback function for keyboard events.
Definition: cloud_viewer.h:136
boost::signals2::connection registerPointPickingCallback(void(*callback)(const pcl::visualization::PointPickingEvent &, void *), void *cookie=NULL)
Register a callback function for point picking events.
Definition: cloud_viewer.h:183
/brief Class representing key hit/release events
boost::signals2::connection registerMouseCallback(void(*callback)(const pcl::visualization::MouseEvent &, void *), void *cookie=NULL)
Register a callback function for mouse events.
Definition: cloud_viewer.h:159
pcl::PointCloud< pcl::PointXYZRGBA > ColorACloud
Definition: cloud_viewer.h:55