YARP
Yet Another Robot Platform
DepthVisualParams_Forwarder.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
7 #include "CameraVocabs.h"
8 
10 
11 DepthVisualParams_Forwarder::DepthVisualParams_Forwarder(yarp::os::Port& port) :
12  m_port(port)
13 {
14 };
15 
17 {
18  yarp::os::Bottle cmd;
19  yarp::os::Bottle response;
21  cmd.addVocab32(VOCAB_GET);
23  m_port.write(cmd, response);
24  return response.get(3).asInt32();
25 }
26 
28 {
29  yarp::os::Bottle cmd;
30  yarp::os::Bottle response;
32  cmd.addVocab32(VOCAB_GET);
34  m_port.write(cmd, response);
35  return response.get(3).asInt32();
36 }
37 
39 {
40  yarp::os::Bottle cmd;
41  yarp::os::Bottle response;
43  cmd.addVocab32(VOCAB_SET);
45  cmd.addInt32(width);
46  cmd.addInt32(height);
47  m_port.write(cmd, response);
48  return response.get(2).asBool();
49 }
50 
51 bool DepthVisualParams_Forwarder::getDepthFOV(double& horizontalFov, double& verticalFov)
52 {
53  yarp::os::Bottle cmd;
54  yarp::os::Bottle response;
56  cmd.addVocab32(VOCAB_GET);
57  cmd.addVocab32(VOCAB_FOV);
58  m_port.write(cmd, response);
59 
60  // Minimal check on response, we suppose the response is always correctly formatted
61  if ((response.get(0).asVocab32()) == VOCAB_FAILED) {
62  horizontalFov = 0;
63  verticalFov = 0;
64  return false;
65  }
66  horizontalFov = response.get(3).asFloat64();
67  verticalFov = response.get(4).asFloat64();
68  return true;
69 }
70 
71 bool DepthVisualParams_Forwarder::setDepthFOV(double horizontalFov, double verticalFov)
72 {
73  yarp::os::Bottle cmd;
74  yarp::os::Bottle response;
76  cmd.addVocab32(VOCAB_SET);
77  cmd.addVocab32(VOCAB_FOV);
78  cmd.addFloat64(horizontalFov);
79  cmd.addFloat64(verticalFov);
80  m_port.write(cmd, response);
81  return response.get(2).asBool();
82 }
83 
85 {
86  yarp::os::Bottle cmd;
87  yarp::os::Bottle response;
89  cmd.addVocab32(VOCAB_GET);
91  m_port.write(cmd, response);
92  return response.get(3).asFloat64();
93 }
94 
96 {
97  yarp::os::Bottle cmd;
98  yarp::os::Bottle response;
100  cmd.addVocab32(VOCAB_SET);
102  cmd.addFloat64(accuracy);
103  m_port.write(cmd, response);
104  return response.get(2).asBool();
105 }
106 
107 bool DepthVisualParams_Forwarder::getDepthClipPlanes(double& nearPlane, double& farPlane)
108 {
109  yarp::os::Bottle cmd;
110  yarp::os::Bottle response;
112  cmd.addVocab32(VOCAB_GET);
114  m_port.write(cmd, response);
115 
116  // Minimal check on response, we suppose the response is always correctly formatted
117  if ((response.get(0).asVocab32()) == VOCAB_FAILED) {
118  nearPlane = 0;
119  farPlane = 0;
120  return false;
121  }
122  nearPlane = response.get(3).asFloat64();
123  farPlane = response.get(4).asFloat64();
124  return true;
125 }
126 
127 bool DepthVisualParams_Forwarder::setDepthClipPlanes(double nearPlane, double farPlane)
128 {
129  yarp::os::Bottle cmd;
130  yarp::os::Bottle response;
132  cmd.addVocab32(VOCAB_SET);
134  cmd.addFloat64(nearPlane);
135  cmd.addFloat64(farPlane);
136  m_port.write(cmd, response);
137  return response.get(2).asBool();
138 }
139 
141 {
142  yarp::os::Bottle cmd;
143  yarp::os::Bottle response;
145  cmd.addVocab32(VOCAB_GET);
147  m_port.write(cmd, response);
148 
149  // Minimal check on response, we suppose the response is always correctly formatted
150  if ((response.get(0).asVocab32()) == VOCAB_FAILED) {
151  intrinsic.clear();
152  return false;
153  }
154 
155  yarp::os::Property::copyPortable(response.get(3), intrinsic); // will it really work??
156  return true;
157 }
158 
160 {
161  yarp::os::Bottle cmd;
162  yarp::os::Bottle response;
164  cmd.addVocab32(VOCAB_GET);
166  m_port.write(cmd, response);
167  if ((response.get(0).asVocab32()) == VOCAB_FAILED) {
168  return false;
169  }
170  mirror = response.get(3).asBool();
171  return true;
172 }
173 
175 {
176  yarp::os::Bottle cmd;
177  yarp::os::Bottle response;
179  cmd.addVocab32(VOCAB_SET);
181  cmd.addInt32(mirror);
182  m_port.write(cmd, response);
183  return response.get(2).asBool();
184 }
constexpr yarp::conf::vocab32_t VOCAB_DEPTH_VISUAL_PARAMS
Definition: CameraVocabs.h:19
constexpr yarp::conf::vocab32_t VOCAB_CLIP_PLANES
Definition: CameraVocabs.h:111
constexpr yarp::conf::vocab32_t VOCAB_RESOLUTION
Definition: CameraVocabs.h:104
constexpr yarp::conf::vocab32_t VOCAB_MIRROR
Definition: CameraVocabs.h:101
constexpr yarp::conf::vocab32_t VOCAB_FOV
Definition: CameraVocabs.h:105
constexpr yarp::conf::vocab32_t VOCAB_ACCURACY
Definition: CameraVocabs.h:110
constexpr yarp::conf::vocab32_t VOCAB_INTRINSIC_PARAM
Definition: CameraVocabs.h:106
constexpr yarp::conf::vocab32_t VOCAB_WIDTH
Definition: GenericVocabs.h:41
constexpr yarp::conf::vocab32_t VOCAB_GET
Definition: GenericVocabs.h:13
constexpr yarp::conf::vocab32_t VOCAB_FAILED
Definition: GenericVocabs.h:16
constexpr yarp::conf::vocab32_t VOCAB_SET
Definition: GenericVocabs.h:12
constexpr yarp::conf::vocab32_t VOCAB_HEIGHT
Definition: GenericVocabs.h:42
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.cpp:164
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Definition: Bottle.cpp:158
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:246
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:140
A mini-server for network communication.
Definition: Port.h:47
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition: Port.cpp:427
static bool copyPortable(const PortWriter &writer, PortReader &reader)
Copy one portable to another, via writing and reading.
Definition: Portable.cpp:16
A class for storing options and configuration information.
Definition: Property.h:34
void clear()
Remove all associations.
Definition: Property.cpp:1057
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:222
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
Definition: Value.cpp:228
virtual bool asBool() const
Get boolean value.
Definition: Value.cpp:186
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
bool setDepthMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool setDepthFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the depth camera.
bool getDepthClipPlanes(double &nearPlane, double &farPlane) override
Get the clipping planes of the sensor.
bool setDepthClipPlanes(double nearPlane, double farPlane) override
Set the clipping planes of the sensor.
int getDepthWidth() override
Return the height of each frame.
bool getDepthMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool setDepthResolution(int width, int height) override
Set the resolution of the depth image from the camera.
double getDepthAccuracy() override
Get the minimum detectable variation in distance [meter].
bool getDepthFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the depth camera.
bool setDepthAccuracy(double accuracy) override
Set the minimum detectable variation in distance [meter] when possible.
bool getDepthIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the depth camera.
int getDepthHeight() override
Return the height of each frame.