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/ObjectToDetect.h>
44 
45 #include <rc_silhouettematch_client/CalibrateBasePlane.h>
46 #include <rc_silhouettematch_client/GetBasePlaneCalibration.h>
47 #include <rc_silhouettematch_client/DeleteBasePlaneCalibration.h>
48 #include <rc_silhouettematch_client/DetectObject.h>
49 
50 namespace rc_common_msgs
51 {
52 inline void from_json(const nlohmann::json& j, ReturnCode& r)
53 {
54  j.at("value").get_to(r.value);
55  j.at("message").get_to(r.message);
56 }
57 
58 } // namespace rc_common_msgs
59 
61 {
62 inline void from_json(const nlohmann::json& j, Instance& r)
63 {
64  j.at("timestamp").get_to(r.timestamp);
65  j.at("id").get_to(r.id);
66  j.at("object_id").get_to(r.object_id);
67  j.at("pose_frame").get_to(r.pose_frame);
68  j.at("pose").get_to(r.pose);
69 }
70 
71 inline void to_json(nlohmann::json& j, const Plane& r)
72 {
73  j["distance"] = r.distance;
74  j["normal"] = r.normal;
75 }
76 
77 inline void from_json(const nlohmann::json& j, EstimatedPlane& r)
78 {
79  j.at("pose_frame").get_to(r.pose_frame);
80  j.at("distance").get_to(r.distance);
81  j.at("normal").get_to(r.normal);
82 }
83 
84 inline void to_json(nlohmann::json& j, const ObjectToDetect& r)
85 {
86  j["object_id"] = r.object_id;
87  j["region_of_interest_2d_id"] = r.region_of_interest_2d_id;
88 }
89 
90 inline void from_json(const nlohmann::json& j, ObjectToDetect& r)
91 {
92  j.at("object_id").get_to(r.object_id);
93  j.at("region_of_interest_2d_id").get_to(r.region_of_interest_2d_id);
94 }
95 
96 inline void to_json(nlohmann::json& j, const DetectObject::Request& r)
97 {
98  j["object_to_detect"] = r.object_to_detect;
99  j["offset"] = r.offset;
100  j["pose_frame"] = r.pose_frame;
101  j["robot_pose"] = r.robot_pose;
102 }
103 
104 inline void from_json(const nlohmann::json& j, DetectObject::Response& r)
105 {
106  j.at("timestamp").get_to(r.timestamp);
107  j.at("return_code").get_to(r.return_code);
108  j.at("object_id").get_to(r.object_id);
109  j.at("instances").get_to(r.instances);
110 }
111 
112 inline void to_json(nlohmann::json& j, const CalibrateBasePlane::Request& r)
113 {
114  j["pose_frame"] = r.pose_frame;
115  j["robot_pose"] = r.robot_pose;
116  j["plane_estimation_method"] = r.plane_estimation_method;
117  j["region_of_interest_2d_id"] = r.region_of_interest_2d_id;
118  j["offset"] = r.offset;
119  if (r.plane_estimation_method == "STEREO")
120  {
121  j["stereo"] = { { "plane_preference", r.stereo.plane_preference } };
122  }
123  else
124  {
125  j["plane"] = r.plane;
126  }
127 }
128 
129 inline void from_json(const nlohmann::json& j, CalibrateBasePlane::Response& r)
130 {
131  j.at("timestamp").get_to(r.timestamp);
132  j.at("return_code").get_to(r.return_code);
133  j.at("plane").get_to(r.plane);
134 }
135 
136 inline void to_json(nlohmann::json& j, const GetBasePlaneCalibration::Request& r)
137 {
138  j["pose_frame"] = r.pose_frame;
139  j["robot_pose"] = r.robot_pose;
140 }
141 
142 inline void from_json(const nlohmann::json& j, GetBasePlaneCalibration::Response& r)
143 {
144  j.at("return_code").get_to(r.return_code);
145  j.at("plane").get_to(r.plane);
146 }
147 
148 inline void to_json(nlohmann::json& j, const DeleteBasePlaneCalibration::Request& r)
149 {
150  j = {};
151 }
152 
153 inline void from_json(const nlohmann::json& j, DeleteBasePlaneCalibration::Response& r)
154 {
155  j.at("return_code").get_to(r.return_code);
156 }
157 
158 } // namespace rc_silhouettematch_client
159 
160 #endif // RC_SILHOUETTEMATCH_CLIENT_JSON_CONVERSIONS_H
nlohmann::json json
void to_json(nlohmann::json &j, const DeleteBasePlaneCalibration::Request &r)
void from_json(const nlohmann::json &j, ReturnCode &r)


rc_silhouettematch_client
Author(s): Elena Gambaro
autogenerated on Sun May 15 2022 03:05:23