src/lemon/graph_to_eps.h
author deba
Mon, 07 Feb 2005 11:28:37 +0000
changeset 1136 8d066154b66a
parent 1107 d972653c89d5
child 1164 80bb73097736
permissions -rw-r--r--
Graph documentation
alpar@1073
     1
/* -*- C++ -*-
alpar@1073
     2
 * src/lemon/graph_to_eps.h - Part of LEMON, a generic C++ optimization library
alpar@1073
     3
 *
alpar@1073
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1073
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@1073
     6
 *
alpar@1073
     7
 * Permission to use, modify and distribute this software is granted
alpar@1073
     8
 * provided that this copyright notice appears in all copies. For
alpar@1073
     9
 * precise terms see the accompanying LICENSE file.
alpar@1073
    10
 *
alpar@1073
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1073
    12
 * express or implied, and with no claim as to its suitability for any
alpar@1073
    13
 * purpose.
alpar@1073
    14
 *
alpar@1073
    15
 */
alpar@1073
    16
alpar@1073
    17
#ifndef LEMON_GRAPH_TO_EPS_H
alpar@1073
    18
#define LEMON_GRAPH_TO_EPS_H
alpar@1073
    19
alpar@1108
    20
#include <sys/time.h>
alpar@1108
    21
#include <time.h>
alpar@1108
    22
alpar@1073
    23
#include<iostream>
alpar@1073
    24
#include<fstream>
alpar@1073
    25
#include<sstream>
alpar@1073
    26
#include<algorithm>
alpar@1073
    27
#include<vector>
alpar@1073
    28
alpar@1073
    29
#include<lemon/xy.h>
alpar@1073
    30
#include<lemon/maps.h>
alpar@1073
    31
#include<lemon/bezier.h>
alpar@1073
    32
alpar@1073
    33
///\ingroup misc
alpar@1073
    34
///\file
alpar@1073
    35
///\brief Simple graph drawer
alpar@1073
    36
///
alpar@1073
    37
///\author Alpar Juttner
alpar@1073
    38
alpar@1073
    39
namespace lemon {
alpar@1073
    40
alpar@1073
    41
///Data structure representing RGB colors.
alpar@1073
    42
alpar@1073
    43
///Data structure representing RGB colors.
alpar@1073
    44
///\ingroup misc
alpar@1073
    45
class Color
alpar@1073
    46
{
alpar@1073
    47
  double _r,_g,_b;
alpar@1073
    48
public:
alpar@1073
    49
  ///Default constructor
alpar@1073
    50
  Color() {}
alpar@1073
    51
  ///Constructor
alpar@1073
    52
  Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
alpar@1073
    53
  ///Returns the red component
alpar@1073
    54
  double getR() {return _r;}
alpar@1073
    55
  ///Returns the green component
alpar@1073
    56
  double getG() {return _g;}
alpar@1073
    57
  ///Returns the blue component
alpar@1073
    58
  double getB() {return _b;}
alpar@1073
    59
  ///Set the color components
alpar@1073
    60
  void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
alpar@1073
    61
};
alpar@1073
    62
  
alpar@1073
    63
///Default traits class of \ref GraphToEps
alpar@1073
    64
alpar@1073
    65
///Default traits class of \ref GraphToEps
alpar@1073
    66
///
alpar@1073
    67
///\c G is the type of the underlying graph.
alpar@1073
    68
template<class G>
alpar@1073
    69
struct DefaultGraphToEpsTraits
alpar@1073
    70
{
alpar@1073
    71
  typedef G Graph;
alpar@1073
    72
  typedef typename Graph::Node Node;
alpar@1073
    73
  typedef typename Graph::NodeIt NodeIt;
alpar@1073
    74
  typedef typename Graph::Edge Edge;
alpar@1073
    75
  typedef typename Graph::EdgeIt EdgeIt;
alpar@1073
    76
  typedef typename Graph::InEdgeIt InEdgeIt;
alpar@1073
    77
  typedef typename Graph::OutEdgeIt OutEdgeIt;
alpar@1073
    78
  
alpar@1073
    79
alpar@1073
    80
  const Graph &g;
alpar@1073
    81
alpar@1073
    82
  std::ostream& os;
alpar@1073
    83
  
alpar@1073
    84
  ConstMap<typename Graph::Node,xy<double> > _coords;
alpar@1073
    85
  ConstMap<typename Graph::Node,double > _nodeSizes;
alpar@1086
    86
  ConstMap<typename Graph::Node,int > _nodeShapes;
alpar@1073
    87
alpar@1073
    88
  ConstMap<typename Graph::Node,Color > _nodeColors;
alpar@1073
    89
  ConstMap<typename Graph::Edge,Color > _edgeColors;
alpar@1073
    90
alpar@1073
    91
  ConstMap<typename Graph::Edge,double > _edgeWidths;
alpar@1103
    92
alpar@1103
    93
  static const double A4HEIGHT = 841.8897637795276;
alpar@1103
    94
  static const double A4WIDTH  = 595.275590551181;
alpar@1103
    95
  static const double A4BORDER = 15;
alpar@1103
    96
alpar@1073
    97
  
alpar@1073
    98
  double _edgeWidthScale;
alpar@1073
    99
  
alpar@1073
   100
  double _nodeScale;
alpar@1073
   101
  double _xBorder, _yBorder;
alpar@1073
   102
  double _scale;
alpar@1073
   103
  double _nodeBorderQuotient;
alpar@1073
   104
  
alpar@1073
   105
  bool _drawArrows;
alpar@1073
   106
  double _arrowLength, _arrowWidth;
alpar@1073
   107
  
alpar@1073
   108
  bool _showNodes, _showEdges;
alpar@1073
   109
alpar@1073
   110
  bool _enableParallel;
alpar@1073
   111
  double _parEdgeDist;
alpar@1073
   112
alpar@1073
   113
  bool _showNodeText;
alpar@1073
   114
  ConstMap<typename Graph::Node,bool > _nodeTexts;  
alpar@1073
   115
  double _nodeTextSize;
alpar@1073
   116
alpar@1085
   117
  bool _showNodePsText;
alpar@1085
   118
  ConstMap<typename Graph::Node,bool > _nodePsTexts;  
alpar@1085
   119
  char *_nodePsTextsPreamble;
alpar@1085
   120
  
alpar@1073
   121
  bool _undir;
alpar@1073
   122
  bool _pleaseRemoveOsStream;
alpar@1103
   123
alpar@1103
   124
  bool _scaleToA4;
alpar@1108
   125
alpar@1108
   126
  std::string _title;
alpar@1108
   127
  std::string _copyright;
alpar@1103
   128
  
alpar@1073
   129
  ///Constructor
alpar@1073
   130
alpar@1073
   131
  ///Constructor
alpar@1073
   132
  ///\param _g is a reference to the graph to be printed
alpar@1073
   133
  ///\param _os is a reference to the output stream.
alpar@1073
   134
  ///\param _os is a reference to the output stream.
alpar@1073
   135
  ///\param _pros If it is \c true, then the \c ostream referenced by \c _os
alpar@1073
   136
  ///will be explicitly deallocated by the destructor.
alpar@1073
   137
  ///By default it is <tt>std::cout</tt>
alpar@1073
   138
  DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
alpar@1073
   139
			  bool _pros=false) :
alpar@1073
   140
    g(_g), os(_os),
alpar@1086
   141
    _coords(xy<double>(1,1)), _nodeSizes(1.0), _nodeShapes(0),
alpar@1073
   142
    _nodeColors(Color(1,1,1)), _edgeColors(Color(0,0,0)),
alpar@1073
   143
    _edgeWidths(1), _edgeWidthScale(0.3),
alpar@1073
   144
    _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
alpar@1073
   145
    _nodeBorderQuotient(.1),
alpar@1073
   146
    _drawArrows(false), _arrowLength(1), _arrowWidth(0.3),
alpar@1073
   147
    _showNodes(true), _showEdges(true),
alpar@1073
   148
    _enableParallel(false), _parEdgeDist(1),
alpar@1073
   149
    _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
alpar@1085
   150
    _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
alpar@1073
   151
    _undir(false),
alpar@1103
   152
    _pleaseRemoveOsStream(_pros), _scaleToA4(false) {}
alpar@1073
   153
};
alpar@1073
   154
