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