demo/graph_to_eps_demo.cc
author athos
Fri, 22 Jul 2005 15:03:23 +0000
changeset 1582 5fd89def7cbc
parent 1435 8e85e6bbefdf
child 1587 8f1c317ebeb4
permissions -rw-r--r--
File demoprograms.dox thrown away: demos module used instead.
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@1573
    17
/// \ingroup demos
alpar@1573
    18
/// \file
alpar@1573
    19
/// \brief Demo of the graph grawing function \ref graphToEps()
alpar@1573
    20
///
alpar@1573
    21
/// This demo program shows examples how to  use the function \ref
alpar@1573
    22
/// graphToEps(). It takes no input but simply creates  six
alpar@1573
    23
/// <tt>.eps</tt> files demonstrating how to draw directed/undirected
alpar@1573
    24
/// graphs, how to handle parallel egdes, how to change the properties
alpar@1573
    25
/// (like color, shape, size, title etc.) of nodes and edges
alpar@1573
    26
/// individually using appropriate \ref maps-page "graphmaps".
alpar@1073
    27
deba@1417
    28
#include <cmath>
deba@1417
    29
alpar@1573
    30
#include<lemon/graph_to_eps.h>
alpar@1573
    31
#include<lemon/list_graph.h>
alpar@1073
    32
alpar@1073
    33
using namespace std;
alpar@1073
    34
using namespace lemon;
alpar@1073
    35
alpar@1073
    36
