gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Improvements related to graphToEps()
0 3 0
default
3 files changed with 98 insertions and 160 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -20,3 +20,3 @@
20 20
/// \file
21
/// \brief Demo of the graph grawing function \ref graphToEps()
21
/// \brief Demo of the graph drawing function \ref graphToEps()
22 22
///
... ...
@@ -25,3 +25,3 @@
25 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 27
/// how to handle parallel egdes, how to change the properties (like
... ...
@@ -32,7 +32,6 @@
32 32

	
33
#include <lemon/math.h>
34

	
35
#include<lemon/graph_to_eps.h>
36 33
#include<lemon/list_graph.h>
37 34
#include<lemon/graph_utils.h>
35
#include<lemon/graph_to_eps.h>
36
#include<lemon/math.h>
38 37

	
... ...
@@ -46,2 +45,3 @@
46 45

	
46
  // Create a small digraph
47 47
  ListDigraph g;
... ...
@@ -62,3 +62,3 @@
62 62
  ListDigraph::NodeMap<int> shapes(g);
63
  ListDigraph::ArcMap<int> ecolors(g);
63
  ListDigraph::ArcMap<int> acolors(g);
64 64
  ListDigraph::ArcMap<int> widths(g);
... ...
@@ -71,11 +71,11 @@
71 71
  
72
  Arc e;
72
  Arc a;
73 73

	
74
  e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1;
75
  e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1;
76
  e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3;
77
  e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1;
78
  e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1;
79
  e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2;
80
  e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1;
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;
81 81
  
... ...
@@ -83,16 +83,15 @@
83 83

	
84
  cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
85
  graphToEps(g,"graph_to_eps_demo_out_pure.eps").
86
    //scale(10).
84
  // Create five .eps files showing the digraph with different options
85
  cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
86
  graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
87 87
    coords(coords).
88 88
    title("Sample .eps figure").
89
    copyright("(C) 2003-2007 LEMON Project").
89
    copyright("(C) 2003-2008 LEMON Project").
90 90
    run();
91 91

	
92
  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
93
  graphToEps(g,"graph_to_eps_demo_out.eps").
94
    //scale(10).
92
  cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
93
  graphToEps(g,"graph_to_eps_demo_out_2.eps").
95 94
    coords(coords).
96 95
    title("Sample .eps figure").
97
    copyright("(C) 2003-2007 LEMON Project").
96
    copyright("(C) 2003-2008 LEMON Project").
98 97
    absoluteNodeSizes().absoluteArcWidths().
... ...
@@ -101,3 +100,3 @@
101 100
    nodeColors(composeMap(palette,colors)).
102
    arcColors(composeMap(palette,ecolors)).
101
    arcColors(composeMap(palette,acolors)).
103 102
    arcWidthScale(.4).arcWidths(widths).
... ...
@@ -106,8 +105,6 @@
106 105

	
107

	
108
  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
109
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").
110
    //scale(10).
106
  cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
107
  graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
111 108
    title("Sample .eps figure (with arrowheads)").
112
    copyright("(C) 2003-2007 LEMON Project").
109
    copyright("(C) 2003-2008 LEMON Project").
113 110
    absoluteNodeSizes().absoluteArcWidths().
... ...
@@ -117,18 +114,18 @@
117 114
    nodeShapes(shapes).
118
    arcColors(composeMap(palette,ecolors)).
115
    arcColors(composeMap(palette,acolors)).
119 116
    arcWidthScale(.4).arcWidths(widths).
120 117
    nodeTexts(id).nodeTextSize(3).
121
    drawArrows().arrowWidth(1).arrowLength(1).
118
    drawArrows().arrowWidth(2).arrowLength(2).
122 119
    run();
123 120

	
124
  e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1;
125
  e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=2;
121
  a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
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;
128
  e=g.addArc(n1,n2); ecolors[e]=2; widths[e]=1;
129
  e=g.addArc(n1,n2); ecolors[e]=3; widths[e]=1;
130
  e=g.addArc(n1,n2); ecolors[e]=4; widths[e]=1;
131
  e=g.addArc(n1,n2); ecolors[e]=5; widths[e]=1;
132
  e=g.addArc(n1,n2); ecolors[e]=6; widths[e]=1;
