lemon/graph_to_eps.h
changeset 1975 64db671eda28
parent 1956 a055123339d5
child 1976 a71f388045f9
equal deleted inserted replaced
19:66a5b654af28 20:0a236df28d1d
    31 #include <cmath>
    31 #include <cmath>
    32 
    32 
    33 #include<lemon/invalid.h>
    33 #include<lemon/invalid.h>
    34 #include<lemon/xy.h>
    34 #include<lemon/xy.h>
    35 #include<lemon/maps.h>
    35 #include<lemon/maps.h>
       
    36 #include<lemon/color.h>
    36 #include<lemon/bezier.h>
    37 #include<lemon/bezier.h>
    37 
    38 
    38 
    39 
    39 ///\ingroup io_group
    40 ///\ingroup io_group
    40 ///\file
    41 ///\file
    41 ///\brief Simple graph drawer
    42 ///\brief Simple graph drawer
    42 ///
    43 ///
    43 ///\author Alpar Juttner
    44 ///\author Alpar Juttner
    44 
    45 
    45 namespace lemon {
    46 namespace lemon {
    46 
       
    47 ///Data structure representing RGB colors.
       
    48 
       
    49 ///Data structure representing RGB colors.
       
    50 ///\ingroup misc
       
    51 class Color
       
    52 {
       
    53   double _r,_g,_b;
       
    54 public:
       
    55   ///Default constructor
       
    56   Color() {}
       
    57   ///Constructor
       
    58   Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
       
    59   ///Returns the red component
       
    60   double & red() {return _r;}
       
    61   ///Returns the red component
       
    62   const double & red() const {return _r;}
       
    63   ///Returns the green component
       
    64   double & green() {return _g;}
       
    65   ///Returns the green component
       
    66   const double & green() const {return _g;}
       
    67   ///Returns the blue component
       
    68   double & blue() {return _b;}
       
    69   ///Returns the blue component
       
    70   const double & blue() const {return _b;}
       
    71   ///Set the color components
       
    72   void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
       
    73 };
       
    74 
       
    75 ///Maps <tt>int</tt>s to different \ref Color "Color"s
       
    76 
       
    77 ///This map assigns one of the predefined \ref Color "Color"s
       
    78 ///to each <tt>int</tt>. It is possible to change the colors as well as their
       
    79 ///number. The integer range is cyclically mapped to the provided set of colors.
       
    80 ///
       
    81 ///This is a true \ref concept::ReferenceMap "reference map", so you can also
       
    82 ///change the actual colors.
       
    83 
       
    84 class ColorSet : public MapBase<int,Color>
       
    85 {
       
    86   std::vector<Color> colors;
       
    87 public:
       
    88   ///Constructor
       
    89 
       
    90   ///Constructor
       
    91   ///\param have_white indicates whether white is
       
    92   ///amongst the provided color (\c true) or not (\c false). If it is true,
       
    93   ///white will be assigned to \c 0.
       
    94   ///\param num the number of the allocated colors. If it is \c 0
       
    95   ///the default color configuration is set up (26 color plus the while).
       
    96   ///If \c num is less then 26/27 then the default color list is cut. Otherwise
       
    97   ///the color list is filled repeatedly with the default color list.
       
    98   ///(The colors can be changed later on.)
       
    99   ColorSet(bool have_white=false,int num=0)
       
   100   {
       
   101     do {
       
   102       if(have_white) colors.push_back(Color(1,1,1));
       
   103 
       
   104       colors.push_back(Color(0,0,0));
       
   105       colors.push_back(Color(1,0,0));
       
   106       colors.push_back(Color(0,1,0));
       
   107       colors.push_back(Color(0,0,1));
       
   108       colors.push_back(Color(1,1,0));
       
   109       colors.push_back(Color(1,0,1));
       
   110       colors.push_back(Color(0,1,1));
       
   111       
       
   112       colors.push_back(Color(.5,0,0));
       
   113       colors.push_back(Color(0,.5,0));
       
   114       colors.push_back(Color(0,0,.5));
       
   115       colors.push_back(Color(.5,.5,0));
       
   116       colors.push_back(Color(.5,0,.5));
       
   117       colors.push_back(Color(0,.5,.5));
       
   118       
       
   119       colors.push_back(Color(.5,.5,.5));
       
   120       colors.push_back(Color(1,.5,.5));
       
   121       colors.push_back(Color(.5,1,.5));
       
   122       colors.push_back(Color(.5,.5,1));
       
   123       colors.push_back(Color(1,1,.5));
       
   124       colors.push_back(Color(1,.5,1));
       
   125       colors.push_back(Color(.5,1,1));
       
   126       
       
   127       colors.push_back(Color(1,.5,0));
       
   128       colors.push_back(Color(.5,1,0));
       
   129       colors.push_back(Color(1,0,.5));
       
   130       colors.push_back(Color(0,1,.5));
       
   131       colors.push_back(Color(0,.5,1));
       
   132       colors.push_back(Color(.5,0,1));
       
   133     } while(int(colors.size())<num);
       
   134     //    colors.push_back(Color(1,1,1));
       
   135     if(num>0) colors.resize(num);
       
   136   }
       
   137   ///\e
       
   138   Color &operator[](int i)
       
   139   {
       
   140     return colors[i%colors.size()];
       
   141   }
       
   142   ///\e
       
   143   const Color &operator[](int i) const
       
   144   {
       
   145     return colors[i%colors.size()];
       
   146   }
       
   147   ///\e
       
   148   void set(int i,const Color &c)
       
   149   {
       
   150     colors[i%colors.size()]=c;
       
   151   }
       
   152   ///Sets the number of the exiting colors.
       
   153   void resize(int s) { colors.resize(s);}
       
   154   ///Returns the number of the existing colors.
       
   155   std::size_t size() const { return colors.size();}
       
   156 };
       
   157 
       
   158 ///Returns a visible distinct \ref Color
       
   159 
       
   160 ///Returns a \ref Color which is as different from the given parameter
       
   161 ///as it is possible.
       
   162 inline Color distantColor(const Color &c) 
       
   163 {
       
   164   return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
       
   165 }
       
   166 ///Returns black for light colors and white for the dark ones.
       
   167 
       
   168 ///Returns black for light colors and white for the dark ones.
       
   169 inline Color distantBW(const Color &c){
       
   170   double v=(.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5?1:0;
       
   171   return Color(v,v,v);
       
   172 }
       
   173 
    47 
   174 template<class MT>
    48 template<class MT>
   175 class _NegY {
    49 class _NegY {
   176 public:
    50 public:
   177   typedef typename MT::Key Key;
    51   typedef typename MT::Key Key;