neuray API Programmer's Manual

mi::math::Color Class Reference

[Color Class]

Description

Standard RGBA color class with floating point elements and operations. This class provides array-like storage for the four RGBA elements of type mi::Float32. Several functions and arithmetic operators support the work with colors.

The color class is a model of the STL container concept. It provides random access to its elements and corresponding random access iterators.

See also:

For the free functions and operators available for colors see Color Class.

The underlying POD type mi::math::Color_struct.

Include File:

#include <mi/math/color.h>

Public Typedefs

typedef Color_struct Pod_type
POD class corresponding to this color.
typedef Float32* const_pointer
Const pointer to element.
typedef Float32& const_reference
Const reference to element.
typedef Difference difference_type
Difference type, signed.
typedef Float32* pointer
Mutable pointer to element.
typedef Float32& reference
Mutable reference to element.
typedef Size size_type
Size type, unsigned.
typedef Color_struct storage_type
Storage class used by this color.
typedef Float32 value_type
Element type.

Public Constructors

 Color()
The default constructor leaves the color elements uninitialized.
 Color( const Color_struct& c)
Constructor from underlying storage type.
 Color( const Float32 s)
Constructor initializes all vector elements to the value s.
 Color( Float32 nr, Float32 ng, Float32 nb, Float32 na = 1.0)
Constructor initializes (r,g,b,a) from (nr,ng,nb,na).
template< typename T> Color( T array[4])
Constructor initializes the color elements from a 4-dimensional array. More...
 Color( const Vector < Float32 , 4 >& v)
Constructor initializes (r,g,b,a) from (v.x, v.y, v.z, v.w) of a compatible 4D vector v.
 Color( const Spectrum_struct& s)
Conversion from Spectrum.

Public Member Functions

Float32begin()
Returns the pointer to the first color element.
const Float32begin() const
Returns the pointer to the first color element.
Float32 cie_intensity() const
Returns the intensity of the RGB components, weighted according to the CIE standard. More...
Color clip( Clip_mode mode = CLIP_RGB, bool desaturate = false) const
Returns this color clipped into the [0,1] range, according to the Clip_mode mode, and fades overbright colors to white if desaturate is true.
Color desaturate( Float32 maxval = 1.0f) const
Returns this color clipped to the range [0,maxval] using color desaturation. More...
Float32end()
Returns the past-the-end pointer. More...
const Float32end() const
Returns the past-the-end pointer. More...
Float32 get( Size i) const
Returns the i-th color element, 0 <= i < 4.
bool  is_black() const
Returns true if the color is black ignoring the alpha value.
Float32 linear_intensity() const
Returns the intensity of the RGB components, equally weighted.
Float32 ntsc_intensity() const
Returns the intensity of the RGB components, weighted according to the NTSC standard. More...
Coloroperator=( const Color& c)
Assignment operator.
Coloroperator=( const Vector < Float32 , 4 >& v)
Assignment operator from compatible 4D vector, setting (r,g,b,a) to (v.x, v.y, v.z, v.w).
const Float32operator[]( Size i) const
Accesses the i-th color element, 0 <= i < 4.
Float32operator[]( Size i)
Accesses the i-th color element, 0 <= i < 4.
void set( Size i, Float32 value)
Sets the i-th color element to value, 0 <= i < 4.

Static Public Member Functions

static Size max_size()
Constant maximum size of the color.
static Size size()
Constant size of the color.

Static Public Variables

static const Size SIZE = 4
Constant size of the color.

Typedefs

typedef Color_struct mi::​math::​Color::Pod_type

POD class corresponding to this color.

typedef Float32* mi::​math::​Color::const_pointer

Const pointer to element.

typedef Float32& mi::​math::​Color::const_reference

Const reference to element.

typedef Difference mi::​math::​Color::difference_type

Difference type, signed.

typedef Float32* mi::​math::​Color::pointer

Mutable pointer to element.

typedef Float32& mi::​math::​Color::reference

Mutable reference to element.

typedef Size mi::​math::​Color::size_type

Size type, unsigned.

typedef Color_struct mi::​math::​Color::storage_type

Storage class used by this color.

typedef Float32 mi::​math::​Color::value_type

