Point Cloud Library (PCL)  1.14.1-dev
depth_sense_grabber_impl.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2014-, Open Perception, 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 the copyright holder(s) 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 
38 #pragma once
39 
40 #include <pcl/common/time.h>
41 #include <pcl/io/buffers.h>
42 #include <pcl/io/depth_sense_grabber.h>
43 
44 #include <DepthSense.hxx>
45 
46 #include <memory>
47 #include <mutex>
48 
49 namespace pcl
50 {
51 
52  namespace io
53  {
54 
55  namespace depth_sense
56  {
57 
59  {
60 
61  /// Parent grabber
63 
64  /// Serial number of the device captured by this grabber
65  std::string device_id_;
66 
68 
71 
72  std::shared_ptr<DepthSense::ProjectionHelper> projection_;
73 
76 
77  /// Signal to indicate whether new XYZ cloud is available
78  boost::signals2::signal<sig_cb_depth_sense_point_cloud>* point_cloud_signal_;
79  /// Signal to indicate whether new XYZRGBA cloud is available
80  boost::signals2::signal<sig_cb_depth_sense_point_cloud_rgba>* point_cloud_rgba_signal_;
81 
82  /// Indicates whether there are subscribers for PointXYZ signal. This is
83  /// computed and stored on start()
84  bool need_xyz_;
85 
86  /// Indicates whether there are subscribers for PointXYZRGBA signal. This
87  /// is computed and stored on start()
89 
91  mutable std::mutex fps_mutex_;
92 
93  /// Temporary buffer to store color data
94  std::vector<std::uint8_t> color_data_;
95 
96  std::shared_ptr<pcl::io::Buffer<float> > depth_buffer_;
97 
98  static const int FRAMERATE = 30;
99  static const int WIDTH = 320;
100  static const int HEIGHT = 240;
101  static const int SIZE = WIDTH * HEIGHT;
102  static const int COLOR_WIDTH = 640;
103  static const int COLOR_HEIGHT = 480;
104  static const int COLOR_SIZE = COLOR_WIDTH * COLOR_HEIGHT;
105 
106  DepthSenseGrabberImpl (DepthSenseGrabber* parent, const std::string& device_id);
107 
109 
110  void
111  start ();
112 
113  void
114  stop ();
115 
116  float
118 
119  void
120  setConfidenceThreshold (int threshold);
121 
122  void
123  enableTemporalFiltering (DepthSenseGrabber::TemporalFilteringType type, std::size_t window_size);
124 
125  void
126  setCameraParameters (const DepthSense::StereoCameraParameters& parameters);
127 
128  void
129  configureDepthNode (DepthSense::DepthNode node) const;
130 
131  void
132  configureColorNode (DepthSense::ColorNode node) const;
133 
134  /** A callback for processing depth data.
135  *
136  * It is supposed to be called from the DepthSense::Context thread that
137  * is managed by DepthSenseDeviceManager. */
138  void
139  onDepthDataReceived (DepthSense::DepthNode node, DepthSense::DepthNode::NewSampleReceivedData data);
140 
141  /** A callback for processing color data.
142  *
143  * It is supposed to be called from the DepthSense::Context thread that
144  * is managed by DepthSenseDeviceManager. */
145  void
146  onColorDataReceived (DepthSense::ColorNode node, DepthSense::ColorNode::NewSampleReceivedData data);
147 
148  template <typename Point> void
149  computeXYZ (PointCloud<Point>& cloud);
150 
151  };
152 
153  }
154 
155  }
156 
157 }
Grabber for DepthSense devices (e.g.
void(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &) sig_cb_depth_sense_point_cloud
void(const pcl::PointCloud< pcl::PointXYZRGBA >::ConstPtr &) sig_cb_depth_sense_point_cloud_rgba
A helper class to measure frequency of a certain event.
Definition: time.h:133
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
Define methods for measuring time spent in code blocks.
DepthSenseGrabber::sig_cb_depth_sense_point_cloud_rgba sig_cb_depth_sense_point_cloud_rgba
bool need_xyzrgba_
Indicates whether there are subscribers for PointXYZRGBA signal.
boost::signals2::signal< sig_cb_depth_sense_point_cloud > * point_cloud_signal_
Signal to indicate whether new XYZ cloud is available.
void configureColorNode(DepthSense::ColorNode node) const
void onDepthDataReceived(DepthSense::DepthNode node, DepthSense::DepthNode::NewSampleReceivedData data)
A callback for processing depth data.
std::vector< std::uint8_t > color_data_
Temporary buffer to store color data.
void enableTemporalFiltering(DepthSenseGrabber::TemporalFilteringType type, std::size_t window_size)
void setCameraParameters(const DepthSense::StereoCameraParameters &parameters)
std::string device_id_
Serial number of the device captured by this grabber.
std::shared_ptr< pcl::io::Buffer< float > > depth_buffer_
bool need_xyz_
Indicates whether there are subscribers for PointXYZ signal.
DepthSenseGrabber::sig_cb_depth_sense_point_cloud sig_cb_depth_sense_point_cloud
void onColorDataReceived(DepthSense::ColorNode node, DepthSense::ColorNode::NewSampleReceivedData data)
A callback for processing color data.
boost::signals2::signal< sig_cb_depth_sense_point_cloud_rgba > * point_cloud_rgba_signal_
Signal to indicate whether new XYZRGBA cloud is available.
void computeXYZ(PointCloud< Point > &cloud)
DepthSenseGrabber::TemporalFilteringType temporal_filtering_type_
std::shared_ptr< DepthSense::ProjectionHelper > projection_
void configureDepthNode(DepthSense::DepthNode node) const
DepthSenseGrabberImpl(DepthSenseGrabber *parent, const std::string &device_id)