133
  e=g.addArc(n1,n2); ecolors[e]=7; widths[e]=1;
124
  a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
125
  a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
126
  a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
127
  a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
128
  a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
129
  a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
130
  a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
134 131

	
... ...
@@ -138,3 +135,3 @@
138 135
    title("Sample .eps figure (parallel arcs)").
139
    copyright("(C) 2003-2007 LEMON Project").
136
    copyright("(C) 2003-2008 LEMON Project").
140 137
    absoluteNodeSizes().absoluteArcWidths().
... ...
@@ -144,3 +141,3 @@
144 141
    nodeColors(composeMap(palette,colors)).
145
    arcColors(composeMap(palette,ecolors)).
142
    arcColors(composeMap(palette,acolors)).
146 143
    arcWidthScale(.4).arcWidths(widths).
... ...
@@ -149,8 +146,7 @@
149 146
    run();
150
  
151
  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
152
  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
153
    //scale(10).
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").
154 150
    title("Sample .eps figure (parallel arcs and arrowheads)").
155
    copyright("(C) 2003-2007 LEMON Project").
151
    copyright("(C) 2003-2008 LEMON Project").
156 152
    absoluteNodeSizes().absoluteArcWidths().
... ...
@@ -160,3 +156,3 @@
160 156
    nodeColors(composeMap(palette,colors)).
161
    arcColors(composeMap(palette,ecolors)).
157
    arcColors(composeMap(palette,acolors)).
162 158
    arcWidthScale(.3).arcWidths(widths).
... ...
@@ -167,6 +163,7 @@
167 163

	
168
  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
169
  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
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").
170 166
    title("Sample .eps figure (fits to A4)").
171
    copyright("(C) 2003-2007 LEMON Project").
167
    copyright("(C) 2003-2008 LEMON Project").
168
    scaleToA4().
172 169
    absoluteNodeSizes().absoluteArcWidths().
... ...
@@ -176,3 +173,3 @@
176 173
    nodeColors(composeMap(palette,colors)).
177
    arcColors(composeMap(palette,ecolors)).
174
    arcColors(composeMap(palette,acolors)).
178 175
    arcWidthScale(.3).arcWidths(widths).
... ...
@@ -183,2 +180,3 @@
183 180

	
181
  // Create an .eps file showing the colors of a default Palette
184 182
  ListDigraph h;
... ...
@@ -190,3 +188,3 @@
190 188
    Node n=h.addNode();
191
    hcoords[n]=Point(i%cols,i/cols);
189
    hcoords[n]=Point(1+i%cols,1+i/cols);
192 190
    hcolors[n]=i;
... ...
@@ -194,7 +192,7 @@
194 192
  
195
  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
196
  graphToEps(h,"graph_to_eps_demo_out_colors.eps").
197
    //scale(60).
193
  cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl;
194
  graphToEps(h,"graph_to_eps_demo_out_6_colors.eps").
195
    scale(60).
198 196
    title("Sample .eps figure (Palette demo)").
199
    copyright("(C) 2003-2007 LEMON Project").
197
    copyright("(C) 2003-2008 LEMON Project").
200 198
    coords(hcoords).
... ...
@@ -203,3 +201,2 @@
203 201
    distantColorNodeTexts().
204
    //    distantBWNodeTexts().
205 202
    nodeTexts(hcolors).nodeTextSize(.6).
... ...
@@ -207,2 +204,4 @@
207 204
    run();
205
    
206
  return 0;
208 207
}
Ignore white space 6 line context
... ...
@@ -110,7 +110,7 @@
110 110

	
111
    ///Constructor 
112
    ///\param have_white indicates whether white is amongst the
111
    ///Constructor.
112
    ///\param have_white Indicates whether white is among the
113 113
    ///provided initial colors (\c true) or not (\c false). If it is true,
114 114
    ///white will be assigned to \c 0.
115
    ///\param num the number of the allocated colors. If it is \c -1,
115
    ///\param num The number of the allocated colors. If it is \c -1,
116 116
    ///the default color configuration is set up (26 color plus optionaly the
... ...
@@ -155,3 +155,2 @@
155 155
      } while(int(colors.size())<num);
156
      //    colors.push_back(Color(1,1,1));
