demo/graph_to_eps_demo.cc
author ladanyi
Tue, 12 Jul 2005 13:36:01 +0000
changeset 1545 e8378402f97e
parent 1417 53c2a0ccc9a4
child 1573 b76a0af36f44
permissions -rw-r--r--
Added the individual png files to EXTRA_DIST instead of the icons directory. This way the .svn directories do not get in the tarball. An alternative solution would be to delete these in a dist-hook target.
alpar@1073
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * demo/graph_to_eps.cc - Part of LEMON, a generic C++ optimization library
alpar@1073
     3
 *
alpar@1164
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     5
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@1073
     6
 *
alpar@1073
     7
 * Permission to use, modify and distribute this software is granted
alpar@1073
     8
 * provided that this copyright notice appears in all copies. For
alpar@1073
     9
 * precise terms see the accompanying LICENSE file.
alpar@1073
    10
 *
alpar@1073
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1073
    12
 * express or implied, and with no claim as to its suitability for any
alpar@1073
    13
 * purpose.
alpar@1073
    14
 *
alpar@1073
    15
 */
alpar@1073
    16
alpar@1073
    17
#include<lemon/graph_to_eps.h>
alpar@1073
    18
#include<lemon/maps.h>
alpar@1073
    19
#include<lemon/list_graph.h>
alpar@1268
    20
#include<lemon/graph_utils.h>
alpar@1073
    21
deba@1417
    22
#include <cmath>
deba@1417
    23
alpar@1073
    24
alpar@1073
    25
using namespace std;
alpar@1073
    26
using namespace lemon;
alpar@1073
    27
alpar@1073
    28
