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
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
00039
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
00047
00048 static CCOLOR black;
00049 static CCOLOR white;
00050
00051 static CCOLOR red;
00052 static CCOLOR green;
00053 static CCOLOR blue;
00054 };
00055
00056
00057 #ifdef JOT_NEEDS_DOUBLE_STAR_EXPLICIT
00058
00059
00060
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
00086
00087
00088 inline HSVCOLOR operator *(double s, const HSVCOLOR& p) { return p * s;}
00089 #endif
00090
00091 #endif // _COLOR_H_INC
00092
00093
00094