00001 #pragma ident "$Id: Palette.hpp 1644 2009-01-27 19:26:14Z ckiesch $"
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef VDRAW_PALETTE_H
00028 #define VDRAW_PALETTE_H
00029
00030 #include <algorithm>
00031
00032 #include "Color.hpp"
00033
00034 namespace vdraw
00035 {
00038
00046 class Palette
00047 {
00048 public:
00055 Palette(const Color &base=Color::BLACK, double imin=0.0, double imax=1.0);
00056
00058 Palette(const Palette &p);
00059
00061 Palette& operator=(Palette p);
00062
00064 ~Palette()
00065 {
00066 }
00067
00070 void setRange(double imin, double imax)
00071 {
00072 if(imax<imin)
00073 {
00074 min = imax;
00075 width=imin-imax;
00076 }
00077 else
00078 {
00079 min = imin;
00080 width = imax-imin;
00081 }
00082 }
00083
00085 void setColor(double val, const Color &c);
00086
00088 Color getColor(double val) const;
00089
00091 inline double getMin() const { return min; }
00092
00094 inline double getMax() const { return min+width; }
00095
00097 inline int getNumColors() const { return (int)palette.size(); }
00098
00099 protected:
00101 double min;
00102
00104 double width;
00105
00107 std::list<std::pair<double,Color> > palette;
00108
00110 inline void clamp(double &val) const
00111 {
00112 if(val<min) val=getMin();
00113 if(val>(min+width)) val=getMax();
00114 }
00115 };
00116
00118
00119 }
00120
00121 #endif // VDRAW_PALETTE_H
00122