demo/graph_to_eps_demo.cc
author Alpar Juttner <alpar@cs.elte.hu>
Tue, 21 Apr 2009 15:18:54 +0100
changeset 658 85cb3aa71cce
parent 313 64f8f7cc6168
child 659 0c8e5c688440
permissions -rw-r--r--
Merge and fix
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@128
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@128
     4
 *
alpar@463
     5
 * Copyright (C) 2003-2009
alpar@128
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@128
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@128
     8
 *
alpar@128
     9
 * Permission to use, modify and distribute this software is granted
alpar@128
    10
 * provided that this copyright notice appears in all copies. For
alpar@128
    11
 * precise terms see the accompanying LICENSE file.
alpar@128
    12
 *
alpar@128
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@128
    14
 * express or implied, and with no claim as to its suitability for any
alpar@128
    15
 * purpose.
alpar@128
    16
 *
alpar@128
    17
 */
alpar@128
    18
alpar@128
    19
/// \ingroup demos
alpar@128
    20
/// \file
kpeter@206
    21
/// \brief Demo of the graph drawing function \ref graphToEps()
alpar@128
    22
///
kpeter@211
    23
/// This demo program shows examples how to use the function \ref
kpeter@211
    24
/// graphToEps(). It takes no input but simply creates seven
alpar@128
    25
/// <tt>.eps</tt> files demonstrating the capability of \ref
kpeter@206
    26
/// graphToEps(), and showing how to draw directed graphs,
alpar@128
    27
/// how to handle parallel egdes, how to change the properties (like
alpar@128
    28
/// color, shape, size, title etc.) of nodes and arcs individually
kpeter@313
    29
/// using appropriate graph maps.
alpar@128
    30
///
alpar@128
    31
/// \include graph_to_eps_demo.cc
alpar@128
    32
alpar@128
    33
#include<lemon/list_graph.h>
kpeter@206
    34
#include<lemon/graph_to_eps.h>
kpeter@206
    35
#include<lemon/math.h>
alpar@128
    36
alpar@128
    37
using namespace std;
alpar@128
    38
using namespace lemon;
alpar@128
    39
alpar@128
    40
