@@ -55,8 +55,8 @@ using nlohmann::json;
55
55
using EdgesPtr = std::unique_ptr<SceneGraphLayer::Edges>;
56
56
using NodeSet = std::unordered_set<NodeId>;
57
57
using NodeCallback = std::function<void (NodeId, LayerId, NodeAttributes::Ptr&&)>;
58
- using DynamicNodeCallback =
59
- std::function< void (LayerId, char , std::chrono::nanoseconds, NodeAttributes::Ptr&&)>;
58
+ using DynamicNodeCallback = std::function<
59
+ void (LayerId, NodeId , std::chrono::nanoseconds, NodeAttributes::Ptr&&)>;
60
60
using EdgeCallback = std::function<void (NodeId, NodeId, EdgeAttributes::Ptr&&)>;
61
61
62
62
void to_json (json& record, const MeshEdge& edge) {
@@ -94,11 +94,12 @@ void read_node_from_json(const json& record, NodeCallback callback) {
94
94
95
95
void read_node_from_json (const json& record, DynamicNodeCallback callback) {
96
96
auto layer = record.at (" layer" ).get <LayerId>();
97
- auto prefix = record.at (" prefix" ).get <char >();
97
+ // auto prefix = record.at("prefix").get<char>();
98
+ auto node_id = record.at (" id" ).get <NodeId>();
98
99
auto timestamp = record.at (" timestamp" ).get <uint64_t >();
99
100
JsonConverter converter (&record.at (" attributes" ));
100
101
auto attrs = JsonNodeFactory::get_default ().create (converter);
101
- callback (layer, prefix , std::chrono::nanoseconds (timestamp), std::move (attrs));
102
+ callback (layer, node_id , std::chrono::nanoseconds (timestamp), std::move (attrs));
102
103
}
103
104
104
105
void read_edge_from_json (const json& record, EdgeCallback callback) {
@@ -176,7 +177,7 @@ std::string DynamicSceneGraph::serialize(bool include_mesh) const {
176
177
record[" layer_ids" ] = layer_ids;
177
178
record[" mesh_layer_id" ] = mesh_layer_id;
178
179
179
- for (const auto & id_layer_pair : layers_) {
180
+ for (const auto & id_layer_pair : layers_){
180
181
for (const auto & id_node_pair : id_layer_pair.second ->nodes_ ) {
181
182
record[" nodes" ].push_back (*id_node_pair.second );
182
183
}
@@ -198,8 +199,16 @@ std::string DynamicSceneGraph::serialize(bool include_mesh) const {
198
199
for (const auto & prefix_layer_pair : id_layer_group_pair.second ) {
199
200
const DynamicSceneGraphLayer& layer = *prefix_layer_pair.second ;
200
201
201
- for (const auto & node : layer.nodes_ ) {
202
- record[" nodes" ].push_back (*node);
202
+ for (size_t i = 0 ; i < layer.nodes_ .size (); ++i) {
203
+ if (!layer.node_status_ .count (i)) {
204
+ continue ;
205
+ }
206
+
207
+ if (layer.node_status_ .at (i) == NodeStatus::DELETED) {
208
+ continue ;
209
+ }
210
+
211
+ record[" nodes" ].push_back (*layer.nodes_ .at (i));
203
212
}
204
213
205
214
for (const auto & id_edge_pair : layer.edges_ .edges ) {
@@ -251,20 +260,29 @@ DynamicSceneGraph::Ptr DynamicSceneGraph::deserialize(const std::string& content
251
260
}
252
261
253
262
for (const auto & id_content_pair : dynamic_contents) {
254
- read_node_from_json (id_content_pair.second ,
255
- [graph](LayerId layer,
256
- char prefix,
257
- std::chrono::nanoseconds time,
258
- NodeAttributes::Ptr&& attrs) {
259
- graph->emplaceNode (
260
- layer, prefix, time, std::move (attrs), false );
261
- });
263
+ read_node_from_json (
264
+ id_content_pair.second ,
265
+ [graph](LayerId layer,
266
+ NodeId node,
267
+ std::chrono::nanoseconds time,
268
+ NodeAttributes::Ptr&& attrs) {
269
+ if (!graph->emplacePrevDynamicNode (layer, node, time, std::move (attrs))) {
270
+ std::stringstream ss;
271
+ ss << " failed to add " << NodeSymbol (node).getLabel ();
272
+ throw std::runtime_error (ss.str ());
273
+ }
274
+ });
262
275
}
263
276
264
277
for (const auto & edge : record.at (" edges" )) {
265
278
read_edge_from_json (
266
279
edge, [graph](NodeId source, NodeId target, EdgeAttributes::Ptr&& attrs) {
267
- graph->insertEdge (source, target, std::move (attrs));
280
+ if (!graph->insertEdge (source, target, std::move (attrs))) {
281
+ std::stringstream ss;
282
+ ss << " failed to add " << NodeSymbol (source).getLabel () << " → "
283
+ << NodeSymbol (target).getLabel ();
284
+ throw std::runtime_error (ss.str ());
285
+ }
268
286
});
269
287
}
270
288
0 commit comments