YARP
Yet Another Robot Platform
DepthVisualParams_Responder.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 
9 #include <yarp/os/LogStream.h>
10 
12 
13 DepthVisualParams_Responder::DepthVisualParams_Responder() :
14  iDepthVisual(nullptr)
15 {
16 }
17 // DepthVisualParams_Responder::~DepthVisualParams_Responder() { }
18 
20 {
21  bool ret = false;
22  if (interface) {
23  iDepthVisual = interface;
24  ret = true;
25  } else {
26  iDepthVisual = nullptr;
27  ret = false;
28  }
29  return ret;
30 }
31 
33 {
34  bool ret = false;
35  response.clear();
36  if (!iDepthVisual) {
37  yError() << "Depth Visual parameter Parser has not been correctly configured. IDepthVisualParams interface is not valid";
38  response.addVocab32(VOCAB_FAILED);
39  return false;
40  }
41 
42  int code = cmd.get(0).asVocab32();
43  if (code != VOCAB_DEPTH_VISUAL_PARAMS) {
44  yError() << "Depth Visual Params Parser received a command not belonging to this interface. Required interface was " << yarp::os::Vocab32::decode(code);
45  response.addVocab32(VOCAB_FAILED);
46  return false;
47  }
48 
49  switch (cmd.get(1).asVocab32()) {
50  case VOCAB_GET: {
51  switch (cmd.get(2).asVocab32()) {
52  case VOCAB_HEIGHT: {
54  response.addVocab32(VOCAB_HEIGHT);
55  response.addVocab32(VOCAB_IS);
56  response.addInt32(iDepthVisual->getDepthHeight());
57  } break;
58 
59  case VOCAB_WIDTH: {
61  response.addVocab32(VOCAB_WIDTH);
62  response.addVocab32(VOCAB_IS);
63  response.addInt32(iDepthVisual->getDepthWidth());
64  } break;
65 
66  case VOCAB_FOV: {
67  double hFov;
68  double vFov;
69  ret = iDepthVisual->getDepthFOV(hFov, vFov);
70  if (ret) {
72  response.addVocab32(VOCAB_FOV);
73  response.addVocab32(VOCAB_IS);
74  response.addFloat64(hFov);
75  response.addFloat64(vFov);
76  } else {
77  response.addVocab32(VOCAB_FAILED);
78  }
79  } break;
80 
81  case VOCAB_INTRINSIC_PARAM: {
82  yarp::os::Property params;
83  ret = iDepthVisual->getDepthIntrinsicParam(params);
84  if (ret) {
87  response.addVocab32(VOCAB_IS);
88  yarp::os::Bottle& tmp = response.addList();
89  ret &= yarp::os::Property::copyPortable(params, tmp);
90  } else {
91  response.addVocab32(VOCAB_FAILED);
92  }
93  } break;
94 
95  case VOCAB_ACCURACY: {
97  response.addVocab32(VOCAB_ACCURACY);
98  response.addVocab32(VOCAB_IS);
99  response.addFloat64(iDepthVisual->getDepthAccuracy());
100  } break;
101 
102  case VOCAB_CLIP_PLANES: {
103  double nearPlane;
104  double farPlane;
105  iDepthVisual->getDepthClipPlanes(nearPlane, farPlane);
107  response.addVocab32(VOCAB_CLIP_PLANES);
108  response.addVocab32(VOCAB_IS);
109  response.addFloat64(nearPlane);
110  response.addFloat64(farPlane);
111  } break;
112 
113  case VOCAB_MIRROR: {
114  bool mirror;
115  ret = iDepthVisual->getDepthMirroring(mirror);
116  if (ret) {
118  response.addVocab32(VOCAB_MIRROR);
119  response.addVocab32(VOCAB_IS);
120  response.addInt32(mirror);
121  } else {
122  response.addVocab32(VOCAB_FAILED);
123  }
124  } break;
125 
126  default:
127  {
128  yError() << "Depth Visual Parameter interface parser received am unknown GET command. Command is " << cmd.toString();
129  response.addVocab32(VOCAB_FAILED);
130  ret = false;
131  } break;
132  }
133  } break;
134 
135  case VOCAB_SET: {
136  switch (cmd.get(2).asVocab32()) {
137  case VOCAB_RESOLUTION: {
138  ret = iDepthVisual->setDepthResolution(cmd.get(3).asInt32(), cmd.get(4).asInt32());
140  response.addVocab32(VOCAB_SET);
141  response.addInt32(ret);
142  } break;
143 
144  case VOCAB_FOV: {
145  ret = iDepthVisual->setDepthFOV(cmd.get(3).asFloat64(), cmd.get(4).asFloat64());
147  response.addVocab32(VOCAB_SET);
148  response.addInt32(ret);
149  } break;
150 
151  case VOCAB_ACCURACY: {
152  ret = iDepthVisual->setDepthAccuracy(cmd.get(3).asFloat64());
154  response.addVocab32(VOCAB_SET);
155  response.addInt32(ret);
156  } break;
157 
158  case VOCAB_CLIP_PLANES: {
159  ret = iDepthVisual->setDepthClipPlanes(cmd.get(3).asFloat64(), cmd.get(4).asFloat64());
161  response.addVocab32(VOCAB_SET);
162  response.addInt32(ret);
163  } break;
164 
165  case VOCAB_MIRROR: {
166  ret = iDepthVisual->setDepthMirroring(cmd.get(3).asBool());
168  response.addVocab32(VOCAB_SET);
169  response.addInt32(ret);
170  } break;
171 
172  default:
173  {
174  yError() << "Rgb Visual Parameter interface parser received am unknown SET command. Command is " << cmd.toString();
175  response.addVocab32(VOCAB_FAILED);
176  ret = false;
177  } break;
178  }
179  } break;
180 
181  default:
182  {
183  yError() << "Rgb Visual parameter interface Parser received a malformed request. Command should either be 'set' or 'get', received " << cmd.toString();
184  response.addVocab32(VOCAB_FAILED);
185  ret = false;
186  } break;
187  }
188  return ret;
189 }
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_IS
Definition: GenericVocabs.h:14
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
bool ret
#define yError(...)
Definition: Log.h:279
An interface for retrieving intrinsic parameter from a depth camera.
virtual bool setDepthMirroring(bool mirror)=0
Set the mirroring setting of the sensor.
virtual double getDepthAccuracy()=0
Get the minimum detectable variation in distance [meter].
virtual bool setDepthAccuracy(double accuracy)=0
Set the minimum detectable variation in distance [meter] when possible.
virtual int getDepthWidth()=0
Return the height of each frame.
virtual bool getDepthIntrinsicParam(yarp::os::Property &intrinsic)=0
Get the intrinsic parameters of the depth camera.
virtual bool getDepthFOV(double &horizontalFov, double &verticalFov)=0
Get the field of view (FOV) of the depth camera.
virtual bool setDepthFOV(double horizontalFov, double verticalFov)=0
Set the field of view (FOV) of the depth camera.
virtual bool setDepthClipPlanes(double nearPlane, double farPlane)=0
Set the clipping planes of the sensor.
virtual bool getDepthClipPlanes(double &nearPlane, double &farPlane)=0
Get the clipping planes of the sensor.
virtual bool getDepthMirroring(bool &mirror)=0
Get the mirroring setting of the sensor.
virtual int getDepthHeight()=0
Return the height of each frame.
virtual bool setDepthResolution(int width, int height)=0
Set the resolution of the depth image from the camera.
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
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
Definition: Bottle.cpp:182
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 clear()
Empties the bottle of any objects it contains.
Definition: Bottle.cpp:121
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:140
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:211
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
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 configure(yarp::dev::IDepthVisualParams *interface)
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition: Vocab.cpp:33