lemon/graph_to_eps.h
author alpar
Thu, 01 Sep 2005 19:21:35 +0000
changeset 1673 8919ca9e70f3
parent 1642 a2dda876316f
child 1676 c3e416514759
permissions -rw-r--r--
negateY() option added.
     1 /* -*- C++ -*-
     2  * lemon/graph_to_eps.h - Part of LEMON, a generic C++ optimization library
     3  *
     4  * Copyright (C) 2005 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 
    43 namespace lemon {
    44 
    45 ///Data structure representing RGB colors.
    46 
    47 ///Data structure representing RGB colors.
    48 ///\ingroup misc
    49 class Color
    50 {
    51   double _r,_g,_b;
    52 public:
    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 
    82 class ColorSet : public MapBase<int,Color>
    83 {
    84   std::vector<Color> colors;
    85 public:
    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.
   160 inline 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.
   167 inline 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 
   172 template<class MT>
   173 class _NegY {
   174 public:
   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.
   188 template<class G>
   189 struct 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 _undir;
   238   bool _pleaseRemoveOsStream;
   239 
   240   bool _scaleToA4;
   241 
   242   std::string _title;
   243   std::string _copyright;
   244 
   245   enum NodeTextColorType 
   246     { DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType;
   247   ConstMap<typename Graph::Node,Color > _nodeTextColors;
   248 
   249   bool _autoNodeScale;
   250   bool _autoEdgeWidthScale;
   251 
   252   bool _negY;
   253   ///Constructor
   254 
   255   ///Constructor
   256   ///\param _g is a reference to the graph to be printed
   257   ///\param _os is a reference to the output stream.
   258   ///\param _os is a reference to the output stream.
   259   ///\param _pros If it is \c true, then the \c ostream referenced by \c _os
   260   ///will be explicitly deallocated by the destructor.
   261   ///By default it is <tt>std::cout</tt>
   262   DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
   263 			  bool _pros=false) :
   264     g(_g), os(_os),
   265     _coords(xy<double>(1,1)), _nodeSizes(1.0), _nodeShapes(0),
   266     _nodeColors(Color(1,1,1)), _edgeColors(Color(0,0,0)),
   267     _edgeWidths(1), _edgeWidthScale(0.3),
   268     _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
   269     _nodeBorderQuotient(.1),
   270     _drawArrows(false), _arrowLength(1), _arrowWidth(0.3),
   271     _showNodes(true), _showEdges(true),
   272     _enableParallel(false), _parEdgeDist(1),
   273     _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
   274     _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
   275     _undir(false),
   276     _pleaseRemoveOsStream(_pros), _scaleToA4(false),
   277     _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)),
   278     _autoNodeScale(false),
   279     _autoEdgeWidthScale(false),
   280     _negY(false)
   281   {}
   282 };
   283 
   284 ///Helper class to implement the named parameters of \ref graphToEps()
   285 
   286 ///Helper class to implement the named parameters of \ref graphToEps()
   287 ///\todo Is 'helper class' a good name for this?
   288 ///
   289 ///\todo Follow PostScript's DSC.
   290 /// Use own dictionary.
   291 ///\todo Useful new features.
   292 /// - Linestyles: dotted, dashed etc.
   293 /// - A second color and percent value for the lines.
   294 template<class T> class GraphToEps : public T 
   295 {
   296   // Can't believe it is required by the C++ standard
   297   using T::g;
   298   using T::os;
   299 
   300   using T::_coords;
   301   using T::_nodeSizes;
   302   using T::_nodeShapes;
   303   using T::_nodeColors;
   304   using T::_edgeColors;
   305   using T::_edgeWidths;
   306 
   307   using T::_edgeWidthScale;
   308   using T::_nodeScale;
   309   using T::_xBorder;
   310   using T::_yBorder;
   311   using T::_scale;
   312   using T::_nodeBorderQuotient;
   313   
   314   using T::_drawArrows;
   315   using T::_arrowLength;
   316   using T::_arrowWidth;
   317   
   318   using T::_showNodes;
   319   using T::_showEdges;
   320 
   321   using T::_enableParallel;
   322   using T::_parEdgeDist;
   323 
   324   using T::_showNodeText;
   325   using T::_nodeTexts;  
   326   using T::_nodeTextSize;
   327 
   328   using T::_showNodePsText;
   329   using T::_nodePsTexts;  
   330   using T::_nodePsTextsPreamble;
   331   
   332   using T::_undir;
   333   using T::_pleaseRemoveOsStream;
   334 
   335   using T::_scaleToA4;
   336 
   337   using T::_title;
   338   using T::_copyright;
   339 
   340   using T::NodeTextColorType;
   341   using T::CUST_COL;
   342   using T::DIST_COL;
   343   using T::DIST_BW;
   344   using T::_nodeTextColorType;
   345   using T::_nodeTextColors;
   346 
   347   using T::_autoNodeScale;
   348   using T::_autoEdgeWidthScale;
   349 
   350   // dradnats ++C eht yb deriuqer si ti eveileb t'naC
   351 
   352   typedef typename T::Graph Graph;
   353   typedef typename Graph::Node Node;
   354   typedef typename Graph::NodeIt NodeIt;
   355   typedef typename Graph::Edge Edge;
   356   typedef typename Graph::EdgeIt EdgeIt;
   357   typedef typename Graph::InEdgeIt InEdgeIt;
   358   typedef typename Graph::OutEdgeIt OutEdgeIt;
   359 
   360   static const int INTERPOL_PREC;
   361   static const double A4HEIGHT;
   362   static const double A4WIDTH;
   363   static const double A4BORDER;
   364 
   365   bool dontPrint;
   366 
   367 public:
   368   ///Node shapes
   369 
   370   ///Node shapes
   371   ///
   372   enum NodeShapes { 
   373     /// = 0
   374     ///\image html nodeshape_0.png
   375     ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm
   376     CIRCLE=0, 
   377     /// = 1
   378     ///\image html nodeshape_1.png
   379     ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm
   380     ///
   381     SQUARE=1, 
   382     /// = 2
   383     ///\image html nodeshape_2.png
   384     ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm
   385     ///
   386     DIAMOND=2
   387   };
   388 
   389 private:
   390   class edgeLess {
   391     const Graph &g;
   392   public:
   393     edgeLess(const Graph &_g) : g(_g) {}
   394     bool operator()(Edge a,Edge b) const 
   395     {
   396       Node ai=std::min(g.source(a),g.target(a));
   397       Node aa=std::max(g.source(a),g.target(a));
   398       Node bi=std::min(g.source(b),g.target(b));
   399       Node ba=std::max(g.source(b),g.target(b));
   400       return ai<bi ||
   401 	(ai==bi && (aa < ba || 
   402 		    (aa==ba && ai==g.source(a) && bi==g.target(b))));
   403     }
   404   };
   405   bool isParallel(Edge e,Edge f) const
   406   {
   407     return (g.source(e)==g.source(f)&&
   408 	    g.target(e)==g.target(f)) ||
   409       (g.source(e)==g.target(f)&&
   410        g.target(e)==g.source(f));
   411   }
   412   template<class TT>
   413   static std::string psOut(const xy<TT> &p) 
   414     {
   415       std::ostringstream os;	
   416       os << p.x << ' ' << p.y;
   417       return os.str();
   418     }
   419   static std::string psOut(const Color &c) 
   420     {
   421       std::ostringstream os;	
   422       os << c.red() << ' ' << c.green() << ' ' << c.blue();
   423       return os.str();
   424     }
   425   
   426 public:
   427   GraphToEps(const T &t) : T(t), dontPrint(false) {};
   428   
   429   template<class X> struct CoordsTraits : public T {
   430   typedef X CoordsMapType;
   431     const X &_coords;
   432     CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {}
   433   };
   434   ///Sets the map of the node coordinates
   435 
   436   ///Sets the map of the node coordinates.
   437   ///\param x must be a node map with xy<double> or \ref xy "xy<int>" values. 
   438   template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
   439     dontPrint=true;
   440     return GraphToEps<CoordsTraits<X> >(CoordsTraits<X>(*this,x));
   441   }
   442   template<class X> struct NodeSizesTraits : public T {
   443     const X &_nodeSizes;
   444     NodeSizesTraits(const T &t,const X &x) : T(t), _nodeSizes(x) {}
   445   };
   446   ///Sets the map of the node sizes
   447 
   448   ///Sets the map of the node sizes
   449   ///\param x must be a node map with \c double (or convertible) values. 
   450   template<class X> GraphToEps<NodeSizesTraits<X> > nodeSizes(const X &x)
   451   {
   452     dontPrint=true;
   453     return GraphToEps<NodeSizesTraits<X> >(NodeSizesTraits<X>(*this,x));
   454   }
   455   template<class X> struct NodeShapesTraits : public T {
   456     const X &_nodeShapes;
   457     NodeShapesTraits(const T &t,const X &x) : T(t), _nodeShapes(x) {}
   458   };
   459   ///Sets the map of the node shapes
   460 
   461   ///Sets the map of the node shapes.
   462   ///The availabe shape values
   463   ///can be found in \ref NodeShapes "enum NodeShapes".
   464   ///\param x must be a node map with \c int (or convertible) values. 
   465   ///\sa NodeShapes
   466   template<class X> GraphToEps<NodeShapesTraits<X> > nodeShapes(const X &x)
   467   {
   468     dontPrint=true;
   469     return GraphToEps<NodeShapesTraits<X> >(NodeShapesTraits<X>(*this,x));
   470   }
   471   template<class X> struct NodeTextsTraits : public T {
   472     const X &_nodeTexts;
   473     NodeTextsTraits(const T &t,const X &x) : T(t), _nodeTexts(x) {}
   474   };
   475   ///Sets the text printed on the nodes
   476 
   477   ///Sets the text printed on the nodes
   478   ///\param x must be a node map with type that can be pushed to a standard
   479   ///ostream. 
   480   template<class X> GraphToEps<NodeTextsTraits<X> > nodeTexts(const X &x)
   481   {
   482     dontPrint=true;
   483     _showNodeText=true;
   484     return GraphToEps<NodeTextsTraits<X> >(NodeTextsTraits<X>(*this,x));
   485   }
   486   template<class X> struct NodePsTextsTraits : public T {
   487     const X &_nodePsTexts;
   488     NodePsTextsTraits(const T &t,const X &x) : T(t), _nodePsTexts(x) {}
   489   };
   490   ///Inserts a PostScript block to the nodes
   491 
   492   ///With this command it is possible to insert a verbatim PostScript
   493   ///block to the nodes.
   494   ///The PS current point will be moved to the centre of the node before
   495   ///the PostScript block inserted.
   496   ///
   497   ///Before and after the block a newline character is inserted so you
   498   ///don't have to bother with the separators.
   499   ///
   500   ///\param x must be a node map with type that can be pushed to a standard
   501   ///ostream.
   502   ///
   503   ///\sa nodePsTextsPreamble()
   504   ///\todo Offer the choise not to move to the centre but pass the coordinates
   505   ///to the Postscript block inserted.
   506   template<class X> GraphToEps<NodePsTextsTraits<X> > nodePsTexts(const X &x)
   507   {
   508     dontPrint=true;
   509     _showNodePsText=true;
   510     return GraphToEps<NodePsTextsTraits<X> >(NodePsTextsTraits<X>(*this,x));
   511   }
   512   template<class X> struct EdgeWidthsTraits : public T {
   513     const X &_edgeWidths;
   514     EdgeWidthsTraits(const T &t,const X &x) : T(t), _edgeWidths(x) {}
   515   };
   516   ///Sets the map of the edge widths
   517 
   518   ///Sets the map of the edge widths
   519   ///\param x must be a edge map with \c double (or convertible) values. 
   520   template<class X> GraphToEps<EdgeWidthsTraits<X> > edgeWidths(const X &x)
   521   {
   522     dontPrint=true;
   523     return GraphToEps<EdgeWidthsTraits<X> >(EdgeWidthsTraits<X>(*this,x));
   524   }
   525 
   526   template<class X> struct NodeColorsTraits : public T {
   527     const X &_nodeColors;
   528     NodeColorsTraits(const T &t,const X &x) : T(t), _nodeColors(x) {}
   529   };
   530   ///Sets the map of the node colors
   531 
   532   ///Sets the map of the node colors
   533   ///\param x must be a node map with \ref Color values.
   534   ///
   535   ///\sa ColorSet
   536   template<class X> GraphToEps<NodeColorsTraits<X> >
   537   nodeColors(const X &x)
   538   {
   539     dontPrint=true;
   540     return GraphToEps<NodeColorsTraits<X> >(NodeColorsTraits<X>(*this,x));
   541   }
   542   template<class X> struct NodeTextColorsTraits : public T {
   543     const X &_nodeTextColors;
   544     NodeTextColorsTraits(const T &t,const X &x) : T(t), _nodeTextColors(x) {}
   545   };
   546   ///Sets the map of the node text colors
   547 
   548   ///Sets the map of the node text colors
   549   ///\param x must be a node map with \ref Color values. 
   550   ///
   551   ///\sa ColorSet
   552   template<class X> GraphToEps<NodeTextColorsTraits<X> >
   553   nodeTextColors(const X &x)
   554   {
   555     dontPrint=true;
   556     _nodeTextColorType=CUST_COL;
   557     return GraphToEps<NodeTextColorsTraits<X> >
   558       (NodeTextColorsTraits<X>(*this,x));
   559   }
   560   template<class X> struct EdgeColorsTraits : public T {
   561     const X &_edgeColors;
   562     EdgeColorsTraits(const T &t,const X &x) : T(t), _edgeColors(x) {}
   563   };
   564   ///Sets the map of the edge colors
   565 
   566   ///Sets the map of the edge colors
   567   ///\param x must be a edge map with \ref Color values. 
   568   ///
   569   ///\sa ColorSet
   570   template<class X> GraphToEps<EdgeColorsTraits<X> >
   571   edgeColors(const X &x)
   572   {
   573     dontPrint=true;
   574     return GraphToEps<EdgeColorsTraits<X> >(EdgeColorsTraits<X>(*this,x));
   575   }
   576   ///Sets a global scale factor for node sizes
   577 
   578   ///Sets a global scale factor for node sizes.
   579   /// 
   580   /// If nodeSizes() is not given, this function simply sets the node
   581   /// sizes to \c d.  If nodeSizes() is given, but
   582   /// autoNodeScale() is not, then the node size given by
   583   /// nodeSizes() will be multiplied by the value \c d.
   584   /// If both nodeSizes() and autoNodeScale() are used, then the
   585   /// node sizes will be scaled in such a way that the greatest size will be
   586   /// equal to \c d.
   587   GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
   588   ///Turns on/off the automatic node width scaling.
   589 
   590   ///Turns on/off the automatic node width scaling.
   591   ///
   592   ///\sa nodeScale()
   593   ///
   594   GraphToEps<T> &autoNodeScale(bool b=true) {
   595     _autoNodeScale=b;return *this;
   596   }
   597 
   598   ///Negates the Y coordinates.
   599 
   600   ///Negates the Y coordinates.
   601   ///
   602   ///\todo More docs.
   603   ///
   604   GraphToEps<T> &negateY(bool b=true) {
   605     _negY=b;return *this;
   606   }
   607 
   608   ///Sets a global scale factor for edge widths
   609 
   610   /// Sets a global scale factor for edge widths.
   611   ///
   612   /// If edgeWidths() is not given, this function simply sets the edge
   613   /// widths to \c d.  If edgeWidths() is given, but
   614   /// autoEdgeWidthScale() is not, then the edge withs given by
   615   /// edgeWidths() will be multiplied by the value \c d.
   616   /// If both edgeWidths() and autoEdgeWidthScale() are used, then the
   617   /// edge withs will be scaled in such a way that the greatest width will be
   618   /// equal to \c d.
   619   GraphToEps<T> &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;}
   620   ///Turns on/off the automatic edge width scaling.
   621 
   622   ///Turns on/off the automatic edge width scaling.
   623   ///
   624   ///\sa edgeWidthScale()
   625   ///
   626   GraphToEps<T> &autoEdgeWidthScale(bool b=true) {
   627     _autoEdgeWidthScale=b;return *this;
   628   }
   629   ///Sets a global scale factor for the whole picture
   630 
   631   ///Sets a global scale factor for the whole picture
   632   ///
   633 
   634   GraphToEps<T> &scale(double d) {_scale=d;return *this;}
   635   ///Sets the width of the border around the picture
   636 
   637   ///Sets the width of the border around the picture
   638   ///
   639   GraphToEps<T> &border(double b) {_xBorder=_yBorder=b;return *this;}
   640   ///Sets the width of the border around the picture
   641 
   642   ///Sets the width of the border around the picture
   643   ///
   644   GraphToEps<T> &border(double x, double y) {
   645     _xBorder=x;_yBorder=y;return *this;
   646   }
   647   ///Sets whether to draw arrows
   648 
   649   ///Sets whether to draw arrows
   650   ///
   651   GraphToEps<T> &drawArrows(bool b=true) {_drawArrows=b;return *this;}
   652   ///Sets the length of the arrowheads
   653 
   654   ///Sets the length of the arrowheads
   655   ///
   656   GraphToEps<T> &arrowLength(double d) {_arrowLength*=d;return *this;}
   657   ///Sets the width of the arrowheads
   658 
   659   ///Sets the width of the arrowheads
   660   ///
   661   GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;}
   662   
   663   ///Scales the drawing to fit to A4 page
   664 
   665   ///Scales the drawing to fit to A4 page
   666   ///
   667   GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
   668   
   669   ///Enables parallel edges
   670 
   671   ///Enables parallel edges
   672   GraphToEps<T> &enableParallel(bool b=true) {_enableParallel=b;return *this;}
   673   
   674   ///Sets the distance 
   675   
   676   ///Sets the distance 
   677   ///
   678   GraphToEps<T> &parEdgeDist(double d) {_parEdgeDist*=d;return *this;}
   679   
   680   ///Hides the edges
   681   
   682   ///Hides the edges
   683   ///
   684   GraphToEps<T> &hideEdges(bool b=true) {_showEdges=!b;return *this;}
   685   ///Hides the nodes
   686   
   687   ///Hides the nodes
   688   ///
   689   GraphToEps<T> &hideNodes(bool b=true) {_showNodes=!b;return *this;}
   690   
   691   ///Sets the size of the node texts
   692   
   693   ///Sets the size of the node texts
   694   ///
   695   GraphToEps<T> &nodeTextSize(double d) {_nodeTextSize=d;return *this;}
   696 
   697   ///Sets the color of the node texts to be different from the node color
   698 
   699   ///Sets the color of the node texts to be as different from the node color
   700   ///as it is possible
   701   ///
   702   GraphToEps<T> &distantColorNodeTexts()
   703   {_nodeTextColorType=DIST_COL;return *this;}
   704   ///Sets the color of the node texts to be black or white and always visible.
   705 
   706   ///Sets the color of the node texts to be black or white according to
   707   ///which is more 
   708   ///different from the node color
   709   ///
   710   GraphToEps<T> &distantBWNodeTexts()
   711   {_nodeTextColorType=DIST_BW;return *this;}
   712 
   713   ///Gives a preamble block for node Postscript block.
   714   
   715   ///Gives a preamble block for node Postscript block.
   716   ///
   717   ///\sa nodePsTexts()
   718   GraphToEps<T> & nodePsTextsPreamble(const char *str) {
   719     _nodePsTextsPreamble=str ;return *this;
   720   }
   721   ///Sets whether the the graph is undirected
   722 
   723   ///Sets whether the the graph is undirected
   724   ///
   725   GraphToEps<T> &undir(bool b=true) {_undir=b;return *this;}
   726   ///Sets whether the the graph is directed
   727 
   728   ///Sets whether the the graph is directed.
   729   ///Use it to show the undirected edges as a pair of directed ones.
   730   GraphToEps<T> &bidir(bool b=true) {_undir=!b;return *this;}
   731 
   732   ///Sets the title.
   733 
   734   ///Sets the title of the generated image,
   735   ///namely it inserts a <tt>%%Title:</tt> DSC field to the header of
   736   ///the EPS file.
   737   GraphToEps<T> &title(const std::string &t) {_title=t;return *this;}
   738   ///Sets the copyright statement.
   739 
   740   ///Sets the copyright statement of the generated image,
   741   ///namely it inserts a <tt>%%Copyright:</tt> DSC field to the header of
   742   ///the EPS file.
   743   ///\todo Multiline copyright notice could be supported.
   744   GraphToEps<T> &copyright(const std::string &t) {_copyright=t;return *this;}
   745 
   746 protected:
   747   bool isInsideNode(xy<double> p, double r,int t) 
   748   {
   749     switch(t) {
   750     case CIRCLE:
   751       return p.normSquare()<=r*r;
   752     case SQUARE:
   753       return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r;
   754     case DIAMOND:
   755       return p.x+p.y<=r && p.x-p.y<=r && -p.x+p.y<=r && -p.x-p.y<=r;
   756     }
   757     return false;
   758   }
   759 
   760 public:
   761   ~GraphToEps() { }
   762   
   763   ///Draws the graph.
   764 
   765   ///Like other functions using
   766   ///\ref named-templ-func-param "named template parameters",
   767   ///this function calles the algorithm itself, i.e. in this case
   768   ///it draws the graph.
   769   void run() {
   770     if(dontPrint) return;
   771     
   772     _NegY<typename T::CoordsMapType> mycoords(_coords,_negY);
   773 
   774     os << "%!PS-Adobe-2.0 EPSF-2.0\n";
   775     if(_title.size()>0) os << "%%Title: " << _title << '\n';
   776      if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n';
   777 //        << "%%Copyright: XXXX\n"
   778     os << "%%Creator: LEMON, graphToEps()\n";
   779     
   780     {
   781       char cbuf[50];
   782       timeval tv;
   783       gettimeofday(&tv, 0);
   784       ctime_r(&tv.tv_sec,cbuf);
   785       os << "%%CreationDate: " << cbuf;
   786     }
   787 
   788     if (_autoEdgeWidthScale) {
   789       double max_w=0;
   790       for(EdgeIt e(g);e!=INVALID;++e)
   791 	max_w=std::max(double(_edgeWidths[e]),max_w);
   792       ///\todo better 'epsilon' would be nice here.
   793       if(max_w>1e-9) {
   794 	_edgeWidthScale/=max_w;
   795       }
   796     }
   797 
   798     if (_autoNodeScale) {
   799       double max_s=0;
   800       for(NodeIt n(g);n!=INVALID;++n)
   801 	max_s=std::max(double(_nodeSizes[n]),max_s);
   802       ///\todo better 'epsilon' would be nice here.
   803       if(max_s>1e-9) {
   804 	_nodeScale/=max_s;
   805       }
   806     }
   807 
   808 
   809     BoundingBox<double> bb;
   810     ///\bug: Chech whether the graph is empty.
   811     for(NodeIt n(g);n!=INVALID;++n) {
   812       double ns=_nodeSizes[n]*_nodeScale;
   813       xy<double> p(ns,ns);
   814       bb.add(p+mycoords[n]);
   815       bb.add(-p+mycoords[n]);
   816     }
   817     if (bb.empty()) {
   818       bb = BoundingBox<double>(xy<double>(0,0));
   819     }
   820     
   821     if(_scaleToA4)
   822       os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
   823     else os << "%%BoundingBox: "
   824 	    << bb.left()   * _scale - _xBorder << ' '
   825 	    << bb.bottom() * _scale - _yBorder << ' '
   826 	    << bb.right()  * _scale + _xBorder << ' '
   827 	    << bb.top()    * _scale + _yBorder << '\n';
   828     
   829     os << "%%EndComments\n";
   830     
   831     //x1 y1 x2 y2 x3 y3 cr cg cb w
   832     os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
   833        << "      4 2 roll 1 index 1 index curveto stroke } bind def\n";
   834     os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n";
   835     //x y r
   836     os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def\n";
   837     //x y r
   838     os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n"
   839        << "      2 index 1 index sub 2 index 2 index add lineto\n"
   840        << "      2 index 1 index sub 2 index 2 index sub lineto\n"
   841        << "      2 index 1 index add 2 index 2 index sub lineto\n"
   842        << "      closepath pop pop pop} bind def\n";
   843     //x y r
   844     os << "/di { newpath 2 index 1 index add 2 index moveto\n"
   845        << "      2 index             2 index 2 index add lineto\n"
   846        << "      2 index 1 index sub 2 index             lineto\n"
   847        << "      2 index             2 index 2 index sub lineto\n"
   848        << "      closepath pop pop pop} bind def\n";
   849     // x y r cr cg cb
   850     os << "/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill\n"
   851        << "     setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n"
   852        << "   } bind def\n";
   853     os << "/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill\n"
   854        << "     setrgbcolor " << 1+_nodeBorderQuotient << " div sq fill\n"
   855        << "   } bind def\n";
   856     os << "/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill\n"
   857        << "     setrgbcolor " << 1+_nodeBorderQuotient << " div di fill\n"
   858        << "   } bind def\n";
   859     os << "/arrl " << _arrowLength << " def\n";
   860     os << "/arrw " << _arrowWidth << " def\n";
   861     // l dx_norm dy_norm
   862     os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
   863     //len w dx_norm dy_norm x1 y1 cr cg cb
   864     os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n"
   865        << "       /w exch def /len exch def\n"
   866       //	 << "       0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke"
   867        << "       newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto\n"
   868        << "       len w sub arrl sub dx dy lrl\n"
   869        << "       arrw dy dx neg lrl\n"
   870        << "       dx arrl w add mul dy w 2 div arrw add mul sub\n"
   871        << "       dy arrl w add mul dx w 2 div arrw add mul add rlineto\n"
   872        << "       dx arrl w add mul neg dy w 2 div arrw add mul sub\n"
   873        << "       dy arrl w add mul neg dx w 2 div arrw add mul add rlineto\n"
   874        << "       arrw dy dx neg lrl\n"
   875        << "       len w sub arrl sub neg dx dy lrl\n"
   876        << "       closepath fill } bind def\n";
   877     os << "/cshow { 2 index 2 index moveto dup stringwidth pop\n"
   878        << "         neg 2 div fosi .35 mul neg rmoveto show pop pop} def\n";
   879 
   880     os << "\ngsave\n";
   881     if(_scaleToA4)
   882       if(bb.height()>bb.width()) {
   883 	double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.height(),
   884 		  (A4WIDTH-2*A4BORDER)/bb.width());
   885 	os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' '
   886 	   << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER << " translate\n"
   887 	   << sc << " dup scale\n"
   888 	   << -bb.left() << ' ' << -bb.bottom() << " translate\n";
   889       }
   890       else {
   891 	//\todo Verify centering
   892 	double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.width(),
   893 		  (A4WIDTH-2*A4BORDER)/bb.height());
   894 	os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' '
   895 	   << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER  << " translate\n"
   896 	   << sc << " dup scale\n90 rotate\n"
   897 	   << -bb.left() << ' ' << -bb.top() << " translate\n";	
   898 	}
   899     else if(_scale!=1.0) os << _scale << " dup scale\n";
   900     
   901     if(_showEdges) {
   902       os << "%Edges:\ngsave\n";      
   903       if(_enableParallel) {
   904 	std::vector<Edge> el;
   905 	for(EdgeIt e(g);e!=INVALID;++e)
   906 	  if((!_undir||g.source(e)<g.target(e))&&_edgeWidths[e]>0)
   907 	    el.push_back(e);
   908 	std::sort(el.begin(),el.end(),edgeLess(g));
   909 	
   910 	typename std::vector<Edge>::iterator j;
   911 	for(typename std::vector<Edge>::iterator i=el.begin();i!=el.end();i=j) {
   912 	  for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ;
   913 
   914 	  double sw=0;
   915 	  for(typename std::vector<Edge>::iterator e=i;e!=j;++e)
   916 	    sw+=_edgeWidths[*e]*_edgeWidthScale+_parEdgeDist;
   917 	  sw-=_parEdgeDist;
   918 	  sw/=-2.0;
   919 	  xy<double> dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]);
   920 	  double l=std::sqrt(dvec.normSquare()); 
   921 	  ///\todo better 'epsilon' would be nice here.
   922 	  xy<double> d(dvec/std::max(l,1e-9));
   923  	  xy<double> m;
   924 // 	  m=xy<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
   925 
   926 //  	  m=xy<double>(mycoords[g.source(*i)])+
   927 // 	    dvec*(double(_nodeSizes[g.source(*i)])/
   928 // 	       (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
   929 
   930  	  m=xy<double>(mycoords[g.source(*i)])+
   931 	    d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
   932 
   933 	  for(typename std::vector<Edge>::iterator e=i;e!=j;++e) {
   934 	    sw+=_edgeWidths[*e]*_edgeWidthScale/2.0;
   935 	    xy<double> mm=m+rot90(d)*sw/.75;
   936 	    if(_drawArrows) {
   937 	      int node_shape;
   938 	      xy<double> s=mycoords[g.source(*e)];
   939 	      xy<double> t=mycoords[g.target(*e)];
   940 	      double rn=_nodeSizes[g.target(*e)]*_nodeScale;
   941 	      node_shape=_nodeShapes[g.target(*e)];
   942 	      Bezier3 bez(s,mm,mm,t);
   943 	      double t1=0,t2=1;
   944 	      for(int i=0;i<INTERPOL_PREC;++i)
   945 		if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t2=(t1+t2)/2;
   946 		else t1=(t1+t2)/2;
   947 	      xy<double> apoint=bez((t1+t2)/2);
   948 	      rn = _arrowLength+_edgeWidths[*e]*_edgeWidthScale;
   949 	      rn*=rn;
   950 	      t2=(t1+t2)/2;t1=0;
   951 	      for(int i=0;i<INTERPOL_PREC;++i)
   952 		if((bez((t1+t2)/2)-apoint).normSquare()>rn) t1=(t1+t2)/2;
   953 		else t2=(t1+t2)/2;
   954 	      xy<double> linend=bez((t1+t2)/2);	      
   955 	      bez=bez.before((t1+t2)/2);
   956 // 	      rn=_nodeSizes[g.source(*e)]*_nodeScale;
   957 // 	      node_shape=_nodeShapes[g.source(*e)];
   958 // 	      t1=0;t2=1;
   959 // 	      for(int i=0;i<INTERPOL_PREC;++i)
   960 // 		if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t1=(t1+t2)/2;
   961 // 		else t2=(t1+t2)/2;
   962 // 	      bez=bez.after((t1+t2)/2);
   963 	      os << _edgeWidths[*e]*_edgeWidthScale << " setlinewidth "
   964 		 << _edgeColors[*e].red() << ' '
   965 		 << _edgeColors[*e].green() << ' '
   966 		 << _edgeColors[*e].blue() << " setrgbcolor newpath\n"
   967 		 << bez.p1.x << ' ' <<  bez.p1.y << " moveto\n"
   968 		 << bez.p2.x << ' ' << bez.p2.y << ' '
   969 		 << bez.p3.x << ' ' << bez.p3.y << ' '
   970 		 << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
   971 	      xy<double> dd(rot90(linend-apoint));
   972 	      dd*=(.5*_edgeWidths[*e]*_edgeWidthScale+_arrowWidth)/
   973 		std::sqrt(dd.normSquare());
   974 	      os << "newpath " << psOut(apoint) << " moveto "
   975 		 << psOut(linend+dd) << " lineto "
   976 		 << psOut(linend-dd) << " lineto closepath fill\n";
   977 	    }
   978 	    else {
   979 	      os << mycoords[g.source(*e)].x << ' '
   980 		 << mycoords[g.source(*e)].y << ' '
   981 		 << mm.x << ' ' << mm.y << ' '
   982 		 << mycoords[g.target(*e)].x << ' '
   983 		 << mycoords[g.target(*e)].y << ' '
   984 		 << _edgeColors[*e].red() << ' '
   985 		 << _edgeColors[*e].green() << ' '
   986 		 << _edgeColors[*e].blue() << ' '
   987 		 << _edgeWidths[*e]*_edgeWidthScale << " lb\n";
   988 	    }
   989 	    sw+=_edgeWidths[*e]*_edgeWidthScale/2.0+_parEdgeDist;
   990 	  }
   991 	}
   992       }
   993       else for(EdgeIt e(g);e!=INVALID;++e)
   994 	if((!_undir||g.source(e)<g.target(e))&&_edgeWidths[e]>0)
   995 	  if(_drawArrows) {
   996 	    xy<double> d(mycoords[g.target(e)]-mycoords[g.source(e)]);
   997 	    double rn=_nodeSizes[g.target(e)]*_nodeScale;
   998 	    int node_shape=_nodeShapes[g.target(e)];
   999 	    double t1=0,t2=1;
  1000 	    for(int i=0;i<INTERPOL_PREC;++i)
  1001 	      if(isInsideNode((-(t1+t2)/2)*d,rn,node_shape)) t1=(t1+t2)/2;
  1002 	      else t2=(t1+t2)/2;
  1003 	    double l=sqrt(d.normSquare());
  1004 	    d/=l;
  1005 	    
  1006 	    os << l*(1-(t1+t2)/2) << ' '
  1007 	       << _edgeWidths[e]*_edgeWidthScale << ' '
  1008 	       << d.x << ' ' << d.y << ' '
  1009 	       << mycoords[g.source(e)].x << ' '
  1010 	       << mycoords[g.source(e)].y << ' '
  1011 	       << _edgeColors[e].red() << ' '
  1012 	       << _edgeColors[e].green() << ' '
  1013 	       << _edgeColors[e].blue() << " arr\n";
  1014 	  }
  1015 	  else os << mycoords[g.source(e)].x << ' '
  1016 		  << mycoords[g.source(e)].y << ' '
  1017 		  << mycoords[g.target(e)].x << ' '
  1018 		  << mycoords[g.target(e)].y << ' '
  1019 		  << _edgeColors[e].red() << ' '
  1020 		  << _edgeColors[e].green() << ' '
  1021 		  << _edgeColors[e].blue() << ' '
  1022 		  << _edgeWidths[e]*_edgeWidthScale << " l\n";
  1023       os << "grestore\n";
  1024     }
  1025     if(_showNodes) {
  1026       os << "%Nodes:\ngsave\n";
  1027       for(NodeIt n(g);n!=INVALID;++n) {
  1028 	os << mycoords[n].x << ' ' << mycoords[n].y << ' '
  1029 	   << _nodeSizes[n]*_nodeScale << ' '
  1030 	   << _nodeColors[n].red() << ' '
  1031 	   << _nodeColors[n].green() << ' '
  1032 	   << _nodeColors[n].blue() << ' ';
  1033 	switch(_nodeShapes[n]) {
  1034 	case CIRCLE:
  1035 	  os<< "nc";break;
  1036 	case SQUARE:
  1037 	  os<< "nsq";break;
  1038 	case DIAMOND:
  1039 	  os<< "ndi";break;
  1040 	}
  1041 	os<<'\n';
  1042       }
  1043       os << "grestore\n";
  1044     }
  1045     if(_showNodeText) {
  1046       os << "%Node texts:\ngsave\n";
  1047       os << "/fosi " << _nodeTextSize << " def\n";
  1048       os << "(Helvetica) findfont fosi scalefont setfont\n";
  1049       for(NodeIt n(g);n!=INVALID;++n) {
  1050 	switch(_nodeTextColorType) {
  1051 	case DIST_COL:
  1052 	  os << psOut(distantColor(_nodeColors[n])) << " setrgbcolor\n";
  1053 	  break;
  1054 	case DIST_BW:
  1055 	  os << psOut(distantBW(_nodeColors[n])) << " setrgbcolor\n";
  1056 	  break;
  1057 	case CUST_COL:
  1058 	  os << psOut(distantColor(_nodeTextColors[n])) << " setrgbcolor\n";
  1059 	  break;
  1060 	default:
  1061 	  os << "0 0 0 setrgbcolor\n";
  1062 	}
  1063 	os << mycoords[n].x << ' ' << mycoords[n].y
  1064 	   << " (" << _nodeTexts[n] << ") cshow\n";
  1065       }
  1066       os << "grestore\n";
  1067     }
  1068     if(_showNodePsText) {
  1069       os << "%Node PS blocks:\ngsave\n";
  1070       for(NodeIt n(g);n!=INVALID;++n)
  1071 	os << mycoords[n].x << ' ' << mycoords[n].y
  1072 	   << " moveto\n" << _nodePsTexts[n] << "\n";
  1073       os << "grestore\n";
  1074     }
  1075     
  1076     os << "grestore\nshowpage\n";
  1077 
  1078     //CleanUp:
  1079     if(_pleaseRemoveOsStream) {delete &os;}
  1080   } 
  1081 };
  1082 
  1083 template<class T>
  1084 const int GraphToEps<T>::INTERPOL_PREC = 20;
  1085 template<class T>
  1086 const double GraphToEps<T>::A4HEIGHT = 841.8897637795276;
  1087 template<class T>
  1088 const double GraphToEps<T>::A4WIDTH  = 595.275590551181;
  1089 template<class T>
  1090 const double GraphToEps<T>::A4BORDER = 15;
  1091 
  1092 
  1093 ///Generates an EPS file from a graph
  1094 
  1095 ///\ingroup io_group
  1096 ///Generates an EPS file from a graph.
  1097 ///\param g is a reference to the graph to be printed
  1098 ///\param os is a reference to the output stream.
  1099 ///By default it is <tt>std::cout</tt>
  1100 ///
  1101 ///This function also has a lot of
  1102 ///\ref named-templ-func-param "named parameters",
  1103 ///they are declared as the members of class \ref GraphToEps. The following
  1104 ///example shows how to use these parameters.
  1105 ///\code
  1106 /// graphToEps(g,os).scale(10).coords(coords)
  1107 ///              .nodeScale(2).nodeSizes(sizes)
  1108 ///              .edgeWidthScale(.4).run();
  1109 ///\endcode
  1110 ///\warning Don't forget to put the \ref GraphToEps::run() "run()"
  1111 ///to the end of the parameter list.
  1112 ///\sa GraphToEps
  1113 ///\sa graphToEps(G &g, const char *file_name)
  1114 template<class G>
  1115 GraphToEps<DefaultGraphToEpsTraits<G> > 
  1116 graphToEps(G &g, std::ostream& os=std::cout)
  1117 {
  1118   return 
  1119     GraphToEps<DefaultGraphToEpsTraits<G> >(DefaultGraphToEpsTraits<G>(g,os));
  1120 }
  1121  
  1122 ///Generates an EPS file from a graph
  1123 
  1124 ///\ingroup io_group
  1125 ///This function does the same as
  1126 ///\ref graphToEps(G &g,std::ostream& os)
  1127 ///but it writes its output into the file \c file_name
  1128 ///instead of a stream.
  1129 ///\sa graphToEps(G &g, std::ostream& os)
  1130 template<class G>
  1131 GraphToEps<DefaultGraphToEpsTraits<G> > 
  1132 graphToEps(G &g,const char *file_name)
  1133 {
  1134   return GraphToEps<DefaultGraphToEpsTraits<G> >
  1135     (DefaultGraphToEpsTraits<G>(g,*new std::ofstream(file_name),true));
  1136 }
  1137 
  1138 } //END OF NAMESPACE LEMON
  1139 
  1140 #endif // LEMON_GRAPH_TO_EPS_H