json_conversions.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Roboception GmbH
3  *
4  * Author: Elena Gambaro
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of the copyright holder nor the names of its contributors
17  * may be used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef RC_SILHOUETTEMATCH_CLIENT_JSON_CONVERSIONS_H
34 #define RC_SILHOUETTEMATCH_CLIENT_JSON_CONVERSIONS_H
35 
37 
38 #include <rc_common_msgs/ReturnCode.h>
39 
40 #include <rc_silhouettematch_client/Instance.h>
41 #include <rc_silhouettematch_client/Plane.h>
42 #include <rc_silhouettematch_client/EstimatedPlane.h>
43 #include <rc_silhouettematch_client/RegionOfInterest.h>
44 #include <rc_silhouettematch_client/ObjectToDetect.h>
45 
46 #include <rc_silhouettematch_client/CalibrateBasePlane.h>
47 #include <rc_silhouettematch_client/GetBasePlaneCalibration.h>
48 #include <rc_silhouettematch_client/DeleteBasePlaneCalibration.h>
49 #include <rc_silhouettematch_client/SetRegionOfInterest.h>
50 #include <rc_silhouettematch_client/GetRegionsOfInterest.h>
51 #include <rc_silhouettematch_client/DeleteRegionsOfInterest.h>
52 #include <rc_silhouettematch_client/DetectObject.h>
53 
54 namespace rc_common_msgs
55 {
56 inline void from_json(const nlohmann::json& j, ReturnCode& r)
57 {
58  j.at("value").get_to(r.value);
59  j.at("message").get_to(r.message);
60 }
61 
62 } // namespace rc_common_msgs
63 
65 {
66 inline void from_json(const nlohmann::json& j, Instance& r)
67 {
68  j.at("timestamp").get_to(r.timestamp);
69  j.at("id").get_to(r.id);
70  j.at("object_id").get_to(r.object_id);
71  j.at("pose_frame").get_to(r.pose_frame);
72  j.at("pose").get_to(r.pose);
73 }
74 
75 inline void to_json(nlohmann::json& j, const Plane& r)
76 {
77  j["distance"] = r.distance;
78  j["normal"] = r.normal;
79 }
80 
81 inline void from_json(const nlohmann::json& j, EstimatedPlane& r)
82 {
83  j.at("pose_frame").get_to(r.pose_frame);
84  j.at("distance").get_to(r.distance);
85  j.at("normal").get_to(r.normal);
86 }
87 
88 inline void to_json(nlohmann::json& j, const RegionOfInterest& r)
89 {
90  j["id"] = r.id;
91  j["offset_x"] = r.offset_x;
92  j["offset_y"] = r.offset_y;
93  j["width"] = r.width;
94  j["height"] = r.height;
95 }
96 
97 inline void from_json(const nlohmann::json& j, RegionOfInterest& r)
98 {
99  j.at("id").get_to(r.id);
100  j.at("offset_x").get_to(r.offset_x);
101  j.at("offset_y").get_to(r.offset_y);
102  j.at("width").get_to(r.width);
103  j.at("height").get_to(r.height);
104 }
105 
106 inline void to_json(nlohmann::json& j, const ObjectToDetect& r)
107 {
108  j["object_id"] = r.object_id;
109  j["region_of_interest_2d_id"] = r.region_of_interest_2d_id;
110 }
111 
112 inline void from_json(const nlohmann::json& j, ObjectToDetect& r)
113 {
114  j.at("object_id").get_to(r.object_id);
115  j.at("region_of_interest_2d_id").get_to(r.region_of_interest_2d_id);
116 }
117 
118 inline void to_json(nlohmann::json& j, const DetectObject::Request& r)
119 {
120  j["object_to_detect"] = r.object_to_detect;
121  j["offset"] = r.offset;
122  j["pose_frame"] = r.pose_frame;
123  j["robot_pose"] = r.robot_pose;
124 }
125 
126 inline void from_json(const nlohmann::json& j, DetectObject::Response& r)
127 {
128  j.at("timestamp").get_to(r.timestamp);
129  j.at("return_code").get_to(r.return_code);
130  j.at("object_id").get_to(r.object_id);
131  j.at("instances").get_to(r.instances);
132 }
133 
134 inline void to_json(nlohmann::json& j, const CalibrateBasePlane::Request& r)
135 {
136  j["pose_frame"] = r.pose_frame;
137  j["robot_pose"] = r.robot_pose;
138  j["plane_estimation_method"] = r.plane_estimation_method;
139  j["region_of_interest_2d_id"] = r.region_of_interest_2d_id;
140  j["offset"] = r.offset;
141  if (r.plane_estimation_method == "STEREO")
142  {
143  j["stereo"] = { { "plane_preference", r.stereo.plane_preference } };
144  }
145  else
146  {
147  j["plane"] = r.plane;
148  }
149 }
150 
151 inline void from_json(const nlohmann::json& j, CalibrateBasePlane::Response& r)
152 {
153  j.at("timestamp").get_to(r.timestamp);
154  j.at("return_code").get_to(r.return_code);
155  j.at("plane").get_to(r.plane);
156 }
157 
158 inline void to_json(nlohmann::json& j, const GetBasePlaneCalibration::Request& r)
159 {
160  j["pose_frame"] = r.pose_frame;
161  j["robot_pose"] = r.robot_pose;
162 }
163 
164 inline void from_json(const nlohmann::json& j, GetBasePlaneCalibration::Response& r)
165 {
166  j.at("return_code").get_to(r.return_code);
167  j.at("plane").get_to(r.plane);
168 }
169 
170 inline void to_json(nlohmann::json& j, const DeleteBasePlaneCalibration::Request& r)
171 {
172  j = {};
173 }
174 
175 inline void from_json(const nlohmann::json& j, DeleteBasePlaneCalibration::Response& r)
176 {
177  j.at("return_code").get_to(r.return_code);
178 }
179 
180 inline void to_json(nlohmann::json& j, const SetRegionOfInterest::Request& r)
181 {
182  j["region_of_interest_2d"] = r.region_of_interest_2d;
183 }
184 
185 inline void from_json(const nlohmann::json& j, SetRegionOfInterest::Response& r)
186 {
187  j.at("return_code").get_to(r.return_code);
188 }
189 
190 inline void to_json(nlohmann::json& j, const GetRegionsOfInterest::Request& r)
191 {
192  j["region_of_interest_2d_ids"] = r.region_of_interest_2d_ids;
193 }
194 
195 inline void from_json(const nlohmann::json& j, GetRegionsOfInterest::Response& r)
196 {
197  j.at("regions_of_interest").get_to(r.regions_of_interest);
198  j.at("return_code").get_to(r.return_code);
199 }
200 
201 inline void to_json(nlohmann::json& j, const DeleteRegionsOfInterest::Request& r)
202 {
203  j["region_of_interest_2d_ids"] = r.region_of_interest_2d_ids;
204 }
205 
206 inline void from_json(const nlohmann::json& j, DeleteRegionsOfInterest::Response& r)
207 {
208  j.at("return_code").get_to(r.return_code);
209 }
210 
211 } // namespace rc_silhouettematch_client
212 
213 #endif // RC_SILHOUETTEMATCH_CLIENT_JSON_CONVERSIONS_H
void to_json(nlohmann::json &j, const DeleteRegionsOfInterest::Request &r)
nlohmann::json json
void from_json(const nlohmann::json &j, ReturnCode &r)


rc_silhouettematch_client
Author(s): Elena Gambaro
autogenerated on Sat Feb 13 2021 03:42:03