alpar@1073
   155
///Helper class to implement the named parameters of \ref graphToEps()
alpar@1073
   156
alpar@1073
   157
///Helper class to implement the named parameters of \ref graphToEps()
alpar@1073
   158
///\todo Is 'helper class' a good name for this?
alpar@1073
   159
///
alpar@1103
   160
///\todo Follow PostScript's DSC.
alpar@1107
   161
/// Use own dictionary.
alpar@1107
   162
///\todo Useful new features.
alpar@1107
   163
/// - Linestyles: dotted, dashed etc.
alpar@1107
   164
/// - A second color and percent value for the lines.
alpar@1073
   165
template<class T> class GraphToEps : public T 
alpar@1073
   166
{
alpar@1073
   167
  typedef typename T::Graph Graph;
alpar@1073
   168
  typedef typename Graph::Node Node;
alpar@1073
   169
  typedef typename Graph::NodeIt NodeIt;
alpar@1073
   170
  typedef typename Graph::Edge Edge;
alpar@1073
   171
  typedef typename Graph::EdgeIt EdgeIt;
alpar@1073
   172
  typedef typename Graph::InEdgeIt InEdgeIt;
alpar@1073
   173
  typedef typename Graph::OutEdgeIt OutEdgeIt;
alpar@1073
   174
alpar@1087
   175
  static const int INTERPOL_PREC=20;
alpar@1087
   176
alpar@1073
   177
  bool dontPrint;
alpar@1073
   178
alpar@1107
   179
public:
alpar@1107
   180
  ///Node shapes
alpar@1107
   181
alpar@1107
   182
  ///Node shapes
alpar@1107
   183
  ///
alpar@1107
   184
  enum NodeShapes { 
alpar@1107
   185
    /// = 0
alpar@1107
   186
    ///\image html nodeshape_0.png
alpar@1107
   187
    ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm
alpar@1107
   188
    CIRCLE=0, 
alpar@1107
   189
    /// = 1
alpar@1107
   190
    ///\image html nodeshape_1.png
alpar@1107
   191
    ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm
alpar@1107
   192
    ///
alpar@1107
   193
    SQUARE=1, 
alpar@1107
   194
    /// = 2
alpar@1107
   195
    ///\image html nodeshape_2.png
alpar@1107
   196
    ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm
alpar@1107
   197
    ///
alpar@1107
   198
    DIAMOND=2
alpar@1107
   199
  };
alpar@1107
   200
alpar@1107
   201
private:
alpar@1073
   202
  class edgeLess {
alpar@1073
   203
    const Graph &g;
alpar@1073
   204
  public:
alpar@1073
   205
    edgeLess(const Graph &_g) : g(_g) {}
alpar@1073
   206
    bool operator()(Edge a,Edge b) const 
alpar@1073
   207
    {
alpar@1073
   208
      Node ai=min(g.source(a),g.target(a));
alpar@1073
   209
      Node aa=max(g.source(a),g.target(a));
alpar@1073
   210
      Node bi=min(g.source(b),g.target(b));
alpar@1073
   211
      Node ba=max(g.source(b),g.target(b));
alpar@1073
   212
      return ai<bi ||
alpar@1073
   213
	(ai==bi && (aa < ba || 
alpar@1073
   214
		    (aa==ba && ai==g.source(a) && bi==g.target(b))));
alpar@1073
   215
    }
alpar@1073
   216
  };
alpar@1073
   217
  bool isParallel(Edge e,Edge f) const
alpar@1073
   218
  {
alpar@1073
   219
    return (g.source(e)==g.source(f)&&g.target(e)==g.target(f))||
alpar@1073
   220
      (g.source(e)==g.target(f)&&g.target(e)==g.source(f));
alpar@1073
   221
  }
alpar@1073
   222
  static xy<double> rot(xy<double> v) 
alpar@1073
   223
  {
alpar@1073
   224
    return xy<double>(v.y,-v.x);
alpar@1073
   225
  }
alpar@1073
   226
  template<class xy>
alpar@1073
   227
  static std::string psOut(const xy &p) 
alpar@1073
   228
    {
alpar@1073
   229
      std::ostringstream os;	
alpar@1073
   230
      os << p.x << ' ' << p.y;
alpar@1073
   231
      return os.str();
alpar@1073
   232
    }
alpar@1073
   233
  
alpar@1073
   234
public:
alpar@1073
   235
  GraphToEps(const T &t) : T(t), dontPrint(false) {};
alpar@1073
   236
  
alpar@1073
   237
  template<class X> struct CoordsTraits : public T {
alpar@1073
   238
    const X &_coords;
alpar@1073
   239
    CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {}
alpar@1073
   240
  };
alpar@1073
   241
  ///Sets the map of the node coordinates
alpar@1073
   242
alpar@1073
   243
  ///Sets the map of the node coordinates.
alpar@1103
   244
  ///\param x must be a node map with xy<double> or \ref xy "xy<int>" values. 
alpar@1073
   245
  template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
alpar@1073
   246
    dontPrint=true;
alpar@1073
   247
    return GraphToEps<CoordsTraits<X> >(CoordsTraits<X>(*this,x));
alpar@1073
   248
  }
