demo/graph_to_eps_demo.cc
author Peter Kovacs <kpeter@inf.elte.hu>
Mon, 14 Jul 2008 09:15:23 +0200
changeset 212 1ae84dea7d09
parent 206 4e22275a2b52
child 211 542dd614cbb4
permissions -rw-r--r--
Fix the incorrect tab replacements of unify-sources.sh
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@128
     5
 * Copyright (C) 2003-2008
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
///
alpar@128
    23
/// This demo program shows examples how to  use the function \ref
alpar@128
    24
/// graphToEps(). It takes no input but simply creates  six
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
alpar@128
    29
/// using appropriate \ref maps-page "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>
alpar@128
    34
#include<lemon/graph_utils.h>
kpeter@206
    35
#include<lemon/graph_to_eps.h>
kpeter@206
    36
#include<lemon/math.h>
alpar@128
    37
alpar@128
    38
using namespace std;
alpar@128
    39
using namespace lemon;
alpar@128
    40
alpar@128
    41
int main()
alpar@128
    42
{
alpar@128
    43
  Palette palette;
alpar@129
    44
  Palette paletteW(true);
alpar@128
    45
kpeter@206
    46
  // Create a small digraph
alpar@128
    47
  ListDigraph g;
alpar@128
    48
  typedef ListDigraph::Node Node;
alpar@128
    49
  typedef ListDigraph::NodeIt NodeIt;
alpar@128
    50
  typedef ListDigraph::Arc Arc;
alpar@128
    51
  typedef dim2::Point<int> Point;
alpar@209
    52
alpar@128
    53
  Node n1=g.addNode();
alpar@128
    54
  Node n2=g.addNode();
alpar@128
    55
  Node n3=g.addNode();
alpar@128
    56
  Node n4=g.addNode();
alpar@128
    57
  Node n5=g.addNode();
alpar@128
    58
alpar@128
    59
  ListDigraph::NodeMap<Point> coords(g);
alpar@128
    60
  ListDigraph::NodeMap<double> sizes(g);
alpar@128
    61
  ListDigraph::NodeMap<int> colors(g);
alpar@128
    62
  ListDigraph::NodeMap<int> shapes(g);
kpeter@206
    63
  ListDigraph::ArcMap<int> acolors(g);
alpar@128
    64
  ListDigraph::ArcMap<int> widths(g);
alpar@209
    65
alpar@128
    66
  coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@128
    67
  coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@128
    68
  coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@128
    69
  coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@128
    70
  coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@209
    71
kpeter@206
    72
  Arc a;
alpar@128
    73
kpeter@206
    74
  a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
kpeter@206
    75
  a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
kpeter@206
    76
  a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
kpeter@206
    77
  a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
kpeter@206
    78
  a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
kpeter@206
    79
  a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
kpeter@206
    80
  a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
alpar@209
    81
alpar@128
    82
  IdMap<ListDigraph,Node> id(g);
alpar@128
    83
kpeter@206
    84
  // Create five .eps files showing the digraph with different options
kpeter@206
    85
  cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
kpeter@206
    86
  graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
alpar@128
    87
    coords(coords).
alpar@128
    88
    title("Sample .eps figure").
kpeter@206
    89
    copyright("(C) 2003-2008 LEMON Project").
alpar@128
    90
    run();
alpar@128
    91
kpeter@206
    92
  cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
kpeter@206
    93
  graphToEps(g,"graph_to_eps_demo_out_2.eps").
alpar@128
    94
    coords(coords).
alpar@128
    95
    title("Sample .eps figure").
kpeter@206
    96
    copyright("(C) 2003-2008 LEMON Project").
alpar@128
    97
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
    98
    nodeScale(2).nodeSizes(sizes).
alpar@128
    99
    nodeShapes(shapes).
alpar@128
   100
    nodeColors(composeMap(palette,colors)).
kpeter@206
   101
    arcColors(composeMap(palette,acolors)).
alpar@128
   102
    arcWidthScale(.4).arcWidths(widths).
alpar@128
   103
    nodeTexts(id).nodeTextSize(3).
alpar@128
   104
    run();
alpar@128
   105
kpeter@206
   106
  cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
kpeter@206
   107
  graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
alpar@128
   108
    title("Sample .eps figure (with arrowheads)").
kpeter@206
   109
    copyright("(C) 2003-2008 LEMON Project").
alpar@128
   110
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
   111
    nodeColors(composeMap(palette,colors)).
alpar@128
   112
    coords(coords).
alpar@128
   113
    nodeScale(2).nodeSizes(sizes).
alpar@128
   114
    nodeShapes(shapes).
kpeter@206
   115
    arcColors(composeMap(palette,acolors)).
alpar@128
   116
    arcWidthScale(.4).arcWidths(widths).
alpar@128
   117
    nodeTexts(id).nodeTextSize(3).
kpeter@206
   118
    drawArrows().arrowWidth(2).arrowLength(2).
alpar@128
   119
    run();
alpar@128
   120
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
alpar@128
   132
  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
alpar@128
   133
  graphToEps(g,"graph_to_eps_demo_out_par.eps").
alpar@128
   134
    //scale(10).
alpar@128
   135
    title("Sample .eps figure (parallel arcs)").
kpeter@206
   136
    copyright("(C) 2003-2008 LEMON Project").
alpar@128
   137
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
   138
    nodeShapes(shapes).
alpar@128
   139
    coords(coords).
alpar@128
   140
    nodeScale(2).nodeSizes(sizes).
alpar@128
   141
    nodeColors(composeMap(palette,colors)).
kpeter@206
   142
    arcColors(composeMap(palette,acolors)).
alpar@128
   143
    arcWidthScale(.4).arcWidths(widths).
alpar@128
   144
    nodeTexts(id).nodeTextSize(3).
alpar@128
   145
    enableParallel().parArcDist(1.5).
alpar@128
   146
    run();
kpeter@206
   147
kpeter@206
   148
  cout << "Create 'graph_to_eps_demo_out_4_par_arr.eps'" << endl;
kpeter@206
   149
  graphToEps(g,"graph_to_eps_demo_out_4_par_arr.eps").
alpar@128
   150
    title("Sample .eps figure (parallel arcs and arrowheads)").
kpeter@206
   151
    copyright("(C) 2003-2008 LEMON Project").
alpar@128
   152
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
   153
    nodeScale(2).nodeSizes(sizes).
alpar@128
   154
    coords(coords).
alpar@128
   155
    nodeShapes(shapes).
alpar@128
   156
    nodeColors(composeMap(palette,colors)).
kpeter@206
   157
    arcColors(composeMap(palette,acolors)).
alpar@128
   158
    arcWidthScale(.3).arcWidths(widths).
alpar@128
   159
    nodeTexts(id).nodeTextSize(3).
alpar@128
   160
    enableParallel().parArcDist(1).
alpar@128
   161
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@128
   162
    run();
alpar@128
   163
kpeter@206
   164
  cout << "Create 'graph_to_eps_demo_out_5_par_arr_a4.eps'" << endl;
kpeter@206
   165
  graphToEps(g,"graph_to_eps_demo_out_5_par_arr_a4.eps").
alpar@128
   166
    title("Sample .eps figure (fits to A4)").
kpeter@206
   167
    copyright("(C) 2003-2008 LEMON Project").
kpeter@206
   168
    scaleToA4().
alpar@128
   169
    absoluteNodeSizes().absoluteArcWidths().
alpar@128
   170
    nodeScale(2).nodeSizes(sizes).
alpar@128
   171
    coords(coords).
alpar@128
   172
    nodeShapes(shapes).
alpar@128
   173
    nodeColors(composeMap(palette,colors)).
kpeter@206
   174
    arcColors(composeMap(palette,acolors)).
alpar@128
   175
    arcWidthScale(.3).arcWidths(widths).
alpar@128
   176
    nodeTexts(id).nodeTextSize(3).
alpar@128
   177
    enableParallel().parArcDist(1).
alpar@128
   178
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@128
   179
    run();
alpar@128
   180
kpeter@206
   181
  // Create an .eps file showing the colors of a default Palette
alpar@128
   182
  ListDigraph h;
alpar@128
   183
  ListDigraph::NodeMap<int> hcolors(h);
alpar@128
   184
  ListDigraph::NodeMap<Point> hcoords(h);
alpar@209
   185
alpar@128
   186
  int cols=int(sqrt(double(palette.size())));
alpar@128
   187
  for(int i=0;i<int(paletteW.size());i++) {
alpar@128
   188
    Node n=h.addNode();
kpeter@206
   189
    hcoords[n]=Point(1+i%cols,1+i/cols);
alpar@128
   190
    hcolors[n]=i;
alpar@128
   191
  }
alpar@209
   192
kpeter@206
   193
  cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl;
kpeter@206
   194
  graphToEps(h,"graph_to_eps_demo_out_6_colors.eps").
kpeter@206
   195
    scale(60).
alpar@128
   196
    title("Sample .eps figure (Palette demo)").
kpeter@206
   197
    copyright("(C) 2003-2008 LEMON Project").
alpar@128
   198
    coords(hcoords).
alpar@128
   199
    absoluteNodeSizes().absoluteArcWidths().
alpar@132
   200
    nodeScale(.45).
alpar@128
   201
    distantColorNodeTexts().
alpar@128
   202
    nodeTexts(hcolors).nodeTextSize(.6).
alpar@128
   203
    nodeColors(composeMap(paletteW,hcolors)).
alpar@128
   204
    run();
alpar@209
   205
kpeter@206
   206
  return 0;
alpar@128
   207
}