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