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