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