demo/graph_to_eps_demo.cc
author kpeter
Fri, 04 Jan 2008 00:47:08 +0000
changeset 2552 5f711e4668f5
parent 2207 75a29ac69c19
child 2553 bfced05fa852
permissions -rw-r--r--
Improved rename script to avoid "undirected digraph".
alpar@1073
     1
/* -*- C++ -*-
alpar@1073
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@2391
     5
 * Copyright (C) 2003-2007
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@1073
     8
 *
alpar@1073
     9
 * Permission to use, modify and distribute this software is granted
alpar@1073
    10
 * provided that this copyright notice appears in all copies. For
alpar@1073
    11
 * precise terms see the accompanying LICENSE file.
alpar@1073
    12
 *
alpar@1073
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1073
    14
 * express or implied, and with no claim as to its suitability for any
alpar@1073
    15
 * purpose.
alpar@1073
    16
 *
alpar@1073
    17
 */
alpar@1073
    18
alpar@1573
    19
/// \ingroup demos
alpar@1573
    20
/// \file
alpar@1573
    21
/// \brief Demo of the graph grawing function \ref graphToEps()
alpar@1573
    22
///
alpar@1573
    23
/// This demo program shows examples how to  use the function \ref
alpar@1573
    24
/// graphToEps(). It takes no input but simply creates  six
alpar@1587
    25
/// <tt>.eps</tt> files demonstrating the capability of \ref
alpar@1587
    26
/// graphToEps(), and showing how to draw directed/undirected graphs,
alpar@1587
    27
/// how to handle parallel egdes, how to change the properties (like
alpar@1587
    28
/// color, shape, size, title etc.) of nodes and edges individually
alpar@1630
    29
/// using appropriate \ref maps-page "graph maps".
alpar@1641
    30
///
alpar@1641
    31
/// \include graph_to_eps_demo.cc
alpar@1073
    32
deba@1417
    33
#include <cmath>
deba@1417
    34
alpar@1573
    35
#include<lemon/graph_to_eps.h>
alpar@1573
    36
#include<lemon/list_graph.h>
deba@1802
    37
#include<lemon/graph_utils.h>
alpar@1073
    38
alpar@1073
    39
using namespace std;
alpar@1073
    40
using namespace lemon;
alpar@1073
    41
alpar@1073
    42
