00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGCOLOR_H_
00040 #define _OSGCOLOR_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include <OSGBase.h>
00046 #include <OSGBaseTypes.h>
00047 #include <iostream>
00048
00049 OSG_BEGIN_NAMESPACE
00050
00054 template <class ValueTypeT>
00055 class Color3
00056 {
00057
00058
00059 public:
00060
00061 typedef ValueTypeT ValueType;
00062
00063 static const Color3 Null;
00064
00065
00069 static void convertFromHSV( ValueType *rgbP,
00070 const Real32 h,
00071 const Real32 s,
00072 const Real32 v );
00073
00074
00075 static void convertToHSV (const ValueType *rgbP,
00076 Real32 &h,
00077 Real32 &s,
00078 Real32 &v );
00079
00080 static UInt32 minPart (const ValueType *rgbP);
00081 static UInt32 maxPart (const ValueType *rgbP);
00082
00084
00088 Color3( void );
00089 Color3(const Color3 &source);
00090 Color3( ValueType red,
00091 ValueType green,
00092 ValueType blue );
00093
00095
00099 ~Color3(void);
00100
00102
00106 void clear ( void );
00107
00108 void setValuesRGB(const ValueType red,
00109 const ValueType green,
00110 const ValueType blue );
00111
00112 void setValuesHSV(const Real32 h,
00113 const Real32 s,
00114 const Real32 v );
00115
00116 void setRandom ( void );
00117 void setRGB ( UInt32 rgbPack );
00118
00119 void setValue (const Char8 *szString);
00120 void setValue ( Char8 *szString);
00121
00123
00127 UInt32 getRGB (void ) const;
00128
00129 void getValuesRGB(ValueType &red,
00130 ValueType &green,
00131 ValueType &blue ) const;
00132
00133 void getValuesHSV(Real32 &h,
00134 Real32 &s,
00135 Real32 &v ) const;
00136
00137 ValueType red (void ) const;
00138 ValueType green (void ) const;
00139 ValueType blue (void ) const;
00140
00141 ValueType *getValuesRGB(void );
00142 const ValueType *getValuesRGB(void ) const;
00143
00144
00146
00150 Color3 operator * (const ValueType val );
00151 Color3 operator / (const ValueType val );
00152 Color3 operator + (const ValueType val );
00153 Color3 operator - (const ValueType val );
00154
00155 void operator *= (const ValueType val );
00156 void operator /= (const ValueType val );
00157 void operator += (const ValueType val );
00158 void operator -= (const ValueType val );
00159
00160 Color3 operator * (const Color3 &other ) const;
00161 Color3 operator / (const Color3 &other ) const;
00162 Color3 operator + (const Color3 &other ) const;
00163 Color3 operator - (const Color3 &other ) const;
00164
00165 void operator *=(const Color3 &other );
00166 void operator /=(const Color3 &other );
00167 void operator +=(const Color3 &other );
00168 void operator -=(const Color3 &other );
00169
00170
00171 ValueType &operator [](const UInt32 uiIndex );
00172 const ValueType &operator [](const UInt32 uiIndex ) const;
00173
00174 Color3 &operator =(const Color3 &source );
00175
00176 bool equals (const Color3 &other,
00177 const ValueType tolerance) const;
00178
00179 bool operator < (const Color3 &other ) const;
00180 bool operator ==(const Color3 &other ) const;
00181 bool operator !=(const Color3 &other ) const;
00182
00184
00185
00186 protected:
00187
00188 ValueType _rgb[3];
00189 };
00190
00194 template <class ValueTypeT>
00195 class Color4
00196 {
00197
00198 public:
00199
00200 typedef ValueTypeT ValueType;
00201
00202 static const Color4 Null;
00203
00204
00208 Color4( void );
00209 Color4(const Color4 &source);
00210 Color4(const ValueType red,
00211 const ValueType green,
00212 const ValueType blue,
00213 const ValueType alpha );
00214
00216
00220 ~Color4(void);
00221
00223
00227 void clear ( void );
00228
00229 void setValuesRGBA(const ValueType red,
00230 const ValueType green,
00231 const ValueType blue,
00232 const ValueType alpha);
00233
00234 void setValuesHSV (const Real32 h,
00235 const Real32 s,
00236 const Real32 v );
00237
00238 void setRandom ( void );
00239 void setRGBA ( UInt32 rgbPack );
00240
00241 void setValue (const Char8 *szString);
00242 void setValue ( Char8 *szString);
00243
00245
00249 UInt32 getRGBA (void ) const;
00250
00251 void getValuesRGBA (ValueType &red,
00252 ValueType &green,
00253 ValueType &blue,
00254 ValueType &alpha) const;
00255
00256 void getValuesHSV (Real32 &h,
00257 Real32 &s,
00258 Real32 &v ) const;
00259
00260 ValueType red (void ) const;
00261 ValueType green (void ) const;
00262 ValueType blue (void ) const;
00263 ValueType alpha (void ) const;
00264
00265 ValueType *getValuesRGBA(void );
00266 const ValueType *getValuesRGBA(void ) const;
00267
00268
00270
00274 Color4 operator * (const ValueType val );
00275 Color4 operator / (const ValueType val );
00276 Color4 operator + (const ValueType val );
00277 Color4 operator - (const ValueType val );
00278
00279 void operator *= (const ValueType val );
00280 void operator /= (const ValueType val );
00281 void operator += (const ValueType val );
00282 void operator -= (const ValueType val );
00283
00284 Color4 operator * (const Color4 &other ) const;
00285 Color4 operator / (const Color4 &other ) const;
00286 Color4 operator + (const Color4 &other ) const;
00287 Color4 operator - (const Color4 &other ) const;
00288
00289 void operator *=(const Color4 &other );
00290 void operator /=(const Color4 &other );
00291 void operator +=(const Color4 &other );
00292 void operator -=(const Color4 &other );
00293
00294 ValueType &operator [](const UInt32 uiIndex );
00295 const ValueType &operator [](const UInt32 uiIndex ) const;
00296
00297 Color4 &operator = (const Color4 &source );
00298
00299 bool equals (const Color4 &other,
00300 const ValueType tolerance) const;
00301
00302 bool operator < (const Color4 &other ) const;
00303 bool operator ==(const Color4 &other ) const;
00304 bool operator !=(const Color4 &other ) const;
00305
00307
00308
00309 protected:
00310
00311 ValueType _rgba[4];
00312 };
00313
00314
00315 template <class ValueTypeT> inline
00316 std::ostream &operator <<( std::ostream &outStream,
00317 const Color3<ValueTypeT> &color);
00318
00319 template <class ValueTypeT> inline
00320 std::ostream &operator <<( std::ostream &outStream,
00321 const Color4<ValueTypeT> &color);
00322
00328 typedef Color3<Real32> Color3f;
00329
00335 typedef Color4<Real32> Color4f;
00336
00342 typedef Color3<UInt8> Color3ub;
00343
00349 typedef Color4<UInt8> Color4ub;
00350
00351 OSG_END_NAMESPACE
00352
00353 #include <OSGColor.inl>
00354
00355 #define OSGCOLOR_HEADER_CVSID "@(#)$Id: $"
00356
00357 #endif