alpar@1073
   249
  template<class X> struct NodeSizesTraits : public T {
alpar@1073
   250
    const X &_nodeSizes;
alpar@1073
   251
    NodeSizesTraits(const T &t,const X &x) : T(t), _nodeSizes(x) {}
alpar@1073
   252
  };
alpar@1073
   253
  ///Sets the map of the node sizes
alpar@1073
   254
alpar@1073
   255
  ///Sets the map of the node sizes
alpar@1073
   256
  ///\param x must be a node map with \c double (or convertible) values. 
alpar@1073
   257
  template<class X> GraphToEps<NodeSizesTraits<X> > nodeSizes(const X &x)
alpar@1073
   258
  {
alpar@1073
   259
    dontPrint=true;
alpar@1073
   260
    return GraphToEps<NodeSizesTraits<X> >(NodeSizesTraits<X>(*this,x));
alpar@1073
   261
  }
alpar@1086
   262
  template<class X> struct NodeShapesTraits : public T {
alpar@1086
   263
    const X &_nodeShapes;
alpar@1086
   264
    NodeShapesTraits(const T &t,const X &x) : T(t), _nodeShapes(x) {}
alpar@1086
   265
  };
alpar@1086
   266
  ///Sets the map of the node shapes
alpar@1086
   267
alpar@1107
   268
  ///Sets the map of the node shapes.
alpar@1107
   269
  ///The availabe shape values
alpar@1107
   270
  ///can be found in \ref NodeShapes "enum NodeShapes".
alpar@1086
   271
  ///\param x must be a node map with \c int (or convertible) values. 
alpar@1107
   272
  ///\sa NodeShapes
alpar@1086
   273
  template<class X> GraphToEps<NodeShapesTraits<X> > nodeShapes(const X &x)
alpar@1086
   274
  {
alpar@1086
   275
    dontPrint=true;
alpar@1086
   276
    return GraphToEps<NodeShapesTraits<X> >(NodeShapesTraits<X>(*this,x));
alpar@1086
   277
  }
alpar@1073
   278
  template<class X> struct NodeTextsTraits : public T {
alpar@1073
   279
    const X &_nodeTexts;
alpar@1073
   280
    NodeTextsTraits(const T &t,const X &x) : T(t), _nodeTexts(x) {}
alpar@1073
   281
  };
alpar@1073
   282
  ///Sets the text printed on the nodes
alpar@1073
   283
alpar@1073
   284
  ///Sets the text printed on the nodes
alpar@1073
   285
  ///\param x must be a node map with type that can be pushed to a standard
alpar@1073
   286
  ///ostream. 
alpar@1073
   287
  template<class X> GraphToEps<NodeTextsTraits<X> > nodeTexts(const X &x)
alpar@1073
   288
  {
alpar@1073
   289
    dontPrint=true;
alpar@1073
   290
    _showNodeText=true;
alpar@1073
   291
    return GraphToEps<NodeTextsTraits<X> >(NodeTextsTraits<X>(*this,x));
alpar@1073
   292
  }
alpar@1085
   293
  template<class X> struct NodePsTextsTraits : public T {
alpar@1085
   294
    const X &_nodePsTexts;
alpar@1085
   295
    NodePsTextsTraits(const T &t,const X &x) : T(t), _nodePsTexts(x) {}
alpar@1085
   296
  };
alpar@1085
   297
  ///Inserts a PostScript block to the nodes
alpar@1085
   298
alpar@1085
   299
  ///With this command it is possible to insert a verbatim PostScript
alpar@1085
   300
  ///block to the nodes.
alpar@1085
   301
  ///The PS current point will be moved to the centre of the node before
alpar@1085
   302
  ///the PostScript block inserted.
alpar@1085
   303
  ///
alpar@1085
   304
  ///Before and after the block a newline character is inserted to you
alpar@1085
   305
  ///don't have to bother with the separators.
alpar@1085
   306
  ///
alpar@1085
   307
  ///\param x must be a node map with type that can be pushed to a standard
alpar@1085
   308
  ///ostream.
alpar@1085
   309
  ///
alpar@1085
   310
  ///\sa nodePsTextsPreamble()
alpar@1085
   311
  ///\todo Offer the choise not to move to the centre but pass the coordinates
alpar@1085
   312
  ///to the Postscript block inserted.
alpar@1085
   313
  template<class X> GraphToEps<NodePsTextsTraits<X> > nodePsTexts(const X &x)
alpar@1085
   314
  {
alpar@1085
   315
    dontPrint=true;
alpar@1085
   316
    _showNodePsText=true;
alpar@1085
   317
    return GraphToEps<NodePsTextsTraits<X> >(NodePsTextsTraits<X>(*this,x));
alpar@1085
   318
  }
alpar@1085
   319
  template<class X> struct EdgeWidthsTraits : public T {
alpar@1073
   320
    const X &_edgeWidths;
alpar@1073
   321
    EdgeWidthsTraits(const T &t,const X &x) : T(t), _edgeWidths(x) {}
alpar@1073
   322
  };
alpar@1073
   323
  ///Sets the map of the edge widths
alpar@1073
   324
alpar@1073
   325
  ///Sets the map of the edge widths
alpar@1073
   326
  ///\param x must be a edge map with \c double (or convertible) values. 
alpar@1073
   327
  template<class X> GraphToEps<EdgeWidthsTraits<X> > edgeWidths(const X &x)
