Changeset 1086:caa13d291528 in lemon0.x for src
 Timestamp:
 01/18/05 13:02:27 (15 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1482
 Location:
 src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/demo/graph_to_eps_demo.cc
r1073 r1086 68 68 ListGraph::NodeMap<double> sizes(g); 69 69 ListGraph::NodeMap<int> colors(g); 70 ListGraph::NodeMap<int> shapes(g); 70 71 ListGraph::EdgeMap<int> ecolors(g); 71 72 ListGraph::EdgeMap<int> widths(g); 72 73 73 coords[n1]=Xy(50,50); sizes[n1]=1; colors[n1]=1; 74 coords[n2]=Xy(50,70); sizes[n2]=2; colors[n2]=2; 75 coords[n3]=Xy(70,70); sizes[n3]=1; colors[n3]=3; 76 coords[n4]=Xy(70,50); sizes[n4]=2; colors[n4]=4; 77 coords[n5]=Xy(85,60); sizes[n5]=3; colors[n5]=5; 74 coords[n1]=Xy(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0; 75 coords[n2]=Xy(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=0; 76 coords[n3]=Xy(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0; 77 coords[n4]=Xy(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1; 78 coords[n5]=Xy(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=0; 78 79 79 80 Edge e; … … 91 92 graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords). 92 93 nodeScale(2).nodeSizes(sizes). 94 nodeShapes(shapes). 93 95 nodeColors(composeMap(colorSet,colors)). 94 96 edgeColors(composeMap(colorSet,ecolors)). … … 98 100 graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).coords(coords). 99 101 nodeScale(2).nodeSizes(sizes). 102 nodeShapes(shapes). 100 103 nodeColors(composeMap(colorSet,colors)). 101 104 edgeColors(composeMap(colorSet,ecolors)). … … 117 120 graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).coords(coords). 118 121 nodeScale(2).nodeSizes(sizes). 122 nodeShapes(shapes). 119 123 nodeColors(composeMap(colorSet,colors)). 120 124 edgeColors(composeMap(colorSet,ecolors)). … … 125 129 graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).coords(coords). 126 130 nodeScale(2).nodeSizes(sizes). 131 nodeShapes(shapes). 127 132 nodeColors(composeMap(colorSet,colors)). 128 133 edgeColors(composeMap(colorSet,ecolors)). … … 130 135 nodeTexts(id).nodeTextSize(3). 131 136 enableParallel().parEdgeDist(1). 137 // hideNodes(). 132 138 drawArrows().arrowWidth(1).arrowLength(1); 133 139 } 
src/lemon/graph_to_eps.h
r1085 r1086 81 81 ConstMap<typename Graph::Node,xy<double> > _coords; 82 82 ConstMap<typename Graph::Node,double > _nodeSizes; 83 ConstMap<typename Graph::Node,int > _nodeShapes; 83 84 84 85 ConstMap<typename Graph::Node,Color > _nodeColors; … … 124 125 bool _pros=false) : 125 126 g(_g), os(_os), 126 _coords(xy<double>(1,1)), _nodeSizes(1.0), 127 _coords(xy<double>(1,1)), _nodeSizes(1.0), _nodeShapes(0), 127 128 _nodeColors(Color(1,1,1)), _edgeColors(Color(0,0,0)), 128 129 _edgeWidths(1), _edgeWidthScale(0.3), … … 155 156 bool dontPrint; 156 157 158 enum NodeShapes { CIRCLE=0, SQUARE=1 }; 159 157 160 class edgeLess { 158 161 const Graph &g; … … 215 218 return GraphToEps<NodeSizesTraits<X> >(NodeSizesTraits<X>(*this,x)); 216 219 } 220 template<class X> struct NodeShapesTraits : public T { 221 const X &_nodeShapes; 222 NodeShapesTraits(const T &t,const X &x) : T(t), _nodeShapes(x) {} 223 }; 224 ///Sets the map of the node shapes 225 226 ///Sets the map of the node shapes 227 ///\param x must be a node map with \c int (or convertible) values. 228 ///\todo Incomplete doc. 229 template<class X> GraphToEps<NodeShapesTraits<X> > nodeShapes(const X &x) 230 { 231 dontPrint=true; 232 return GraphToEps<NodeShapesTraits<X> >(NodeShapesTraits<X>(*this,x)); 233 } 217 234 template<class X> struct NodeTextsTraits : public T { 218 235 const X &_nodeTexts; … … 387 404 ///Use it to show the undirected edges as a pair of directed ones. 388 405 GraphToEps<T> &bidir(bool b=true) {_undir=!b;return *this;} 389 406 407 protected: 408 bool isInsideNode(xy<double> p, double r,int t) 409 { 410 switch(t) { 411 case CIRCLE: 412 return p.normSquare()<=r*r; 413 case SQUARE: 414 return p.x<=r&&p.x>=r&&p.y<=r&&p.y>=r; 415 } 416 return false; 417 } 418 419 public: 390 420 ~GraphToEps() 391 421 { … … 410 440 << " 4 2 roll 1 index 1 index curveto stroke } bind def\n"; 411 441 os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n"; 442 //x y r 412 443 os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def\n"; 444 //x y r 445 os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n" 446 << " 2 index 1 index sub 2 index 2 index add lineto\n" 447 << " 2 index 1 index sub 2 index 2 index sub lineto\n" 448 << " 2 index 1 index add 2 index 2 index sub lineto\n" 449 << " closepath pop pop pop} bind def\n"; 413 450 // x y r cr cg cb 414 os << "/n { setrgbcolor 2 index 2 index 2 index c fill\n"451 os << "/nc { setrgbcolor 2 index 2 index 2 index c fill\n" 415 452 << " 0 0 0 setrgbcolor dup " 416 453 << _nodeBorderQuotient << " mul setlinewidth " 417 454 << 1+_nodeBorderQuotient/2 << " div c stroke\n" 455 << " } bind def\n"; 456 os << "/nsq { setrgbcolor 2 index 2 index 2 index sq fill\n" 457 << " 0 0 0 setrgbcolor dup " 458 << _nodeBorderQuotient << " mul setlinewidth " 459 << 1+_nodeBorderQuotient/2 << " div sq stroke\n" 418 460 << " } bind def\n"; 419 461 os << "/arrl " << _arrowLength << " def\n"; … … 475 517 xy<double> mm=m+rot(d)*sw/.75; 476 518 if(_drawArrows) { 519 int node_shape; 477 520 const int INERPOL_PREC=20; 478 521 xy<double> s=_coords[g.source(*e)]; 479 522 xy<double> t=_coords[g.target(*e)]; 480 523 double rn=_nodeSizes[g.target(*e)]*_nodeScale; 481 rn*=rn;524 node_shape=_nodeShapes[g.target(*e)]; 482 525 Bezier3 bez(s,mm,mm,t); 483 526 double t1=0,t2=1; 484 527 for(int i=0;i<INERPOL_PREC;++i) 485 if( (bez((t1+t2)/2)t).normSquare()>rn) t1=(t1+t2)/2;486 else t 2=(t1+t2)/2;528 if(isInsideNode(bez((t1+t2)/2)t,rn,node_shape)) t2=(t1+t2)/2; 529 else t1=(t1+t2)/2; 487 530 xy<double> apoint=bez((t1+t2)/2); 488 rn = _nodeSizes[g.target(*e)]*_nodeScale+_arrowLength+ 489 _edgeWidths[*e]*_edgeWidthScale; 531 rn = _arrowLength+_edgeWidths[*e]*_edgeWidthScale; 490 532 rn*=rn; 491 t 1=0;t2=1;533 t2=(t1+t2)/2;t1=0; 492 534 for(int i=0;i<INERPOL_PREC;++i) 493 if((bez((t1+t2)/2) t).normSquare()>rn) t1=(t1+t2)/2;535 if((bez((t1+t2)/2)apoint).normSquare()>rn) t1=(t1+t2)/2; 494 536 else t2=(t1+t2)/2; 495 537 xy<double> linend=bez((t1+t2)/2); 496 538 bez=bez.before((t1+t2)/2); 497 rn=_nodeSizes[g.source(*e)]*_nodeScale; rn*=rn; 498 t1=0;t2=1; 499 for(int i=0;i<INERPOL_PREC;++i) 500 if((bez((t1+t2)/2)s).normSquare()>rn) t2=(t1+t2)/2; 501 else t1=(t1+t2)/2; 502 bez=bez.after((t1+t2)/2); 539 // rn=_nodeSizes[g.source(*e)]*_nodeScale; 540 // node_shape=_nodeShapes[g.source(*e)]; 541 // t1=0;t2=1; 542 // for(int i=0;i<INERPOL_PREC;++i) 543 // if(isInsideNode(bez((t1+t2)/2)t,rn,node_shape)) t1=(t1+t2)/2; 544 // else t2=(t1+t2)/2; 545 // bez=bez.after((t1+t2)/2); 503 546 os << _edgeWidths[*e]*_edgeWidthScale << " setlinewidth " 504 547 << _edgeColors[*e].getR() << ' ' … … 560 603 if(_showNodes) { 561 604 os << "%Nodes:\ngsave\n"; 562 for(NodeIt n(g);n!=INVALID;++n) 605 for(NodeIt n(g);n!=INVALID;++n) { 563 606 os << _coords[n].x << ' ' << _coords[n].y << ' ' 564 607 << _nodeSizes[n]*_nodeScale << ' ' 565 608 << _nodeColors[n].getR() << ' ' 566 609 << _nodeColors[n].getG() << ' ' 567 << _nodeColors[n].getB() << " n\n"; 610 << _nodeColors[n].getB() << ' '; 611 switch(_nodeShapes[n]) { 612 case CIRCLE: 613 os<< "nc";break; 614 case SQUARE: 615 os<< "nsq";break; 616 } 617 os<<'\n'; 618 } 568 619 os << "grestore\n"; 569 620 }
Note: See TracChangeset
for help on using the changeset viewer.