0
2
0
| ... | ... |
@@ -10,199 +10,199 @@ |
| 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 |
/// \ingroup demos |
| 20 | 20 |
/// \file |
| 21 | 21 |
/// \brief Demo of the graph grawing function \ref graphToEps() |
| 22 | 22 |
/// |
| 23 | 23 |
/// This demo program shows examples how to use the function \ref |
| 24 | 24 |
/// graphToEps(). It takes no input but simply creates six |
| 25 | 25 |
/// <tt>.eps</tt> files demonstrating the capability of \ref |
| 26 | 26 |
/// graphToEps(), and showing how to draw directed/graphs, |
| 27 | 27 |
/// how to handle parallel egdes, how to change the properties (like |
| 28 | 28 |
/// color, shape, size, title etc.) of nodes and arcs individually |
| 29 | 29 |
/// using appropriate \ref maps-page "graph maps". |
| 30 | 30 |
/// |
| 31 | 31 |
/// \include graph_to_eps_demo.cc |
| 32 | 32 |
|
| 33 | 33 |
#include <lemon/math.h> |
| 34 | 34 |
|
| 35 | 35 |
#include<lemon/graph_to_eps.h> |
| 36 | 36 |
#include<lemon/list_graph.h> |
| 37 | 37 |
#include<lemon/graph_utils.h> |
| 38 | 38 |
|
| 39 | 39 |
using namespace std; |
| 40 | 40 |
using namespace lemon; |
| 41 | 41 |
|
| 42 | 42 |
int main() |
| 43 | 43 |
{
|
| 44 | 44 |
Palette palette; |
| 45 | 45 |
Palette paletteW(true); |
| 46 | 46 |
|
| 47 | 47 |
ListDigraph g; |
| 48 | 48 |
typedef ListDigraph::Node Node; |
| 49 | 49 |
typedef ListDigraph::NodeIt NodeIt; |
| 50 | 50 |
typedef ListDigraph::Arc Arc; |
| 51 | 51 |
typedef dim2::Point<int> Point; |
| 52 | 52 |
|
| 53 | 53 |
Node n1=g.addNode(); |
| 54 | 54 |
Node n2=g.addNode(); |
| 55 | 55 |
Node n3=g.addNode(); |
| 56 | 56 |
Node n4=g.addNode(); |
| 57 | 57 |
Node n5=g.addNode(); |
| 58 | 58 |
|
| 59 | 59 |
ListDigraph::NodeMap<Point> coords(g); |
| 60 | 60 |
ListDigraph::NodeMap<double> sizes(g); |
| 61 | 61 |
ListDigraph::NodeMap<int> colors(g); |
| 62 | 62 |
ListDigraph::NodeMap<int> shapes(g); |
| 63 | 63 |
ListDigraph::ArcMap<int> ecolors(g); |
| 64 | 64 |
ListDigraph::ArcMap<int> widths(g); |
| 65 | 65 |
|
| 66 | 66 |
coords[n1]=Point(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0; |
| 67 | 67 |
coords[n2]=Point(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2; |
| 68 | 68 |
coords[n3]=Point(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0; |
| 69 | 69 |
coords[n4]=Point(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1; |
| 70 | 70 |
coords[n5]=Point(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2; |
| 71 | 71 |
|
| 72 | 72 |
Arc e; |
| 73 | 73 |
|
| 74 | 74 |
e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1; |
| 75 | 75 |
e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1; |
| 76 | 76 |
e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3; |
| 77 | 77 |
e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1; |
| 78 | 78 |
e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1; |
| 79 | 79 |
e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2; |
| 80 | 80 |
e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1; |
| 81 | 81 |
|
| 82 | 82 |
IdMap<ListDigraph,Node> id(g); |
| 83 | 83 |
|
| 84 | 84 |
cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl; |
| 85 | 85 |
graphToEps(g,"graph_to_eps_demo_out_pure.eps"). |
| 86 | 86 |
//scale(10). |
| 87 | 87 |
coords(coords). |
| 88 | 88 |
title("Sample .eps figure").
|
| 89 | 89 |
copyright("(C) 2003-2007 LEMON Project").
|
| 90 | 90 |
run(); |
| 91 | 91 |
|
| 92 | 92 |
cout << "Create 'graph_to_eps_demo_out.eps'" << endl; |
| 93 | 93 |
graphToEps(g,"graph_to_eps_demo_out.eps"). |
| 94 | 94 |
//scale(10). |
| 95 | 95 |
coords(coords). |
| 96 | 96 |
title("Sample .eps figure").
|
| 97 | 97 |
copyright("(C) 2003-2007 LEMON Project").
|
| 98 | 98 |
absoluteNodeSizes().absoluteArcWidths(). |
| 99 | 99 |
nodeScale(2).nodeSizes(sizes). |
| 100 | 100 |
nodeShapes(shapes). |
| 101 | 101 |
nodeColors(composeMap(palette,colors)). |
| 102 | 102 |
arcColors(composeMap(palette,ecolors)). |
| 103 | 103 |
arcWidthScale(.4).arcWidths(widths). |
| 104 | 104 |
nodeTexts(id).nodeTextSize(3). |
| 105 | 105 |
run(); |
| 106 | 106 |
|
| 107 | 107 |
|
| 108 | 108 |
cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl; |
| 109 | 109 |
graphToEps(g,"graph_to_eps_demo_out_arr.eps"). |
| 110 | 110 |
//scale(10). |
| 111 | 111 |
title("Sample .eps figure (with arrowheads)").
|
| 112 | 112 |
copyright("(C) 2003-2007 LEMON Project").
|
| 113 | 113 |
absoluteNodeSizes().absoluteArcWidths(). |
| 114 | 114 |
nodeColors(composeMap(palette,colors)). |
| 115 | 115 |
coords(coords). |
| 116 | 116 |
nodeScale(2).nodeSizes(sizes). |
| 117 | 117 |
nodeShapes(shapes). |
| 118 | 118 |
arcColors(composeMap(palette,ecolors)). |
| 119 | 119 |
arcWidthScale(.4).arcWidths(widths). |
| 120 | 120 |
nodeTexts(id).nodeTextSize(3). |
| 121 | 121 |
drawArrows().arrowWidth(1).arrowLength(1). |
| 122 | 122 |
run(); |
| 123 | 123 |
|
| 124 | 124 |
e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1; |
| 125 | 125 |
e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=2; |
| 126 | 126 |
|
| 127 | 127 |
e=g.addArc(n1,n2); ecolors[e]=1; widths[e]=1; |
| 128 | 128 |
e=g.addArc(n1,n2); ecolors[e]=2; widths[e]=1; |
| 129 | 129 |
e=g.addArc(n1,n2); ecolors[e]=3; widths[e]=1; |
| 130 | 130 |
e=g.addArc(n1,n2); ecolors[e]=4; widths[e]=1; |
| 131 | 131 |
e=g.addArc(n1,n2); ecolors[e]=5; widths[e]=1; |
| 132 | 132 |
e=g.addArc(n1,n2); ecolors[e]=6; widths[e]=1; |
| 133 | 133 |
e=g.addArc(n1,n2); ecolors[e]=7; widths[e]=1; |
| 134 | 134 |
|
| 135 | 135 |
cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl; |
| 136 | 136 |
graphToEps(g,"graph_to_eps_demo_out_par.eps"). |
| 137 | 137 |
//scale(10). |
| 138 | 138 |
title("Sample .eps figure (parallel arcs)").
|
| 139 | 139 |
copyright("(C) 2003-2007 LEMON Project").
|
| 140 | 140 |
absoluteNodeSizes().absoluteArcWidths(). |
| 141 | 141 |
nodeShapes(shapes). |
| 142 | 142 |
coords(coords). |
| 143 | 143 |
nodeScale(2).nodeSizes(sizes). |
| 144 | 144 |
nodeColors(composeMap(palette,colors)). |
| 145 | 145 |
arcColors(composeMap(palette,ecolors)). |
| 146 | 146 |
arcWidthScale(.4).arcWidths(widths). |
| 147 | 147 |
nodeTexts(id).nodeTextSize(3). |
| 148 | 148 |
enableParallel().parArcDist(1.5). |
| 149 | 149 |
run(); |
| 150 | 150 |
|
| 151 | 151 |
cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl; |
| 152 | 152 |
graphToEps(g,"graph_to_eps_demo_out_par_arr.eps"). |
| 153 | 153 |
//scale(10). |
| 154 | 154 |
title("Sample .eps figure (parallel arcs and arrowheads)").
|
| 155 | 155 |
copyright("(C) 2003-2007 LEMON Project").
|
| 156 | 156 |
absoluteNodeSizes().absoluteArcWidths(). |
| 157 | 157 |
nodeScale(2).nodeSizes(sizes). |
| 158 | 158 |
coords(coords). |
| 159 | 159 |
nodeShapes(shapes). |
| 160 | 160 |
nodeColors(composeMap(palette,colors)). |
| 161 | 161 |
arcColors(composeMap(palette,ecolors)). |
| 162 | 162 |
arcWidthScale(.3).arcWidths(widths). |
| 163 | 163 |
nodeTexts(id).nodeTextSize(3). |
| 164 | 164 |
enableParallel().parArcDist(1). |
| 165 | 165 |
drawArrows().arrowWidth(1).arrowLength(1). |
| 166 | 166 |
run(); |
| 167 | 167 |
|
| 168 | 168 |
cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl; |
| 169 | 169 |
graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4(). |
| 170 | 170 |
title("Sample .eps figure (fits to A4)").
|
| 171 | 171 |
copyright("(C) 2003-2007 LEMON Project").
|
| 172 | 172 |
absoluteNodeSizes().absoluteArcWidths(). |
| 173 | 173 |
nodeScale(2).nodeSizes(sizes). |
| 174 | 174 |
coords(coords). |
| 175 | 175 |
nodeShapes(shapes). |
| 176 | 176 |
nodeColors(composeMap(palette,colors)). |
| 177 | 177 |
arcColors(composeMap(palette,ecolors)). |
| 178 | 178 |
arcWidthScale(.3).arcWidths(widths). |
| 179 | 179 |
nodeTexts(id).nodeTextSize(3). |
| 180 | 180 |
enableParallel().parArcDist(1). |
| 181 | 181 |
drawArrows().arrowWidth(1).arrowLength(1). |
| 182 | 182 |
run(); |
| 183 | 183 |
|
| 184 | 184 |
ListDigraph h; |
| 185 | 185 |
ListDigraph::NodeMap<int> hcolors(h); |
| 186 | 186 |
ListDigraph::NodeMap<Point> hcoords(h); |
| 187 | 187 |
|
| 188 | 188 |
int cols=int(sqrt(double(palette.size()))); |
| 189 | 189 |
for(int i=0;i<int(paletteW.size());i++) {
|
| 190 | 190 |
Node n=h.addNode(); |
| 191 | 191 |
hcoords[n]=Point(i%cols,i/cols); |
| 192 | 192 |
hcolors[n]=i; |
| 193 | 193 |
} |
| 194 | 194 |
|
| 195 | 195 |
cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl; |
| 196 | 196 |
graphToEps(h,"graph_to_eps_demo_out_colors.eps"). |
| 197 | 197 |
//scale(60). |
| 198 | 198 |
title("Sample .eps figure (Palette demo)").
|
| 199 | 199 |
copyright("(C) 2003-2007 LEMON Project").
|
| 200 | 200 |
coords(hcoords). |
| 201 | 201 |
absoluteNodeSizes().absoluteArcWidths(). |
| 202 |
nodeScale(45). |
|
| 202 |
nodeScale(.45). |
|
| 203 | 203 |
distantColorNodeTexts(). |
| 204 | 204 |
// distantBWNodeTexts(). |
| 205 | 205 |
nodeTexts(hcolors).nodeTextSize(.6). |
| 206 | 206 |
nodeColors(composeMap(paletteW,hcolors)). |
| 207 | 207 |
run(); |
| 208 | 208 |
} |
| 1 | 1 |
/* -*- C++ -*- |
| 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 <sys/time.h> |
| 23 | 23 |
|
| 24 | 24 |
#ifdef WIN32 |
| 25 | 25 |
#include <lemon/bits/mingw32_time.h> |
| 26 | 26 |
#endif |
| 27 | 27 |
|
| 28 | 28 |
#include<iostream> |
| 29 | 29 |
#include<fstream> |
| 30 | 30 |
#include<sstream> |
| 31 | 31 |
#include<algorithm> |
| 32 | 32 |
#include<vector> |
| 33 | 33 |
|
| 34 | 34 |
#include<ctime> |
| 35 | 35 |
|
| 36 | 36 |
#include<lemon/math.h> |
| 37 | 37 |
#include<lemon/bits/invalid.h> |
| 38 | 38 |
#include<lemon/dim2.h> |
| 39 | 39 |
#include<lemon/maps.h> |
| 40 | 40 |
#include<lemon/color.h> |
| 41 | 41 |
#include<lemon/bits/bezier.h> |
| 42 | 42 |
|
| 43 | 43 |
|
| 44 | 44 |
///\ingroup eps_io |
| 45 | 45 |
///\file |
| 46 | 46 |
///\brief Simple graph drawer |
| 47 | 47 |
/// |
| 48 | 48 |
///\author Alpar Juttner |
| 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 \ref 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 is a reference to the graph to be printed |
| 145 | 145 |
///\param _os is a reference to the output stream. |
| 146 | 146 |
///\param _os is a reference to the output stream. |
| 147 | 147 |
///\param _pros If it is \c true, then the \c ostream referenced by \c _os |
| 148 | 148 |
///will be explicitly deallocated by the destructor. |
| 149 | 149 |
///By default it is <tt>std::cout</tt> |
| 150 | 150 |
DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout, |
| 151 | 151 |
bool _pros=false) : |
| 152 | 152 |
g(_g), os(_os), |
| 153 |
_coords(dim2::Point<double>(1,1)), _nodeSizes( |
|
| 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 |
_nodeScale( |
|
| 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 |
///Helper class to implement the named parameters of \ref graphToEps() |
| 176 | 176 |
|
| 177 | 177 |
///Helper class to implement the named parameters of \ref graphToEps() |
| 178 | 178 |
///\todo Is 'helper class' a good name for this? |
| 179 | 179 |
/// |
| 180 | 180 |
///\todo Follow PostScript's DSC. |
| 181 | 181 |
/// Use own dictionary. |
| 182 | 182 |
///\todo Useful new features. |
| 183 | 183 |
/// - Linestyles: dotted, dashed etc. |
| 184 | 184 |
/// - A second color and percent value for the lines. |
| 185 | 185 |
template<class T> class GraphToEps : public T |
| 186 | 186 |
{
|
| 187 | 187 |
// Can't believe it is required by the C++ standard |
| 188 | 188 |
using T::g; |
| 189 | 189 |
using T::os; |
| 190 | 190 |
|
| 191 | 191 |
using T::_coords; |
| 192 | 192 |
using T::_nodeSizes; |
| 193 | 193 |
using T::_nodeShapes; |
| 194 | 194 |
using T::_nodeColors; |
| 195 | 195 |
using T::_arcColors; |
| 196 | 196 |
using T::_arcWidths; |
| 197 | 197 |
|
| 198 | 198 |
using T::_arcWidthScale; |
| 199 | 199 |
using T::_nodeScale; |
| 200 | 200 |
using T::_xBorder; |
| 201 | 201 |
using T::_yBorder; |
| 202 | 202 |
using T::_scale; |
| 203 | 203 |
using T::_nodeBorderQuotient; |
| 204 | 204 |
|
| 205 | 205 |
using T::_drawArrows; |
| 206 | 206 |
using T::_arrowLength; |
| 207 | 207 |
using T::_arrowWidth; |
| 208 | 208 |
|
| 209 | 209 |
using T::_showNodes; |
| 210 | 210 |
using T::_showArcs; |
| 211 | 211 |
|
| 212 | 212 |
using T::_enableParallel; |
| 213 | 213 |
using T::_parArcDist; |
| 214 | 214 |
|
| 215 | 215 |
using T::_showNodeText; |
| 216 | 216 |
using T::_nodeTexts; |
| 217 | 217 |
using T::_nodeTextSize; |
| 218 | 218 |
|
| 219 | 219 |
using T::_showNodePsText; |
| 220 | 220 |
using T::_nodePsTexts; |
| 221 | 221 |
using T::_nodePsTextsPreamble; |
| 222 | 222 |
|
| 223 | 223 |
using T::_undirected; |
| 224 | 224 |
|
| 225 | 225 |
using T::_pleaseRemoveOsStream; |
| 226 | 226 |
|
| 227 | 227 |
using T::_scaleToA4; |
| 228 | 228 |
|
| 229 | 229 |
using T::_title; |
| 230 | 230 |
using T::_copyright; |
| 231 | 231 |
|
| 232 | 232 |
using T::NodeTextColorType; |
| 233 | 233 |
using T::CUST_COL; |
| 234 | 234 |
using T::DIST_COL; |
| 235 | 235 |
using T::DIST_BW; |
| 236 | 236 |
using T::_nodeTextColorType; |
| 237 | 237 |
using T::_nodeTextColors; |
| 238 | 238 |
|
| 239 | 239 |
using T::_autoNodeScale; |
| 240 | 240 |
using T::_autoArcWidthScale; |
| 241 | 241 |
|
| 242 | 242 |
using T::_absoluteNodeSizes; |
| 243 | 243 |
using T::_absoluteArcWidths; |
| 244 | 244 |
|
| 245 | 245 |
|
| 246 | 246 |
using T::_negY; |
| 247 | 247 |
using T::_preScale; |
| 248 | 248 |
|
| 249 | 249 |
// dradnats ++C eht yb deriuqer si ti eveileb t'naC |
| 250 | 250 |
|
| 251 | 251 |
typedef typename T::Graph Graph; |
| 252 | 252 |
typedef typename Graph::Node Node; |
| 253 | 253 |
typedef typename Graph::NodeIt NodeIt; |
| 254 | 254 |
typedef typename Graph::Arc Arc; |
| 255 | 255 |
typedef typename Graph::ArcIt ArcIt; |
| 256 | 256 |
typedef typename Graph::InArcIt InArcIt; |
| 257 | 257 |
typedef typename Graph::OutArcIt OutArcIt; |
| 258 | 258 |
|
| 259 | 259 |
static const int INTERPOL_PREC; |
| 260 | 260 |
static const double A4HEIGHT; |
| 261 | 261 |
static const double A4WIDTH; |
| 262 | 262 |
static const double A4BORDER; |
| 263 | 263 |
|
| 264 | 264 |
bool dontPrint; |
| 265 | 265 |
|
| 266 | 266 |
public: |
| 267 | 267 |
///Node shapes |
| 268 | 268 |
|
| 269 | 269 |
///Node shapes |
| 270 | 270 |
/// |
| 271 | 271 |
enum NodeShapes {
|
| 272 | 272 |
/// = 0 |
| 273 | 273 |
///\image html nodeshape_0.png |
| 274 | 274 |
///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm |
| 275 | 275 |
CIRCLE=0, |
| 276 | 276 |
/// = 1 |
| 277 | 277 |
///\image html nodeshape_1.png |
| 278 | 278 |
///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm |
| 279 | 279 |
/// |
| 280 | 280 |
SQUARE=1, |
| 281 | 281 |
/// = 2 |
| 282 | 282 |
///\image html nodeshape_2.png |
| 283 | 283 |
///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm |
| 284 | 284 |
/// |
| 285 | 285 |
DIAMOND=2, |
| 286 | 286 |
/// = 3 |
| 287 | 287 |
///\image html nodeshape_3.png |
| 288 | 288 |
///\image latex nodeshape_2.eps "MALE shape (4)" width=2cm |
| 289 | 289 |
/// |
| 290 | 290 |
MALE=3, |
| 291 | 291 |
/// = 4 |
| 292 | 292 |
///\image html nodeshape_4.png |
| 293 | 293 |
///\image latex nodeshape_2.eps "FEMALE shape (4)" width=2cm |
| 294 | 294 |
/// |
| 295 | 295 |
FEMALE=4 |
| 296 | 296 |
}; |
| 297 | 297 |
|
| 298 | 298 |
private: |
| 299 | 299 |
class arcLess {
|
| 300 | 300 |
const Graph &g; |
| 301 | 301 |
public: |
| 302 | 302 |
arcLess(const Graph &_g) : g(_g) {}
|
| 303 | 303 |
bool operator()(Arc a,Arc b) const |
| 304 | 304 |
{
|
| 305 | 305 |
Node ai=std::min(g.source(a),g.target(a)); |
| 306 | 306 |
Node aa=std::max(g.source(a),g.target(a)); |
| 307 | 307 |
Node bi=std::min(g.source(b),g.target(b)); |
| 308 | 308 |
Node ba=std::max(g.source(b),g.target(b)); |
| 309 | 309 |
return ai<bi || |
| 310 | 310 |
(ai==bi && (aa < ba || |
| 311 | 311 |
(aa==ba && ai==g.source(a) && bi==g.target(b)))); |
| 312 | 312 |
} |
| 313 | 313 |
}; |
| 314 | 314 |
bool isParallel(Arc e,Arc f) const |
| 315 | 315 |
{
|
| 316 | 316 |
return (g.source(e)==g.source(f)&& |
| 317 | 317 |
g.target(e)==g.target(f)) || |
| 318 | 318 |
(g.source(e)==g.target(f)&& |
| 319 | 319 |
g.target(e)==g.source(f)); |
| 320 | 320 |
} |
| 321 | 321 |
template<class TT> |
| 322 | 322 |
static std::string psOut(const dim2::Point<TT> &p) |
| 323 | 323 |
{
|
| 324 | 324 |
std::ostringstream os; |
| 325 | 325 |
os << p.x << ' ' << p.y; |
| 326 | 326 |
return os.str(); |
| 327 | 327 |
} |
| 328 | 328 |
static std::string psOut(const Color &c) |
| 329 | 329 |
{
|
| 330 | 330 |
std::ostringstream os; |
| 331 | 331 |
os << c.red() << ' ' << c.green() << ' ' << c.blue(); |
| 332 | 332 |
return os.str(); |
| 333 | 333 |
} |
| 334 | 334 |
|
| 335 | 335 |
public: |
| 336 | 336 |
GraphToEps(const T &t) : T(t), dontPrint(false) {};
|
| 337 | 337 |
|
| 338 | 338 |
template<class X> struct CoordsTraits : public T {
|
| 339 | 339 |
typedef X CoordsMapType; |
| 340 | 340 |
const X &_coords; |
| 341 | 341 |
CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {}
|
| 342 | 342 |
}; |
| 343 | 343 |
///Sets the map of the node coordinates |
| 344 | 344 |
|
| 345 | 345 |
///Sets the map of the node coordinates. |
| 346 | 346 |
///\param x must be a node map with dim2::Point<double> or |
| 347 | 347 |
///\ref dim2::Point "dim2::Point<int>" values. |
| 348 | 348 |
template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
|
| 349 | 349 |
dontPrint=true; |
| 350 | 350 |
return GraphToEps<CoordsTraits<X> >(CoordsTraits<X>(*this,x)); |
| 351 | 351 |
} |
| 352 | 352 |
template<class X> struct NodeSizesTraits : public T {
|
| 353 | 353 |
const X &_nodeSizes; |
| 354 | 354 |
NodeSizesTraits(const T &t,const X &x) : T(t), _nodeSizes(x) {}
|
| 355 | 355 |
}; |
| 356 | 356 |
///Sets the map of the node sizes |
| 357 | 357 |
|
| 358 | 358 |
///Sets the map of the node sizes |
| 359 | 359 |
///\param x must be a node map with \c double (or convertible) values. |
| 360 | 360 |
template<class X> GraphToEps<NodeSizesTraits<X> > nodeSizes(const X &x) |
| 361 | 361 |
{
|
| 362 | 362 |
dontPrint=true; |
| 363 | 363 |
return GraphToEps<NodeSizesTraits<X> >(NodeSizesTraits<X>(*this,x)); |
| 364 | 364 |
} |
| 365 | 365 |
template<class X> struct NodeShapesTraits : public T {
|
| 366 | 366 |
const X &_nodeShapes; |
| 367 | 367 |
NodeShapesTraits(const T &t,const X &x) : T(t), _nodeShapes(x) {}
|
| 368 | 368 |
}; |
| 369 | 369 |
///Sets the map of the node shapes |
| 370 | 370 |
|
| 371 | 371 |
///Sets the map of the node shapes. |
| 372 | 372 |
///The availabe shape values |
| 373 | 373 |
///can be found in \ref NodeShapes "enum NodeShapes". |
| 374 | 374 |
///\param x must be a node map with \c int (or convertible) values. |
| 375 | 375 |
///\sa NodeShapes |
| 376 | 376 |
template<class X> GraphToEps<NodeShapesTraits<X> > nodeShapes(const X &x) |
| 377 | 377 |
{
|
| 378 | 378 |
dontPrint=true; |
| 379 | 379 |
return GraphToEps<NodeShapesTraits<X> >(NodeShapesTraits<X>(*this,x)); |
| 380 | 380 |
} |
| 381 | 381 |
template<class X> struct NodeTextsTraits : public T {
|
| 382 | 382 |
const X &_nodeTexts; |
| 383 | 383 |
NodeTextsTraits(const T &t,const X &x) : T(t), _nodeTexts(x) {}
|
| 384 | 384 |
}; |
| 385 | 385 |
///Sets the text printed on the nodes |
| 386 | 386 |
|
| 387 | 387 |
///Sets the text printed on the nodes |
| 388 | 388 |
///\param x must be a node map with type that can be pushed to a standard |
| 389 | 389 |
///ostream. |
| 390 | 390 |
template<class X> GraphToEps<NodeTextsTraits<X> > nodeTexts(const X &x) |
| 391 | 391 |
{
|
| 392 | 392 |
dontPrint=true; |
| 393 | 393 |
_showNodeText=true; |
| 394 | 394 |
return GraphToEps<NodeTextsTraits<X> >(NodeTextsTraits<X>(*this,x)); |
| 395 | 395 |
} |
| 396 | 396 |
template<class X> struct NodePsTextsTraits : public T {
|
| 397 | 397 |
const X &_nodePsTexts; |
| 398 | 398 |
NodePsTextsTraits(const T &t,const X &x) : T(t), _nodePsTexts(x) {}
|
| 399 | 399 |
}; |
| 400 | 400 |
///Inserts a PostScript block to the nodes |
| 401 | 401 |
|
| 402 | 402 |
///With this command it is possible to insert a verbatim PostScript |
| 403 | 403 |
///block to the nodes. |
| 404 | 404 |
///The PS current point will be moved to the centre of the node before |
| 405 | 405 |
///the PostScript block inserted. |
| 406 | 406 |
/// |
| 407 | 407 |
///Before and after the block a newline character is inserted so you |
| 408 | 408 |
///don't have to bother with the separators. |
| 409 | 409 |
/// |
| 410 | 410 |
///\param x must be a node map with type that can be pushed to a standard |
| 411 | 411 |
///ostream. |
| 412 | 412 |
/// |
| 413 | 413 |
///\sa nodePsTextsPreamble() |
| 414 | 414 |
///\todo Offer the choise not to move to the centre but pass the coordinates |
| 415 | 415 |
///to the Postscript block inserted. |
| 416 | 416 |
template<class X> GraphToEps<NodePsTextsTraits<X> > nodePsTexts(const X &x) |
| 417 | 417 |
{
|
| 418 | 418 |
dontPrint=true; |
| 419 | 419 |
_showNodePsText=true; |
| 420 | 420 |
return GraphToEps<NodePsTextsTraits<X> >(NodePsTextsTraits<X>(*this,x)); |
| 421 | 421 |
} |
| 422 | 422 |
template<class X> struct ArcWidthsTraits : public T {
|
| 423 | 423 |
const X &_arcWidths; |
| 424 | 424 |
ArcWidthsTraits(const T &t,const X &x) : T(t), _arcWidths(x) {}
|
| 425 | 425 |
}; |
| 426 | 426 |
///Sets the map of the arc widths |
| 427 | 427 |
|
| 428 | 428 |
///Sets the map of the arc widths |
| 429 | 429 |
///\param x must be a arc map with \c double (or convertible) values. |
| 430 | 430 |
template<class X> GraphToEps<ArcWidthsTraits<X> > arcWidths(const X &x) |
| 431 | 431 |
{
|
| 432 | 432 |
dontPrint=true; |
| 433 | 433 |
return GraphToEps<ArcWidthsTraits<X> >(ArcWidthsTraits<X>(*this,x)); |
| 434 | 434 |
} |
| 435 | 435 |
|
| 436 | 436 |
template<class X> struct NodeColorsTraits : public T {
|
| 437 | 437 |
const X &_nodeColors; |
| 438 | 438 |
NodeColorsTraits(const T &t,const X &x) : T(t), _nodeColors(x) {}
|
| 439 | 439 |
}; |
| 440 | 440 |
///Sets the map of the node colors |
| 441 | 441 |
|
| 442 | 442 |
///Sets the map of the node colors |
| 443 | 443 |
///\param x must be a node map with \ref Color values. |
| 444 | 444 |
/// |
| 445 | 445 |
///\sa Palette |
| 446 | 446 |
template<class X> GraphToEps<NodeColorsTraits<X> > |
| 447 | 447 |
nodeColors(const X &x) |
| 448 | 448 |
{
|
| 449 | 449 |
dontPrint=true; |
| 450 | 450 |
return GraphToEps<NodeColorsTraits<X> >(NodeColorsTraits<X>(*this,x)); |
| 451 | 451 |
} |
| 452 | 452 |
template<class X> struct NodeTextColorsTraits : public T {
|
| 453 | 453 |
const X &_nodeTextColors; |
| 454 | 454 |
NodeTextColorsTraits(const T &t,const X &x) : T(t), _nodeTextColors(x) {}
|
| 455 | 455 |
}; |
| 456 | 456 |
///Sets the map of the node text colors |
| 457 | 457 |
|
| 458 | 458 |
///Sets the map of the node text colors |
| 459 | 459 |
///\param x must be a node map with \ref Color values. |
| 460 | 460 |
/// |
| 461 | 461 |
///\sa Palette |
| 462 | 462 |
template<class X> GraphToEps<NodeTextColorsTraits<X> > |
| 463 | 463 |
nodeTextColors(const X &x) |
| 464 | 464 |
{
|
| 465 | 465 |
dontPrint=true; |
| 466 | 466 |
_nodeTextColorType=CUST_COL; |
| 467 | 467 |
return GraphToEps<NodeTextColorsTraits<X> > |
| 468 | 468 |
(NodeTextColorsTraits<X>(*this,x)); |
| 469 | 469 |
} |
| 470 | 470 |
template<class X> struct ArcColorsTraits : public T {
|
| 471 | 471 |
const X &_arcColors; |
| 472 | 472 |
ArcColorsTraits(const T &t,const X &x) : T(t), _arcColors(x) {}
|
| 473 | 473 |
}; |
| 474 | 474 |
///Sets the map of the arc colors |
| 475 | 475 |
|
| 476 | 476 |
///Sets the map of the arc colors |
| 477 | 477 |
///\param x must be a arc map with \ref Color values. |
| 478 | 478 |
/// |
| 479 | 479 |
///\sa Palette |
| 480 | 480 |
template<class X> GraphToEps<ArcColorsTraits<X> > |
| 481 | 481 |
arcColors(const X &x) |
| 482 | 482 |
{
|
| 483 | 483 |
dontPrint=true; |
| 484 | 484 |
return GraphToEps<ArcColorsTraits<X> >(ArcColorsTraits<X>(*this,x)); |
| 485 | 485 |
} |
| 486 | 486 |
///Sets a global scale factor for node sizes |
| 487 | 487 |
|
| 488 | 488 |
///Sets a global scale factor for node sizes. |
| 489 | 489 |
/// |
| 490 | 490 |
/// If nodeSizes() is not given, this function simply sets the node |
| 491 | 491 |
/// sizes to \c d. If nodeSizes() is given, but |
| 492 | 492 |
/// autoNodeScale() is not, then the node size given by |
| 493 | 493 |
/// nodeSizes() will be multiplied by the value \c d. |
| 494 | 494 |
/// If both nodeSizes() and autoNodeScale() are used, then the |
| 495 | 495 |
/// node sizes will be scaled in such a way that the greatest size will be |
| 496 | 496 |
/// equal to \c d. |
| 497 | 497 |
/// \sa nodeSizes() |
| 498 | 498 |
/// \sa autoNodeScale() |
| 499 |
GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
|
|
| 499 |
GraphToEps<T> &nodeScale(double d=.01) {_nodeScale=d;return *this;}
|
|
| 500 | 500 |
///Turns on/off the automatic node width scaling. |
| 501 | 501 |
|
| 502 | 502 |
///Turns on/off the automatic node width scaling. |
| 503 | 503 |
/// |
| 504 | 504 |
///\sa nodeScale() |
| 505 | 505 |
/// |
| 506 | 506 |
GraphToEps<T> &autoNodeScale(bool b=true) {
|
| 507 | 507 |
_autoNodeScale=b;return *this; |
| 508 | 508 |
} |
| 509 | 509 |
|
| 510 | 510 |
///Turns on/off the absolutematic node width scaling. |
| 511 | 511 |
|
| 512 | 512 |
///Turns on/off the absolutematic node width scaling. |
| 513 | 513 |
/// |
| 514 | 514 |
///\sa nodeScale() |
| 515 | 515 |
/// |
| 516 | 516 |
GraphToEps<T> &absoluteNodeSizes(bool b=true) {
|
| 517 | 517 |
_absoluteNodeSizes=b;return *this; |
| 518 | 518 |
} |
| 519 | 519 |
|
| 520 | 520 |
///Negates the Y coordinates. |
| 521 | 521 |
|
| 522 | 522 |
///Negates the Y coordinates. |
| 523 | 523 |
/// |
| 524 | 524 |
///\todo More docs. |
| 525 | 525 |
/// |
| 526 | 526 |
GraphToEps<T> &negateY(bool b=true) {
|
| 527 | 527 |
_negY=b;return *this; |
| 528 | 528 |
} |
| 529 | 529 |
|
| 530 | 530 |
///Turn on/off prescaling |
| 531 | 531 |
|
| 532 | 532 |
///By default graphToEps() rescales the whole image in order to avoid |
| 533 | 533 |
///very big or very small bounding boxes. |
| 534 | 534 |
/// |
| 535 | 535 |
///This (p)rescaling can be turned off with this function. |
| 536 | 536 |
/// |
| 537 | 537 |
GraphToEps<T> &preScale(bool b=true) {
|
| 538 | 538 |
_preScale=b;return *this; |
| 539 | 539 |
} |
| 540 | 540 |
|
| 541 | 541 |
///Sets a global scale factor for arc widths |
| 542 | 542 |
|
| 543 | 543 |
/// Sets a global scale factor for arc widths. |
| 544 | 544 |
/// |
| 545 | 545 |
/// If arcWidths() is not given, this function simply sets the arc |
| 546 | 546 |
/// widths to \c d. If arcWidths() is given, but |
| 547 | 547 |
/// autoArcWidthScale() is not, then the arc withs given by |
| 548 | 548 |
/// arcWidths() will be multiplied by the value \c d. |
| 549 | 549 |
/// If both arcWidths() and autoArcWidthScale() are used, then the |
| 550 | 550 |
/// arc withs will be scaled in such a way that the greatest width will be |
| 551 | 551 |
/// equal to \c d. |
| 552 |
GraphToEps<T> &arcWidthScale(double d) {_arcWidthScale=d;return *this;}
|
|
| 552 |
GraphToEps<T> &arcWidthScale(double d=.003) {_arcWidthScale=d;return *this;}
|
|
| 553 | 553 |
///Turns on/off the automatic arc width scaling. |
| 554 | 554 |
|
| 555 | 555 |
///Turns on/off the automatic arc width scaling. |
| 556 | 556 |
/// |
| 557 | 557 |
///\sa arcWidthScale() |
| 558 | 558 |
/// |
| 559 | 559 |
GraphToEps<T> &autoArcWidthScale(bool b=true) {
|
| 560 | 560 |
_autoArcWidthScale=b;return *this; |
| 561 | 561 |
} |
| 562 | 562 |
///Turns on/off the absolutematic arc width scaling. |
| 563 | 563 |
|
| 564 | 564 |
///Turns on/off the absolutematic arc width scaling. |
| 565 | 565 |
/// |
| 566 | 566 |
///\sa arcWidthScale() |
| 567 | 567 |
/// |
| 568 | 568 |
GraphToEps<T> &absoluteArcWidths(bool b=true) {
|
| 569 | 569 |
_absoluteArcWidths=b;return *this; |
| 570 | 570 |
} |
| 571 | 571 |
///Sets a global scale factor for the whole picture |
| 572 | 572 |
|
| 573 | 573 |
///Sets a global scale factor for the whole picture |
| 574 | 574 |
/// |
| 575 | 575 |
|
| 576 | 576 |
GraphToEps<T> &scale(double d) {_scale=d;return *this;}
|
| 577 | 577 |
///Sets the width of the border around the picture |
| 578 | 578 |
|
| 579 | 579 |
///Sets the width of the border around the picture |
| 580 | 580 |
/// |
| 581 | 581 |
GraphToEps<T> &border(double b) {_xBorder=_yBorder=b;return *this;}
|
| 582 | 582 |
///Sets the width of the border around the picture |
| 583 | 583 |
|
| 584 | 584 |
///Sets the width of the border around the picture |
| 585 | 585 |
/// |
| 586 | 586 |
GraphToEps<T> &border(double x, double y) {
|
| 587 | 587 |
_xBorder=x;_yBorder=y;return *this; |
| 588 | 588 |
} |
| 589 | 589 |
///Sets whether to draw arrows |
| 590 | 590 |
|
| 591 | 591 |
///Sets whether to draw arrows |
| 592 | 592 |
/// |
| 593 | 593 |
GraphToEps<T> &drawArrows(bool b=true) {_drawArrows=b;return *this;}
|
| 594 | 594 |
///Sets the length of the arrowheads |
| 595 | 595 |
|
| 596 | 596 |
///Sets the length of the arrowheads |
| 597 | 597 |
/// |
| 598 | 598 |
GraphToEps<T> &arrowLength(double d) {_arrowLength*=d;return *this;}
|
| 599 | 599 |
///Sets the width of the arrowheads |
| 600 | 600 |
|
| 601 | 601 |
///Sets the width of the arrowheads |
| 602 | 602 |
/// |
| 603 | 603 |
GraphToEps<T> &arrowWidth(double d) {_arrowWidth*=d;return *this;}
|
| 604 | 604 |
|
| 605 | 605 |
///Scales the drawing to fit to A4 page |
| 606 | 606 |
|
| 607 | 607 |
///Scales the drawing to fit to A4 page |
| 608 | 608 |
/// |
| 609 | 609 |
GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
|
| 610 | 610 |
|
| 611 | 611 |
///Enables parallel arcs |
| 612 | 612 |
|
| 613 | 613 |
///Enables parallel arcs |
| 614 | 614 |
GraphToEps<T> &enableParallel(bool b=true) {_enableParallel=b;return *this;}
|
| 615 | 615 |
|
| 616 | 616 |
///Sets the distance |
| 617 | 617 |
|
| 618 | 618 |
///Sets the distance |
| 619 | 619 |
/// |
| 620 | 620 |
GraphToEps<T> &parArcDist(double d) {_parArcDist*=d;return *this;}
|
| 621 | 621 |
|
| 622 | 622 |
///Hides the arcs |
| 623 | 623 |
|
| 624 | 624 |
///Hides the arcs |
| 625 | 625 |
/// |
| 626 | 626 |
GraphToEps<T> &hideArcs(bool b=true) {_showArcs=!b;return *this;}
|
| 627 | 627 |
///Hides the nodes |
| 628 | 628 |
|
| 629 | 629 |
///Hides the nodes |
| 630 | 630 |
/// |
| 631 | 631 |
GraphToEps<T> &hideNodes(bool b=true) {_showNodes=!b;return *this;}
|
| 632 | 632 |
|
| 633 | 633 |
///Sets the size of the node texts |
| 634 | 634 |
|
| 635 | 635 |
///Sets the size of the node texts |
| 636 | 636 |
/// |
| 637 | 637 |
GraphToEps<T> &nodeTextSize(double d) {_nodeTextSize=d;return *this;}
|
| 638 | 638 |
|
| 639 | 639 |
///Sets the color of the node texts to be different from the node color |
| 640 | 640 |
|
| 641 | 641 |
///Sets the color of the node texts to be as different from the node color |
| 642 | 642 |
///as it is possible |
| 643 | 643 |
/// |
| 644 | 644 |
GraphToEps<T> &distantColorNodeTexts() |
| 645 | 645 |
{_nodeTextColorType=DIST_COL;return *this;}
|
| 646 | 646 |
///Sets the color of the node texts to be black or white and always visible. |
| 647 | 647 |
|
| 648 | 648 |
///Sets the color of the node texts to be black or white according to |
| 649 | 649 |
///which is more |
| 650 | 650 |
///different from the node color |
| 651 | 651 |
/// |
| 652 | 652 |
GraphToEps<T> &distantBWNodeTexts() |
| 653 | 653 |
{_nodeTextColorType=DIST_BW;return *this;}
|
| 654 | 654 |
|
| 655 | 655 |
///Gives a preamble block for node Postscript block. |
| 656 | 656 |
|
| 657 | 657 |
///Gives a preamble block for node Postscript block. |
| 658 | 658 |
/// |
| 659 | 659 |
///\sa nodePsTexts() |
| 660 | 660 |
GraphToEps<T> & nodePsTextsPreamble(const char *str) {
|
| 661 | 661 |
_nodePsTextsPreamble=str ;return *this; |
| 662 | 662 |
} |
| 663 | 663 |
///Sets whether the the graph is undirected |
| 664 | 664 |
|
| 665 | 665 |
///Sets whether the the graph is undirected |
| 666 | 666 |
/// |
| 667 | 667 |
GraphToEps<T> &undirected(bool b=true) {_undirected=b;return *this;}
|
| 668 | 668 |
|
| 669 | 669 |
///Sets whether the the graph is directed |
| 670 | 670 |
|
| 671 | 671 |
///Sets whether the the graph is directed. |
| 672 | 672 |
///Use it to show the edges as a pair of directed ones. |
| 673 | 673 |
GraphToEps<T> &directed(bool b=true) {_undirected=!b;return *this;}
|
| 674 | 674 |
|
| 675 | 675 |
///Sets the title. |
| 676 | 676 |
|
| 677 | 677 |
///Sets the title of the generated image, |
| 678 | 678 |
///namely it inserts a <tt>%%Title:</tt> DSC field to the header of |
| 679 | 679 |
///the EPS file. |
| 680 | 680 |
GraphToEps<T> &title(const std::string &t) {_title=t;return *this;}
|
| 681 | 681 |
///Sets the copyright statement. |
| 682 | 682 |
|
| 683 | 683 |
///Sets the copyright statement of the generated image, |
| 684 | 684 |
///namely it inserts a <tt>%%Copyright:</tt> DSC field to the header of |
| 685 | 685 |
///the EPS file. |
| 686 | 686 |
///\todo Multiline copyright notice could be supported. |
| 687 | 687 |
GraphToEps<T> ©right(const std::string &t) {_copyright=t;return *this;}
|
| 688 | 688 |
|
| 689 | 689 |
protected: |
| 690 | 690 |
bool isInsideNode(dim2::Point<double> p, double r,int t) |
| 691 | 691 |
{
|
| 692 | 692 |
switch(t) {
|
| 693 | 693 |
case CIRCLE: |
| 694 | 694 |
case MALE: |
| 695 | 695 |
case FEMALE: |
| 696 | 696 |
return p.normSquare()<=r*r; |
| 697 | 697 |
case SQUARE: |
| 698 | 698 |
return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r; |
| 699 | 699 |
case DIAMOND: |
| 700 | 700 |
return p.x+p.y<=r && p.x-p.y<=r && -p.x+p.y<=r && -p.x-p.y<=r; |
| 701 | 701 |
} |
| 702 | 702 |
return false; |
| 703 | 703 |
} |
| 704 | 704 |
|
| 705 | 705 |
public: |
| 706 | 706 |
~GraphToEps() { }
|
| 707 | 707 |
|
| 708 | 708 |
///Draws the graph. |
| 709 | 709 |
|
| 710 | 710 |
///Like other functions using |
| 711 | 711 |
///\ref named-templ-func-param "named template parameters", |
| 712 | 712 |
///this function calles the algorithm itself, i.e. in this case |
| 713 | 713 |
///it draws the graph. |
| 714 | 714 |
void run() {
|
| 715 | 715 |
///\todo better 'epsilon' would be nice here. |
| 716 | 716 |
const double EPSILON=1e-9; |
| 717 | 717 |
if(dontPrint) return; |
| 718 | 718 |
|
| 719 | 719 |
_graph_to_eps_bits::_NegY<typename T::CoordsMapType> |
| 720 | 720 |
mycoords(_coords,_negY); |
| 721 | 721 |
|
| 722 | 722 |
os << "%!PS-Adobe-2.0 EPSF-2.0\n"; |
| 723 | 723 |
if(_title.size()>0) os << "%%Title: " << _title << '\n'; |
| 724 | 724 |
if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n'; |
| 725 | 725 |
// << "%%Copyright: XXXX\n" |
| 726 | 726 |
os << "%%Creator: LEMON, graphToEps()\n"; |
| 727 | 727 |
|
| 728 | 728 |
{
|
| 729 | 729 |
char cbuf[50]; |
| 730 | 730 |
timeval tv; |
| 731 | 731 |
gettimeofday(&tv, 0); |
| 732 | 732 |
ctime_r(&tv.tv_sec,cbuf); |
| 733 | 733 |
os << "%%CreationDate: " << cbuf; |
| 734 | 734 |
} |
| 735 | 735 |
|
| 736 | 736 |
if (_autoArcWidthScale) {
|
| 737 | 737 |
double max_w=0; |
| 738 | 738 |
for(ArcIt e(g);e!=INVALID;++e) |
| 739 | 739 |
max_w=std::max(double(_arcWidths[e]),max_w); |
| 740 | 740 |
///\todo better 'epsilon' would be nice here. |
| 741 | 741 |
if(max_w>EPSILON) {
|
| 742 | 742 |
_arcWidthScale/=max_w; |
| 743 | 743 |
} |
| 744 | 744 |
} |
0 comments (0 inline)