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 
00036 //
00037 // DrawingColor
00038 //
00040 class DrawingColor {
00041 public:
00042         
00043         // RGB constructor:
00044         DrawingColor(const std::string &name="white",unsigned char red=255,unsigned char green=255,unsigned char blue=255);
00045         // Postscript or HTML-style hex triplet constructor:
00046         DrawingColor(const std::string &name,const std::string &postScriptOrHexTriplet);
00047         // HSV Constructor: Note 0<=h<=360, 0<=s<=1, 0<=v<=1 :
00048         DrawingColor(const std::string &name,double h,double s, double v);
00049         
00050         // Comparison functor:
00051         struct compare
00052         {
00053                 bool operator()(const DrawingColor & c1, const DrawingColor & c2) const
00054                 {
00055                         return strcasecmp(c1._name.c_str(), c2._name.c_str() ) < 0;
00056                 }
00057         };
00058         
00059         void set(unsigned char red, unsigned char green, unsigned char blue);
00060         void set(const std::string &color);
00061         void setFromHSV(double h, double s, double v);
00062         std::string get(void) const;
00063         std::string getName(void) const;
00064         std::string getComplement(void) const;
00065         std::string getPostscript(void) const;
00066         bool useBlackInk(void) const;
00067         
00068         static void setCutoffAdjustment(double value);
00069         static double getCutoffAdjustment(void);
00070         
00071         double getHue(void)        const {return _h;};
00072         double getSaturation(void) const {return _s;};
00073         double getValue(void)      const {return _v;};
00074         // DEBUG only:
00075         //void printColor(void){ std::cout << "Color: " << std::hex << (int)_red << ":" << std::hex << (int)_green << ":" << std::hex << (int)_blue << std::endl; };
00076         
00077 private:
00078         
00079         //friend class DrawingMetricsLoader;
00080         
00081         std::string   _name;
00082         // RGB model:
00083         unsigned char _red;   // Range: [0,255]
00084         unsigned char _green; // Range: [0,255]
00085         unsigned char _blue;  // Range: [0,255]
00086         
00087         //HSV model:
00088         double _h; // Range [0,360] degrees
00089         double _s; // Range [0,1]
00090         double _v; // Range [0,1]
00091         
00092         //
00093         // static lookup table for determining
00094         // whether a label printed on a colored
00095         // background should be printed using 
00096         // black or white ink.  The 36 entries
00097         // represent 10-degree increment hue
00098         // "buckets":
00099         // 
00100         static int _cutoff[36];
00101         
00102         //
00103         // Because different screens and printers
00104         // will render / print colors differently,
00105         // manual adjustment of the _cutoff entries
00106         // may be necessary, either up or down:
00107         // 
00108         static double _cutoffAdjustment;
00109         
00110         void _setColorFromString(const std::string &color);
00111         void _calculateHSV(void);
00112         
00113         unsigned char _hexCharacterToInt(const char digit);
00114         std::string   _intToHexString(unsigned char v) const;
00115 };
00116 
00117 std::ostream& operator<<(std::ostream& s, const DrawingColor& color);
00118 
00119 #endif
00120 

Generated on Tue Feb 27 14:39:23 2007 for MINIMADELINE by  doxygen 1.4.4