Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
oni_grabber.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) 2011-2012, 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 
37 #include <pcl/pcl_config.h>
38 #ifdef HAVE_OPENNI
39 
40 #ifndef __PCL_IO_ONI_PLAYER__
41 #define __PCL_IO_ONI_PLAYER__
42 
43 #include <Eigen/Core>
44 #include <pcl/io/grabber.h>
50 #include <string>
51 #include <deque>
52 #include <boost/thread/mutex.hpp>
54 
55 
56 namespace pcl
57 {
58  struct PointXYZ;
59  struct PointXYZRGB;
60  struct PointXYZRGBA;
61  struct PointXYZI;
62  template <typename T> class PointCloud;
63 
67  class PCL_EXPORTS ONIGrabber : public Grabber
68  {
69  public:
70  //define callback signature typedefs
71  typedef void (sig_cb_openni_image) (const boost::shared_ptr<openni_wrapper::Image>&);
72  typedef void (sig_cb_openni_depth_image) (const boost::shared_ptr<openni_wrapper::DepthImage>&);
73  typedef void (sig_cb_openni_ir_image) (const boost::shared_ptr<openni_wrapper::IRImage>&);
74  typedef void (sig_cb_openni_image_depth_image) (const boost::shared_ptr<openni_wrapper::Image>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ;
75  typedef void (sig_cb_openni_ir_depth_image) (const boost::shared_ptr<openni_wrapper::IRImage>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ;
76  typedef void (sig_cb_openni_point_cloud) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >&);
77  typedef void (sig_cb_openni_point_cloud_rgb) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >&);
78  typedef void (sig_cb_openni_point_cloud_rgba) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGBA> >&);
79  typedef void (sig_cb_openni_point_cloud_i) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&);
80 
86  ONIGrabber (const std::string& file_name, bool repeat, bool stream);
87 
89  virtual ~ONIGrabber () throw ();
90 
94  virtual void
95  start ();
96 
100  virtual void
101  stop ();
102 
106  virtual std::string
107  getName () const;
108 
112  virtual bool
113  isRunning () const;
114 
116  virtual float
117  getFramesPerSecond () const;
118 
119  protected:
121  void
122  imageCallback (boost::shared_ptr<openni_wrapper::Image> image, void* cookie);
123 
125  void
126  depthCallback (boost::shared_ptr<openni_wrapper::DepthImage> depth_image, void* cookie);
127 
129  void
130  irCallback (boost::shared_ptr<openni_wrapper::IRImage> ir_image, void* cookie);
131 
133  void
134  imageDepthImageCallback (const boost::shared_ptr<openni_wrapper::Image> &image,
135  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image);
136 
138  void
139  irDepthImageCallback (const boost::shared_ptr<openni_wrapper::IRImage> &image,
140  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image);
141 
143  boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >
144  convertToXYZPointCloud (const boost::shared_ptr<openni_wrapper::DepthImage> &depth) const;
145 
147  boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB> >
148  convertToXYZRGBPointCloud (const boost::shared_ptr<openni_wrapper::Image> &image,
149  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const;
150 
152  boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> >
153  convertToXYZRGBAPointCloud (const boost::shared_ptr<openni_wrapper::Image> &image,
154  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const;
155 
157  boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> >
158  convertToXYZIPointCloud (const boost::shared_ptr<openni_wrapper::IRImage> &image,
159  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const;
160 
162  Synchronizer<boost::shared_ptr<openni_wrapper::Image>, boost::shared_ptr<openni_wrapper::DepthImage> > rgb_sync_;
163 
165  Synchronizer<boost::shared_ptr<openni_wrapper::IRImage>, boost::shared_ptr<openni_wrapper::DepthImage> > ir_sync_;
166 
168  boost::shared_ptr<openni_wrapper::DeviceONI> device_;
169  std::string rgb_frame_id_;
170  std::string depth_frame_id_;
171  bool running_;
172  unsigned image_width_;
173  unsigned image_height_;
174  unsigned depth_width_;
175  unsigned depth_height_;
176  openni_wrapper::OpenNIDevice::CallbackHandle depth_callback_handle;
177  openni_wrapper::OpenNIDevice::CallbackHandle image_callback_handle;
178  openni_wrapper::OpenNIDevice::CallbackHandle ir_callback_handle;
179  boost::signals2::signal<sig_cb_openni_image >* image_signal_;
180  boost::signals2::signal<sig_cb_openni_depth_image >* depth_image_signal_;
181  boost::signals2::signal<sig_cb_openni_ir_image >* ir_image_signal_;
182  boost::signals2::signal<sig_cb_openni_image_depth_image>* image_depth_image_signal_;
183  boost::signals2::signal<sig_cb_openni_ir_depth_image>* ir_depth_image_signal_;
184  boost::signals2::signal<sig_cb_openni_point_cloud >* point_cloud_signal_;
185  boost::signals2::signal<sig_cb_openni_point_cloud_i >* point_cloud_i_signal_;
186  boost::signals2::signal<sig_cb_openni_point_cloud_rgb >* point_cloud_rgb_signal_;
187  boost::signals2::signal<sig_cb_openni_point_cloud_rgba >* point_cloud_rgba_signal_;
188 
189  public:
190  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
191  };
192 
193 } // namespace
194 
195 #endif // __PCL_IO_ONI_PLAYER__
196 #endif // HAVE_OPENNI
197