Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

DrawingColor.h

Go to the documentation of this file.
00001 
00002 //
00003 // This file is part of the MADELINE 2 program 
00004 // written by Edward H. Trager, Ritu Khanna and Adrian Marrs
00005 // Copyright (c) 2005 by the
00006 // Regents of the University of Michigan.
00007 // All Rights Reserved.
00008 // 
00009 // The latest version of this program is available from:
00010 // 
00011 //   http://eyegene.ophthy.med.umich.edu/madeline/
00012 //   
00013 // Released under the GNU General Public License.
00014 // A copy of the GPL is included in the distribution
00015 // package of this software, or see:
00016 // 
00017 //   http://www.gnu.org/copyleft/
00018 //   
00019 // ... for licensing details.
00020 // 
00022 //
00023 // 2006.11.16.ET.
00024 //
00025 
00026 //
00027 // DrawingColor.h
00028 //
00029 #ifndef DrawingColor_INCLUDED
00030 #define DrawingColor_INCLUDED
00031 
00032 #include <string>
00033 #include <sstream>
00034 #include <strings.h>
00035 
00037 //
00038 // DrawingColor
00039 //
00041 class DrawingColor {
00042 public:
00043         
00044         // RGB constructor:
00045         DrawingColor(const std::string &name="white",unsigned char red=255,unsigned char green=255,unsigned char blue=255);
00046         // Postscript or HTML-style hex triplet constructor:
00047         DrawingColor(const std::string &name,const std::string &postScriptOrHexTriplet);
00048         // HSV Constructor: Note 0<=h<=360, 0<=s<=1, 0<=v<=1 :
00049         DrawingColor(const std::string &name,double h,double s, double v);
00050         
00051         // Comparison functor:
00052         struct compare
00053         {
00054                 bool operator()(const DrawingColor & c1, const DrawingColor & c2) const
00055                 {
00056                         return strcasecmp(c1._name.c_str(), c2._name.c_str() ) < 0;
00057                 }
00058         };
00059         
00060         void set(unsigned char red, unsigned char green, unsigned char blue);
00061         void set(const std::string &color);
00062         void setFromHSV(double h, double s, double v);
00063         std::string get(void) const;
00064         std::string getName(void) const;
00065         std::string getComplement(void) const;
00066         std::string getPostscript(void) const;
00067         bool useBlackInk(void) const;
00068         
00069         static void setCutoffAdjustment(double value);
00070         static double getCutoffAdjustment(void);
00071         
00072         double getHue(void)        const {return _h;};
00073         double getSaturation(void) const {return _s;};
00074         double getValue(void)      const {return _v;};
00075         // DEBUG only:
00076         //void printColor(void){ std::cout << "Color: " << std::hex << (int)_red << ":" << std::hex << (int)_green << ":" << std::hex << (int)_blue << std::endl; };
00077         
00078 private:
00079         
00080         //friend class DrawingMetricsLoader;
00081         
00082         std::string   _name;
00083         // RGB model:
00084         unsigned char _red;   // Range: [0,255]
00085         unsigned char _green; // Range: [0,255]
00086         unsigned char _blue;  // Range: [0,255]
00087         
00088         //HSV model:
00089         double _h; // Range [0,360] degrees
00090         double _s; // Range [0,1]
00091         double _v; // Range [0,1]
00092         
00093         //
00094         // static lookup table for determining
00095         // whether a label printed on a colored
00096         // background should be printed using 
00097         // black or white ink.  The 36 entries
00098         // represent 10-degree increment hue
00099         // "buckets":
00100         // 
00101         static int _cutoff[36];
00102         
00103         //
00104         // Because different screens and printers
00105         // will render / print colors differently,
00106         // manual adjustment of the _cutoff entries
00107         // may be necessary, either up or down:
00108         // 
00109         static double _cutoffAdjustment;
00110         
00111         void _setColorFromString(const std::string &color);
00112         void _calculateHSV(void);
00113         
00114         unsigned char _hexCharacterToInt(const char digit);
00115         std::string   _intToHexString(unsigned char v) const;
00116 };
00117 
00118 std::ostream& operator<<(std::ostream& s, const DrawingColor& color);
00119 
00120 #endif
00121 

Generated on Fri Nov 18 16:24:39 2011 for MADELINE by  doxygen 1.4.4