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
     1 /* -*- C++ -*-
     2  * demo/graph_to_eps.cc - Part of LEMON, a generic C++ optimization library
     3  *
     4  * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     6  *
     7  * Permission to use, modify and distribute this software is granted
     8  * provided that this copyright notice appears in all copies. For
     9  * precise terms see the accompanying LICENSE file.
    10  *
    11  * This software is provided "AS IS" with no warranty of any kind,
    12  * express or implied, and with no claim as to its suitability for any
    13  * purpose.
    14  *
    15  */
    16 
    17 /// \ingroup demos
    18 /// \file
    19 /// \brief Demo of the graph grawing function \ref graphToEps()
    20 ///
    21 /// This demo program shows examples how to  use the function \ref
    22 /// graphToEps(). It takes no input but simply creates  six
    23 /// <tt>.eps</tt> files demonstrating the capability of \ref
    24 /// graphToEps(), and showing how to draw directed/undirected graphs,
    25 /// how to handle parallel egdes, how to change the properties (like
    26 /// color, shape, size, title etc.) of nodes and edges individually
    27 /// using appropriate \ref maps-page "graph maps".
    28 ///
    29 /// \include graph_to_eps_demo.cc
    30 
    31 #include <cmath>
    32 
    33 #include<lemon/graph_to_eps.h>
    34 #include<lemon/list_graph.h>
    35 #include<lemon/graph_utils.h>
    36 
    37 using namespace std;
    38 using namespace lemon;
    39 
    40 int main()
    41 {
    42   ColorSet colorSet;
    43 
    44   ListGraph g;
    45   typedef ListGraph::Node Node;
    46   typedef ListGraph::NodeIt NodeIt;
    47   typedef ListGraph::Edge Edge;
    48   typedef xy<int> Xy;
    49   
    50   Node n1=g.addNode();
    51   Node n2=g.addNode();
    52   Node n3=g.addNode();
    53   Node n4=g.addNode();
    54   Node n5=g.addNode();
    55 
    56   ListGraph::NodeMap<Xy> coords(g);
    57   ListGraph::NodeMap<double> sizes(g);
    58   ListGraph::NodeMap<int> colors(g);
    59   ListGraph::NodeMap<int> shapes(g);
    60   ListGraph::EdgeMap<int> ecolors(g);
    61   ListGraph::EdgeMap<int> widths(g);
    62   
    63   coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    64   coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
    65   coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
    66   coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
    67   coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    68   
    69   Edge e;
    70 
    71   e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
    72   e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
    73   e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
    74   e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
    75   e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
    76   e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
    77   e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
    78   
    79   IdMap<ListGraph,Node> id(g);
    80 
    81   cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
    82   graphToEps(g,"graph_to_eps_demo_out.eps").
    83     //scale(10).
    84     coords(coords).
    85     title("Sample .eps figure").
    86     copyright("(C) 2006 LEMON Project").
    87     nodeScale(2).nodeSizes(sizes).
    88     nodeShapes(shapes).
    89     nodeColors(composeMap(colorSet,colors)).
    90     edgeColors(composeMap(colorSet,ecolors)).
    91     edgeWidthScale(.4).edgeWidths(widths).
    92     nodeTexts(id).nodeTextSize(3).
    93     run();
    94 
    95 
    96   cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
    97   graphToEps(g,"graph_to_eps_demo_out_arr.eps").
    98     //scale(10).
    99     title("Sample .eps figure (with arrowheads)").
   100     copyright("(C) 2006 LEMON Project").
   101     nodeColors(composeMap(colorSet,colors)).
   102     coords(coords).
   103     nodeScale(2).nodeSizes(sizes).
   104     nodeShapes(shapes).
   105     edgeColors(composeMap(colorSet,ecolors)).
   106     edgeWidthScale(.4).edgeWidths(widths).
   107     nodeTexts(id).nodeTextSize(3).
   108     drawArrows().arrowWidth(1).arrowLength(1).
   109     run();
   110 
   111   e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
   112   e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
   113 
   114   e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
   115   e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
   116   e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
   117   e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
   118   e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
   119   e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
   120   e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
   121 
   122   cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
   123   graphToEps(g,"graph_to_eps_demo_out_par.eps").
   124     //scale(10).
   125     title("Sample .eps figure (parallel edges)").
   126     copyright("(C) 2006 LEMON Project").
   127     nodeShapes(shapes).
   128     coords(coords).
   129     nodeScale(2).nodeSizes(sizes).
   130     nodeColors(composeMap(colorSet,colors)).
   131     edgeColors(composeMap(colorSet,ecolors)).
   132     edgeWidthScale(.4).edgeWidths(widths).
   133     nodeTexts(id).nodeTextSize(3).
   134     enableParallel().parEdgeDist(1.5).
   135     run();
   136   
   137   cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
   138   graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
   139     //scale(10).
   140     title("Sample .eps figure (parallel edges and arrowheads)").
   141     copyright("(C) 2006 LEMON Project").
   142     nodeScale(2).nodeSizes(sizes).
   143     coords(coords).
   144     nodeShapes(shapes).
   145     nodeColors(composeMap(colorSet,colors)).
   146     edgeColors(composeMap(colorSet,ecolors)).
   147     edgeWidthScale(.3).edgeWidths(widths).
   148     nodeTexts(id).nodeTextSize(3).
   149     enableParallel().parEdgeDist(1).
   150     drawArrows().arrowWidth(1).arrowLength(1).
   151     run();
   152 
   153   cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
   154   graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
   155     title("Sample .eps figure (fits to A4)").
   156     copyright("(C) 2006 LEMON Project").
   157     nodeScale(2).nodeSizes(sizes).
   158     coords(coords).
   159     nodeShapes(shapes).
   160     nodeColors(composeMap(colorSet,colors)).
   161     edgeColors(composeMap(colorSet,ecolors)).
   162     edgeWidthScale(.3).edgeWidths(widths).
   163     nodeTexts(id).nodeTextSize(3).
   164     enableParallel().parEdgeDist(1).
   165     drawArrows().arrowWidth(1).arrowLength(1).
   166     run();
   167 
   168   ListGraph h;
   169   ListGraph::NodeMap<int> hcolors(h);
   170   ListGraph::NodeMap<Xy> hcoords(h);
   171   
   172   int cols=int(sqrt(double(colorSet.size())));
   173   for(int i=0;i<int(colorSet.size());i++) {
   174     Node n=h.addNode();
   175     hcoords[n]=Xy(i%cols,i/cols);
   176     hcolors[n]=i;
   177   }
   178   
   179   cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
   180   graphToEps(h,"graph_to_eps_demo_out_colors.eps").
   181     //scale(60).
   182     title("Sample .eps figure (ColorSet demo)").
   183     copyright("(C) 2006 LEMON Project").
   184     coords(hcoords).
   185     nodeScale(.45).
   186     distantColorNodeTexts().
   187     //    distantBWNodeTexts().
   188     nodeTexts(hcolors).nodeTextSize(.6).
   189     nodeColors(composeMap(colorSet,hcolors)).
   190     run();
   191 
   192 
   193 }