int main()
alpar@1073
    29
{
alpar@1178
    30
  ColorSet colorSet;
alpar@1178
    31
alpar@1073
    32
  ListGraph g;
alpar@1073
    33
  typedef ListGraph::Node Node;
alpar@1073
    34
  typedef ListGraph::NodeIt NodeIt;
alpar@1073
    35
  typedef ListGraph::Edge Edge;
alpar@1073
    36
  typedef xy<int> Xy;
alpar@1073
    37
  
alpar@1073
    38
  Node n1=g.addNode();
alpar@1073
    39
  Node n2=g.addNode();
alpar@1073
    40
  Node n3=g.addNode();
alpar@1073
    41
  Node n4=g.addNode();
alpar@1073
    42
  Node n5=g.addNode();
alpar@1073
    43
alpar@1073
    44
  ListGraph::NodeMap<Xy> coords(g);
alpar@1073
    45
  ListGraph::NodeMap<double> sizes(g);
alpar@1073
    46
  ListGraph::NodeMap<int> colors(g);
alpar@1086
    47
  ListGraph::NodeMap<int> shapes(g);
alpar@1073
    48
  ListGraph::EdgeMap<int> ecolors(g);
alpar@1073
    49
  ListGraph::EdgeMap<int> widths(g);
alpar@1073
    50
  
alpar@1086
    51
  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@1088
    52
  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@1086
    53
  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@1086
    54
  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@1088
    55
  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@1073
    56
  
alpar@1073
    57
  Edge e;
alpar@1073
    58
alpar@1073
    59
  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
alpar@1073
    60
  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
alpar@1073
    61
  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
alpar@1073
    62
  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
alpar@1073
    63
  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
alpar@1073
    64
  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
alpar@1073
    65
  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
    66
  
alpar@1268
    67
  IdMap<ListGraph,Node> id(g);
alpar@1073
    68
alpar@1073
    69
  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
alpar@1108
    70
    title("Sample .eps figure").
alpar@1164
    71
    copyright("(C) 2005 LEMON Project").
alpar@1073
    72
    nodeScale(2).nodeSizes(sizes).
alpar@1086
    73
    nodeShapes(shapes).
alpar@1073
    74
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
    75
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    76
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1091
    77
    nodeTexts(id).nodeTextSize(3).
alpar@1091
    78
    run();
alpar@1073
    79
alpar@1091
    80
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
alpar@1108
    81
    title("Sample .eps figure (with arrowheads)").
alpar@1164
    82
    copyright("(C) 2005 LEMON Project").
alpar@1091
    83
    nodeColors(composeMap(colorSet,colors)).
alpar@1091
    84
    coords(coords).
alpar@1073
    85
    nodeScale(2).nodeSizes(sizes).
alpar@1086
    86
    nodeShapes(shapes).
alpar@1073
    87
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    88
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
    89
    nodeTexts(id).nodeTextSize(3).
alpar@1091
    90
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1091
    91
    run();
alpar@1073
    92
alpar@1073
    93
  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
    94
  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
alpar@1073
    95
alpar@1073
    96
  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
alpar@1073
    97
  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
alpar@1073
    98
  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
alpar@1073
    99
  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
alpar@1073
   100
  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
alpar@1073
   101
  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
alpar@1073
   102
  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
alpar@1073
   103
alpar@1091
   104
  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
alpar@1108
   105
    title("Sample .eps figure (parallel edges)").
alpar@1164
   106
    copyright("(C) 2005 LEMON Project").
alpar@1091
   107
    nodeShapes(shapes).
alpar@1091
   108
    coords(coords).
alpar@1073
   109
    nodeScale(2).nodeSizes(sizes).
alpar@1073
   110
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   111
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   112
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   113
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   114
    enableParallel().parEdgeDist(1.5).
alpar@1091
   115
    run();
alpar@1091
   116
  
alpar@1091
   117
  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
alpar@1108
   118
    title("Sample .eps figure (parallel edges and arrowheads)").
alpar@1164
   119
    copyright("(C) 2005 LEMON Project").
alpar@1073
   120
    nodeScale(2).nodeSizes(sizes).
alpar@1091
   121
    coords(coords).
alpar@1086
   122
    nodeShapes(shapes).
alpar@1073
   123
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   124
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   125
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1073
   126
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   127
    enableParallel().parEdgeDist(1).
alpar@1091
   128
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   129
    run();
alpar@1103
   130
alpar@1103
   131
  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
alpar@1108
   132
    title("Sample .eps figure (fits to A4)").
alpar@1164
   133
    copyright("(C) 2005 LEMON Project").
alpar@1103
   134
    nodeScale(2).nodeSizes(sizes).
alpar@1103
   135
    coords(coords).
alpar@1103
   136
    nodeShapes(shapes).
alpar@1103
   137
    nodeColors(composeMap(colorSet,colors)).
alpar@1103
   138
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1103
   139
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1103
   140
    nodeTexts(id).nodeTextSize(3).
alpar@1103
   141
    enableParallel().parEdgeDist(1).
alpar@1103
   142
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   143
    run();
alpar@1103
   144
alpar@1178
   145
  ListGraph h;
alpar@1178
   146
  ListGraph::NodeMap<int> hcolors(h);
alpar@1178
   147
  ListGraph::NodeMap<Xy> hcoords(h);
alpar@1178
   148
  
alpar@1178
   149
  int cols=int(sqrt(double(colorSet.size())));
alpar@1178
   150
  for(int i=0;i<int(colorSet.size());i++) {
alpar@1178
   151
    Node n=h.addNode();
alpar@1178
   152
    hcoords[n]=Xy(i%cols,i/cols);
alpar@1178
   153
    hcolors[n]=i;
alpar@1178
   154
  }
alpar@1178
   155
  
alpar@1178
   156
  graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
alpar@1178
   157
    title("Sample .eps figure (parallel edges and arrowheads)").
alpar@1178
   158
    copyright("(C) 2005 LEMON Project").
alpar@1178
   159
    coords(hcoords).
alpar@1178
   160
    nodeScale(.45).
alpar@1178
   161
    distantColorNodeTexts().
alpar@1178
   162
    //    distantBWNodeTexts().
alpar@1178
   163
    nodeTexts(hcolors).nodeTextSize(.6).
alpar@1178
   164
    nodeColors(composeMap(colorSet,hcolors)).
alpar@1178
   165
    run();
alpar@1178
   166
alpar@1178
   167
alpar@1073
   168
}