Changeset 1055:f901ff02b2d7 in lemon-0.x for src/work/alpar/graph_to_eps.cc
- Timestamp:
- 01/06/05 09:39:50 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1449
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/alpar/graph_to_eps.cc
r1051 r1055 1 1 #include <iostream> 2 #include <fstream> 3 #include <algorithm> 2 4 #include<math.h> 3 5 … … 73 75 double _arrowLength, _arrowWidth; 74 76 77 bool _enableParallel; 78 79 bool _pleaseRemoveOsStream; 75 80 ///Constructor 76 81 … … 78 83 ///\param _g is a reference to the graph to be printed 79 84 ///\param _os is a reference to the output stream. 85 ///\param _os is a reference to the output stream. 86 ///\param _pros If it is \c true, then the \c ostream referenced by \c _os 87 ///will be explicitly deallocated by the destructor. 80 88 ///By default it is <tt>std::cout</tt> 81 DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout) : 89 DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout, 90 bool _pros=false) : 82 91 g(_g), os(_os), 83 92 _coords(xy<double>(1,1)), _nodeSizes(1.0), … … 86 95 _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0), 87 96 _nodeBorderQuotient(.1), 88 _drawArrows(false), _arrowLength(1), _arrowWidth(0.3) {} 97 _drawArrows(false), _arrowLength(1), _arrowWidth(0.3), 98 _enableParallel(false), _pleaseRemoveOsStream(_pros) {} 89 99 }; 90 100 … … 106 116 bool dontPrint; 107 117 118 class edgeLess { 119 const Graph &g; 120 public: 121 edgeLess(const Graph &_g) : g(_g) {} 122 bool operator()(Edge a,Edge b) const 123 { 124 Node ai=min(g.source(a),g.target(a)); 125 Node aa=max(g.source(a),g.target(a)); 126 Node bi=min(g.source(b),g.target(b)); 127 Node ba=max(g.source(b),g.target(b)); 128 return ai<bi || 129 (ai==bi && (aa < ba || 130 (aa==ba && ai==g.source(a) && bi==g.target(b)))); 131 } 132 }; 133 108 134 public: 109 135 GraphToEps(const T &t) : T(t), dontPrint(false) {}; … … 218 244 /// 219 245 GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;} 246 247 ///Enables parallel edges 248 249 ///Enables parallel edges 250 ///\todo Unimplemented 251 GraphToEps<T> &enableParallel(bool b=true) {_enableParallel=b;return *this;} 220 252 221 253 ~GraphToEps() … … 266 298 os << "\ngsave\n"; 267 299 if(_scale!=1.0) os << _scale << " dup scale\n"; 300 268 301 os << "%Edges:\ngsave\n"; 302 303 vector<Edge> el; 304 if(_enableParallel) { 305 for(EdgeIt e(g);e!=INVALID;++e) el.push_back(e); 306 sort(el.begin(),el.end(),edgeLess(g)); 307 } 308 269 309 for(NodeIt n(g);n!=INVALID;++n) 270 310 for(OutEdgeIt e(g,n);e!=INVALID;++e) … … 300 340 << _nodeColors[n].getB() << " n\n"; 301 341 os << "grestore\ngrestore\n"; 342 343 344 //CleanUp: 345 if(_pleaseRemoveOsStream) {delete &os;} 302 346 } 303 347 }; … … 322 366 ///\sa GraphToEps 323 367 template<class G> 324 GraphToEps<DefaultGraphToEpsTraits<G> > graphToEps(G &g,std::ostream& os=std::cout) 325 { 326 return GraphToEps<DefaultGraphToEpsTraits<G> >(DefaultGraphToEpsTraits<G>(g)); 368 GraphToEps<DefaultGraphToEpsTraits<G> > 369 graphToEps(G &g,std::ostream& os=std::cout) 370 { 371 return 372 GraphToEps<DefaultGraphToEpsTraits<G> >(DefaultGraphToEpsTraits<G>(g,os)); 327 373 } 328 374 375 ///Generates an EPS file from a graph 376 377 ///\ingroup misc 378 ///Generates an EPS file from a graph. 379 ///\param g is a reference to the graph to be printed 380 ///\param file_name is the output file_name. 381 /// 382 ///This function also has a lot of \ref named-templ-param "named parameters", 383 ///they are declared as the members of class \ref GraphToEps. The following 384 ///example shows how to use these parameters. 385 ///\code 386 /// graphToEps(g).scale(10).coords(coords) 387 /// .nodeScale(2).nodeSizes(sizes) 388 /// .edgeWidthScale(.4); 389 ///\endcode 390 ///\sa GraphToEps 391 ///\todo Avoid duplicated documentation 392 ///\bug Exception handling is missing? (Or we can just ignore it?) 393 template<class G> 394 GraphToEps<DefaultGraphToEpsTraits<G> > 395 graphToEps(G &g,char *file_name) 396 { 397 return GraphToEps<DefaultGraphToEpsTraits<G> > 398 (DefaultGraphToEpsTraits<G>(g,*new ofstream(file_name),true)); 399 } 400 401 329 402 } 330 403 … … 386 459 e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1; 387 460 388 graphToEps(g).scale(10).coords(coords). 461 graphToEps(g,"proba.eps").scale(10).coords(coords). 462 nodeScale(2).nodeSizes(sizes). 463 nodeColors(composeMap(colorSet,colors)). 464 edgeColors(composeMap(colorSet,ecolors)). 465 edgeWidthScale(.4).edgeWidths(widths); 466 graphToEps(g,"proba_arr.eps").scale(10).coords(coords). 389 467 nodeScale(2).nodeSizes(sizes). 390 468 nodeColors(composeMap(colorSet,colors)).
Note: See TracChangeset
for help on using the changeset viewer.