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