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