Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Graph Queries

yggdrasil has support for common graph queries.

Node by id

Starting with the basics, besides label matching, a node in yggdrasil can be retrieved via its id.

#![allow(unused)]
fn main() {
    // Here we first retrieve the root node by matching for its features, and then use its id to
    // retrieve the same node using its id.
    let root_node_id = ygg
        .layer(3)?
        .nodes_matching(&[&Feature::new("name", "root")])[0]
        .id;
}

For immutable access:

#![allow(unused)]
fn main() {
    let root_node = ygg.node(root_node_id)?;
    assert_eq!(root_node.features, vec![Feature::new("name", "root")]);
}

And for mutable access:

#![allow(unused)]
fn main() {
   let mut root_node = ygg.node_mut(root_node_id)?;
   root_node.features.push(Feature::new("is_root", "true"));
}

Layer by id

As shown many times throughout this demo, a layer can be retrieved by its id

#![allow(unused)]
fn main() {
    let root_layer = ygg.layer(3)?;
    assert_eq!(root_layer.id, ygg.layer_of(root_node_id));
}

All Nodes

Using the retrieved layer, one can iterate over all nodes in the layer

#![allow(unused)]
fn main() {
    let layer = ygg.layer(0)?
    for node in layer.all_nodes(){
        println!("Node: {:?}",node.id)
    }
}

Sub Graph

yggdrasil allows you to get a sub graph of the scene, given a reference root node. This is especially useful when dealing with agents with limited computational resources that might not have a need for the entire scene and just a sub set of the scene would be enough for them.

#![allow(unused)]
fn main() {
    // Subgraph retrieval: retrieve the subtree under the "car" node. This query would return a new
    // scene graph containing only the nodes in the subtree under the "car" node, along with the
    // edges between those nodes.
    let car_node_id = ygg
        .layer(1)?
        .nodes_matching(&[&Feature::new("type", "car")])[0]
        .id;

    let car_subgraph = ygg.subgraph(car_node_id)?;

    // We expect the subgraph to contain the "car" node and its 10 point cloud nodes, and no other
    // nodes.
    assert_eq!(car_subgraph.layer(0)?.all_nodes().len(), 10);
    assert_eq!(car_subgraph.layer(1)?.all_nodes().len(), 1);
    assert_eq!(car_subgraph.layer(2)?.all_nodes().len(), 0);
    assert_eq!(car_subgraph.layer(3)?.all_nodes().len(), 0);
}

Merge

Updates in yggdrasil can be in the form of sub graph merge requests, that is, merging a newer version of a sub graph of the original scene graph into the scene graph. This is useful in scenarios where a global scene graph is maintained centrally, and agents can send their local updates to it.

yggdrasil will do the following during the merge:

  1. Nodes with the same ID will be merged, meaning the node in the original scene graph gets updated.
  2. New nodes in the subgraph will be added to the original scene graph.
  • Node deletion is not supported in this operation.
  1. Edges from the original scene graph from src to dst where both src and dst are present in the subgraph but the edge itself is not, are removed from the scene graph.
  2. New edges in the subgraph will be added to the original scene graph.
#![allow(unused)]
fn main() {
    ygg.merge(car_subgraph)?;
}