- Node shapes are shown in the doc.
- The generated PS file is closer to be DSC conform.
2 * src/lemon/graph_to_eps.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef LEMON_GRAPH_TO_EPS_H
18 #define LEMON_GRAPH_TO_EPS_H
27 #include<lemon/maps.h>
28 #include<lemon/bezier.h>
32 ///\brief Simple graph drawer
34 ///\author Alpar Juttner
38 ///Data structure representing RGB colors.
40 ///Data structure representing RGB colors.
46 ///Default constructor
49 Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
50 ///Returns the red component
51 double getR() {return _r;}
52 ///Returns the green component
53 double getG() {return _g;}
54 ///Returns the blue component
55 double getB() {return _b;}
56 ///Set the color components
57 void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
60 ///Default traits class of \ref GraphToEps
62 ///Default traits class of \ref GraphToEps
64 ///\c G is the type of the underlying graph.
66 struct DefaultGraphToEpsTraits
69 typedef typename Graph::Node Node;
70 typedef typename Graph::NodeIt NodeIt;
71 typedef typename Graph::Edge Edge;
72 typedef typename Graph::EdgeIt EdgeIt;
73 typedef typename Graph::InEdgeIt InEdgeIt;
74 typedef typename Graph::OutEdgeIt OutEdgeIt;
81 ConstMap<typename Graph::Node,xy<double> > _coords;
82 ConstMap<typename Graph::Node,double > _nodeSizes;
83 ConstMap<typename Graph::Node,int > _nodeShapes;
85 ConstMap<typename Graph::Node,Color > _nodeColors;
86 ConstMap<typename Graph::Edge,Color > _edgeColors;
88 ConstMap<typename Graph::Edge,double > _edgeWidths;
90 static const double A4HEIGHT = 841.8897637795276;
91 static const double A4WIDTH = 595.275590551181;
92 static const double A4BORDER = 15;
95 double _edgeWidthScale;
98 double _xBorder, _yBorder;
100 double _nodeBorderQuotient;
103 double _arrowLength, _arrowWidth;
105 bool _showNodes, _showEdges;
107 bool _enableParallel;
111 ConstMap<typename Graph::Node,bool > _nodeTexts;
112 double _nodeTextSize;
114 bool _showNodePsText;
115 ConstMap<typename Graph::Node,bool > _nodePsTexts;
116 char *_nodePsTextsPreamble;
119 bool _pleaseRemoveOsStream;
126 ///\param _g is a reference to the graph to be printed
127 ///\param _os is a reference to the output stream.
128 ///\param _os is a reference to the output stream.
129 ///\param _pros If it is \c true, then the \c ostream referenced by \c _os
130 ///will be explicitly deallocated by the destructor.
131 ///By default it is <tt>std::cout</tt>
132 DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
135 _coords(xy<double>(1,1)), _nodeSizes(1.0), _nodeShapes(0),
136 _nodeColors(Color(1,1,1)), _edgeColors(Color(0,0,0)),
137 _edgeWidths(1), _edgeWidthScale(0.3),
138 _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
139 _nodeBorderQuotient(.1),
140 _drawArrows(false), _arrowLength(1), _arrowWidth(0.3),
141 _showNodes(true), _showEdges(true),
142 _enableParallel(false), _parEdgeDist(1),
143 _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
144 _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
146 _pleaseRemoveOsStream(_pros), _scaleToA4(false) {}
149 ///Helper class to implement the named parameters of \ref graphToEps()
151 ///Helper class to implement the named parameters of \ref graphToEps()
152 ///\todo Is 'helper class' a good name for this?
154 ///\todo Follow PostScript's DSC.
155 /// Use own dictionary.
156 ///\todo Provide a way to set %%Title: and %%Copyright:. Set %%CreationDate:
157 ///\todo Useful new features.
158 /// - Linestyles: dotted, dashed etc.
159 /// - A second color and percent value for the lines.
160 template<class T> class GraphToEps : public T
162 typedef typename T::Graph Graph;
163 typedef typename Graph::Node Node;
164 typedef typename Graph::NodeIt NodeIt;
165 typedef typename Graph::Edge Edge;
166 typedef typename Graph::EdgeIt EdgeIt;
167 typedef typename Graph::InEdgeIt InEdgeIt;
168 typedef typename Graph::OutEdgeIt OutEdgeIt;
170 static const int INTERPOL_PREC=20;
181 ///\image html nodeshape_0.png
182 ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm
185 ///\image html nodeshape_1.png
186 ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm
190 ///\image html nodeshape_2.png
191 ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm
200 edgeLess(const Graph &_g) : g(_g) {}
201 bool operator()(Edge a,Edge b) const
203 Node ai=min(g.source(a),g.target(a));
204 Node aa=max(g.source(a),g.target(a));
205 Node bi=min(g.source(b),g.target(b));
206 Node ba=max(g.source(b),g.target(b));
208 (ai==bi && (aa < ba ||
209 (aa==ba && ai==g.source(a) && bi==g.target(b))));
212 bool isParallel(Edge e,Edge f) const
214 return (g.source(e)==g.source(f)&&g.target(e)==g.target(f))||
215 (g.source(e)==g.target(f)&&g.target(e)==g.source(f));
217 static xy<double> rot(xy<double> v)
219 return xy<double>(v.y,-v.x);
222 static std::string psOut(const xy &p)
224 std::ostringstream os;
225 os << p.x << ' ' << p.y;
230 GraphToEps(const T &t) : T(t), dontPrint(false) {};
232 template<class X> struct CoordsTraits : public T {
234 CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {}
236 ///Sets the map of the node coordinates
238 ///Sets the map of the node coordinates.
239 ///\param x must be a node map with xy<double> or \ref xy "xy<int>" values.
240 template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
242 return GraphToEps<CoordsTraits<X> >(CoordsTraits<X>(*this,x));
244 template<class X> struct NodeSizesTraits : public T {
246 NodeSizesTraits(const T &t,const X &x) : T(t), _nodeSizes(x) {}
248 ///Sets the map of the node sizes
250 ///Sets the map of the node sizes
251 ///\param x must be a node map with \c double (or convertible) values.
252 template<class X> GraphToEps<NodeSizesTraits<X> > nodeSizes(const X &x)
255 return GraphToEps<NodeSizesTraits<X> >(NodeSizesTraits<X>(*this,x));
257 template<class X> struct NodeShapesTraits : public T {
258 const X &_nodeShapes;
259 NodeShapesTraits(const T &t,const X &x) : T(t), _nodeShapes(x) {}
261 ///Sets the map of the node shapes
263 ///Sets the map of the node shapes.
264 ///The availabe shape values
265 ///can be found in \ref NodeShapes "enum NodeShapes".
266 ///\param x must be a node map with \c int (or convertible) values.
268 template<class X> GraphToEps<NodeShapesTraits<X> > nodeShapes(const X &x)
271 return GraphToEps<NodeShapesTraits<X> >(NodeShapesTraits<X>(*this,x));
273 template<class X> struct NodeTextsTraits : public T {
275 NodeTextsTraits(const T &t,const X &x) : T(t), _nodeTexts(x) {}
277 ///Sets the text printed on the nodes
279 ///Sets the text printed on the nodes
280 ///\param x must be a node map with type that can be pushed to a standard
282 template<class X> GraphToEps<NodeTextsTraits<X> > nodeTexts(const X &x)
286 return GraphToEps<NodeTextsTraits<X> >(NodeTextsTraits<X>(*this,x));
288 template<class X> struct NodePsTextsTraits : public T {
289 const X &_nodePsTexts;
290 NodePsTextsTraits(const T &t,const X &x) : T(t), _nodePsTexts(x) {}
292 ///Inserts a PostScript block to the nodes
294 ///With this command it is possible to insert a verbatim PostScript
295 ///block to the nodes.
296 ///The PS current point will be moved to the centre of the node before
297 ///the PostScript block inserted.
299 ///Before and after the block a newline character is inserted to you
300 ///don't have to bother with the separators.
302 ///\param x must be a node map with type that can be pushed to a standard
305 ///\sa nodePsTextsPreamble()
306 ///\todo Offer the choise not to move to the centre but pass the coordinates
307 ///to the Postscript block inserted.
308 template<class X> GraphToEps<NodePsTextsTraits<X> > nodePsTexts(const X &x)
311 _showNodePsText=true;
312 return GraphToEps<NodePsTextsTraits<X> >(NodePsTextsTraits<X>(*this,x));
314 template<class X> struct EdgeWidthsTraits : public T {
315 const X &_edgeWidths;
316 EdgeWidthsTraits(const T &t,const X &x) : T(t), _edgeWidths(x) {}
318 ///Sets the map of the edge widths
320 ///Sets the map of the edge widths
321 ///\param x must be a edge map with \c double (or convertible) values.
322 template<class X> GraphToEps<EdgeWidthsTraits<X> > edgeWidths(const X &x)
325 return GraphToEps<EdgeWidthsTraits<X> >(EdgeWidthsTraits<X>(*this,x));
328 template<class X> struct NodeColorsTraits : public T {
329 const X &_nodeColors;
330 NodeColorsTraits(const T &t,const X &x) : T(t), _nodeColors(x) {}
332 ///Sets the map of the node colors
334 ///Sets the map of the node colors
335 ///\param x must be a node map with \ref Color values.
336 template<class X> GraphToEps<NodeColorsTraits<X> >
337 nodeColors(const X &x)
340 return GraphToEps<NodeColorsTraits<X> >(NodeColorsTraits<X>(*this,x));
342 template<class X> struct EdgeColorsTraits : public T {
343 const X &_edgeColors;
344 EdgeColorsTraits(const T &t,const X &x) : T(t), _edgeColors(x) {}
346 ///Sets the map of the edge colors
348 ///Sets the map of the edge colors
349 ///\param x must be a edge map with \ref Color values.
350 template<class X> GraphToEps<EdgeColorsTraits<X> >
351 edgeColors(const X &x)
354 return GraphToEps<EdgeColorsTraits<X> >(EdgeColorsTraits<X>(*this,x));
356 ///Sets a global scale factor for node sizes
358 ///Sets a global scale factor for node sizes
360 GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
361 ///Sets a global scale factor for edge widths
363 ///Sets a global scale factor for edge widths
365 GraphToEps<T> &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;}
366 ///Sets a global scale factor for the whole picture
368 ///Sets a global scale factor for the whole picture
370 GraphToEps<T> &scale(double d) {_scale=d;return *this;}
371 ///Sets the width of the border around the picture
373 ///Sets the width of the border around the picture
375 GraphToEps<T> &border(double b) {_xBorder=_yBorder=b;return *this;}
376 ///Sets the width of the border around the picture
378 ///Sets the width of the border around the picture
380 GraphToEps<T> &border(double x, double y) {
381 _xBorder=x;_yBorder=y;return *this;
383 ///Sets whether to draw arrows
385 ///Sets whether to draw arrows
387 GraphToEps<T> &drawArrows(bool b=true) {_drawArrows=b;return *this;}
388 ///Sets the length of the arrowheads
390 ///Sets the length of the arrowheads
392 GraphToEps<T> &arrowLength(double d) {_arrowLength*=d;return *this;}
393 ///Sets the width of the arrowheads
395 ///Sets the width of the arrowheads
397 GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;}
399 ///Scales the drawing to fit to A4 page
401 ///Scales the drawing to fit to A4 page
403 GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
405 ///Enables parallel edges
407 ///Enables parallel edges
408 ///\todo Partially implemented
409 GraphToEps<T> &enableParallel(bool b=true) {_enableParallel=b;return *this;}
415 GraphToEps<T> &parEdgeDist(double d) {_parEdgeDist*=d;return *this;}
421 GraphToEps<T> &hideEdges(bool b=true) {_showEdges=!b;return *this;}
426 GraphToEps<T> &hideNodes(bool b=true) {_showNodes=!b;return *this;}
428 ///Sets the size of the node texts
430 ///Sets the size of the node texts
432 GraphToEps<T> &nodeTextSize(double d) {_nodeTextSize=d;return *this;}
433 ///Gives a preamble block for node Postscript block.
435 ///Gives a preamble block for node Postscript block.
438 GraphToEps<T> & nodePsTextsPreamble(const char *str) {
439 _nodePsTextsPreamble=s ;return *this;
441 ///Sets whether the the graph is undirected
443 ///Sets whether the the graph is undirected
445 GraphToEps<T> &undir(bool b=true) {_undir=b;return *this;}
446 ///Sets whether the the graph is directed
448 ///Sets whether the the graph is directed.
449 ///Use it to show the undirected edges as a pair of directed ones.
450 GraphToEps<T> &bidir(bool b=true) {_undir=!b;return *this;}
453 bool isInsideNode(xy<double> p, double r,int t)
457 return p.normSquare()<=r*r;
459 return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r;
461 return p.x+p.y<=r && p.x-p.y<=r && -p.x+p.y<=r && -p.x-p.y<=r;
471 ///Like other functions using
472 ///\ref named-templ-func-param "named template parameters",
473 ///this function calles the algorithm itself, i.e. in this case
474 ///it draws the graph.
476 if(dontPrint) return;
478 os << "%!PS-Adobe-2.0 EPSF-2.0\n";
479 os << "%%Title: LEMON GraphToEps figure\n" ///\todo setTitle() is needed
480 // << "%%Copyright: XXXX\n"
481 << "%%Creator: LEMON GraphToEps function\n"
482 // << "%%CreationDate: XXXXXXX\n"
484 ///\todo: Chech whether the graph is empty.
485 BoundingBox<double> bb;
486 for(NodeIt n(g);n!=INVALID;++n) {
487 double ns=_nodeSizes[n]*_nodeScale;
492 if(!_scaleToA4) os << "%%BoundingBox: "
493 << bb.left()* _scale-_xBorder << ' '
494 << bb.bottom()*_scale-_yBorder << ' '
495 << bb.right()* _scale+_xBorder << ' '
496 << bb.top()* _scale+_yBorder << '\n';
498 os << "%%EndComments\n";
500 //x1 y1 x2 y2 x3 y3 cr cg cb w
501 os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
502 << " 4 2 roll 1 index 1 index curveto stroke } bind def\n";
503 os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n";
505 os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def\n";
507 os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n"
508 << " 2 index 1 index sub 2 index 2 index add lineto\n"
509 << " 2 index 1 index sub 2 index 2 index sub lineto\n"
510 << " 2 index 1 index add 2 index 2 index sub lineto\n"
511 << " closepath pop pop pop} bind def\n";
513 os << "/di { newpath 2 index 1 index add 2 index moveto\n"
514 << " 2 index 2 index 2 index add lineto\n"
515 << " 2 index 1 index sub 2 index lineto\n"
516 << " 2 index 2 index 2 index sub lineto\n"
517 << " closepath pop pop pop} bind def\n";
519 os << "/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill\n"
520 << " setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n"
522 os << "/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill\n"
523 << " setrgbcolor " << 1+_nodeBorderQuotient << " div sq fill\n"
525 os << "/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill\n"
526 << " setrgbcolor " << 1+_nodeBorderQuotient << " div di fill\n"
528 os << "/arrl " << _arrowLength << " def\n";
529 os << "/arrw " << _arrowWidth << " def\n";
531 os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
532 //len w dx_norm dy_norm x1 y1 cr cg cb
533 os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n"
534 << " /w exch def /len exch def\n"
535 // << " 0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke"
536 << " newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto\n"
537 << " len w sub arrl sub dx dy lrl\n"
538 << " arrw dy dx neg lrl\n"
539 << " dx arrl w add mul dy w 2 div arrw add mul sub\n"
540 << " dy arrl w add mul dx w 2 div arrw add mul add rlineto\n"
541 << " dx arrl w add mul neg dy w 2 div arrw add mul sub\n"
542 << " dy arrl w add mul neg dx w 2 div arrw add mul add rlineto\n"
543 << " arrw dy dx neg lrl\n"
544 << " len w sub arrl sub neg dx dy lrl\n"
545 << " closepath fill } bind def\n";
546 os << "/cshow { 2 index 2 index moveto dup stringwidth pop\n"
547 << " neg 2 div fosi .35 mul neg rmoveto show pop pop} def\n";
551 if(bb.height()>bb.width()) {
552 double sc= min((A4HEIGHT-2*A4BORDER)/bb.height(),
553 (A4WIDTH-2*A4BORDER)/bb.width());
554 os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' '
555 << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER << " translate\n"
556 << sc << " dup scale\n"
557 << -bb.left() << ' ' << -bb.bottom() << " translate\n";
560 //\todo Verify centering
561 double sc= min((A4HEIGHT-2*A4BORDER)/bb.width(),
562 (A4WIDTH-2*A4BORDER)/bb.height());
563 os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' '
564 << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER << " translate\n"
565 << sc << " dup scale\n90 rotate\n"
566 << -bb.left() << ' ' << -bb.top() << " translate\n";
568 else if(_scale!=1.0) os << _scale << " dup scale\n";
571 os << "%Edges:\ngsave\n";
572 if(_enableParallel) {
573 std::vector<Edge> el;
574 for(EdgeIt e(g);e!=INVALID;++e)
575 if(!_undir||g.source(e)<g.target(e)) el.push_back(e);
576 sort(el.begin(),el.end(),edgeLess(g));
578 typename std::vector<Edge>::iterator j;
579 for(typename std::vector<Edge>::iterator i=el.begin();i!=el.end();i=j) {
580 for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ;
583 for(typename std::vector<Edge>::iterator e=i;e!=j;++e)
584 sw+=_edgeWidths[*e]*_edgeWidthScale+_parEdgeDist;
587 xy<double> dvec(_coords[g.target(*i)]-_coords[g.source(*i)]);
588 double l=sqrt(dvec.normSquare());
589 xy<double> d(dvec/l);
591 // m=xy<double>(_coords[g.target(*i)]+_coords[g.source(*i)])/2.0;
593 // m=xy<double>(_coords[g.source(*i)])+
594 // dvec*(double(_nodeSizes[g.source(*i)])/
595 // (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
597 m=xy<double>(_coords[g.source(*i)])+
598 d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
600 for(typename std::vector<Edge>::iterator e=i;e!=j;++e) {
601 sw+=_edgeWidths[*e]*_edgeWidthScale/2.0;
602 xy<double> mm=m+rot(d)*sw/.75;
605 xy<double> s=_coords[g.source(*e)];
606 xy<double> t=_coords[g.target(*e)];
607 double rn=_nodeSizes[g.target(*e)]*_nodeScale;
608 node_shape=_nodeShapes[g.target(*e)];
609 Bezier3 bez(s,mm,mm,t);
611 for(int i=0;i<INTERPOL_PREC;++i)
612 if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t2=(t1+t2)/2;
614 xy<double> apoint=bez((t1+t2)/2);
615 rn = _arrowLength+_edgeWidths[*e]*_edgeWidthScale;
618 for(int i=0;i<INTERPOL_PREC;++i)
619 if((bez((t1+t2)/2)-apoint).normSquare()>rn) t1=(t1+t2)/2;
621 xy<double> linend=bez((t1+t2)/2);
622 bez=bez.before((t1+t2)/2);
623 // rn=_nodeSizes[g.source(*e)]*_nodeScale;
624 // node_shape=_nodeShapes[g.source(*e)];
626 // for(int i=0;i<INTERPOL_PREC;++i)
627 // if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t1=(t1+t2)/2;
628 // else t2=(t1+t2)/2;
629 // bez=bez.after((t1+t2)/2);
630 os << _edgeWidths[*e]*_edgeWidthScale << " setlinewidth "
631 << _edgeColors[*e].getR() << ' '
632 << _edgeColors[*e].getG() << ' '
633 << _edgeColors[*e].getB() << " setrgbcolor newpath\n"
634 << bez.p1.x << ' ' << bez.p1.y << " moveto\n"
635 << bez.p2.x << ' ' << bez.p2.y << ' '
636 << bez.p3.x << ' ' << bez.p3.y << ' '
637 << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
638 xy<double> dd(rot(linend-apoint));
639 dd*=(.5*_edgeWidths[*e]*_edgeWidthScale+_arrowWidth)/
640 sqrt(dd.normSquare());
641 os << "newpath " << psOut(apoint) << " moveto "
642 << psOut(linend+dd) << " lineto "
643 << psOut(linend-dd) << " lineto closepath fill\n";
646 os << _coords[g.source(*e)].x << ' '
647 << _coords[g.source(*e)].y << ' '
648 << mm.x << ' ' << mm.y << ' '
649 << _coords[g.target(*e)].x << ' '
650 << _coords[g.target(*e)].y << ' '
651 << _edgeColors[*e].getR() << ' '
652 << _edgeColors[*e].getG() << ' '
653 << _edgeColors[*e].getB() << ' '
654 << _edgeWidths[*e]*_edgeWidthScale << " lb\n";
656 sw+=_edgeWidths[*e]*_edgeWidthScale/2.0+_parEdgeDist;
660 else for(EdgeIt e(g);e!=INVALID;++e)
661 if(!_undir||g.source(e)<g.target(e))
663 xy<double> d(_coords[g.target(e)]-_coords[g.source(e)]);
664 double rn=_nodeSizes[g.target(e)]*_nodeScale;
665 int node_shape=_nodeShapes[g.target(e)];
667 for(int i=0;i<INTERPOL_PREC;++i)
668 if(isInsideNode((-(t1+t2)/2)*d,rn,node_shape)) t1=(t1+t2)/2;
670 double l=sqrt(d.normSquare());
673 os << l*(1-(t1+t2)/2) << ' '
674 << _edgeWidths[e]*_edgeWidthScale << ' '
675 << d.x << ' ' << d.y << ' '
676 << _coords[g.source(e)].x << ' '
677 << _coords[g.source(e)].y << ' '
678 << _edgeColors[e].getR() << ' '
679 << _edgeColors[e].getG() << ' '
680 << _edgeColors[e].getB() << " arr\n";
682 else os << _coords[g.source(e)].x << ' '
683 << _coords[g.source(e)].y << ' '
684 << _coords[g.target(e)].x << ' '
685 << _coords[g.target(e)].y << ' '
686 << _edgeColors[e].getR() << ' '
687 << _edgeColors[e].getG() << ' '
688 << _edgeColors[e].getB() << ' '
689 << _edgeWidths[e]*_edgeWidthScale << " l\n";
693 os << "%Nodes:\ngsave\n";
694 for(NodeIt n(g);n!=INVALID;++n) {
695 os << _coords[n].x << ' ' << _coords[n].y << ' '
696 << _nodeSizes[n]*_nodeScale << ' '
697 << _nodeColors[n].getR() << ' '
698 << _nodeColors[n].getG() << ' '
699 << _nodeColors[n].getB() << ' ';
700 switch(_nodeShapes[n]) {
713 os << "%Node texts:\ngsave\n";
714 os << "/fosi " << _nodeTextSize << " def\n";
715 os << "(Helvetica) findfont fosi scalefont setfont\n";
716 os << "0 0 0 setrgbcolor\n";
717 for(NodeIt n(g);n!=INVALID;++n)
718 os << _coords[n].x << ' ' << _coords[n].y
719 << " (" << _nodeTexts[n] << ") cshow\n";
722 if(_showNodePsText) {
723 os << "%Node PS blocks:\ngsave\n";
724 for(NodeIt n(g);n!=INVALID;++n)
725 os << _coords[n].x << ' ' << _coords[n].y
726 << " moveto\n" << _nodePsTexts[n] << "\n";
730 os << "grestore\nshowpage\n";
733 if(_pleaseRemoveOsStream) {delete &os;}
738 ///Generates an EPS file from a graph
741 ///Generates an EPS file from a graph.
742 ///\param g is a reference to the graph to be printed
743 ///\param os is a reference to the output stream.
744 ///By default it is <tt>std::cout</tt>
746 ///This function also has a lot of
747 ///\ref named-templ-func-param "named parameters",
748 ///they are declared as the members of class \ref GraphToEps. The following
749 ///example shows how to use these parameters.
751 /// graphToEps(g).scale(10).coords(coords)
752 /// .nodeScale(2).nodeSizes(sizes)
753 /// .edgeWidthScale(.4).run();
755 ///\warning Don't forget to put the \ref GraphToEps::run() "run()"
756 ///to the end of the parameter list.
758 ///\sa graphToEps(G &g, char *file_name)
760 GraphToEps<DefaultGraphToEpsTraits<G> >
761 graphToEps(G &g, std::ostream& os=std::cout)
764 GraphToEps<DefaultGraphToEpsTraits<G> >(DefaultGraphToEpsTraits<G>(g,os));
767 ///Generates an EPS file from a graph
770 ///This function does the same as
771 ///\ref graphToEps(G &g,std::ostream& os)
772 ///but it writes its output into the file \c file_name
773 ///instead of a stream.
774 ///\sa graphToEps(G &g, std::ostream& os)
776 GraphToEps<DefaultGraphToEpsTraits<G> >
777 graphToEps(G &g,const char *file_name)
779 return GraphToEps<DefaultGraphToEpsTraits<G> >
780 (DefaultGraphToEpsTraits<G>(g,*new std::ofstream(file_name),true));
783 } //END OF NAMESPACE LEMON
785 #endif // LEMON_GRAPH_TO_EPS_H