COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/graph_to_eps.h @ 1936:0722ea2b0907

Last change on this file since 1936:0722ea2b0907 was 1936:0722ea2b0907, checked in by Alpar Juttner, 14 years ago

Fix icc compilation failures.

File size: 37.8 KB
Line 
1/* -*- C++ -*-
2 * lemon/graph_to_eps.h - Part of LEMON, a generic C++ optimization library
3 *
4 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
6 *
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
10 *
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
13 * purpose.
14 *
15 */
16
17#ifndef LEMON_GRAPH_TO_EPS_H
18#define LEMON_GRAPH_TO_EPS_H
19
20#include <sys/time.h>
21
22#include<iostream>
23#include<fstream>
24#include<sstream>
25#include<algorithm>
26#include<vector>
27
28#include <ctime>
29#include <cmath>
30
31#include<lemon/invalid.h>
32#include<lemon/xy.h>
33#include<lemon/maps.h>
34#include<lemon/bezier.h>
35
36
37///\ingroup io_group
38///\file
39///\brief Simple graph drawer
40///
41///\author Alpar Juttner
42
43namespace lemon {
44
45///Data structure representing RGB colors.
46
47///Data structure representing RGB colors.
48///\ingroup misc
49class Color
50{
51  double _r,_g,_b;
52public:
53  ///Default constructor
54  Color() {}
55  ///Constructor
56  Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
57  ///Returns the red component
58  double & red() {return _r;}
59  ///Returns the red component
60  const double & red() const {return _r;}
61  ///Returns the green component
62  double & green() {return _g;}
63  ///Returns the green component
64  const double & green() const {return _g;}
65  ///Returns the blue component
66  double & blue() {return _b;}
67  ///Returns the blue component
68  const double & blue() const {return _b;}
69  ///Set the color components
70  void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
71};
72
73///Maps <tt>int</tt>s to different \ref Color "Color"s
74
75///This map assigns one of the predefined \ref Color "Color"s
76///to each <tt>int</tt>. It is possible to change the colors as well as their
77///number. The integer range is cyclically mapped to the provided set of colors.
78///
79///This is a true \ref concept::ReferenceMap "reference map", so you can also
80///change the actual colors.
81
82class ColorSet : public MapBase<int,Color>
83{
84  std::vector<Color> colors;
85public:
86  ///Constructor
87
88  ///Constructor
89  ///\param have_white indicates whether white is
90  ///amongst the provided color (\c true) or not (\c false). If it is true,
91  ///white will be assigned to \c 0.
92  ///\param num the number of the allocated colors. If it is \c 0
93  ///the default color configuration is set up (26 color plus the while).
94  ///If \c num is less then 26/27 then the default color list is cut. Otherwise
95  ///the color list is filled repeatedly with the default color list.
96  ///(The colors can be changed later on.)
97  ColorSet(bool have_white=false,int num=0)
98  {
99    do {
100      if(have_white) colors.push_back(Color(1,1,1));
101
102      colors.push_back(Color(0,0,0));
103      colors.push_back(Color(1,0,0));
104      colors.push_back(Color(0,1,0));
105      colors.push_back(Color(0,0,1));
106      colors.push_back(Color(1,1,0));
107      colors.push_back(Color(1,0,1));
108      colors.push_back(Color(0,1,1));
109     
110      colors.push_back(Color(.5,0,0));
111      colors.push_back(Color(0,.5,0));
112      colors.push_back(Color(0,0,.5));
113      colors.push_back(Color(.5,.5,0));
114      colors.push_back(Color(.5,0,.5));
115      colors.push_back(Color(0,.5,.5));
116     
117      colors.push_back(Color(.5,.5,.5));
118      colors.push_back(Color(1,.5,.5));
119      colors.push_back(Color(.5,1,.5));
120      colors.push_back(Color(.5,.5,1));
121      colors.push_back(Color(1,1,.5));
122      colors.push_back(Color(1,.5,1));
123      colors.push_back(Color(.5,1,1));
124     
125      colors.push_back(Color(1,.5,0));
126      colors.push_back(Color(.5,1,0));
127      colors.push_back(Color(1,0,.5));
128      colors.push_back(Color(0,1,.5));
129      colors.push_back(Color(0,.5,1));
130      colors.push_back(Color(.5,0,1));
131    } while(int(colors.size())<num);
132    //    colors.push_back(Color(1,1,1));
133    if(num>0) colors.resize(num);
134  }
135  ///\e
136  Color &operator[](int i)
137  {
138    return colors[i%colors.size()];
139  }
140  ///\e
141  const Color &operator[](int i) const
142  {
143    return colors[i%colors.size()];
144  }
145  ///\e
146  void set(int i,const Color &c)
147  {
148    colors[i%colors.size()]=c;
149  }
150  ///Sets the number of the exiting colors.
151  void resize(int s) { colors.resize(s);}
152  ///Returns the number of the existing colors.
153  std::size_t size() const { return colors.size();}
154};
155
156///Returns a visible distinct \ref Color
157
158///Returns a \ref Color which is as different from the given parameter
159///as it is possible.
160inline Color distantColor(const Color &c)
161{
162  return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
163}
164///Returns black for light colors and white for the dark ones.
165
166///Returns black for light colors and white for the dark ones.
167inline Color distantBW(const Color &c){
168  double v=(.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5?1:0;
169  return Color(v,v,v);
170}
171
172template<class MT>
173class _NegY {
174public:
175  typedef typename MT::Key Key;
176  typedef typename MT::Value Value;
177  const MT &map;
178  int yscale;
179  _NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {}
180  Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);}
181};
182
183///Default traits class of \ref GraphToEps
184
185///Default traits class of \ref GraphToEps
186///
187///\c G is the type of the underlying graph.
188template<class G>
189struct DefaultGraphToEpsTraits
190{
191  typedef G Graph;
192  typedef typename Graph::Node Node;
193  typedef typename Graph::NodeIt NodeIt;
194  typedef typename Graph::Edge Edge;
195  typedef typename Graph::EdgeIt EdgeIt;
196  typedef typename Graph::InEdgeIt InEdgeIt;
197  typedef typename Graph::OutEdgeIt OutEdgeIt;
198 
199
200  const Graph &g;
201
202  std::ostream& os;
203 
204  typedef ConstMap<typename Graph::Node,xy<double> > CoordsMapType;
205  CoordsMapType _coords;
206  ConstMap<typename Graph::Node,double > _nodeSizes;
207  ConstMap<typename Graph::Node,int > _nodeShapes;
208
209  ConstMap<typename Graph::Node,Color > _nodeColors;
210  ConstMap<typename Graph::Edge,Color > _edgeColors;
211
212  ConstMap<typename Graph::Edge,double > _edgeWidths;
213
214  double _edgeWidthScale;
215 
216  double _nodeScale;
217  double _xBorder, _yBorder;
218  double _scale;
219  double _nodeBorderQuotient;
220 
221  bool _drawArrows;
222  double _arrowLength, _arrowWidth;
223 
224  bool _showNodes, _showEdges;
225
226  bool _enableParallel;
227  double _parEdgeDist;
228
229  bool _showNodeText;
230  ConstMap<typename Graph::Node,bool > _nodeTexts; 
231  double _nodeTextSize;
232
233  bool _showNodePsText;
234  ConstMap<typename Graph::Node,bool > _nodePsTexts; 
235  char *_nodePsTextsPreamble;
236 
237  bool _undirected;
238
239  bool _pleaseRemoveOsStream;
240
241  bool _scaleToA4;
242
243  std::string _title;
244  std::string _copyright;
245
246  enum NodeTextColorType
247    { DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType;
248  ConstMap<typename Graph::Node,Color > _nodeTextColors;
249
250  bool _autoNodeScale;
251  bool _autoEdgeWidthScale;
252
253  bool _negY;
254  ///Constructor
255
256  ///Constructor
257  ///\param _g is a reference to the graph to be printed
258  ///\param _os is a reference to the output stream.
259  ///\param _os is a reference to the output stream.
260  ///\param _pros If it is \c true, then the \c ostream referenced by \c _os
261  ///will be explicitly deallocated by the destructor.
262  ///By default it is <tt>std::cout</tt>
263  DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
264                          bool _pros=false) :
265    g(_g), os(_os),
266    _coords(xy<double>(1,1)), _nodeSizes(1.0), _nodeShapes(0),
267    _nodeColors(Color(1,1,1)), _edgeColors(Color(0,0,0)),
268    _edgeWidths(1), _edgeWidthScale(0.3),
269    _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
270    _nodeBorderQuotient(.1),
271    _drawArrows(false), _arrowLength(1), _arrowWidth(0.3),
272    _showNodes(true), _showEdges(true),
273    _enableParallel(false), _parEdgeDist(1),
274    _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
275    _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
276    _undirected(false),
277    _pleaseRemoveOsStream(_pros), _scaleToA4(false),
278    _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)),
279    _autoNodeScale(false),
280    _autoEdgeWidthScale(false),
281    _negY(false)
282  {}
283};
284
285///Helper class to implement the named parameters of \ref graphToEps()
286
287///Helper class to implement the named parameters of \ref graphToEps()
288///\todo Is 'helper class' a good name for this?
289///
290///\todo Follow PostScript's DSC.
291/// Use own dictionary.
292///\todo Useful new features.
293/// - Linestyles: dotted, dashed etc.
294/// - A second color and percent value for the lines.
295template<class T> class GraphToEps : public T
296{
297  // Can't believe it is required by the C++ standard
298  using T::g;
299  using T::os;
300
301  using T::_coords;
302  using T::_nodeSizes;
303  using T::_nodeShapes;
304  using T::_nodeColors;
305  using T::_edgeColors;
306  using T::_edgeWidths;
307
308  using T::_edgeWidthScale;
309  using T::_nodeScale;
310  using T::_xBorder;
311  using T::_yBorder;
312  using T::_scale;
313  using T::_nodeBorderQuotient;
314 
315  using T::_drawArrows;
316  using T::_arrowLength;
317  using T::_arrowWidth;
318 
319  using T::_showNodes;
320  using T::_showEdges;
321
322  using T::_enableParallel;
323  using T::_parEdgeDist;
324
325  using T::_showNodeText;
326  using T::_nodeTexts; 
327  using T::_nodeTextSize;
328
329  using T::_showNodePsText;
330  using T::_nodePsTexts; 
331  using T::_nodePsTextsPreamble;
332 
333  using T::_undirected;
334
335  using T::_pleaseRemoveOsStream;
336
337  using T::_scaleToA4;
338
339  using T::_title;
340  using T::_copyright;
341
342  using T::NodeTextColorType;
343  using T::CUST_COL;
344  using T::DIST_COL;
345  using T::DIST_BW;
346  using T::_nodeTextColorType;
347  using T::_nodeTextColors;
348
349  using T::_autoNodeScale;
350  using T::_autoEdgeWidthScale;
351
352  using T::_negY;
353
354  // dradnats ++C eht yb deriuqer si ti eveileb t'naC
355
356  typedef typename T::Graph Graph;
357  typedef typename Graph::Node Node;
358  typedef typename Graph::NodeIt NodeIt;
359  typedef typename Graph::Edge Edge;
360  typedef typename Graph::EdgeIt EdgeIt;
361  typedef typename Graph::InEdgeIt InEdgeIt;
362  typedef typename Graph::OutEdgeIt OutEdgeIt;
363
364  static const int INTERPOL_PREC;
365  static const double A4HEIGHT;
366  static const double A4WIDTH;
367  static const double A4BORDER;
368
369  bool dontPrint;
370
371public:
372  ///Node shapes
373
374  ///Node shapes
375  ///
376  enum NodeShapes {
377    /// = 0
378    ///\image html nodeshape_0.png
379    ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm
380    CIRCLE=0,
381    /// = 1
382    ///\image html nodeshape_1.png
383    ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm
384    ///
385    SQUARE=1,
386    /// = 2
387    ///\image html nodeshape_2.png
388    ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm
389    ///
390    DIAMOND=2,
391    /// = 3
392    ///\image html nodeshape_3.png
393    ///\image latex nodeshape_2.eps "MALE shape (4)" width=2cm
394    ///
395    MALE=3,
396    /// = 4
397    ///\image html nodeshape_4.png
398    ///\image latex nodeshape_2.eps "FEMALE shape (4)" width=2cm
399    ///
400    FEMALE=4
401  };
402
403private:
404  class edgeLess {
405    const Graph &g;
406  public:
407    edgeLess(const Graph &_g) : g(_g) {}
408    bool operator()(Edge a,Edge b) const
409    {
410      Node ai=std::min(g.source(a),g.target(a));
411      Node aa=std::max(g.source(a),g.target(a));
412      Node bi=std::min(g.source(b),g.target(b));
413      Node ba=std::max(g.source(b),g.target(b));
414      return ai<bi ||
415        (ai==bi && (aa < ba ||
416                    (aa==ba && ai==g.source(a) && bi==g.target(b))));
417    }
418  };
419  bool isParallel(Edge e,Edge f) const
420  {
421    return (g.source(e)==g.source(f)&&
422            g.target(e)==g.target(f)) ||
423      (g.source(e)==g.target(f)&&
424       g.target(e)==g.source(f));
425  }
426  template<class TT>
427  static std::string psOut(const xy<TT> &p)
428    {
429      std::ostringstream os;   
430      os << p.x << ' ' << p.y;
431      return os.str();
432    }
433  static std::string psOut(const Color &c)
434    {
435      std::ostringstream os;   
436      os << c.red() << ' ' << c.green() << ' ' << c.blue();
437      return os.str();
438    }
439 
440public:
441  GraphToEps(const T &t) : T(t), dontPrint(false) {};
442 
443  template<class X> struct CoordsTraits : public T {
444  typedef X CoordsMapType;
445    const X &_coords;
446    CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {}
447  };
448  ///Sets the map of the node coordinates
449
450  ///Sets the map of the node coordinates.
451  ///\param x must be a node map with xy<double> or \ref xy "xy<int>" values.
452  template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
453    dontPrint=true;
454    return GraphToEps<CoordsTraits<X> >(CoordsTraits<X>(*this,x));
455  }
456  template<class X> struct NodeSizesTraits : public T {
457    const X &_nodeSizes;
458    NodeSizesTraits(const T &t,const X &x) : T(t), _nodeSizes(x) {}
459  };
460  ///Sets the map of the node sizes
461
462  ///Sets the map of the node sizes
463  ///\param x must be a node map with \c double (or convertible) values.
464  template<class X> GraphToEps<NodeSizesTraits<X> > nodeSizes(const X &x)
465  {
466    dontPrint=true;
467    return GraphToEps<NodeSizesTraits<X> >(NodeSizesTraits<X>(*this,x));
468  }
469  template<class X> struct NodeShapesTraits : public T {
470    const X &_nodeShapes;
471    NodeShapesTraits(const T &t,const X &x) : T(t), _nodeShapes(x) {}
472  };
473  ///Sets the map of the node shapes
474
475  ///Sets the map of the node shapes.
476  ///The availabe shape values
477  ///can be found in \ref NodeShapes "enum NodeShapes".
478  ///\param x must be a node map with \c int (or convertible) values.
479  ///\sa NodeShapes
480  template<class X> GraphToEps<NodeShapesTraits<X> > nodeShapes(const X &x)
481  {
482    dontPrint=true;
483    return GraphToEps<NodeShapesTraits<X> >(NodeShapesTraits<X>(*this,x));
484  }
485  template<class X> struct NodeTextsTraits : public T {
486    const X &_nodeTexts;
487    NodeTextsTraits(const T &t,const X &x) : T(t), _nodeTexts(x) {}
488  };
489  ///Sets the text printed on the nodes
490
491  ///Sets the text printed on the nodes
492  ///\param x must be a node map with type that can be pushed to a standard
493  ///ostream.
494  template<class X> GraphToEps<NodeTextsTraits<X> > nodeTexts(const X &x)
495  {
496    dontPrint=true;
497    _showNodeText=true;
498    return GraphToEps<NodeTextsTraits<X> >(NodeTextsTraits<X>(*this,x));
499  }
500  template<class X> struct NodePsTextsTraits : public T {
501    const X &_nodePsTexts;
502    NodePsTextsTraits(const T &t,const X &x) : T(t), _nodePsTexts(x) {}
503  };
504  ///Inserts a PostScript block to the nodes
505
506  ///With this command it is possible to insert a verbatim PostScript
507  ///block to the nodes.
508  ///The PS current point will be moved to the centre of the node before
509  ///the PostScript block inserted.
510  ///
511  ///Before and after the block a newline character is inserted so you
512  ///don't have to bother with the separators.
513  ///
514  ///\param x must be a node map with type that can be pushed to a standard
515  ///ostream.
516  ///
517  ///\sa nodePsTextsPreamble()
518  ///\todo Offer the choise not to move to the centre but pass the coordinates
519  ///to the Postscript block inserted.
520  template<class X> GraphToEps<NodePsTextsTraits<X> > nodePsTexts(const X &x)
521  {
522    dontPrint=true;
523    _showNodePsText=true;
524    return GraphToEps<NodePsTextsTraits<X> >(NodePsTextsTraits<X>(*this,x));
525  }
526  template<class X> struct EdgeWidthsTraits : public T {
527    const X &_edgeWidths;
528    EdgeWidthsTraits(const T &t,const X &x) : T(t), _edgeWidths(x) {}
529  };
530  ///Sets the map of the edge widths
531
532  ///Sets the map of the edge widths
533  ///\param x must be a edge map with \c double (or convertible) values.
534  template<class X> GraphToEps<EdgeWidthsTraits<X> > edgeWidths(const X &x)
535  {
536    dontPrint=true;
537    return GraphToEps<EdgeWidthsTraits<X> >(EdgeWidthsTraits<X>(*this,x));
538  }
539
540  template<class X> struct NodeColorsTraits : public T {
541    const X &_nodeColors;
542    NodeColorsTraits(const T &t,const X &x) : T(t), _nodeColors(x) {}
543  };
544  ///Sets the map of the node colors
545
546  ///Sets the map of the node colors
547  ///\param x must be a node map with \ref Color values.
548  ///
549  ///\sa ColorSet
550  template<class X> GraphToEps<NodeColorsTraits<X> >
551  nodeColors(const X &x)
552  {
553    dontPrint=true;
554    return GraphToEps<NodeColorsTraits<X> >(NodeColorsTraits<X>(*this,x));
555  }
556  template<class X> struct NodeTextColorsTraits : public T {
557    const X &_nodeTextColors;
558    NodeTextColorsTraits(const T &t,const X &x) : T(t), _nodeTextColors(x) {}
559  };
560  ///Sets the map of the node text colors
561
562  ///Sets the map of the node text colors
563  ///\param x must be a node map with \ref Color values.
564  ///
565  ///\sa ColorSet
566  template<class X> GraphToEps<NodeTextColorsTraits<X> >
567  nodeTextColors(const X &x)
568  {
569    dontPrint=true;
570    _nodeTextColorType=CUST_COL;
571    return GraphToEps<NodeTextColorsTraits<X> >
572      (NodeTextColorsTraits<X>(*this,x));
573  }
574  template<class X> struct EdgeColorsTraits : public T {
575    const X &_edgeColors;
576    EdgeColorsTraits(const T &t,const X &x) : T(t), _edgeColors(x) {}
577  };
578  ///Sets the map of the edge colors
579
580  ///Sets the map of the edge colors
581  ///\param x must be a edge map with \ref Color values.
582  ///
583  ///\sa ColorSet
584  template<class X> GraphToEps<EdgeColorsTraits<X> >
585  edgeColors(const X &x)
586  {
587    dontPrint=true;
588    return GraphToEps<EdgeColorsTraits<X> >(EdgeColorsTraits<X>(*this,x));
589  }
590  ///Sets a global scale factor for node sizes
591
592  ///Sets a global scale factor for node sizes.
593  ///
594  /// If nodeSizes() is not given, this function simply sets the node
595  /// sizes to \c d.  If nodeSizes() is given, but
596  /// autoNodeScale() is not, then the node size given by
597  /// nodeSizes() will be multiplied by the value \c d.
598  /// If both nodeSizes() and autoNodeScale() are used, then the
599  /// node sizes will be scaled in such a way that the greatest size will be
600  /// equal to \c d.
601  GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
602  ///Turns on/off the automatic node width scaling.
603
604  ///Turns on/off the automatic node width scaling.
605  ///
606  ///\sa nodeScale()
607  ///
608  GraphToEps<T> &autoNodeScale(bool b=true) {
609    _autoNodeScale=b;return *this;
610  }
611
612  ///Negates the Y coordinates.
613
614  ///Negates the Y coordinates.
615  ///
616  ///\todo More docs.
617  ///
618  GraphToEps<T> &negateY(bool b=true) {
619    _negY=b;return *this;
620  }
621
622  ///Sets a global scale factor for edge widths
623
624  /// Sets a global scale factor for edge widths.
625  ///
626  /// If edgeWidths() is not given, this function simply sets the edge
627  /// widths to \c d.  If edgeWidths() is given, but
628  /// autoEdgeWidthScale() is not, then the edge withs given by
629  /// edgeWidths() will be multiplied by the value \c d.
630  /// If both edgeWidths() and autoEdgeWidthScale() are used, then the
631  /// edge withs will be scaled in such a way that the greatest width will be
632  /// equal to \c d.
633  GraphToEps<T> &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;}
634  ///Turns on/off the automatic edge width scaling.
635
636  ///Turns on/off the automatic edge width scaling.
637  ///
638  ///\sa edgeWidthScale()
639  ///
640  GraphToEps<T> &autoEdgeWidthScale(bool b=true) {
641    _autoEdgeWidthScale=b;return *this;
642  }
643  ///Sets a global scale factor for the whole picture
644
645  ///Sets a global scale factor for the whole picture
646  ///
647
648  GraphToEps<T> &scale(double d) {_scale=d;return *this;}
649  ///Sets the width of the border around the picture
650
651  ///Sets the width of the border around the picture
652  ///
653  GraphToEps<T> &border(double b) {_xBorder=_yBorder=b;return *this;}
654  ///Sets the width of the border around the picture
655
656  ///Sets the width of the border around the picture
657  ///
658  GraphToEps<T> &border(double x, double y) {
659    _xBorder=x;_yBorder=y;return *this;
660  }
661  ///Sets whether to draw arrows
662
663  ///Sets whether to draw arrows
664  ///
665  GraphToEps<T> &drawArrows(bool b=true) {_drawArrows=b;return *this;}
666  ///Sets the length of the arrowheads
667
668  ///Sets the length of the arrowheads
669  ///
670  GraphToEps<T> &arrowLength(double d) {_arrowLength*=d;return *this;}
671  ///Sets the width of the arrowheads
672
673  ///Sets the width of the arrowheads
674  ///
675  GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;}
676 
677  ///Scales the drawing to fit to A4 page
678
679  ///Scales the drawing to fit to A4 page
680  ///
681  GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
682 
683  ///Enables parallel edges
684
685  ///Enables parallel edges
686  GraphToEps<T> &enableParallel(bool b=true) {_enableParallel=b;return *this;}
687 
688  ///Sets the distance
689 
690  ///Sets the distance
691  ///
692  GraphToEps<T> &parEdgeDist(double d) {_parEdgeDist*=d;return *this;}
693 
694  ///Hides the edges
695 
696  ///Hides the edges
697  ///
698  GraphToEps<T> &hideEdges(bool b=true) {_showEdges=!b;return *this;}
699  ///Hides the nodes
700 
701  ///Hides the nodes
702  ///
703  GraphToEps<T> &hideNodes(bool b=true) {_showNodes=!b;return *this;}
704 
705  ///Sets the size of the node texts
706 
707  ///Sets the size of the node texts
708  ///
709  GraphToEps<T> &nodeTextSize(double d) {_nodeTextSize=d;return *this;}
710
711  ///Sets the color of the node texts to be different from the node color
712
713  ///Sets the color of the node texts to be as different from the node color
714  ///as it is possible
715  ///
716  GraphToEps<T> &distantColorNodeTexts()
717  {_nodeTextColorType=DIST_COL;return *this;}
718  ///Sets the color of the node texts to be black or white and always visible.
719
720  ///Sets the color of the node texts to be black or white according to
721  ///which is more
722  ///different from the node color
723  ///
724  GraphToEps<T> &distantBWNodeTexts()
725  {_nodeTextColorType=DIST_BW;return *this;}
726
727  ///Gives a preamble block for node Postscript block.
728 
729  ///Gives a preamble block for node Postscript block.
730  ///
731  ///\sa nodePsTexts()
732  GraphToEps<T> & nodePsTextsPreamble(const char *str) {
733    _nodePsTextsPreamble=str ;return *this;
734  }
735  ///Sets whether the the graph is undirected
736
737  ///Sets whether the the graph is undirected
738  ///
739  GraphToEps<T> &undirected(bool b=true) {_undirected=b;return *this;}
740
741  ///Sets whether the the graph is directed
742
743  ///Sets whether the the graph is directed.
744  ///Use it to show the undirected edges as a pair of directed ones.
745  GraphToEps<T> &bidir(bool b=true) {_undirected=!b;return *this;}
746
747  ///Sets the title.
748
749  ///Sets the title of the generated image,
750  ///namely it inserts a <tt>%%Title:</tt> DSC field to the header of
751  ///the EPS file.
752  GraphToEps<T> &title(const std::string &t) {_title=t;return *this;}
753  ///Sets the copyright statement.
754
755  ///Sets the copyright statement of the generated image,
756  ///namely it inserts a <tt>%%Copyright:</tt> DSC field to the header of
757  ///the EPS file.
758  ///\todo Multiline copyright notice could be supported.
759  GraphToEps<T> &copyright(const std::string &t) {_copyright=t;return *this;}
760
761protected:
762  bool isInsideNode(xy<double> p, double r,int t)
763  {
764    switch(t) {
765    case CIRCLE:
766    case MALE:
767    case FEMALE:
768      return p.normSquare()<=r*r;
769    case SQUARE:
770      return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r;
771    case DIAMOND:
772      return p.x+p.y<=r && p.x-p.y<=r && -p.x+p.y<=r && -p.x-p.y<=r;
773    }
774    return false;
775  }
776
777public:
778  ~GraphToEps() { }
779 
780  ///Draws the graph.
781
782  ///Like other functions using
783  ///\ref named-templ-func-param "named template parameters",
784  ///this function calles the algorithm itself, i.e. in this case
785  ///it draws the graph.
786  void run() {
787    if(dontPrint) return;
788   
789    _NegY<typename T::CoordsMapType> mycoords(_coords,_negY);
790
791    os << "%!PS-Adobe-2.0 EPSF-2.0\n";
792    if(_title.size()>0) os << "%%Title: " << _title << '\n';
793     if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n';
794//        << "%%Copyright: XXXX\n"
795    os << "%%Creator: LEMON, graphToEps()\n";
796   
797    {
798      char cbuf[50];
799      timeval tv;
800      gettimeofday(&tv, 0);
801      ctime_r(&tv.tv_sec,cbuf);
802      os << "%%CreationDate: " << cbuf;
803    }
804
805    if (_autoEdgeWidthScale) {
806      double max_w=0;
807      for(EdgeIt e(g);e!=INVALID;++e)
808        max_w=std::max(double(_edgeWidths[e]),max_w);
809      ///\todo better 'epsilon' would be nice here.
810      if(max_w>1e-9) {
811        _edgeWidthScale/=max_w;
812      }
813    }
814
815    if (_autoNodeScale) {
816      double max_s=0;
817      for(NodeIt n(g);n!=INVALID;++n)
818        max_s=std::max(double(_nodeSizes[n]),max_s);
819      ///\todo better 'epsilon' would be nice here.
820      if(max_s>1e-9) {
821        _nodeScale/=max_s;
822      }
823    }
824
825
826    BoundingBox<double> bb;
827    ///\bug: Chech whether the graph is empty.
828    for(NodeIt n(g);n!=INVALID;++n) {
829      double ns=_nodeSizes[n]*_nodeScale;
830      xy<double> p(ns,ns);
831      switch(_nodeShapes[n]) {
832      case CIRCLE:
833      case SQUARE:
834      case DIAMOND:
835        bb.add(p+mycoords[n]);
836        bb.add(-p+mycoords[n]);
837        break;
838      case MALE:
839        bb.add(-p+mycoords[n]);
840        bb.add(xy<double>(1.5*ns,1.5*std::sqrt(3.0)*ns)+mycoords[n]);
841        break;
842      case FEMALE:
843        bb.add(p+mycoords[n]);
844        bb.add(xy<double>(-ns,-3.01*ns)+mycoords[n]);
845        break;
846      }
847    }
848    if (bb.empty()) {
849      bb = BoundingBox<double>(xy<double>(0,0));
850    }
851   
852    if(_scaleToA4)
853      os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
854    else {
855      //Rescale so that BoundingBox won't be neither to big nor too small.
856      while(bb.height()*_scale>1000||bb.width()*_scale>1000) _scale/=10;
857      while(bb.height()*_scale<100||bb.width()*_scale<100) _scale*=10;
858   
859      os << "%%BoundingBox: "
860         << int(floor(bb.left()   * _scale - _xBorder)) << ' '
861         << int(floor(bb.bottom() * _scale - _yBorder)) << ' '
862         << int(ceil(bb.right()  * _scale + _xBorder)) << ' '
863         << int(ceil(bb.top()    * _scale + _yBorder)) << '\n';
864    }
865   
866    os << "%%EndComments\n";
867   
868    //x1 y1 x2 y2 x3 y3 cr cg cb w
869    os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
870       << "      4 2 roll 1 index 1 index curveto stroke } bind def\n";
871    os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n";
872    //x y r
873    os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def\n";
874    //x y r
875    os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n"
876       << "      2 index 1 index sub 2 index 2 index add lineto\n"
877       << "      2 index 1 index sub 2 index 2 index sub lineto\n"
878       << "      2 index 1 index add 2 index 2 index sub lineto\n"
879       << "      closepath pop pop pop} bind def\n";
880    //x y r
881    os << "/di { newpath 2 index 1 index add 2 index moveto\n"
882       << "      2 index             2 index 2 index add lineto\n"
883       << "      2 index 1 index sub 2 index             lineto\n"
884       << "      2 index             2 index 2 index sub lineto\n"
885       << "      closepath pop pop pop} bind def\n";
886    // x y r cr cg cb
887    os << "/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill\n"
888       << "     setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n"
889       << "   } bind def\n";
890    os << "/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill\n"
891       << "     setrgbcolor " << 1+_nodeBorderQuotient << " div sq fill\n"
892       << "   } bind def\n";
893    os << "/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill\n"
894       << "     setrgbcolor " << 1+_nodeBorderQuotient << " div di fill\n"
895       << "   } bind def\n";
896    os << "/nfemale { 0 0 0 setrgbcolor 3 index "
897       << _nodeBorderQuotient/(1+_nodeBorderQuotient)
898       << " 1.5 mul mul setlinewidth\n"
899       << "  newpath 5 index 5 index moveto "
900       << "5 index 5 index 5 index 3.01 mul sub\n"
901       << "  lineto 5 index 4 index .7 mul sub 5 index 5 index 2.2 mul sub moveto\n"
902       << "  5 index 4 index .7 mul add 5 index 5 index 2.2 mul sub lineto stroke\n"
903       << "  5 index 5 index 5 index c fill\n"
904       << "  setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n"
905       << "  } bind def\n";
906    os << "/nmale {\n"
907       << "  0 0 0 setrgbcolor 3 index "
908       << _nodeBorderQuotient/(1+_nodeBorderQuotient)
909       <<" 1.5 mul mul setlinewidth\n"
910       << "  newpath 5 index 5 index moveto\n"
911       << "  5 index 4 index 1 mul 1.5 mul add\n"
912       << "  5 index 5 index 3 sqrt 1.5 mul mul add\n"
913       << "  1 index 1 index lineto\n"
914       << "  1 index 1 index 7 index sub moveto\n"
915       << "  1 index 1 index lineto\n"
916       << "  exch 5 index 3 sqrt .5 mul mul sub exch 5 index .5 mul sub lineto\n"
917       << "  stroke\n"
918       << "  5 index 5 index 5 index c fill\n"
919       << "  setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n"
920       << "  } bind def\n";
921   
922
923    os << "/arrl " << _arrowLength << " def\n";
924    os << "/arrw " << _arrowWidth << " def\n";
925    // l dx_norm dy_norm
926    os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
927    //len w dx_norm dy_norm x1 y1 cr cg cb
928    os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n"
929       << "       /w exch def /len exch def\n"
930      //         << "       0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke"
931       << "       newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto\n"
932       << "       len w sub arrl sub dx dy lrl\n"
933       << "       arrw dy dx neg lrl\n"
934       << "       dx arrl w add mul dy w 2 div arrw add mul sub\n"
935       << "       dy arrl w add mul dx w 2 div arrw add mul add rlineto\n"
936       << "       dx arrl w add mul neg dy w 2 div arrw add mul sub\n"
937       << "       dy arrl w add mul neg dx w 2 div arrw add mul add rlineto\n"
938       << "       arrw dy dx neg lrl\n"
939       << "       len w sub arrl sub neg dx dy lrl\n"
940       << "       closepath fill } bind def\n";
941    os << "/cshow { 2 index 2 index moveto dup stringwidth pop\n"
942       << "         neg 2 div fosi .35 mul neg rmoveto show pop pop} def\n";
943
944    os << "\ngsave\n";
945    if(_scaleToA4)
946      if(bb.height()>bb.width()) {
947        double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.height(),
948                  (A4WIDTH-2*A4BORDER)/bb.width());
949        os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' '
950           << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER << " translate\n"
951           << sc << " dup scale\n"
952           << -bb.left() << ' ' << -bb.bottom() << " translate\n";
953      }
954      else {
955        //\todo Verify centering
956        double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.width(),
957                  (A4WIDTH-2*A4BORDER)/bb.height());
958        os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' '
959           << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER  << " translate\n"
960           << sc << " dup scale\n90 rotate\n"
961           << -bb.left() << ' ' << -bb.top() << " translate\n";
962        }
963    else if(_scale!=1.0) os << _scale << " dup scale\n";
964   
965    if(_showEdges) {
966      os << "%Edges:\ngsave\n";     
967      if(_enableParallel) {
968        std::vector<Edge> el;
969        for(EdgeIt e(g);e!=INVALID;++e)
970          if((!_undirected||g.source(e)<g.target(e))&&_edgeWidths[e]>0)
971            el.push_back(e);
972        std::sort(el.begin(),el.end(),edgeLess(g));
973       
974        typename std::vector<Edge>::iterator j;
975        for(typename std::vector<Edge>::iterator i=el.begin();i!=el.end();i=j) {
976          for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ;
977
978          double sw=0;
979          for(typename std::vector<Edge>::iterator e=i;e!=j;++e)
980            sw+=_edgeWidths[*e]*_edgeWidthScale+_parEdgeDist;
981          sw-=_parEdgeDist;
982          sw/=-2.0;
983          xy<double> dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]);
984          double l=std::sqrt(dvec.normSquare());
985          ///\todo better 'epsilon' would be nice here.
986          xy<double> d(dvec/std::max(l,1e-9));
987          xy<double> m;
988//        m=xy<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
989
990//        m=xy<double>(mycoords[g.source(*i)])+
991//          dvec*(double(_nodeSizes[g.source(*i)])/
992//             (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
993
994          m=xy<double>(mycoords[g.source(*i)])+
995            d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
996
997          for(typename std::vector<Edge>::iterator e=i;e!=j;++e) {
998            sw+=_edgeWidths[*e]*_edgeWidthScale/2.0;
999            xy<double> mm=m+rot90(d)*sw/.75;
1000            if(_drawArrows) {
1001              int node_shape;
1002              xy<double> s=mycoords[g.source(*e)];
1003              xy<double> t=mycoords[g.target(*e)];
1004              double rn=_nodeSizes[g.target(*e)]*_nodeScale;
1005              node_shape=_nodeShapes[g.target(*e)];
1006              Bezier3 bez(s,mm,mm,t);
1007              double t1=0,t2=1;
1008              for(int i=0;i<INTERPOL_PREC;++i)
1009                if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t2=(t1+t2)/2;
1010                else t1=(t1+t2)/2;
1011              xy<double> apoint=bez((t1+t2)/2);
1012              rn = _arrowLength+_edgeWidths[*e]*_edgeWidthScale;
1013              rn*=rn;
1014              t2=(t1+t2)/2;t1=0;
1015              for(int i=0;i<INTERPOL_PREC;++i)
1016                if((bez((t1+t2)/2)-apoint).normSquare()>rn) t1=(t1+t2)/2;
1017                else t2=(t1+t2)/2;
1018              xy<double> linend=bez((t1+t2)/2);       
1019              bez=bez.before((t1+t2)/2);
1020//            rn=_nodeSizes[g.source(*e)]*_nodeScale;
1021//            node_shape=_nodeShapes[g.source(*e)];
1022//            t1=0;t2=1;
1023//            for(int i=0;i<INTERPOL_PREC;++i)
1024//              if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t1=(t1+t2)/2;
1025//              else t2=(t1+t2)/2;
1026//            bez=bez.after((t1+t2)/2);
1027              os << _edgeWidths[*e]*_edgeWidthScale << " setlinewidth "
1028                 << _edgeColors[*e].red() << ' '
1029                 << _edgeColors[*e].green() << ' '
1030                 << _edgeColors[*e].blue() << " setrgbcolor newpath\n"
1031                 << bez.p1.x << ' ' <<  bez.p1.y << " moveto\n"
1032                 << bez.p2.x << ' ' << bez.p2.y << ' '
1033                 << bez.p3.x << ' ' << bez.p3.y << ' '
1034                 << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
1035              xy<double> dd(rot90(linend-apoint));
1036              dd*=(.5*_edgeWidths[*e]*_edgeWidthScale+_arrowWidth)/
1037                std::sqrt(dd.normSquare());
1038              os << "newpath " << psOut(apoint) << " moveto "
1039                 << psOut(linend+dd) << " lineto "
1040                 << psOut(linend-dd) << " lineto closepath fill\n";
1041            }
1042            else {
1043              os << mycoords[g.source(*e)].x << ' '
1044                 << mycoords[g.source(*e)].y << ' '
1045                 << mm.x << ' ' << mm.y << ' '
1046                 << mycoords[g.target(*e)].x << ' '
1047                 << mycoords[g.target(*e)].y << ' '
1048                 << _edgeColors[*e].red() << ' '
1049                 << _edgeColors[*e].green() << ' '
1050                 << _edgeColors[*e].blue() << ' '
1051                 << _edgeWidths[*e]*_edgeWidthScale << " lb\n";
1052            }
1053            sw+=_edgeWidths[*e]*_edgeWidthScale/2.0+_parEdgeDist;
1054          }
1055        }
1056      }
1057      else for(EdgeIt e(g);e!=INVALID;++e)
1058        if((!_undirected||g.source(e)<g.target(e))&&_edgeWidths[e]>0)
1059          if(_drawArrows) {
1060            xy<double> d(mycoords[g.target(e)]-mycoords[g.source(e)]);
1061            double rn=_nodeSizes[g.target(e)]*_nodeScale;
1062            int node_shape=_nodeShapes[g.target(e)];
1063            double t1=0,t2=1;
1064            for(int i=0;i<INTERPOL_PREC;++i)
1065              if(isInsideNode((-(t1+t2)/2)*d,rn,node_shape)) t1=(t1+t2)/2;
1066              else t2=(t1+t2)/2;
1067            double l=std::sqrt(d.normSquare());
1068            d/=l;
1069           
1070            os << l*(1-(t1+t2)/2) << ' '
1071               << _edgeWidths[e]*_edgeWidthScale << ' '
1072               << d.x << ' ' << d.y << ' '
1073               << mycoords[g.source(e)].x << ' '
1074               << mycoords[g.source(e)].y << ' '
1075               << _edgeColors[e].red() << ' '
1076               << _edgeColors[e].green() << ' '
1077               << _edgeColors[e].blue() << " arr\n";
1078          }
1079          else os << mycoords[g.source(e)].x << ' '
1080                  << mycoords[g.source(e)].y << ' '
1081                  << mycoords[g.target(e)].x << ' '
1082                  << mycoords[g.target(e)].y << ' '
1083                  << _edgeColors[e].red() << ' '
1084                  << _edgeColors[e].green() << ' '
1085                  << _edgeColors[e].blue() << ' '
1086                  << _edgeWidths[e]*_edgeWidthScale << " l\n";
1087      os << "grestore\n";
1088    }
1089    if(_showNodes) {
1090      os << "%Nodes:\ngsave\n";
1091      for(NodeIt n(g);n!=INVALID;++n) {
1092        os << mycoords[n].x << ' ' << mycoords[n].y << ' '
1093           << _nodeSizes[n]*_nodeScale << ' '
1094           << _nodeColors[n].red() << ' '
1095           << _nodeColors[n].green() << ' '
1096           << _nodeColors[n].blue() << ' ';
1097        switch(_nodeShapes[n]) {
1098        case CIRCLE:
1099          os<< "nc";break;
1100        case SQUARE:
1101          os<< "nsq";break;
1102        case DIAMOND:
1103          os<< "ndi";break;
1104        case MALE:
1105          os<< "nmale";break;
1106        case FEMALE:
1107          os<< "nfemale";break;
1108        }
1109        os<<'\n';
1110      }
1111      os << "grestore\n";
1112    }
1113    if(_showNodeText) {
1114      os << "%Node texts:\ngsave\n";
1115      os << "/fosi " << _nodeTextSize << " def\n";
1116      os << "(Helvetica) findfont fosi scalefont setfont\n";
1117      for(NodeIt n(g);n!=INVALID;++n) {
1118        switch(_nodeTextColorType) {
1119        case DIST_COL:
1120          os << psOut(distantColor(_nodeColors[n])) << " setrgbcolor\n";
1121          break;
1122        case DIST_BW:
1123          os << psOut(distantBW(_nodeColors[n])) << " setrgbcolor\n";
1124          break;
1125        case CUST_COL:
1126          os << psOut(distantColor(_nodeTextColors[n])) << " setrgbcolor\n";
1127          break;
1128        default:
1129          os << "0 0 0 setrgbcolor\n";
1130        }
1131        os << mycoords[n].x << ' ' << mycoords[n].y
1132           << " (" << _nodeTexts[n] << ") cshow\n";
1133      }
1134      os << "grestore\n";
1135    }
1136    if(_showNodePsText) {
1137      os << "%Node PS blocks:\ngsave\n";
1138      for(NodeIt n(g);n!=INVALID;++n)
1139        os << mycoords[n].x << ' ' << mycoords[n].y
1140           << " moveto\n" << _nodePsTexts[n] << "\n";
1141      os << "grestore\n";
1142    }
1143   
1144    os << "grestore\nshowpage\n";
1145
1146    //CleanUp:
1147    if(_pleaseRemoveOsStream) {delete &os;}
1148  }
1149};
1150
1151template<class T>
1152const int GraphToEps<T>::INTERPOL_PREC = 20;
1153template<class T>
1154const double GraphToEps<T>::A4HEIGHT = 841.8897637795276;
1155template<class T>
1156const double GraphToEps<T>::A4WIDTH  = 595.275590551181;
1157template<class T>
1158const double GraphToEps<T>::A4BORDER = 15;
1159
1160
1161///Generates an EPS file from a graph
1162
1163///\ingroup io_group
1164///Generates an EPS file from a graph.
1165///\param g is a reference to the graph to be printed
1166///\param os is a reference to the output stream.
1167///By default it is <tt>std::cout</tt>
1168///
1169///This function also has a lot of
1170///\ref named-templ-func-param "named parameters",
1171///they are declared as the members of class \ref GraphToEps. The following
1172///example shows how to use these parameters.
1173///\code
1174/// graphToEps(g,os).scale(10).coords(coords)
1175///              .nodeScale(2).nodeSizes(sizes)
1176///              .edgeWidthScale(.4).run();
1177///\endcode
1178///\warning Don't forget to put the \ref GraphToEps::run() "run()"
1179///to the end of the parameter list.
1180///\sa GraphToEps
1181///\sa graphToEps(G &g, const char *file_name)
1182template<class G>
1183GraphToEps<DefaultGraphToEpsTraits<G> >
1184graphToEps(G &g, std::ostream& os=std::cout)
1185{
1186  return
1187    GraphToEps<DefaultGraphToEpsTraits<G> >(DefaultGraphToEpsTraits<G>(g,os));
1188}
1189 
1190///Generates an EPS file from a graph
1191
1192///\ingroup io_group
1193///This function does the same as
1194///\ref graphToEps(G &g,std::ostream& os)
1195///but it writes its output into the file \c file_name
1196///instead of a stream.
1197///\sa graphToEps(G &g, std::ostream& os)
1198template<class G>
1199GraphToEps<DefaultGraphToEpsTraits<G> >
1200graphToEps(G &g,const char *file_name)
1201{
1202  return GraphToEps<DefaultGraphToEpsTraits<G> >
1203    (DefaultGraphToEpsTraits<G>(g,*new std::ofstream(file_name),true));
1204}
1205
1206///Generates an EPS file from a graph
1207
1208///\ingroup io_group
1209///This function does the same as
1210///\ref graphToEps(G &g,std::ostream& os)
1211///but it writes its output into the file \c file_name
1212///instead of a stream.
1213///\sa graphToEps(G &g, std::ostream& os)
1214template<class G>
1215GraphToEps<DefaultGraphToEpsTraits<G> >
1216graphToEps(G &g,const std::string& file_name)
1217{
1218  return GraphToEps<DefaultGraphToEpsTraits<G> >
1219    (DefaultGraphToEpsTraits<G>(g,*new std::ofstream(file_name.c_str()),true));
1220}
1221
1222} //END OF NAMESPACE LEMON
1223
1224#endif // LEMON_GRAPH_TO_EPS_H
Note: See TracBrowser for help on using the repository browser.