Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

color.H

Go to the documentation of this file.
00001 #ifndef _COLOR_H_INC
00002 #define _COLOR_H_INC
00003 #include "mlib/points.H"
00004 
00005 
00006 class COLOR;
00007 class HSVCOLOR;
00008 
00009 typedef const class COLOR     CCOLOR;
00010 typedef const class HSVCOLOR  CHSVCOLOR;
00011 
00012 /* ------------------ class definitions --------------------- */
00013 
00014 class COLVEC : public mlib::Vec3<COLVEC> {
00015  public :
00016    COLVEC() { }
00017    COLVEC(double x, double y, double z)
00018       : mlib::Vec3<COLVEC>(x,y,z) { }
00019 };
00020 
00021 class COLOR : public mlib::Point3<COLOR, COLVEC> {
00022  protected:
00023 
00024  public :
00025    COLOR() { }
00026    COLOR(double x, double y, double z)
00027       : mlib::Point3<COLOR,COLVEC>(x,y,z) { }
00028    COLOR(const double col[4])
00029       : mlib::Point3<COLOR,COLVEC>(col[0],col[1],col[2]) {}
00030    COLOR(CHSVCOLOR &c);
00031    static inline COLOR any()  { return COLOR(.5 + drand48()/2, 
00032                                              .5 + drand48()/2, 
00033                                              .5 + drand48()/2); }
00034    static COLOR random() { return COLOR(drand48(), drand48(), drand48()); }
00035 
00036    double luminance()     const { return .30*_x + .59*_y + .11*_z; }
00037 
00038    // returns linear blend between this color and dest. amount should
00039    // be between 0 and 1
00040    COLOR blend(CCOLOR& dest, double amount) const { 
00041       return COLOR(dest[0]*amount + (1.0-amount)*_x, 
00042                    dest[1]*amount + (1.0-amount)*_y, 
00043                    dest[2]*amount + (1.0-amount)*_z);
00044    }
00045 
00046    // basic color constants:
00047    // (more are defined in colors.H):
00048    static CCOLOR     black;     // 0 0 0
00049    static CCOLOR     white;     // 1 1 1
00050 
00051    static CCOLOR       red;     // 1 0 0
00052    static CCOLOR     green;     // 0 1 0
00053    static CCOLOR      blue;     // 0 0 1
00054 };
00055 
00056 
00057 #ifdef JOT_NEEDS_DOUBLE_STAR_EXPLICIT
00058 // Should be able to define this once for Point3, but that doesn't work
00059 // (then again, we have to do this because of template problems in the first
00060 // place)
00061 inline COLOR operator *(double s, const COLOR& p) { return p * s;}
00062 #endif
00063 
00064 
00065 #define CHSVCOLOR const HSVCOLOR
00066 class HSVCOLVEC : public mlib::Vec3<HSVCOLVEC> {
00067  public :
00068    HSVCOLVEC() { }
00069    HSVCOLVEC(double h, double s, double v)
00070       : mlib::Vec3<HSVCOLVEC>(h,s,v) { }
00071 };
00072 
00073 class HSVCOLOR : public mlib::Point3<HSVCOLOR, HSVCOLVEC> {
00074  public :
00075    HSVCOLOR() { }
00076    HSVCOLOR(double h, double s, double v)
00077       : mlib::Point3<HSVCOLOR,HSVCOLVEC>(h,s,v) { }
00078    HSVCOLOR(const double col[4])
00079       : mlib::Point3<HSVCOLOR,HSVCOLVEC>(col[0],col[1],col[2]) { }
00080    HSVCOLOR(CCOLOR &c);
00081 };
00082 
00083 
00084 #ifdef JOT_NEEDS_DOUBLE_STAR_EXPLICIT
00085 // Should be able to define this once for Point3, but that doesn't work
00086 // (then again, we have to do this because of template problems in the first
00087 // place)
00088 inline HSVCOLOR operator *(double s, const HSVCOLOR& p) { return p * s;}
00089 #endif
00090 
00091 #endif // _COLOR_H_INC
00092 
00093 // end of file color.H
00094 

Generated on Mon Sep 18 11:39:29 2006 for jot by  doxygen 1.4.4