int main()
alpar@1073
    37
{
alpar@1178
    38
  ColorSet colorSet;
alpar@1178
    39
alpar@1073
    40
  ListGraph g;
alpar@1073
    41
  typedef ListGraph::Node Node;
alpar@1073
    42
  typedef ListGraph::NodeIt NodeIt;
alpar@1073
    43
  typedef ListGraph::Edge Edge;
alpar@1073
    44
  typedef xy<int> Xy;
alpar@1073
    45
  
alpar@1073
    46
  Node n1=g.addNode();
alpar@1073
    47
  Node n2=g.addNode();
alpar@1073
    48
  Node n3=g.addNode();
alpar@1073
    49
  Node n4=g.addNode();
alpar@1073
    50
  Node n5=g.addNode();
alpar@1073
    51
alpar@1073
    52
  ListGraph::NodeMap<Xy> coords(g);
alpar@1073
    53
  ListGraph::NodeMap<double> sizes(g);
alpar@1073
    54
  ListGraph::NodeMap<int> colors(g);
alpar@1086
    55
  ListGraph::NodeMap<int> shapes(g);
alpar@1073
    56
  ListGraph::EdgeMap<int> ecolors(g);
alpar@1073
    57
  ListGraph::EdgeMap<int> widths(g);
alpar@1073
    58
  
alpar@1086
    59
  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@1088
    60
  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@1086
    61
  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@1086
    62
  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@1088
    63
  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@1073
    64
  
alpar@1073
    65
  Edge e;
alpar@1073
    66
alpar@1073
    67
  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
alpar@1073
    68
  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
alpar@1073
    69
  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
alpar@1073
    70
  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
alpar@1073
    71
  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
alpar@1073
    72
  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
alpar@1073
    73
  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
    74
  
alpar@1268
    75
  IdMap<ListGraph,Node> id(g);
alpar@1073
    76
alpar@1573
    77
  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
alpar@1073
    78
  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
alpar@1108
    79
    title("Sample .eps figure").
alpar@1164
    80
    copyright("(C) 2005 LEMON Project").
alpar@1073
    81
    nodeScale(2).nodeSizes(sizes).
alpar@1086
    82
    nodeShapes(shapes).
alpar@1073
    83
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
    84
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    85
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1091
    86
    nodeTexts(id).nodeTextSize(3).
alpar@1091
    87
    run();
alpar@1073
    88
alpar@1573
    89
alpar@1573
    90
  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
alpar@1091
    91
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
alpar@1108
    92
    title("Sample .eps figure (with arrowheads)").
alpar@1164
    93
    copyright("(C) 2005 LEMON Project").
alpar@1091
    94
    nodeColors(composeMap(colorSet,colors)).
alpar@1091
    95
    coords(coords).
alpar@1073
    96
    nodeScale(2).nodeSizes(sizes).
alpar@1086
    97
    nodeShapes(shapes).
alpar@1073
    98
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    99
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   100
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   101
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1091
   102
    run();
alpar@1073
   103
alpar@1073
   104
  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
   105
  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
alpar@1073
   106
alpar@1073
   107
  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
alpar@1073
   108
  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
alpar@1073
   109
  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
alpar@1073
   110
  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
alpar@1073
   111
  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
alpar@1073
   112
  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
alpar@1073
   113
  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
alpar@1073
   114
alpar@1573
   115
  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
alpar@1091
   116
  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
alpar@1108
   117
    title("Sample .eps figure (parallel edges)").
alpar@1164
   118
    copyright("(C) 2005 LEMON Project").
alpar@1091
   119
    nodeShapes(shapes).
alpar@1091
   120
    coords(coords).
alpar@1073
   121
    nodeScale(2).nodeSizes(sizes).
alpar@1073
   122
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   123
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   124
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   125
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   126
    enableParallel().parEdgeDist(1.5).
alpar@1091
   127
    run();
alpar@1091
   128
  
alpar@1573
   129
  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
alpar@1091
   130
  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
alpar@1108
   131
    title("Sample .eps figure (parallel edges and arrowheads)").
alpar@1164
   132
    copyright("(C) 2005 LEMON Project").
alpar@1073
   133
    nodeScale(2).nodeSizes(sizes).
alpar@1091
   134
    coords(coords).
alpar@1086
   135
    nodeShapes(shapes).
alpar@1073
   136
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   137
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   138
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1073
   139
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   140
    enableParallel().parEdgeDist(1).
alpar@1091
   141
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   142
    run();
alpar@1103
   143
alpar@1573
   144
  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
alpar@1103
   145
  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
alpar@1108
   146
    title("Sample .eps figure (fits to A4)").
alpar@1164
   147
    copyright("(C) 2005 LEMON Project").
alpar@1103
   148
    nodeScale(2).nodeSizes(sizes).
alpar@1103
   149
    coords(coords).
alpar@1103
   150
    nodeShapes(shapes).
alpar@1103
   151
    nodeColors(composeMap(colorSet,colors)).
alpar@1103
   152
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1103
   153
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1103
   154
    nodeTexts(id).nodeTextSize(3).
alpar@1103
   155
    enableParallel().parEdgeDist(1).
alpar@1103
   156
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   157
    run();
alpar@1103
   158
alpar@1178
   159
  ListGraph h;
alpar@1178
   160
  ListGraph::NodeMap<int> hcolors(h);
alpar@1178
   161
  ListGraph::NodeMap<Xy> hcoords(h);
alpar@1178
   162
  
alpar@1178
   163
  int cols=int(sqrt(double(colorSet.size())));
alpar@1178
   164
  for(int i=0;i<int(colorSet.size());i++) {
alpar@1178
   165
    Node n=h.addNode();
alpar@1178
   166
    hcoords[n]=Xy(i%cols,i/cols);
alpar@1178
   167
    hcolors[n]=i;
alpar@1178
   168
  }
alpar@1178
   169
  
alpar@1573
   170
  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
alpar@1178
   171
  graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
alpar@1573
   172
    title("Sample .eps figure (ColorSet demo)").
alpar@1178
   173
    copyright("(C) 2005 LEMON Project").
alpar@1178
   174
    coords(hcoords).
alpar@1178
   175
    nodeScale(.45).
alpar@1178
   176
    distantColorNodeTexts().
alpar@1178
   177
    //    distantBWNodeTexts().
alpar@1178
   178
    nodeTexts(hcolors).nodeTextSize(.6).
alpar@1178
   179
    nodeColors(composeMap(colorSet,hcolors)).
alpar@1178
   180
    run();
alpar@1178
   181
alpar@1178
   182
alpar@1073
   183
}