YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RGBDSensorClient_StreamingMsgParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
8
9#include <yarp/os/Time.h>
10
11using namespace yarp::dev;
12
13// Callback reader for rgb
15{
16 std::lock_guard<std::mutex> lock(mutex);
17 local_arrival_time = yarp::os::Time::now();
18 std::swap(datum, last_rgb);
19 getEnvelope(stamp);
20}
21
22std::tuple<bool, yarp::sig::FlexImage, yarp::os::Stamp> RgbImageBufferedPort::getImage() const
23{
24 std::lock_guard<std::mutex> lock(mutex);
25 if (local_arrival_time <= 0.0) {
26 // No image received yet
27 // FIXME C++17:
28 // return {false, yarp::sig::FlexImage(), yarp::os::Stamp()};
29 // or perhaps just return {false, {}, {}}; ?
30 return std::make_tuple(false, yarp::sig::FlexImage(), yarp::os::Stamp());
31 }
32 // FIXME C++17:
33 // return {true, last_rgb, stamp};
34 return std::make_tuple(true, last_rgb, stamp);
35}
36
37
38// callback reader for depthImage
40{
41 std::lock_guard<std::mutex> lock(mutex);
42 local_arrival_time = yarp::os::Time::now();
43 std::swap(datum, last_depth);
44 getEnvelope(stamp);
45}
46
47std::tuple<bool, yarp::sig::ImageOf<yarp::sig::PixelFloat>, yarp::os::Stamp> FloatImageBufferedPort::getImage() const
48{
49 std::lock_guard<std::mutex> lock(mutex);
50 if (local_arrival_time <= 0.0) {
51 // No image received yet
52 // FIXME C++17:
53 // return {false, yarp::sig::ImageOf<yarp::sig::PixelFloat>(), yarp::os::Stamp()};
54 // or perhaps just return {false, {}, {}}; ?
55 return std::make_tuple(false, yarp::sig::ImageOf<yarp::sig::PixelFloat>(), yarp::os::Stamp());
56
57 }
58 // FIXME C++17:
59 // return {true, last_depth, stamp};
60 return std::make_tuple(true, last_depth, stamp);
61}
62
63
64// Streaming handler
66{
67 auto result = port_rgb->getImage();
68
69 if (!std::get<0>(result)) {
70 return false;
71 }
72
73 data = std::get<1>(result);
74 if (timeStamp) {
75 *timeStamp = std::get<2>(result);
76 }
77
78 return true;
79}
80
82{
83 auto result = port_depth->getImage();
84
85 if (!std::get<0>(result)) {
86 return false;
87 }
88
89 data = std::get<1>(result);
90 if(timeStamp) {
91 *timeStamp = std::get<2>(result);
92 }
93
94 return true;
95}
96
98{
99 auto resultRgb = port_rgb->getImage();
100 auto resultDepth = port_depth->getImage();
101
102 bool retRgb = std::get<0>(resultRgb);
103 bool retDepth = std::get<0>(resultDepth);
104
105 if (!retRgb || !retDepth) {
106 return false;
107 }
108
109 rgbImage = std::get<1>(resultRgb);
110 depthImage = std::get<1>(resultDepth);
111 if(rgbStamp) {
112 port_rgb->getEnvelope(*rgbStamp);
113 }
114
115 if(depthStamp) {
116 port_depth->getEnvelope(*depthStamp);
117 }
118 return true;
119}
120
122 FloatImageBufferedPort* _port_depth)
123{
124 port_rgb = _port_rgb;
125 port_depth = _port_depth;
126 port_rgb->useCallback();
127 port_depth->useCallback();
128}
void onRead(yarp::sig::ImageOf< yarp::sig::PixelFloat > &datum) override
std::tuple< bool, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::os::Stamp > getImage() const
bool read(yarp::sig::FlexImage &rgbImage, yarp::sig::ImageOf< yarp::sig::PixelFloat > &depthImage, yarp::os::Stamp *rgbStamp=nullptr, yarp::os::Stamp *depthStamp=nullptr)
void attach(RgbImageBufferedPort *_port_rgb, FloatImageBufferedPort *_port_depth)
bool readDepth(yarp::sig::ImageOf< yarp::sig::PixelFloat > &data, yarp::os::Stamp *timeStamp=nullptr)
bool readRgb(yarp::sig::FlexImage &data, yarp::os::Stamp *timeStamp=nullptr)
void onRead(yarp::sig::FlexImage &datum) override
std::tuple< bool, yarp::sig::FlexImage, yarp::os::Stamp > getImage() const
bool getEnvelope(PortReader &envelope) override
void useCallback(TypedReaderCallback< T > &callback) override
Set an object whose onRead method will be called when data is available.
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21
Image class with user control of representation details.
Definition Image.h:374
Typed image class.
Definition Image.h:616
For streams capable of holding different kinds of content, check what they actually have.
Definition jointData.cpp:13
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121