[Lemon-commits] [lemon_svn] alpar: r1445 - hugo/trunk/src/work/alpar
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:45:30 CET 2006
Author: alpar
Date: Wed Jan 5 11:14:37 2005
New Revision: 1445
Modified:
hugo/trunk/src/work/alpar/graph_to_eps.cc
Log:
graphToEps is now able to write to any ostream.
Modified: hugo/trunk/src/work/alpar/graph_to_eps.cc
==============================================================================
--- hugo/trunk/src/work/alpar/graph_to_eps.cc (original)
+++ hugo/trunk/src/work/alpar/graph_to_eps.cc Wed Jan 5 11:14:37 2005
@@ -1,4 +1,6 @@
+#include <iostream>
#include<math.h>
+
#include<lemon/xy.h>
#include<lemon/maps.h>
#include<lemon/list_graph.h>
@@ -49,6 +51,9 @@
const Graph &g;
+
+ std::ostream& os;
+
ConstMap<typename Graph::Node,xy<double> > _coords;
ConstMap<typename Graph::Node,double > _nodeSizes;
@@ -70,9 +75,12 @@
///Constructor
///Constructor
- ///\param _g is a reference to the underlying graph
- DefaultGraphToEpsTraits(const G &_g) :
- g(_g), _coords(xy<double>(1,1)), _nodeSizes(1.0),
+ ///\param _g is a reference to the graph to be printed
+ ///\param _os is a reference to the output stream.
+ ///By default it is <tt>std::cout</tt>
+ DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout) :
+ g(_g), os(_os),
+ _coords(xy<double>(1,1)), _nodeSizes(1.0),
_nodeColors(Color(1,1,1)), _edgeColors(Color(0,0,0)),
_edgeWidths(1), _edgeWidthScale(0.3),
_nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
@@ -214,7 +222,7 @@
{
if(dontPrint) return;
- cout << "%!PS-Adobe-2.0 EPSF-2.0\n";
+ os << "%!PS-Adobe-2.0 EPSF-2.0\n";
//\todo: Chech whether the graph is empty.
BoundingBox<double> bb;
for(NodeIt n(g);n!=INVALID;++n) {
@@ -223,26 +231,26 @@
bb+=p+_coords[n];
bb+=-p+_coords[n];
}
- cout << "%%BoundingBox: "
+ os << "%%BoundingBox: "
<< bb.left()* _scale-_xBorder << ' '
<< bb.bottom()*_scale-_yBorder << ' '
<< bb.right()* _scale+_xBorder << ' '
<< bb.top()* _scale+_yBorder << '\n';
//x1 y1 x2 y2 cr cg cb w
- cout << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n";
- cout << "/c { newpath dup 3 index add 2 index moveto 0 360 arc } bind def\n";
+ os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n";
+ os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc } bind def\n";
// x y r cr cg cb
- cout << "/n { setrgbcolor 2 index 2 index 2 index c fill\n"
+ os << "/n { setrgbcolor 2 index 2 index 2 index c fill\n"
<< " 0 0 0 setrgbcolor dup "
<< _nodeBorderQuotient << " mul setlinewidth "
<< 1+_nodeBorderQuotient/2 << " div c stroke\n"
<< " } bind def\n";
- cout << "/arrl " << _arrowLength << " def\n";
- cout << "/arrw " << _arrowWidth << " def\n";
+ os << "/arrl " << _arrowLength << " def\n";
+ os << "/arrw " << _arrowWidth << " def\n";
// l dx_norm dy_norm
- cout << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
+ os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
//len w dx_norm dy_norm x1 y1 cr cg cb
- cout << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n"
+ os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n"
<< " /w exch def /len exch def\n"
// << " 0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke"
<< " newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto\n"
@@ -255,9 +263,9 @@
<< " arrw dy dx neg lrl\n"
<< " len w sub arrl sub neg dx dy lrl\n"
<< " closepath fill } bind def\n";
- cout << "\ngsave\n";
- if(_scale!=1.0) cout << _scale << " dup scale\n";
- cout << "%Edges:\ngsave\n";
+ os << "\ngsave\n";
+ if(_scale!=1.0) os << _scale << " dup scale\n";
+ os << "%Edges:\ngsave\n";
for(NodeIt n(g);n!=INVALID;++n)
for(OutEdgeIt e(g,n);e!=INVALID;++e)
if(_drawArrows) {
@@ -266,7 +274,7 @@
d/=l;
xy<double> x1(d*_nodeScale*_nodeSizes[g.source(e)]+
_coords[g.source(e)]);
- cout << l-(_nodeSizes[g.source(e)]+
+ os << l-(_nodeSizes[g.source(e)]+
_nodeSizes[g.target(e)])*_nodeScale << ' '
<< _edgeWidths[e]*_edgeWidthScale << ' '
<< d.x << ' ' << d.y << ' '
@@ -275,7 +283,7 @@
<< _edgeColors[e].getG() << ' '
<< _edgeColors[e].getB() << " arr\n";
}
- else cout << _coords[g.source(e)].x << ' '
+ else os << _coords[g.source(e)].x << ' '
<< _coords[g.source(e)].y << ' '
<< _coords[g.target(e)].x << ' '
<< _coords[g.target(e)].y << ' '
@@ -283,14 +291,14 @@
<< _edgeColors[e].getG() << ' '
<< _edgeColors[e].getB() << ' '
<< _edgeWidths[e]*_edgeWidthScale << " l\n";
- cout << "grestore\n%Nodes:\ngsave\n";
+ os << "grestore\n%Nodes:\ngsave\n";
for(NodeIt n(g);n!=INVALID;++n)
- cout << _coords[n].x << ' ' << _coords[n].y << ' '
+ os << _coords[n].x << ' ' << _coords[n].y << ' '
<< _nodeSizes[n]*_nodeScale << ' '
<< _nodeColors[n].getR() << ' '
<< _nodeColors[n].getG() << ' '
<< _nodeColors[n].getB() << " n\n";
- cout << "grestore\ngrestore\n";
+ os << "grestore\ngrestore\n";
}
};
@@ -299,8 +307,11 @@
///\ingroup misc
///Generates an EPS file from a graph.
+///\param g is a reference to the graph to be printed
+///\param os is a reference to the output stream.
+///By default it is <tt>std::cout</tt>
///
-///This function has a lot of \ref named-templ-param "named parameters",
+///This function also has a lot of \ref named-templ-param "named parameters",
///they are declared as the members of class \ref GraphToEps. The following
///example shows how to use these parameters.
///\code
@@ -310,7 +321,7 @@
///\endcode
///\sa GraphToEps
template<class G>
-GraphToEps<DefaultGraphToEpsTraits<G> > graphToEps(G &g)
+GraphToEps<DefaultGraphToEpsTraits<G> > graphToEps(G &g,std::ostream& os=std::cout)
{
return GraphToEps<DefaultGraphToEpsTraits<G> >(DefaultGraphToEpsTraits<G>(g));
}
More information about the Lemon-commits
mailing list