demo/graph_to_eps_demo.cc
author klao
Thu, 02 Feb 2006 17:09:09 +0000
changeset 1945 e5c0c5cc477f
parent 1875 98698b69a902
child 1956 a055123339d5
permissions -rw-r--r--
NEWS: major changes since 0.4 added
alpar@1073
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * demo/graph_to_eps.cc - Part of LEMON, a generic C++ optimization library
alpar@1073
     3
 *
alpar@1875
     4
 * Copyright (C) 2006 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@1587
    23
/// <tt>.eps</tt> files demonstrating the capability of \ref
alpar@1587
    24
/// graphToEps(), and showing how to draw directed/undirected graphs,
alpar@1587
    25
/// how to handle parallel egdes, how to change the properties (like
alpar@1587
    26
/// color, shape, size, title etc.) of nodes and edges individually
alpar@1630
    27
/// using appropriate \ref maps-page "graph maps".
alpar@1641
    28
///
alpar@1641
    29
/// \include graph_to_eps_demo.cc
alpar@1073
    30
deba@1417
    31
#include <cmath>
deba@1417
    32
alpar@1573
    33
#include<lemon/graph_to_eps.h>
alpar@1573
    34
#include<lemon/list_graph.h>
deba@1802
    35
#include<lemon/graph_utils.h>
alpar@1073
    36
alpar@1073
    37
using namespace std;
alpar@1073
    38
using namespace lemon;
alpar@1073
    39
alpar@1073
    40
