demo/graph_to_eps_demo.cc
changeset 207 574b963d0275
parent 132 50ff949140fa
child 209 765619b7cbb2
     1.1 --- a/demo/graph_to_eps_demo.cc	Sat Jul 12 09:45:11 2008 +0100
     1.2 +++ b/demo/graph_to_eps_demo.cc	Sun Jul 13 16:35:05 2008 +0100
     1.3 @@ -18,23 +18,22 @@
     1.4  
     1.5  /// \ingroup demos
     1.6  /// \file
     1.7 -/// \brief Demo of the graph grawing function \ref graphToEps()
     1.8 +/// \brief Demo of the graph drawing function \ref graphToEps()
     1.9  ///
    1.10  /// This demo program shows examples how to  use the function \ref
    1.11  /// graphToEps(). It takes no input but simply creates  six
    1.12  /// <tt>.eps</tt> files demonstrating the capability of \ref
    1.13 -/// graphToEps(), and showing how to draw directed/graphs,
    1.14 +/// graphToEps(), and showing how to draw directed graphs,
    1.15  /// how to handle parallel egdes, how to change the properties (like
    1.16  /// color, shape, size, title etc.) of nodes and arcs individually
    1.17  /// using appropriate \ref maps-page "graph maps".
    1.18  ///
    1.19  /// \include graph_to_eps_demo.cc
    1.20  
    1.21 -#include <lemon/math.h>
    1.22 -
    1.23 -#include<lemon/graph_to_eps.h>
    1.24  #include<lemon/list_graph.h>
    1.25  #include<lemon/graph_utils.h>
    1.26 +#include<lemon/graph_to_eps.h>
    1.27 +#include<lemon/math.h>
    1.28  
    1.29  using namespace std;
    1.30  using namespace lemon;
    1.31 @@ -44,6 +43,7 @@
    1.32    Palette palette;
    1.33    Palette paletteW(true);
    1.34  
    1.35 +  // Create a small digraph
    1.36    ListDigraph g;
    1.37    typedef ListDigraph::Node Node;
    1.38    typedef ListDigraph::NodeIt NodeIt;
    1.39 @@ -60,7 +60,7 @@
    1.40    ListDigraph::NodeMap<double> sizes(g);
    1.41    ListDigraph::NodeMap<int> colors(g);
    1.42    ListDigraph::NodeMap<int> shapes(g);
    1.43 -  ListDigraph::ArcMap<int> ecolors(g);
    1.44 +  ListDigraph::ArcMap<int> acolors(g);
    1.45    ListDigraph::ArcMap<int> widths(g);
    1.46    
    1.47    coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    1.48 @@ -69,118 +69,116 @@
    1.49    coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
    1.50    coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    1.51    
    1.52 -  Arc e;
    1.53 +  Arc a;
    1.54  
    1.55 -  e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1;
    1.56 -  e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1;
    1.57 -  e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3;
    1.58 -  e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1;
    1.59 -  e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1;
    1.60 -  e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2;
    1.61 -  e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1;
    1.62 +  a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
    1.63 +  a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
    1.64 +  a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
    1.65 +  a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
    1.66 +  a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
    1.67 +  a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
    1.68 +  a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
    1.69    
    1.70    IdMap<ListDigraph,Node> id(g);
    1.71  
    1.72 -  cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
    1.73 -  graphToEps(g,"graph_to_eps_demo_out_pure.eps").
    1.74 -    //scale(10).
    1.75 +  // Create five .eps files showing the digraph with different options
    1.76 +  cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
    1.77 +  graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
    1.78      coords(coords).
    1.79      title("Sample .eps figure").
    1.80 -    copyright("(C) 2003-2007 LEMON Project").
    1.81 +    copyright("(C) 2003-2008 LEMON Project").
    1.82      run();
    1.83  
    1.84 -  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
    1.85 -  graphToEps(g,"graph_to_eps_demo_out.eps").
    1.86 -    //scale(10).
    1.87 +  cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
    1.88 +  graphToEps(g,"graph_to_eps_demo_out_2.eps").
    1.89      coords(coords).
    1.90      title("Sample .eps figure").
    1.91 -    copyright("(C) 2003-2007 LEMON Project").
    1.92 +    copyright("(C) 2003-2008 LEMON Project").
    1.93      absoluteNodeSizes().absoluteArcWidths().
    1.94      nodeScale(2).nodeSizes(sizes).
    1.95      nodeShapes(shapes).
    1.96      nodeColors(composeMap(palette,colors)).
    1.97 -    arcColors(composeMap(palette,ecolors)).
    1.98 +    arcColors(composeMap(palette,acolors)).
    1.99      arcWidthScale(.4).arcWidths(widths).
   1.100      nodeTexts(id).nodeTextSize(3).
   1.101      run();
   1.102  
   1.103 -
   1.104 -  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
   1.105 -  graphToEps(g,"graph_to_eps_demo_out_arr.eps").
   1.106 -    //scale(10).
   1.107 +  cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
   1.108 +  graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
   1.109      title("Sample .eps figure (with arrowheads)").
   1.110 -    copyright("(C) 2003-2007 LEMON Project").
   1.111 +    copyright("(C) 2003-2008 LEMON Project").
   1.112      absoluteNodeSizes().absoluteArcWidths().
   1.113      nodeColors(composeMap(palette,colors)).
   1.114      coords(coords).
   1.115      nodeScale(2).nodeSizes(sizes).
   1.116      nodeShapes(shapes).
   1.117 -    arcColors(composeMap(palette,ecolors)).
   1.118 +    arcColors(composeMap(palette,acolors)).
   1.119      arcWidthScale(.4).arcWidths(widths).
   1.120      nodeTexts(id).nodeTextSize(3).
   1.121 -    drawArrows().arrowWidth(1).arrowLength(1).
   1.122 +    drawArrows().arrowWidth(2).arrowLength(2).
   1.123      run();
   1.124  
   1.125 -  e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1;
   1.126 -  e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=2;
   1.127 +  a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
   1.128 +  a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2;
   1.129  
   1.130 -  e=g.addArc(n1,n2); ecolors[e]=1; widths[e]=1;
   1.131 -  e=g.addArc(n1,n2); ecolors[e]=2; widths[e]=1;
   1.132 -  e=g.addArc(n1,n2); ecolors[e]=3; widths[e]=1;
   1.133 -  e=g.addArc(n1,n2); ecolors[e]=4; widths[e]=1;
   1.134 -  e=g.addArc(n1,n2); ecolors[e]=5; widths[e]=1;
   1.135 -  e=g.addArc(n1,n2); ecolors[e]=6; widths[e]=1;
   1.136 -  e=g.addArc(n1,n2); ecolors[e]=7; widths[e]=1;
   1.137 +  a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
   1.138 +  a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
   1.139 +  a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
   1.140 +  a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
   1.141 +  a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
   1.142 +  a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
   1.143 +  a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
   1.144  
   1.145    cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
   1.146    graphToEps(g,"graph_to_eps_demo_out_par.eps").
   1.147      //scale(10).
   1.148      title("Sample .eps figure (parallel arcs)").
   1.149 -    copyright("(C) 2003-2007 LEMON Project").
   1.150 +    copyright("(C) 2003-2008 LEMON Project").
   1.151      absoluteNodeSizes().absoluteArcWidths().
   1.152      nodeShapes(shapes).
   1.153      coords(coords).
   1.154      nodeScale(2).nodeSizes(sizes).
   1.155      nodeColors(composeMap(palette,colors)).
   1.156 -    arcColors(composeMap(palette,ecolors)).
   1.157 +    arcColors(composeMap(palette,acolors)).
   1.158      arcWidthScale(.4).arcWidths(widths).
   1.159      nodeTexts(id).nodeTextSize(3).
   1.160      enableParallel().parArcDist(1.5).
   1.161      run();
   1.162 -  
   1.163 -  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
   1.164 -  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
   1.165 -    //scale(10).
   1.166 +
   1.167 +  cout << "Create 'graph_to_eps_demo_out_4_par_arr.eps'" << endl;
   1.168 +  graphToEps(g,"graph_to_eps_demo_out_4_par_arr.eps").
   1.169      title("Sample .eps figure (parallel arcs and arrowheads)").
   1.170 -    copyright("(C) 2003-2007 LEMON Project").
   1.171 +    copyright("(C) 2003-2008 LEMON Project").
   1.172      absoluteNodeSizes().absoluteArcWidths().
   1.173      nodeScale(2).nodeSizes(sizes).
   1.174      coords(coords).
   1.175      nodeShapes(shapes).
   1.176      nodeColors(composeMap(palette,colors)).
   1.177 -    arcColors(composeMap(palette,ecolors)).
   1.178 +    arcColors(composeMap(palette,acolors)).
   1.179      arcWidthScale(.3).arcWidths(widths).
   1.180      nodeTexts(id).nodeTextSize(3).
   1.181      enableParallel().parArcDist(1).
   1.182      drawArrows().arrowWidth(1).arrowLength(1).
   1.183      run();
   1.184  
   1.185 -  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
   1.186 -  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
   1.187 +  cout << "Create 'graph_to_eps_demo_out_5_par_arr_a4.eps'" << endl;
   1.188 +  graphToEps(g,"graph_to_eps_demo_out_5_par_arr_a4.eps").
   1.189      title("Sample .eps figure (fits to A4)").
   1.190 -    copyright("(C) 2003-2007 LEMON Project").
   1.191 +    copyright("(C) 2003-2008 LEMON Project").
   1.192 +    scaleToA4().
   1.193      absoluteNodeSizes().absoluteArcWidths().
   1.194      nodeScale(2).nodeSizes(sizes).
   1.195      coords(coords).
   1.196      nodeShapes(shapes).
   1.197      nodeColors(composeMap(palette,colors)).
   1.198 -    arcColors(composeMap(palette,ecolors)).
   1.199 +    arcColors(composeMap(palette,acolors)).
   1.200      arcWidthScale(.3).arcWidths(widths).
   1.201      nodeTexts(id).nodeTextSize(3).
   1.202      enableParallel().parArcDist(1).
   1.203      drawArrows().arrowWidth(1).arrowLength(1).
   1.204      run();
   1.205  
   1.206 +  // Create an .eps file showing the colors of a default Palette
   1.207    ListDigraph h;
   1.208    ListDigraph::NodeMap<int> hcolors(h);
   1.209    ListDigraph::NodeMap<Point> hcoords(h);
   1.210 @@ -188,21 +186,22 @@
   1.211    int cols=int(sqrt(double(palette.size())));
   1.212    for(int i=0;i<int(paletteW.size());i++) {
   1.213      Node n=h.addNode();
   1.214 -    hcoords[n]=Point(i%cols,i/cols);
   1.215 +    hcoords[n]=Point(1+i%cols,1+i/cols);
   1.216      hcolors[n]=i;
   1.217    }
   1.218    
   1.219 -  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
   1.220 -  graphToEps(h,"graph_to_eps_demo_out_colors.eps").
   1.221 -    //scale(60).
   1.222 +  cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl;
   1.223 +  graphToEps(h,"graph_to_eps_demo_out_6_colors.eps").
   1.224 +    scale(60).
   1.225      title("Sample .eps figure (Palette demo)").
   1.226 -    copyright("(C) 2003-2007 LEMON Project").
   1.227 +    copyright("(C) 2003-2008 LEMON Project").
   1.228      coords(hcoords).
   1.229      absoluteNodeSizes().absoluteArcWidths().
   1.230      nodeScale(.45).
   1.231      distantColorNodeTexts().
   1.232 -    //    distantBWNodeTexts().
   1.233      nodeTexts(hcolors).nodeTextSize(.6).
   1.234      nodeColors(composeMap(paletteW,hcolors)).
   1.235      run();
   1.236 +    
   1.237 +  return 0;
   1.238  }