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