Example 3D Spring Embedding
#include <LEDA/graph/graph.h> #include <LEDA/graph/graph_alg.h> #include <LEDA/graphics/window.h> #include <LEDA/graphics/d3_window.h> using namespace leda; int main() { graph G; d3_grid_graph(G,3); node_array< double> xpos(G,0), ypos(G,0), zpos(G,0); double xmin=-180, xmax=180, ymin=-180, ymax=180, zmin=-180, zmax=360; int lb=static_cast<int>(xmin); int ub=static_cast<int>(xmax); random_source S(lb,ub);node v; int x; forall_nodes(v,G) {S >> x;xpos[v]=x;} lb=static_cast<int>(ymin); ub=static_cast<int>(ymax); S.set_range(lb,ub); int y; forall_nodes(v,G) {S >> y;ypos[v]=y;} lb=static_cast<int>(zmin); ub=static_cast<int>(zmax); S.set_range(lb,ub); int z; forall_nodes(v,G) {S >> z;zpos[v]=z;} D3_SPRING_EMBEDDING (G,xpos,ypos,zpos,xmin,xmax,ymin,ymax,zmin,zmax); int width=500, height=500; window W(width,height,"D3 Window"); W.display(); W.init(xmin,xmax,ymin); node_array<vector> pos(G); forall_nodes(v,G) {pos[v] = vector(xpos[v],ypos[v],zpos[v]);} d3_window d3_win(W,G,pos); d3_win.set_draw_graph(true); d3_win.set_speed(16); d3_win.set_message ("\\bf\\blue left: \\black zoom up ~~~~~\ \\bf\\blue middle:\\black zoom down ~~~~~\ \\bf\\blue right: \\black exit"); d3_win.set_node_color(red); d3_win.draw(); int but = 0; while (but != MOUSE_BUTTON(3)) but = d3_win.move(); return 0; } |
See also:Manual Entries: Manual Page Graph Drawing Algorithms |