Changeset 2178:0d7c0f96a5ee in lemon-0.x
- Timestamp:
- 08/14/06 17:15:57 (18 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2894
- Files:
-
- 1 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
demo/graph_to_eps_demo.cc
r2172 r2178 43 43 { 44 44 Palette palette; 45 Palette paletteW(true); 45 46 46 47 ListGraph g; … … 81 82 IdMap<ListGraph,Node> id(g); 82 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). 87 coords(coords). 88 title("Sample .eps figure"). 89 copyright("(C) 2006 LEMON Project"). 90 run(); 91 83 92 cout << "Create 'graph_to_eps_demo_out.eps'" << endl; 84 93 graphToEps(g,"graph_to_eps_demo_out.eps"). … … 87 96 title("Sample .eps figure"). 88 97 copyright("(C) 2006 LEMON Project"). 98 absoluteNodeSizes().absoluteEdgeWidths(). 89 99 nodeScale(2).nodeSizes(sizes). 90 100 nodeShapes(shapes). … … 101 111 title("Sample .eps figure (with arrowheads)"). 102 112 copyright("(C) 2006 LEMON Project"). 113 absoluteNodeSizes().absoluteEdgeWidths(). 103 114 nodeColors(composeMap(palette,colors)). 104 115 coords(coords). … … 127 138 title("Sample .eps figure (parallel edges)"). 128 139 copyright("(C) 2006 LEMON Project"). 140 absoluteNodeSizes().absoluteEdgeWidths(). 129 141 nodeShapes(shapes). 130 142 coords(coords). … … 142 154 title("Sample .eps figure (parallel edges and arrowheads)"). 143 155 copyright("(C) 2006 LEMON Project"). 156 absoluteNodeSizes().absoluteEdgeWidths(). 144 157 nodeScale(2).nodeSizes(sizes). 145 158 coords(coords). … … 157 170 title("Sample .eps figure (fits to A4)"). 158 171 copyright("(C) 2006 LEMON Project"). 172 absoluteNodeSizes().absoluteEdgeWidths(). 159 173 nodeScale(2).nodeSizes(sizes). 160 174 coords(coords). … … 173 187 174 188 int cols=int(sqrt(double(palette.size()))); 175 for(int i=0;i<int(palette .size());i++) {189 for(int i=0;i<int(paletteW.size());i++) { 176 190 Node n=h.addNode(); 177 191 hcoords[n]=Xy(i%cols,i/cols); … … 185 199 copyright("(C) 2006 LEMON Project"). 186 200 coords(hcoords). 187 nodeScale(.45). 201 absoluteNodeSizes().absoluteEdgeWidths(). 202 nodeScale(45). 188 203 distantColorNodeTexts(). 189 204 // distantBWNodeTexts(). 190 205 nodeTexts(hcolors).nodeTextSize(.6). 191 nodeColors(composeMap(palette,hcolors)). 192 run(); 193 194 206 nodeColors(composeMap(paletteW,hcolors)). 207 run(); 195 208 } -
lemon/graph_to_eps.h
r2174 r2178 39 39 #include<lemon/maps.h> 40 40 #include<lemon/color.h> 41 #include<lemon/b ezier.h>41 #include<lemon/bits/bezier.h> 42 42 43 43 … … 131 131 bool _autoEdgeWidthScale; 132 132 133 bool _absoluteNodeSizes; 134 bool _absoluteEdgeWidths; 135 133 136 bool _negY; 134 137 ///Constructor … … 144 147 bool _pros=false) : 145 148 g(_g), os(_os), 146 _coords(xy<double>(1,1)), _nodeSizes( 1.0), _nodeShapes(0),149 _coords(xy<double>(1,1)), _nodeSizes(.01), _nodeShapes(0), 147 150 _nodeColors(WHITE), _edgeColors(BLACK), 148 _edgeWidths(1 ), _edgeWidthScale(0.3),151 _edgeWidths(1.0), _edgeWidthScale(0.003), 149 152 _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0), 150 153 _nodeBorderQuotient(.1), … … 159 162 _autoNodeScale(false), 160 163 _autoEdgeWidthScale(false), 164 _absoluteNodeSizes(false), 165 _absoluteEdgeWidths(false), 161 166 _negY(false) 162 167 {} … … 229 234 using T::_autoNodeScale; 230 235 using T::_autoEdgeWidthScale; 236 237 using T::_absoluteNodeSizes; 238 using T::_absoluteEdgeWidths; 239 231 240 232 241 using T::_negY; … … 479 488 /// node sizes will be scaled in such a way that the greatest size will be 480 489 /// equal to \c d. 490 /// \sa nodeSizes() 491 /// \sa autoNodeScale() 481 492 GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;} 482 493 ///Turns on/off the automatic node width scaling. … … 488 499 GraphToEps<T> &autoNodeScale(bool b=true) { 489 500 _autoNodeScale=b;return *this; 501 } 502 503 ///Turns on/off the absolutematic node width scaling. 504 505 ///Turns on/off the absolutematic node width scaling. 506 /// 507 ///\sa nodeScale() 508 /// 509 GraphToEps<T> &absoluteNodeSizes(bool b=true) { 510 _absoluteNodeSizes=b;return *this; 490 511 } 491 512 … … 520 541 GraphToEps<T> &autoEdgeWidthScale(bool b=true) { 521 542 _autoEdgeWidthScale=b;return *this; 543 } 544 ///Turns on/off the absolutematic edge width scaling. 545 546 ///Turns on/off the absolutematic edge width scaling. 547 /// 548 ///\sa edgeWidthScale() 549 /// 550 GraphToEps<T> &absoluteEdgeWidths(bool b=true) { 551 _absoluteEdgeWidths=b;return *this; 522 552 } 523 553 ///Sets a global scale factor for the whole picture … … 665 695 ///it draws the graph. 666 696 void run() { 697 ///\todo better 'epsilon' would be nice here. 698 const double EPSILON=1e-9; 667 699 if(dontPrint) return; 668 700 … … 688 720 max_w=std::max(double(_edgeWidths[e]),max_w); 689 721 ///\todo better 'epsilon' would be nice here. 690 if(max_w> 1e-9) {722 if(max_w>EPSILON) { 691 723 _edgeWidthScale/=max_w; 692 724 } … … 698 730 max_s=std::max(double(_nodeSizes[n]),max_s); 699 731 ///\todo better 'epsilon' would be nice here. 700 if(max_s> 1e-9) {732 if(max_s>EPSILON) { 701 733 _nodeScale/=max_s; 702 734 } 703 735 } 704 736 705 737 double diag_len = 1; 738 if(!(_absoluteNodeSizes&&_absoluteEdgeWidths)) { 739 BoundingBox<double> bb; 740 for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]); 741 if (bb.empty()) { 742 bb = BoundingBox<double>(xy<double>(0,0)); 743 } 744 diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare()); 745 if(diag_len<EPSILON) diag_len = 1; 746 if(!_absoluteNodeSizes) _nodeScale*=diag_len; 747 if(!_absoluteEdgeWidths) _edgeWidthScale*=diag_len; 748 } 749 706 750 BoundingBox<double> bb; 707 ///\bug: Chech whether the graph is empty.708 751 for(NodeIt n(g);n!=INVALID;++n) { 709 752 double ns=_nodeSizes[n]*_nodeScale; … … 865 908 double l=std::sqrt(dvec.normSquare()); 866 909 ///\todo better 'epsilon' would be nice here. 867 xy<double> d(dvec/std::max(l, 1e-9));910 xy<double> d(dvec/std::max(l,EPSILON)); 868 911 xy<double> m; 869 912 // m=xy<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
Note: See TracChangeset
for help on using the changeset viewer.