[Lemon-commits] [lemon_svn] alpar: r2555 - in hugo/trunk: demo lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:53:32 CET 2006


Author: alpar
Date: Mon Feb 20 07:41:12 2006
New Revision: 2555

Added:
   hugo/trunk/demo/eps_demo.cc
   hugo/trunk/lemon/color.h
   hugo/trunk/lemon/eps.cc
   hugo/trunk/lemon/eps.h
Modified:
   hugo/trunk/demo/Makefile.am
   hugo/trunk/lemon/Makefile.am
   hugo/trunk/lemon/graph_to_eps.h

Log:
- RGB color related stuff is in color.h now
- eps.h: A simple class to create .eps figures (demo: eps_demo.h)



Modified: hugo/trunk/demo/Makefile.am
==============================================================================
--- hugo/trunk/demo/Makefile.am	(original)
+++ hugo/trunk/demo/Makefile.am	Mon Feb 20 07:41:12 2006
@@ -8,6 +8,7 @@
 	dijkstra_demo \
 	reader_writer_demo \
 	dim_to_lgf \
+	eps_demo \
 	graph_to_eps_demo \
 	graph_orientation \
 	min_route \
@@ -32,6 +33,8 @@
 
 dijkstra_demo_SOURCES = dijkstra_demo.cc
 
+eps_demo_SOURCES = eps_demo.cc
+
 reader_writer_demo_SOURCES = reader_writer_demo.cc
 
 dim_to_lgf_SOURCES = dim_to_lgf.cc

Added: hugo/trunk/demo/eps_demo.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/demo/eps_demo.cc	Mon Feb 20 07:41:12 2006
@@ -0,0 +1,110 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+/// \ingroup demos
+/// \file
+/// \brief Demo of the EPS grawing class \ref EpsDrawer()
+///
+/// This demo program shows examples how to use the class \ref
+/// EpsDrawer(). It takes no input but simply creates a file
+/// <tt>eps_demo.eps</tt> demonstrating the capability of \ref
+/// EpsDrawer().
+///
+/// \include eps_demo.cc
+
+#include <cmath>
+#include <lemon/eps.h>
+
+using namespace lemon;
+
+void kosar(EpsDrawer &ed)
+{
+  double d,r;
+  
+  r = sqrt(2);
+  
+  ed.save();
+  
+  ed.translate(256,256).scale(256,256);
+  ed.lineWidth(1/256);
+  
+  ed.collect();
+  
+  ed.moveTo(0,1);
+  
+  for(d=0;d<M_PI*2*5;d+=.1)
+    {
+      ed.lineTo(sin(d*3),cos(d*5));
+    }
+  
+  ed.stroke();
+  ed.restore();
+  
+}
+
+void fonts(EpsDrawer &ed)
+{
+  ed.save().centerMode(true);
+  
+  ed.font("Helvetica").fontSize(90);
+  ed.moveTo(256,512/3*2+50) << "Helvetica";
+  ed.font("Courier");
+  ed.moveTo(256,512/3+50) << "Courier" ;
+  ed.font("Times-Roman");
+  ed.moveTo(256,50) << "Times-Roman";
+  
+  ed.centerMode(false).restore();
+}
+
+int main()
+{
+
+  EpsDrawer ed("eps_demo.eps",512,512);
+  ed.scale(1,1);
+  
+  ed.color(0,0,0).collect();
+  ed.moveTo(0,0).lineTo(0,512).lineTo(512,512).lineTo(512,0).closePath().fill();
+  
+  ed.lineWidth(4);
+  
+  for(double r=0;r<=256;r+=2)
+    {
+      ed.color(r/256.0,0,1-r/256.0).circle(256,256,r);
+    }
+  
+  
+  ed.save();
+  ed.color(0,0,0);
+  ed.translate(256,256);
+  
+  for(int i=0;i<18;i++)
+    {
+      ed.rotate(20);
+      
+      for(double r=0;r<=256;r+=20)
+	ed.fontSize(r/10+1).rotate(2).moveTo(0,r) << r;
+      ed.rotate(-26);
+      
+    }
+  
+  ed.restore();
+  
+  fonts(ed.color(.7,.7,.7));
+  ed.color(0,1,0);
+  kosar(ed);
+}

