Color.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: Color.hpp 1644 2009-01-27 19:26:14Z ckiesch $"
00002 
00004 
00005 //============================================================================
00006 //
00007 //  This file is part of GPSTk, the GPS Toolkit.
00008 //
00009 //  The GPSTk is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU Lesser General Public License as published
00011 //  by the Free Software Foundation; either version 2.1 of the License, or
00012 //  any later version.
00013 //
00014 //  The GPSTk is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 //  GNU Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with GPSTk; if not, write to the Free Software Foundation,
00021 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //  
00023 //  Copyright 2004, The University of Texas at Austin
00024 //
00025 //============================================================================
00026 
00027 
00028 #ifndef VDRAW_COLOR_H
00029 #define VDRAW_COLOR_H
00030 
00031 #include<string>
00032 #include<list>
00033 #include<cstdlib>
00034 
00035 namespace vdraw
00036 {
00039 
00044   class Color {
00045 
00046     public:
00047 
00054 
00055       static const int RED          = 0xFF0000; 
00057       static const int ORANGE       = 0xFFA500;
00059       static const int YELLOW       = 0xFFFF00;
00061       static const int GREEN        = 0x00FF00;
00063       static const int BLUE         = 0x0000FF;
00065       static const int VIOLET       = 0xEE82EE;
00067       static const int WHITE        = 0xFFFFFF;
00069       static const int BROWN        = 0xA5252A;
00071       static const int BLACK        = 0x000000;
00073       static const int GREY         = 0xBEBEBE;
00075       static const int GRAY         = 0xBEBEBE;
00077       static const int PINK         = 0xFFC0CB;
00079       static const int CYAN         = 0x00FFFF;
00081       static const int OLIVE        = 0x6B8E23;
00083       static const int KHAKI        = 0xBDB76B;
00085       static const int SKY_BLUE     = 0x87CEEB;
00087       static const int TURQUOISE    = 0x40E0D0;
00089       static const int CHARTREUSE   = 0x7FFF00; 
00091       static const int MAGENTA      = 0xFF00FF;
00093       static const int MAROON       = 0xB03060;
00095       static const int BURNT_ORANGE = 0xCD5500;
00097       static const int CARDINAL     = 0x9C0001; // The color, NOT the bird...
00099       static const int NAVY         = 0x000080;
00101       static const int FOREST_GREEN = 0x228B22;
00103       static const int DARK_PURPLE  = 0x800080;
00105 
00111       static const int CLEAR        = -1;
00112 
00116       Color(void) : rgb(BLACK) {};
00117 
00123       Color(int rgbDef)
00124       {
00125         if(rgbDef != CLEAR)
00126           rgbDef &= 0xFFFFFF;
00127         rgb = rgbDef;
00128       };
00129 
00134       Color(int red, int green, int blue) 
00135       {
00136         if( red < 0 ) red = 0;
00137         else if( red > 0xFF ) red = 0xFF;
00138         if( green < 0 ) green = 0;
00139         else if( green > 0xFF ) green = 0xFF;
00140         if( blue < 0 ) blue = 0;
00141         else if( blue > 0xFF ) blue = 0xFF;
00142         rgb = (red << 16) | (green << 8) | blue;
00143       };
00144 
00151       Color(const std::string& colorName) { setToString(colorName); }; 
00152 
00154       bool operator==(const Color& rhs) const {return (rgb==rhs.rgb);};
00155 
00157       bool operator!=(const Color& rhs) const {return (rgb!=rhs.rgb);};
00158 
00186       void setToString( const std::string& str);
00187 
00192       int getRGB( void ) const { return rgb; };
00193 
00200       void getRGBTriplet( short& red, short& green, short& blue ) const;
00201 
00209       void getRGBTripletFractional( double& red, double& green, 
00210           double& blue ) const;
00211 
00218       void setRGBTriplet( short red, short green, short blue );
00219 
00226       void setRGBTripletFractional( double red, double green, double blue );
00227 
00228       
00230       inline int dist(const Color& o) const
00231       {
00232         short r,g,b,ro,go,bo;
00233         this->getRGBTriplet(r,g,b);
00234         o.getRGBTriplet(ro,go,bo);
00235         return abs(r-ro)+abs(g-go)+abs(b-bo);
00236       }
00237 
00241       Color interpolate(double dist, const Color &o) const;
00242 
00247       bool isClear( void ) const { return rgb == CLEAR; }
00248 
00249     protected:
00250 
00252       int rgb;
00253 
00254     private:
00255 
00256   }; // class Color
00257 
00259 
00260 } // namespace vdraw
00261 
00262 #endif //VDRAW_COLOR_H
00263 

Generated on Wed Feb 8 03:30:58 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1