alpar@1073
   328
  {
alpar@1073
   329
    dontPrint=true;
alpar@1073
   330
    return GraphToEps<EdgeWidthsTraits<X> >(EdgeWidthsTraits<X>(*this,x));
alpar@1073
   331
  }
alpar@1073
   332
alpar@1073
   333
  template<class X> struct NodeColorsTraits : public T {
alpar@1073
   334
    const X &_nodeColors;
alpar@1073
   335
    NodeColorsTraits(const T &t,const X &x) : T(t), _nodeColors(x) {}
alpar@1073
   336
  };
alpar@1073
   337
  ///Sets the map of the node colors
alpar@1073
   338
alpar@1073
   339
  ///Sets the map of the node colors
alpar@1073
   340
  ///\param x must be a node map with \ref Color values. 
alpar@1073
   341
  template<class X> GraphToEps<NodeColorsTraits<X> >
alpar@1073
   342
  nodeColors(const X &x)
alpar@1073
   343
  {
alpar@1073
   344
    dontPrint=true;
alpar@1073
   345
    return GraphToEps<NodeColorsTraits<X> >(NodeColorsTraits<X>(*this,x));
alpar@1073
   346
  }
alpar@1073
   347
  template<class X> struct EdgeColorsTraits : public T {
alpar@1073
   348
    const X &_edgeColors;
alpar@1073
   349
    EdgeColorsTraits(const T &t,const X &x) : T(t), _edgeColors(x) {}
alpar@1073
   350
  };
alpar@1073
   351
  ///Sets the map of the edge colors
alpar@1073
   352
alpar@1073
   353
  ///Sets the map of the edge colors
alpar@1073
   354
  ///\param x must be a edge map with \ref Color values. 
alpar@1073
   355
  template<class X> GraphToEps<EdgeColorsTraits<X> >
alpar@1073
   356
  edgeColors(const X &x)
alpar@1073
   357
  {
alpar@1073
   358
    dontPrint=true;
alpar@1073
   359
    return GraphToEps<EdgeColorsTraits<X> >(EdgeColorsTraits<X>(*this,x));
alpar@1073
   360
  }
alpar@1073
   361
  ///Sets a global scale factor for node sizes
alpar@1073
   362
alpar@1073
   363
  ///Sets a global scale factor for node sizes
alpar@1073
   364
  ///
alpar@1073
   365
  GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
alpar@1073
   366
  ///Sets a global scale factor for edge widths
alpar@1073
   367
alpar@1073
   368
  ///Sets a global scale factor for edge widths
alpar@1073
   369
  ///
alpar@1073
   370
  GraphToEps<T> &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;}
alpar@1073
   371
  ///Sets a global scale factor for the whole picture
alpar@1073
   372
alpar@1073
   373
  ///Sets a global scale factor for the whole picture
alpar@1073
   374
  ///
alpar@1073
   375
  GraphToEps<T> &scale(double d) {_scale=d;return *this;}
alpar@1073
   376
  ///Sets the width of the border around the picture
alpar@1073
   377
alpar@1073
   378
  ///Sets the width of the border around the picture
alpar@1073
   379
  ///
alpar@1073
   380
  GraphToEps<T> &border(double b) {_xBorder=_yBorder=b;return *this;}
alpar@1073
   381
  ///Sets the width of the border around the picture
alpar@1073
   382
alpar@1073
   383
  ///Sets the width of the border around the picture
alpar@1073
   384
  ///
alpar@1073
   385
  GraphToEps<T> &border(double x, double y) {
alpar@1073
   386
    _xBorder=x;_yBorder=y;return *this;
alpar@1073
   387
  }
alpar@1073
   388
  ///Sets whether to draw arrows
alpar@1073
   389
alpar@1073
   390
  ///Sets whether to draw arrows
alpar@1073
   391
  ///
alpar@1073
   392
  GraphToEps<T> &drawArrows(bool b=true) {_drawArrows=b;return *this;}
alpar@1073
   393
  ///Sets the length of the arrowheads
alpar@1073
   394
alpar@1073
   395
  ///Sets the length of the arrowheads
alpar@1073
   396
  ///
alpar@1073
   397
  GraphToEps<T> &arrowLength(double d) {_arrowLength*=d;return *this;}
alpar@1073
   398
  ///Sets the width of the arrowheads
alpar@1073
   399
alpar@1073
   400
  ///Sets the width of the arrowheads
alpar@1073
   401
  ///
alpar@1073
   402
  GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;}
alpar@1073
   403
  
alpar@1103
   404
  ///Scales the drawing to fit to A4 page
alpar@1103
   405
alpar@1103
   406
  ///Scales the drawing to fit to A4 page
alpar@1103
   407
  ///
alpar@1103
   408
  GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
alpar@1103
   409
  
alpar@1073
   410
  ///Enables parallel edges
alpar@1073
   411
alpar@1073
   412
  ///Enables parallel edges
alpar@1073
   413
  ///\todo Partially implemented
alpar@1073
   414
  GraphToEps<T> &enableParallel(bool b=true) {_enableParallel=b;return *this;}
alpar@1073
   415
  
alpar@1073
   416
  ///Sets the distance 
alpar@1073
   417
  
alpar@1073
   418
  ///Sets the distance 
alpar@1073
   419
  ///
alpar@1073
   420
  GraphToEps<T> &parEdgeDist(double d) {_parEdgeDist*=d;return *this;}
alpar@1073
   421
  
alpar@1073
   422
  ///Hides the edges
alpar@1073
   423
  
alpar@1073
   424
  ///Hides the edges
alpar@1073
   425
  ///
alpar@1073
   426
  GraphToEps<T> &hideEdges(bool b=true) {_showEdges=!b;return *this;}
alpar@1073
   427
  ///Hides the nodes
alpar@1073
   428
  
alpar@1073
   429
  ///Hides the nodes
alpar@1073
   430
  ///
alpar@1073
   431
  GraphToEps<T> &hideNodes(bool b=true) {_showNodes=!b;return *this;}
alpar@1073
   432
  
alpar@1073
   433
  ///Sets the size of the node texts
alpar@1073
   434
  
alpar@1073
   435
  ///Sets the size of the node texts
alpar@1073
   436
  ///
alpar@1073
   437
  GraphToEps<T> &nodeTextSize(double d) {_nodeTextSize=d;return *this;}
alpar@1085
   438
  ///Gives a preamble block for node Postscript block.
