demo/graph_to_eps_demo.cc
changeset 208 4317d277ba21
parent 132 50ff949140fa
child 209 765619b7cbb2
equal deleted inserted replaced
2:deda980c31b7 3:8638ae505a6b
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 /// \ingroup demos
    19 /// \ingroup demos
    20 /// \file
    20 /// \file
    21 /// \brief Demo of the graph grawing function \ref graphToEps()
    21 /// \brief Demo of the graph drawing function \ref graphToEps()
    22 ///
    22 ///
    23 /// This demo program shows examples how to  use the function \ref
    23 /// This demo program shows examples how to  use the function \ref
    24 /// graphToEps(). It takes no input but simply creates  six
    24 /// graphToEps(). It takes no input but simply creates  six
    25 /// <tt>.eps</tt> files demonstrating the capability of \ref
    25 /// <tt>.eps</tt> files demonstrating the capability of \ref
    26 /// graphToEps(), and showing how to draw directed/graphs,
    26 /// graphToEps(), and showing how to draw directed graphs,
    27 /// how to handle parallel egdes, how to change the properties (like
    27 /// how to handle parallel egdes, how to change the properties (like
    28 /// color, shape, size, title etc.) of nodes and arcs individually
    28 /// color, shape, size, title etc.) of nodes and arcs individually
    29 /// using appropriate \ref maps-page "graph maps".
    29 /// using appropriate \ref maps-page "graph maps".
    30 ///
    30 ///
    31 /// \include graph_to_eps_demo.cc
    31 /// \include graph_to_eps_demo.cc
    32 
    32 
    33 #include <lemon/math.h>
       
    34 
       
    35 #include<lemon/graph_to_eps.h>
       
    36 #include<lemon/list_graph.h>
    33 #include<lemon/list_graph.h>
    37 #include<lemon/graph_utils.h>
    34 #include<lemon/graph_utils.h>
       
    35 #include<lemon/graph_to_eps.h>
       
    36 #include<lemon/math.h>
    38 
    37 
    39 using namespace std;
    38 using namespace std;
    40 using namespace lemon;
    39 using namespace lemon;
    41 
    40 
    42 int main()
    41 int main()
    43 {
    42 {
    44   Palette palette;
    43   Palette palette;
    45   Palette paletteW(true);
    44   Palette paletteW(true);
    46 
    45 
       
    46   // Create a small digraph
    47   ListDigraph g;
    47   ListDigraph g;
    48   typedef ListDigraph::Node Node;
    48   typedef ListDigraph::Node Node;
    49   typedef ListDigraph::NodeIt NodeIt;
    49   typedef ListDigraph::NodeIt NodeIt;
    50   typedef ListDigraph::Arc Arc;
    50   typedef ListDigraph::Arc Arc;
    51   typedef dim2::Point<int> Point;
    51   typedef dim2::Point<int> Point;
    58 
    58 
    59   ListDigraph::NodeMap<Point> coords(g);
    59   ListDigraph::NodeMap<Point> coords(g);
    60   ListDigraph::NodeMap<double> sizes(g);
    60   ListDigraph::NodeMap<double> sizes(g);
    61   ListDigraph::NodeMap<int> colors(g);
    61   ListDigraph::NodeMap<int> colors(g);
    62   ListDigraph::NodeMap<int> shapes(g);
    62   ListDigraph::NodeMap<int> shapes(g);
    63   ListDigraph::ArcMap<int> ecolors(g);
    63   ListDigraph::ArcMap<int> acolors(g);
    64   ListDigraph::ArcMap<int> widths(g);
    64   ListDigraph::ArcMap<int> widths(g);
    65   
    65   
    66   coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    66   coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    67   coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
    67   coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
    68   coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
    68   coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
    69   coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
    69   coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
    70   coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    70   coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    71   
    71   
    72   Arc e;
    72   Arc a;
    73 
    73 
    74   e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1;
    74   a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
    75   e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1;
    75   a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
    76   e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3;
    76   a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
    77   e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1;
    77   a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
    78   e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1;
    78   a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
    79   e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2;
    79   a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
    80   e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1;
    80   a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
    81   
    81   
    82   IdMap<ListDigraph,Node> id(g);
    82   IdMap<ListDigraph,Node> id(g);
    83 
    83 
    84   cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
    84   // Create five .eps files showing the digraph with different options
    85   graphToEps(g,"graph_to_eps_demo_out_pure.eps").
    85   cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
    86     //scale(10).
    86   graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
    87     coords(coords).
    87     coords(coords).
    88     title("Sample .eps figure").
    88     title("Sample .eps figure").
    89     copyright("(C) 2003-2007 LEMON Project").
    89     copyright("(C) 2003-2008 LEMON Project").
    90     run();
    90     run();
    91 
    91 
    92   cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
    92   cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
    93   graphToEps(g,"graph_to_eps_demo_out.eps").
    93   graphToEps(g,"graph_to_eps_demo_out_2.eps").
    94     //scale(10).
       
    95     coords(coords).
    94     coords(coords).
    96     title("Sample .eps figure").
    95     title("Sample .eps figure").
    97     copyright("(C) 2003-2007 LEMON Project").
    96     copyright("(C) 2003-2008 LEMON Project").
    98     absoluteNodeSizes().absoluteArcWidths().
    97     absoluteNodeSizes().absoluteArcWidths().
    99     nodeScale(2).nodeSizes(sizes).
    98     nodeScale(2).nodeSizes(sizes).
   100     nodeShapes(shapes).
    99     nodeShapes(shapes).
   101     nodeColors(composeMap(palette,colors)).
   100     nodeColors(composeMap(palette,colors)).
   102     arcColors(composeMap(palette,ecolors)).
   101     arcColors(composeMap(palette,acolors)).
   103     arcWidthScale(.4).arcWidths(widths).
   102     arcWidthScale(.4).arcWidths(widths).
   104     nodeTexts(id).nodeTextSize(3).
   103     nodeTexts(id).nodeTextSize(3).
   105     run();
   104     run();
   106 
   105 
   107 
   106   cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
   108   cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
   107   graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
   109   graphToEps(g,"graph_to_eps_demo_out_arr.eps").
       
   110     //scale(10).
       
   111     title("Sample .eps figure (with arrowheads)").
   108     title("Sample .eps figure (with arrowheads)").
   112     copyright("(C) 2003-2007 LEMON Project").
   109     copyright("(C) 2003-2008 LEMON Project").
   113     absoluteNodeSizes().absoluteArcWidths().
   110     absoluteNodeSizes().absoluteArcWidths().
   114     nodeColors(composeMap(palette,colors)).
   111     nodeColors(composeMap(palette,colors)).
   115     coords(coords).
   112     coords(coords).
   116     nodeScale(2).nodeSizes(sizes).
   113     nodeScale(2).nodeSizes(sizes).
   117     nodeShapes(shapes).
   114     nodeShapes(shapes).
   118     arcColors(composeMap(palette,ecolors)).
   115     arcColors(composeMap(palette,acolors)).
   119     arcWidthScale(.4).arcWidths(widths).
   116     arcWidthScale(.4).arcWidths(widths).
   120     nodeTexts(id).nodeTextSize(3).
   117     nodeTexts(id).nodeTextSize(3).
   121     drawArrows().arrowWidth(1).arrowLength(1).
   118     drawArrows().arrowWidth(2).arrowLength(2).
   122     run();
   119     run();
   123 
   120 
   124   e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1;
   121   a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
   125   e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=2;
   122   a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2;
   126 
   123 
   127   e=g.addArc(n1,n2); ecolors[e]=1; widths[e]=1;
   124   a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
   128   e=g.addArc(n1,n2); ecolors[e]=2; widths[e]=1;
   125   a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
   129   e=g.addArc(n1,n2); ecolors[e]=3; widths[e]=1;
   126   a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
   130   e=g.addArc(n1,n2); ecolors[e]=4; widths[e]=1;
   127   a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
   131   e=g.addArc(n1,n2); ecolors[e]=5; widths[e]=1;
   128   a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
   132   e=g.addArc(n1,n2); ecolors[e]=6; widths[e]=1;
   129   a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
   133   e=g.addArc(n1,n2); ecolors[e]=7; widths[e]=1;
   130   a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
   134 
   131 
   135   cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
   132   cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
   136   graphToEps(g,"graph_to_eps_demo_out_par.eps").
   133   graphToEps(g,"graph_to_eps_demo_out_par.eps").
   137     //scale(10).
   134     //scale(10).
   138     title("Sample .eps figure (parallel arcs)").
   135     title("Sample .eps figure (parallel arcs)").
   139     copyright("(C) 2003-2007 LEMON Project").
   136     copyright("(C) 2003-2008 LEMON Project").
   140     absoluteNodeSizes().absoluteArcWidths().
   137     absoluteNodeSizes().absoluteArcWidths().
   141     nodeShapes(shapes).
   138     nodeShapes(shapes).
   142     coords(coords).
   139     coords(coords).
   143     nodeScale(2).nodeSizes(sizes).
   140     nodeScale(2).nodeSizes(sizes).
   144     nodeColors(composeMap(palette,colors)).
   141     nodeColors(composeMap(palette,colors)).
   145     arcColors(composeMap(palette,ecolors)).
   142     arcColors(composeMap(palette,acolors)).
   146     arcWidthScale(.4).arcWidths(widths).
   143     arcWidthScale(.4).arcWidths(widths).
   147     nodeTexts(id).nodeTextSize(3).
   144     nodeTexts(id).nodeTextSize(3).
   148     enableParallel().parArcDist(1.5).
   145     enableParallel().parArcDist(1.5).
   149     run();
   146     run();
   150   
   147 
   151   cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
   148   cout << "Create 'graph_to_eps_demo_out_4_par_arr.eps'" << endl;
   152   graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
   149   graphToEps(g,"graph_to_eps_demo_out_4_par_arr.eps").
   153     //scale(10).
       
   154     title("Sample .eps figure (parallel arcs and arrowheads)").
   150     title("Sample .eps figure (parallel arcs and arrowheads)").
   155     copyright("(C) 2003-2007 LEMON Project").
   151     copyright("(C) 2003-2008 LEMON Project").
   156     absoluteNodeSizes().absoluteArcWidths().
   152     absoluteNodeSizes().absoluteArcWidths().
   157     nodeScale(2).nodeSizes(sizes).
   153     nodeScale(2).nodeSizes(sizes).
   158     coords(coords).
   154     coords(coords).
   159     nodeShapes(shapes).
   155     nodeShapes(shapes).
   160     nodeColors(composeMap(palette,colors)).
   156     nodeColors(composeMap(palette,colors)).
   161     arcColors(composeMap(palette,ecolors)).
   157     arcColors(composeMap(palette,acolors)).
   162     arcWidthScale(.3).arcWidths(widths).
   158     arcWidthScale(.3).arcWidths(widths).
   163     nodeTexts(id).nodeTextSize(3).
   159     nodeTexts(id).nodeTextSize(3).
   164     enableParallel().parArcDist(1).
   160     enableParallel().parArcDist(1).
   165     drawArrows().arrowWidth(1).arrowLength(1).
   161     drawArrows().arrowWidth(1).arrowLength(1).
   166     run();
   162     run();
   167 
   163 
   168   cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
   164   cout << "Create 'graph_to_eps_demo_out_5_par_arr_a4.eps'" << endl;
   169   graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
   165   graphToEps(g,"graph_to_eps_demo_out_5_par_arr_a4.eps").
   170     title("Sample .eps figure (fits to A4)").
   166     title("Sample .eps figure (fits to A4)").
   171     copyright("(C) 2003-2007 LEMON Project").
   167     copyright("(C) 2003-2008 LEMON Project").
   172     absoluteNodeSizes().absoluteArcWidths().
   168     scaleToA4().
   173     nodeScale(2).nodeSizes(sizes).
   169     absoluteNodeSizes().absoluteArcWidths().
   174     coords(coords).
   170     nodeScale(2).nodeSizes(sizes).
   175     nodeShapes(shapes).
   171     coords(coords).
   176     nodeColors(composeMap(palette,colors)).
   172     nodeShapes(shapes).
   177     arcColors(composeMap(palette,ecolors)).
   173     nodeColors(composeMap(palette,colors)).
       
   174     arcColors(composeMap(palette,acolors)).
   178     arcWidthScale(.3).arcWidths(widths).
   175     arcWidthScale(.3).arcWidths(widths).
   179     nodeTexts(id).nodeTextSize(3).
   176     nodeTexts(id).nodeTextSize(3).
   180     enableParallel().parArcDist(1).
   177     enableParallel().parArcDist(1).
   181     drawArrows().arrowWidth(1).arrowLength(1).
   178     drawArrows().arrowWidth(1).arrowLength(1).
   182     run();
   179     run();
   183 
   180 
       
   181   // Create an .eps file showing the colors of a default Palette
   184   ListDigraph h;
   182   ListDigraph h;
   185   ListDigraph::NodeMap<int> hcolors(h);
   183   ListDigraph::NodeMap<int> hcolors(h);
   186   ListDigraph::NodeMap<Point> hcoords(h);
   184   ListDigraph::NodeMap<Point> hcoords(h);
   187   
   185   
   188   int cols=int(sqrt(double(palette.size())));
   186   int cols=int(sqrt(double(palette.size())));
   189   for(int i=0;i<int(paletteW.size());i++) {
   187   for(int i=0;i<int(paletteW.size());i++) {
   190     Node n=h.addNode();
   188     Node n=h.addNode();
   191     hcoords[n]=Point(i%cols,i/cols);
   189     hcoords[n]=Point(1+i%cols,1+i/cols);
   192     hcolors[n]=i;
   190     hcolors[n]=i;
   193   }
   191   }
   194   
   192   
   195   cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
   193   cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl;
   196   graphToEps(h,"graph_to_eps_demo_out_colors.eps").
   194   graphToEps(h,"graph_to_eps_demo_out_6_colors.eps").
   197     //scale(60).
   195     scale(60).
   198     title("Sample .eps figure (Palette demo)").
   196     title("Sample .eps figure (Palette demo)").
   199     copyright("(C) 2003-2007 LEMON Project").
   197     copyright("(C) 2003-2008 LEMON Project").
   200     coords(hcoords).
   198     coords(hcoords).
   201     absoluteNodeSizes().absoluteArcWidths().
   199     absoluteNodeSizes().absoluteArcWidths().
   202     nodeScale(.45).
   200     nodeScale(.45).
   203     distantColorNodeTexts().
   201     distantColorNodeTexts().
   204     //    distantBWNodeTexts().
       
   205     nodeTexts(hcolors).nodeTextSize(.6).
   202     nodeTexts(hcolors).nodeTextSize(.6).
   206     nodeColors(composeMap(paletteW,hcolors)).
   203     nodeColors(composeMap(paletteW,hcolors)).
   207     run();
   204     run();
       
   205     
       
   206   return 0;
   208 }
   207 }