int main()
alpar@128
    41
{
alpar@128
    42
  Palette palette;
alpar@129
    43
  Palette paletteW(true);
alpar@128
    44
kpeter@206
    45
  // Create a small digraph
alpar@128
    46
  ListDigraph g;
alpar@128
    47
  typedef ListDigraph::Node Node;
alpar@128
    48
  typedef ListDigraph::NodeIt NodeIt;
alpar@128
    49
  typedef ListDigraph::Arc Arc;
alpar@128
    50
  typedef dim2::Point<int> Point;
alpar@209
    51
alpar@128
    52
  Node n1=g.addNode();
alpar@128
    53
  Node n2=g.addNode();
alpar@128
    54
  Node n3=g.addNode();
alpar@128
    55
  Node n4=g.addNode();
alpar@128
    56
  Node n5=g.addNode();
alpar@128
    57
alpar@128
    58
  ListDigraph::NodeMap<Point> coords(g);
alpar@128
    59
  ListDigraph::NodeMap<double> sizes(g);
alpar@128
    60
  ListDigraph::NodeMap<int> colors(g);
alpar@128
    61
  ListDigraph::NodeMap<int> shapes(g);
kpeter@206
    62
  ListDigraph::ArcMap<int> acolors(g);
alpar@128
    63
  ListDigraph::ArcMap<int> widths(g);
alpar@209
    64
alpar@128
    65
  coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@128
    66
  coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@128
    67
  coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@128
    68
  coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@128
    69
  coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@209
    70
kpeter@206
    71
  Arc a;
alpar@128
    72
kpeter@206
    73
  a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
kpeter@206
    74
  a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
kpeter@206
    75
  a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
kpeter@206
    76
  a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
kpeter@206
    77
  a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
kpeter@206
    78
  a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
kpeter@206
    79
  a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
alpar@209
    80
alpar@128
    81
  IdMap<ListDigraph,Node> id(g);
alpar@128
    82
kpeter@211
    83
  // Create .eps files showing the digraph with different options
kpeter@206
    84
  cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
kpeter@206
    85
  graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
alpar@128
    86
    coords(coords).
alpar@128
    87
    title("Sample .eps figure").
alpar@463
    88
    copyright("(C) 2003-2009 LEMON Project").
alpar@128
    89
    run();
alpar@128
    90
kpeter@206
    91
  cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
kpeter@206
    92
  graphToEps(g,"graph_to_eps_demo_out_2.eps").
alpar@128
    93
    coords(coords).
alpar@128
    94
    title("Sample .eps figure").
alpar@463
    95
    copyright("(C) 2003-2009 LEMON Project").
alpar@128
    96
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
    97
    nodeScale(2).nodeSizes(sizes).
alpar@128
    98
    nodeShapes(shapes).
alpar@128
    99
    nodeColors(composeMap(palette,colors)).
kpeter@206
   100
    arcColors(composeMap(palette,acolors)).
alpar@128
   101
    arcWidthScale(.4).arcWidths(widths).
alpar@128
   102
    nodeTexts(id).nodeTextSize(3).
alpar@128
   103
    run();
alpar@128
   104
kpeter@206
   105
  cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
kpeter@206
   106
  graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
alpar@128
   107
    title("Sample .eps figure (with arrowheads)").
alpar@463
   108
    copyright("(C) 2003-2009 LEMON Project").
alpar@128
   109
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
   110
    nodeColors(composeMap(palette,colors)).
alpar@128
   111
    coords(coords).
alpar@128
   112
    nodeScale(2).nodeSizes(sizes).
alpar@128
   113
    nodeShapes(shapes).
kpeter@206
   114
    arcColors(composeMap(palette,acolors)).
alpar@128
   115
    arcWidthScale(.4).arcWidths(widths).
alpar@128
   116
    nodeTexts(id).nodeTextSize(3).
kpeter@206
   117
    drawArrows().arrowWidth(2).arrowLength(2).
alpar@128
   118
    run();
alpar@128
   119
kpeter@211
   120
  // Add more arcs to the digraph
kpeter@206
   121
  a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
kpeter@206
   122
  a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2;
alpar@128
   123
kpeter@206
   124
  a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
kpeter@206
   125
  a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
kpeter@206
   126
  a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
kpeter@206
   127
  a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
kpeter@206
   128
  a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
kpeter@206
   129
  a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
kpeter@206
   130
  a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
alpar@128
   131
kpeter@211
   132
  cout << "Create 'graph_to_eps_demo_out_4_par.eps'" << endl;
kpeter@211
   133
  graphToEps(g,"graph_to_eps_demo_out_4_par.eps").
alpar@128
   134
    title("Sample .eps figure (parallel arcs)").
alpar@463
   135
    copyright("(C) 2003-2009 LEMON Project").
alpar@128
   136
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
   137
    nodeShapes(shapes).
alpar@128
   138
    coords(coords).
alpar@128
   139
    nodeScale(2).nodeSizes(sizes).
alpar@128
   140
    nodeColors(composeMap(palette,colors)).
kpeter@206
   141
    arcColors(composeMap(palette,acolors)).
alpar@128
   142
    arcWidthScale(.4).arcWidths(widths).
alpar@128
   143
    nodeTexts(id).nodeTextSize(3).
alpar@128
   144
    enableParallel().parArcDist(1.5).
alpar@128
   145
    run();
kpeter@206
   146
kpeter@211
   147
  cout << "Create 'graph_to_eps_demo_out_5_par_arr.eps'" << endl;
kpeter@211
   148
  graphToEps(g,"graph_to_eps_demo_out_5_par_arr.eps").
alpar@128
   149
    title("Sample .eps figure (parallel arcs and arrowheads)").
alpar@463
   150
    copyright("(C) 2003-2009 LEMON Project").
alpar@128
   151
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
   152
    nodeScale(2).nodeSizes(sizes).
alpar@128
   153
    coords(coords).
alpar@128
   154
    nodeShapes(shapes).
alpar@128
   155
    nodeColors(composeMap(palette,colors)).
kpeter@206
   156
    arcColors(composeMap(palette,acolors)).
alpar@128
   157
    arcWidthScale(.3).arcWidths(widths).
alpar@128
   158
    nodeTexts(id).nodeTextSize(3).
alpar@128
   159
    enableParallel().parArcDist(1).
alpar@128
   160
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@128
   161
    run();
alpar@128
   162
kpeter@211
   163
  cout << "Create 'graph_to_eps_demo_out_6_par_arr_a4.eps'" << endl;
kpeter@211
   164
  graphToEps(g,"graph_to_eps_demo_out_6_par_arr_a4.eps").
alpar@128
   165
    title("Sample .eps figure (fits to A4)").
alpar@463
   166
    copyright("(C) 2003-2009 LEMON Project").
kpeter@206
   167
    scaleToA4().
alpar@128
   168
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
   169
    nodeScale(2).nodeSizes(sizes).
alpar@128
   170
    coords(coords).
alpar@128
   171
    nodeShapes(shapes).
alpar@128
   172
    nodeColors(composeMap(palette,colors)).
kpeter@206
   173
    arcColors(composeMap(palette,acolors)).
alpar@128
   174
    arcWidthScale(.3).arcWidths(widths).
alpar@128
   175
    nodeTexts(id).nodeTextSize(3).
alpar@128
   176
    enableParallel().parArcDist(1).
alpar@128
   177
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@128
   178
    run();
alpar@128
   179
kpeter@206
   180
  // Create an .eps file showing the colors of a default Palette
alpar@128
   181
  ListDigraph h;
alpar@128
   182
  ListDigraph::NodeMap<int> hcolors(h);
alpar@128
   183
  ListDigraph::NodeMap<Point> hcoords(h);
alpar@209
   184
alpar@128
   185
  int cols=int(sqrt(double(palette.size())));
alpar@128
   186
  for(int i=0;i<int(paletteW.size());i++) {
alpar@128
   187
    Node n=h.addNode();
kpeter@206
   188
    hcoords[n]=Point(1+i%cols,1+i/cols);
alpar@128
   189
    hcolors[n]=i;
alpar@128
   190
  }
alpar@209
   191
kpeter@211
   192
  cout << "Create 'graph_to_eps_demo_out_7_colors.eps'" << endl;
kpeter@211
   193
  graphToEps(h,"graph_to_eps_demo_out_7_colors.eps").
kpeter@206
   194
    scale(60).
alpar@128
   195
    title("Sample .eps figure (Palette demo)").
alpar@463
   196
    copyright("(C) 2003-2009 LEMON Project").
alpar@128
   197
    coords(hcoords).
alpar@128
   198
    absoluteNodeSizes().absoluteArcWidths().
alpar@132
   199
    nodeScale(.45).
alpar@128
   200
    distantColorNodeTexts().
alpar@128
   201
    nodeTexts(hcolors).nodeTextSize(.6).
alpar@128
   202
    nodeColors(composeMap(paletteW,hcolors)).
alpar@128
   203
    run();
alpar@209
   204
kpeter@206
   205
  return 0;
alpar@128
   206
}