11 #include <boost/utility.hpp>
18 class Color : boost::noncopyable
22 typedef NUKLEI_UNIQUE_PTR< Color > ptr;
24 typedef enum { RGB = 0, HSV, HSVCONE, UNKNOWN } Type;
25 static const Type defaultType = RGB;
26 static const std::string TypeNames[];
30 virtual void assertConsistency()
const = 0;
32 virtual NUKLEI_UNIQUE_PTR<Color> clone()
const = 0;
33 virtual NUKLEI_UNIQUE_PTR<Color> create()
const = 0;
36 virtual appear_t getMaxDist()
const = 0;
38 virtual void makeRandom() = 0;
40 virtual GVector getVector()
const = 0;
41 virtual void setVector(
const GVector &v) = 0;
44 friend class NUKLEI_SERIALIZATION_FRIEND_CLASSNAME;
45 template<
class Archive>
46 void serialize(Archive &ar,
const unsigned int version)
53 return d.clone().release();
59 typedef NUKLEI_UNIQUE_PTR< RGBColor > ptr;
61 RGBColor() : c_(0, 0, 0) {assertConsistency();}
63 RGBColor(
const Vector3 &rgb) : c_(rgb) {assertConsistency();}
68 NUKLEI_UNIQUE_PTR<Color> clone()
const {
return NUKLEI_UNIQUE_PTR<Color>(
new RGBColor(c_)); }
69 NUKLEI_UNIQUE_PTR<Color> create()
const {
return NUKLEI_UNIQUE_PTR<Color>(NUKLEI_MOVE(
new RGBColor)); }
71 void assertConsistency()
const
73 NUKLEI_RANGE_CHECK(R(), 0, 1);
74 NUKLEI_RANGE_CHECK(G(), 0, 1);
75 NUKLEI_RANGE_CHECK(B(), 0, 1);
79 appear_t R()
const {
return c_.X(); }
81 appear_t G()
const {
return c_.Y(); }
83 appear_t B()
const {
return c_.Z(); }
85 Vector3 getRGB()
const {
return c_; }
86 void setRGB(
const Vector3& c) { c_ = c; }
93 return distanceTo(
dynamic_cast<const RGBColor&
>(c));
97 return (c_-rgb.c_).Length();
99 appear_t getMaxDist()
const {
return MAX_DIST; }
103 GVector getVector()
const
105 return GVector(3, getRGB());
107 void setVector(
const GVector &v)
109 c_ = la::vector3Copy(v);
116 friend class NUKLEI_SERIALIZATION_FRIEND_CLASSNAME;
117 template<
class Archive>
118 void serialize(Archive &ar,
const unsigned int version)
120 ar & NUKLEI_SERIALIZATION_MAKE_NVP
122 NUKLEI_SERIALIZATION_BASE(
Color) );
123 ar & NUKLEI_SERIALIZATION_NVP(c_);
130 typedef NUKLEI_UNIQUE_PTR< HSVColor > ptr;
132 HSVColor() : c_(0, 0, 0) {assertConsistency();}
134 HSVColor(
const Vector3 &hsv) : c_(hsv) {assertConsistency();}
137 NUKLEI_UNIQUE_PTR<Color> clone()
const {
return NUKLEI_UNIQUE_PTR<Color>(
new HSVColor(c_)); }
138 NUKLEI_UNIQUE_PTR<Color> create()
const {
return NUKLEI_UNIQUE_PTR<Color>(NUKLEI_MOVE(
new HSVColor)); }
140 void assertConsistency()
const
142 NUKLEI_RANGE_CHECK(H(), 0, 2*M_PI);
143 NUKLEI_RANGE_CHECK(S(), 0, 1);
144 NUKLEI_RANGE_CHECK(V(), 0, 1);
148 appear_t H()
const {
return c_.X(); }
150 appear_t S()
const {
return c_.Y(); }
152 appear_t V()
const {
return c_.Z(); }
154 Vector3 getHSV()
const {
return c_; }
155 void setHSV(
const Vector3& c) { c_ = c; }
162 appear_t getMaxDist()
const {
return MAX_DIST; }
166 GVector getVector()
const
168 return GVector(3, getHSV());
170 void setVector(
const GVector &v)
172 c_ = la::vector3Copy(v);
179 friend class NUKLEI_SERIALIZATION_FRIEND_CLASSNAME;
180 template<
class Archive>
181 void serialize(Archive &ar,
const unsigned int version)
183 ar & NUKLEI_SERIALIZATION_MAKE_NVP
185 NUKLEI_SERIALIZATION_BASE(
Color) );
186 ar & NUKLEI_SERIALIZATION_NVP(c_);
193 typedef NUKLEI_UNIQUE_PTR< HSVConeColor > ptr;
195 HSVConeColor() : c_(0, 0, 0), valueWeight_(1) {assertConsistency();}
197 c_(sch, ssh, weightedValue), valueWeight_(valueWeight) {assertConsistency();}
198 HSVConeColor(
const Vector3 &c,
appear_t valueWeight = 1) : c_(c), valueWeight_(valueWeight) {assertConsistency();}
201 NUKLEI_UNIQUE_PTR<Color> clone()
const {
return NUKLEI_UNIQUE_PTR<Color>(
new HSVConeColor(c_)); }
202 NUKLEI_UNIQUE_PTR<Color> create()
const {
return NUKLEI_UNIQUE_PTR<Color>(NUKLEI_MOVE(
new HSVConeColor)); }
204 void assertConsistency()
const
206 NUKLEI_RANGE_CHECK(SCosH(), -1, 1);
207 NUKLEI_RANGE_CHECK(SSinH(), -1, 1);
208 NUKLEI_RANGE_CHECK(WV(), 0, 1);
211 appear_t& SCosH() {
return c_.X(); }
212 appear_t SCosH()
const {
return c_.X(); }
213 appear_t& SSinH() {
return c_.Y(); }
214 appear_t SSinH()
const {
return c_.Y(); }
216 appear_t WV()
const {
return c_.Z(); }
217 appear_t& W() {
return valueWeight_; }
218 appear_t W()
const {
return valueWeight_; }
220 Vector3 getHSVCone()
const {
return c_; }
221 void setHSVCone(
const Vector3& c) { c_ = c; }
222 appear_t getValueWeight()
const {
return valueWeight_; }
223 void setValueWeight(
const appear_t& valueWeight) { valueWeight_ = valueWeight; }
231 appear_t getMaxDist()
const {
return MAX_DIST; }
235 GVector getVector()
const
238 for (
int i = 0; i < 3; ++i) gv[i] = c_[i];
239 gv[3] = valueWeight_;
242 void setVector(
const GVector &v)
245 c_ = Vector3(v[0], v[1], v[2]);
254 friend class NUKLEI_SERIALIZATION_FRIEND_CLASSNAME;
255 template<
class Archive>
256 void serialize(Archive &ar,
const unsigned int version)
258 ar & NUKLEI_SERIALIZATION_MAKE_NVP
260 NUKLEI_SERIALIZATION_BASE(
Color) );
261 ar & NUKLEI_SERIALIZATION_NVP(c_) & NUKLEI_SERIALIZATION_NVP(valueWeight_);