COIN-OR::LEMON - Graph Library

Changeset 206:4e22275a2b52 in lemon for demo


Ignore:
Timestamp:
07/13/08 17:34:27 (16 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Improvements related to graphToEps()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • demo/graph_to_eps_demo.cc

    r132 r206  
    1919/// \ingroup demos
    2020/// \file
    21 /// \brief Demo of the graph grawing function \ref graphToEps()
     21/// \brief Demo of the graph drawing function \ref graphToEps()
    2222///
    2323/// This demo program shows examples how to  use the function \ref
    2424/// graphToEps(). It takes no input but simply creates  six
    2525/// <tt>.eps</tt> files demonstrating the capability of \ref
    26 /// graphToEps(), and showing how to draw directed/graphs,
     26/// graphToEps(), and showing how to draw directed graphs,
    2727/// how to handle parallel egdes, how to change the properties (like
    2828/// color, shape, size, title etc.) of nodes and arcs individually
     
    3131/// \include graph_to_eps_demo.cc
    3232
    33 #include <lemon/math.h>
    34 
    35 #include<lemon/graph_to_eps.h>
    3633#include<lemon/list_graph.h>
    3734#include<lemon/graph_utils.h>
     35#include<lemon/graph_to_eps.h>
     36#include<lemon/math.h>
    3837
    3938using namespace std;
     
    4544  Palette paletteW(true);
    4645
     46  // Create a small digraph
    4747  ListDigraph g;
    4848  typedef ListDigraph::Node Node;
     
    6161  ListDigraph::NodeMap<int> colors(g);
    6262  ListDigraph::NodeMap<int> shapes(g);
    63   ListDigraph::ArcMap<int> ecolors(g);
     63  ListDigraph::ArcMap<int> acolors(g);
    6464  ListDigraph::ArcMap<int> widths(g);
    6565 
     
    7070  coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    7171 
    72   Arc e;
    73 
    74   e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1;
    75   e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1;
    76   e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3;
    77   e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1;
    78   e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1;
    79   e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2;
    80   e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1;
     72  Arc a;
     73
     74  a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
     75  a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
     76  a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
     77  a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
     78  a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
     79  a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
     80  a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
    8181 
    8282  IdMap<ListDigraph,Node> id(g);
    8383
    84   cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
    85   graphToEps(g,"graph_to_eps_demo_out_pure.eps").
    86     //scale(10).
     84  // Create five .eps files showing the digraph with different options
     85  cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
     86  graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
    8787    coords(coords).
    8888    title("Sample .eps figure").
    89     copyright("(C) 2003-2007 LEMON Project").
    90     run();
    91 
    92   cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
    93   graphToEps(g,"graph_to_eps_demo_out.eps").
    94     //scale(10).
     89    copyright("(C) 2003-2008 LEMON Project").
     90    run();
     91
     92  cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
     93  graphToEps(g,"graph_to_eps_demo_out_2.eps").
    9594    coords(coords).
    9695    title("Sample .eps figure").
    97     copyright("(C) 2003-2007 LEMON Project").
    98     absoluteNodeSizes().absoluteArcWidths().
    99     nodeScale(2).nodeSizes(sizes).
    100     nodeShapes(shapes).
    101     nodeColors(composeMap(palette,colors)).
    102     arcColors(composeMap(palette,ecolors)).
     96    copyright("(C) 2003-2008 LEMON Project").
     97    absoluteNodeSizes().absoluteArcWidths().
     98    nodeScale(2).nodeSizes(sizes).
     99    nodeShapes(shapes).
     100    nodeColors(composeMap(palette,colors)).
     101    arcColors(composeMap(palette,acolors)).
    103102    arcWidthScale(.4).arcWidths(widths).
    104103    nodeTexts(id).nodeTextSize(3).
    105104    run();
    106105
    107 
    108   cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
    109   graphToEps(g,"graph_to_eps_demo_out_arr.eps").
    110     //scale(10).
     106  cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
     107  graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
    111108    title("Sample .eps figure (with arrowheads)").
    112     copyright("(C) 2003-2007 LEMON Project").
    113     absoluteNodeSizes().absoluteArcWidths().
    114     nodeColors(composeMap(palette,colors)).
    115     coords(coords).
    116     nodeScale(2).nodeSizes(sizes).
    117     nodeShapes(shapes).
    118     arcColors(composeMap(palette,ecolors)).
     109    copyright("(C) 2003-2008 LEMON Project").
     110    absoluteNodeSizes().absoluteArcWidths().
     111    nodeColors(composeMap(palette,colors)).
     112    coords(coords).
     113    nodeScale(2).nodeSizes(sizes).
     114    nodeShapes(shapes).
     115    arcColors(composeMap(palette,acolors)).
    119116    arcWidthScale(.4).arcWidths(widths).
    120117    nodeTexts(id).nodeTextSize(3).
    121     drawArrows().arrowWidth(1).arrowLength(1).
    122     run();
    123 
    124   e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1;
    125   e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=2;
    126 
    127   e=g.addArc(n1,n2); ecolors[e]=1; widths[e]=1;
    128   e=g.addArc(n1,n2); ecolors[e]=2; widths[e]=1;
    129   e=g.addArc(n1,n2); ecolors[e]=3; widths[e]=1;
    130   e=g.addArc(n1,n2); ecolors[e]=4; widths[e]=1;
    131   e=g.addArc(n1,n2); ecolors[e]=5; widths[e]=1;
    132   e=g.addArc(n1,n2); ecolors[e]=6; widths[e]=1;
    133   e=g.addArc(n1,n2); ecolors[e]=7; widths[e]=1;
     118    drawArrows().arrowWidth(2).arrowLength(2).
     119    run();
     120
     121  a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
     122  a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2;
     123
     124  a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
     125  a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
     126  a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
     127  a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
     128  a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
     129  a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
     130  a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
    134131
    135132  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
     
    137134    //scale(10).
    138135    title("Sample .eps figure (parallel arcs)").
    139     copyright("(C) 2003-2007 LEMON Project").
    140     absoluteNodeSizes().absoluteArcWidths().
    141     nodeShapes(shapes).
    142     coords(coords).
    143     nodeScale(2).nodeSizes(sizes).
    144     nodeColors(composeMap(palette,colors)).
    145     arcColors(composeMap(palette,ecolors)).
     136    copyright("(C) 2003-2008 LEMON Project").
     137    absoluteNodeSizes().absoluteArcWidths().
     138    nodeShapes(shapes).
     139    coords(coords).
     140    nodeScale(2).nodeSizes(sizes).
     141    nodeColors(composeMap(palette,colors)).
     142    arcColors(composeMap(palette,acolors)).
    146143    arcWidthScale(.4).arcWidths(widths).
    147144    nodeTexts(id).nodeTextSize(3).
    148145    enableParallel().parArcDist(1.5).
    149146    run();
    150  
    151   cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
    152   graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
    153     //scale(10).
     147
     148  cout << "Create 'graph_to_eps_demo_out_4_par_arr.eps'" << endl;
     149  graphToEps(g,"graph_to_eps_demo_out_4_par_arr.eps").
    154150    title("Sample .eps figure (parallel arcs and arrowheads)").
    155     copyright("(C) 2003-2007 LEMON Project").
    156     absoluteNodeSizes().absoluteArcWidths().
    157     nodeScale(2).nodeSizes(sizes).
    158     coords(coords).
    159     nodeShapes(shapes).
    160     nodeColors(composeMap(palette,colors)).
    161     arcColors(composeMap(palette,ecolors)).
     151    copyright("(C) 2003-2008 LEMON Project").
     152    absoluteNodeSizes().absoluteArcWidths().
     153    nodeScale(2).nodeSizes(sizes).
     154    coords(coords).
     155    nodeShapes(shapes).
     156    nodeColors(composeMap(palette,colors)).
     157    arcColors(composeMap(palette,acolors)).
    162158    arcWidthScale(.3).arcWidths(widths).
    163159    nodeTexts(id).nodeTextSize(3).
     
    166162    run();
    167163
    168   cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
    169   graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
     164  cout << "Create 'graph_to_eps_demo_out_5_par_arr_a4.eps'" << endl;
     165  graphToEps(g,"graph_to_eps_demo_out_5_par_arr_a4.eps").
    170166    title("Sample .eps figure (fits to A4)").
    171     copyright("(C) 2003-2007 LEMON Project").
    172     absoluteNodeSizes().absoluteArcWidths().
    173     nodeScale(2).nodeSizes(sizes).
    174     coords(coords).
    175     nodeShapes(shapes).
    176     nodeColors(composeMap(palette,colors)).
    177     arcColors(composeMap(palette,ecolors)).
     167    copyright("(C) 2003-2008 LEMON Project").
     168    scaleToA4().
     169    absoluteNodeSizes().absoluteArcWidths().
     170    nodeScale(2).nodeSizes(sizes).
     171    coords(coords).
     172    nodeShapes(shapes).
     173    nodeColors(composeMap(palette,colors)).
     174    arcColors(composeMap(palette,acolors)).
    178175    arcWidthScale(.3).arcWidths(widths).
    179176    nodeTexts(id).nodeTextSize(3).
     
    182179    run();
    183180
     181  // Create an .eps file showing the colors of a default Palette
    184182  ListDigraph h;
    185183  ListDigraph::NodeMap<int> hcolors(h);
     
    189187  for(int i=0;i<int(paletteW.size());i++) {
    190188    Node n=h.addNode();
    191     hcoords[n]=Point(i%cols,i/cols);
     189    hcoords[n]=Point(1+i%cols,1+i/cols);
    192190    hcolors[n]=i;
    193191  }
    194192 
    195   cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
    196   graphToEps(h,"graph_to_eps_demo_out_colors.eps").
    197     //scale(60).
     193  cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl;
     194  graphToEps(h,"graph_to_eps_demo_out_6_colors.eps").
     195    scale(60).
    198196    title("Sample .eps figure (Palette demo)").
    199     copyright("(C) 2003-2007 LEMON Project").
     197    copyright("(C) 2003-2008 LEMON Project").
    200198    coords(hcoords).
    201199    absoluteNodeSizes().absoluteArcWidths().
    202200    nodeScale(.45).
    203201    distantColorNodeTexts().
    204     //    distantBWNodeTexts().
    205202    nodeTexts(hcolors).nodeTextSize(.6).
    206203    nodeColors(composeMap(paletteW,hcolors)).
    207204    run();
     205   
     206  return 0;
    208207}
Note: See TracChangeset for help on using the changeset viewer.