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 
6 
7 void mygraph::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 = simox::color::interpol::linear(0.5, cmap(vertex.value), simox::Color::white());
16  j["style"]["fill-color"] = color.to_vector4i();
17 }
18 
19 void mygraph::from_json(const nlohmann::json& j, mygraph::MyVertex& vertex)
20 {
21  j.at("name").get_to(vertex.name);
22  j.at("value").get_to(vertex.value);
23 
24 }
25 
26 void mygraph::to_json(nlohmann::json& j, const mygraph::MyEdge& edge)
27 {
28  j["value"] = edge.value;
29 
30  simox::Color color;
31  switch (edge.value)
32  {
33  case 1:
34  color = simox::Color::blue();
35  break;
36  case 2:
37  color = simox::Color::green();
38  break;
39  default:
40  color = simox::Color::black();
41  break;
42  }
43 
44  j["style"]["color"] = color.to_vector4i();
45  if (edge.value > 0)
46  {
47  j["style"]["label"] = std::to_string(edge.value);
48  }
49 }
50 
51 void mygraph::from_json(const nlohmann::json& j, mygraph::MyEdge& edge)
52 {
53  j.at("value").get_to(edge.value);
54 }
55 
56 void mygraph::to_json(nlohmann::json& j, const mygraph::MyGraphAttributes& graph)
57 {
58  j["position"] = graph.position;
59  j["orientation"] = graph.orientation;
60 }
61 
62 void mygraph::from_json(const nlohmann::json& j, mygraph::MyGraphAttributes& graph)
63 {
64  j.at("position").get_to(graph.position);
65  j.at("orientation").get_to(graph.orientation);
66 }
mygraph::MyVertex::name
std::string name
Definition: MyGraph.h:10
mygraph::MyGraphAttributes::position
Eigen::Vector3f position
Definition: MyGraph.h:21
mygraph::MyVertex
Definition: MyGraph.h:8
mygraph::from_json
void from_json(const nlohmann::json &j, MyVertex &vertex)
Definition: json.cpp:19
mygraph::MyGraphAttributes::orientation
Eigen::Quaternionf orientation
Definition: MyGraph.h:22
mygraph::MyGraphAttributes
Definition: MyGraph.h:19
mygraph::MyVertex::value
float value
Definition: MyGraph.h:11
Color
uint32_t Color
RGBA color.
Definition: color.h:8
mygraph::MyEdge
Definition: MyGraph.h:14
armarx::trajectory::interpolate::linear
ReturnT linear(float t, const VariantValue &lhs, const VariantValue &rhs)
Definition: linear.h:56
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
mygraph::MyEdge::value
int value
Definition: MyGraph.h:16
json.h
mygraph::to_json
void to_json(nlohmann::json &j, const MyVertex &vertex)
Definition: json.cpp:7
armarx::green
QColor green()
Definition: StyleSheets.h:72