Menu

Using api to create meta node

Help
2023-12-08
2023-12-13
  • Perry Kloet

    Perry Kloet - 2023-12-08

    Hello,

    I am exploring the use of the Tulip api in c++ for visualizing some hierachical data, and I am trying to generate a meta-node using the api. However, looking at the documentation it is not clear how the createMetaNode function is supposed to work.

    The example below generates an error that a meta-node cannot be created in the root of the graph.

    #include <iostream>
    #include <tulip/TlpTools.h>
    #include <tulip/Graph.h>
    
    using namespace std;
    using namespace tlp;
    
    int main() {
      initTulipLib();
    
      Graph *graph = newGraph();
      Graph *subGraph = graph->addSubGraph();
      node n1 = subGraph->addNode();
      node n2 = subGraph->addNode();
      graph->addEdge(n1,n2);
    
      graph->createMetaNode(subGraph);
    
      saveGraph(graph, "tutorial004.tlp");
      delete graph;
    }
    

    Replacing the body of the main function with the following creates an empty metanode:

      Graph *graph = newGraph();
      Graph *subGraph1 = graph->addSubGraph();
      Graph *subGraph2 = graph->addSubGraph();
      node n1 = subGraph1->addNode();
      node n2 = subGraph1->addNode();
      graph->addEdge(n1,n2);
      subGraph1->createMetaNode(subGraph2);
    

    I feel like I'm misunderstanding something about how this function works. Can someone give me a minimal working example that generates a simple structure containing a metanode?

     
  • Bruno Pinaud

    Bruno Pinaud - 2023-12-08

    Dear Perry,
    Metanodes cannot be created on the root graph. You should create another subgraph level and create the metanode on the subgraph. The root graph cannot be used anymore for visualization (it contains the metanodes and the nodes and edges which are inside the metanodes). The following code should work (not tested) :
    Graph graph = newGraph();
    sub = graph->addSubGraph();
    Graph
    subGraph = sub->addSubGraph();
    node n1 = subGraph->addNode();
    node n2 = subGraph->addNode();
    sub->addEdge(n1,n2);

    sub->createMetaNode(subGraph);

     
  • Perry Kloet

    Perry Kloet - 2023-12-11

    Thank you for your reply.

    Your code is quite similar to the code I gave in the second snippet, and has the same problem: the created metanode is empty.
    I also tried this:
    ~~~
    Graph graph = newGraph();
    Graph
    sub = graph->addSubGraph();
    Graph* subGraph = sub->addSubGraph();
    sub->createMetaNode(subGraph);
    node n1 = subGraph->addNode();
    node n2 = subGraph->addNode();
    sub->addEdge(n1,n2);
    ~~~
    But that results in the nodes n1 and n2 being created twice, once inside the metanode and once outside the metanode (and the addedge function appears to be ignored inside the metanode). Do you happen to have any ideas to fix that?

     
  • Bruno Pinaud

    Bruno Pinaud - 2023-12-11

    This is working (Python, easier for testing) and tested:
    n1 = graph.addNode();
    n2 = graph.addNode();
    graph.addEdge(n1,n2);
    g = graph.addCloneSubGraph("g");
    meta = graph.addCloneSubGraph("meta");

    sub.createMetaNode(meta);
    
    
    - metanodes cannot be created on the root graph
    - subgraph g contains the resulting graph after the creation of the metanode. The content of the metanode should be inside it before the creation of the metanode
    - subgraph meta is the content of the metanodes.
    
    hope this helps
    
     
  • Perry Kloet

    Perry Kloet - 2023-12-13

    I think I might not have made clear what I want. The above snippit works (assuming you ment g.createMetaNode instead of sub.createMetaNode), but when using saveGraph(graph, "test.tlp"), it will render the nodes n1 and n2 twice. Once inside the generated metanode and once outside the metanode. I would like the nodes to be only visible inside the metanode.

    Is this possible or am I misunderstanding what a metanode is supposed to do?

     
  • Melançon Guy

    Melançon Guy - 2023-12-13

    Hi Perry, I followed the discussion you are having with Bruno, allow me to jump in. If I understand well, you are annoyed by the fact that the top level graph contains both the metanode you created and the nodes it contains, and would like to only have the metanode, the contained node being accessible by other means (double clicking the metanode in the GUI for instance).

    This however is not possible. The highest level graph in the hierarchy will necessarily contain the collection of all nodes that have been created. That is what this graph shoudl do, in a sense. One way to deal with the situation is to create subgraphs, one that would contain the original low level nodes, and another that would only contain your metanode(s). You should see the higher level graph as a convenience holding all created entities (nodes and edges) populating whatever subgraphs in the hierarchy.

    Hope this helps
    Guy

     

Log in to post a comment.