[Lemon-commits] deba: r3230 - lemon/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Wed Mar 7 12:57:24 CET 2007


Author: deba
Date: Wed Mar  7 12:57:23 2007
New Revision: 3230

Modified:
   lemon/trunk/lemon/color.h

Log:
Little interface improvment



Modified: lemon/trunk/lemon/color.h
==============================================================================
--- lemon/trunk/lemon/color.h	(original)
+++ lemon/trunk/lemon/color.h	Wed Mar  7 12:57:23 2007
@@ -33,35 +33,35 @@
 namespace lemon {
 
 
-/// \addtogroup misc
-/// @{
+  /// \addtogroup misc
+  /// @{
 
-///Data structure representing RGB colors.
+  ///Data structure representing RGB colors.
 
-///Data structure representing RGB colors.
-class Color
-{
-  double _r,_g,_b;
-public:
-  ///Default constructor
-  Color() {}
-  ///Constructor
-  Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
-  ///Set the red component
-  double & red() {return _r;}
-  ///Return the red component
-  const double & red() const {return _r;}
-  ///Set the green component
-  double & green() {return _g;}
-  ///Return the green component
-  const double & green() const {return _g;}
-  ///Set the blue component
-  double & blue() {return _b;}
-  ///Return 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; };
-};
+  ///Data structure representing RGB colors.
+  class Color
+  {
+    double _r,_g,_b;
+  public:
+    ///Default constructor
+    Color() {}
+    ///Constructor
+    Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
+    ///Set the red component
+    double & red() {return _r;}
+    ///Return the red component
+    const double & red() const {return _r;}
+    ///Set the green component
+    double & green() {return _g;}
+    ///Return the green component
+    const double & green() const {return _g;}
+    ///Set the blue component
+    double & blue() {return _b;}
+    ///Return 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; };
+  };
 
   /// White color constant
   extern const Color WHITE;  
@@ -94,105 +94,113 @@
   /// Dark cyan color constant
   extern const Color DARK_CYAN;
 
-///Map <tt>int</tt>s to different \ref Color "Color"s
+  ///Map <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 concepts::ReferenceMap "reference map", so you can also
-///change the actual colors.
-
-class Palette : 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 white).
-  ///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.)
-  Palette(bool have_white=false,int num=0)
-  {
-    do {
-      if(have_white) colors.push_back(Color(1,1,1));
+  ///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 concepts::ReferenceMap "reference map", so
+  ///you can also change the actual colors.
 
-      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));
+  class Palette : public MapBase<int,Color>
+  {
+    std::vector<Color> colors;
+  public:
+    ///Constructor
+
+    ///Constructor 
+    ///\param num the number of the allocated colors. If it is \c -1,
+    ///the default color configuration is set up (26 color plus the
+    ///white).  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.)
+    ///\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.
+    Palette(int num=-1,bool have_white=false)
+    {
+      if (num==0) return;
+      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,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(.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)
+        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;
+    }
+    ///\e
+    void add(const Color &c) 
+    {
+      colors.push_back(c);
+    }
+
+    ///Sets the number of the exiting colors.
+    void resize(int s) { colors.resize(s);}
+    ///Returns the number of the existing colors.
+    int size() const { return int(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 colors[i%colors.size()];
+    return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
   }
-  ///\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;
+  ///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){
+    return (.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5 ? WHITE : BLACK;
   }
-  ///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){
-  return (.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5 ? WHITE : BLACK;
-}
 
-/// @}
+  /// @}
 
 } //END OF NAMESPACE LEMON
 



More information about the Lemon-commits mailing list