Changeset 1051:4ebe32765b48 in lemon-0.x for src/work/alpar/graph_to_eps.cc
- Timestamp:
- 01/05/05 11:14:37 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1445
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/alpar/graph_to_eps.cc
r1050 r1051 1 #include <iostream> 1 2 #include<math.h> 3 2 4 #include<lemon/xy.h> 3 5 #include<lemon/maps.h> … … 50 52 51 53 const Graph &g; 54 55 std::ostream& os; 56 52 57 ConstMap<typename Graph::Node,xy<double> > _coords; 53 58 ConstMap<typename Graph::Node,double > _nodeSizes; … … 71 76 72 77 ///Constructor 73 ///\param _g is a reference to the underlying graph 74 DefaultGraphToEpsTraits(const G &_g) : 75 g(_g), _coords(xy<double>(1,1)), _nodeSizes(1.0), 78 ///\param _g is a reference to the graph to be printed 79 ///\param _os is a reference to the output stream. 80 ///By default it is <tt>std::cout</tt> 81 DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout) : 82 g(_g), os(_os), 83 _coords(xy<double>(1,1)), _nodeSizes(1.0), 76 84 _nodeColors(Color(1,1,1)), _edgeColors(Color(0,0,0)), 77 85 _edgeWidths(1), _edgeWidthScale(0.3), … … 215 223 if(dontPrint) return; 216 224 217 cout<< "%!PS-Adobe-2.0 EPSF-2.0\n";225 os << "%!PS-Adobe-2.0 EPSF-2.0\n"; 218 226 //\todo: Chech whether the graph is empty. 219 227 BoundingBox<double> bb; … … 224 232 bb+=-p+_coords[n]; 225 233 } 226 cout<< "%%BoundingBox: "234 os << "%%BoundingBox: " 227 235 << bb.left()* _scale-_xBorder << ' ' 228 236 << bb.bottom()*_scale-_yBorder << ' ' … … 230 238 << bb.top()* _scale+_yBorder << '\n'; 231 239 //x1 y1 x2 y2 cr cg cb w 232 cout<< "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n";233 cout<< "/c { newpath dup 3 index add 2 index moveto 0 360 arc } bind def\n";240 os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def\n"; 241 os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc } bind def\n"; 234 242 // x y r cr cg cb 235 cout<< "/n { setrgbcolor 2 index 2 index 2 index c fill\n"243 os << "/n { setrgbcolor 2 index 2 index 2 index c fill\n" 236 244 << " 0 0 0 setrgbcolor dup " 237 245 << _nodeBorderQuotient << " mul setlinewidth " 238 246 << 1+_nodeBorderQuotient/2 << " div c stroke\n" 239 247 << " } bind def\n"; 240 cout<< "/arrl " << _arrowLength << " def\n";241 cout<< "/arrw " << _arrowWidth << " def\n";248 os << "/arrl " << _arrowLength << " def\n"; 249 os << "/arrw " << _arrowWidth << " def\n"; 242 250 // l dx_norm dy_norm 243 cout<< "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";251 os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n"; 244 252 //len w dx_norm dy_norm x1 y1 cr cg cb 245 cout<< "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n"253 os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n" 246 254 << " /w exch def /len exch def\n" 247 255 // << " 0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke" … … 256 264 << " len w sub arrl sub neg dx dy lrl\n" 257 265 << " closepath fill } bind def\n"; 258 cout<< "\ngsave\n";259 if(_scale!=1.0) cout<< _scale << " dup scale\n";260 cout<< "%Edges:\ngsave\n";266 os << "\ngsave\n"; 267 if(_scale!=1.0) os << _scale << " dup scale\n"; 268 os << "%Edges:\ngsave\n"; 261 269 for(NodeIt n(g);n!=INVALID;++n) 262 270 for(OutEdgeIt e(g,n);e!=INVALID;++e) … … 267 275 xy<double> x1(d*_nodeScale*_nodeSizes[g.source(e)]+ 268 276 _coords[g.source(e)]); 269 cout<< l-(_nodeSizes[g.source(e)]+277 os << l-(_nodeSizes[g.source(e)]+ 270 278 _nodeSizes[g.target(e)])*_nodeScale << ' ' 271 279 << _edgeWidths[e]*_edgeWidthScale << ' ' … … 276 284 << _edgeColors[e].getB() << " arr\n"; 277 285 } 278 else cout<< _coords[g.source(e)].x << ' '286 else os << _coords[g.source(e)].x << ' ' 279 287 << _coords[g.source(e)].y << ' ' 280 288 << _coords[g.target(e)].x << ' ' … … 284 292 << _edgeColors[e].getB() << ' ' 285 293 << _edgeWidths[e]*_edgeWidthScale << " l\n"; 286 cout<< "grestore\n%Nodes:\ngsave\n";294 os << "grestore\n%Nodes:\ngsave\n"; 287 295 for(NodeIt n(g);n!=INVALID;++n) 288 cout<< _coords[n].x << ' ' << _coords[n].y << ' '296 os << _coords[n].x << ' ' << _coords[n].y << ' ' 289 297 << _nodeSizes[n]*_nodeScale << ' ' 290 298 << _nodeColors[n].getR() << ' ' 291 299 << _nodeColors[n].getG() << ' ' 292 300 << _nodeColors[n].getB() << " n\n"; 293 cout<< "grestore\ngrestore\n";301 os << "grestore\ngrestore\n"; 294 302 } 295 303 }; … … 300 308 ///\ingroup misc 301 309 ///Generates an EPS file from a graph. 310 ///\param g is a reference to the graph to be printed 311 ///\param os is a reference to the output stream. 312 ///By default it is <tt>std::cout</tt> 302 313 /// 303 ///This function has a lot of \ref named-templ-param "named parameters",314 ///This function also has a lot of \ref named-templ-param "named parameters", 304 315 ///they are declared as the members of class \ref GraphToEps. The following 305 316 ///example shows how to use these parameters. … … 311 322 ///\sa GraphToEps 312 323 template<class G> 313 GraphToEps<DefaultGraphToEpsTraits<G> > graphToEps(G &g )324 GraphToEps<DefaultGraphToEpsTraits<G> > graphToEps(G &g,std::ostream& os=std::cout) 314 325 { 315 326 return GraphToEps<DefaultGraphToEpsTraits<G> >(DefaultGraphToEpsTraits<G>(g));
Note: See TracChangeset
for help on using the changeset viewer.