11 #include <json/json.h>
15 namespace registration {
20 value[
"class_name"] =
"PoseGraphNode";
21 value[
"version_major"] = 1;
22 value[
"version_minor"] = 0;
24 Json::Value pose_object;
28 value[
"pose"] = pose_object;
33 if (!value.isObject()) {
35 "PoseGraphNode read JSON failed: unsupported json format.");
38 if (value.get(
"class_name",
"").asString() !=
"PoseGraphNode" ||
39 value.get(
"version_major", 1).asInt() != 1 ||
40 value.get(
"version_minor", 0).asInt() != 0) {
42 "PoseGraphNode read JSON failed: unsupported json format.");
46 const Json::Value &pose_object = value[
"pose"];
56 value[
"class_name"] =
"PoseGraphEdge";
57 value[
"version_major"] = 1;
58 value[
"version_minor"] = 0;
64 Json::Value transformation_object;
68 value[
"transformation"] = transformation_object;
69 Json::Value information_object;
73 value[
"information"] = information_object;
78 if (!value.isObject()) {
80 "PoseGraphEdge read JSON failed: unsupported json format.");
83 if (value.get(
"class_name",
"").asString() !=
"PoseGraphEdge" ||
84 value.get(
"version_major", 1).asInt() != 1 ||
85 value.get(
"version_minor", 0).asInt() != 0) {
87 "PoseGraphEdge read JSON failed: unsupported json format.");
93 uncertain_ = value.get(
"uncertain",
false).asBool();
94 confidence_ = value.get(
"confidence", 1.0).asDouble();
95 const Json::Value &transformation_object = value[
"transformation"];
99 const Json::Value &information_object = value[
"information"];
111 value[
"class_name"] =
"PoseGraph";
112 value[
"version_major"] = 1;
113 value[
"version_minor"] = 0;
115 Json::Value node_array;
116 for (
const auto &node :
nodes_) {
117 Json::Value node_object;
118 if (!node.ConvertToJsonValue(node_object)) {
121 node_array.append(node_object);
123 value[
"nodes"] = node_array;
125 Json::Value edge_array;
126 for (
const auto &edge :
edges_) {
127 Json::Value edge_object;
128 if (!edge.ConvertToJsonValue(edge_object)) {
131 edge_array.append(edge_object);
133 value[
"edges"] = edge_array;
138 if (!value.isObject()) {
140 "PoseGraph read JSON failed: unsupported json format.");
143 if (value.get(
"class_name",
"").asString() !=
"PoseGraph" ||
144 value.get(
"version_major", 1).asInt() != 1 ||
145 value.get(
"version_minor", 0).asInt() != 0) {
147 "PoseGraph read JSON failed: unsupported json format.");
151 const Json::Value &node_array = value[
"nodes"];
152 if (node_array.empty()) {
157 for (
int i = 0; i < (int)node_array.size(); i++) {
158 const Json::Value &node_object = node_array[i];
163 nodes_.push_back(new_node);
166 const Json::Value &edge_array = value[
"edges"];
167 if (edge_array.empty()) {
172 for (
int i = 0; i < (int)edge_array.size(); i++) {
173 const Json::Value &edge_object = edge_array[i];
178 edges_.push_back(new_edge);
Eigen::Matrix4d_u transformation_
Transformation matrix.
int target_node_id_
Target PoseGraphNode id.
int source_node_id_
Source PoseGraphNode id.
bool uncertain_
Whether the edge is uncertain.
bool ConvertToJsonValue(Json::Value &value) const override
bool ConvertFromJsonValue(const Json::Value &value) override
Eigen::Matrix6d_u information_
Information matrix.
double confidence_
Confidence value of the edge.
bool ConvertToJsonValue(Json::Value &value) const override
bool ConvertFromJsonValue(const Json::Value &value) override
bool ConvertFromJsonValue(const Json::Value &value) override
bool ConvertToJsonValue(Json::Value &value) const override
PoseGraph()
Default Constructor.
std::vector< PoseGraphNode > nodes_
List of PoseGraphNode.
std::vector< PoseGraphEdge > edges_
List of PoseGraphEdge.
static bool EigenMatrix6dFromJsonArray(Eigen::Matrix6d &mat, const Json::Value &value)
static bool EigenMatrix6dToJsonArray(const Eigen::Matrix6d &mat, Json::Value &value)
static bool EigenMatrix4dFromJsonArray(Eigen::Matrix4d &mat, const Json::Value &value)
static bool EigenMatrix4dToJsonArray(const Eigen::Matrix4d &mat, Json::Value &value)
Generic file read and write utility for python interface.