alpar@1085
   439
  
alpar@1085
   440
  ///Gives a preamble block for node Postscript block.
alpar@1085
   441
  ///
alpar@1085
   442
  ///\sa nodePsTexts()
alpar@1085
   443
  GraphToEps<T> & nodePsTextsPreamble(const char *str) {
alpar@1085
   444
    _nodePsTextsPreamble=s ;return *this;
alpar@1085
   445
  }
alpar@1073
   446
  ///Sets whether the the graph is undirected
alpar@1073
   447
alpar@1073
   448
  ///Sets whether the the graph is undirected
alpar@1073
   449
  ///
alpar@1073
   450
  GraphToEps<T> &undir(bool b=true) {_undir=b;return *this;}
alpar@1073
   451
  ///Sets whether the the graph is directed
alpar@1073
   452
alpar@1073
   453
  ///Sets whether the the graph is directed.
alpar@1073
   454
  ///Use it to show the undirected edges as a pair of directed ones.
alpar@1073
   455
  GraphToEps<T> &bidir(bool b=true) {_undir=!b;return *this;}
alpar@1086
   456
alpar@1108
   457
  ///Sets the title.
alpar@1108
   458
alpar@1108
   459
  ///Sets the title of the generated image,
alpar@1108
   460
  ///namely it inserts a <tt>%%Title:</tt> DSC field to the header of
alpar@1108
   461
  ///the EPS file.
alpar@1108
   462
  GraphToEps<T> &title(const std::string &t) {_title=t;return *this;}
alpar@1108
   463
  ///Sets the copyright statement.
alpar@1108
   464
alpar@1108
   465
  ///Sets the copyright statement of the generated image,
alpar@1108
   466
  ///namely it inserts a <tt>%%Copyright:</tt> DSC field to the header of
alpar@1108
   467
  ///the EPS file.
alpar@1108
   468
  ///\todo Multiline copyright notice could be supported.
alpar@1108
   469
  GraphToEps<T> &copyright(const std::string &t) {_copyright=t;return *this;}
alpar@1108
   470
alpar@1086
   471
protected:
alpar@1086
   472
  bool isInsideNode(xy<double> p, double r,int t) 
alpar@1086
   473
  {
alpar@1086
   474
    switch(t) {
alpar@1086
   475
    case CIRCLE:
alpar@1086
   476
      return p.normSquare()<=r*r;
alpar@1086
   477
    case SQUARE:
alpar@1086
   478
      return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r;
alpar@1088
   479
    case DIAMOND:
alpar@1088
   480
      return p.x+p.y<=r && p.x-p.y<=r && -p.x+p.y<=r && -p.x-p.y<=r;
alpar@1086
   481
    }
alpar@1086
   482
    return false;
alpar@1086
   483
  }
alpar@1086
   484
alpar@1086
   485
public:
alpar@1091
   486
  ~GraphToEps() { }
alpar@1091
   487
  
alpar@1091
   488
  ///Draws the graph.
alpar@1091
   489
alpar@1091
   490
  ///Like other functions using
alpar@1091
   491
  ///\ref named-templ-func-param "named template parameters",
alpar@1091
   492
  ///this function calles the algorithm itself, i.e. in this case
alpar@1091
   493
  ///it draws the graph.