int main()
alpar@1073
    43
{
alpar@2172
    44
  Palette palette;
alpar@2178
    45
  Palette paletteW(true);
alpar@1178
    46
alpar@1073
    47
  ListGraph g;
alpar@1073
    48
  typedef ListGraph::Node Node;
alpar@1073
    49
  typedef ListGraph::NodeIt NodeIt;
alpar@1073
    50
  typedef ListGraph::Edge Edge;
alpar@2207
    51
  typedef dim2::Point<int> Point;
alpar@1073
    52
  
alpar@1073
    53
  Node n1=g.addNode();
alpar@1073
    54
  Node n2=g.addNode();
alpar@1073
    55
  Node n3=g.addNode();
alpar@1073
    56
  Node n4=g.addNode();
alpar@1073
    57
  Node n5=g.addNode();
alpar@1073
    58
alpar@2207
    59
  ListGraph::NodeMap<Point> coords(g);
alpar@1073
    60
  ListGraph::NodeMap<double> sizes(g);
alpar@1073
    61
  ListGraph::NodeMap<int> colors(g);
alpar@1086
    62
  ListGraph::NodeMap<int> shapes(g);
alpar@1073
    63
  ListGraph::EdgeMap<int> ecolors(g);
alpar@1073
    64
  ListGraph::EdgeMap<int> widths(g);
alpar@1073
    65
  
alpar@2207
    66
  coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@2207
    67
  coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@2207
    68
  coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@2207
    69
  coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@2207
    70
  coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@1073
    71
  
alpar@1073
    72
  Edge e;
alpar@1073
    73
alpar@1073
    74
  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
alpar@1073
    75
  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
alpar@1073
    76
  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
alpar@1073
    77
  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
alpar@1073
    78
  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
alpar@1073
    79
  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
alpar@1073
    80
  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
    81
  
alpar@1268
    82
  IdMap<ListGraph,Node> id(g);
alpar@1073
    83
alpar@2178
    84
  cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
alpar@2178
    85
  graphToEps(g,"graph_to_eps_demo_out_pure.eps").
alpar@2178
    86
    //scale(10).
alpar@2178
    87
    coords(coords).
alpar@2178
    88
    title("Sample .eps figure").
alpar@2391
    89
    copyright("(C) 2003-2007 LEMON Project").
alpar@2178
    90
    run();
alpar@2178
    91
alpar@1573
    92
  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
alpar@1930
    93
  graphToEps(g,"graph_to_eps_demo_out.eps").
alpar@1930
    94
    //scale(10).
alpar@1930
    95
    coords(coords).
alpar@1108
    96
    title("Sample .eps figure").
alpar@2391
    97
    copyright("(C) 2003-2007 LEMON Project").
alpar@2178
    98
    absoluteNodeSizes().absoluteEdgeWidths().
alpar@1073
    99
    nodeScale(2).nodeSizes(sizes).
alpar@1086
   100
    nodeShapes(shapes).
alpar@2172
   101
    nodeColors(composeMap(palette,colors)).
alpar@2172
   102
    edgeColors(composeMap(palette,ecolors)).
alpar@1073
   103
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1091
   104
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   105
    run();
alpar@1073
   106
alpar@1573
   107
alpar@1573
   108
  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
alpar@1930
   109
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").
alpar@1930
   110
    //scale(10).
alpar@1108
   111
    title("Sample .eps figure (with arrowheads)").
alpar@2391
   112
    copyright("(C) 2003-2007 LEMON Project").
alpar@2178
   113
    absoluteNodeSizes().absoluteEdgeWidths().
alpar@2172
   114
    nodeColors(composeMap(palette,colors)).
alpar@1091
   115
    coords(coords).
alpar@1073
   116
    nodeScale(2).nodeSizes(sizes).
alpar@1086
   117
    nodeShapes(shapes).
alpar@2172
   118
    edgeColors(composeMap(palette,ecolors)).
alpar@1073
   119
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   120
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   121
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1091
   122
    run();
alpar@1073
   123
alpar@1073
   124
  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
   125
  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
alpar@1073
   126
alpar@1073
   127
  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
alpar@1073
   128
  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
alpar@1073
   129
  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
alpar@1073
   130
  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
alpar@1073
   131
  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
alpar@1073
   132
  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
alpar@1073
   133
  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
alpar@1073
   134
alpar@1573
   135
  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
alpar@1930
   136
  graphToEps(g,"graph_to_eps_demo_out_par.eps").
alpar@1930
   137
    //scale(10).
alpar@1108
   138
    title("Sample .eps figure (parallel edges)").
alpar@2391
   139
    copyright("(C) 2003-2007 LEMON Project").
alpar@2178
   140
    absoluteNodeSizes().absoluteEdgeWidths().
alpar@1091
   141
    nodeShapes(shapes).
alpar@1091
   142
    coords(coords).
alpar@1073
   143
    nodeScale(2).nodeSizes(sizes).
alpar@2172
   144
    nodeColors(composeMap(palette,colors)).
alpar@2172
   145
    edgeColors(composeMap(palette,ecolors)).
alpar@1073
   146
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   147
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   148
    enableParallel().parEdgeDist(1.5).
alpar@1091
   149
    run();
alpar@1091
   150
  
alpar@1573
   151
  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
alpar@1930
   152
  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
alpar@1930
   153
    //scale(10).
alpar@1108
   154
    title("Sample .eps figure (parallel edges and arrowheads)").
alpar@2391
   155
    copyright("(C) 2003-2007 LEMON Project").
alpar@2178
   156
    absoluteNodeSizes().absoluteEdgeWidths().
alpar@1073
   157
    nodeScale(2).nodeSizes(sizes).
alpar@1091
   158
    coords(coords).
alpar@1086
   159
    nodeShapes(shapes).
alpar@2172
   160
    nodeColors(composeMap(palette,colors)).
alpar@2172
   161
    edgeColors(composeMap(palette,ecolors)).
alpar@1073
   162
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1073
   163
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   164
    enableParallel().parEdgeDist(1).
alpar@1091
   165
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   166
    run();
alpar@1103
   167
alpar@1573
   168
  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
alpar@1103
   169
  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
alpar@1108
   170
    title("Sample .eps figure (fits to A4)").
alpar@2391
   171
    copyright("(C) 2003-2007 LEMON Project").
alpar@2178
   172
    absoluteNodeSizes().absoluteEdgeWidths().
alpar@1103
   173
    nodeScale(2).nodeSizes(sizes).
alpar@1103
   174
    coords(coords).
alpar@1103
   175
    nodeShapes(shapes).
alpar@2172
   176
    nodeColors(composeMap(palette,colors)).
alpar@2172
   177
    edgeColors(composeMap(palette,ecolors)).
alpar@1103
   178
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1103
   179
    nodeTexts(id).nodeTextSize(3).
alpar@1103
   180
    enableParallel().parEdgeDist(1).
alpar@1103
   181
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   182
    run();
alpar@1103
   183
alpar@1178
   184
  ListGraph h;
alpar@1178
   185
  ListGraph::NodeMap<int> hcolors(h);
alpar@2207
   186
  ListGraph::NodeMap<Point> hcoords(h);
alpar@1178
   187
  
alpar@2172
   188
  int cols=int(sqrt(double(palette.size())));
alpar@2178
   189
  for(int i=0;i<int(paletteW.size());i++) {
alpar@1178
   190
    Node n=h.addNode();
alpar@2207
   191
    hcoords[n]=Point(i%cols,i/cols);
alpar@1178
   192
    hcolors[n]=i;
alpar@1178
   193
  }
alpar@1178
   194
  
alpar@1573
   195
  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
alpar@1930
   196
  graphToEps(h,"graph_to_eps_demo_out_colors.eps").
alpar@1930
   197
    //scale(60).
alpar@2172
   198
    title("Sample .eps figure (Palette demo)").
alpar@2391
   199
    copyright("(C) 2003-2007 LEMON Project").
alpar@1178
   200
    coords(hcoords).
alpar@2178
   201
    absoluteNodeSizes().absoluteEdgeWidths().
alpar@2178
   202
    nodeScale(45).
alpar@1178
   203
    distantColorNodeTexts().
alpar@1178
   204
    //    distantBWNodeTexts().
alpar@1178
   205
    nodeTexts(hcolors).nodeTextSize(.6).
alpar@2178
   206
    nodeColors(composeMap(paletteW,hcolors)).
alpar@1178
   207
    run();
alpar@1073
   208
}