src/demo/graph_to_eps_demo.cc
author hegyi
Thu, 17 Mar 2005 11:45:05 +0000
changeset 1224 7f4f2855fa11
parent 1164 80bb73097736
child 1268 a1f9a4d4ea0c
permissions -rw-r--r--
Magic triangle is a bit more DONE, and is already not only a triangle.
alpar@1073
     1
/* -*- C++ -*-
alpar@1073
     2
 * src/lemon/demo/graph_to_eps.cc - 
alpar@1073
     3
 * Part of LEMON, a generic C++ optimization library
alpar@1073
     4
 *
alpar@1164
     5
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1073
     6
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@1073
     7
 *
alpar@1073
     8
 * Permission to use, modify and distribute this software is granted
alpar@1073
     9
 * provided that this copyright notice appears in all copies. For
alpar@1073
    10
 * precise terms see the accompanying LICENSE file.
alpar@1073
    11
 *
alpar@1073
    12
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1073
    13
 * express or implied, and with no claim as to its suitability for any
alpar@1073
    14
 * purpose.
alpar@1073
    15
 *
alpar@1073
    16
 */
alpar@1073
    17
alpar@1073
    18
#include<lemon/graph_to_eps.h>
alpar@1073
    19
#include<lemon/maps.h>
alpar@1073
    20
#include<lemon/list_graph.h>
alpar@1073
    21
alpar@1073
    22
alpar@1073
    23
using namespace std;
alpar@1073
    24
using namespace lemon;
alpar@1073
    25
alpar@1073
    26
class IdMap :public MapBase<ListGraph::Node,int>
alpar@1073
    27
{
alpar@1073
    28
  const ListGraph &g;
alpar@1073
    29
public:
alpar@1073
    30
  IdMap(const ListGraph &_g) :g(_g) {}
alpar@1073
    31
  Value operator[](Key n) const { return g.id(n); }
alpar@1073
    32
};
alpar@1073
    33
alpar@1073
    34
