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
void
7
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 =
16
simox::color::interpol::linear(0.5, cmap(vertex.
value
), simox::Color::white());
17
j[
"style"
][
"fill-color"
] = color.to_vector4i();
18
}
19
20
void
21
mygraph::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
27
void
28
mygraph::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
53
void
54
mygraph::from_json
(
const
nlohmann::json& j,
mygraph::MyEdge
& edge)
55
{
56
j.at(
"value"
).get_to(edge.
value
);
57
}
58
59
void
60
mygraph::to_json
(nlohmann::json& j,
const
mygraph::MyGraphAttributes
& graph)
61
{
62
j[
"position"
] = graph.
position
;
63
j[
"orientation"
] = graph.
orientation
;
64
}
65
66
void
67
mygraph::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
}
json.h
mygraph::to_json
void to_json(nlohmann::json &j, const MyVertex &vertex)
Definition
json.cpp:7
mygraph::from_json
void from_json(const nlohmann::json &j, MyVertex &vertex)
Definition
json.cpp:21
mygraph::MyEdge
Definition
MyGraph.h:14
mygraph::MyEdge::value
int value
Definition
MyGraph.h:15
mygraph::MyGraphAttributes
Definition
MyGraph.h:19
mygraph::MyGraphAttributes::orientation
Eigen::Quaternionf orientation
Definition
MyGraph.h:21
mygraph::MyGraphAttributes::position
Eigen::Vector3f position
Definition
MyGraph.h:20
mygraph::MyVertex
Definition
MyGraph.h:8
mygraph::MyVertex::value
float value
Definition
MyGraph.h:10
mygraph::MyVertex::name
std::string name
Definition
MyGraph.h:9
VisionX
components
SemanticGraphExample
json.cpp
Generated by
1.13.2