Point Cloud Library (PCL)  1.11.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 
108  ~DepthSenseGrabberImpl () noexcept;
109 
110  void
111  start ();
112 
113  void
114  stop ();
115 
116  float
117  getFramesPerSecond () const;
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 }
pcl::io::depth_sense::DepthSenseGrabberImpl::start
void start()
pcl
Definition: convolution.h:46
pcl::io::depth_sense::DepthSenseGrabberImpl::SIZE
static const int SIZE
Definition: depth_sense_grabber_impl.h:101
pcl::io::depth_sense::DepthSenseGrabberImpl::frequency_
EventFrequency frequency_
Definition: depth_sense_grabber_impl.h:90
pcl::io::depth_sense::DepthSenseGrabberImpl::stop
void stop()
pcl::io::depth_sense::DepthSenseGrabberImpl::point_cloud_rgba_signal_
boost::signals2::signal< sig_cb_depth_sense_point_cloud_rgba > * point_cloud_rgba_signal_
Signal to indicate whether new XYZRGBA cloud is available.
Definition: depth_sense_grabber_impl.h:80
pcl::io::depth_sense::DepthSenseGrabberImpl::confidence_threshold_
int confidence_threshold_
Definition: depth_sense_grabber_impl.h:69
pcl::io::depth_sense::DepthSenseGrabberImpl::device_id_
std::string device_id_
Serial number of the device captured by this grabber.
Definition: depth_sense_grabber_impl.h:65
pcl::io::depth_sense::DepthSenseGrabberImpl::onDepthDataReceived
void onDepthDataReceived(DepthSense::DepthNode node, DepthSense::DepthNode::NewSampleReceivedData data)
A callback for processing depth data.
pcl::io::depth_sense::DepthSenseGrabberImpl::DepthSenseGrabberImpl
DepthSenseGrabberImpl(DepthSenseGrabber *parent, const std::string &device_id)
pcl::io::depth_sense::DepthSenseGrabberImpl::need_xyz_
bool need_xyz_
Indicates whether there are subscribers for PointXYZ signal.
Definition: depth_sense_grabber_impl.h:84
pcl::io::depth_sense::DepthSenseGrabberImpl::setConfidenceThreshold
void setConfidenceThreshold(int threshold)
pcl::io::depth_sense::DepthSenseGrabberImpl::FRAMERATE
static const int FRAMERATE
Definition: depth_sense_grabber_impl.h:98
pcl::io::depth_sense::DepthSenseGrabberImpl::depth_buffer_
std::shared_ptr< pcl::io::Buffer< float > > depth_buffer_
Definition: depth_sense_grabber_impl.h:96
pcl::io::depth_sense::DepthSenseGrabberImpl::WIDTH
static const int WIDTH
Definition: depth_sense_grabber_impl.h:99
pcl::DepthSenseGrabber::sig_cb_depth_sense_point_cloud_rgba
void(const pcl::PointCloud< pcl::PointXYZRGBA >::ConstPtr &) sig_cb_depth_sense_point_cloud_rgba
Definition: depth_sense_grabber.h:65
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::io::depth_sense::DepthSenseGrabberImpl::sig_cb_depth_sense_point_cloud_rgba
DepthSenseGrabber::sig_cb_depth_sense_point_cloud_rgba sig_cb_depth_sense_point_cloud_rgba
Definition: depth_sense_grabber_impl.h:75
pcl::io::depth_sense::DepthSenseGrabberImpl::onColorDataReceived
void onColorDataReceived(DepthSense::ColorNode node, DepthSense::ColorNode::NewSampleReceivedData data)
A callback for processing color data.
pcl::io::depth_sense::DepthSenseGrabberImpl::color_data_
std::vector< std::uint8_t > color_data_
Temporary buffer to store color data.
Definition: depth_sense_grabber_impl.h:94
pcl::io::depth_sense::DepthSenseGrabberImpl::computeXYZ
void computeXYZ(PointCloud< Point > &cloud)
pcl::DepthSenseGrabber
Grabber for DepthSense devices (e.g.
Definition: depth_sense_grabber.h:56
pcl::io::depth_sense::DepthSenseGrabberImpl::need_xyzrgba_
bool need_xyzrgba_
Indicates whether there are subscribers for PointXYZRGBA signal.
Definition: depth_sense_grabber_impl.h:88
pcl::io::depth_sense::DepthSenseGrabberImpl::p_
DepthSenseGrabber * p_
Parent grabber.
Definition: depth_sense_grabber_impl.h:62
pcl::io::depth_sense::DepthSenseGrabberImpl::point_cloud_signal_
boost::signals2::signal< sig_cb_depth_sense_point_cloud > * point_cloud_signal_
Signal to indicate whether new XYZ cloud is available.
Definition: depth_sense_grabber_impl.h:78
pcl::io::depth_sense::DepthSenseGrabberImpl::COLOR_WIDTH
static const int COLOR_WIDTH
Definition: depth_sense_grabber_impl.h:102
pcl::EventFrequency
A helper class to measure frequency of a certain event.
Definition: time.h:134
pcl::DepthSenseGrabber::TemporalFilteringType
TemporalFilteringType
Definition: depth_sense_grabber.h:72
pcl::DepthSenseGrabber::sig_cb_depth_sense_point_cloud
void(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &) sig_cb_depth_sense_point_cloud
Definition: depth_sense_grabber.h:64
pcl::io::depth_sense::DepthSenseGrabberImpl::COLOR_SIZE
static const int COLOR_SIZE
Definition: depth_sense_grabber_impl.h:104
pcl::io::depth_sense::DepthSenseGrabberImpl::enableTemporalFiltering
void enableTemporalFiltering(DepthSenseGrabber::TemporalFilteringType type, std::size_t window_size)
pcl::io::depth_sense::DepthSenseGrabberImpl::is_running_
bool is_running_
Definition: depth_sense_grabber_impl.h:67
pcl::io::depth_sense::DepthSenseGrabberImpl::temporal_filtering_type_
DepthSenseGrabber::TemporalFilteringType temporal_filtering_type_
Definition: depth_sense_grabber_impl.h:70
pcl::io::depth_sense::DepthSenseGrabberImpl::configureColorNode
void configureColorNode(DepthSense::ColorNode node) const
pcl::io::depth_sense::DepthSenseGrabberImpl::fps_mutex_
std::mutex fps_mutex_
Definition: depth_sense_grabber_impl.h:91
pcl::io::depth_sense::DepthSenseGrabberImpl::~DepthSenseGrabberImpl
~DepthSenseGrabberImpl() noexcept
time.h
pcl::io::depth_sense::DepthSenseGrabberImpl::COLOR_HEIGHT
static const int COLOR_HEIGHT
Definition: depth_sense_grabber_impl.h:103
pcl::io::depth_sense::DepthSenseGrabberImpl::HEIGHT
static const int HEIGHT
Definition: depth_sense_grabber_impl.h:100
pcl::io::depth_sense::DepthSenseGrabberImpl::setCameraParameters
void setCameraParameters(const DepthSense::StereoCameraParameters &parameters)
pcl::io::depth_sense::DepthSenseGrabberImpl::configureDepthNode
void configureDepthNode(DepthSense::DepthNode node) const
pcl::io::depth_sense::DepthSenseGrabberImpl::projection_
std::shared_ptr< DepthSense::ProjectionHelper > projection_
Definition: depth_sense_grabber_impl.h:72
pcl::io::depth_sense::DepthSenseGrabberImpl
Definition: depth_sense_grabber_impl.h:58
pcl::io::depth_sense::DepthSenseGrabberImpl::sig_cb_depth_sense_point_cloud
DepthSenseGrabber::sig_cb_depth_sense_point_cloud sig_cb_depth_sense_point_cloud
Definition: depth_sense_grabber_impl.h:74
pcl::io::depth_sense::DepthSenseGrabberImpl::getFramesPerSecond
float getFramesPerSecond() const