Thea
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ColorRgb Class Reference

A color with three floating-point channels: red, green and blue, each in [0, 1]. More...

#include <ColorRgb.hpp>

Public Types

typedef Real value_type
 The numerical type of each channel. More...
 

Public Member Functions

Real b () const
 The value of the blue channel. More...
 
Real & b ()
 A reference to the blue channel. More...
 
ColorRgb bgr () const
 Swap the red and blue channels. More...
 
 ColorRgb ()
 Default constructor. More...
 
 ColorRgb (Real r_, Real g_, Real b_)
 Construct from red, green and blue components. More...
 
 ColorRgb (Real v)
 Initialize all channels to the same value. More...
 
 ColorRgb (Vector3 const &v)
 Construct a color from a 3-vector. More...
 
 ColorRgb (Real const *v)
 Construct a color from three components in an array. More...
 
 ColorRgb (ColorRgba const &other)
 Initialize from a 32-bit RGBA color. More...
 
 ColorRgb (ColorRgb8 const &src)
 Construct from a color with byte channels, with automatic scaling from [0, 255] to [0, 1]. More...
 
Real const * data () const
 Get the address of the array storing color channel values in RGB order. More...
 
Real * data ()
 Get the address of the array storing color channel values in RGB order. More...
 
void fill (Real v)
 Set all channels to the same value. More...
 
bool fuzzyEq (ColorRgb const &other) const
 Check if two colors are approximately equal. More...
 
bool fuzzyNe (ColorRgb const &other) const
 Check if two colors are not approximately equal. More...
 
Real g () const
 The value of the green channel. More...
 
Real & g ()
 A reference to the green channel. More...
 
ColorRgb max (ColorRgb const &rhs) const
 Get the per-component maximum of two colors. More...
 
Real max () const
 Get the largest component. More...
 
ColorRgb min (ColorRgb const &rhs) const
 Get the per-component minimum of two colors. More...
 
Real min () const
 Get the smallest component. More...
 
Real norm () const
 Get the magnitude of the color. More...
 
void normalize ()
 Scale the color to unit magnitude. More...
 
ColorRgb normalized () const
 Get a unit magnitude color by dividing by the magnitude. More...
 
ColorRgb operator* (Real s) const
 Multiplication by a scalar. More...
 
ColorRgb operator* (ColorRgb const &rhs) const
 Component-wise multiplication by another color. More...
 
ColorRgboperator*= (ColorRgb const &rhs)
 Multiply component-wise and assign. More...
 
ColorRgboperator*= (Real s)
 Multiply by a scalar and assign. More...
 
ColorRgb operator+ (ColorRgb const &rhs) const
 Addition. More...
 
ColorRgboperator+= (ColorRgb const &rhs)
 Add and assign. More...
 
ColorRgb operator- (ColorRgb const &rhs) const
 Subtraction. More...
 
ColorRgb operator- () const
 Negation of the color. More...
 
ColorRgboperator-= (ColorRgb const &rhs)
 Subtract and assign. More...
 
ColorRgb operator/ (Real s) const
 Division by a scalar. More...
 
ColorRgb operator/ (ColorRgb const &rhs) const
 Component-wise division by another color. More...
 
ColorRgboperator/= (ColorRgb const &rhs)
 Divide component-wise and assign. More...
 
ColorRgboperator/= (Real s)
 Divide by a scalar and assign. More...
 
template<typename IntegerT >
Real const & operator[] (IntegerT channel) const
 Array-style channel access. More...
 
template<typename IntegerT >
Real & operator[] (IntegerT channel)
 Array-style channel access. More...
 
ColorRgb pow (ColorRgb const &rhs) const
 Raise the components to powers specified as another color. More...
 
ColorRgb pow (Real s) const
 Raise the components to a power. More...
 
Real r () const
 The value of the red channel. More...
 
Real & r ()
 A reference to the red channel. More...
 
void set (Real r_, Real g_, Real b_)
 Set all channels simultaneously. More...
 
Real squaredNorm () const
 Get the square of the magnitude of the color. More...
 
Vector3 toHSV () const
 Convert from RGB to HSV. More...
 
std::string toString () const
 Get a string representation of the color. More...
 

Static Public Member Functions

static ColorRgb ansiMap (int i)
 Generate colors according to the ANSI color set, mod 16. More...
 
static ColorRgb const & black ()
 Black color. More...
 
static ColorRgb const & blue ()
 Blue color. More...
 
static ColorRgb const & brown ()
 Brown color. More...
 
static ColorRgb const & cyan ()
 Cyan color. More...
 