157 156
      if(num>=0) colors.resize(num);
... ...
@@ -173,3 +172,3 @@
173 172
    }
174
    ///Add a new color to the end of the color list.
173
    ///Adds a new color to the end of the color list.
175 174
    void add(const Color &c) 
... ...
@@ -179,3 +178,3 @@
179 178

	
180
    ///Sets the number of the exiting colors.
179
    ///Sets the number of the existing colors.
181 180
    void resize(int s) { colors.resize(s);}
Show white space 6 line context
... ...
@@ -65,3 +65,3 @@
65 65

	
66
///Default traits class of \ref GraphToEps
66
///Default traits class of \ref GraphToEps.
67 67
///
... ...
@@ -142,8 +142,7 @@
142 142
  ///Constructor
143
  ///\param _g is a reference to the graph to be printed
144
  ///\param _os is a reference to the output stream.
145
  ///\param _os is a reference to the output stream.
143
  ///\param _g  Reference to the graph to be printed.
144
  ///\param _os Reference to the output stream.
145
  ///\param _os Reference to the output stream. By default it is <tt>std::cout</tt>.
146 146
  ///\param _pros If it is \c true, then the \c ostream referenced by \c _os
147 147
  ///will be explicitly deallocated by the destructor.
148
  ///By default it is <tt>std::cout</tt>
149 148
  DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
... ...
@@ -175,3 +174,5 @@
175 174

	
176
///Auxiliary class to implement the named parameters of \ref graphToEps()
175
///Auxiliary class to implement the named parameters of \ref graphToEps().
176
///
177
///For detailed examples see the \ref graph_to_eps_demo.cc demo file.
177 178
template<class T> class GraphToEps : public T 
... ...
@@ -260,3 +261,3 @@
260 261

	
261
  ///Node shapes
262
  ///Node shapes.
262 263
  ///
... ...
@@ -337,3 +338,3 @@
337 338
  ///Sets the map of the node coordinates.
338
  ///\param x must be a node map with dim2::Point<double> or
339
  ///\param x must be a node map with \ref dim2::Point "dim2::Point<double>" or
339 340
  ///\ref dim2::Point "dim2::Point<int>" values. 
... ...
@@ -349,3 +350,3 @@
349 350

	
350
  ///Sets the map of the node sizes
351
  ///Sets the map of the node sizes.
351 352
  ///\param x must be a node map with \c double (or convertible) values. 
... ...
@@ -378,5 +379,5 @@
378 379

	
379
  ///Sets the text printed on the nodes
380
  ///Sets the text printed on the nodes.
380 381
  ///\param x must be a node map with type that can be pushed to a standard
381
  ///ostream. 
382
  ///\c ostream. 
382 383
  template<class X> GraphToEps<NodeTextsTraits<X> > nodeTexts(const X &x)
... ...
@@ -395,3 +396,3 @@
395 396
  ///block to the nodes.
396
  ///The PS current point will be moved to the centre of the node before
397
  ///The PS current point will be moved to the center of the node before
397 398
  ///the PostScript block inserted.
... ...
@@ -402,3 +403,3 @@
402 403
  ///\param x must be a node map with type that can be pushed to a standard
403
  ///ostream.
404
  ///\c ostream.
404 405
  ///
... ...
@@ -417,3 +418,3 @@
417 418

	
418
  ///Sets the map of the arc widths
419
  ///Sets the map of the arc widths.
419 420
  ///\param x must be an arc map with \c double (or convertible) values. 
... ...
@@ -431,3 +432,3 @@
431 432

	
432
  ///Sets the map of the node colors
433
  ///Sets the map of the node colors.
433 434
  ///\param x must be a node map with \ref Color values.
... ...
@@ -447,3 +448,3 @@
447 448

	
448
  ///Sets the map of the node text colors
449
  ///Sets the map of the node text colors.
449 450
  ///\param x must be a node map with \ref Color values. 
... ...
@@ -465,3 +466,3 @@
465 466

	
466
  ///Sets the map of the arc colors
467
  ///Sets the map of the arc colors.
467 468
  ///\param x must be an arc map with \ref Color values. 
... ...
@@ -489,5 +490,5 @@
489 490
  GraphToEps<T> &nodeScale(double d=.01) {_nodeScale=d;return *this;}
