demo/graph_to_eps_demo.cc
changeset 1435 8e85e6bbefdf
parent 1417 53c2a0ccc9a4
child 1573 b76a0af36f44
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/demo/graph_to_eps_demo.cc	Mon May 23 04:48:14 2005 +0000
     1.3 @@ -0,0 +1,168 @@
     1.4 +/* -*- C++ -*-
     1.5 + * demo/graph_to_eps.cc - Part of LEMON, a generic C++ optimization library
     1.6 + *
     1.7 + * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     1.8 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
     1.9 + *
    1.10 + * Permission to use, modify and distribute this software is granted
    1.11 + * provided that this copyright notice appears in all copies. For
    1.12 + * precise terms see the accompanying LICENSE file.
    1.13 + *
    1.14 + * This software is provided "AS IS" with no warranty of any kind,
    1.15 + * express or implied, and with no claim as to its suitability for any
    1.16 + * purpose.
    1.17 + *
    1.18 + */
    1.19 +
    1.20 +#include<lemon/graph_to_eps.h>
    1.21 +#include<lemon/maps.h>
    1.22 +#include<lemon/list_graph.h>
    1.23 +#include<lemon/graph_utils.h>
    1.24 +
    1.25 +#include <cmath>
    1.26 +
    1.27 +
    1.28 +using namespace std;
    1.29 +using namespace lemon;
    1.30 +
    1.31 +int main()
    1.32 +{
    1.33 +  ColorSet colorSet;
    1.34 +
    1.35 +  ListGraph g;
    1.36 +  typedef ListGraph::Node Node;
    1.37 +  typedef ListGraph::NodeIt NodeIt;
    1.38 +  typedef ListGraph::Edge Edge;
    1.39 +  typedef xy<int> Xy;
    1.40 +  
    1.41 +  Node n1=g.addNode();
    1.42 +  Node n2=g.addNode();
    1.43 +  Node n3=g.addNode();
    1.44 +  Node n4=g.addNode();
    1.45 +  Node n5=g.addNode();
    1.46 +
    1.47 +  ListGraph::NodeMap<Xy> coords(g);
    1.48 +  ListGraph::NodeMap<double> sizes(g);
    1.49 +  ListGraph::NodeMap<int> colors(g);
    1.50 +  ListGraph::NodeMap<int> shapes(g);
    1.51 +  ListGraph::EdgeMap<int> ecolors(g);
    1.52 +  ListGraph::EdgeMap<int> widths(g);
    1.53 +  
    1.54 +  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    1.55 +  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
    1.56 +  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
    1.57 +  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
    1.58 +  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    1.59 +  
    1.60 +  Edge e;
    1.61 +
    1.62 +  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
    1.63 +  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
    1.64 +  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
    1.65 +  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
    1.66 +  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
    1.67 +  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
    1.68 +  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
    1.69 +  
    1.70 +  IdMap<ListGraph,Node> id(g);
    1.71 +
    1.72 +  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
    1.73 +    title("Sample .eps figure").
    1.74 +    copyright("(C) 2005 LEMON Project").
    1.75 +    nodeScale(2).nodeSizes(sizes).
    1.76 +    nodeShapes(shapes).
    1.77 +    nodeColors(composeMap(colorSet,colors)).
    1.78 +    edgeColors(composeMap(colorSet,ecolors)).
    1.79 +    edgeWidthScale(.4).edgeWidths(widths).
    1.80 +    nodeTexts(id).nodeTextSize(3).
    1.81 +    run();
    1.82 +
    1.83 +  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
    1.84 +    title("Sample .eps figure (with arrowheads)").
    1.85 +    copyright("(C) 2005 LEMON Project").
    1.86 +    nodeColors(composeMap(colorSet,colors)).
    1.87 +    coords(coords).
    1.88 +    nodeScale(2).nodeSizes(sizes).
    1.89 +    nodeShapes(shapes).
    1.90 +    edgeColors(composeMap(colorSet,ecolors)).
    1.91 +    edgeWidthScale(.4).edgeWidths(widths).
    1.92 +    nodeTexts(id).nodeTextSize(3).
    1.93 +    drawArrows().arrowWidth(1).arrowLength(1).
    1.94 +    run();
    1.95 +
    1.96 +  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
    1.97 +  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
    1.98 +
    1.99 +  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
   1.100 +  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
   1.101 +  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
   1.102 +  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
   1.103 +  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
   1.104 +  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
   1.105 +  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
   1.106 +
   1.107 +  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
   1.108 +    title("Sample .eps figure (parallel edges)").
   1.109 +    copyright("(C) 2005 LEMON Project").
   1.110 +    nodeShapes(shapes).
   1.111 +    coords(coords).
   1.112 +    nodeScale(2).nodeSizes(sizes).
   1.113 +    nodeColors(composeMap(colorSet,colors)).
   1.114 +    edgeColors(composeMap(colorSet,ecolors)).
   1.115 +    edgeWidthScale(.4).edgeWidths(widths).
   1.116 +    nodeTexts(id).nodeTextSize(3).
   1.117 +    enableParallel().parEdgeDist(1.5).
   1.118 +    run();
   1.119 +  
   1.120 +  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
   1.121 +    title("Sample .eps figure (parallel edges and arrowheads)").
   1.122 +    copyright("(C) 2005 LEMON Project").
   1.123 +    nodeScale(2).nodeSizes(sizes).
   1.124 +    coords(coords).
   1.125 +    nodeShapes(shapes).
   1.126 +    nodeColors(composeMap(colorSet,colors)).
   1.127 +    edgeColors(composeMap(colorSet,ecolors)).
   1.128 +    edgeWidthScale(.3).edgeWidths(widths).
   1.129 +    nodeTexts(id).nodeTextSize(3).
   1.130 +    enableParallel().parEdgeDist(1).
   1.131 +    drawArrows().arrowWidth(1).arrowLength(1).
   1.132 +    run();
   1.133 +
   1.134 +  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
   1.135 +    title("Sample .eps figure (fits to A4)").
   1.136 +    copyright("(C) 2005 LEMON Project").
   1.137 +    nodeScale(2).nodeSizes(sizes).
   1.138 +    coords(coords).
   1.139 +    nodeShapes(shapes).
   1.140 +    nodeColors(composeMap(colorSet,colors)).
   1.141 +    edgeColors(composeMap(colorSet,ecolors)).
   1.142 +    edgeWidthScale(.3).edgeWidths(widths).
   1.143 +    nodeTexts(id).nodeTextSize(3).
   1.144 +    enableParallel().parEdgeDist(1).
   1.145 +    drawArrows().arrowWidth(1).arrowLength(1).
   1.146 +    run();
   1.147 +
   1.148 +  ListGraph h;
   1.149 +  ListGraph::NodeMap<int> hcolors(h);
   1.150 +  ListGraph::NodeMap<Xy> hcoords(h);
   1.151 +  
   1.152 +  int cols=int(sqrt(double(colorSet.size())));
   1.153 +  for(int i=0;i<int(colorSet.size());i++) {
   1.154 +    Node n=h.addNode();
   1.155 +    hcoords[n]=Xy(i%cols,i/cols);
   1.156 +    hcolors[n]=i;
   1.157 +  }
   1.158 +  
   1.159 +  graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
   1.160 +    title("Sample .eps figure (parallel edges and arrowheads)").
   1.161 +    copyright("(C) 2005 LEMON Project").
   1.162 +    coords(hcoords).
   1.163 +    nodeScale(.45).
   1.164 +    distantColorNodeTexts().
   1.165 +    //    distantBWNodeTexts().
   1.166 +    nodeTexts(hcolors).nodeTextSize(.6).
   1.167 +    nodeColors(composeMap(colorSet,hcolors)).
   1.168 +    run();
   1.169 +
   1.170 +
   1.171 +}