NVIDIA Iray: Math API nvidia_logo_transpbg.gif Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mi::math::Color Class Reference

Standard RGBA color class with floating point elements and operations. More...

+ Inheritance diagram for mi::math::Color:

Public Types

typedef Color_struct Pod_type
 POD class corresponding to this color. More...
 
typedef Color_struct storage_type
 Storage class used by this color. More...
 
typedef Float32 value_type
 Element type. More...
 
typedef Size size_type
 Size type, unsigned. More...
 
typedef Difference difference_type
 Difference type, signed. More...
 
typedef Float32pointer
 Mutable pointer to element. More...
 
typedef const Float32const_pointer
 Const pointer to element. More...
 
typedef Float32reference
 Mutable reference to element. More...
 
typedef const Float32const_reference
 Const reference to element. More...
 

Public Member Functions

Float32begin ()
 Returns the pointer to the first color element. More...
 
const Float32begin () const
 Returns the pointer to the first color element. More...
 
Float32end ()
 Returns the past-the-end pointer. More...
 
const Float32end () const
 Returns the past-the-end pointer. More...
 
 Color ()
 The default constructor leaves the color elements uninitialized. More...
 
 Color (const Color_struct &c)
 Constructor from underlying storage type. More...
 
 Color (const Float32 s)
 Constructor initializes all vector elements to the value s. More...
 
 Color (Float32 nr, Float32 ng, Float32 nb, Float32 na=1.0)
 Constructor initializes (r,g,b,a) from (nr,ng,nb,na). More...
 
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. More...
 
 Color (const Spectrum_struct &s)
 Conversion from Spectrum. More...
 
Coloroperator= (const Color &c)
 Assignment operator. More...
 
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). More...
 
const Float32operator[] (Size i) const
 Accesses the i-th color element, 0 <= i < 4. More...
 
Float32operator[] (Size i)
 Accesses the i-th color element, 0 <= i < 4. More...
 
Float32 get (Size i) const
 Returns the i-th color element, 0 <= i < 4. More...
 
void set (Size i, Float32 value)
 Sets the i-th color element to value, 0 <= i < 4. More...
 
bool is_black () const
 Returns true if the color is black ignoring the alpha value. More...
 
Float32 linear_intensity () const
 Returns the intensity of the RGB components, equally weighted. More...
 
Float32 ntsc_intensity () const
 Returns the intensity of the RGB components, weighted according to the NTSC standard. More...
 
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. More...
 
Color desaturate (Float32 maxval=1.0f) const
 Returns this color clipped to the range [0,maxval] using color desaturation. More...
 

Static Public Member Functions

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

Public Attributes

Float32 r
 Red color component. More...
 
Float32 g
 Green color component. More...
 
Float32 b
 Blue color component. More...
 
Float32 a
 Alpha value, 0.0 is fully transparent and 1.0 is opaque; value can lie outside that range. More...
 

Static Public Attributes

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

Detailed 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>

Member Typedef Documentation

Const pointer to element.

Const reference to element.

Difference type, signed.

POD class corresponding to this color.

Mutable pointer to element.

Mutable reference to element.

Size type, unsigned.

Storage class used by this color.

Element type.

Constructor & Destructor Documentation

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)
inlineexplicit

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 ( array[4])
inlineexplicit

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)
inlineexplicit

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)
inlineexplicit

Conversion from Spectrum.

Member Function Documentation

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 ( )
inlinestatic

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 ( )
inlinestatic

Constant size of the color.

Member Data Documentation

Float32 mi::math::Color_struct::a
inherited

Alpha value, 0.0 is fully transparent and 1.0 is opaque; value can lie outside that range.

Float32 mi::math::Color_struct::b
inherited

Blue color component.

Float32 mi::math::Color_struct::g
inherited

Green color component.

Float32 mi::math::Color_struct::r
inherited

Red color component.

const Size mi::math::Color::SIZE = 4
static

Constant size of the color.