json_base.cpp
Go to the documentation of this file.
1 #include "json_base.h"
2 
3 #include <SimoxUtility/math/pose/pose.h>
4 
6 
7 
8 void armarx::to_json(nlohmann::json& j, const armarx::Vector2f& value)
9 {
10  j["x"] = value.e0;
11  j["y"] = value.e1;
12 }
13 void armarx::from_json(const nlohmann::json& j, armarx::Vector2f& value)
14 {
15  value.e0 = j.at("x").get<float>();
16  value.e1 = j.at("y").get<float>();
17 }
18 
19 
20 void armarx::to_json(nlohmann::json& j, const armarx::Vector3f& value)
21 {
22  j["x"] = value.e0;
23  j["y"] = value.e1;
24  j["z"] = value.e2;
25 }
26 void armarx::from_json(const nlohmann::json& j, armarx::Vector3f& value)
27 {
28  value.e0 = j.at("x").get<float>();
29  value.e1 = j.at("y").get<float>();
30  value.e2 = j.at("z").get<float>();
31 }
32 
33 
34 namespace armarx::viz
35 {
36  void data::to_json(nlohmann::json& j, const data::GlobalPose& pose)
37  {
38  armarx::Vector3f pos;
39  pos.e0 = pose.x;
40  pos.e1 = pose.y;
41  pos.e2 = pose.z;
42  j["position"] = pos;
43 
44  j["orientation"] = Eigen::Quaternionf(pose.qw, pose.qx, pose.qy, pose.qz);
45 
46  j[json::meta::KEY]["orientation"] = json::meta::ORIENTATION;
47  }
48  void data::from_json(const nlohmann::json& j, data::GlobalPose& pose)
49  {
50  const armarx::Vector3f pos = j.at("position").get<armarx::Vector3f>();
51  const Eigen::Quaternionf ori = j.at("orientation").get<Eigen::Quaternionf>();
52  pose.x = pos.e0;
53  pose.y = pos.e1;
54  pose.z = pos.e2;
55  pose.qw = ori.w();
56  pose.qx = ori.x();
57  pose.qy = ori.y();
58  pose.qz = ori.z();
59  }
60 
61  void data::to_json(nlohmann::json& j, const data::Color& color)
62  {
63  j["r"] = color.r;
64  j["g"] = color.g;
65  j["b"] = color.b;
66  j["a"] = color.a;
67  }
68  void data::from_json(const nlohmann::json& j, data::Color& color)
69  {
70  color.r = j.at("r").get<Ice::Byte>();
71  color.g = j.at("g").get<Ice::Byte>();
72  color.b = j.at("b").get<Ice::Byte>();
73  color.a = j.at("a").get<Ice::Byte>();
74  }
75 
76 
77  const std::string json::meta::KEY = "__meta__";
78 
79  const std::string json::meta::HIDE = "hide";
80  const std::string json::meta::READ_ONLY = "read_only";
81 
82  const std::string json::meta::COLOR = "color";
83  const std::string json::meta::ORIENTATION = "orientation";
84 
85 
86  void json::to_json_base(nlohmann::json& j, const data::Element& element)
87  {
88  j["id"] = element.id;
89  j["pose"] = element.pose;
90  j["color"] = element.color;
91  j["flags"] = element.flags;
92  j["scale"] = element.scale;
93 
94  j[meta::KEY]["id"] = meta::HIDE;
95  j[meta::KEY]["flags"] = meta::HIDE;
96  j[meta::KEY]["color"] = meta::COLOR;
97  }
98  void json::from_json_base(const nlohmann::json& j, data::Element& element)
99  {
100  element.id = j.at("id").get<std::string>();
101  element.pose = j.at("pose").get<data::GlobalPose>();
102  element.color = j.at("color").get<data::Color>();
103  element.flags = j.at("flags").get<int>();
104  element.scale = j.at("scale").get<armarx::Vector3f>();
105  }
106 
107 }
108 
armarx::to_json
void to_json(nlohmann::json &j, const Vector2f &value)
armarx::viz::json::to_json_base
void to_json_base(nlohmann::json &j, const data::Element &element)
Definition: json_base.cpp:86
armarx::viz::json::meta::KEY
const std::string KEY
Definition: json_base.cpp:77
armarx::viz::json::meta::HIDE
const std::string HIDE
Do not show.
Definition: json_base.cpp:79
armarx::viz::json::meta::COLOR
const std::string COLOR
Use a color picker.
Definition: json_base.cpp:82
armarx::viz::data::from_json
void from_json(nlohmann::json const &j, RecordingBatchHeader &batch)
Definition: ArVizStorage.cpp:430
ElementJsonSerializers.h
Color
uint32_t Color
RGBA color.
Definition: color.h:8
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::viz::json::meta::ORIENTATION
const std::string ORIENTATION
Definition: json_base.cpp:83
armarx::viz::json::meta::READ_ONLY
const std::string READ_ONLY
Make read-only.
Definition: json_base.cpp:80
json_base.h
Eigen::Quaternionf
Quaternion< float, 0 > Quaternionf
Definition: EigenForwardDeclarations.h:61
armarx::from_json
void from_json(const nlohmann::json &j, Vector2f &value)
armarx::Quaternion< float, 0 >
armarx::viz
This file is part of ArmarX.
Definition: ArVizStorage.cpp:416
armarx::viz::json::from_json_base
void from_json_base(const nlohmann::json &j, data::Element &value)
Definition: json_base.cpp:98
armarx::viz::data::to_json
void to_json(nlohmann::json &j, RecordingBatchHeader const &batch)
Definition: ArVizStorage.cpp:420