TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Color3 Class Reference

#include <Color3.h>

Public Member Functions

 Color3 ()
 Initializes to all zero. More...
 
bool nonZero () const
 
 Color3 (const Any &any)
 
Color3operator= (const Any &a)
 
Any toAny () const
 
 Color3 (class BinaryInput &bi)
 
 Color3 (float r, float g, float b)
 
 Color3 (float v)
 Initializes all channels to v. More...
 
 Color3 (const class Vector3 &v)
 
 Color3 (const float value[3])
 
const Color3rgb () const
 
 Color3 (const Color3 &other)
 
 Color3 (const class Color3unorm8 &other)
 
bool isZero () const
 
bool isOne () const
 
bool isFinite () const
 
void serialize (class BinaryOutput &bo) const
 
void deserialize (class BinaryInput &bi)
 
const float & operator[] (int i) const
 
float & operator[] (int i)
 
Color3operator= (const Color3 &rkVector)
 
bool operator== (const Color3 &rkVector) const
 
bool operator!= (const Color3 &rkVector) const
 
size_t hashCode () const
 
Color3 operator+ (const Color3 &rkVector) const
 
Color3 operator- (const Color3 &rkVector) const
 
Color3 operator* (float s) const
 
Color3 operator/ (const Color3 &rkVector) const
 
Color3 operator* (const Color3 &rkVector) const
 
Color3 operator/ (float fScalar) const
 
Color3 operator- () const
 
Color3operator+= (const Color3 &rkVector)
 
Color3operator-= (const Color3 &rkVector)
 
Color3operator*= (const Color3 &rkVector)
 
Color3operator*= (float fScalar)
 
Color3operator/= (float fScalar)
 
bool fuzzyEq (const Color3 &other) const
 
bool fuzzyNe (const Color3 &other) const
 
float length () const
 
Color3 direction () const
 
float squaredLength () const
 
float dot (const Color3 &rkVector) const
 
float unitize (float fTolerance=1e-06f)
 
Color3 cross (const Color3 &rkVector) const
 
Color3 unitCross (const Color3 &rkVector) const
 
Color3 pow (const Color3 &other) const
 
Color3 pow (float other) const
 
Color3 max (const Color3 &other) const
 
Color3 min (const Color3 &other) const
 
float min () const
 
float max () const
 
Color3 lerp (const Color3 &other, float a) const
 
float sum () const
 
float average () const
 
std::string toString () const
 
Color3 bgr () const
 

Static Public Member Functions

static Color3 fromARGB (uint32)
 
static Color3 fromASRGB (uint32)
 
static const Color3wheelRandom ()
 
static Color3 ansiMap (uint32 i)
 
static Color3 pastelMap (uint32 i)
 
static Color3 fromHSV (const Vector3 &_hsv)
 
static Vector3 toHSV (const Color3 &_rgb)
 
static Color3 jetColorMap (const float &val)
 
static Color3 rainbowColorMap (float hue)
 
static Color3 random ()
 
static const Color3red ()
 
static const Color3green ()
 
static const Color3blue ()
 
static const Color3purple ()
 
static const Color3cyan ()
 
static const Color3yellow ()
 
static const Color3brown ()
 
static const Color3orange ()
 
static const Color3black ()
 
static const Color3gray ()
 
static const Color3white ()
 
static const Color3zero ()
 
static const Color3one ()
 

Public Attributes

float r
 
float g
 
float b
 

Private Member Functions

bool operator< (const Color3 &) const
 
bool operator> (const Color3 &) const
 
bool operator<= (const Color3 &) const
 
bool operator>= (const Color3 &) const
 

Detailed Description

Do not subclass– this implementation makes assumptions about the memory layout.

Constructor & Destructor Documentation

G3D::Color3::Color3 ( )
inline

Initializes to all zero.

45 : r(0), g(0), b(0) {}
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the caller graph for this function:

G3D::Color3::Color3 ( const Any any)
explicit
Parameters
anyMust be in one of the following forms:

In the current implementation, G3D::Power3, G3D::Radiance3, and G3D::Irradiance3 are typedefs for Color3, so Color3 accepts "Power3" and "Radiance3" as a prefixes as well, e.g., Power3(1,0,0).

