@@ -65,7 +65,8 @@ void declare_config(Update2dPlacesFunctor::Config& config) {
6565 field (config.merge_proposer , " merge_proposer" );
6666}
6767
68- NodeAttributes::Ptr merge2dPlaceAttributes (const DynamicSceneGraph& graph,
68+ NodeAttributes::Ptr merge2dPlaceAttributes (const Update2dPlacesFunctor::Config config,
69+ const DynamicSceneGraph& graph,
6970 const std::vector<NodeId>& nodes) {
7071 if (nodes.empty ()) {
7172 return nullptr ;
@@ -84,12 +85,13 @@ NodeAttributes::Ptr merge2dPlaceAttributes(const DynamicSceneGraph& graph,
8485 utils::mergeIndices (from_attrs.pcl_mesh_connections ,
8586 new_attrs.pcl_mesh_connections );
8687
87- new_attrs.need_finish_merge = true ;
88- new_attrs.need_cleanup_splitting = true ;
8988 new_attrs.has_active_mesh_indices |= from_attrs.has_active_mesh_indices ;
9089 ++iter;
9190 }
9291
92+ addRectInfo (graph.mesh ()->points , config.connection_ellipse_scale_factor , new_attrs);
93+ addBoundaryInfo (graph.mesh ()->points , new_attrs);
94+
9395 return attrs_ptr;
9496}
9597
@@ -110,9 +112,9 @@ UpdateFunctor::Hooks Update2dPlacesFunctor::hooks() const {
110112 return findMerges (graph, info);
111113 };
112114
113- my_hooks.merge = [](const DynamicSceneGraph& graph,
114- const std::vector<NodeId>& nodes) {
115- return merge2dPlaceAttributes (graph, nodes);
115+ my_hooks.merge = [this ](const DynamicSceneGraph& graph,
116+ const std::vector<NodeId>& nodes) {
117+ return merge2dPlaceAttributes (config, graph, nodes);
116118 };
117119
118120 return my_hooks;
@@ -217,6 +219,9 @@ void Update2dPlacesFunctor::updateNode(const spark_dsg::Mesh::Ptr& mesh,
217219
218220bool Update2dPlacesFunctor::shouldMerge (const Place2dNodeAttributes& from_attrs,
219221 const Place2dNodeAttributes& to_attrs) const {
222+ if (to_attrs.is_active ) {
223+ return false ;
224+ }
220225 const auto z_diff = std::abs (from_attrs.position (2 ) - to_attrs.position (2 ));
221226 if (z_diff > config.merge_max_delta_z ) {
222227 return false ;
@@ -250,80 +255,28 @@ void Update2dPlacesFunctor::cleanup(SharedDsgInfo& dsg) const {
250255
251256 // existing node id for each place
252257 std::vector<std::pair<NodeId, Place2d>> nodes_to_update;
253- // node id that new nodes split from (necessary to copy other
254- // place info)
255- std::vector<std::pair<NodeId, std::vector<Place2d>>> nodes_to_add;
256- std::map<std::tuple<size_t , size_t , size_t , size_t >, double > edge_map;
257-
258- if (config.enable_splitting ) {
259- utils::getNecessaryUpdates (*mesh,
260- config.min_points ,
261- config.min_size ,
262- config.connection_ellipse_scale_factor ,
263- place_2ds,
264- nodes_to_update,
265- nodes_to_add);
266- edge_map = utils::buildEdgeMap (nodes_to_add,
267- config.connection_overlap_threshold ,
268- config.connection_max_delta_z );
269- } else {
270- utils::computeAttributeUpdates (
271- *mesh, config.connection_ellipse_scale_factor , place_2ds, nodes_to_update);
272- }
258+
259+ utils::computeAttributeUpdates (
260+ *mesh, config.connection_ellipse_scale_factor , place_2ds, nodes_to_update);
273261
274262 // Update attributes for place nodes that did not need to split after merge
275263 utils::updateExistingNodes (nodes_to_update, graph);
276264
277- if (config.enable_splitting ) {
278- // Insert new nodes that are formed by splitting existing nodes (and delete
279- // previous node)
280- std::map<std::tuple<size_t , size_t >, NodeId> new_id_map;
281- next_node_id_ = utils::insertNewNodes (nodes_to_add,
282- config.connection_overlap_threshold ,
283- config.connection_max_delta_z ,
284- next_node_id_,
285- graph,
286- new_id_map);
287-
288- // Add edges between new nodes
289- utils::addNewNodeEdges (nodes_to_add, edge_map, new_id_map, graph);
290- }
291-
292- std::unordered_map<NodeId, bool > checked_nodes;
265+ std::set<NodeId> checked_nodes;
293266 // Clean up places that are far enough away from the active window
294267 // Far enough means that none of a node's neighbors or the node itself have
295268 // active mesh vertices
296269 for (auto & [node_id, node] : places_layer->nodes ()) {
297270 auto attrs = node->tryAttributes <Place2dNodeAttributes>();
298- if (!attrs) {
299- continue ;
300- }
301-
302- if (!attrs->need_cleanup_splitting || attrs->is_active ) {
271+ if (!attrs || attrs->is_active ) {
303272 continue ;
304273 }
305274
306- bool has_active_neighbor = false ;
275+ checked_nodes. insert (node_id) ;
307276 for (const auto nid : node->siblings ()) {
308277 auto & neighbor_attrs = graph.getNode (nid).attributes <Place2dNodeAttributes>();
309- if (attrs->semantic_label != neighbor_attrs.semantic_label ) {
310- continue ;
311- }
312278
313- if (neighbor_attrs.has_active_mesh_indices ) {
314- has_active_neighbor = true ;
315- break ;
316- }
317- }
318-
319- checked_nodes[node_id] = !has_active_neighbor && !attrs->has_active_mesh_indices ;
320- for (const auto nid : node->siblings ()) {
321- auto & neighbor_attrs = graph.getNode (nid).attributes <Place2dNodeAttributes>();
322-
323- auto search = checked_nodes.find (nid);
324- if (search == checked_nodes.end ()) {
325- checked_nodes.insert ({nid, false });
326- }
279+ checked_nodes.insert (nid);
327280
328281 if (neighbor_attrs.is_active ) {
329282 continue ;
@@ -335,7 +288,7 @@ void Update2dPlacesFunctor::cleanup(SharedDsgInfo& dsg) const {
335288 }
336289 }
337290
338- for (auto & [ node_id, should_finalize] : checked_nodes) {
291+ for (auto & node_id : checked_nodes) {
339292 auto & attrs = graph.getNode (node_id).attributes <Place2dNodeAttributes>();
340293
341294 if (attrs.pcl_mesh_connections .size () == 0 ) {
@@ -349,10 +302,10 @@ void Update2dPlacesFunctor::cleanup(SharedDsgInfo& dsg) const {
349302
350303 std::vector<std::pair<NodeId, NodeId>> edges_to_remove;
351304 std::map<NodeId, NodeId> extra_edges_to_check;
352- for (const auto & [ node_id, finalize] : checked_nodes) {
305+ for (const auto & node_id : checked_nodes) {
353306 auto & attrs1 = graph.getNode (node_id).attributes <Place2dNodeAttributes>();
354307
355- for (const auto & [ neighbor_id, neighbor_finalize] : checked_nodes) {
308+ for (const auto & neighbor_id : checked_nodes) {
356309 const auto & neighbor_node = graph.getNode (neighbor_id);
357310 auto & attrs2 = neighbor_node.attributes <Place2dNodeAttributes>();
358311 EdgeAttributes ea;
@@ -384,10 +337,6 @@ void Update2dPlacesFunctor::cleanup(SharedDsgInfo& dsg) const {
384337 for (auto [source, target] : sibs_edges_to_remove) {
385338 graph.removeEdge (source, target);
386339 }
387-
388- if (finalize) {
389- attrs1.need_cleanup_splitting = false ;
390- }
391340 }
392341}
393342
0 commit comments