Element type.

Constructors

mi::​math::​Color::Color() [inline]

The default constructor leaves the color elements uninitialized.

mi::​math::​Color::Color( const Color_struct& c) [inline]

Constructor from underlying storage type.

mi::​math::​Color::Color( const Float32 s) [inline, explicit]

Constructor initializes all vector elements to the value s.

mi::​math::​Color::Color( Float32 nr, Float32 ng, Float32 nb, Float32 na = 1.0) [inline]

Constructor initializes (r,g,b,a) from (nr,ng,nb,na).

template< typename T>

mi::​math::​Color::Color( T array[4]) [inline, explicit]

Constructor initializes the color elements from a 4-dimensional array. The value type T of the array must be assignment compatible with the mi::Float32 type of the vector elements.

An example defining a red color:

‎        int data[4] = { 1, 0, 0, 1};
        mi::math::Color color( data);

mi::​math::​Color::Color( const Vector < Float32 , 4 >& v) [inline, explicit]

Constructor initializes (r,g,b,a) from (v.x, v.y, v.z, v.w) of a compatible 4D vector v.

mi::​math::​Color::Color( const Spectrum_struct& s) [inline, explicit]

Conversion from Spectrum.

Member Functions

Float32* mi::​math::​Color::begin() [inline]

Returns the pointer to the first color element.

const Float32* mi::​math::​Color::begin() const [inline]

Returns the pointer to the first color element.

Float32 mi::​math::​Color::cie_intensity() const [inline]

Returns the intensity of the RGB components, weighted according to the CIE standard. Components are weighted to match the subjective color brightness perceived by the human eye; green appears brighter than blue.

Color mi::​math::​Color::clip( Clip_mode mode = CLIP_RGB, bool desaturate = false) const [inline]

Returns this color clipped into the [0,1] range, according to the Clip_mode mode, and fades overbright colors to white if desaturate is true.

Color mi::​math::​Color::desaturate( Float32 maxval = 1.0f) const [inline]

Returns this color clipped to the range [0,maxval] using color desaturation. This function tries to maintain the apparent brightness. It recognizes the brightness values of the different colors according to the NTSC standard. If possible, colors are adjusted by desaturating towards the brightness value.

For an explanation of color clipping using desaturation, see pp. 125-128 and pp. 251-252 of "Illumination and Color in Computer Generated Imagery" by Roy Hall.

Float32* mi::​math::​Color::end() [inline]

Returns the past-the-end pointer. The range [begin(),end()) forms the range over all color elements.

const Float32* mi::​math::​Color::end() const [inline]

Returns the past-the-end pointer. The range [begin(),end()) forms the range over all color elements.

Float32 mi::​math::​Color::get( Size i) const [inline]

Returns the i-th color element, 0 <= i < 4.

bool mi::​math::​Color::is_black() const [inline]

Returns true if the color is black ignoring the alpha value.

Float32 mi::​math::​Color::linear_intensity() const [inline]

Returns the intensity of the RGB components, equally weighted.

static Size mi::​math::​Color::max_size() [inline, static]

Constant maximum size of the color.

Float32 mi::​math::​Color::ntsc_intensity() const [inline]

Returns the intensity of the RGB components, weighted according to the NTSC standard. Components are weighted to match the subjective color brightness perceived by the human eye; green appears brighter than blue.

Color& mi::​math::​Color::operator=( const Color& c) [inline]

Assignment operator.

Color& mi::​math::​Color::operator=( const Vector < Float32 , 4 >& v) [inline]

Assignment operator from compatible 4D vector, setting (r,g,b,a) to (v.x, v.y, v.z, v.w).

const Float32& mi::​math::​Color::operator[]( Size i) const [inline]

Accesses the i-th color element, 0 <= i < 4.

Float32& mi::​math::​Color::operator[]( Size i) [inline]

Accesses the i-th color element, 0 <= i < 4.

void mi::​math::​Color::set( Size i, Float32 value) [inline]

Sets the i-th color element to value, 0 <= i < 4.

static Size mi::​math::​Color::size() [inline, static]

Constant size of the color.

Variables

const Size mi::​math::​Color::SIZE = 4 [static]

Constant size of the color.