int main()
alpar@1073
    41
{
alpar@1178
    42
  ColorSet colorSet;
alpar@1178
    43
alpar@1073
    44
  ListGraph g;
alpar@1073
    45
  typedef ListGraph::Node Node;
alpar@1073
    46
  typedef ListGraph::NodeIt NodeIt;
alpar@1073
    47
  typedef ListGraph::Edge Edge;
alpar@1073
    48
  typedef xy<int> Xy;
alpar@1073
    49
  
alpar@1073
    50
  Node n1=g.addNode();
alpar@1073
    51
  Node n2=g.addNode();
alpar@1073
    52
  Node n3=g.addNode();
alpar@1073
    53
  Node n4=g.addNode();
alpar@1073
    54
  Node n5=g.addNode();
alpar@1073
    55
alpar@1073
    56
  ListGraph::NodeMap<Xy> coords(g);
alpar@1073
    57
  ListGraph::NodeMap<double> sizes(g);
alpar@1073
    58
  ListGraph::NodeMap<int> colors(g);
alpar@1086
    59
  ListGraph::NodeMap<int> shapes(g);
alpar@1073
    60
  ListGraph::EdgeMap<int> ecolors(g);
alpar@1073
    61
  ListGraph::EdgeMap<int> widths(g);
alpar@1073
    62
  
alpar@1086
    63
  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@1088
    64
  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@1086
    65
  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@1086
    66
  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@1088
    67
  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@1073
    68
  
alpar@1073
    69
  Edge e;
alpar@1073
    70
alpar@1073
    71
  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
alpar@1073
    72
  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
alpar@1073
    73
  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
alpar@1073
    74
  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
alpar@1073
    75
  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
alpar@1073
    76
  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
alpar@1073
    77
  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
    78
  
alpar@1268
    79
  IdMap<ListGraph,Node> id(g);
alpar@1073
    80
alpar@1573
    81
  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
alpar@1930
    82
  graphToEps(g,"graph_to_eps_demo_out.eps").
alpar@1930
    83
    //scale(10).
alpar@1930
    84
    coords(coords).
alpar@1108
    85
    title("Sample .eps figure").
alpar@1875
    86
    copyright("(C) 2006 LEMON Project").
alpar@1073
    87
    nodeScale(2).nodeSizes(sizes).
alpar@1086
    88
    nodeShapes(shapes).
alpar@1073
    89
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
    90
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    91
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1091
    92
    nodeTexts(id).nodeTextSize(3).
alpar@1091
    93
    run();
alpar@1073
    94
alpar@1573
    95
alpar@1573
    96
  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
alpar@1930
    97
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").
alpar@1930
    98
    //scale(10).
alpar@1108
    99
    title("Sample .eps figure (with arrowheads)").
alpar@1875
   100
    copyright("(C) 2006 LEMON Project").
alpar@1091
   101
    nodeColors(composeMap(colorSet,colors)).
alpar@1091
   102
    coords(coords).
alpar@1073
   103
    nodeScale(2).nodeSizes(sizes).
alpar@1086
   104
    nodeShapes(shapes).
alpar@1073
   105
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   106
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   107
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   108
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1091
   109
    run();
alpar@1073
   110
alpar@1073
   111
  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
   112
  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
alpar@1073
   113
alpar@1073
   114
  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
alpar@1073
   115
  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
alpar@1073
   116
  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
alpar@1073
   117
  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
alpar@1073
   118
  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
alpar@1073
   119
  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
alpar@1073
   120
  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
alpar@1073
   121
alpar@1573
   122
  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
alpar@1930
   123
  graphToEps(g,"graph_to_eps_demo_out_par.eps").
alpar@1930
   124
    //scale(10).
alpar@1108
   125
    title("Sample .eps figure (parallel edges)").
alpar@1875
   126
    copyright("(C) 2006 LEMON Project").
alpar@1091
   127
    nodeShapes(shapes).
alpar@1091
   128
    coords(coords).
alpar@1073
   129
    nodeScale(2).nodeSizes(sizes).
alpar@1073
   130
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   131
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   132
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   133
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   134
    enableParallel().parEdgeDist(1.5).
alpar@1091
   135
    run();
alpar@1091
   136
  
alpar@1573
   137
  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
alpar@1930
   138
  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
alpar@1930
   139
    //scale(10).
alpar@1108
   140
    title("Sample .eps figure (parallel edges and arrowheads)").
alpar@1875
   141
    copyright("(C) 2006 LEMON Project").
alpar@1073
   142
    nodeScale(2).nodeSizes(sizes).
alpar@1091
   143
    coords(coords).
alpar@1086
   144
    nodeShapes(shapes).
alpar@1073
   145
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   146
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   147
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1073
   148
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   149
    enableParallel().parEdgeDist(1).
alpar@1091
   150
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   151
    run();
alpar@1103
   152
alpar@1573
   153
  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
alpar@1103
   154
  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
alpar@1108
   155
    title("Sample .eps figure (fits to A4)").
alpar@1875
   156
    copyright("(C) 2006 LEMON Project").
alpar@1103
   157
    nodeScale(2).nodeSizes(sizes).
alpar@1103
   158
    coords(coords).
alpar@1103
   159
    nodeShapes(shapes).
alpar@1103
   160
    nodeColors(composeMap(colorSet,colors)).
alpar@1103
   161
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1103
   162
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1103
   163
    nodeTexts(id).nodeTextSize(3).
alpar@1103
   164
    enableParallel().parEdgeDist(1).
alpar@1103
   165
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   166
    run();
alpar@1103
   167
alpar@1178
   168
  ListGraph h;
alpar@1178
   169
  ListGraph::NodeMap<int> hcolors(h);
alpar@1178
   170
  ListGraph::NodeMap<Xy> hcoords(h);
alpar@1178
   171
  
alpar@1178
   172
  int cols=int(sqrt(double(colorSet.size())));
alpar@1178
   173
  for(int i=0;i<int(colorSet.size());i++) {
alpar@1178
   174
    Node n=h.addNode();
alpar@1178
   175
    hcoords[n]=Xy(i%cols,i/cols);
alpar@1178
   176
    hcolors[n]=i;
alpar@1178
   177
  }
alpar@1178
   178
  
alpar@1573
   179
  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
alpar@1930
   180
  graphToEps(h,"graph_to_eps_demo_out_colors.eps").
alpar@1930
   181
    //scale(60).
alpar@1573
   182
    title("Sample .eps figure (ColorSet demo)").
alpar@1875
   183
    copyright("(C) 2006 LEMON Project").
alpar@1178
   184
    coords(hcoords).
alpar@1178
   185
    nodeScale(.45).
alpar@1178
   186
    distantColorNodeTexts().
alpar@1178
   187
    //    distantBWNodeTexts().
alpar@1178
   188
    nodeTexts(hcolors).nodeTextSize(.6).
alpar@1178
   189
    nodeColors(composeMap(colorSet,hcolors)).
alpar@1178
   190
    run();
alpar@1178
   191
alpar@1178
   192
alpar@1073
   193
}