int main()
alpar@1073
    35
{
alpar@1178
    36
  ColorSet colorSet;
alpar@1178
    37
alpar@1073
    38
  ListGraph g;
alpar@1073
    39
  typedef ListGraph::Node Node;
alpar@1073
    40
  typedef ListGraph::NodeIt NodeIt;
alpar@1073
    41
  typedef ListGraph::Edge Edge;
alpar@1073
    42
  typedef xy<int> Xy;
alpar@1073
    43
  
alpar@1073
    44
  Node n1=g.addNode();
alpar@1073
    45
  Node n2=g.addNode();
alpar@1073
    46
  Node n3=g.addNode();
alpar@1073
    47
  Node n4=g.addNode();
alpar@1073
    48
  Node n5=g.addNode();
alpar@1073
    49
alpar@1073
    50
  ListGraph::NodeMap<Xy> coords(g);
alpar@1073
    51
  ListGraph::NodeMap<double> sizes(g);
alpar@1073
    52
  ListGraph::NodeMap<int> colors(g);
alpar@1086
    53
  ListGraph::NodeMap<int> shapes(g);
alpar@1073
    54
  ListGraph::EdgeMap<int> ecolors(g);
alpar@1073
    55
  ListGraph::EdgeMap<int> widths(g);
alpar@1073
    56
  
alpar@1086
    57
  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@1088
    58
  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@1086
    59
  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@1086
    60
  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@1088
    61
  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@1073
    62
  
alpar@1073
    63
  Edge e;
alpar@1073
    64
alpar@1073
    65
  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
alpar@1073
    66
  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
alpar@1073
    67
  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
alpar@1073
    68
  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
alpar@1073
    69
  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
alpar@1073
    70
  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
alpar@1073
    71
  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
    72
  
alpar@1073
    73
  IdMap id(g);
alpar@1073
    74
alpar@1073
    75
  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
alpar@1108
    76
    title("Sample .eps figure").
alpar@1164
    77
    copyright("(C) 2005 LEMON Project").
alpar@1073
    78
    nodeScale(2).nodeSizes(sizes).
alpar@1086
    79
    nodeShapes(shapes).
alpar@1073
    80
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
    81
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    82
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1091
    83
    nodeTexts(id).nodeTextSize(3).
alpar@1091
    84
    run();
alpar@1073
    85
alpar@1091
    86
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
alpar@1108
    87
    title("Sample .eps figure (with arrowheads)").
alpar@1164
    88
    copyright("(C) 2005 LEMON Project").
alpar@1091
    89
    nodeColors(composeMap(colorSet,colors)).
alpar@1091
    90
    coords(coords).
alpar@1073
    91
    nodeScale(2).nodeSizes(sizes).
alpar@1086
    92
    nodeShapes(shapes).
alpar@1073
    93
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    94
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
    95
    nodeTexts(id).nodeTextSize(3).
alpar@1091
    96
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1091
    97
    run();
alpar@1073
    98
alpar@1073
    99
  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
   100
  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
alpar@1073
   101
alpar@1073
   102
  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
alpar@1073
   103
  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
alpar@1073
   104
  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
alpar@1073
   105
  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
alpar@1073
   106
  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
alpar@1073
   107
  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
alpar@1073
   108
  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
alpar@1073
   109
alpar@1091
   110
  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
alpar@1108
   111
    title("Sample .eps figure (parallel edges)").
alpar@1164
   112
    copyright("(C) 2005 LEMON Project").
alpar@1091
   113
    nodeShapes(shapes).
alpar@1091
   114
    coords(coords).
alpar@1073
   115
    nodeScale(2).nodeSizes(sizes).
alpar@1073
   116
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   117
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   118
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   119
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   120
    enableParallel().parEdgeDist(1.5).
alpar@1091
   121
    run();
alpar@1091
   122
  
alpar@1091
   123
  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
alpar@1108
   124
    title("Sample .eps figure (parallel edges and arrowheads)").
alpar@1164
   125
    copyright("(C) 2005 LEMON Project").
alpar@1073
   126
    nodeScale(2).nodeSizes(sizes).
alpar@1091
   127
    coords(coords).
alpar@1086
   128
    nodeShapes(shapes).
alpar@1073
   129
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   130
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   131
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1073
   132
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   133
    enableParallel().parEdgeDist(1).
alpar@1091
   134
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   135
    run();
alpar@1103
   136
alpar@1103
   137
  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
alpar@1108
   138
    title("Sample .eps figure (fits to A4)").
alpar@1164
   139
    copyright("(C) 2005 LEMON Project").
alpar@1103
   140
    nodeScale(2).nodeSizes(sizes).
alpar@1103
   141
    coords(coords).
alpar@1103
   142
    nodeShapes(shapes).
alpar@1103
   143
    nodeColors(composeMap(colorSet,colors)).
alpar@1103
   144
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1103
   145
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1103
   146
    nodeTexts(id).nodeTextSize(3).
alpar@1103
   147
    enableParallel().parEdgeDist(1).
alpar@1103
   148
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   149
    run();
alpar@1103
   150
alpar@1178
   151
  ListGraph h;
alpar@1178
   152
  ListGraph::NodeMap<int> hcolors(h);
alpar@1178
   153
  ListGraph::NodeMap<Xy> hcoords(h);
alpar@1178
   154
  
alpar@1178
   155
  int cols=int(sqrt(double(colorSet.size())));
alpar@1178
   156
  for(int i=0;i<int(colorSet.size());i++) {
alpar@1178
   157
    Node n=h.addNode();
alpar@1178
   158
    hcoords[n]=Xy(i%cols,i/cols);
alpar@1178
   159
    hcolors[n]=i;
alpar@1178
   160
  }
alpar@1178
   161
  
alpar@1178
   162
  graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
alpar@1178
   163
    title("Sample .eps figure (parallel edges and arrowheads)").
alpar@1178
   164
    copyright("(C) 2005 LEMON Project").
alpar@1178
   165
    coords(hcoords).
alpar@1178
   166
    nodeScale(.45).
alpar@1178
   167
    distantColorNodeTexts().
alpar@1178
   168
    //    distantBWNodeTexts().
alpar@1178
   169
    nodeTexts(hcolors).nodeTextSize(.6).
alpar@1178
   170
    nodeColors(composeMap(colorSet,hcolors)).
alpar@1178
   171
    run();
alpar@1178
   172
alpar@1178
   173
alpar@1073
   174
}