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