alpar@1091
   494
  void run() {
alpar@1073
   495
    if(dontPrint) return;
alpar@1073
   496
    
alpar@1073
   497
    os << "%!PS-Adobe-2.0 EPSF-2.0\n";
alpar@1108
   498
    if(_title.size()>0) os << "%%Title: " << _title << '\n';
alpar@1108
   499
     if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n';
alpar@1107
   500
//        << "%%Copyright: XXXX\n"
alpar@1108
   501
    os << "%%Creator: LEMON GraphToEps function\n";
alpar@1108
   502
    
alpar@1108
   503
    {
alpar@1108
   504
      char cbuf[50];
alpar@1108
   505
      timeval tv;
alpar@1108
   506
      gettimeofday(&tv, 0);
alpar@1108
   507
      ctime_r(&tv.tv_sec,cbuf);
alpar@1108
   508
      os << "%%CreationDate: " << cbuf;
alpar@1108
   509
    }
alpar@1107
   510
    ///\todo: Chech whether the graph is empty.
alpar@1073
   511
    BoundingBox<double> bb;
alpar@1073
   512
    for(NodeIt n(g);n!=INVALID;++n) {
alpar@1073
   513
      double ns=_nodeSizes[n]*_nodeScale;
alpar@1073
   514
      xy<double> p(ns,ns);
alpar@1073
   515
      bb+=p+_coords[n];
alpar@1073
   516
      bb+=-p+_coords[n];
alpar@1073
   517
      }
alpar@1108
   518
    if(_scaleToA4)
alpar@1108
   519
      os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
alpar@1108
   520
    else os << "%%BoundingBox: "
alpar@1108
   521
	    << bb.left()*  _scale-_xBorder << ' '
alpar@1108
   522
	    << bb.bottom()*_scale-_yBorder << ' '
alpar@1108
   523
	    << bb.right()* _scale+_xBorder << ' '
alpar@1108
   524
	    << bb.top()*   _scale+_yBorder << '\n';
alpar@1108
   525
    
alpar@1107
   526
    os << "%%EndComments\n";
alpar@1107
   527
    
alpar@1073
   528
    //x1 y1 x2 y2 x3 y3 cr cg cb w
alpar@1073
   529
    os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
alpar@1073
   530
       << "      4 2 roll 1 index 1 index curveto stroke } bind def\n";
alpar@1073
   531
    os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n";
alpar@1086
   532
    //x y r
alpar@1073
   533
    os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def\n";
alpar@1086
   534
    //x y r
alpar@1086
   535
    os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n"
alpar@1086
   536
       << "      2 index 1 index sub 2 index 2 index add lineto\n"
alpar@1086
   537
       << "      2 index 1 index sub 2 index 2 index sub lineto\n"
alpar@1086
   538
       << "      2 index 1 index add 2 index 2 index sub lineto\n"
alpar@1086
   539
       << "      closepath pop pop pop} bind def\n";
alpar@1088
   540
    //x y r
alpar@1088
   541
    os << "/di { newpath 2 index 1 index add 2 index moveto\n"
alpar@1088
   542
       << "      2 index             2 index 2 index add lineto\n"
alpar@1088
   543
       << "      2 index 1 index sub 2 index             lineto\n"
alpar@1088
   544
       << "      2 index             2 index 2 index sub lineto\n"
alpar@1088
   545
       << "      closepath pop pop pop} bind def\n";
alpar@1073
   546
    // x y r cr cg cb
alpar@1089
   547
    os << "/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill\n"
alpar@1089
   548
       << "     setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n"
alpar@1073
   549
       << "   } bind def\n";
alpar@1089
   550
    os << "/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill\n"
alpar@1089
   551
       << "     setrgbcolor " << 1+_nodeBorderQuotient << " div sq fill\n"
alpar@1086
   552
       << "   } bind def\n";
alpar@1089
   553
    os << "/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill\n"
alpar@1089
   554
       << "     setrgbcolor " << 1+_nodeBorderQuotient << " div di fill\n"
alpar@1088
   555
       << "   } bind def\n";
alpar@1073
   556
    os << "/arrl " << _arrowLength << " def\n";
alpar@1073
   557
    os << "/arrw " << _arrowWidth << " def\n";
alpar@1073
   558
    // l dx_norm dy_norm
alpar@1073
   559
    os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
alpar@1073
   560
    //len w dx_norm dy_norm x1 y1 cr cg cb
alpar@1073
   561
    os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n"
alpar@1073
   562
       << "       /w exch def /len exch def\n"
alpar@1073
   563
      //	 << "       0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke"
alpar@1073
   564
       << "       newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto\n"
alpar@1073
   565
       << "       len w sub arrl sub dx dy lrl\n"
alpar@1073
   566
       << "       arrw dy dx neg lrl\n"
alpar@1073
   567
       << "       dx arrl w add mul dy w 2 div arrw add mul sub\n"
alpar@1073
   568
       << "       dy arrl w add mul dx w 2 div arrw add mul add rlineto\n"
alpar@1073
   569
       << "       dx arrl w add mul neg dy w 2 div arrw add mul sub\n"
alpar@1073
   570
       << "       dy arrl w add mul neg dx w 2 div arrw add mul add rlineto\n"
alpar@1073
   571
       << "       arrw dy dx neg lrl\n"
alpar@1073
   572
       << "       len w sub arrl sub neg dx dy lrl\n"
alpar@1073
   573
       << "       closepath fill } bind def\n";
alpar@1073
   574
    os << "/cshow { 2 index 2 index moveto dup stringwidth pop\n"
alpar@1073
   575
       << "         neg 2 div fosi .35 mul neg rmoveto show pop pop} def\n";
alpar@1073
   576
alpar@1073
   577
    os << "\ngsave\n";
alpar@1103
   578
    if(_scaleToA4)
alpar@1103
   579
      if(bb.height()>bb.width()) {
alpar@1103
   580
	double sc= min((A4HEIGHT-2*A4BORDER)/bb.height(),
alpar@1103
   581
		  (A4WIDTH-2*A4BORDER)/bb.width());
alpar@1103
   582
	os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' '
alpar@1103
   583
	   << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER << " translate\n"
alpar@1103
   584
	   << sc << " dup scale\n"
alpar@1103
   585
	   << -bb.left() << ' ' << -bb.bottom() << " translate\n";
alpar@1103
   586
      }
alpar@1103
   587
      else {
alpar@1103
   588
	//\todo Verify centering
alpar@1103
   589
	double sc= min((A4HEIGHT-2*A4BORDER)/bb.width(),
alpar@1103
   590
		  (A4WIDTH-2*A4BORDER)/bb.height());
alpar@1103
   591
	os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' '
alpar@1103
   592
	   << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER  << " translate\n"
alpar@1103
   593
	   << sc << " dup scale\n90 rotate\n"
alpar@1103
   594
	   << -bb.left() << ' ' << -bb.top() << " translate\n";	
alpar@1103
   595
	}
alpar@1103
   596
    else if(_scale!=1.0) os << _scale << " dup scale\n";
alpar@1073
   597
    
alpar@1085
   598
    if(_showEdges) {
alpar@1085
   599
      os << "%Edges:\ngsave\n";      
alpar@1073
   600
      if(_enableParallel) {
alpar@1073
   601
	std::vector<Edge> el;
alpar@1073
   602
	for(EdgeIt e(g);e!=INVALID;++e)
alpar@1073
   603
	  if(!_undir||g.source(e)<g.target(e)) el.push_back(e);
alpar@1073
   604
	sort(el.begin(),el.end(),edgeLess(g));
alpar@1073
   605
	
alpar@1073
   606
	typename std::vector<Edge>::iterator j;
alpar@1073
   607
	for(typename std::vector<Edge>::iterator i=el.begin();i!=el.end();i=j) {
alpar@1073
   608
	  for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ;
alpar@1073
   609
alpar@1073
   610
	  double sw=0;
alpar@1073
   611
	  for(typename std::vector<Edge>::iterator e=i;e!=j;++e)
alpar@1073
   612
	    sw+=_edgeWidths[*e]*_edgeWidthScale+_parEdgeDist;
alpar@1073
   613
	  sw-=_parEdgeDist;
alpar@1073
   614
	  sw/=-2.0;
alpar@1085
   615
	  xy<double> dvec(_coords[g.target(*i)]-_coords[g.source(*i)]);
alpar@1085
   616
	  double l=sqrt(dvec.normSquare());
alpar@1085
   617
	  xy<double> d(dvec/l);
alpar@1085
   618
 	  xy<double> m;
alpar@1085
   619
// 	  m=xy<double>(_coords[g.target(*i)]+_coords[g.source(*i)])/2.0;
alpar@1085
   620
alpar@1085
   621
//  	  m=xy<double>(_coords[g.source(*i)])+
alpar@1085
   622
// 	    dvec*(double(_nodeSizes[g.source(*i)])/
alpar@1085
   623
// 	       (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
alpar@1085
   624
alpar@1085
   625
 	  m=xy<double>(_coords[g.source(*i)])+
alpar@1085
   626
	    d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
alpar@1085
   627
alpar@1073
   628
	  for(typename std::vector<Edge>::iterator e=i;e!=j;++e) {
alpar@1073
   629
	    sw+=_edgeWidths[*e]*_edgeWidthScale/2.0;
alpar@1085
   630
	    xy<double> mm=m+rot(d)*sw/.75;
alpar@1073
   631
	    if(_drawArrows) {
alpar@1086
   632
	      int node_shape;
alpar@1073
   633
	      xy<double> s=_coords[g.source(*e)];
alpar@1073
   634
	      xy<double> t=_coords[g.target(*e)];
alpar@1073
   635
	      double rn=_nodeSizes[g.target(*e)]*_nodeScale;
alpar@1086
   636
	      node_shape=_nodeShapes[g.target(*e)];
alpar@1085
   637
	      Bezier3 bez(s,mm,mm,t);
alpar@1073
   638
	      double t1=0,t2=1;
alpar@1087
   639
	      for(int i=0;i<INTERPOL_PREC;++i)
alpar@1086
   640
		if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t2=(t1+t2)/2;
alpar@1086
   641
		else t1=(t1+t2)/2;
alpar@1073
   642
	      xy<double> apoint=bez((t1+t2)/2);
alpar@1086
   643
	      rn = _arrowLength+_edgeWidths[*e]*_edgeWidthScale;
alpar@1073
   644
	      rn*=rn;
alpar@1086
   645
	      t2=(t1+t2)/2;t1=0;
alpar@1087
   646
	      for(int i=0;i<INTERPOL_PREC;++i)
alpar@1086
   647
		if((bez((t1+t2)/2)-apoint).normSquare()>rn) t1=(t1+t2)/2;
alpar@1073
   648
		else t2=(t1+t2)/2;
alpar@1073
   649
	      xy<double> linend=bez((t1+t2)/2);	      
alpar@1073
   650
	      bez=bez.before((t1+t2)/2);
alpar@1086
   651
// 	      rn=_nodeSizes[g.source(*e)]*_nodeScale;
alpar@1086
   652
// 	      node_shape=_nodeShapes[g.source(*e)];
alpar@1086
   653
// 	      t1=0;t2=1;
alpar@1087
   654
// 	      for(int i=0;i<INTERPOL_PREC;++i)
alpar@1086
   655
// 		if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t1=(t1+t2)/2;
alpar@1086
   656
// 		else t2=(t1+t2)/2;
alpar@1086
   657
// 	      bez=bez.after((t1+t2)/2);
alpar@1073
   658
	      os << _edgeWidths[*e]*_edgeWidthScale << " setlinewidth "
alpar@1073
   659
		 << _edgeColors[*e].getR() << ' '
alpar@1073
   660
		 << _edgeColors[*e].getG() << ' '
alpar@1073
   661
		 << _edgeColors[*e].getB() << " setrgbcolor newpath\n"
alpar@1073
   662
		 << bez.p1.x << ' ' <<  bez.p1.y << " moveto\n"
alpar@1073
   663
		 << bez.p2.x << ' ' << bez.p2.y << ' '
alpar@1073
   664
		 << bez.p3.x << ' ' << bez.p3.y << ' '
alpar@1073
   665
		 << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
alpar@1073
   666
	      xy<double> dd(rot(linend-apoint));
alpar@1089
   667
	      dd*=(.5*_edgeWidths[*e]*_edgeWidthScale+_arrowWidth)/
alpar@1073
   668
		sqrt(dd.normSquare());
alpar@1073
   669
	      os << "newpath " << psOut(apoint) << " moveto "
alpar@1073
   670
		 << psOut(linend+dd) << " lineto "
alpar@1073
   671
		 << psOut(linend-dd) << " lineto closepath fill\n";
alpar@1073
   672
	    }
alpar@1073
   673
	    else {
alpar@1073
   674
	      os << _coords[g.source(*e)].x << ' '
alpar@1073
   675
		 << _coords[g.source(*e)].y << ' '
alpar@1085
   676
		 << mm.x << ' ' << mm.y << ' '
alpar@1073
   677
		 << _coords[g.target(*e)].x << ' '
alpar@1073
   678
		 << _coords[g.target(*e)].y << ' '
alpar@1073
   679
		 << _edgeColors[*e].getR() << ' '
alpar@1073
   680
		 << _edgeColors[*e].getG() << ' '
alpar@1073
   681
		 << _edgeColors[*e].getB() << ' '
alpar@1073
   682
		 << _edgeWidths[*e]*_edgeWidthScale << " lb\n";
alpar@1073
   683
	    }
alpar@1073
   684
	    sw+=_edgeWidths[*e]*_edgeWidthScale/2.0+_parEdgeDist;
alpar@1073
   685
	  }
alpar@1073
   686
	}
alpar@1073
   687
      }
alpar@1073
   688
      else for(EdgeIt e(g);e!=INVALID;++e)
alpar@1073
   689
	if(!_undir||g.source(e)<g.target(e))
alpar@1073
   690
	  if(_drawArrows) {
alpar@1073
   691
	    xy<double> d(_coords[g.target(e)]-_coords[g.source(e)]);
alpar@1087
   692
	    double rn=_nodeSizes[g.target(e)]*_nodeScale;
alpar@1087
   693
	    int node_shape=_nodeShapes[g.target(e)];
alpar@1087
   694
	    double t1=0,t2=1;
alpar@1087
   695
	    for(int i=0;i<INTERPOL_PREC;++i)
alpar@1087
   696
	      if(isInsideNode((-(t1+t2)/2)*d,rn,node_shape)) t1=(t1+t2)/2;
alpar@1087
   697
	      else t2=(t1+t2)/2;
alpar@1073
   698
	    double l=sqrt(d.normSquare());
alpar@1073
   699
	    d/=l;
alpar@1087
   700
	    
alpar@1087
   701
	    os << l*(1-(t1+t2)/2) << ' '
alpar@1073
   702
	       << _edgeWidths[e]*_edgeWidthScale << ' '
alpar@1073
   703
	       << d.x << ' ' << d.y << ' '
alpar@1087
   704
	       << _coords[g.source(e)].x << ' '
alpar@1087
   705
	       << _coords[g.source(e)].y << ' '
alpar@1073
   706
	       << _edgeColors[e].getR() << ' '
alpar@1073
   707
	       << _edgeColors[e].getG() << ' '
alpar@1073
   708
	       << _edgeColors[e].getB() << " arr\n";
alpar@1073
   709
	  }
alpar@1073
   710
	  else os << _coords[g.source(e)].x << ' '
alpar@1073
   711
		  << _coords[g.source(e)].y << ' '
alpar@1073
   712
		  << _coords[g.target(e)].x << ' '
alpar@1073
   713
		  << _coords[g.target(e)].y << ' '
alpar@1073
   714
		  << _edgeColors[e].getR() << ' '
alpar@1073
   715
		  << _edgeColors[e].getG() << ' '
alpar@1073
   716
		  << _edgeColors[e].getB() << ' '
alpar@1073
   717
		  << _edgeWidths[e]*_edgeWidthScale << " l\n";
alpar@1085
   718
      os << "grestore\n";
alpar@1085
   719
    }
alpar@1085
   720
    if(_showNodes) {
alpar@1085
   721
      os << "%Nodes:\ngsave\n";
alpar@1086
   722
      for(NodeIt n(g);n!=INVALID;++n) {
alpar@1073
   723
	os << _coords[n].x << ' ' << _coords[n].y << ' '
alpar@1073
   724
	   << _nodeSizes[n]*_nodeScale << ' '
alpar@1073
   725
	   << _nodeColors[n].getR() << ' '
alpar@1073
   726
	   << _nodeColors[n].getG() << ' '
alpar@1086
   727
	   << _nodeColors[n].getB() << ' ';
alpar@1086
   728
	switch(_nodeShapes[n]) {
alpar@1086
   729
	case CIRCLE:
alpar@1086
   730
	  os<< "nc";break;
alpar@1086
   731
	case SQUARE:
alpar@1086
   732
	  os<< "nsq";break;
alpar@1088
   733
	case DIAMOND:
alpar@1088
   734
	  os<< "ndi";break;
alpar@1086
   735
	}
alpar@1086
   736
	os<<'\n';
alpar@1086
   737
      }
alpar@1085
   738
      os << "grestore\n";
alpar@1085
   739
    }
alpar@1073
   740
    if(_showNodeText) {
alpar@1085
   741
      os << "%Node texts:\ngsave\n";
alpar@1073
   742
      os << "/fosi " << _nodeTextSize << " def\n";
alpar@1073
   743
      os << "(Helvetica) findfont fosi scalefont setfont\n";
alpar@1073
   744
      os << "0 0 0 setrgbcolor\n";
alpar@1073
   745
      for(NodeIt n(g);n!=INVALID;++n)
alpar@1073
   746
	os << _coords[n].x << ' ' << _coords[n].y
alpar@1073
   747
	   << " (" << _nodeTexts[n] << ") cshow\n";
alpar@1085
   748
      os << "grestore\n";
alpar@1073
   749
    }
alpar@1085
   750
    if(_showNodePsText) {
alpar@1085
   751
      os << "%Node PS blocks:\ngsave\n";
alpar@1085
   752
      for(NodeIt n(g);n!=INVALID;++n)
alpar@1085
   753
	os << _coords[n].x << ' ' << _coords[n].y
alpar@1085
   754
	   << " moveto\n" << _nodePsTexts[n] << "\n";
alpar@1085
   755
      os << "grestore\n";
alpar@1085
   756
    }
alpar@1085
   757
    
alpar@1103
   758
    os << "grestore\nshowpage\n";
alpar@1073
   759
alpar@1073
   760
    //CleanUp:
alpar@1073
   761
    if(_pleaseRemoveOsStream) {delete &os;}
alpar@1073
   762
  } 
