Point Cloud Library (PCL)  1.8.1
oni_grabber.h
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  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include <pcl/pcl_config.h>
39 #ifdef HAVE_OPENNI
40 
41 #ifndef __PCL_IO_ONI_PLAYER__
42 #define __PCL_IO_ONI_PLAYER__
43 
44 #include <pcl/io/eigen.h>
45 #include <pcl/io/boost.h>
46 #include <pcl/io/grabber.h>
47 #include <pcl/io/openni_camera/openni_driver.h>
48 #include <pcl/io/openni_camera/openni_device_oni.h>
49 #include <pcl/io/openni_camera/openni_image.h>
50 #include <pcl/io/openni_camera/openni_depth_image.h>
51 #include <pcl/io/openni_camera/openni_ir_image.h>
52 #include <string>
53 #include <deque>
54 #include <pcl/common/synchronizer.h>
55 
56 namespace pcl
57 {
58  /** */
59  template <typename T> class PointCloud;
60  /** */
61  struct PointXYZ;
62  /** */
63  struct PointXYZRGB;
64  /** */
65  struct PointXYZRGBA;
66  /** */
67  struct PointXYZI;
68 
69  /** \brief A simple ONI grabber.
70  * \author Suat Gedikli
71  * \ingroup io
72  */
73  class PCL_EXPORTS ONIGrabber : public Grabber
74  {
75  public:
76  //define callback signature typedefs
77  typedef void (sig_cb_openni_image) (const boost::shared_ptr<openni_wrapper::Image>&);
78  typedef void (sig_cb_openni_depth_image) (const boost::shared_ptr<openni_wrapper::DepthImage>&);
79  typedef void (sig_cb_openni_ir_image) (const boost::shared_ptr<openni_wrapper::IRImage>&);
80  typedef void (sig_cb_openni_image_depth_image) (const boost::shared_ptr<openni_wrapper::Image>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ;
81  typedef void (sig_cb_openni_ir_depth_image) (const boost::shared_ptr<openni_wrapper::IRImage>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ;
82  typedef void (sig_cb_openni_point_cloud) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >&);
83  typedef void (sig_cb_openni_point_cloud_rgb) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >&);
84  typedef void (sig_cb_openni_point_cloud_rgba) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGBA> >&);
85  typedef void (sig_cb_openni_point_cloud_i) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&);
86 
87  /** \brief constuctor
88  * \param[in] file_name the path to the ONI file
89  * \param[in] repeat whether the play back should be in an infinite loop or not
90  * \param[in] stream whether the playback should be in streaming mode or in triggered mode.
91  */
92  ONIGrabber (const std::string& file_name, bool repeat, bool stream);
93 
94  /** \brief destructor never throws an exception */
95  virtual ~ONIGrabber () throw ();
96 
97  /** \brief For devices that are streaming, the streams are started by calling this method.
98  * Trigger-based devices, just trigger the device once for each call of start.
99  */
100  virtual void
101  start ();
102 
103  /** \brief For devices that are streaming, the streams are stopped.
104  * This method has no effect for triggered devices.
105  */
106  virtual void
107  stop ();
108 
109  /** \brief returns the name of the concrete subclass.
110  * \return the name of the concrete driver.
111  */
112  virtual std::string
113  getName () const;
114 
115  /** \brief Indicates whether the grabber is streaming or not. This value is not defined for triggered devices.
116  * \return true if grabber is running / streaming. False otherwise.
117  */
118  virtual bool
119  isRunning () const;
120 
121  /** \brief returns the frames pre second. 0 if it is trigger based. */
122  virtual float
123  getFramesPerSecond () const;
124 
125  /** \brief Check if there is any data left in the ONI file to process. */
126  inline bool
127  hasDataLeft ()
128  {
129  return (device_->hasDataLeft ());
130  }
131 
132  protected:
133  /** \brief internal OpenNI (openni_wrapper) callback that handles image streams */
134  void
135  imageCallback (boost::shared_ptr<openni_wrapper::Image> image, void* cookie);
136 
137  /** \brief internal OpenNI (openni_wrapper) callback that handles depth streams */
138  void
139  depthCallback (boost::shared_ptr<openni_wrapper::DepthImage> depth_image, void* cookie);
140 
141  /** \brief internal OpenNI (openni_wrapper) callback that handles IR streams */
142  void
143  irCallback (boost::shared_ptr<openni_wrapper::IRImage> ir_image, void* cookie);
144 
145  /** \brief internal callback that handles synchronized image + depth streams */
146  void
147  imageDepthImageCallback (const boost::shared_ptr<openni_wrapper::Image> &image,
148  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image);
149 
150  /** \brief internal callback that handles synchronized IR + depth streams */
151  void
152  irDepthImageCallback (const boost::shared_ptr<openni_wrapper::IRImage> &image,
153  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image);
154 
155  /** \brief internal method to assemble a point cloud object */
156  boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >
157  convertToXYZPointCloud (const boost::shared_ptr<openni_wrapper::DepthImage> &depth) const;
158 
159  /** \brief internal method to assemble a point cloud object */
160  boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB> >
161  convertToXYZRGBPointCloud (const boost::shared_ptr<openni_wrapper::Image> &image,
162  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const;
163 
164  /** \brief internal method to assemble a point cloud object */
165  boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> >
166  convertToXYZRGBAPointCloud (const boost::shared_ptr<openni_wrapper::Image> &image,
167  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const;
168 
169  /** \brief internal method to assemble a point cloud object */
170  boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> >
171  convertToXYZIPointCloud (const boost::shared_ptr<openni_wrapper::IRImage> &image,
172  const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const;
173 
174  /** \brief synchronizer object to synchronize image and depth streams*/
175  Synchronizer<boost::shared_ptr<openni_wrapper::Image>, boost::shared_ptr<openni_wrapper::DepthImage> > rgb_sync_;
176 
177  /** \brief synchronizer object to synchronize IR and depth streams*/
178  Synchronizer<boost::shared_ptr<openni_wrapper::IRImage>, boost::shared_ptr<openni_wrapper::DepthImage> > ir_sync_;
179 
180  /** \brief the actual openni device*/
181  boost::shared_ptr<openni_wrapper::DeviceONI> device_;
182  std::string rgb_frame_id_;
183  std::string depth_frame_id_;
184  bool running_;
185  unsigned image_width_;
186  unsigned image_height_;
187  unsigned depth_width_;
188  unsigned depth_height_;
192  boost::signals2::signal<sig_cb_openni_image >* image_signal_;
193  boost::signals2::signal<sig_cb_openni_depth_image >* depth_image_signal_;
194  boost::signals2::signal<sig_cb_openni_ir_image >* ir_image_signal_;
195  boost::signals2::signal<sig_cb_openni_image_depth_image>* image_depth_image_signal_;
196  boost::signals2::signal<sig_cb_openni_ir_depth_image>* ir_depth_image_signal_;
197  boost::signals2::signal<sig_cb_openni_point_cloud >* point_cloud_signal_;
198  boost::signals2::signal<sig_cb_openni_point_cloud_i >* point_cloud_i_signal_;
199  boost::signals2::signal<sig_cb_openni_point_cloud_rgb >* point_cloud_rgb_signal_;
200  boost::signals2::signal<sig_cb_openni_point_cloud_rgba >* point_cloud_rgba_signal_;
201 
202  public:
203  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
204  };
205 
206 } // namespace
207 
208 #endif // __PCL_IO_ONI_PLAYER__
209 #endif // HAVE_OPENNI
210 
unsigned depth_width_
Definition: oni_grabber.h:187
Synchronizer< boost::shared_ptr< openni_wrapper::IRImage >, boost::shared_ptr< openni_wrapper::DepthImage > > ir_sync_
synchronizer object to synchronize IR and depth streams
Definition: oni_grabber.h:178
boost::signals2::signal< sig_cb_openni_depth_image > * depth_image_signal_
Definition: oni_grabber.h:193
boost::signals2::signal< sig_cb_openni_ir_depth_image > * ir_depth_image_signal_
Definition: oni_grabber.h:196
unsigned image_height_
Definition: oni_grabber.h:186
openni_wrapper::OpenNIDevice::CallbackHandle depth_callback_handle
Definition: oni_grabber.h:189
boost::signals2::signal< sig_cb_openni_point_cloud_i > * point_cloud_i_signal_
Definition: oni_grabber.h:198
boost::signals2::signal< sig_cb_openni_point_cloud_rgb > * point_cloud_rgb_signal_
Definition: oni_grabber.h:199
/brief This template class synchronizes two data streams of different types.
Definition: synchronizer.h:49
Grabber interface for PCL 1.x device drivers.
Definition: grabber.h:58
Synchronizer< boost::shared_ptr< openni_wrapper::Image >, boost::shared_ptr< openni_wrapper::DepthImage > > rgb_sync_
synchronizer object to synchronize image and depth streams
Definition: oni_grabber.h:175
float4 PointXYZRGB
Definition: internal.hpp:60
std::string depth_frame_id_
Definition: oni_grabber.h:183
boost::signals2::signal< sig_cb_openni_ir_image > * ir_image_signal_
Definition: oni_grabber.h:194
openni_wrapper::OpenNIDevice::CallbackHandle image_callback_handle
Definition: oni_grabber.h:190
unsigned depth_height_
Definition: oni_grabber.h:188
boost::signals2::signal< sig_cb_openni_point_cloud > * point_cloud_signal_
Definition: oni_grabber.h:197
unsigned image_width_
Definition: oni_grabber.h:185
boost::signals2::signal< sig_cb_openni_image_depth_image > * image_depth_image_signal_
Definition: oni_grabber.h:195
PointCloud represents the base class in PCL for storing collections of 3D points. ...
boost::signals2::signal< sig_cb_openni_image > * image_signal_
Definition: oni_grabber.h:192
std::string rgb_frame_id_
Definition: oni_grabber.h:182
A simple ONI grabber.
Definition: oni_grabber.h:73
boost::shared_ptr< openni_wrapper::DeviceONI > device_
the actual openni device
Definition: oni_grabber.h:181
boost::signals2::signal< sig_cb_openni_point_cloud_rgba > * point_cloud_rgba_signal_
Definition: oni_grabber.h:200
openni_wrapper::OpenNIDevice::CallbackHandle ir_callback_handle
Definition: oni_grabber.h:191