Modified: hugo/trunk/lemon/Makefile.am
==============================================================================
--- hugo/trunk/lemon/Makefile.am	(original)
+++ hugo/trunk/lemon/Makefile.am	Mon Feb 20 07:41:12 2006
@@ -8,7 +8,8 @@
 libemon_la_SOURCES = \
 	lp_base.cc \
 	lp_skeleton.cc \
-	base.cc 
+	base.cc \
+	eps.cc 
 libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS)
 libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS)
 
@@ -26,6 +27,7 @@
 	bfs.h \
 	dfs.h \
 	bin_heap.h \
+	color.h \
 	config.h \
 	counter.h \
 	dijkstra.h \
@@ -33,6 +35,7 @@
 	dag_shortest_path.h \
 	edge_set.h \
 	error.h \
+	eps.h \
 	fib_heap.h \
 	floyd_warshall.h \
 	fredman_tarjan.h \

Added: hugo/trunk/lemon/color.h
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/color.h	Mon Feb 20 07:41:12 2006
@@ -0,0 +1,176 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_COLOR_H
+#define LEMON_COLOR_H
+
+#include <sys/time.h>
+
+#include<iostream>
+#include<fstream>
+#include<sstream>
+#include<algorithm>
+#include<vector>
+
+#include <ctime>
+#include <cmath>
+
+#include<lemon/invalid.h>
+#include<lemon/xy.h>
+#include<lemon/maps.h>
+#include<lemon/bezier.h>
+
+
+///\ingroup misc
+///\file
+///\brief Tools to manage RGB colors.
+///
+///\author Alpar Juttner
+
+namespace lemon {
+
+///Data structure representing RGB colors.
+
+///Data structure representing RGB colors.
+///\ingroup misc
+class Color
+{
+  double _r,_g,_b;
+public:
+  ///Default constructor
+  Color() {}
+  ///Constructor
+  Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
+  ///Returns the red component
+  double & red() {return _r;}
+  ///Returns the red component
+  const double & red() const {return _r;}
+  ///Returns the green component
+  double & green() {return _g;}
+  ///Returns the green component
+  const double & green() const {return _g;}
+  ///Returns the blue component
+  double & blue() {return _b;}
+  ///Returns the blue component
+  const double & blue() const {return _b;}
+  ///Set the color components
+  void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
+};
+
+///Maps <tt>int</tt>s to different \ref Color "Color"s
+
+///This map assigns one of the predefined \ref Color "Color"s
+///to each <tt>int</tt>. It is possible to change the colors as well as their
+///number. The integer range is cyclically mapped to the provided set of colors.
+///
+///This is a true \ref concept::ReferenceMap "reference map", so you can also
+///change the actual colors.
+
+class ColorSet : public MapBase<int,Color>
+{
+  std::vector<Color> colors;
+public:
+  ///Constructor
+
+  ///Constructor
+  ///\param have_white indicates whether white is
+  ///amongst the provided color (\c true) or not (\c false). If it is true,
+  ///white will be assigned to \c 0.
+  ///\param num the number of the allocated colors. If it is \c 0
+  ///the default color configuration is set up (26 color plus the while).
+  ///If \c num is less then 26/27 then the default color list is cut. Otherwise
+  ///the color list is filled repeatedly with the default color list.
+  ///(The colors can be changed later on.)
+  ColorSet(bool have_white=false,int num=0)
+  {
+    do {
+      if(have_white) colors.push_back(Color(1,1,1));
+
+      colors.push_back(Color(0,0,0));
+      colors.push_back(Color(1,0,0));
+      colors.push_back(Color(0,1,0));
+      colors.push_back(Color(0,0,1));
+      colors.push_back(Color(1,1,0));
+      colors.push_back(Color(1,0,1));
+      colors.push_back(Color(0,1,1));
+      
+      colors.push_back(Color(.5,0,0));
+      colors.push_back(Color(0,.5,0));
+      colors.push_back(Color(0,0,.5));
+      colors.push_back(Color(.5,.5,0));
+      colors.push_back(Color(.5,0,.5));
+      colors.push_back(Color(0,.5,.5));
+      
+      colors.push_back(Color(.5,.5,.5));
+      colors.push_back(Color(1,.5,.5));
+      colors.push_back(Color(.5,1,.5));
+      colors.push_back(Color(.5,.5,1));
+      colors.push_back(Color(1,1,.5));
+      colors.push_back(Color(1,.5,1));
+      colors.push_back(Color(.5,1,1));
+      
+      colors.push_back(Color(1,.5,0));
+      colors.push_back(Color(.5,1,0));
+      colors.push_back(Color(1,0,.5));
+      colors.push_back(Color(0,1,.5));
+      colors.push_back(Color(0,.5,1));
+      colors.push_back(Color(.5,0,1));
+    } while(int(colors.size())<num);
+    //    colors.push_back(Color(1,1,1));
+    if(num>0) colors.resize(num);
+  }
+  ///\e
+  Color &operator[](int i)
+  {
+    return colors[i%colors.size()];
+  }
+  ///\e
+  const Color &operator[](int i) const
+  {
+    return colors[i%colors.size()];
+  }
+  ///\e
+  void set(int i,const Color &c)
+  {
+    colors[i%colors.size()]=c;
+  }
+  ///Sets the number of the exiting colors.
+  void resize(int s) { colors.resize(s);}
+  ///Returns the number of the existing colors.
+  std::size_t size() const { return colors.size();}
+};
+
+///Returns a visible distinct \ref Color
+
+///Returns a \ref Color which is as different from the given parameter
+///as it is possible.
+inline Color distantColor(const Color &c) 
+{
+  return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
+}
+///Returns black for light colors and white for the dark ones.
+
+///Returns black for light colors and white for the dark ones.
+inline Color distantBW(const Color &c){
+  double v=(.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5?1:0;
+  return Color(v,v,v);
+}
+
+} //END OF NAMESPACE LEMON
+
+#endif // LEMON_COLOR_H

Added: hugo/trunk/lemon/eps.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/eps.cc	Mon Feb 20 07:41:12 2006
@@ -0,0 +1,301 @@
+#include <eps.h>
+
+namespace lemon {
+  
+  void EpsDrawer::defMacros()
+  {
+    out << "/clmode true def\n" <<
+      "/cshowmode false def\n" <<
+      "/defont (Helvetica) findfont def\n" <<
+      "/fosi 12 def\n" <<
+      "\n" <<
+      "/st { clmode { currentpoint stroke newpath moveto } if } bind def\n" <<
+      "/str { currentpoint stroke newpath moveto /clmode true def } bind def\n"
+	<<
+      "/fl { currentpoint fill newpath moveto /clmode true def } bind def\n" <<
+      "/eofl { currentpoint eofill newpath moveto /clmode true def } bind def\n"
+	<<
+      "/cl { currentpoint clip newpath moveto /clmode true def } bind def\n"
+	<<
+      "/eocl { currentpoint eoclip newpath moveto /clmode true def } bind def\n"
+	<<
+      "\n" <<
+      "/l { moveto lineto st } bind def\n" <<
+      "/lt { lineto st } bind def\n" <<
+      "/mt { moveto } bind def\n" <<
+      "/c { dup 3 index add 2 index moveto 0 360 arc st } bind def\n" <<
+      "/collect { /clmode false def currentpoint newpath moveto } bind def\n" <<
+      "\n" <<
+      "/fontset { defont fosi scalefont setfont } bind def\n" <<
+      "/stfs { /fosi exch def fontset } bind def\n" <<
+      "/cshow { dup stringwidth pop\n" <<
+      "   neg 2 div 0 rmoveto show } bind def\n" <<
+      "/xshow { cshowmode { cshow } { show } ifelse } def\n" <<
+      "\n" <<
+      "fontset\n" <<
+      "newpath\n" <<
+      "0 0 moveto\n" <<
+      "1 setlinecap\n";
+  }
+
+  void EpsDrawer::init(int x1,int y1,int x2,int y2)
+  {
+    out << "%!PS-Adobe-2.0 EPSF-2.0\n" <<
+      "%%BoundingBox: " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
+      "\n%%EndComments\n";
+    defMacros();
+  }
+
+  void EpsDrawer::init(double x1,double y1,double x2,double y2)
+  {
+    out << "%!PS-Adobe-2.0\n" <<
+      "%%HiResBoundingBox: " << 
+      x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 <<
+      "\n%%EndComments\n";
+    defMacros();
+  }
+
+
+  EpsDrawer::EpsDrawer(std::ostream &os,int x,int y) : local_stream(false),
+						       out(os)
+  {
+    init(0,0,x,y);
+  }
+
+  EpsDrawer::EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2) : 
+    local_stream(false),
+    out(os)
+  {
+    init(x1,y1,x2,y2);
+  }
+
+  EpsDrawer::EpsDrawer(std::ostream &os,xy<double> s) : local_stream(false),
+							out(os)
+  {
+    init(0.0,0.0,s.x,s.y);
+  }
+
+  EpsDrawer::EpsDrawer(std::ostream &os,xy<double> a, xy<double> b) :
+    local_stream(false),
+    out(os)
+  {
+    init(a.x,a.y,b.x,b.y);
+  }
+
+
+  EpsDrawer::EpsDrawer(const std::string &name,int x,int y) :
+    local_stream(true),
+    out(*new std::ofstream(name.c_str()))
+  {
+    init(0,0,x,y);
+  }
+
+  EpsDrawer::EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2) : 
+    local_stream(true),
+    out(*new std::ofstream(name.c_str()))
+  {
+    init(x1,y1,x2,y2);
+  }
+  
+  EpsDrawer::EpsDrawer(const std::string &name,xy<double> s) :
+    local_stream(true),
+    out(*new std::ofstream(name.c_str()))
+  {
+    init(0.0,0.0,s.x,s.y);
+  }
+
+  EpsDrawer::EpsDrawer(const std::string &name,xy<double> a, xy<double> b) :
+    local_stream(true),
+    out(*new std::ofstream(name.c_str()))
+  {
+    init(a.x,a.y,b.x,b.y);
+  }
+
+
+  EpsDrawer::~EpsDrawer()
+  {
+    out << "showpage\n";
+    if(local_stream) delete &out;
+  }
+
+  EpsDrawer &EpsDrawer::save()
+  {
+    out << "gsave\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::restore()
+  {
+    out << "grestore\n";
+    return *this;  
+  }
+ 
+  EpsDrawer &EpsDrawer::line(double x1,double y1,double x2,double y2)
+  {
+    out << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << " l\n";
+    return *this;
+  
+  }
+
+  EpsDrawer &EpsDrawer::lineTo(double x1,double y1)
+  {
+    out << x1 << ' ' << y1 << " lt\n";
+    return *this;
+  
+  }
+
+  EpsDrawer &EpsDrawer::moveTo(double x1,double y1)
+  {
+    out << x1 << ' ' << y1 << " mt\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::circle(double x,double y, double r)
+  {
+    out << x << ' ' << y << ' ' << r << " c\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::operator<<(const std::string &s)
+  {
+    out << "(" << s <<") xshow\n";
+    return *this;
+  }
+
+  EpsDrawer &EpsDrawer::operator<<(const char *s)
+  {
+    out << "(" << s <<") xshow\n";
+    return *this;
+  }
+
+  EpsDrawer &EpsDrawer::operator<<(int i)
+  {
+    out << "(" << i <<") xshow\n";
+    return *this;
+  }
+
+  EpsDrawer &EpsDrawer::operator<<(double d)
+  {
+    out << "(" << d <<") xshow\n";
+    return *this;
+  }
+
+  EpsDrawer &EpsDrawer::fontSize(double si)
+  {
+    out << si << " stfs\n";
+    return *this;
+  }
+  EpsDrawer &EpsDrawer::font(std::string s)
+  {
+    out << "/defont ("<<s<<") findfont def fontset\n";
+    return *this;
+  }
+
+
+  EpsDrawer &EpsDrawer::collect()
+  {
+    out << "collect\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::closePath()
+  {
+    out << "closepath\n";
+    return *this;
+  }
+
+  EpsDrawer &EpsDrawer::stroke()
+  {
+    out << "str\n";
+    return *this;  
+  }
+  EpsDrawer &EpsDrawer::fill()
+  {
+    out << "fl\n";
+    return *this;  
+  }
+  EpsDrawer &EpsDrawer::eoFill()
+  {
+    out << "eofl\n";
+    return *this;  
+  }
+  EpsDrawer &EpsDrawer::clip()
+  {
+    out << "cl\n";
+    return *this;  
+  }
+  EpsDrawer &EpsDrawer::eoClip()
+  {
+    out << "eocl\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::lineWidth(double w)
+  {
+    out << w << " setlinewidth\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::lineCap(int i)
+  {
+    out << i << " setlinecap\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::lineJoin(int i)
+  {
+    out << i << " setlinejoin\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::miterLimit(double w)
+  {
+    out << w << " setmiterlimit\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::color(double r, double g, double b)
+  {
+    out << r << ' ' << g << ' ' << b << " setrgbcolor\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::translate(double x,double y)
+  {
+    out << x << ' ' << y << " translate\n";
+    return *this;  
+  }
+
+  EpsDrawer &EpsDrawer::rotate(double r)
+  {
+    out << r << " rotate\n";
+    return *this;  
+  }
+  EpsDrawer &EpsDrawer::scale(double sx, double sy)
+  {
+    out << sx << ' ' << sy << " scale\n";
+    return *this;  
+  }
+  
+  EpsDrawer &EpsDrawer::clear()
+  {
+    out << "erasepage\n";
+    return *this;  
+  }
+  
+  EpsDrawer &EpsDrawer::centerMode(bool m)
+  {
+    if(m) out << "/cshowmode true def\n";
+    else out << "/cshowmode false def\n";
+
+    return *this;  
+  }
+  
+  EpsDrawer &EpsDrawer::flush()
+  {
+    out << "flush\n";
+    //  fflush(fp);
+    return *this;
+  }
+
+}

Added: hugo/trunk/lemon/eps.h
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/eps.h	Mon Feb 20 07:41:12 2006
@@ -0,0 +1,293 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_EPS_H
+#define LEMON_EPS_H
+
+#include<string>
+#include<iostream>
+#include<fstream>
+#include<sstream>
+#include<lemon/color.h>
+#include<lemon/xy.h>
+
+  ///\ingroup io_group
+  ///\file
+  ///\brief Simple tool to create \c .eps files
+  ///
+  ///\author Alpar Juttner
+
+namespace lemon {
+  
+  ///\ingroup io_group
+  ///\brief A simple tool to create \c .eps files
+  ///
+  ///A simple tool to create \c .eps files
+  ///\author Alpar Juttner
+  class EpsDrawer
+  {
+    void defMacros();
+    void init(int x1,int y1,int x2,int y2);
+    void init(double x1,double y1,double x2,double y2);
+    bool local_stream;
+  public:
+    
+    std::ostream &out;
+    
+    ///\e 
+
+    ///The generated file is put to \c os.
+    ///
+    /// \c x and \c y determine the upper
+    ///right corner of the bounding box. The lower left corner is (0,0).
+    EpsDrawer(std::ostream &os,int x,int y);
+    ///\e
+
+    ///The generated file is put to \c os.
+    ///
+    ///(x1,y1) and (x2,y2)
+    /// determine the lower left and the upper right corners of
+    ///the bounding box, respectively.
+    EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2);
+    ///\e
+
+    ///The generated file is put to \c os.
+    ///
+    ///\c s determines the upper
+    ///right corner of the bounding box. The lower left corner is (0,0).
+    EpsDrawer(std::ostream &os,xy<double> s);
+    ///\e
+
+    ///The generated file is put to \c os.
+    ///
+    ///\c a and \c b
+    /// determine the lower left and the upper right corners of
+    ///the bounding box, respectively.
+    EpsDrawer(std::ostream &os,xy<double> a, xy<double> b);
+    ///\e
+
+    ///The generated picture is put to the file \c name.
+    ///
+    ///\c x and \c y determine the upper
+    ///right corner of the bounding box. The lower left corner is (0,0).
+    EpsDrawer(const std::string &name,int x,int y);
+    ///\e
+
+    ///The generated picture is put to the file \c name.
+    ///
+    ///(x1,y1) and (x2,y2)
+    /// determine the lower left and the upper right corners of
+    ///the bounding box, respectively.
+    EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2);
+    ///\e
+
+    ///The generated picture is put to the file \c name.
+    ///
+    ///\c s determines the upper
+    ///right corner of the bounding box. The lower left corner is (0,0).
+    EpsDrawer(const std::string &name,xy<double> s);
+    ///\e
+
+    ///The generated picture is put to the file \c name.
+    ///
+    ///\c a and \c b
+    /// determine the lower left and the upper right corners of
+    ///the bounding box, respectively.
+    EpsDrawer(const std::string &name,xy<double> a, xy<double> b);
+
+//     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b) 
+//     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b);
+    
+    ~EpsDrawer();
+    
+    ///Save the current graphic state.
+
+    ///This function saves the current coordinate system, and the parameters
+    ///set by \ref color(), \ref lineWidth() etc.
+    ///The can be \ref restore "restore()"d later.
+    ///
+    ///The \ref save() - \ref restore() pairs can be nested.
+    ///
+    EpsDrawer &save();
+    ///Restore the saves graphic state.
+
+    EpsDrawer &restore();
+    
+    ///Draw a line
+    EpsDrawer &line(double x1,double y1,double x2,double y2);
+    ///Draw a line from the current point
+    EpsDrawer &lineTo(double x1,double y1);
+    ///Move the current point
+    EpsDrawer &moveTo(double x1,double y1);
+    ///Draw a circle
+    EpsDrawer &circle(double x,double y, double r);
+    
+    ///Draw a line
+    template<class T> EpsDrawer &line(xy<T> p1,xy<T> p2) 
+    {
+      return line(p1.x,p1.y,p2.x,p2.y);
+    }
+    ///Draw a line from the current point
+    template<class T> EpsDrawer &lineTo(xy<T> p)
+    {
+      return lineTo(p.x,p.y);
+    }
+    ///Move the current point
+    template<class T> EpsDrawer &moveTo(xy<T> p)
+    {
+      return moveTo(p.x,p.y);
+    }
+    ///Draw a circle
+    template<class T> EpsDrawer &circle(xy<T> p, double r)
+    {
+      return circle(p.x,p.y,r);
+    }
+    
+    ///Set the font size
+    EpsDrawer &fontSize(double si);
+    ///Set the fint type
+    EpsDrawer &font(std::string );
+    ///Sets whether text output is centerized of not
+
+    ///Sets whether text output is centerized of not.
+    ///
+    ///\warning \ref save() doesn't save this setting.
+    ///
+    EpsDrawer &centerMode(bool m);
+    ///Turn to collect mode.
+
+    ///If you call this function, then the drawing operations like \ref line(),
+    ///\ref lineTo(), \ref moveTo() will not take place immediately, but istead
+    ///they
+    ///are collected. These operations form a \e path.
+    ///Then you can \ref stroke(), \ref fill(), \ref eofill(), \ref clip() or
+    ///\ref eoclip() it.
+    ///When drawing, you can also use \ref closePath() to - surprise - close the
+    ///current path.
+    ///
+    ///This example draws a red filled diamond.
+    ///\code
+    ///  EpsDraw ed("diamond.eps",-1,-1,1,1);
+    ///  ed.color(1,0,0,).collect().line(0,-1,1,0).lineTo(0,1)
+    ///    .lineTo(-1,0).closePath().fill();
+    ///\endcode
+    EpsDrawer &collect();
+    ///Close the current drawing path
+    EpsDrawer &closePath();
+    ///Stroke (draw) a path
+
+    ///Stroke (draw) a path.
+    ///\sa collect
+    ///
+    EpsDrawer &stroke();
+    ///Fill a path
+
+    ///Fill a path.
+    ///\sa collect
+    ///
+    EpsDrawer &fill();
+    ///Even-odd fill a path
+
+    ///Even-odd fill a path.
+    ///\sa collect
+    ///
+    EpsDrawer &eoFill();
+    ///Set a clipping area.
+
+    ///This function sets a clipping area. After that, the drawing operations
+    ///will affect only this area.
+    ///\sa collect
+    ///
+    EpsDrawer &clip();
+    ///Set a clipping area using even-odd rule.
+
+    ///This function sets a clipping area using even-odd rule.
+    ///After that, the drawing operations
+    ///will affect only this area.
+    ///\sa collect
+    ///
+    EpsDrawer &eoClip();
+    
+    ///Set the line width.
+    EpsDrawer &lineWidth(double w);
+    ///Set the style of the line ends
+
+    ///\param i It can be 0, 1 or 2
+    ///
+    EpsDrawer &lineCap(int i);
+    ///Set the style of the line joins
+
+    ///\param i It can be 0, 1 or 2
+    ///
+    EpsDrawer &lineJoin(int i);
+    ///Set the cut length of near parallel joining lines.
+    EpsDrawer &miterLimit(double w);
+    
+    ///Set the drawing color
+    EpsDrawer &color(double r, double g, double b);
+    ///Set the drawing color
+    EpsDrawer &color(Color c)
+    {
+      return color(c.red(),c.green(),c.blue());
+    }
+    
+    ///Translate the coordinate system
+    EpsDrawer &translate(double x,double y);
+    ///Translate the coordinate system
+    template<class T> EpsDrawer &translate(xy<T> p)
+    {
+      return translate(p.x,p.y);
+    }
+    ///Rotate the coordinate system
+    EpsDrawer &rotate(double r);
+    ///Scale the coordinate system
+    EpsDrawer &scale(double sx, double sy);
+    ///Scale the coordinate system
+    EpsDrawer &scale(double s) { return scale(s,s); }
+    ///Scale the coordinate system
+    template<class T> EpsDrawer &scale(xy<T> p)
+    {
+      return scale(p.x,p.y);
+    }
+    
+    ///\e
+    EpsDrawer &flush();
+    ///Clear the image
+    EpsDrawer &clear();
+    
+    ///Print a text at the current point
+    EpsDrawer &operator<<(const std::string &s);
+    ///Print a text at the current point
+    EpsDrawer &operator<<(const char *s);
+    ///Print a number at the current point
+    EpsDrawer &operator<<(int i);
+    ///Print a number at the current point
+    EpsDrawer &operator<<(double d);
+    ///Print a coordinate at the current point
+    template<class T>
+    EpsDrawer &operator<<(xy<T> p) 
+    {
+      out << "((" << p.x << ',' << p.y <<")) show\n";
+      return *this;
+    }
+    
+  };
+  
+}
+
+#endif

Modified: hugo/trunk/lemon/graph_to_eps.h
==============================================================================
--- hugo/trunk/lemon/graph_to_eps.h	(original)
+++ hugo/trunk/lemon/graph_to_eps.h	Mon Feb 20 07:41:12 2006
@@ -33,6 +33,7 @@
 #include<lemon/invalid.h>
 #include<lemon/xy.h>
 #include<lemon/maps.h>
+#include<lemon/color.h>
 #include<lemon/bezier.h>
 
 
@@ -44,133 +45,6 @@
 
 namespace lemon {
 
-///Data structure representing RGB colors.
-
-///Data structure representing RGB colors.
-///\ingroup misc
-class Color
-{
-  double _r,_g,_b;
-public:
-  ///Default constructor
-  Color() {}
-  ///Constructor
-  Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
-  ///Returns the red component
-  double & red() {return _r;}
-  ///Returns the red component
-  const double & red() const {return _r;}
-  ///Returns the green component
-  double & green() {return _g;}
-  ///Returns the green component
-  const double & green() const {return _g;}
-  ///Returns the blue component
-  double & blue() {return _b;}
-  ///Returns the blue component
-  const double & blue() const {return _b;}
-  ///Set the color components
-  void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
-};
-
-///Maps <tt>int</tt>s to different \ref Color "Color"s
-
-///This map assigns one of the predefined \ref Color "Color"s
-///to each <tt>int</tt>. It is possible to change the colors as well as their
-///number. The integer range is cyclically mapped to the provided set of colors.
-///
-///This is a true \ref concept::ReferenceMap "reference map", so you can also
-///change the actual colors.
-
-class ColorSet : public MapBase<int,Color>
-{
-  std::vector<Color> colors;
-public:
-  ///Constructor
-
-  ///Constructor
-  ///\param have_white indicates whether white is
-  ///amongst the provided color (\c true) or not (\c false). If it is true,
-  ///white will be assigned to \c 0.
-  ///\param num the number of the allocated colors. If it is \c 0
-  ///the default color configuration is set up (26 color plus the while).
-  ///If \c num is less then 26/27 then the default color list is cut. Otherwise
-  ///the color list is filled repeatedly with the default color list.
-  ///(The colors can be changed later on.)
-  ColorSet(bool have_white=false,int num=0)
-  {
-    do {
-      if(have_white) colors.push_back(Color(1,1,1));
-
-      colors.push_back(Color(0,0,0));
-      colors.push_back(Color(1,0,0));
-      colors.push_back(Color(0,1,0));
-      colors.push_back(Color(0,0,1));
-      colors.push_back(Color(1,1,0));
-      colors.push_back(Color(1,0,1));
-      colors.push_back(Color(0,1,1));
-      
-      colors.push_back(Color(.5,0,0));
-      colors.push_back(Color(0,.5,0));
-      colors.push_back(Color(0,0,.5));
-      colors.push_back(Color(.5,.5,0));
-      colors.push_back(Color(.5,0,.5));
-      colors.push_back(Color(0,.5,.5));
-      
-      colors.push_back(Color(.5,.5,.5));
-      colors.push_back(Color(1,.5,.5));
-      colors.push_back(Color(.5,1,.5));
-      colors.push_back(Color(.5,.5,1));
-      colors.push_back(Color(1,1,.5));
-      colors.push_back(Color(1,.5,1));
-      colors.push_back(Color(.5,1,1));
-      
-      colors.push_back(Color(1,.5,0));
-      colors.push_back(Color(.5,1,0));
-      colors.push_back(Color(1,0,.5));
-      colors.push_back(Color(0,1,.5));
-      colors.push_back(Color(0,.5,1));
-      colors.push_back(Color(.5,0,1));
-    } while(int(colors.size())<num);
-    //    colors.push_back(Color(1,1,1));
-    if(num>0) colors.resize(num);
-  }
-  ///\e
-  Color &operator[](int i)
-  {
-    return colors[i%colors.size()];
-  }
-  ///\e
-  const Color &operator[](int i) const
-  {
-    return colors[i%colors.size()];
-  }
-  ///\e
-  void set(int i,const Color &c)
-  {
-    colors[i%colors.size()]=c;
-  }
-  ///Sets the number of the exiting colors.
-  void resize(int s) { colors.resize(s);}
-  ///Returns the number of the existing colors.
-  std::size_t size() const { return colors.size();}
-};
-
-///Returns a visible distinct \ref Color
-
-///Returns a \ref Color which is as different from the given parameter
-///as it is possible.
-inline Color distantColor(const Color &c) 
-{
-  return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
-}
-///Returns black for light colors and white for the dark ones.
-
-///Returns black for light colors and white for the dark ones.
-inline Color distantBW(const Color &c){
-  double v=(.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5?1:0;
-  return Color(v,v,v);
-}
-
 template<class MT>
 class _NegY {
 public:



More information about the Lemon-commits mailing list