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