-
Notifications
You must be signed in to change notification settings - Fork 0
/
real_sense_common.h
245 lines (203 loc) · 9.16 KB
/
real_sense_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
* Copyright (c) 2016, Intel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef PCL_IO_REAL_SENSE_COMMON_H //name change due to position change
#define PCL_IO_REAL_SENSE_COMMON_H
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
//#include <pcl/io/buffers.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/common/time.h>
namespace pcl
{
namespace io
{
template <typename T> class Buffer;
namespace real_sense
{
class RealSenseDevice;
class PCL_EXPORTS Common
{
public:
/*typedef
void (sig_cb_real_sense_point_cloud)
(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&);
typedef
void (sig_cb_real_sense_point_cloud_rgba)
(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&);*/
/** A descriptor for capturing mode.
*
* Consists of framerate and resolutions of depth and color streams.
* Serves two purposes: to describe the desired capturing mode when
* creating a grabber, and to list the available modes supported by the
* grabber (see getAvailableModes()). In the first case setting some
* fields to zero means "don't care", i.e. the grabber is allowed to
* decide itself which concrete values to use. */
struct PCL_EXPORTS Mode
{
unsigned int fps;
unsigned int depth_width;
unsigned int depth_height;
unsigned int color_width;
unsigned int color_height;
/** Set all fields to zero (i.e. "don't care"). */
Mode ();
/** Set desired framerate, the rest is "don't care". */
Mode (unsigned int fps);
/** Set desired depth resolution, the rest is "don't care". */
Mode (unsigned int depth_width, unsigned int depth_height);
/** Set desired framerate and depth resolution, the rest is "don't
* care". */
Mode (unsigned int fps, unsigned int depth_width, unsigned int depth_height);
/** Set desired depth and color resolution, the rest is "don't
* care". */
Mode (unsigned int depth_width, unsigned int depth_height, unsigned int color_width, unsigned int color_height);
/** Set desired framerate, depth and color resolution. */
Mode (unsigned int fps, unsigned int depth_width, unsigned int depth_height, unsigned int color_width, unsigned int color_height);
bool
operator== (const pcl::io::real_sense::Common::Mode& m) const;
};
enum TemporalFilteringType
{
RealSense_None = 0,
RealSense_Median = 1,
RealSense_Average = 2,
};
/** A constructor which will be utilized by the RealSenseGrabber constructor.
*
* This constructor provides the common code for the grabber "to capture the device",
* making it impossible for other grabbers to interact with it. The device is "released"
* when the grabber is destructed.
*
* This will throw pcl::io::IOException if there are no free devices
* that match the supplied \a device_id.
*
* \param[in] device_id device identifier, which can be a serial number,
* a zero-based index (with '#' prefix), or an empty string (to select
* the first available device)
* \param[in] mode desired framerate and stream resolution (see Mode).
* If the default is supplied, then the mode closest to VGA at 30 Hz
* will be chosen.
* \param[in] strict if set to \c true, an exception will be thrown if
* device does not support exactly the mode requsted. Otherwise the
* closest available mode is selected. */
Common (const std::string& device_id, const Mode& mode, bool strict);
virtual
~Common () throw ();
virtual void
stop ();
virtual bool
isRunning () const;
virtual std::string
getName () const
{
return (std::string ("RealSenseGrabber"));
}
virtual float
getFramesPerSecond () const;
/** Enable temporal filtering of the depth data received from the device.
*
* The window size parameter is not relevant for `RealSense_None`
* filtering type.
*
* \note if the grabber is running and the new parameters are different
* from the current parameters, grabber will be restarted. */
void
enableTemporalFiltering (TemporalFilteringType type, size_t window_size);
/** Disable temporal filtering. */
void
disableTemporalFiltering ();
/** Get the serial number of device captured by the grabber. */
const std::string&
getDeviceSerialNumber () const;
/** Set desired capturing mode.
*
* \note if the grabber is running and the new mode is different the
* one requested previously, grabber will be restarted. */
void
setMode (const Mode& mode, bool strict = false);
/** Get currently active capturing mode.
*
* \note: capturing mode is selected when start() is called; output of
* this function before grabber was started is undefined. */
const Mode&
getMode () const
{
return (mode_selected_);
}
/** Compute a score which indicates how different is a given mode is from
* the mode requested by the user.
*
* Importance of factors: fps > depth resolution > color resolution. The
* lower the score the better. */
float
computeModeScore (const Mode& mode);
void
createDepthBuffer ();
/*// Signals to indicate whether new clouds are available
boost::signals2::signal<sig_cb_real_sense_point_cloud>* point_cloud_signal_;
boost::signals2::signal<sig_cb_real_sense_point_cloud_rgba>* point_cloud_rgba_signal_;*/
boost::shared_ptr<pcl::io::real_sense::RealSenseDevice> device_;
bool is_running_;
unsigned int confidence_threshold_;
TemporalFilteringType temporal_filtering_type_;
size_t temporal_filtering_window_size_;
/// Capture mode requested by the user at construction time
Mode mode_requested_;
/// Whether or not selected capture mode should strictly match what the user
/// has requested
bool strict_;
/// Capture mode selected by grabber (among the modes supported by the
/// device), computed and stored on start()
Mode mode_selected_;
/// Indicates whether there are subscribers for PointXYZ signal, computed
/// and stored on start()
bool need_xyz_;
/// Indicates whether there are subscribers for PointXYZRGBA signal,
/// computed and stored on start()
bool need_xyzrgba_;
EventFrequency frequency_;
mutable boost::mutex fps_mutex_;
boost::thread thread_;
/// Depth buffer to perform temporal filtering of the depth images
boost::shared_ptr<pcl::io::Buffer<unsigned short> > depth_buffer_;
};
}
}
}
#endif /* PCL_IO_REAL_SENSE_COMMON_H */