static ColorRgb fromARGB (uint32 argb)
 Initialize from an HTML-style color (e.g. More...
 
static ColorRgb fromHSV (Vector3 const &hsv)
 Convert from HSV to RGB. More...
 
static ColorRgb const & gray ()
 Gray color. More...
 
static ColorRgb const & green ()
 Green color. More...
 
static ColorRgb jetColorMap (Real val)
 Duplicates the Matlab jet colormap map [0, 1] –> (r, g, b) where blue is close to 0 and red is close to 1. More...
 
static ColorRgb const & orange ()
 Orange color. More...
 
static ColorRgb pastelMap (int i)
 Generate colors using a hash such that adjacent values are unlikely to have similar colors. More...
 
static ColorRgb const & purple ()
 Purple color. More...
 
static ColorRgb rainbowColorMap (Real hue)
 Get a color with a specified hue, and maximum saturation and value. More...
 
static ColorRgb random ()
 Random color with unit magnitude. More...
 
static ColorRgb const & red ()
 Red color. More...
 
static ColorRgb const & wheelRandom ()
 Returns one of the color wheel colors (such as red, green, cyan). More...
 
static ColorRgb const & white ()
 White color. More...
 
static ColorRgb const & yellow ()
 Yellow color. More...
 
static ColorRgb const & zero ()
 Color with all channels zero (black). More...
 

Detailed Description

A color with three floating-point channels: red, green and blue, each in [0, 1].

Derived from the G3D library: http://g3d.sourceforge.net

Definition at line 51 of file ColorRgb.hpp.

Member Typedef Documentation

typedef Real value_type

The numerical type of each channel.

Definition at line 57 of file ColorRgb.hpp.

Constructor & Destructor Documentation

ColorRgb ( )

Default constructor.

Does not initialize fields.

Definition at line 60 of file ColorRgb.hpp.

ColorRgb ( Real  r_,
Real  g_,
Real  b_ 
)

Construct from red, green and blue components.

Definition at line 63 of file ColorRgb.hpp.

ColorRgb ( Real  v)
explicit

Initialize all channels to the same value.

Definition at line 66 of file ColorRgb.hpp.

ColorRgb ( Vector3 const &  v)
explicit

Construct a color from a 3-vector.

Definition at line 69 of file ColorRgb.hpp.

ColorRgb ( Real const *  v)
explicit

Construct a color from three components in an array.

Definition at line 72 of file ColorRgb.hpp.

ColorRgb ( ColorRgba const &  other)

Initialize from a 32-bit RGBA color.

For conversion from a consistent source type.

Definition at line 169 of file ColorRgb.cpp.

ColorRgb ( ColorRgb8 const &  src)

Construct from a color with byte channels, with automatic scaling from [0, 255] to [0, 1].

Definition at line 174 of file ColorRgb.cpp.

Member Function Documentation

ColorRgb ansiMap ( int  i)
static

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

See also
pastelMap

Definition at line 36 of file ColorRgb.cpp.

Real b ( ) const

The value of the blue channel.

Definition at line 117 of file ColorRgb.hpp.

Real& b ( )

A reference to the blue channel.

Definition at line 120 of file ColorRgb.hpp.

ColorRgb bgr ( ) const

Swap the red and blue channels.

Definition at line 320 of file ColorRgb.hpp.

ColorRgb const & black ( )
static

Black color.

Definition at line 130 of file ColorRgb.cpp.

ColorRgb const & blue ( )
static

Blue color.

Definition at line 88 of file ColorRgb.cpp.

ColorRgb const & brown ( )
static

Brown color.

Definition at line 116 of file ColorRgb.cpp.

ColorRgb const & cyan ( )
static

Cyan color.

Definition at line 102 of file ColorRgb.cpp.

Real const* data ( ) const

Get the address of the array storing color channel values in RGB order.

Definition at line 123 of file ColorRgb.hpp.

Real* data ( )

Get the address of the array storing color channel values in RGB order.

Definition at line 126 of file ColorRgb.hpp.

void fill ( Real  v)

Set all channels to the same value.

Definition at line 151 of file ColorRgb.hpp.

ColorRgb fromARGB ( uint32  argb)
static

Initialize from an HTML-style color (e.g.

0xFF0000 == RED)

Definition at line 182 of file ColorRgb.cpp.

ColorRgb fromHSV ( Vector3 const &  hsv)
static

Convert 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.
See also
Alvy Ray Smith. "Color Gamut Transform Pairs". SIGGRAPH 1978

Definition at line 193 of file ColorRgb.cpp.

bool fuzzyEq ( ColorRgb const &  other) const

Check if two colors are approximately equal.

Definition at line 272 of file ColorRgb.hpp.

bool fuzzyNe ( ColorRgb const &  other) const

Check if two colors are not approximately equal.

Definition at line 278 of file ColorRgb.hpp.

Real g ( ) const

The value of the green channel.

Definition at line 111 of file ColorRgb.hpp.

Real& g ( )

A reference to the green channel.

Definition at line 114 of file ColorRgb.hpp.

ColorRgb const & gray ( )
static

Gray color.

Definition at line 137 of file ColorRgb.cpp.

ColorRgb const & green ( )
static

Green color.

Definition at line 81 of file ColorRgb.cpp.

ColorRgb jetColorMap ( Real  val)
static

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

Definition at line 285 of file ColorRgb.cpp.

ColorRgb max ( ColorRgb const &  rhs) const

Get the per-component maximum of two colors.

Definition at line 296 of file ColorRgb.hpp.

Real max ( ) const

Get the largest component.

Definition at line 308 of file ColorRgb.hpp.

ColorRgb min ( ColorRgb const &  rhs) const

Get the per-component minimum of two colors.

Definition at line 302 of file ColorRgb.hpp.

Real min ( ) const

Get the smallest component.

Definition at line 314 of file ColorRgb.hpp.

Real norm ( ) const

Get the magnitude of the color.

Definition at line 253 of file ColorRgb.hpp.

void normalize ( )

Scale the color to unit magnitude.

Definition at line 256 of file ColorRgb.hpp.

ColorRgb normalized ( ) const

Get a unit magnitude color by dividing by the magnitude.

Definition at line 262 of file ColorRgb.hpp.

ColorRgb operator* ( Real  s) const

Multiplication by a scalar.

Definition at line 166 of file ColorRgb.hpp.

ColorRgb operator* ( ColorRgb const &  rhs) const

Component-wise multiplication by another color.

Definition at line 172 of file ColorRgb.hpp.

ColorRgb& operator*= ( ColorRgb const &  rhs)

Multiply component-wise and assign.

Definition at line 214 of file ColorRgb.hpp.

ColorRgb& operator*= ( Real  s)

Multiply by a scalar and assign.

Definition at line 232 of file ColorRgb.hpp.

ColorRgb operator+ ( ColorRgb const &  rhs) const

Addition.

Definition at line 154 of file ColorRgb.hpp.

ColorRgb& operator+= ( ColorRgb const &  rhs)

Add and assign.

Definition at line 196 of file ColorRgb.hpp.

ColorRgb operator- ( ColorRgb const &  rhs) const

Subtraction.

Definition at line 160 of file ColorRgb.hpp.

ColorRgb operator- ( ) const

Negation of the color.

Definition at line 190 of file ColorRgb.hpp.

ColorRgb& operator-= ( ColorRgb const &  rhs)

Subtract and assign.

Definition at line 205 of file ColorRgb.hpp.

ColorRgb operator/ ( Real  s) const

Division by a scalar.

Definition at line 178 of file ColorRgb.hpp.

ColorRgb operator/ ( ColorRgb const &  rhs) const

Component-wise division by another color.

Definition at line 184 of file ColorRgb.hpp.

ColorRgb& operator/= ( ColorRgb const &  rhs)

Divide component-wise and assign.

Definition at line 223 of file ColorRgb.hpp.

ColorRgb& operator/= ( Real  s)

Divide by a scalar and assign.

Definition at line 241 of file ColorRgb.hpp.

Real const& operator[] ( IntegerT  channel) const

Array-style channel access.

Definition at line 129 of file ColorRgb.hpp.

Real& operator[] ( IntegerT  channel)

Array-style channel access.

Definition at line 136 of file ColorRgb.hpp.

ColorRgb const & orange ( )
static

Orange color.

Definition at line 123 of file ColorRgb.cpp.

ColorRgb pastelMap ( int  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

Definition at line 62 of file ColorRgb.cpp.

ColorRgb pow ( ColorRgb const &  rhs) const

Raise the components to powers specified as another color.

Definition at line 284 of file ColorRgb.hpp.

ColorRgb pow ( Real  s) const

Raise the components to a power.

Definition at line 290 of file ColorRgb.hpp.

ColorRgb const & purple ( )
static

Purple color.

Definition at line 95 of file ColorRgb.cpp.

Real r ( ) const

The value of the red channel.

Definition at line 105 of file ColorRgb.hpp.

Real& r ( )

A reference to the red channel.

Definition at line 108 of file ColorRgb.hpp.

ColorRgb rainbowColorMap ( Real  hue)
static

Get a color with a specified hue, and maximum saturation and value.

Parameters
hueThe target hue. Must be in [0, 1].

Definition at line 300 of file ColorRgb.cpp.

ColorRgb random ( )
static

Random color with unit magnitude.

Definition at line 187 of file ColorRgb.cpp.

ColorRgb const & red ( )
static

Red color.

Definition at line 74 of file ColorRgb.cpp.

void set ( Real  r_,
Real  g_,
Real  b_ 
)

Set all channels simultaneously.

Definition at line 143 of file ColorRgb.hpp.

Real squaredNorm ( ) const

Get the square of the magnitude of the color.

Definition at line 250 of file ColorRgb.hpp.

Vector3 toHSV ( ) const

Convert from RGB to HSV.

See also
fromHSV

Definition at line 221 of file ColorRgb.cpp.

std::string toString ( ) const

Get a string representation of the color.

Definition at line 294 of file ColorRgb.cpp.

ColorRgb const & wheelRandom ( )
static

Returns one of the color wheel colors (such as red, green, cyan).

Does not include white, black, or gray.

Definition at line 157 of file ColorRgb.cpp.

ColorRgb const & white ( )
static

White color.

Definition at line 144 of file ColorRgb.cpp.

ColorRgb const & yellow ( )
static

Yellow color.

Definition at line 109 of file ColorRgb.cpp.

ColorRgb const & zero ( )
static

Color with all channels zero (black).

Definition at line 151 of file ColorRgb.cpp.


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