31  {
32  *this = Color3::zero();
33  any.verifyNameBeginsWith("Color3", "Power3", "Radiance3", "Irradiance3", "Energy3", "Radiosity3", "Biradiance3");
34 
35  switch (any.type()) {
36  case Any::TABLE:
37 
38  for (Any::AnyTable::Iterator it = any.table().begin(); it.isValid(); ++it) {
39  const std::string& key = toLower(it->key);
40  if (key == "r") {
41  r = it->value;
42  } else if (key == "g") {
43  g = it->value;
44  } else if (key == "b") {
45  b = it->value;
46  } else {
47  any.verify(false, "Illegal key: " + it->key);
48  }
49  }
50  break;
51 
52  case Any::ARRAY: // Intentionally falls through
54  {
55  const std::string& name = any.name();
56  std::string factoryName;
57  size_t i = name.find("::");
58  if (i != std::string::npos && i > 1) {
59  factoryName = name.substr(i + 2);
60  }
61 
62  if (factoryName == "") {
63  if (any.size() == 1) {
64  r = g = b = any[0];
65  } else {
66  any.verifySize(3);
67  r = any[0];
68  g = any[1];
69  b = any[2];
70  }
71  } else if (factoryName == "one") {
72  any.verifySize(0);
73  *this = one();
74  } else if (factoryName == "zero") {
75  any.verifySize(0);
76  *this = zero();
77  } else if (factoryName == "fromARGB") {
78  *this = Color3::fromARGB((int)any[0].number());
79  } else if (factoryName == "fromASRGB") {
80  *this = Color3::fromASRGB((int)any[0].number());
81  } else {
82  any.verify(false, "Expected Color3 constructor");
83  }
84  }
85  break;
86 
87  default:
88  any.verify(false, "Bad Color3 constructor");
89  }
90 }
Definition: Any.h:187
static Color3 fromASRGB(uint32)
Definition: Color3.cpp:256
bool any(float x)
Definition: g3dmath.h:424
Definition: Any.h:187
float g
Definition: Color3.h:139
static const Color3 & one()
Definition: Color3.cpp:180
static const Color3 & zero()
Definition: Color3.cpp:174
std::string toLower(const std::string &x)
Definition: stringutils.cpp:223
static Color3 fromARGB(uint32)
Definition: Color3.cpp:252
float r
Definition: Color3.h:139
Definition: Any.h:187
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

G3D::Color3::Color3 ( class BinaryInput bi)
explicit
203  {
204  deserialize(bi);
205 }
void deserialize(class BinaryInput &bi)
Definition: Color3.cpp:208

+ Here is the call graph for this function:

