alpar@1073: /* -*- C++ -*- alpar@1073: * src/lemon/graph_to_eps.h - Part of LEMON, a generic C++ optimization library alpar@1073: * alpar@1073: * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1073: * (Egervary Combinatorial Optimization Research Group, EGRES). alpar@1073: * alpar@1073: * Permission to use, modify and distribute this software is granted alpar@1073: * provided that this copyright notice appears in all copies. For alpar@1073: * precise terms see the accompanying LICENSE file. alpar@1073: * alpar@1073: * This software is provided "AS IS" with no warranty of any kind, alpar@1073: * express or implied, and with no claim as to its suitability for any alpar@1073: * purpose. alpar@1073: * alpar@1073: */ alpar@1073: alpar@1073: #ifndef LEMON_GRAPH_TO_EPS_H alpar@1073: #define LEMON_GRAPH_TO_EPS_H alpar@1073: alpar@1073: #include alpar@1073: #include alpar@1073: #include alpar@1073: #include alpar@1073: #include alpar@1073: alpar@1073: #include alpar@1073: #include alpar@1073: #include alpar@1073: alpar@1073: ///\ingroup misc alpar@1073: ///\file alpar@1073: ///\brief Simple graph drawer alpar@1073: /// alpar@1073: ///\author Alpar Juttner alpar@1073: alpar@1073: namespace lemon { alpar@1073: alpar@1073: ///Data structure representing RGB colors. alpar@1073: alpar@1073: ///Data structure representing RGB colors. alpar@1073: ///\ingroup misc alpar@1073: class Color alpar@1073: { alpar@1073: double _r,_g,_b; alpar@1073: public: alpar@1073: ///Default constructor alpar@1073: Color() {} alpar@1073: ///Constructor alpar@1073: Color(double r,double g,double b) :_r(r),_g(g),_b(b) {}; alpar@1073: ///Returns the red component alpar@1073: double getR() {return _r;} alpar@1073: ///Returns the green component alpar@1073: double getG() {return _g;} alpar@1073: ///Returns the blue component alpar@1073: double getB() {return _b;} alpar@1073: ///Set the color components alpar@1073: void set(double r,double g,double b) { _r=r;_g=g;_b=b; }; alpar@1073: }; alpar@1073: alpar@1073: ///Default traits class of \ref GraphToEps alpar@1073: alpar@1073: ///Default traits class of \ref GraphToEps alpar@1073: /// alpar@1073: ///\c G is the type of the underlying graph. alpar@1073: template alpar@1073: struct DefaultGraphToEpsTraits alpar@1073: { alpar@1073: typedef G Graph; alpar@1073: typedef typename Graph::Node Node; alpar@1073: typedef typename Graph::NodeIt NodeIt; alpar@1073: typedef typename Graph::Edge Edge; alpar@1073: typedef typename Graph::EdgeIt EdgeIt; alpar@1073: typedef typename Graph::InEdgeIt InEdgeIt; alpar@1073: typedef typename Graph::OutEdgeIt OutEdgeIt; alpar@1073: alpar@1073: alpar@1073: const Graph &g; alpar@1073: alpar@1073: std::ostream& os; alpar@1073: alpar@1073: ConstMap > _coords; alpar@1073: ConstMap _nodeSizes; alpar@1073: alpar@1073: ConstMap _nodeColors; alpar@1073: ConstMap _edgeColors; alpar@1073: alpar@1073: ConstMap _edgeWidths; alpar@1073: alpar@1073: double _edgeWidthScale; alpar@1073: alpar@1073: double _nodeScale; alpar@1073: double _xBorder, _yBorder; alpar@1073: double _scale; alpar@1073: double _nodeBorderQuotient; alpar@1073: alpar@1073: bool _drawArrows; alpar@1073: double _arrowLength, _arrowWidth; alpar@1073: alpar@1073: bool _showNodes, _showEdges; alpar@1073: alpar@1073: bool _enableParallel; alpar@1073: double _parEdgeDist; alpar@1073: alpar@1073: bool _showNodeText; alpar@1073: ConstMap _nodeTexts; alpar@1073: double _nodeTextSize; alpar@1073: alpar@1073: bool _undir; alpar@1073: bool _pleaseRemoveOsStream; alpar@1073: ///Constructor alpar@1073: alpar@1073: ///Constructor alpar@1073: ///\param _g is a reference to the graph to be printed alpar@1073: ///\param _os is a reference to the output stream. alpar@1073: ///\param _os is a reference to the output stream. alpar@1073: ///\param _pros If it is \c true, then the \c ostream referenced by \c _os alpar@1073: ///will be explicitly deallocated by the destructor. alpar@1073: ///By default it is std::cout alpar@1073: DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout, alpar@1073: bool _pros=false) : alpar@1073: g(_g), os(_os), alpar@1073: _coords(xy(1,1)), _nodeSizes(1.0), alpar@1073: _nodeColors(Color(1,1,1)), _edgeColors(Color(0,0,0)), alpar@1073: _edgeWidths(1), _edgeWidthScale(0.3), alpar@1073: _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0), alpar@1073: _nodeBorderQuotient(.1), alpar@1073: _drawArrows(false), _arrowLength(1), _arrowWidth(0.3), alpar@1073: _showNodes(true), _showEdges(true), alpar@1073: _enableParallel(false), _parEdgeDist(1), alpar@1073: _showNodeText(false), _nodeTexts(false), _nodeTextSize(1), alpar@1073: _undir(false), alpar@1073: _pleaseRemoveOsStream(_pros) {} alpar@1073: }; alpar@1073: alpar@1073: ///Helper class to implement the named parameters of \ref graphToEps() alpar@1073: alpar@1073: ///Helper class to implement the named parameters of \ref graphToEps() alpar@1073: ///\todo Is 'helper class' a good name for this? alpar@1073: /// alpar@1073: template class GraphToEps : public T alpar@1073: { alpar@1073: typedef typename T::Graph Graph; alpar@1073: typedef typename Graph::Node Node; alpar@1073: typedef typename Graph::NodeIt NodeIt; alpar@1073: typedef typename Graph::Edge Edge; alpar@1073: typedef typename Graph::EdgeIt EdgeIt; alpar@1073: typedef typename Graph::InEdgeIt InEdgeIt; alpar@1073: typedef typename Graph::OutEdgeIt OutEdgeIt; alpar@1073: alpar@1073: bool dontPrint; alpar@1073: alpar@1073: class edgeLess { alpar@1073: const Graph &g; alpar@1073: public: alpar@1073: edgeLess(const Graph &_g) : g(_g) {} alpar@1073: bool operator()(Edge a,Edge b) const alpar@1073: { alpar@1073: Node ai=min(g.source(a),g.target(a)); alpar@1073: Node aa=max(g.source(a),g.target(a)); alpar@1073: Node bi=min(g.source(b),g.target(b)); alpar@1073: Node ba=max(g.source(b),g.target(b)); alpar@1073: return ai rot(xy v) alpar@1073: { alpar@1073: return xy(v.y,-v.x); alpar@1073: } alpar@1073: template alpar@1073: static std::string psOut(const xy &p) alpar@1073: { alpar@1073: std::ostringstream os; alpar@1073: os << p.x << ' ' << p.y; alpar@1073: return os.str(); alpar@1073: } alpar@1073: alpar@1073: public: alpar@1073: GraphToEps(const T &t) : T(t), dontPrint(false) {}; alpar@1073: alpar@1073: template struct CoordsTraits : public T { alpar@1073: const X &_coords; alpar@1073: CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {} alpar@1073: }; alpar@1073: ///Sets the map of the node coordinates alpar@1073: alpar@1073: ///Sets the map of the node coordinates. alpar@1073: ///\param x must be a node map with xy or xy values. alpar@1073: template GraphToEps > coords(const X &x) { alpar@1073: dontPrint=true; alpar@1073: return GraphToEps >(CoordsTraits(*this,x)); alpar@1073: } alpar@1073: template struct NodeSizesTraits : public T { alpar@1073: const X &_nodeSizes; alpar@1073: NodeSizesTraits(const T &t,const X &x) : T(t), _nodeSizes(x) {} alpar@1073: }; alpar@1073: ///Sets the map of the node sizes alpar@1073: alpar@1073: ///Sets the map of the node sizes alpar@1073: ///\param x must be a node map with \c double (or convertible) values. alpar@1073: template GraphToEps > nodeSizes(const X &x) alpar@1073: { alpar@1073: dontPrint=true; alpar@1073: return GraphToEps >(NodeSizesTraits(*this,x)); alpar@1073: } alpar@1073: template struct NodeTextsTraits : public T { alpar@1073: const X &_nodeTexts; alpar@1073: NodeTextsTraits(const T &t,const X &x) : T(t), _nodeTexts(x) {} alpar@1073: }; alpar@1073: ///Sets the text printed on the nodes alpar@1073: alpar@1073: ///Sets the text printed on the nodes alpar@1073: ///\param x must be a node map with type that can be pushed to a standard alpar@1073: ///ostream. alpar@1073: template GraphToEps > nodeTexts(const X &x) alpar@1073: { alpar@1073: dontPrint=true; alpar@1073: _showNodeText=true; alpar@1073: return GraphToEps >(NodeTextsTraits(*this,x)); alpar@1073: } alpar@1073: template struct EdgeWidthsTraits : public T { alpar@1073: const X &_edgeWidths; alpar@1073: EdgeWidthsTraits(const T &t,const X &x) : T(t), _edgeWidths(x) {} alpar@1073: }; alpar@1073: ///Sets the map of the edge widths alpar@1073: alpar@1073: ///Sets the map of the edge widths alpar@1073: ///\param x must be a edge map with \c double (or convertible) values. alpar@1073: template GraphToEps > edgeWidths(const X &x) alpar@1073: { alpar@1073: dontPrint=true; alpar@1073: return GraphToEps >(EdgeWidthsTraits(*this,x)); alpar@1073: } alpar@1073: alpar@1073: template struct NodeColorsTraits : public T { alpar@1073: const X &_nodeColors; alpar@1073: NodeColorsTraits(const T &t,const X &x) : T(t), _nodeColors(x) {} alpar@1073: }; alpar@1073: ///Sets the map of the node colors alpar@1073: alpar@1073: ///Sets the map of the node colors alpar@1073: ///\param x must be a node map with \ref Color values. alpar@1073: template GraphToEps > alpar@1073: nodeColors(const X &x) alpar@1073: { alpar@1073: dontPrint=true; alpar@1073: return GraphToEps >(NodeColorsTraits(*this,x)); alpar@1073: } alpar@1073: template struct EdgeColorsTraits : public T { alpar@1073: const X &_edgeColors; alpar@1073: EdgeColorsTraits(const T &t,const X &x) : T(t), _edgeColors(x) {} alpar@1073: }; alpar@1073: ///Sets the map of the edge colors alpar@1073: alpar@1073: ///Sets the map of the edge colors alpar@1073: ///\param x must be a edge map with \ref Color values. alpar@1073: template GraphToEps > alpar@1073: edgeColors(const X &x) alpar@1073: { alpar@1073: dontPrint=true; alpar@1073: return GraphToEps >(EdgeColorsTraits(*this,x)); alpar@1073: } alpar@1073: ///Sets a global scale factor for node sizes alpar@1073: alpar@1073: ///Sets a global scale factor for node sizes alpar@1073: /// alpar@1073: GraphToEps &nodeScale(double d) {_nodeScale=d;return *this;} alpar@1073: ///Sets a global scale factor for edge widths alpar@1073: alpar@1073: ///Sets a global scale factor for edge widths alpar@1073: /// alpar@1073: GraphToEps &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;} alpar@1073: ///Sets a global scale factor for the whole picture alpar@1073: alpar@1073: ///Sets a global scale factor for the whole picture alpar@1073: /// alpar@1073: GraphToEps &scale(double d) {_scale=d;return *this;} alpar@1073: ///Sets the width of the border around the picture alpar@1073: alpar@1073: ///Sets the width of the border around the picture alpar@1073: /// alpar@1073: GraphToEps &border(double b) {_xBorder=_yBorder=b;return *this;} alpar@1073: ///Sets the width of the border around the picture alpar@1073: alpar@1073: ///Sets the width of the border around the picture alpar@1073: /// alpar@1073: GraphToEps &border(double x, double y) { alpar@1073: _xBorder=x;_yBorder=y;return *this; alpar@1073: } alpar@1073: ///Sets whether to draw arrows alpar@1073: alpar@1073: ///Sets whether to draw arrows alpar@1073: /// alpar@1073: GraphToEps &drawArrows(bool b=true) {_drawArrows=b;return *this;} alpar@1073: ///Sets the length of the arrowheads alpar@1073: alpar@1073: ///Sets the length of the arrowheads alpar@1073: /// alpar@1073: GraphToEps &arrowLength(double d) {_arrowLength*=d;return *this;} alpar@1073: ///Sets the width of the arrowheads alpar@1073: alpar@1073: ///Sets the width of the arrowheads alpar@1073: /// alpar@1073: GraphToEps &arrowWidth(double d) {_arrowWidth*=d;return *this;} alpar@1073: alpar@1073: ///Enables parallel edges alpar@1073: alpar@1073: ///Enables parallel edges alpar@1073: ///\todo Partially implemented alpar@1073: GraphToEps &enableParallel(bool b=true) {_enableParallel=b;return *this;} alpar@1073: alpar@1073: ///Sets the distance alpar@1073: alpar@1073: ///Sets the distance alpar@1073: /// alpar@1073: GraphToEps &parEdgeDist(double d) {_parEdgeDist*=d;return *this;} alpar@1073: alpar@1073: ///Hides the edges alpar@1073: alpar@1073: ///Hides the edges alpar@1073: /// alpar@1073: GraphToEps &hideEdges(bool b=true) {_showEdges=!b;return *this;} alpar@1073: ///Hides the nodes alpar@1073: alpar@1073: ///Hides the nodes alpar@1073: /// alpar@1073: GraphToEps &hideNodes(bool b=true) {_showNodes=!b;return *this;} alpar@1073: alpar@1073: ///Sets the size of the node texts alpar@1073: alpar@1073: ///Sets the size of the node texts alpar@1073: /// alpar@1073: GraphToEps &nodeTextSize(double d) {_nodeTextSize=d;return *this;} alpar@1073: ///Sets whether the the graph is undirected alpar@1073: alpar@1073: ///Sets whether the the graph is undirected alpar@1073: /// alpar@1073: GraphToEps &undir(bool b=true) {_undir=b;return *this;} alpar@1073: ///Sets whether the the graph is directed alpar@1073: alpar@1073: ///Sets whether the the graph is directed. alpar@1073: ///Use it to show the undirected edges as a pair of directed ones. alpar@1073: GraphToEps &bidir(bool b=true) {_undir=!b;return *this;} alpar@1073: alpar@1073: ~GraphToEps() alpar@1073: { alpar@1073: if(dontPrint) return; alpar@1073: alpar@1073: os << "%!PS-Adobe-2.0 EPSF-2.0\n"; alpar@1073: //\todo: Chech whether the graph is empty. alpar@1073: BoundingBox bb; alpar@1073: for(NodeIt n(g);n!=INVALID;++n) { alpar@1073: double ns=_nodeSizes[n]*_nodeScale; alpar@1073: xy p(ns,ns); alpar@1073: bb+=p+_coords[n]; alpar@1073: bb+=-p+_coords[n]; alpar@1073: } alpar@1073: os << "%%BoundingBox: " alpar@1073: << bb.left()* _scale-_xBorder << ' ' alpar@1073: << bb.bottom()*_scale-_yBorder << ' ' alpar@1073: << bb.right()* _scale+_xBorder << ' ' alpar@1073: << bb.top()* _scale+_yBorder << '\n'; alpar@1073: //x1 y1 x2 y2 x3 y3 cr cg cb w alpar@1073: os << "/lb { setlinewidth setrgbcolor newpath moveto\n" alpar@1073: << " 4 2 roll 1 index 1 index curveto stroke } bind def\n"; alpar@1073: os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n"; alpar@1073: os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def\n"; alpar@1073: // x y r cr cg cb alpar@1073: os << "/n { setrgbcolor 2 index 2 index 2 index c fill\n" alpar@1073: << " 0 0 0 setrgbcolor dup " alpar@1073: << _nodeBorderQuotient << " mul setlinewidth " alpar@1073: << 1+_nodeBorderQuotient/2 << " div c stroke\n" alpar@1073: << " } bind def\n"; alpar@1073: os << "/arrl " << _arrowLength << " def\n"; alpar@1073: os << "/arrw " << _arrowWidth << " def\n"; alpar@1073: // l dx_norm dy_norm alpar@1073: os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n"; alpar@1073: //len w dx_norm dy_norm x1 y1 cr cg cb alpar@1073: os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n" alpar@1073: << " /w exch def /len exch def\n" alpar@1073: // << " 0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke" alpar@1073: << " newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto\n" alpar@1073: << " len w sub arrl sub dx dy lrl\n" alpar@1073: << " arrw dy dx neg lrl\n" alpar@1073: << " dx arrl w add mul dy w 2 div arrw add mul sub\n" alpar@1073: << " dy arrl w add mul dx w 2 div arrw add mul add rlineto\n" alpar@1073: << " dx arrl w add mul neg dy w 2 div arrw add mul sub\n" alpar@1073: << " dy arrl w add mul neg dx w 2 div arrw add mul add rlineto\n" alpar@1073: << " arrw dy dx neg lrl\n" alpar@1073: << " len w sub arrl sub neg dx dy lrl\n" alpar@1073: << " closepath fill } bind def\n"; alpar@1073: os << "/cshow { 2 index 2 index moveto dup stringwidth pop\n" alpar@1073: << " neg 2 div fosi .35 mul neg rmoveto show pop pop} def\n"; alpar@1073: alpar@1073: os << "\ngsave\n"; alpar@1073: if(_scale!=1.0) os << _scale << " dup scale\n"; alpar@1073: alpar@1073: os << "%Edges:\ngsave\n"; alpar@1073: alpar@1073: if(_showEdges) alpar@1073: if(_enableParallel) { alpar@1073: std::vector el; alpar@1073: for(EdgeIt e(g);e!=INVALID;++e) alpar@1073: if(!_undir||g.source(e)::iterator j; alpar@1073: for(typename std::vector::iterator i=el.begin();i!=el.end();i=j) { alpar@1073: for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ; alpar@1073: alpar@1073: double sw=0; alpar@1073: for(typename std::vector::iterator e=i;e!=j;++e) alpar@1073: sw+=_edgeWidths[*e]*_edgeWidthScale+_parEdgeDist; alpar@1073: sw-=_parEdgeDist; alpar@1073: sw/=-2.0; alpar@1073: xy d(_coords[g.target(*i)]-_coords[g.source(*i)]); alpar@1073: double l=sqrt(d.normSquare()); alpar@1073: d/=l; alpar@1073: alpar@1073: for(typename std::vector::iterator e=i;e!=j;++e) { alpar@1073: sw+=_edgeWidths[*e]*_edgeWidthScale/2.0; alpar@1073: xy m(_coords[g.target(*e)]+_coords[g.source(*e)]); alpar@1073: m=m/2.0+rot(d)*sw/.75; alpar@1073: if(_drawArrows) { alpar@1073: const int INERPOL_PREC=20; alpar@1073: xy s=_coords[g.source(*e)]; alpar@1073: xy t=_coords[g.target(*e)]; alpar@1073: double rn=_nodeSizes[g.target(*e)]*_nodeScale; alpar@1073: rn*=rn; alpar@1073: Bezier3 bez(s,m,m,t); alpar@1073: double t1=0,t2=1; alpar@1073: for(int i=0;irn) t1=(t1+t2)/2; alpar@1073: else t2=(t1+t2)/2; alpar@1073: xy apoint=bez((t1+t2)/2); alpar@1073: rn = _nodeSizes[g.target(*e)]*_nodeScale+_arrowLength+ alpar@1073: _edgeWidths[*e]*_edgeWidthScale; alpar@1073: rn*=rn; alpar@1073: t1=0;t2=1; alpar@1073: for(int i=0;irn) t1=(t1+t2)/2; alpar@1073: else t2=(t1+t2)/2; alpar@1073: xy linend=bez((t1+t2)/2); alpar@1073: bez=bez.before((t1+t2)/2); alpar@1073: rn=_nodeSizes[g.source(*e)]*_nodeScale; rn*=rn; alpar@1073: t1=0;t2=1; alpar@1073: for(int i=0;irn) t2=(t1+t2)/2; alpar@1073: else t1=(t1+t2)/2; alpar@1073: bez=bez.after((t1+t2)/2); alpar@1073: os << _edgeWidths[*e]*_edgeWidthScale << " setlinewidth " alpar@1073: << _edgeColors[*e].getR() << ' ' alpar@1073: << _edgeColors[*e].getG() << ' ' alpar@1073: << _edgeColors[*e].getB() << " setrgbcolor newpath\n" alpar@1073: << bez.p1.x << ' ' << bez.p1.y << " moveto\n" alpar@1073: << bez.p2.x << ' ' << bez.p2.y << ' ' alpar@1073: << bez.p3.x << ' ' << bez.p3.y << ' ' alpar@1073: << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n"; alpar@1073: xy dd(rot(linend-apoint)); alpar@1073: dd*=(_edgeWidths[*e]*_edgeWidthScale+_arrowWidth)/ alpar@1073: sqrt(dd.normSquare()); alpar@1073: os << "newpath " << psOut(apoint) << " moveto " alpar@1073: << psOut(linend+dd) << " lineto " alpar@1073: << psOut(linend-dd) << " lineto closepath fill\n"; alpar@1073: } alpar@1073: else { alpar@1073: os << _coords[g.source(*e)].x << ' ' alpar@1073: << _coords[g.source(*e)].y << ' ' alpar@1073: << m.x << ' ' << m.y << ' ' alpar@1073: << _coords[g.target(*e)].x << ' ' alpar@1073: << _coords[g.target(*e)].y << ' ' alpar@1073: << _edgeColors[*e].getR() << ' ' alpar@1073: << _edgeColors[*e].getG() << ' ' alpar@1073: << _edgeColors[*e].getB() << ' ' alpar@1073: << _edgeWidths[*e]*_edgeWidthScale << " lb\n"; alpar@1073: } alpar@1073: sw+=_edgeWidths[*e]*_edgeWidthScale/2.0+_parEdgeDist; alpar@1073: } alpar@1073: } alpar@1073: } alpar@1073: else for(EdgeIt e(g);e!=INVALID;++e) alpar@1073: if(!_undir||g.source(e) d(_coords[g.target(e)]-_coords[g.source(e)]); alpar@1073: double l=sqrt(d.normSquare()); alpar@1073: d/=l; alpar@1073: xy x1(d*_nodeScale*_nodeSizes[g.source(e)]+ alpar@1073: _coords[g.source(e)]); alpar@1073: os << l-(_nodeSizes[g.source(e)]+ alpar@1073: _nodeSizes[g.target(e)])*_nodeScale << ' ' alpar@1073: << _edgeWidths[e]*_edgeWidthScale << ' ' alpar@1073: << d.x << ' ' << d.y << ' ' alpar@1073: << x1.x << ' ' << x1.y << ' ' alpar@1073: << _edgeColors[e].getR() << ' ' alpar@1073: << _edgeColors[e].getG() << ' ' alpar@1073: << _edgeColors[e].getB() << " arr\n"; alpar@1073: } alpar@1073: else os << _coords[g.source(e)].x << ' ' alpar@1073: << _coords[g.source(e)].y << ' ' alpar@1073: << _coords[g.target(e)].x << ' ' alpar@1073: << _coords[g.target(e)].y << ' ' alpar@1073: << _edgeColors[e].getR() << ' ' alpar@1073: << _edgeColors[e].getG() << ' ' alpar@1073: << _edgeColors[e].getB() << ' ' alpar@1073: << _edgeWidths[e]*_edgeWidthScale << " l\n"; alpar@1073: os << "grestore\n%Nodes:\ngsave\n"; alpar@1073: if(_showNodes) alpar@1073: for(NodeIt n(g);n!=INVALID;++n) alpar@1073: os << _coords[n].x << ' ' << _coords[n].y << ' ' alpar@1073: << _nodeSizes[n]*_nodeScale << ' ' alpar@1073: << _nodeColors[n].getR() << ' ' alpar@1073: << _nodeColors[n].getG() << ' ' alpar@1073: << _nodeColors[n].getB() << " n\n"; alpar@1073: if(_showNodeText) { alpar@1073: os << "grestore\n%Node texts:\ngsave\n"; alpar@1073: os << "/fosi " << _nodeTextSize << " def\n"; alpar@1073: os << "(Helvetica) findfont fosi scalefont setfont\n"; alpar@1073: os << "0 0 0 setrgbcolor\n"; alpar@1073: for(NodeIt n(g);n!=INVALID;++n) alpar@1073: os << _coords[n].x << ' ' << _coords[n].y alpar@1073: << " (" << _nodeTexts[n] << ") cshow\n"; alpar@1073: } alpar@1073: os << "grestore\ngrestore\n"; alpar@1073: alpar@1073: //CleanUp: alpar@1073: if(_pleaseRemoveOsStream) {delete &os;} alpar@1073: } alpar@1073: }; alpar@1073: alpar@1073: alpar@1073: ///Generates an EPS file from a graph alpar@1073: alpar@1073: ///\ingroup misc alpar@1073: ///Generates an EPS file from a graph. alpar@1073: ///\param g is a reference to the graph to be printed alpar@1073: ///\param os is a reference to the output stream. alpar@1073: ///By default it is std::cout alpar@1073: /// alpar@1073: ///This function also has a lot of \ref named-templ-param "named parameters", alpar@1073: ///they are declared as the members of class \ref GraphToEps. The following alpar@1073: ///example shows how to use these parameters. alpar@1073: ///\code alpar@1073: /// graphToEps(g).scale(10).coords(coords) alpar@1073: /// .nodeScale(2).nodeSizes(sizes) alpar@1073: /// .edgeWidthScale(.4); alpar@1073: ///\endcode alpar@1073: ///\sa GraphToEps alpar@1073: ///\sa graphToEps(G &g, char *file_name) alpar@1073: template alpar@1073: GraphToEps > alpar@1073: graphToEps(G &g, std::ostream& os=std::cout) alpar@1073: { alpar@1073: return alpar@1073: GraphToEps >(DefaultGraphToEpsTraits(g,os)); alpar@1073: } alpar@1073: alpar@1073: ///Generates an EPS file from a graph alpar@1073: alpar@1073: //\ingroup misc alpar@1073: ///This function does the same as alpar@1073: ///\ref graphToEps(G &g,std::ostream& os) alpar@1073: ///but it writes its output into the file \c file_name alpar@1073: ///instead of a stream. alpar@1073: ///\sa graphToEps(G &g, std::ostream& os) alpar@1073: template alpar@1073: GraphToEps > alpar@1073: graphToEps(G &g,char *file_name) alpar@1073: { alpar@1073: return GraphToEps > alpar@1073: (DefaultGraphToEpsTraits(g,*new std::ofstream(file_name),true)); alpar@1073: } alpar@1073: alpar@1073: //Generates an EPS file from a graph. alpar@1073: //\param g is a reference to the graph to be printed alpar@1073: //\param file_name is the output file_name. alpar@1073: // alpar@1073: //This function also has a lot of \ref named-templ-param "named parameters", alpar@1073: //they are declared as the members of class \ref GraphToEps. The following alpar@1073: //example shows how to use these parameters. alpar@1073: //\code alpar@1073: // graphToEps(g).scale(10).coords(coords) alpar@1073: // .nodeScale(2).nodeSizes(sizes) alpar@1073: // .edgeWidthScale(.4); alpar@1073: //\endcode alpar@1073: //\sa GraphToEps alpar@1073: //\todo Avoid duplicated documentation alpar@1073: //\bug Exception handling is missing? (Or we can just ignore it?) alpar@1073: alpar@1073: } //END OF NAMESPACE LEMON alpar@1073: alpar@1073: #endif // LEMON_GRAPH_TO_EPS_H