json.cpp
Go to the documentation of this file.
1#include "json.h"
2
3#include <SimoxUtility/color/cmaps.h>
4#include <SimoxUtility/color/interpolation.h>
5
6void
7mygraph::to_json(nlohmann::json& j, const mygraph::MyVertex& vertex)
8{
9 static simox::ColorMap cmap = simox::color::cmaps::viridis();
10
11 j["name"] = vertex.name;
12 j["value"] = vertex.value;
13
14 j["style"]["label"] = vertex.name;
15 simox::Color color =
16 simox::color::interpol::linear(0.5, cmap(vertex.value), simox::Color::white());
17 j["style"]["fill-color"] = color.to_vector4i();
18}
19
20void
21mygraph::from_json(const nlohmann::json& j, mygraph::MyVertex& vertex)
22{
23 j.at("name").get_to(vertex.name);
24 j.at("value").get_to(vertex.value);
25}
26
27void
28mygraph::to_json(nlohmann::json& j, const mygraph::MyEdge& edge)
29{
30 j["value"] = edge.value;
31
32 simox::Color color;
33 switch (edge.value)
34 {
35 case 1:
36 color = simox::Color::blue();
37 break;
38 case 2:
39 color = simox::Color::green();
40 break;
41 default:
42 color = simox::Color::black();
43 break;
44 }
45
46 j["style"]["color"] = color.to_vector4i();
47 if (edge.value > 0)
48 {
49 j["style"]["label"] = std::to_string(edge.value);
50 }
51}
52
53void
54mygraph::from_json(const nlohmann::json& j, mygraph::MyEdge& edge)
55{
56 j.at("value").get_to(edge.value);
57}
58
59void
60mygraph::to_json(nlohmann::json& j, const mygraph::MyGraphAttributes& graph)
61{
62 j["position"] = graph.position;
63 j["orientation"] = graph.orientation;
64}
65
66void
67mygraph::from_json(const nlohmann::json& j, mygraph::MyGraphAttributes& graph)
68{
69 j.at("position").get_to(graph.position);
70 j.at("orientation").get_to(graph.orientation);
71}
void to_json(nlohmann::json &j, const MyVertex &vertex)
Definition json.cpp:7
void from_json(const nlohmann::json &j, MyVertex &vertex)
Definition json.cpp:21
Eigen::Quaternionf orientation
Definition MyGraph.h:21
Eigen::Vector3f position
Definition MyGraph.h:20
std::string name
Definition MyGraph.h:9