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