diff -r 5b7ca75297b5 -r caa13d291528 src/lemon/graph_to_eps.h --- a/src/lemon/graph_to_eps.h Sun Jan 16 22:34:51 2005 +0000 +++ b/src/lemon/graph_to_eps.h Tue Jan 18 12:02:27 2005 +0000 @@ -80,6 +80,7 @@ ConstMap > _coords; ConstMap _nodeSizes; + ConstMap _nodeShapes; ConstMap _nodeColors; ConstMap _edgeColors; @@ -123,7 +124,7 @@ DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout, bool _pros=false) : g(_g), os(_os), - _coords(xy(1,1)), _nodeSizes(1.0), + _coords(xy(1,1)), _nodeSizes(1.0), _nodeShapes(0), _nodeColors(Color(1,1,1)), _edgeColors(Color(0,0,0)), _edgeWidths(1), _edgeWidthScale(0.3), _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0), @@ -154,6 +155,8 @@ bool dontPrint; + enum NodeShapes { CIRCLE=0, SQUARE=1 }; + class edgeLess { const Graph &g; public: @@ -214,6 +217,20 @@ dontPrint=true; return GraphToEps >(NodeSizesTraits(*this,x)); } + template struct NodeShapesTraits : public T { + const X &_nodeShapes; + NodeShapesTraits(const T &t,const X &x) : T(t), _nodeShapes(x) {} + }; + ///Sets the map of the node shapes + + ///Sets the map of the node shapes + ///\param x must be a node map with \c int (or convertible) values. + ///\todo Incomplete doc. + template GraphToEps > nodeShapes(const X &x) + { + dontPrint=true; + return GraphToEps >(NodeShapesTraits(*this,x)); + } template struct NodeTextsTraits : public T { const X &_nodeTexts; NodeTextsTraits(const T &t,const X &x) : T(t), _nodeTexts(x) {} @@ -386,7 +403,20 @@ ///Sets whether the the graph is directed. ///Use it to show the undirected edges as a pair of directed ones. GraphToEps &bidir(bool b=true) {_undir=!b;return *this;} - + +protected: + bool isInsideNode(xy p, double r,int t) + { + switch(t) { + case CIRCLE: + return p.normSquare()<=r*r; + case SQUARE: + return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r; + } + return false; + } + +public: ~GraphToEps() { if(dontPrint) return; @@ -409,13 +439,25 @@ os << "/lb { setlinewidth setrgbcolor newpath moveto\n" << " 4 2 roll 1 index 1 index curveto stroke } bind def\n"; os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n"; + //x y r os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def\n"; + //x y r + os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n" + << " 2 index 1 index sub 2 index 2 index add lineto\n" + << " 2 index 1 index sub 2 index 2 index sub lineto\n" + << " 2 index 1 index add 2 index 2 index sub lineto\n" + << " closepath pop pop pop} bind def\n"; // x y r cr cg cb - os << "/n { setrgbcolor 2 index 2 index 2 index c fill\n" + os << "/nc { setrgbcolor 2 index 2 index 2 index c fill\n" << " 0 0 0 setrgbcolor dup " << _nodeBorderQuotient << " mul setlinewidth " << 1+_nodeBorderQuotient/2 << " div c stroke\n" << " } bind def\n"; + os << "/nsq { setrgbcolor 2 index 2 index 2 index sq fill\n" + << " 0 0 0 setrgbcolor dup " + << _nodeBorderQuotient << " mul setlinewidth " + << 1+_nodeBorderQuotient/2 << " div sq stroke\n" + << " } bind def\n"; os << "/arrl " << _arrowLength << " def\n"; os << "/arrw " << _arrowWidth << " def\n"; // l dx_norm dy_norm @@ -474,32 +516,33 @@ sw+=_edgeWidths[*e]*_edgeWidthScale/2.0; xy mm=m+rot(d)*sw/.75; if(_drawArrows) { + int node_shape; const int INERPOL_PREC=20; xy s=_coords[g.source(*e)]; xy t=_coords[g.target(*e)]; double rn=_nodeSizes[g.target(*e)]*_nodeScale; - rn*=rn; + node_shape=_nodeShapes[g.target(*e)]; Bezier3 bez(s,mm,mm,t); double t1=0,t2=1; for(int i=0;irn) t1=(t1+t2)/2; - else t2=(t1+t2)/2; + if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t2=(t1+t2)/2; + else t1=(t1+t2)/2; xy apoint=bez((t1+t2)/2); - rn = _nodeSizes[g.target(*e)]*_nodeScale+_arrowLength+ - _edgeWidths[*e]*_edgeWidthScale; + rn = _arrowLength+_edgeWidths[*e]*_edgeWidthScale; rn*=rn; - t1=0;t2=1; + t2=(t1+t2)/2;t1=0; for(int i=0;irn) t1=(t1+t2)/2; + if((bez((t1+t2)/2)-apoint).normSquare()>rn) t1=(t1+t2)/2; else t2=(t1+t2)/2; xy linend=bez((t1+t2)/2); bez=bez.before((t1+t2)/2); - rn=_nodeSizes[g.source(*e)]*_nodeScale; rn*=rn; - t1=0;t2=1; - for(int i=0;irn) t2=(t1+t2)/2; - else t1=(t1+t2)/2; - bez=bez.after((t1+t2)/2); +// rn=_nodeSizes[g.source(*e)]*_nodeScale; +// node_shape=_nodeShapes[g.source(*e)]; +// t1=0;t2=1; +// for(int i=0;i