alpar@1073
   763
};
alpar@1073
   764
alpar@1073
   765
alpar@1073
   766
///Generates an EPS file from a graph
alpar@1073
   767
alpar@1073
   768
///\ingroup misc
alpar@1073
   769
///Generates an EPS file from a graph.
alpar@1073
   770
///\param g is a reference to the graph to be printed
alpar@1073
   771
///\param os is a reference to the output stream.
alpar@1073
   772
///By default it is <tt>std::cout</tt>
alpar@1073
   773
///
alpar@1091
   774
///This function also has a lot of
alpar@1091
   775
///\ref named-templ-func-param "named parameters",
alpar@1073
   776
///they are declared as the members of class \ref GraphToEps. The following
alpar@1073
   777
///example shows how to use these parameters.
alpar@1073
   778
///\code
alpar@1073
   779
/// graphToEps(g).scale(10).coords(coords)
alpar@1073
   780
///              .nodeScale(2).nodeSizes(sizes)
alpar@1091
   781
///              .edgeWidthScale(.4).run();
alpar@1073
   782
///\endcode
alpar@1091
   783
///\warning Don't forget to put the \ref GraphToEps::run() "run()"
alpar@1091
   784
///to the end of the parameter list.
alpar@1073
   785
///\sa GraphToEps
alpar@1073
   786