G3D::Color3::Color3 ( float  r,
float  g,
float  b 
)
inline
294  {
295  r = fX;
296  g = fY;
297  b = fZ;
298 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
G3D::Color3::Color3 ( float  v)
inlineexplicit

Initializes all channels to v.

77 : r(v), g(v), b(v) {}
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
G3D::Color3::Color3 ( const class Vector3 v)
explicit
G3D::Color3::Color3 ( const float  value[3])
inlineexplicit
301  {
302  r = afCoordinate[0];
303  g = afCoordinate[1];
304  b = afCoordinate[2];
305 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
G3D::Color3::Color3 ( const Color3 other)
inline

Initialize from another color.

308  {
309  r = rkVector.r;
310  g = rkVector.g;
311  b = rkVector.b;
312 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
G3D::Color3::Color3 ( const class Color3unorm8 &  other)
248  : r(other.r), g(other.g), b(other.b) {
249 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

Member Function Documentation

Color3 G3D::Color3::ansiMap ( uint32  i)
static

Generate colors according to the ANSI color set, mod 16.

See also
pastelMap
100  {
101  static const Color3 map[] =
102  {Color3::black(), Color3::red() * 0.75f, Color3::green() * 0.75f, Color3::yellow() * 0.75f,
103  Color3::blue() * 0.75f, Color3::purple() * 0.75f, Color3::cyan() * 0.75f, Color3::white() * 0.75f,
106 
107  return map[i & 15];
108 }
static const Color3 & white()
Definition: Color3.cpp:192
Color3()
Initializes to all zero.
Definition: Color3.h:45
static const Color3 & purple()
Definition: Color3.cpp:139
static const Color3 & green()
Definition: Color3.cpp:127
static const Color3 & cyan()
Definition: Color3.cpp:145
static const Color3 & yellow()
Definition: Color3.cpp:151
static const Color3 & blue()
Definition: Color3.cpp:133
static const Color3 & red()
Definition: Color3.cpp:121
static const Color3 & black()
Definition: Color3.cpp:169

+ Here is the call graph for this function:

float G3D::Color3::average ( ) const
inline
229  {
230  return sum() / 3.0f;
231  }
float sum() const
Definition: Color3.h:225

+ Here is the call graph for this function:

Color3 G3D::Color3::bgr ( ) const
inline
270  {
271  return Color3(b, g, r);
272  }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

const Color3 & G3D::Color3::black ( )
static
169  {
170  static Color3 c(0.0f, 0.0f, 0.0f);
171  return c;
172 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

const Color3 & G3D::Color3::blue ( )
static
133  {
134  static Color3 c(0.0f, 0.0f, 1.0f);
135  return c;
136 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

const Color3 & G3D::Color3::brown ( )
static
157  {
158  static Color3 c(0.5f, 0.5f, 0.0f);
159  return c;
160 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

Color3 G3D::Color3::cross ( const Color3 rkVector) const
inline
434  {
435  return Color3(g*rkVector.b - b*rkVector.g, b*rkVector.r - r*rkVector.b,
436  r*rkVector.g - g*rkVector.r);
437 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

const Color3 & G3D::Color3::cyan ( )
static
145  {
146  static Color3 c(0.0f, 0.7f, 1.0f);
147  return c;
148 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

void G3D::Color3::deserialize ( class BinaryInput bi)
208  {
209  r = bi.readFloat32();
210  g = bi.readFloat32();
211  b = bi.readFloat32();
212 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Color3 G3D::Color3::direction ( ) const
inline
418  {
419  float lenSquared = r * r + g * g + b * b;
420 
421  if (lenSquared != 1.0f) {
422  return *this / sqrtf(lenSquared);
423  } else {
424  return *this;
425  }
426 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the caller graph for this function:

float G3D::Color3::dot ( const Color3 rkVector) const
inline
429  {
430  return r*rkVector.r + g*rkVector.g + b*rkVector.b;
431 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
Color3 G3D::Color3::fromARGB ( uint32  x)
static

Initialize from an HTML-style color (e.g. 0xFF0000 == RED)

252  {
253  return Color3(Color3unorm8::fromARGB(x));
254 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Color3 G3D::Color3::fromASRGB ( uint32  x)
static

Initialize from an HTML-style color (e.g. 0xFF0000 == RED) by converting from sRGB to RGB.

256  {
257  return Color3(Color3unorm8::fromARGB(x)).pow(2.2f);
258 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Color3 G3D::Color3::fromHSV ( const Vector3 _hsv)
static

Converts from HSV to RGB , note: toHSV(fromHSV(_hsv)) may not be _hsv, if it is at a grey point or black point. The components of _hsv should lie in the unit interval. [Alvy] Ray Smith SIGGRAPH 1978 "Color Gamut Transform Pairs"

302  {
303  debugAssertM((_hsv.x <= 1.0f && _hsv.x >= 0.0f)
304  && (_hsv.y <= 1.0f && _hsv.y >= 0.0f)
305  && ( _hsv.z <= 1.0f && _hsv.z >= 0.0f), "H,S,V must be between [0,1]");
306  const int i = iMin(5, G3D::iFloor(6.0 * _hsv.x));
307  const float f = 6.0f * _hsv.x - i;
308  const float m = _hsv.z * (1.0f - (_hsv.y));
309  const float n = _hsv.z * (1.0f - (_hsv.y * f));
310  const float k = _hsv.z * (1.0f - (_hsv.y * (1 - f)));
311  switch(i) {
312  case 0:
313  return Color3(_hsv.z, k, m);
314 
315  case 1:
316  return Color3(n, _hsv.z, m);
317 
318  case 2:
319  return Color3(m, _hsv.z, k);
320 
321  case 3:
322  return Color3(m, n, _hsv.z);
323 
324  case 4:
325  return Color3(k, m, _hsv.z);
326 
327  case 5:
328  return Color3(_hsv.z, m, n);
329 
330  default:
331  debugAssertM(false, "fell through switch..");
332  }
333  return Color3::black();
334 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
int iFloor(double fValue)
Definition: g3dmath.h:603
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
static const Color3 & black()
Definition: Color3.cpp:169
int iMin(int x, int y)
Definition: g3dmath.h:753

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::Color3::fuzzyEq ( const Color3 other) const
inline
327  {
328  return G3D::fuzzyEq((*this - other).squaredLength(), 0);
329 }
float squaredLength() const
Definition: Color3.h:408
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857

+ Here is the call graph for this function:

bool G3D::Color3::fuzzyNe ( const Color3 other) const
inline
333  {
334  return G3D::fuzzyNe((*this - other).squaredLength(), 0);
335 }
float squaredLength() const
Definition: Color3.h:408
bool fuzzyNe(double a, double b)
Definition: g3dmath.h:861

+ Here is the call graph for this function:

const Color3 & G3D::Color3::gray ( )
static
186  {
187  static Color3 c(0.7f, 0.7f, 0.7f);
188  return c;
189 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
const Color3 & G3D::Color3::green ( )
static
127  {
128  static Color3 c(0.0f, 1.0f, 0.0f);
129  return c;
130 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

size_t G3D::Color3::hashCode ( ) const
232  {
233  unsigned int rhash = (*(int*)(void*)(&r));
234  unsigned int ghash = (*(int*)(void*)(&g));
235  unsigned int bhash = (*(int*)(void*)(&b));
236 
237  return rhash + (ghash * 37) + (bhash * 101);
238 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the caller graph for this function:

bool G3D::Color3::isFinite ( ) const
198  {
199  return G3D::isFinite(r) && G3D::isFinite(g) && G3D::isFinite(b);
200 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
bool isFinite(double x)
Definition: g3dmath.h:525
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

bool G3D::Color3::isOne ( ) const
inline
99  {
100  return (r == 1.0f) && (g == 1.0f) && (b == 1.0f);
101  }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
bool G3D::Color3::isZero ( ) const
inline
95  {
96  return (r == 0.0f) && (g == 0.0f) && (b == 0.0f);
97  }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
Color3 G3D::Color3::jetColorMap ( const float &  val)
static

Duplicates the matlab jet colormap maps [0,1] –> (r,g,b) where blue is close to 0 and red is close to 1.

372  {
373  debugAssertM(val <= 1.0f && val >= 0.0f , "value should be in [0,1]");
374 
375  //truncated triangles where sides have slope 4
376  Color3 jet;
377 
378  jet.r = G3D::min(4.0f * val - 1.5f,-4.0f * val + 4.5f) ;
379  jet.g = G3D::min(4.0f * val - 0.5f,-4.0f * val + 3.5f) ;
380  jet.b = G3D::min(4.0f * val + 0.5f,-4.0f * val + 2.5f) ;
381 
382 
383  jet.r = G3D::clamp(jet.r, 0.0f, 1.0f);
384  jet.g = G3D::clamp(jet.g, 0.0f, 1.0f);
385  jet.b = G3D::clamp(jet.b, 0.0f, 1.0f);
386 
387  return jet;
388 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
double clamp(double val, double low, double hi)
Definition: g3dmath.h:571
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
T min(const T &x, const T &y)
Definition: g3dmath.h:305

+ Here is the call graph for this function:

float G3D::Color3::length ( ) const
inline
413  {
414  return sqrtf(r*r + g*g + b*b);
415 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the caller graph for this function:

Color3 G3D::Color3::lerp ( const Color3 other,
float  a 
) const
inline
220  {
221  return (*this) + (other - *this) * a;
222 
223  }

+ Here is the caller graph for this function:

Color3 G3D::Color3::max ( const Color3 other) const
inline
202  {
203  return Color3(G3D::max(r, other.r), G3D::max(g, other.g), G3D::max(b, other.b));
204  }
Color3()
Initializes to all zero.
Definition: Color3.h:45
T max(const T &x, const T &y)
Definition: g3dmath.h:320
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float G3D::Color3::max ( ) const
inline

Largest element

216  {
217  return G3D::max(G3D::max(r, g), b);
218  }
T max(const T &x, const T &y)
Definition: g3dmath.h:320
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

Color3 G3D::Color3::min ( const Color3 other) const
inline
206  {
207  return Color3(G3D::min(r, other.r), G3D::min(g, other.g), G3D::min(b, other.b));
208  }
Color3()
Initializes to all zero.
Definition: Color3.h:45
T min(const T &x, const T &y)
Definition: g3dmath.h:305
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float G3D::Color3::min ( ) const
inline

Smallest element

211  {
212  return G3D::min(G3D::min(r, g), b);
213  }
T min(const T &x, const T &y)
Definition: g3dmath.h:305
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

bool G3D::Color3::nonZero ( ) const
inline
47  {
48  return (r != 0) || (g != 0) || (b != 0);
49  }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
const Color3 & G3D::Color3::one ( )
static
180  {
181  static Color3 c(1.0f, 1.0f, 1.0f);
182  return c;
183 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

bool G3D::Color3::operator!= ( const Color3 rkVector) const
inline
352  {
353  return ( r != rkVector.r || g != rkVector.g || b != rkVector.b );
354 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
Color3 G3D::Color3::operator* ( float  s) const
inline
161  {
162  return Color3(r * s, g * s, b * s);
163  }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

Color3 G3D::Color3::operator* ( const Color3 rkVector) const
inline
367  {
368  return Color3(r * rkVector.r, g * rkVector.g, b * rkVector.b);
369 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

Color3 & G3D::Color3::operator*= ( const Color3 rkVector)
inline
401  {
402  r *= rkVector.r;
403  g *= rkVector.g;
404  b *= rkVector.b;
405  return *this;
406 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
Color3 & G3D::Color3::operator*= ( float  fScalar)
inline
393  {
394  r *= fScalar;
395  g *= fScalar;
396  b *= fScalar;
397  return *this;
398 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
Color3 G3D::Color3::operator+ ( const Color3 rkVector) const
inline
357  {
358  return Color3(r + rkVector.r, g + rkVector.g, b + rkVector.b);
359 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

Color3 & G3D::Color3::operator+= ( const Color3 rkVector)
inline
377  {
378  r += rkVector.r;
379  g += rkVector.g;
380  b += rkVector.b;
381  return *this;
382 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
Color3 G3D::Color3::operator- ( const Color3 rkVector) const
inline
362  {
363  return Color3(r -rkVector.r, g - rkVector.g, b - rkVector.b);
364 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

Color3 G3D::Color3::operator- ( ) const
inline
372  {
373  return Color3( -r, -g, -b);
374 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

Color3 & G3D::Color3::operator-= ( const Color3 rkVector)
inline
385  {
386  r -= rkVector.r;
387  g -= rkVector.g;
388  b -= rkVector.b;
389  return *this;
390 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
Color3 G3D::Color3::operator/ ( const Color3 rkVector) const
inline
164  {
165  return Color3(r / rkVector.r, g / rkVector.g, b / rkVector.b);
166  }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

Color3 G3D::Color3::operator/ ( float  fScalar) const
inline
169  {
170  return (*this) * (1.0f / fScalar);
171  }
Color3 & G3D::Color3::operator/= ( float  fScalar)
270  {
271  if (fScalar != 0.0f) {
272  float fInvScalar = 1.0f / fScalar;
273  r *= fInvScalar;
274  g *= fInvScalar;
275  b *= fInvScalar;
276  } else {
277  r = (float)G3D::finf();
278  g = (float)G3D::finf();
279  b = (float)G3D::finf();
280  }
281 
282  return *this;
283 }
float finf()
Definition: g3dmath.cpp:71
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

bool G3D::Color3::operator< ( const Color3 ) const
private
bool G3D::Color3::operator<= ( const Color3 ) const
private
Color3 & G3D::Color3::operator= ( const Any a)
25  {
26  *this = Color3(a);
27  return *this;
28 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the call graph for this function:

Color3 & G3D::Color3::operator= ( const Color3 rkVector)
inline
339  {
340  r = rkVector.r;
341  g = rkVector.g;
342  b = rkVector.b;
343  return *this;
344 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
bool G3D::Color3::operator== ( const Color3 rkVector) const
inline
347  {
348  return ( r == rkVector.r && g == rkVector.g && b == rkVector.b );
349 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139
bool G3D::Color3::operator> ( const Color3 ) const
private
bool G3D::Color3::operator>= ( const Color3 ) const
private
const float & G3D::Color3::operator[] ( int  i) const
inline
321  {
322  return ((float*)this)[i];
323 }
float & G3D::Color3::operator[] ( int  i)
inline
315  {
316  return ((float*)this)[i];
317 }
const Color3 & G3D::Color3::orange ( )
static
163  {
164  static Color3 c(1.0f, 0.5f, 0.0f);
165  return c;
166 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

Color3 G3D::Color3::pastelMap ( uint32  i)
static

Generate colors using a hash such that adjacent values are unlikely to have similar colors.

Useful for rendering with stable but arbitrary colors, e.g., when debugging a mesh algorithm.

See also
ansiMap
111  {
112  uint32 x = Crypto::crc32(&i, sizeof(uint32));
113  // Create fairly bright, saturated colors
114  Vector3 v(((x >> 22) & 1023) / 1023.0f,
115  (((x >> 11) & 2047) / 2047.0f) * 0.5f + 0.25f,
116  ((x & 2047) / 2047.0f) * 0.75f + 0.25f);
117  return Color3::fromHSV(v);
118 }
static Color3 fromHSV(const Vector3 &_hsv)
Definition: Color3.cpp:302
uint32_t uint32
Definition: Define.h:150
static uint32 crc32(const void *bytes, size_t numBytes)
Definition: Crypto.cpp:66
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

Color3 G3D::Color3::pow ( const Color3 other) const
inline
194  {
195  return Color3(::pow(r, other.r), ::pow(g, other.g), ::pow(b, other.b));
196  }
Color3 pow(const Color3 &other) const
Definition: Color3.h:194
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Color3 G3D::Color3::pow ( float  other) const
inline
198  {
199  return Color3(::pow(r, other), ::pow(g, other), ::pow(b, other));
200  }
Color3 pow(const Color3 &other) const
Definition: Color3.h:194
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

const Color3 & G3D::Color3::purple ( )
static
139  {
140  static Color3 c(0.7f, 0.0f, 1.0f);
141  return c;
142 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

Color3 G3D::Color3::rainbowColorMap ( float  hue)
static

Returns colors with maximum saturation and value

Parameters
hue[0, 1]
400  {
401  return fromHSV(Vector3(hue, 1.0f, 1.0f));
402 }
static Color3 fromHSV(const Vector3 &_hsv)
Definition: Color3.cpp:302

+ Here is the call graph for this function:

Color3 G3D::Color3::random ( )
static

Random unit vector

263  {
264  return Color3(uniformRandom(),
265  uniformRandom(),
266  uniformRandom()).direction();
267 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float uniformRandom(float low=0.0f, float hi=1.0f)
Definition: g3dmath.h:694

+ Here is the call graph for this function:

const Color3 & G3D::Color3::red ( )
static
121  {
122  static Color3 c(1.0f, 0.0f, 0.0f);
123  return c;
124 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

const Color3& G3D::Color3::rgb ( ) const
inline

Returns this color

84  {
85  return *this;
86  }
void G3D::Color3::serialize ( class BinaryOutput bo) const
215  {
216  bo.writeFloat32(r);
217  bo.writeFloat32(g);
218  bo.writeFloat32(b);
219 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

float G3D::Color3::squaredLength ( ) const
inline
408  {
409  return r*r + g*g + b*b;
410 }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the caller graph for this function:

float G3D::Color3::sum ( ) const
inline
225  {
226  return r + g + b;
227  }
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the caller graph for this function:

Any G3D::Color3::toAny ( ) const

Converts the Color3 to an Any.

93  {
94  Any a(Any::ARRAY, "Color3");
95  a.append(r, g, b);
96  return a;
97 }
Definition: Any.h:187
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

Vector3 G3D::Color3::toHSV ( const Color3 _rgb)
static
337  {
338  debugAssertM((_rgb.r <= 1.0f && _rgb.r >= 0.0f)
339  && (_rgb.g <= 1.0f && _rgb.g >= 0.0f)
340  && (_rgb.b <= 1.0f && _rgb.b >= 0.0f), "R,G,B must be between [0,1]");
341  Vector3 hsv = Vector3::zero();
342  hsv.z = G3D::max(G3D::max(_rgb.r, _rgb.g), _rgb.b);
343  if (G3D::fuzzyEq(hsv.z, 0.0f)) {
344  return hsv;
345  }
346 
347  const float x = G3D::min(G3D::min(_rgb.r, _rgb.g), _rgb.b);
348  hsv.y = (hsv.z - x) / hsv.z;
349 
350  if (G3D::fuzzyEq(hsv.y, 0.0f)) {
351  return hsv;
352  }
353 
354  Vector3 rgbN;
355  rgbN.x = (hsv.z - _rgb.r) / (hsv.z - x);
356  rgbN.y = (hsv.z - _rgb.g) / (hsv.z - x);
357  rgbN.z = (hsv.z - _rgb.b) / (hsv.z - x);
358 
359  if (_rgb.r == hsv.z) { // note from the max we know that it exactly equals one of the three.
360  hsv.x = (_rgb.g == x)? 5.0f + rgbN.z : 1.0f - rgbN.y;
361  } else if (_rgb.g == hsv.z) {
362  hsv.x = (_rgb.b == x)? 1.0f + rgbN.x : 3.0f - rgbN.z;
363  } else {
364  hsv.x = (_rgb.r == x)? 3.0f + rgbN.y : 5.0f - rgbN.x;
365  }
366 
367  hsv.x /= 6.0f;
368 
369  return hsv;
370 }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
T max(const T &x, const T &y)
Definition: g3dmath.h:320
static const Vector3 & zero()
Definition: Vector3.cpp:119
T min(const T &x, const T &y)
Definition: g3dmath.h:305
G3D::int16 x
Definition: Vector2int16.h:37
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857

+ Here is the call graph for this function:

std::string G3D::Color3::toString ( ) const
394  {
395  return G3D::format("(%g, %g, %g)", r, g, b);
396 }
float g
Definition: Color3.h:139
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

Color3 G3D::Color3::unitCross ( const Color3 rkVector) const
inline
440  {
441  Color3 kCross(g*rkVector.b - b*rkVector.g, b*rkVector.r - r*rkVector.b,
442  r*rkVector.g - g*rkVector.r);
443  return kCross.direction();
444 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

float G3D::Color3::unitize ( float  fTolerance = 1e-06f)
286  {
287  float fLength = length();
288 
289  if ( fLength > fTolerance ) {
290  float fInvLength = 1.0f / fLength;
291  r *= fInvLength;
292  g *= fInvLength;
293  b *= fInvLength;
294  } else {
295  fLength = 0.0f;
296  }
297 
298  return fLength;
299 }
float length() const
Definition: Color3.h:413
float g
Definition: Color3.h:139
float r
Definition: Color3.h:139
float b
Definition: Color3.h:139

+ Here is the call graph for this function:

const Color3 & G3D::Color3::wheelRandom ( )
static

Returns one of the color wheel colors (e.g. RED, GREEN, CYAN). Does not include white, black, or gray.

222  {
223  static const Color3 colorArray[8] =
227 
228  return colorArray[iRandom(0, 7)];
229 }
Color3()
Initializes to all zero.
Definition: Color3.h:45
static const Color3 & purple()
Definition: Color3.cpp:139
static const Color3 & green()
Definition: Color3.cpp:127
static const Color3 & orange()
Definition: Color3.cpp:163
static const Color3 & cyan()
Definition: Color3.cpp:145
static const Color3 & yellow()
Definition: Color3.cpp:151
static const Color3 & blue()
Definition: Color3.cpp:133
static const Color3 & red()
Definition: Color3.cpp:121
int iRandom(int low, int hi)
Definition: g3dmath.cpp:110
static const Color3 & brown()
Definition: Color3.cpp:157

+ Here is the call graph for this function:

const Color3 & G3D::Color3::white ( )
static
192  {
193  static Color3 c(1.0f, 1.0f, 1.0f);
194  return c;
195 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

const Color3 & G3D::Color3::yellow ( )
static
151  {
152  static Color3 c(1.0f, 1.0f, 0.0f);
153  return c;
154 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

const Color3 & G3D::Color3::zero ( )
static
174  {
175  static Color3 c(0.0f, 0.0f, 0.0f);
176  return c;
177 }
Color3()
Initializes to all zero.
Definition: Color3.h:45

+ Here is the caller graph for this function:

Member Data Documentation

float G3D::Color3::b
float G3D::Color3::g
float G3D::Color3::r

Channel value.


The documentation for this class was generated from the following files: