Advertisement
Guest User

Untitled

a guest
Jun 27th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <ogdf/basic/Graph.h>
  3. #include <ogdf/planarlayout/PlanarStraightLayout.h>
  4. #include <ogdf/basic/CombinatorialEmbedding.h>
  5. #include <ogdf/basic/GridLayout.h>
  6.  
  7. int main() {
  8. // Create a graph
  9. ogdf::Graph graph;
  10. auto graphAttributes = ogdf::GraphAttributes(graph);
  11. // Add nodes to the graph
  12. //ogdf::node v0 = graph.newNode();
  13. ogdf::node v1 = graph.newNode();
  14. ogdf::node v2 = graph.newNode();
  15. ogdf::node v3 = graph.newNode();
  16. ogdf::node v4 = graph.newNode();
  17. ogdf::node v5 = graph.newNode();
  18. ogdf::node v6 = graph.newNode();
  19. ogdf::node v7 = graph.newNode();
  20.  
  21. // Add edges to the graph
  22. graph.newEdge(v1,v2);
  23. graph.newEdge(v1,v3);
  24. graph.newEdge(v1,v4);
  25. graph.newEdge(v2,v5);
  26. graph.newEdge(v1,v5);
  27. graph.newEdge(v4,v6);
  28. graph.newEdge(v3,v6);
  29. graph.newEdge(v6,v7);
  30. graph.newEdge(v3,v7);
  31. graph.newEdge(v4,v7);
  32. graph.newEdge(v1,v7);
  33.  
  34. ogdf::PlanarStraightLayout layout;
  35. layout.call(graphAttributes);
  36. ogdf::CombinatorialEmbedding combEmbending = ogdf::CombinatorialEmbedding(graph);
  37. combEmbending.computeFaces();
  38.  
  39. auto elem = combEmbending.faces;
  40. std::vector<std::vector<ogdf::node>> allFaces;
  41. for (auto &x : elem) {
  42. auto first = x->firstAdj();
  43. std::vector <ogdf::node> all;
  44. for (auto smth : x->entries) {
  45. auto y = smth;
  46. all.push_back(y->theNode());
  47. //std::cout << y->isSource() << ' ';
  48. }
  49. allFaces.push_back(all);
  50. }
  51.  
  52. std::cout << "SEE\n";
  53. for (auto i : allFaces) {
  54. for (auto j : i) std::cout << j->index() << " ";
  55. std::cout << '\n';
  56. }
  57. std::cout << '\n';
  58.  
  59. // Output the coordinates of each node
  60. std::vector<std::string> arr;
  61. for (ogdf::node n : graph.nodes) {
  62. ogdf::DPoint pos = graphAttributes.point(n);
  63. std::cout << "Node " << n->index() << " Position: (" << pos.m_x << ", " << pos.m_y << ")" << std::endl;
  64. arr.push_back(std::to_string(pos.m_x) + " " + std::to_string(pos.m_y));
  65. }
  66. for (auto &e: graph.edges) {
  67. auto nodes = e->nodes();
  68. auto point1 = graphAttributes.point(nodes[0]);
  69. auto point2 = graphAttributes.point(nodes[1]);
  70. std::cout << point1.m_x << " " << point1.m_y << " " << point2.m_x << " " << point2.m_y << '\n';
  71. }
  72. for (auto i : arr)
  73. std::cout << i << '\n';
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement