demo/graph_to_eps_demo.cc
changeset 135 6e7aee618f03
parent 129 e99385bca9fe
child 206 4e22275a2b52
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/demo/graph_to_eps_demo.cc	Thu Apr 17 15:54:30 2008 +0100
     1.3 @@ -0,0 +1,208 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2008
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +/// \ingroup demos
    1.23 +/// \file
    1.24 +/// \brief Demo of the graph grawing function \ref graphToEps()
    1.25 +///
    1.26 +/// This demo program shows examples how to  use the function \ref
    1.27 +/// graphToEps(). It takes no input but simply creates  six
    1.28 +/// <tt>.eps</tt> files demonstrating the capability of \ref
    1.29 +/// graphToEps(), and showing how to draw directed/graphs,
    1.30 +/// how to handle parallel egdes, how to change the properties (like
    1.31 +/// color, shape, size, title etc.) of nodes and arcs individually
    1.32 +/// using appropriate \ref maps-page "graph maps".
    1.33 +///
    1.34 +/// \include graph_to_eps_demo.cc
    1.35 +
    1.36 +#include <lemon/math.h>
    1.37 +
    1.38 +#include<lemon/graph_to_eps.h>
    1.39 +#include<lemon/list_graph.h>
    1.40 +#include<lemon/graph_utils.h>
    1.41 +
    1.42 +using namespace std;
    1.43 +using namespace lemon;
    1.44 +
    1.45 +int main()
    1.46 +{
    1.47 +  Palette palette;
    1.48 +  Palette paletteW(true);
    1.49 +
    1.50 +  ListDigraph g;
    1.51 +  typedef ListDigraph::Node Node;
    1.52 +  typedef ListDigraph::NodeIt NodeIt;
    1.53 +  typedef ListDigraph::Arc Arc;
    1.54 +  typedef dim2::Point<int> Point;
    1.55 +  
    1.56 +  Node n1=g.addNode();
    1.57 +  Node n2=g.addNode();
    1.58 +  Node n3=g.addNode();
    1.59 +  Node n4=g.addNode();
    1.60 +  Node n5=g.addNode();
    1.61 +
    1.62 +  ListDigraph::NodeMap<Point> coords(g);
    1.63 +  ListDigraph::NodeMap<double> sizes(g);
    1.64 +  ListDigraph::NodeMap<int> colors(g);
    1.65 +  ListDigraph::NodeMap<int> shapes(g);
    1.66 +  ListDigraph::ArcMap<int> ecolors(g);
    1.67 +  ListDigraph::ArcMap<int> widths(g);
    1.68 +  
    1.69 +  coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    1.70 +  coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
    1.71 +  coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
    1.72 +  coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
    1.73 +  coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    1.74 +  
    1.75 +  Arc e;
    1.76 +
    1.77 +  e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1;
    1.78 +  e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1;
    1.79 +  e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3;
    1.80 +  e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1;
    1.81 +  e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1;
    1.82 +  e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2;
    1.83 +  e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1;
    1.84 +  
    1.85 +  IdMap<ListDigraph,Node> id(g);
    1.86 +
    1.87 +  cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
    1.88 +  graphToEps(g,"graph_to_eps_demo_out_pure.eps").
    1.89 +    //scale(10).
    1.90 +    coords(coords).
    1.91 +    title("Sample .eps figure").
    1.92 +    copyright("(C) 2003-2007 LEMON Project").
    1.93 +    run();
    1.94 +
    1.95 +  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
    1.96 +  graphToEps(g,"graph_to_eps_demo_out.eps").
    1.97 +    //scale(10).
    1.98 +    coords(coords).
    1.99 +    title("Sample .eps figure").
   1.100 +    copyright("(C) 2003-2007 LEMON Project").
   1.101 +    absoluteNodeSizes().absoluteArcWidths().
   1.102 +    nodeScale(2).nodeSizes(sizes).
   1.103 +    nodeShapes(shapes).
   1.104 +    nodeColors(composeMap(palette,colors)).
   1.105 +    arcColors(composeMap(palette,ecolors)).
   1.106 +    arcWidthScale(.4).arcWidths(widths).
   1.107 +    nodeTexts(id).nodeTextSize(3).
   1.108 +    run();
   1.109 +
   1.110 +
   1.111 +  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
   1.112 +  graphToEps(g,"graph_to_eps_demo_out_arr.eps").
   1.113 +    //scale(10).
   1.114 +    title("Sample .eps figure (with arrowheads)").
   1.115 +    copyright("(C) 2003-2007 LEMON Project").
   1.116 +    absoluteNodeSizes().absoluteArcWidths().
   1.117 +    nodeColors(composeMap(palette,colors)).
   1.118 +    coords(coords).
   1.119 +    nodeScale(2).nodeSizes(sizes).
   1.120 +    nodeShapes(shapes).
   1.121 +    arcColors(composeMap(palette,ecolors)).
   1.122 +    arcWidthScale(.4).arcWidths(widths).
   1.123 +    nodeTexts(id).nodeTextSize(3).
   1.124 +    drawArrows().arrowWidth(1).arrowLength(1).
   1.125 +    run();
   1.126 +
   1.127 +  e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1;
   1.128 +  e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=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 +
   1.138 +  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
   1.139 +  graphToEps(g,"graph_to_eps_demo_out_par.eps").
   1.140 +    //scale(10).
   1.141 +    title("Sample .eps figure (parallel arcs)").
   1.142 +    copyright("(C) 2003-2007 LEMON Project").
   1.143 +    absoluteNodeSizes().absoluteArcWidths().
   1.144 +    nodeShapes(shapes).
   1.145 +    coords(coords).
   1.146 +    nodeScale(2).nodeSizes(sizes).
   1.147 +    nodeColors(composeMap(palette,colors)).
   1.148 +    arcColors(composeMap(palette,ecolors)).
   1.149 +    arcWidthScale(.4).arcWidths(widths).
   1.150 +    nodeTexts(id).nodeTextSize(3).
   1.151 +    enableParallel().parArcDist(1.5).
   1.152 +    run();
   1.153 +  
   1.154 +  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
   1.155 +  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
   1.156 +    //scale(10).
   1.157 +    title("Sample .eps figure (parallel arcs and arrowheads)").
   1.158 +    copyright("(C) 2003-2007 LEMON Project").
   1.159 +    absoluteNodeSizes().absoluteArcWidths().
   1.160 +    nodeScale(2).nodeSizes(sizes).
   1.161 +    coords(coords).
   1.162 +    nodeShapes(shapes).
   1.163 +    nodeColors(composeMap(palette,colors)).
   1.164 +    arcColors(composeMap(palette,ecolors)).
   1.165 +    arcWidthScale(.3).arcWidths(widths).
   1.166 +    nodeTexts(id).nodeTextSize(3).
   1.167 +    enableParallel().parArcDist(1).
   1.168 +    drawArrows().arrowWidth(1).arrowLength(1).
   1.169 +    run();
   1.170 +
   1.171 +  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
   1.172 +  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
   1.173 +    title("Sample .eps figure (fits to A4)").
   1.174 +    copyright("(C) 2003-2007 LEMON Project").
   1.175 +    absoluteNodeSizes().absoluteArcWidths().
   1.176 +    nodeScale(2).nodeSizes(sizes).
   1.177 +    coords(coords).
   1.178 +    nodeShapes(shapes).
   1.179 +    nodeColors(composeMap(palette,colors)).
   1.180 +    arcColors(composeMap(palette,ecolors)).
   1.181 +    arcWidthScale(.3).arcWidths(widths).
   1.182 +    nodeTexts(id).nodeTextSize(3).
   1.183 +    enableParallel().parArcDist(1).
   1.184 +    drawArrows().arrowWidth(1).arrowLength(1).
   1.185 +    run();
   1.186 +
   1.187 +  ListDigraph h;
   1.188 +  ListDigraph::NodeMap<int> hcolors(h);
   1.189 +  ListDigraph::NodeMap<Point> hcoords(h);
   1.190 +  
   1.191 +  int cols=int(sqrt(double(palette.size())));
   1.192 +  for(int i=0;i<int(paletteW.size());i++) {
   1.193 +    Node n=h.addNode();
   1.194 +    hcoords[n]=Point(i%cols,i/cols);
   1.195 +    hcolors[n]=i;
   1.196 +  }
   1.197 +  
   1.198 +  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
   1.199 +  graphToEps(h,"graph_to_eps_demo_out_colors.eps").
   1.200 +    //scale(60).
   1.201 +    title("Sample .eps figure (Palette demo)").
   1.202 +    copyright("(C) 2003-2007 LEMON Project").
   1.203 +    coords(hcoords).
   1.204 +    absoluteNodeSizes().absoluteArcWidths().
   1.205 +    nodeScale(.45).
   1.206 +    distantColorNodeTexts().
   1.207 +    //    distantBWNodeTexts().
   1.208 +    nodeTexts(hcolors).nodeTextSize(.6).
   1.209 +    nodeColors(composeMap(paletteW,hcolors)).
   1.210 +    run();
   1.211 +}