Point Cloud Library (PCL)  1.7.0
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 
41 #include <string>
42 
43 namespace pcl
44 {
45  namespace visualization
46  {
47  /** \brief Simple point cloud visualization class
48  * \author Ethan Rublee
49  * \ingroup visualization
50  */
51  class PCL_EXPORTS CloudViewer : boost::noncopyable
52  {
53  public:
58 
59  /** \brief Construct a cloud viewer, with a window name.
60  * \param window_name This is displayed at the top of the window
61  */
62  CloudViewer (const std::string& window_name);
63 
64  /** \brief Will quit the window,
65  * and release all resources held by the viewer.
66  * @return
67  */
68  ~CloudViewer ();
69 
70  /** \brief Show a cloud, with an optional key for multiple clouds.
71  * \param[in] cloud RGB point cloud
72  * \param[in] cloudname a key for the point cloud, use the same name if you would like to overwrite the existing cloud.
73  */
74  void
75  showCloud (const ColorCloud::ConstPtr &cloud, const std::string& cloudname = "cloud");
76 
77  /** \brief Show a cloud, with an optional key for multiple clouds.
78  * \param[in] cloud RGB point cloud
79  * \param[in] cloudname a key for the point cloud, use the same name if you would like to overwrite the existing cloud.
80  */
81  void
82  showCloud (const ColorACloud::ConstPtr &cloud, const std::string& cloudname = "cloud");
83 
84  /** \brief Show a cloud, with an optional key for multiple clouds.
85  * \param[in] cloud XYZI point cloud
86  * \param[in] cloudname a key for the point cloud, use the same name if you would like to overwrite the existing cloud.
87  */
88  void
89  showCloud (const GrayCloud::ConstPtr &cloud, const std::string& cloudname = "cloud");
90 
91 
92  /** \brief Show a cloud, with an optional key for multiple clouds.
93  * \param[in] cloud XYZ point cloud
94  * \param[in] cloudname a key for the point cloud, use the same name if you would like to overwrite the existing cloud.
95  */
96  void
97  showCloud (const MonochromeCloud::ConstPtr &cloud, const std::string& cloudname = "cloud");
98 
99  /** \brief Check if the gui was quit, you should quit also
100  * \param millis_to_wait This will request to "spin" for the number of milliseconds, before exiting.
101  * \return true if the user signaled the gui to stop
102  */
103  bool
104  wasStopped (int millis_to_wait = 1);
105 
106  /** Visualization callable function, may be used for running things on the UI thread.
107  */
108  typedef boost::function1<void, pcl::visualization::PCLVisualizer&> VizCallable;
109 
110  /** \brief Run a callbable object on the UI thread. Will persist until removed
111  * @param x Use boost::ref(x) for a function object that you would like to not copy
112  * \param key The key for the callable -- use the same key to overwrite.
113  */
114  void
115  runOnVisualizationThread (VizCallable x, const std::string& key = "callable");
116 
117  /** \brief Run a callbable object on the UI thread. This will run once and be removed
118  * @param x Use boost::ref(x) for a function object that you would like to not copy
119  */
120  void
121  runOnVisualizationThreadOnce (VizCallable x);
122 
123  /** \brief Remove a previously added callable object, NOP if it doesn't exist.
124  * @param key the key that was registered with the callable object.
125  */
126  void
127  removeVisualizationCallable (const std::string& key = "callable");
128 
129  /** \brief Register a callback function for keyboard events
130  * \param[in] callback the function that will be registered as a callback for a keyboard event
131  * \param[in] cookie user data that is passed to the callback
132  * \return connection object that allows to disconnect the callback function.
133  */
134  inline boost::signals2::connection
135  registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*), void* cookie = NULL)
136  {
137  return (registerKeyboardCallback (boost::bind (callback, _1, cookie)));
138  }
139 
140  /** \brief Register a callback function for keyboard events
141  * \param[in] callback the member function that will be registered as a callback for a keyboard event
142  * \param[in] instance instance to the class that implements the callback function
143  * \param[in] cookie user data that is passed to the callback
144  * \return connection object that allows to disconnect the callback function.
145  */
146  template<typename T> inline boost::signals2::connection
147  registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*), T& instance, void* cookie = NULL)
148  {
149  return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
150  }
151 
152  /** \brief Register a callback function for mouse events
153  * \param[in] callback the function that will be registered as a callback for a mouse event
154  * \param[in] cookie user data that is passed to the callback
155  * \return connection object that allows to disconnect the callback function.
156  */
157  inline boost::signals2::connection
158  registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*), void* cookie = NULL)
159  {
160  return (registerMouseCallback (boost::bind (callback, _1, cookie)));
161  }
162 
163  /** \brief Register a callback function for mouse events
164  * \param[in] callback the member function that will be registered as a callback for a mouse event
165  * \param[in] instance instance to the class that implements the callback function
166  * \param[in] cookie user data that is passed to the callback
167  * \return connection object that allows to disconnect the callback function.
168  */
169  template<typename T> inline boost::signals2::connection
170  registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*), T& instance, void* cookie = NULL)
171  {
172  return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
173  }
174 
175 
176  /** \brief Register a callback function for point picking events
177  * \param[in] callback the function that will be registered as a callback for a point picking event
178  * \param[in] cookie user data that is passed to the callback
179  * \return connection object that allows to disconnect the callback function.
180  */
181  inline boost::signals2::connection
182  registerPointPickingCallback (void (*callback) (const pcl::visualization::PointPickingEvent&, void*), void* cookie = NULL)
183  {
184  return (registerPointPickingCallback (boost::bind (callback, _1, cookie)));
185  }
186 
187  /** \brief Register a callback function for point picking events
188  * \param[in] callback the member function that will be registered as a callback for a point picking event
189  * \param[in] instance instance to the class that implements the callback function
190  * \param[in] cookie user data that is passed to the callback
191  * \return connection object that allows to disconnect the callback function.
192  */
193  template<typename T> inline boost::signals2::connection
194  registerPointPickingCallback (void (T::*callback) (const pcl::visualization::PointPickingEvent&, void*), T& instance, void* cookie = NULL)
195  {
196  return (registerPointPickingCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
197  }
198 
199  private:
200  /** \brief Private implementation. */
201  struct CloudViewer_impl;
202  std::auto_ptr<CloudViewer_impl> impl_;
203 
204  boost::signals2::connection
205  registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)>);
206 
207  boost::signals2::connection
208  registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)>);
209 
210  boost::signals2::connection
211  registerPointPickingCallback (boost::function<void (const pcl::visualization::PointPickingEvent&)>);
212  };
213  }
214 }
215 
216 #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:170
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:194
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::PointCloud< pcl::PointXYZI > GrayCloud
Definition: cloud_viewer.h:56
/brief Class representing 3D point picking events.
pcl::PointCloud< pcl::PointXYZ > MonochromeCloud
Definition: cloud_viewer.h:57
pcl::PointCloud< pcl::PointXYZRGB > ColorCloud
Definition: cloud_viewer.h:55
boost::function1< void, pcl::visualization::PCLVisualizer & > VizCallable
Visualization callable function, may be used for running things on the UI thread. ...
Definition: cloud_viewer.h:108
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Simple point cloud visualization class.
Definition: cloud_viewer.h:51
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:147
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:135
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:182
/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:158
pcl::PointCloud< pcl::PointXYZRGBA > ColorACloud
Definition: cloud_viewer.h:54