///\sa graphToEps(G &g, char *file_name)
alpar@1073
   787
template<class G>
alpar@1073
   788
GraphToEps<DefaultGraphToEpsTraits<G> > 
alpar@1073
   789
graphToEps(G &g, std::ostream& os=std::cout)
alpar@1073
   790
{
alpar@1073
   791
  return 
alpar@1073
   792
    GraphToEps<DefaultGraphToEpsTraits<G> >(DefaultGraphToEpsTraits<G>(g,os));
alpar@1073
   793
}
alpar@1073
   794
 
alpar@1073
   795
///Generates an EPS file from a graph
alpar@1073
   796
alpar@1103
   797
///\ingroup misc
alpar@1073
   798
///This function does the same as
alpar@1073
   799
///\ref graphToEps(G &g,std::ostream& os)
alpar@1073
   800
///but it writes its output into the file \c file_name
alpar@1073
   801
///instead of a stream.
alpar@1073
   802
///\sa graphToEps(G &g, std::ostream& os)
alpar@1073
   803
template<class G>
alpar@1073
   804
GraphToEps<DefaultGraphToEpsTraits<G> > 
alpar@1107
   805
graphToEps(G &g,const char *file_name)
alpar@1073
   806
{
alpar@1073
   807
  return GraphToEps<DefaultGraphToEpsTraits<G> >
alpar@1073
   808
    (DefaultGraphToEpsTraits<G>(g,*new std::ofstream(file_name),true));
alpar@1073
   809
}
alpar@1073
   810
alpar@1073
   811
} //END OF NAMESPACE LEMON
alpar@1073
   812
alpar@1073
   813
#endif // LEMON_GRAPH_TO_EPS_H