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
00152 ValueType &operator [](const UInt32 uiIndex );
00153 const ValueType &operator [](const UInt32 uiIndex ) const;
00154
00155 Color3 &operator =(const Color3 &source );
00156
00157 bool equals (const Color3 &other,
00158 const ValueType tolerance) const;
00159
00160 bool operator ==(const Color3 &other ) const;
00161 bool operator !=(const Color3 &other ) const;
00162
00164
00165
00166 protected:
00167
00168 ValueType _rgb[3];
00169 };
00170
00174 template <class ValueTypeT>
00175 class Color4
00176 {
00177
00178 public:
00179
00180 typedef ValueTypeT ValueType;
00181
00182 static const Color4 Null;
00183
00184
00188 Color4( void );
00189 Color4(const Color4 &source);
00190 Color4(const ValueType red,
00191 const ValueType green,
00192 const ValueType blue,
00193 const ValueType alpha );
00194
00196
00200 ~Color4(void);
00201
00203
00207 void clear ( void );
00208
00209 void setValuesRGBA(const ValueType red,
00210 const ValueType green,
00211 const ValueType blue,
00212 const ValueType alpha);
00213
00214 void setValuesHSV (const Real32 h,
00215 const Real32 s,
00216 const Real32 v );
00217
00218 void setRandom ( void );
00219 void setRGBA ( UInt32 rgbPack );
00220
00221 void setValue (const Char8 *szString);
00222 void setValue ( Char8 *szString);
00223
00225
00229 UInt32 getRGBA (void ) const;
00230
00231 void getValuesRGBA (ValueType &red,
00232 ValueType &green,
00233 ValueType &blue,
00234 ValueType &alpha) const;
00235
00236 void getValuesHSV (Real32 &h,
00237 Real32 &s,
00238 Real32 &v ) const;
00239
00240 ValueType red (void ) const;
00241 ValueType green (void ) const;
00242 ValueType blue (void ) const;
00243 ValueType alpha (void ) const;
00244
00245 ValueType *getValuesRGBA(void );
00246 const ValueType *getValuesRGBA(void ) const;
00247
00248
00250
00254 Color4 operator * (const ValueType val );
00255
00256 ValueType &operator [](const UInt32 uiIndex );
00257 const ValueType &operator [](const UInt32 uiIndex ) const;
00258
00259 Color4 &operator = (const Color4 &source );
00260
00261 bool equals (const Color4 &other,
00262 const ValueType tolerance) const;
00263
00264 bool operator ==(const Color4 &other ) const;
00265 bool operator !=(const Color4 &other ) const;
00266
00268
00269
00270 protected:
00271
00272 ValueType _rgba[4];
00273 };
00274
00275
00276 template <class ValueTypeT> inline
00277 std::ostream &operator <<( std::ostream &outStream,
00278 const Color3<ValueTypeT> &color);
00279
00280 template <class ValueTypeT> inline
00281 std::ostream &operator <<( std::ostream &outStream,
00282 const Color4<ValueTypeT> &color);
00283
00289 typedef Color3<Real32> Color3f;
00290
00296 typedef Color4<Real32> Color4f;
00297
00303 typedef Color3<UInt8> Color3ub;
00304
00310 typedef Color4<UInt8> Color4ub;
00311
00312 OSG_END_NAMESPACE
00313
00314 #include <OSGColor.inl>
00315
00316 #define OSGCOLOR_HEADER_CVSID "@(#)$Id: $"
00317
00318 #endif