home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / prog / graphics / embeddin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  904 b   |  66 lines

  1. #include <LEDA/graph.h>
  2. #include <LEDA/graph_alg.h>
  3.  
  4. #include <LEDA/window.h>
  5.  
  6. declare2(GRAPH,int,int)
  7.  
  8. main()
  9. {
  10. GRAPH(int,int) G;
  11.  
  12. cout << "Give a planar graph.\n";
  13.  
  14. test_graph(G);
  15.  
  16. if ( ! PLANAR(G) )
  17.  { cout << "Graph is not planar\n";
  18.    exit(1);
  19.   }
  20.  
  21. if (Yes("print planar map ? "))  G.print();
  22.  
  23. if (!Yes("draw ? ")) exit(1);
  24.  
  25. node v,w;
  26.  
  27.  
  28. node_array(int) x(G),y(G);
  29.  
  30. STRAIGHT_LINE_EMBEDDING(G,x,y);
  31.  
  32. int xmax=0;
  33. int ymax=0;
  34. forall_nodes(w,G)  
  35.   { if (x[w]>xmax) xmax= x[w];
  36.     if (y[w]>ymax) ymax= y[w];
  37.    }
  38.  
  39. int maxcoord = Max(xmax,ymax);
  40.  
  41.  
  42. window W;
  43.  
  44. W.init(-5,maxcoord+5,-5);
  45.  
  46. W.set_line_width(2);
  47. W.set_node_width(10);
  48.  
  49. edge e;
  50.  
  51. forall_edges(e,G)  
  52. { v = source(e);
  53.   w = target(e);
  54.   W.draw_edge(x[v],y[v],x[w],y[w],blue);
  55.  }
  56.  
  57. int i = 1;
  58. forall_nodes(v,G) W.draw_text_node(x[v],y[v],form("%d",i++),red);
  59.  
  60. W.read_mouse();
  61.  
  62. forall_nodes(v,G) cout << form("x = %2d    y = %2d\n",x[v],y[v]);
  63.  
  64.  
  65. }
  66.