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