lemon/color.h
changeset 306 2bf7c645d5a6
parent 206 4e22275a2b52
child 313 64f8f7cc6168
equal deleted inserted replaced
4:b318b780a7e5 5:7eddb289b614
     1 /* -*- C++ -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2008
     5  * Copyright (C) 2003-2008
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
    60     ///Set the color components
    60     ///Set the color components
    61     void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
    61     void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
    62   };
    62   };
    63 
    63 
    64   /// White color constant
    64   /// White color constant
    65   extern const Color WHITE;  
    65   extern const Color WHITE;
    66   /// Black color constant
    66   /// Black color constant
    67   extern const Color BLACK;
    67   extern const Color BLACK;
    68   /// Red color constant
    68   /// Red color constant
    69   extern const Color RED;
    69   extern const Color RED;
    70   /// Green color constant
    70   /// Green color constant
   128         colors.push_back(Color(0,1,0));
   128         colors.push_back(Color(0,1,0));
   129         colors.push_back(Color(0,0,1));
   129         colors.push_back(Color(0,0,1));
   130         colors.push_back(Color(1,1,0));
   130         colors.push_back(Color(1,1,0));
   131         colors.push_back(Color(1,0,1));
   131         colors.push_back(Color(1,0,1));
   132         colors.push_back(Color(0,1,1));
   132         colors.push_back(Color(0,1,1));
   133       
   133 
   134         colors.push_back(Color(.5,0,0));
   134         colors.push_back(Color(.5,0,0));
   135         colors.push_back(Color(0,.5,0));
   135         colors.push_back(Color(0,.5,0));
   136         colors.push_back(Color(0,0,.5));
   136         colors.push_back(Color(0,0,.5));
   137         colors.push_back(Color(.5,.5,0));
   137         colors.push_back(Color(.5,.5,0));
   138         colors.push_back(Color(.5,0,.5));
   138         colors.push_back(Color(.5,0,.5));
   139         colors.push_back(Color(0,.5,.5));
   139         colors.push_back(Color(0,.5,.5));
   140       
   140 
   141         colors.push_back(Color(.5,.5,.5));
   141         colors.push_back(Color(.5,.5,.5));
   142         colors.push_back(Color(1,.5,.5));
   142         colors.push_back(Color(1,.5,.5));
   143         colors.push_back(Color(.5,1,.5));
   143         colors.push_back(Color(.5,1,.5));
   144         colors.push_back(Color(.5,.5,1));
   144         colors.push_back(Color(.5,.5,1));
   145         colors.push_back(Color(1,1,.5));
   145         colors.push_back(Color(1,1,.5));
   146         colors.push_back(Color(1,.5,1));
   146         colors.push_back(Color(1,.5,1));
   147         colors.push_back(Color(.5,1,1));
   147         colors.push_back(Color(.5,1,1));
   148       
   148 
   149         colors.push_back(Color(1,.5,0));
   149         colors.push_back(Color(1,.5,0));
   150         colors.push_back(Color(.5,1,0));
   150         colors.push_back(Color(.5,1,0));
   151         colors.push_back(Color(1,0,.5));
   151         colors.push_back(Color(1,0,.5));
   152         colors.push_back(Color(0,1,.5));
   152         colors.push_back(Color(0,1,.5));
   153         colors.push_back(Color(0,.5,1));
   153         colors.push_back(Color(0,.5,1));
   169     void set(int i,const Color &c)
   169     void set(int i,const Color &c)
   170     {
   170     {
   171       colors[i%colors.size()]=c;
   171       colors[i%colors.size()]=c;
   172     }
   172     }
   173     ///Adds a new color to the end of the color list.
   173     ///Adds a new color to the end of the color list.
   174     void add(const Color &c) 
   174     void add(const Color &c)
   175     {
   175     {
   176       colors.push_back(c);
   176       colors.push_back(c);
   177     }
   177     }
   178 
   178 
   179     ///Sets the number of the existing colors.
   179     ///Sets the number of the existing colors.
   184 
   184 
   185   ///Returns a visibly distinct \ref Color
   185   ///Returns a visibly distinct \ref Color
   186 
   186 
   187   ///Returns a \ref Color which is as different from the given parameter
   187   ///Returns a \ref Color which is as different from the given parameter
   188   ///as it is possible.
   188   ///as it is possible.
   189   inline Color distantColor(const Color &c) 
   189   inline Color distantColor(const Color &c)
   190   {
   190   {
   191     return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
   191     return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
   192   }
   192   }
   193   ///Returns black for light colors and white for the dark ones.
   193   ///Returns black for light colors and white for the dark ones.
   194 
   194