- RGB color related stuff is in color.h now
authoralpar
Mon, 20 Feb 2006 06:41:12 +0000
changeset 19719a59a6cacfd9
parent 1970 bd88ea06ab69
child 1972 487a868e30e5
- RGB color related stuff is in color.h now
- eps.h: A simple class to create .eps figures (demo: eps_demo.h)
demo/Makefile.am
demo/eps_demo.cc
lemon/Makefile.am
lemon/color.h
lemon/eps.cc
lemon/eps.h
lemon/graph_to_eps.h
     1.1 --- a/demo/Makefile.am	Mon Feb 20 06:38:18 2006 +0000
     1.2 +++ b/demo/Makefile.am	Mon Feb 20 06:41:12 2006 +0000
     1.3 @@ -8,6 +8,7 @@
     1.4  	dijkstra_demo \
     1.5  	reader_writer_demo \
     1.6  	dim_to_lgf \
     1.7 +	eps_demo \
     1.8  	graph_to_eps_demo \
     1.9  	graph_orientation \
    1.10  	min_route \
    1.11 @@ -32,6 +33,8 @@
    1.12  
    1.13  dijkstra_demo_SOURCES = dijkstra_demo.cc
    1.14  
    1.15 +eps_demo_SOURCES = eps_demo.cc
    1.16 +
    1.17  reader_writer_demo_SOURCES = reader_writer_demo.cc
    1.18  
    1.19  dim_to_lgf_SOURCES = dim_to_lgf.cc
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/demo/eps_demo.cc	Mon Feb 20 06:41:12 2006 +0000
     2.3 @@ -0,0 +1,110 @@
     2.4 +/* -*- C++ -*-
     2.5 + *
     2.6 + * This file is a part of LEMON, a generic C++ optimization library
     2.7 + *
     2.8 + * Copyright (C) 2003-2006
     2.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    2.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    2.11 + *
    2.12 + * Permission to use, modify and distribute this software is granted
    2.13 + * provided that this copyright notice appears in all copies. For
    2.14 + * precise terms see the accompanying LICENSE file.
    2.15 + *
    2.16 + * This software is provided "AS IS" with no warranty of any kind,
    2.17 + * express or implied, and with no claim as to its suitability for any
    2.18 + * purpose.
    2.19 + *
    2.20 + */
    2.21 +
    2.22 +/// \ingroup demos
    2.23 +/// \file
    2.24 +/// \brief Demo of the EPS grawing class \ref EpsDrawer()
    2.25 +///
    2.26 +/// This demo program shows examples how to use the class \ref
    2.27 +/// EpsDrawer(). It takes no input but simply creates a file
    2.28 +/// <tt>eps_demo.eps</tt> demonstrating the capability of \ref
    2.29 +/// EpsDrawer().
    2.30 +///
    2.31 +/// \include eps_demo.cc
    2.32 +
    2.33 +#include <cmath>
    2.34 +#include <lemon/eps.h>
    2.35 +
    2.36 +using namespace lemon;
    2.37 +
    2.38 +void kosar(EpsDrawer &ed)
    2.39 +{
    2.40 +  double d,r;
    2.41 +  
    2.42 +  r = sqrt(2);
    2.43 +  
    2.44 +  ed.save();
    2.45 +  
    2.46 +  ed.translate(256,256).scale(256,256);
    2.47 +  ed.lineWidth(1/256);
    2.48 +  
    2.49 +  ed.collect();
    2.50 +  
    2.51 +  ed.moveTo(0,1);
    2.52 +  
    2.53 +  for(d=0;d<M_PI*2*5;d+=.1)
    2.54 +    {
    2.55 +      ed.lineTo(sin(d*3),cos(d*5));
    2.56 +    }
    2.57 +  
    2.58 +  ed.stroke();
    2.59 +  ed.restore();
    2.60 +  
    2.61 +}
    2.62 +
    2.63 +void fonts(EpsDrawer &ed)
    2.64 +{
    2.65 +  ed.save().centerMode(true);
    2.66 +  
    2.67 +  ed.font("Helvetica").fontSize(90);
    2.68 +  ed.moveTo(256,512/3*2+50) << "Helvetica";
    2.69 +  ed.font("Courier");
    2.70 +  ed.moveTo(256,512/3+50) << "Courier" ;
    2.71 +  ed.font("Times-Roman");
    2.72 +  ed.moveTo(256,50) << "Times-Roman";
    2.73 +  
    2.74 +  ed.centerMode(false).restore();
    2.75 +}
    2.76 +
    2.77 +int main()
    2.78 +{
    2.79 +
    2.80 +  EpsDrawer ed("eps_demo.eps",512,512);
    2.81 +  ed.scale(1,1);
    2.82 +  
    2.83 +  ed.color(0,0,0).collect();
    2.84 +  ed.moveTo(0,0).lineTo(0,512).lineTo(512,512).lineTo(512,0).closePath().fill();
    2.85 +  
    2.86 +  ed.lineWidth(4);
    2.87 +  
    2.88 +  for(double r=0;r<=256;r+=2)
    2.89 +    {
    2.90 +      ed.color(r/256.0,0,1-r/256.0).circle(256,256,r);
    2.91 +    }
    2.92 +  
    2.93 +  
    2.94 +  ed.save();
    2.95 +  ed.color(0,0,0);
    2.96 +  ed.translate(256,256);
    2.97 +  
    2.98 +  for(int i=0;i<18;i++)
    2.99 +    {
   2.100 +      ed.rotate(20);
   2.101 +      
   2.102 +      for(double r=0;r<=256;r+=20)
   2.103 +	ed.fontSize(r/10+1).rotate(2).moveTo(0,r) << r;
   2.104 +      ed.rotate(-26);
   2.105 +      
   2.106 +    }
   2.107 +  
   2.108 +  ed.restore();
   2.109 +  
   2.110 +  fonts(ed.color(.7,.7,.7));
   2.111 +  ed.color(0,1,0);
   2.112 +  kosar(ed);
   2.113 +}
     3.1 --- a/lemon/Makefile.am	Mon Feb 20 06:38:18 2006 +0000
     3.2 +++ b/lemon/Makefile.am	Mon Feb 20 06:41:12 2006 +0000
     3.3 @@ -8,7 +8,8 @@
     3.4  libemon_la_SOURCES = \
     3.5  	lp_base.cc \
     3.6  	lp_skeleton.cc \
     3.7 -	base.cc 
     3.8 +	base.cc \
     3.9 +	eps.cc 
    3.10  libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS)
    3.11  libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS)
    3.12  
    3.13 @@ -26,6 +27,7 @@
    3.14  	bfs.h \
    3.15  	dfs.h \
    3.16  	bin_heap.h \
    3.17 +	color.h \
    3.18  	config.h \
    3.19  	counter.h \
    3.20  	dijkstra.h \
    3.21 @@ -33,6 +35,7 @@
    3.22  	dag_shortest_path.h \
    3.23  	edge_set.h \
    3.24  	error.h \
    3.25 +	eps.h \
    3.26  	fib_heap.h \
    3.27  	floyd_warshall.h \
    3.28  	fredman_tarjan.h \
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/lemon/color.h	Mon Feb 20 06:41:12 2006 +0000
     4.3 @@ -0,0 +1,176 @@
     4.4 +/* -*- C++ -*-
     4.5 + *
     4.6 + * This file is a part of LEMON, a generic C++ optimization library
     4.7 + *
     4.8 + * Copyright (C) 2003-2006
     4.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    4.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    4.11 + *
    4.12 + * Permission to use, modify and distribute this software is granted
    4.13 + * provided that this copyright notice appears in all copies. For
    4.14 + * precise terms see the accompanying LICENSE file.
    4.15 + *
    4.16 + * This software is provided "AS IS" with no warranty of any kind,
    4.17 + * express or implied, and with no claim as to its suitability for any
    4.18 + * purpose.
    4.19 + *
    4.20 + */
    4.21 +
    4.22 +#ifndef LEMON_COLOR_H
    4.23 +#define LEMON_COLOR_H
    4.24 +
    4.25 +#include <sys/time.h>
    4.26 +
    4.27 +#include<iostream>
    4.28 +#include<fstream>
    4.29 +#include<sstream>
    4.30 +#include<algorithm>
    4.31 +#include<vector>
    4.32 +
    4.33 +#include <ctime>
    4.34 +#include <cmath>
    4.35 +
    4.36 +#include<lemon/invalid.h>
    4.37 +#include<lemon/xy.h>
    4.38 +#include<lemon/maps.h>
    4.39 +#include<lemon/bezier.h>
    4.40 +
    4.41 +
    4.42 +///\ingroup misc
    4.43 +///\file
    4.44 +///\brief Tools to manage RGB colors.
    4.45 +///
    4.46 +///\author Alpar Juttner
    4.47 +
    4.48 +namespace lemon {
    4.49 +
    4.50 +///Data structure representing RGB colors.
    4.51 +
    4.52 +///Data structure representing RGB colors.
    4.53 +///\ingroup misc
    4.54 +class Color
    4.55 +{
    4.56 +  double _r,_g,_b;
    4.57 +public:
    4.58 +  ///Default constructor
    4.59 +  Color() {}
    4.60 +  ///Constructor
    4.61 +  Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
    4.62 +  ///Returns the red component
    4.63 +  double & red() {return _r;}
    4.64 +  ///Returns the red component
    4.65 +  const double & red() const {return _r;}
    4.66 +  ///Returns the green component
    4.67 +  double & green() {return _g;}
    4.68 +  ///Returns the green component
    4.69 +  const double & green() const {return _g;}
    4.70 +  ///Returns the blue component
    4.71 +  double & blue() {return _b;}
    4.72 +  ///Returns the blue component
    4.73 +  const double & blue() const {return _b;}
    4.74 +  ///Set the color components
    4.75 +  void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
    4.76 +};
    4.77 +
    4.78 +///Maps <tt>int</tt>s to different \ref Color "Color"s
    4.79 +
    4.80 +///This map assigns one of the predefined \ref Color "Color"s
    4.81 +///to each <tt>int</tt>. It is possible to change the colors as well as their
    4.82 +///number. The integer range is cyclically mapped to the provided set of colors.
    4.83 +///
    4.84 +///This is a true \ref concept::ReferenceMap "reference map", so you can also
    4.85 +///change the actual colors.
    4.86 +
    4.87 +class ColorSet : public MapBase<int,Color>
    4.88 +{
    4.89 +  std::vector<Color> colors;
    4.90 +public:
    4.91 +  ///Constructor
    4.92 +
    4.93 +  ///Constructor
    4.94 +  ///\param have_white indicates whether white is
    4.95 +  ///amongst the provided color (\c true) or not (\c false). If it is true,
    4.96 +  ///white will be assigned to \c 0.
    4.97 +  ///\param num the number of the allocated colors. If it is \c 0
    4.98 +  ///the default color configuration is set up (26 color plus the while).
    4.99 +  ///If \c num is less then 26/27 then the default color list is cut. Otherwise
   4.100 +  ///the color list is filled repeatedly with the default color list.
   4.101 +  ///(The colors can be changed later on.)
   4.102 +  ColorSet(bool have_white=false,int num=0)
   4.103 +  {
   4.104 +    do {
   4.105 +      if(have_white) colors.push_back(Color(1,1,1));
   4.106 +
   4.107 +      colors.push_back(Color(0,0,0));
   4.108 +      colors.push_back(Color(1,0,0));
   4.109 +      colors.push_back(Color(0,1,0));
   4.110 +      colors.push_back(Color(0,0,1));
   4.111 +      colors.push_back(Color(1,1,0));
   4.112 +      colors.push_back(Color(1,0,1));
   4.113 +      colors.push_back(Color(0,1,1));
   4.114 +      
   4.115 +      colors.push_back(Color(.5,0,0));
   4.116 +      colors.push_back(Color(0,.5,0));
   4.117 +      colors.push_back(Color(0,0,.5));
   4.118 +      colors.push_back(Color(.5,.5,0));
   4.119 +      colors.push_back(Color(.5,0,.5));
   4.120 +      colors.push_back(Color(0,.5,.5));
   4.121 +      
   4.122 +      colors.push_back(Color(.5,.5,.5));
   4.123 +      colors.push_back(Color(1,.5,.5));
   4.124 +      colors.push_back(Color(.5,1,.5));
   4.125 +      colors.push_back(Color(.5,.5,1));
   4.126 +      colors.push_back(Color(1,1,.5));
   4.127 +      colors.push_back(Color(1,.5,1));
   4.128 +      colors.push_back(Color(.5,1,1));
   4.129 +      
   4.130 +      colors.push_back(Color(1,.5,0));
   4.131 +      colors.push_back(Color(.5,1,0));
   4.132 +      colors.push_back(Color(1,0,.5));
   4.133 +      colors.push_back(Color(0,1,.5));
   4.134 +      colors.push_back(Color(0,.5,1));
   4.135 +      colors.push_back(Color(.5,0,1));
   4.136 +    } while(int(colors.size())<num);
   4.137 +    //    colors.push_back(Color(1,1,1));
   4.138 +    if(num>0) colors.resize(num);
   4.139 +  }
   4.140 +  ///\e
   4.141 +  Color &operator[](int i)
   4.142 +  {
   4.143 +    return colors[i%colors.size()];
   4.144 +  }
   4.145 +  ///\e
   4.146 +  const Color &operator[](int i) const
   4.147 +  {
   4.148 +    return colors[i%colors.size()];
   4.149 +  }
   4.150 +  ///\e
   4.151 +  void set(int i,const Color &c)
   4.152 +  {
   4.153 +    colors[i%colors.size()]=c;
   4.154 +  }
   4.155 +  ///Sets the number of the exiting colors.
   4.156 +  void resize(int s) { colors.resize(s);}
   4.157 +  ///Returns the number of the existing colors.
   4.158 +  std::size_t size() const { return colors.size();}
   4.159 +};
   4.160 +
   4.161 +///Returns a visible distinct \ref Color
   4.162 +
   4.163 +///Returns a \ref Color which is as different from the given parameter
   4.164 +///as it is possible.
   4.165 +inline Color distantColor(const Color &c) 
   4.166 +{
   4.167 +  return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
   4.168 +}
   4.169 +///Returns black for light colors and white for the dark ones.
   4.170 +
   4.171 +///Returns black for light colors and white for the dark ones.
   4.172 +inline Color distantBW(const Color &c){
   4.173 +  double v=(.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5?1:0;
   4.174 +  return Color(v,v,v);
   4.175 +}
   4.176 +
   4.177 +} //END OF NAMESPACE LEMON
   4.178 +
   4.179 +#endif // LEMON_COLOR_H
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/lemon/eps.cc	Mon Feb 20 06:41:12 2006 +0000
     5.3 @@ -0,0 +1,301 @@
     5.4 +#include <eps.h>
     5.5 +
     5.6 +namespace lemon {
     5.7 +  
     5.8 +  void EpsDrawer::defMacros()
     5.9 +  {
    5.10 +    out << "/clmode true def\n" <<
    5.11 +      "/cshowmode false def\n" <<
    5.12 +      "/defont (Helvetica) findfont def\n" <<
    5.13 +      "/fosi 12 def\n" <<
    5.14 +      "\n" <<
    5.15 +      "/st { clmode { currentpoint stroke newpath moveto } if } bind def\n" <<
    5.16 +      "/str { currentpoint stroke newpath moveto /clmode true def } bind def\n"
    5.17 +	<<
    5.18 +      "/fl { currentpoint fill newpath moveto /clmode true def } bind def\n" <<
    5.19 +      "/eofl { currentpoint eofill newpath moveto /clmode true def } bind def\n"
    5.20 +	<<
    5.21 +      "/cl { currentpoint clip newpath moveto /clmode true def } bind def\n"
    5.22 +	<<
    5.23 +      "/eocl { currentpoint eoclip newpath moveto /clmode true def } bind def\n"
    5.24 +	<<
    5.25 +      "\n" <<
    5.26 +      "/l { moveto lineto st } bind def\n" <<
    5.27 +      "/lt { lineto st } bind def\n" <<
    5.28 +      "/mt { moveto } bind def\n" <<
    5.29 +      "/c { dup 3 index add 2 index moveto 0 360 arc st } bind def\n" <<
    5.30 +      "/collect { /clmode false def currentpoint newpath moveto } bind def\n" <<
    5.31 +      "\n" <<
    5.32 +      "/fontset { defont fosi scalefont setfont } bind def\n" <<
    5.33 +      "/stfs { /fosi exch def fontset } bind def\n" <<
    5.34 +      "/cshow { dup stringwidth pop\n" <<
    5.35 +      "   neg 2 div 0 rmoveto show } bind def\n" <<
    5.36 +      "/xshow { cshowmode { cshow } { show } ifelse } def\n" <<
    5.37 +      "\n" <<
    5.38 +      "fontset\n" <<
    5.39 +      "newpath\n" <<
    5.40 +      "0 0 moveto\n" <<
    5.41 +      "1 setlinecap\n";
    5.42 +  }
    5.43 +
    5.44 +  void EpsDrawer::init(int x1,int y1,int x2,int y2)
    5.45 +  {
    5.46 +    out << "%!PS-Adobe-2.0 EPSF-2.0\n" <<
    5.47 +      "%%BoundingBox: " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
    5.48 +      "\n%%EndComments\n";
    5.49 +    defMacros();
    5.50 +  }
    5.51 +
    5.52 +  void EpsDrawer::init(double x1,double y1,double x2,double y2)
    5.53 +  {
    5.54 +    out << "%!PS-Adobe-2.0\n" <<
    5.55 +      "%%HiResBoundingBox: " << 
    5.56 +      x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
    5.57 +      "\n%%EndComments\n";
    5.58 +    defMacros();
    5.59 +  }
    5.60 +
    5.61 +
    5.62 +  EpsDrawer::EpsDrawer(std::ostream &os,int x,int y) : local_stream(false),
    5.63 +						       out(os)
    5.64 +  {
    5.65 +    init(0,0,x,y);
    5.66 +  }
    5.67 +
    5.68 +  EpsDrawer::EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2) : 
    5.69 +    local_stream(false),
    5.70 +    out(os)
    5.71 +  {
    5.72 +    init(x1,y1,x2,y2);
    5.73 +  }
    5.74 +
    5.75 +  EpsDrawer::EpsDrawer(std::ostream &os,xy<double> s) : local_stream(false),
    5.76 +							out(os)
    5.77 +  {
    5.78 +    init(0.0,0.0,s.x,s.y);
    5.79 +  }
    5.80 +
    5.81 +  EpsDrawer::EpsDrawer(std::ostream &os,xy<double> a, xy<double> b) :
    5.82 +    local_stream(false),
    5.83 +    out(os)
    5.84 +  {
    5.85 +    init(a.x,a.y,b.x,b.y);
    5.86 +  }
    5.87 +
    5.88 +
    5.89 +  EpsDrawer::EpsDrawer(const std::string &name,int x,int y) :
    5.90 +    local_stream(true),
    5.91 +    out(*new std::ofstream(name.c_str()))
    5.92 +  {
    5.93 +    init(0,0,x,y);
    5.94 +  }
    5.95 +
    5.96 +  EpsDrawer::EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2) : 
    5.97 +    local_stream(true),
    5.98 +    out(*new std::ofstream(name.c_str()))
    5.99 +  {
   5.100 +    init(x1,y1,x2,y2);
   5.101 +  }
   5.102 +  
   5.103 +  EpsDrawer::EpsDrawer(const std::string &name,xy<double> s) :
   5.104 +    local_stream(true),
   5.105 +    out(*new std::ofstream(name.c_str()))
   5.106 +  {
   5.107 +    init(0.0,0.0,s.x,s.y);
   5.108 +  }
   5.109 +
   5.110 +  EpsDrawer::EpsDrawer(const std::string &name,xy<double> a, xy<double> b) :
   5.111 +    local_stream(true),
   5.112 +    out(*new std::ofstream(name.c_str()))
   5.113 +  {
   5.114 +    init(a.x,a.y,b.x,b.y);
   5.115 +  }
   5.116 +
   5.117 +
   5.118 +  EpsDrawer::~EpsDrawer()
   5.119 +  {
   5.120 +    out << "showpage\n";
   5.121 +    if(local_stream) delete &out;
   5.122 +  }
   5.123 +
   5.124 +  EpsDrawer &EpsDrawer::save()
   5.125 +  {
   5.126 +    out << "gsave\n";
   5.127 +    return *this;  
   5.128 +  }
   5.129 +
   5.130 +  EpsDrawer &EpsDrawer::restore()
   5.131 +  {
   5.132 +    out << "grestore\n";
   5.133 +    return *this;  
   5.134 +  }
   5.135 + 
   5.136 +  EpsDrawer &EpsDrawer::line(double x1,double y1,double x2,double y2)
   5.137 +  {
   5.138 +    out << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << " l\n";
   5.139 +    return *this;
   5.140 +  
   5.141 +  }
   5.142 +
   5.143 +  EpsDrawer &EpsDrawer::lineTo(double x1,double y1)
   5.144 +  {
   5.145 +    out << x1 << ' ' << y1 << " lt\n";
   5.146 +    return *this;
   5.147 +  
   5.148 +  }
   5.149 +
   5.150 +  EpsDrawer &EpsDrawer::moveTo(double x1,double y1)
   5.151 +  {
   5.152 +    out << x1 << ' ' << y1 << " mt\n";
   5.153 +    return *this;  
   5.154 +  }
   5.155 +
   5.156 +  EpsDrawer &EpsDrawer::circle(double x,double y, double r)
   5.157 +  {
   5.158 +    out << x << ' ' << y << ' ' << r << " c\n";
   5.159 +    return *this;  
   5.160 +  }
   5.161 +
   5.162 +  EpsDrawer &EpsDrawer::operator<<(const std::string &s)
   5.163 +  {
   5.164 +    out << "(" << s <<") xshow\n";
   5.165 +    return *this;
   5.166 +  }
   5.167 +
   5.168 +  EpsDrawer &EpsDrawer::operator<<(const char *s)
   5.169 +  {
   5.170 +    out << "(" << s <<") xshow\n";
   5.171 +    return *this;
   5.172 +  }
   5.173 +
   5.174 +  EpsDrawer &EpsDrawer::operator<<(int i)
   5.175 +  {
   5.176 +    out << "(" << i <<") xshow\n";
   5.177 +    return *this;
   5.178 +  }
   5.179 +
   5.180 +  EpsDrawer &EpsDrawer::operator<<(double d)
   5.181 +  {
   5.182 +    out << "(" << d <<") xshow\n";
   5.183 +    return *this;
   5.184 +  }
   5.185 +
   5.186 +  EpsDrawer &EpsDrawer::fontSize(double si)
   5.187 +  {
   5.188 +    out << si << " stfs\n";
   5.189 +    return *this;
   5.190 +  }
   5.191 +  EpsDrawer &EpsDrawer::font(std::string s)
   5.192 +  {
   5.193 +    out << "/defont ("<<s<<") findfont def fontset\n";
   5.194 +    return *this;
   5.195 +  }
   5.196 +
   5.197 +
   5.198 +  EpsDrawer &EpsDrawer::collect()
   5.199 +  {
   5.200 +    out << "collect\n";
   5.201 +    return *this;  
   5.202 +  }
   5.203 +
   5.204 +  EpsDrawer &EpsDrawer::closePath()
   5.205 +  {
   5.206 +    out << "closepath\n";
   5.207 +    return *this;
   5.208 +  }
   5.209 +
   5.210 +  EpsDrawer &EpsDrawer::stroke()
   5.211 +  {
   5.212 +    out << "str\n";
   5.213 +    return *this;  
   5.214 +  }
   5.215 +  EpsDrawer &EpsDrawer::fill()
   5.216 +  {
   5.217 +    out << "fl\n";
   5.218 +    return *this;  
   5.219 +  }
   5.220 +  EpsDrawer &EpsDrawer::eoFill()
   5.221 +  {
   5.222 +    out << "eofl\n";
   5.223 +    return *this;  
   5.224 +  }
   5.225 +  EpsDrawer &EpsDrawer::clip()
   5.226 +  {
   5.227 +    out << "cl\n";
   5.228 +    return *this;  
   5.229 +  }
   5.230 +  EpsDrawer &EpsDrawer::eoClip()
   5.231 +  {
   5.232 +    out << "eocl\n";
   5.233 +    return *this;  
   5.234 +  }
   5.235 +
   5.236 +  EpsDrawer &EpsDrawer::lineWidth(double w)
   5.237 +  {
   5.238 +    out << w << " setlinewidth\n";
   5.239 +    return *this;  
   5.240 +  }
   5.241 +
   5.242 +  EpsDrawer &EpsDrawer::lineCap(int i)
   5.243 +  {
   5.244 +    out << i << " setlinecap\n";
   5.245 +    return *this;  
   5.246 +  }
   5.247 +
   5.248 +  EpsDrawer &EpsDrawer::lineJoin(int i)
   5.249 +  {
   5.250 +    out << i << " setlinejoin\n";
   5.251 +    return *this;  
   5.252 +  }
   5.253 +
   5.254 +  EpsDrawer &EpsDrawer::miterLimit(double w)
   5.255 +  {
   5.256 +    out << w << " setmiterlimit\n";
   5.257 +    return *this;  
   5.258 +  }
   5.259 +
   5.260 +  EpsDrawer &EpsDrawer::color(double r, double g, double b)
   5.261 +  {
   5.262 +    out << r << ' ' << g << ' ' << b << " setrgbcolor\n";
   5.263 +    return *this;  
   5.264 +  }
   5.265 +
   5.266 +  EpsDrawer &EpsDrawer::translate(double x,double y)
   5.267 +  {
   5.268 +    out << x << ' ' << y << " translate\n";
   5.269 +    return *this;  
   5.270 +  }
   5.271 +
   5.272 +  EpsDrawer &EpsDrawer::rotate(double r)
   5.273 +  {
   5.274 +    out << r << " rotate\n";
   5.275 +    return *this;  
   5.276 +  }
   5.277 +  EpsDrawer &EpsDrawer::scale(double sx, double sy)
   5.278 +  {
   5.279 +    out << sx << ' ' << sy << " scale\n";
   5.280 +    return *this;  
   5.281 +  }
   5.282 +  
   5.283 +  EpsDrawer &EpsDrawer::clear()
   5.284 +  {
   5.285 +    out << "erasepage\n";
   5.286 +    return *this;  
   5.287 +  }
   5.288 +  
   5.289 +  EpsDrawer &EpsDrawer::centerMode(bool m)
   5.290 +  {
   5.291 +    if(m) out << "/cshowmode true def\n";
   5.292 +    else out << "/cshowmode false def\n";
   5.293 +
   5.294 +    return *this;  
   5.295 +  }
   5.296 +  
   5.297 +  EpsDrawer &EpsDrawer::flush()
   5.298 +  {
   5.299 +    out << "flush\n";
   5.300 +    //  fflush(fp);
   5.301 +    return *this;
   5.302 +  }
   5.303 +
   5.304 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/lemon/eps.h	Mon Feb 20 06:41:12 2006 +0000
     6.3 @@ -0,0 +1,293 @@
     6.4 +/* -*- C++ -*-
     6.5 + *
     6.6 + * This file is a part of LEMON, a generic C++ optimization library
     6.7 + *
     6.8 + * Copyright (C) 2003-2006
     6.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    6.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    6.11 + *
    6.12 + * Permission to use, modify and distribute this software is granted
    6.13 + * provided that this copyright notice appears in all copies. For
    6.14 + * precise terms see the accompanying LICENSE file.
    6.15 + *
    6.16 + * This software is provided "AS IS" with no warranty of any kind,
    6.17 + * express or implied, and with no claim as to its suitability for any
    6.18 + * purpose.
    6.19 + *
    6.20 + */
    6.21 +
    6.22 +#ifndef LEMON_EPS_H
    6.23 +#define LEMON_EPS_H
    6.24 +
    6.25 +#include<string>
    6.26 +#include<iostream>
    6.27 +#include<fstream>
    6.28 +#include<sstream>
    6.29 +#include<lemon/color.h>
    6.30 +#include<lemon/xy.h>
    6.31 +
    6.32 +  ///\ingroup io_group
    6.33 +  ///\file
    6.34 +  ///\brief Simple tool to create \c .eps files
    6.35 +  ///
    6.36 +  ///\author Alpar Juttner
    6.37 +
    6.38 +namespace lemon {
    6.39 +  
    6.40 +  ///\ingroup io_group
    6.41 +  ///\brief A simple tool to create \c .eps files
    6.42 +  ///
    6.43 +  ///A simple tool to create \c .eps files
    6.44 +  ///\author Alpar Juttner
    6.45 +  class EpsDrawer
    6.46 +  {
    6.47 +    void defMacros();
    6.48 +    void init(int x1,int y1,int x2,int y2);
    6.49 +    void init(double x1,double y1,double x2,double y2);
    6.50 +    bool local_stream;
    6.51 +  public:
    6.52 +    
    6.53 +    std::ostream &out;
    6.54 +    
    6.55 +    ///\e 
    6.56 +
    6.57 +    ///The generated file is put to \c os.
    6.58 +    ///
    6.59 +    /// \c x and \c y determine the upper
    6.60 +    ///right corner of the bounding box. The lower left corner is (0,0).
    6.61 +    EpsDrawer(std::ostream &os,int x,int y);
    6.62 +    ///\e
    6.63 +
    6.64 +    ///The generated file is put to \c os.
    6.65 +    ///
    6.66 +    ///(x1,y1) and (x2,y2)
    6.67 +    /// determine the lower left and the upper right corners of
    6.68 +    ///the bounding box, respectively.
    6.69 +    EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2);
    6.70 +    ///\e
    6.71 +
    6.72 +    ///The generated file is put to \c os.
    6.73 +    ///
    6.74 +    ///\c s determines the upper
    6.75 +    ///right corner of the bounding box. The lower left corner is (0,0).
    6.76 +    EpsDrawer(std::ostream &os,xy<double> s);
    6.77 +    ///\e
    6.78 +
    6.79 +    ///The generated file is put to \c os.
    6.80 +    ///
    6.81 +    ///\c a and \c b
    6.82 +    /// determine the lower left and the upper right corners of
    6.83 +    ///the bounding box, respectively.
    6.84 +    EpsDrawer(std::ostream &os,xy<double> a, xy<double> b);
    6.85 +    ///\e
    6.86 +
    6.87 +    ///The generated picture is put to the file \c name.
    6.88 +    ///
    6.89 +    ///\c x and \c y determine the upper
    6.90 +    ///right corner of the bounding box. The lower left corner is (0,0).
    6.91 +    EpsDrawer(const std::string &name,int x,int y);
    6.92 +    ///\e
    6.93 +
    6.94 +    ///The generated picture is put to the file \c name.
    6.95 +    ///
    6.96 +    ///(x1,y1) and (x2,y2)
    6.97 +    /// determine the lower left and the upper right corners of
    6.98 +    ///the bounding box, respectively.
    6.99 +    EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2);
   6.100 +    ///\e
   6.101 +
   6.102 +    ///The generated picture is put to the file \c name.
   6.103 +    ///
   6.104 +    ///\c s determines the upper
   6.105 +    ///right corner of the bounding box. The lower left corner is (0,0).
   6.106 +    EpsDrawer(const std::string &name,xy<double> s);
   6.107 +    ///\e
   6.108 +
   6.109 +    ///The generated picture is put to the file \c name.
   6.110 +    ///
   6.111 +    ///\c a and \c b
   6.112 +    /// determine the lower left and the upper right corners of
   6.113 +    ///the bounding box, respectively.
   6.114 +    EpsDrawer(const std::string &name,xy<double> a, xy<double> b);
   6.115 +
   6.116 +//     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b) 
   6.117 +//     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b);
   6.118 +    
   6.119 +    ~EpsDrawer();
   6.120 +    
   6.121 +    ///Save the current graphic state.
   6.122 +
   6.123 +    ///This function saves the current coordinate system, and the parameters
   6.124 +    ///set by \ref color(), \ref lineWidth() etc.
   6.125 +    ///The can be \ref restore "restore()"d later.
   6.126 +    ///
   6.127 +    ///The \ref save() - \ref restore() pairs can be nested.
   6.128 +    ///
   6.129 +    EpsDrawer &save();
   6.130 +    ///Restore the saves graphic state.
   6.131 +
   6.132 +    EpsDrawer &restore();
   6.133 +    
   6.134 +    ///Draw a line
   6.135 +    EpsDrawer &line(double x1,double y1,double x2,double y2);
   6.136 +    ///Draw a line from the current point
   6.137 +    EpsDrawer &lineTo(double x1,double y1);
   6.138 +    ///Move the current point
   6.139 +    EpsDrawer &moveTo(double x1,double y1);
   6.140 +    ///Draw a circle
   6.141 +    EpsDrawer &circle(double x,double y, double r);
   6.142 +    
   6.143 +    ///Draw a line
   6.144 +    template<class T> EpsDrawer &line(xy<T> p1,xy<T> p2) 
   6.145 +    {
   6.146 +      return line(p1.x,p1.y,p2.x,p2.y);
   6.147 +    }
   6.148 +    ///Draw a line from the current point
   6.149 +    template<class T> EpsDrawer &lineTo(xy<T> p)
   6.150 +    {
   6.151 +      return lineTo(p.x,p.y);
   6.152 +    }
   6.153 +    ///Move the current point
   6.154 +    template<class T> EpsDrawer &moveTo(xy<T> p)
   6.155 +    {
   6.156 +      return moveTo(p.x,p.y);
   6.157 +    }
   6.158 +    ///Draw a circle
   6.159 +    template<class T> EpsDrawer &circle(xy<T> p, double r)
   6.160 +    {
   6.161 +      return circle(p.x,p.y,r);
   6.162 +    }
   6.163 +    
   6.164 +    ///Set the font size
   6.165 +    EpsDrawer &fontSize(double si);
   6.166 +    ///Set the fint type
   6.167 +    EpsDrawer &font(std::string );
   6.168 +    ///Sets whether text output is centerized of not
   6.169 +
   6.170 +    ///Sets whether text output is centerized of not.
   6.171 +    ///
   6.172 +    ///\warning \ref save() doesn't save this setting.
   6.173 +    ///
   6.174 +    EpsDrawer &centerMode(bool m);
   6.175 +    ///Turn to collect mode.
   6.176 +
   6.177 +    ///If you call this function, then the drawing operations like \ref line(),
   6.178 +    ///\ref lineTo(), \ref moveTo() will not take place immediately, but istead
   6.179 +    ///they
   6.180 +    ///are collected. These operations form a \e path.
   6.181 +    ///Then you can \ref stroke(), \ref fill(), \ref eofill(), \ref clip() or
   6.182 +    ///\ref eoclip() it.
   6.183 +    ///When drawing, you can also use \ref closePath() to - surprise - close the
   6.184 +    ///current path.
   6.185 +    ///
   6.186 +    ///This example draws a red filled diamond.
   6.187 +    ///\code
   6.188 +    ///  EpsDraw ed("diamond.eps",-1,-1,1,1);
   6.189 +    ///  ed.color(1,0,0,).collect().line(0,-1,1,0).lineTo(0,1)
   6.190 +    ///    .lineTo(-1,0).closePath().fill();
   6.191 +    ///\endcode
   6.192 +    EpsDrawer &collect();
   6.193 +    ///Close the current drawing path
   6.194 +    EpsDrawer &closePath();
   6.195 +    ///Stroke (draw) a path
   6.196 +
   6.197 +    ///Stroke (draw) a path.
   6.198 +    ///\sa collect
   6.199 +    ///
   6.200 +    EpsDrawer &stroke();
   6.201 +    ///Fill a path
   6.202 +
   6.203 +    ///Fill a path.
   6.204 +    ///\sa collect
   6.205 +    ///
   6.206 +    EpsDrawer &fill();
   6.207 +    ///Even-odd fill a path
   6.208 +
   6.209 +    ///Even-odd fill a path.
   6.210 +    ///\sa collect
   6.211 +    ///
   6.212 +    EpsDrawer &eoFill();
   6.213 +    ///Set a clipping area.
   6.214 +
   6.215 +    ///This function sets a clipping area. After that, the drawing operations
   6.216 +    ///will affect only this area.
   6.217 +    ///\sa collect
   6.218 +    ///
   6.219 +    EpsDrawer &clip();
   6.220 +    ///Set a clipping area using even-odd rule.
   6.221 +
   6.222 +    ///This function sets a clipping area using even-odd rule.
   6.223 +    ///After that, the drawing operations
   6.224 +    ///will affect only this area.
   6.225 +    ///\sa collect
   6.226 +    ///
   6.227 +    EpsDrawer &eoClip();
   6.228 +    
   6.229 +    ///Set the line width.
   6.230 +    EpsDrawer &lineWidth(double w);
   6.231 +    ///Set the style of the line ends
   6.232 +
   6.233 +    ///\param i It can be 0, 1 or 2
   6.234 +    ///
   6.235 +    EpsDrawer &lineCap(int i);
   6.236 +    ///Set the style of the line joins
   6.237 +
   6.238 +    ///\param i It can be 0, 1 or 2
   6.239 +    ///
   6.240 +    EpsDrawer &lineJoin(int i);
   6.241 +    ///Set the cut length of near parallel joining lines.
   6.242 +    EpsDrawer &miterLimit(double w);
   6.243 +    
   6.244 +    ///Set the drawing color
   6.245 +    EpsDrawer &color(double r, double g, double b);
   6.246 +    ///Set the drawing color
   6.247 +    EpsDrawer &color(Color c)
   6.248 +    {
   6.249 +      return color(c.red(),c.green(),c.blue());
   6.250 +    }
   6.251 +    
   6.252 +    ///Translate the coordinate system
   6.253 +    EpsDrawer &translate(double x,double y);
   6.254 +    ///Translate the coordinate system
   6.255 +    template<class T> EpsDrawer &translate(xy<T> p)
   6.256 +    {
   6.257 +      return translate(p.x,p.y);
   6.258 +    }
   6.259 +    ///Rotate the coordinate system
   6.260 +    EpsDrawer &rotate(double r);
   6.261 +    ///Scale the coordinate system
   6.262 +    EpsDrawer &scale(double sx, double sy);
   6.263 +    ///Scale the coordinate system
   6.264 +    EpsDrawer &scale(double s) { return scale(s,s); }
   6.265 +    ///Scale the coordinate system
   6.266 +    template<class T> EpsDrawer &scale(xy<T> p)
   6.267 +    {
   6.268 +      return scale(p.x,p.y);
   6.269 +    }
   6.270 +    
   6.271 +    ///\e
   6.272 +    EpsDrawer &flush();
   6.273 +    ///Clear the image
   6.274 +    EpsDrawer &clear();
   6.275 +    
   6.276 +    ///Print a text at the current point
   6.277 +    EpsDrawer &operator<<(const std::string &s);
   6.278 +    ///Print a text at the current point
   6.279 +    EpsDrawer &operator<<(const char *s);
   6.280 +    ///Print a number at the current point
   6.281 +    EpsDrawer &operator<<(int i);
   6.282 +    ///Print a number at the current point
   6.283 +    EpsDrawer &operator<<(double d);
   6.284 +    ///Print a coordinate at the current point
   6.285 +    template<class T>
   6.286 +    EpsDrawer &operator<<(xy<T> p) 
   6.287 +    {
   6.288 +      out << "((" << p.x << ',' << p.y <<")) show\n";
   6.289 +      return *this;
   6.290 +    }
   6.291 +    
   6.292 +  };
   6.293 +  
   6.294 +}
   6.295 +
   6.296 +#endif
     7.1 --- a/lemon/graph_to_eps.h	Mon Feb 20 06:38:18 2006 +0000
     7.2 +++ b/lemon/graph_to_eps.h	Mon Feb 20 06:41:12 2006 +0000
     7.3 @@ -33,6 +33,7 @@
     7.4  #include<lemon/invalid.h>
     7.5  #include<lemon/xy.h>
     7.6  #include<lemon/maps.h>
     7.7 +#include<lemon/color.h>
     7.8  #include<lemon/bezier.h>
     7.9  
    7.10  
    7.11 @@ -44,133 +45,6 @@
    7.12  
    7.13  namespace lemon {
    7.14  
    7.15 -///Data structure representing RGB colors.
    7.16 -
    7.17 -///Data structure representing RGB colors.
    7.18 -///\ingroup misc
    7.19 -class Color
    7.20 -{
    7.21 -  double _r,_g,_b;
    7.22 -public:
    7.23 -  ///Default constructor
    7.24 -  Color() {}
    7.25 -  ///Constructor
    7.26 -  Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
    7.27 -  ///Returns the red component
    7.28 -  double & red() {return _r;}
    7.29 -  ///Returns the red component
    7.30 -  const double & red() const {return _r;}
    7.31 -  ///Returns the green component
    7.32 -  double & green() {return _g;}
    7.33 -  ///Returns the green component
    7.34 -  const double & green() const {return _g;}
    7.35 -  ///Returns the blue component
    7.36 -  double & blue() {return _b;}
    7.37 -  ///Returns the blue component
    7.38 -  const double & blue() const {return _b;}
    7.39 -  ///Set the color components
    7.40 -  void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
    7.41 -};
    7.42 -
    7.43 -///Maps <tt>int</tt>s to different \ref Color "Color"s
    7.44 -
    7.45 -///This map assigns one of the predefined \ref Color "Color"s
    7.46 -///to each <tt>int</tt>. It is possible to change the colors as well as their
    7.47 -///number. The integer range is cyclically mapped to the provided set of colors.
    7.48 -///
    7.49 -///This is a true \ref concept::ReferenceMap "reference map", so you can also
    7.50 -///change the actual colors.
    7.51 -
    7.52 -class ColorSet : public MapBase<int,Color>
    7.53 -{
    7.54 -  std::vector<Color> colors;
    7.55 -public:
    7.56 -  ///Constructor
    7.57 -
    7.58 -  ///Constructor
    7.59 -  ///\param have_white indicates whether white is
    7.60 -  ///amongst the provided color (\c true) or not (\c false). If it is true,
    7.61 -  ///white will be assigned to \c 0.
    7.62 -  ///\param num the number of the allocated colors. If it is \c 0
    7.63 -  ///the default color configuration is set up (26 color plus the while).
    7.64 -  ///If \c num is less then 26/27 then the default color list is cut. Otherwise
    7.65 -  ///the color list is filled repeatedly with the default color list.
    7.66 -  ///(The colors can be changed later on.)
    7.67 -  ColorSet(bool have_white=false,int num=0)
    7.68 -  {
    7.69 -    do {
    7.70 -      if(have_white) colors.push_back(Color(1,1,1));
    7.71 -
    7.72 -      colors.push_back(Color(0,0,0));
    7.73 -      colors.push_back(Color(1,0,0));
    7.74 -      colors.push_back(Color(0,1,0));
    7.75 -      colors.push_back(Color(0,0,1));
    7.76 -      colors.push_back(Color(1,1,0));
    7.77 -      colors.push_back(Color(1,0,1));
    7.78 -      colors.push_back(Color(0,1,1));
    7.79 -      
    7.80 -      colors.push_back(Color(.5,0,0));
    7.81 -      colors.push_back(Color(0,.5,0));
    7.82 -      colors.push_back(Color(0,0,.5));
    7.83 -      colors.push_back(Color(.5,.5,0));
    7.84 -      colors.push_back(Color(.5,0,.5));
    7.85 -      colors.push_back(Color(0,.5,.5));
    7.86 -      
    7.87 -      colors.push_back(Color(.5,.5,.5));
    7.88 -      colors.push_back(Color(1,.5,.5));
    7.89 -      colors.push_back(Color(.5,1,.5));
    7.90 -      colors.push_back(Color(.5,.5,1));
    7.91 -      colors.push_back(Color(1,1,.5));
    7.92 -      colors.push_back(Color(1,.5,1));
    7.93 -      colors.push_back(Color(.5,1,1));
    7.94 -      
    7.95 -      colors.push_back(Color(1,.5,0));
    7.96 -      colors.push_back(Color(.5,1,0));
    7.97 -      colors.push_back(Color(1,0,.5));
    7.98 -      colors.push_back(Color(0,1,.5));
    7.99 -      colors.push_back(Color(0,.5,1));
   7.100 -      colors.push_back(Color(.5,0,1));
   7.101 -    } while(int(colors.size())<num);
   7.102 -    //    colors.push_back(Color(1,1,1));
   7.103 -    if(num>0) colors.resize(num);
   7.104 -  }
   7.105 -  ///\e
   7.106 -  Color &operator[](int i)
   7.107 -  {
   7.108 -    return colors[i%colors.size()];
   7.109 -  }
   7.110 -  ///\e
   7.111 -  const Color &operator[](int i) const
   7.112 -  {
   7.113 -    return colors[i%colors.size()];
   7.114 -  }
   7.115 -  ///\e
   7.116 -  void set(int i,const Color &c)
   7.117 -  {
   7.118 -    colors[i%colors.size()]=c;
   7.119 -  }
   7.120 -  ///Sets the number of the exiting colors.
   7.121 -  void resize(int s) { colors.resize(s);}
   7.122 -  ///Returns the number of the existing colors.
   7.123 -  std::size_t size() const { return colors.size();}
   7.124 -};
   7.125 -
   7.126 -///Returns a visible distinct \ref Color
   7.127 -
   7.128 -///Returns a \ref Color which is as different from the given parameter
   7.129 -///as it is possible.
   7.130 -inline Color distantColor(const Color &c) 
   7.131 -{
   7.132 -  return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
   7.133 -}
   7.134 -///Returns black for light colors and white for the dark ones.
   7.135 -
   7.136 -///Returns black for light colors and white for the dark ones.
   7.137 -inline Color distantBW(const Color &c){
   7.138 -  double v=(.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5?1:0;
   7.139 -  return Color(v,v,v);
   7.140 -}
   7.141 -
   7.142  template<class MT>
   7.143  class _NegY {
   7.144  public: