Point Cloud Library (PCL)  1.9.1-dev
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 #pragma once
39 
40 #include <pcl/pcl_config.h>
41 #include <pcl/pcl_macros.h>
42 
43 #ifdef HAVE_OPENNI
44 
45 #include <pcl/point_cloud.h>
46 #include <pcl/io/eigen.h>
47 #include <pcl/io/boost.h>
48 #include <pcl/io/grabber.h>
49 #include <pcl/io/openni_camera/openni_driver.h>
50 #include <pcl/io/openni_camera/openni_device_oni.h>
51 #include <pcl/io/openni_camera/openni_image.h>
52 #include <pcl/io/openni_camera/openni_depth_image.h>
53 #include <pcl/io/openni_camera/openni_ir_image.h>
54 #include <string>
55 #include <deque>
56 #include <pcl/common/synchronizer.h>
57 
58 namespace pcl
59 {
60  struct PointXYZ;
61  struct PointXYZRGB;
62  struct PointXYZRGBA;
63  struct PointXYZI;
64 
65  /** \brief A simple ONI grabber.
66  * \author Suat Gedikli
67  * \ingroup io
68  */
70  {
71  public:
72  //define callback signature typedefs
82 
83  /** \brief constructor
84  * \param[in] file_name the path to the ONI file
85  * \param[in] repeat whether the play back should be in an infinite loop or not
86  * \param[in] stream whether the playback should be in streaming mode or in triggered mode.
87  */
88  ONIGrabber (const std::string& file_name, bool repeat, bool stream);
89 
90  /** \brief destructor never throws an exception */
91  ~ONIGrabber () throw ();
92 
93  /** \brief For devices that are streaming, the streams are started by calling this method.
94  * Trigger-based devices, just trigger the device once for each call of start.
95  */
96  void
97  start () override;
98 
99  /** \brief For devices that are streaming, the streams are stopped.
100  * This method has no effect for triggered devices.
101  */
102  void
103  stop () override;
104 
105  /** \brief returns the name of the concrete subclass.
106  * \return the name of the concrete driver.
107  */
108  std::string
109  getName () const override;
110 
111  /** \brief Indicates whether the grabber is streaming or not. This value is not defined for triggered devices.
112  * \return true if grabber is running / streaming. False otherwise.
113  */
114  bool
115  isRunning () const override;
116 
117  /** \brief returns the frames pre second. 0 if it is trigger based. */
118  float
119  getFramesPerSecond () const override;
120 
121  /** \brief Check if there is any data left in the ONI file to process. */
122  inline bool
123  hasDataLeft ()
124  {
125  return (device_->hasDataLeft ());
126  }
127 
128  protected:
129  /** \brief internal OpenNI (openni_wrapper) callback that handles image streams */
130  void
131  imageCallback (openni_wrapper::Image::Ptr image, void* cookie);
132 
133  /** \brief internal OpenNI (openni_wrapper) callback that handles depth streams */
134  void
135  depthCallback (openni_wrapper::DepthImage::Ptr depth_image, void* cookie);
136 
137  /** \brief internal OpenNI (openni_wrapper) callback that handles IR streams */
138  void
139  irCallback (openni_wrapper::IRImage::Ptr ir_image, void* cookie);
140 
141  /** \brief internal callback that handles synchronized image + depth streams */
142  void
143  imageDepthImageCallback (const openni_wrapper::Image::Ptr &image,
144  const openni_wrapper::DepthImage::Ptr &depth_image);
145 
146  /** \brief internal callback that handles synchronized IR + depth streams */
147  void
148  irDepthImageCallback (const openni_wrapper::IRImage::Ptr &image,
149  const openni_wrapper::DepthImage::Ptr &depth_image);
150 
151  /** \brief internal method to assemble a point cloud object */
153  convertToXYZPointCloud (const openni_wrapper::DepthImage::Ptr &depth) const;
154 
155  /** \brief internal method to assemble a point cloud object */
157  convertToXYZRGBPointCloud (const openni_wrapper::Image::Ptr &image,
158  const openni_wrapper::DepthImage::Ptr &depth_image) const;
159 
160  /** \brief internal method to assemble a point cloud object */
162  convertToXYZRGBAPointCloud (const openni_wrapper::Image::Ptr &image,
163  const openni_wrapper::DepthImage::Ptr &depth_image) const;
164 
165  /** \brief internal method to assemble a point cloud object */
167  convertToXYZIPointCloud (const openni_wrapper::IRImage::Ptr &image,
168  const openni_wrapper::DepthImage::Ptr &depth_image) const;
169 
170  /** \brief synchronizer object to synchronize image and depth streams*/
172 
173  /** \brief synchronizer object to synchronize IR and depth streams*/
175 
176  /** \brief the actual openni device*/
177  boost::shared_ptr<openni_wrapper::DeviceONI> device_;
178  std::string rgb_frame_id_;
179  std::string depth_frame_id_;
180  bool running_;
181  unsigned image_width_;
182  unsigned image_height_;
183  unsigned depth_width_;
184  unsigned depth_height_;
188  boost::signals2::signal<sig_cb_openni_image >* image_signal_;
189  boost::signals2::signal<sig_cb_openni_depth_image >* depth_image_signal_;
190  boost::signals2::signal<sig_cb_openni_ir_image >* ir_image_signal_;
191  boost::signals2::signal<sig_cb_openni_image_depth_image>* image_depth_image_signal_;
192  boost::signals2::signal<sig_cb_openni_ir_depth_image>* ir_depth_image_signal_;
193  boost::signals2::signal<sig_cb_openni_point_cloud >* point_cloud_signal_;
194  boost::signals2::signal<sig_cb_openni_point_cloud_i >* point_cloud_i_signal_;
195  boost::signals2::signal<sig_cb_openni_point_cloud_rgb >* point_cloud_rgb_signal_;
196  boost::signals2::signal<sig_cb_openni_point_cloud_rgba >* point_cloud_rgba_signal_;
197 
198  public:
200  };
201 
202 } // namespace
203 #endif // HAVE_OPENNI
void(const openni_wrapper::DepthImage::Ptr &) sig_cb_openni_depth_image
Definition: oni_grabber.h:74
unsigned depth_width_
Definition: oni_grabber.h:183
void(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &) sig_cb_openni_point_cloud_rgb
Definition: oni_grabber.h:79
boost::signals2::signal< sig_cb_openni_depth_image > * depth_image_signal_
Definition: oni_grabber.h:189
boost::signals2::signal< sig_cb_openni_ir_depth_image > * ir_depth_image_signal_
Definition: oni_grabber.h:192
unsigned image_height_
Definition: oni_grabber.h:182
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
openni_wrapper::OpenNIDevice::CallbackHandle depth_callback_handle
Definition: oni_grabber.h:185
boost::shared_ptr< DepthImage > Ptr
boost::signals2::signal< sig_cb_openni_point_cloud_i > * point_cloud_i_signal_
Definition: oni_grabber.h:194
boost::shared_ptr< Image > Ptr
Definition: openni_image.h:61
boost::signals2::signal< sig_cb_openni_point_cloud_rgb > * point_cloud_rgb_signal_
Definition: oni_grabber.h:195
Grabber interface for PCL 1.x device drivers.
Definition: grabber.h:57
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: pcl_macros.h:359
std::string depth_frame_id_
Definition: oni_grabber.h:179
boost::signals2::signal< sig_cb_openni_ir_image > * ir_image_signal_
Definition: oni_grabber.h:190
boost::shared_ptr< IRImage > Ptr
void(const openni_wrapper::IRImage::Ptr &, const openni_wrapper::DepthImage::Ptr &, float) sig_cb_openni_ir_depth_image
Definition: oni_grabber.h:77
void(const openni_wrapper::IRImage::Ptr &) sig_cb_openni_ir_image
Definition: oni_grabber.h:75
Synchronizer< openni_wrapper::Image::Ptr, openni_wrapper::DepthImage::Ptr > rgb_sync_
synchronizer object to synchronize image and depth streams
Definition: oni_grabber.h:171
openni_wrapper::OpenNIDevice::CallbackHandle image_callback_handle
Definition: oni_grabber.h:186
unsigned depth_height_
Definition: oni_grabber.h:184
void(const openni_wrapper::Image::Ptr &) sig_cb_openni_image
Definition: oni_grabber.h:73
boost::signals2::signal< sig_cb_openni_point_cloud > * point_cloud_signal_
Definition: oni_grabber.h:193
unsigned image_width_
Definition: oni_grabber.h:181
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:411
void(const openni_wrapper::Image::Ptr &, const openni_wrapper::DepthImage::Ptr &, float) sig_cb_openni_image_depth_image
Definition: oni_grabber.h:76
float4 PointXYZRGB
Definition: internal.hpp:60
boost::signals2::signal< sig_cb_openni_image_depth_image > * image_depth_image_signal_
Definition: oni_grabber.h:191
void(const pcl::PointCloud< pcl::PointXYZI >::ConstPtr &) sig_cb_openni_point_cloud_i
Definition: oni_grabber.h:81
boost::signals2::signal< sig_cb_openni_image > * image_signal_
Definition: oni_grabber.h:188
std::string rgb_frame_id_
Definition: oni_grabber.h:178
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:412
void(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &) sig_cb_openni_point_cloud
Definition: oni_grabber.h:78
A simple ONI grabber.
Definition: oni_grabber.h:69
Synchronizer< openni_wrapper::IRImage::Ptr, openni_wrapper::DepthImage::Ptr > ir_sync_
synchronizer object to synchronize IR and depth streams
Definition: oni_grabber.h:174
void(const pcl::PointCloud< pcl::PointXYZRGBA >::ConstPtr &) sig_cb_openni_point_cloud_rgba
Definition: oni_grabber.h:80
boost::shared_ptr< openni_wrapper::DeviceONI > device_
the actual openni device
Definition: oni_grabber.h:177
boost::signals2::signal< sig_cb_openni_point_cloud_rgba > * point_cloud_rgba_signal_
Definition: oni_grabber.h:196
#define PCL_EXPORTS
Definition: pcl_macros.h:241
openni_wrapper::OpenNIDevice::CallbackHandle ir_callback_handle
Definition: oni_grabber.h:187
Defines all the PCL and non-PCL macros used.