490
  ///Turns on/off the automatic node width scaling.
491
  ///Turns on/off the automatic node size scaling.
491 492

	
492
  ///Turns on/off the automatic node width scaling.
493
  ///Turns on/off the automatic node size scaling.
493 494
  ///
... ...
@@ -499,5 +500,5 @@
499 500

	
500
  ///Turns on/off the absolutematic node width scaling.
501
  ///Turns on/off the absolutematic node size scaling.
501 502

	
502
  ///Turns on/off the absolutematic node width scaling.
503
  ///Turns on/off the absolutematic node size scaling.
503 504
  ///
... ...
@@ -510,5 +511,2 @@
510 511
  ///Negates the Y coordinates.
511

	
512
  ///Negates the Y coordinates.
513
  ///
514 512
  GraphToEps<T> &negateY(bool b=true) {
... ...
@@ -559,16 +557,6 @@
559 557
  ///Sets a global scale factor for the whole picture
560

	
561
  ///Sets a global scale factor for the whole picture
562
  ///
563

	
564 558
  GraphToEps<T> &scale(double d) {_scale=d;return *this;}
565 559
  ///Sets the width of the border around the picture
566

	
567
  ///Sets the width of the border around the picture
568
  ///
569 560
  GraphToEps<T> &border(double b=10) {_xBorder=_yBorder=b;return *this;}
570 561
  ///Sets the width of the border around the picture
571

	
572
  ///Sets the width of the border around the picture
573
  ///
574 562
  GraphToEps<T> &border(double x, double y) {
... ...
@@ -577,15 +565,6 @@
577 565
  ///Sets whether to draw arrows
578

	
579
  ///Sets whether to draw arrows
580
  ///
581 566
  GraphToEps<T> &drawArrows(bool b=true) {_drawArrows=b;return *this;}
582 567
  ///Sets the length of the arrowheads
583

	
584
  ///Sets the length of the arrowheads
585
  ///
586 568
  GraphToEps<T> &arrowLength(double d=1.0) {_arrowLength*=d;return *this;}
587 569
  ///Sets the width of the arrowheads
588

	
589
  ///Sets the width of the arrowheads
590
  ///
591 570
  GraphToEps<T> &arrowWidth(double d=.3) {_arrowWidth*=d;return *this;}
... ...
@@ -593,5 +572,2 @@
593 572
  ///Scales the drawing to fit to A4 page
594

	
595
  ///Scales the drawing to fit to A4 page
596
  ///
597 573
  GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
... ...
@@ -599,10 +575,5 @@
599 575
  ///Enables parallel arcs
600

	
601
  ///Enables parallel arcs
602 576
  GraphToEps<T> &enableParallel(bool b=true) {_enableParallel=b;return *this;}
603 577
  
604
  ///Sets the distance 
605
  
606
  ///Sets the distance 
607
  ///
578
  ///Sets the distance between parallel arcs
608 579
  GraphToEps<T> &parArcDist(double d) {_parArcDist*=d;return *this;}
... ...
@@ -610,10 +581,4 @@
610 581
  ///Hides the arcs
611
  
612
  ///Hides the arcs
613
  ///
614 582
  GraphToEps<T> &hideArcs(bool b=true) {_showArcs=!b;return *this;}
615 583
  ///Hides the nodes
616
  
617
  ///Hides the nodes
618
  ///
619 584
  GraphToEps<T> &hideNodes(bool b=true) {_showNodes=!b;return *this;}
... ...
@@ -621,5 +586,2 @@
621 586
  ///Sets the size of the node texts
622
  
623
  ///Sets the size of the node texts
624
  ///
625 587
  GraphToEps<T> &nodeTextSize(double d) {_nodeTextSize=d;return *this;}
... ...
@@ -629,4 +591,3 @@
629 591
  ///Sets the color of the node texts to be as different from the node color
630
  ///as it is possible
631
  ///
592
  ///as it is possible.
632 593
  GraphToEps<T> &distantColorNodeTexts()
... ...
@@ -636,5 +597,3 @@
636 597
  ///Sets the color of the node texts to be black or white according to
637
  ///which is more 
638
  ///different from the node color
639
  ///
598
  ///which is more different from the node color.
640 599
  GraphToEps<T> &distantBWNodeTexts()
... ...
@@ -650,5 +609,5 @@
650 609
  }
651
  ///Sets whether the the graph is undirected
610
  ///Sets whether the graph is undirected
652 611

	
653
  ///Sets whether the the graph is undirected.
612
  ///Sets whether the graph is undirected.
654 613
  ///
... ...
@@ -659,5 +618,5 @@
659 618

	
660
  ///Sets whether the the graph is directed
619
  ///Sets whether the graph is directed
661 620

	
662
  ///Sets whether the the graph is directed.
621
  ///Sets whether the graph is directed.
663 622
  ///Use it to show the edges as a pair of directed ones.
... ...
@@ -718,3 +677,2 @@
718 677
     if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n';
719
//        << "%%Copyright: XXXX\n"
720 678
    os << "%%Creator: LEMON, graphToEps()\n";
... ...
@@ -750,3 +708,3 @@
750 708
	max_w=std::max(double(_arcWidths[e]),max_w);
751
      ///\todo better 'epsilon' would be nice here.
709
      //\todo better 'epsilon' would be nice here.
752 710
      if(max_w>EPSILON) {
... ...
@@ -760,3 +718,3 @@
760 718
	max_s=std::max(double(_nodeSizes[n]),max_s);
761
      ///\todo better 'epsilon' would be nice here.
719
      //\todo better 'epsilon' would be nice here.
762 720
      if(max_s>EPSILON) {
... ...
@@ -1116,5 +1074,2 @@
1116 1074
  ///An alias for arcWidths()
1117

	
1118
  ///An alias for arcWidths()
1119
  ///
1120 1075
  template<class X> GraphToEps<ArcWidthsTraits<X> > edgeWidths(const X &x)
... ...
@@ -1125,5 +1080,2 @@
1125 1080
  ///An alias for arcColors()
1126

	
1127
  ///An alias for arcColors()
1128
  ///
1129 1081
  template<class X> GraphToEps<ArcColorsTraits<X> >
... ...
@@ -1135,5 +1087,2 @@
1135 1087
  ///An alias for arcWidthScale()
1136

	
1137
  ///An alias for arcWidthScale()
1138
  ///
1139 1088
  GraphToEps<T> &edgeWidthScale(double d) {return arcWidthScale(d);}
... ...
@@ -1141,5 +1090,2 @@
1141 1090
  ///An alias for autoArcWidthScale()
1142

	
1143
  ///An alias for autoArcWidthScale()
1144
  ///
1145 1091
  GraphToEps<T> &autoEdgeWidthScale(bool b=true)
... ...
@@ -1150,5 +1096,2 @@
1150 1096
  ///An alias for absoluteArcWidths()
1151

	
1152
  ///An alias for absoluteArcWidths()
1153
  ///
1154 1097
  GraphToEps<T> &absoluteEdgeWidths(bool b=true)
... ...
@@ -1159,5 +1102,2 @@
1159 1102
  ///An alias for parArcDist()
1160

	
1161
  ///An alias for parArcDist()
1162
  ///
1163 1103
  GraphToEps<T> &parEdgeDist(double d) {return parArcDist(d);}
... ...
@@ -1165,5 +1105,2 @@
1165 1105
  ///An alias for hideArcs()
1166
  
1167
  ///An alias for hideArcs()
1168
  ///
1169 1106
  GraphToEps<T> &hideEdges(bool b=true) {return hideArcs(b);}
... ...
@@ -1187,5 +1124,5 @@
1187 1124
///Generates an EPS file from a graph.
1188
///\param g is a reference to the graph to be printed
1189
///\param os is a reference to the output stream.
1190
///By default it is <tt>std::cout</tt>
1125
///\param g Reference to the graph to be printed.
1126
///\param os Reference to the output stream.
1127
///By default it is <tt>std::cout</tt>.
1191 1128
///
... ...
@@ -1200,2 +1137,5 @@
1200 1137
///\endcode
1138
///
1139
///For more detailed examples see the \ref graph_to_eps_demo.cc demo file.
1140
///
1201 1141
///\warning Don't forget to put the \ref GraphToEps::run() "run()"
0 comments (0 inline)