Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Friends

MColor Class Reference

Search for all occurrences

Detailed Description

A color math class.

This class is used to store values of color attributes. Right now, this class provides no more functionality than the MFltVector class, but it is used because Rendering plans to employ more advanced color models in the future. In these models, colors cannot necessarily be represented as an RGB triple.

Examples:

apiMeshShapeUI.cpp, cvColorNode.cpp, cvColorShader.cpp, D3DResourceManager.cpp, D3DViewportRenderer.cpp, hlslShader.cpp, hwAnisotropicShader_NV20.cpp, hwColorPerVertexShader.cpp, hwPhongShader.cpp, hwToonShader_NV20.cpp, hwUnlitShader.cpp, pnTrianglesNode.cpp, pnTrianglesNode.h, scanDagCmd.cpp, scanDagSyntax.cpp, ShadingConnection.cpp, ShadingConnection.h, simpleFluidEmitter.cpp, and volumeLightCmd.cpp.

#include <MColor.h>

List of all members.

Public Types

enum   MColorType { kRGB, kHSV, kCMY, kCMYK }
 

Defines color space.

More...

Public Member Functions

  MColor ()
  Default class contructor.
  MColor (const MColor &src)
  Copy contructor.
  MColor (float rr, float gg, float bb=0.0, float aa=1.0)
  RGB contructor.
  MColor (const float d[3])
  RGB contructor.
  MColor (float alpha)
  Alpha contructor.
  MColor (MColorType colorModel, unsigned char c1, unsigned char c2, unsigned char c3, unsigned char alpha=255U)
  Color space contructor.
  MColor (MColorType colorModel, unsigned short c1, unsigned short c2, unsigned short c3, unsigned short alpha=65535U)
  Color space contructor.
  MColor (MColorType colorModel, float c1, float c2, float c3, float alpha=1.0)
  Color space contructor.
  MColor (MColorType colorModel, double c1, double c2, double c3, double alpha=1.0)
  Color space contructor.
  ~MColor ()
  Class destructor.
MColor operator= (const MColor &src)
  Assignment operator.
float  operator() (unsigned int i) const
  Index operator.
float  operator[] (unsigned int i) const
  Index operator.
MColor operator*= (float scalar)
  In place multiply operator.
MColor  operator* (float scalar) const
  Multiply operator.
MColor operator*= (const MColor &other)
  In place multiply operator.
MColor  operator* (const MColor &other) const
  Multiply operator.
MColor operator/= (float scalar)
  In place divide operator.
MColor  operator/ (float scalar) const
  Divide operator.
MColor operator+= (const MColor &other)
  In place add operator.
MColor  operator+ (const MColor &other) const
  Add operator.
MColor  operator- () const
  Unary minus operator.
MColor  operator- (const MColor &other) const
  Substraction operator.
bool  operator== (const MColor &other) const
  Equality operator.
bool  operator!= (const MColor &other) const
  Inequality operator.
bool  get (float d[3]) const
  Color component accessor.
bool  get (MColorType colorModel, float &, float &, float &) const
  Color component accessor.
bool  get (MColorType colorModel, float &, float &, float &, float &alpha) const
  Color component accessor.
bool  set (MColorType colorModel, float, float, float, float alpha=1.0)
  Color component assigment.
float &  operator() (unsigned int i)
  Index operator. NO SCRIPT SUPPORT.
float &  operator[] (unsigned int i)
  Index operator. NO SCRIPT SUPPORT.

Public Attributes

float  r
  The red component of the color.
float  g
  The green component of the color.
float  b
  The blue component of the color.
float  a
  The alpha component of the color.

Static Public Attributes

static const MColor  kOpaqueBlack
  Opaque black color.

Friends

OPENMAYA_EXPORT MColor  operator* (float scalar, const MColor &other)
  Multiply operator. NO SCRIPT SUPPORT.
OPENMAYA_EXPORT std::ostream &  operator<< (std::ostream &os, const MColor &c)
  Print operator. NO SCRIPT SUPPORT.

Member Enumeration Documentation

enum MColorType

Defines color space.

Enumerator:
kRGB 

Red, Green, Blue.

kHSV 

Hue, Saturation, Value.

kCMY 

Cyan, Magenta, Yellow.

kCMYK 

Cyan, Magenta, Yellow, Black.


Constructor & Destructor Documentation

MColor ( ) [inline]

Default class contructor.

Initializes the object to a black opaque color.

MColor ( const MColor src ) [inline]

Copy contructor.

Create a new color and initialize it to the same values as the given color.

Parameters:
[in] src The color object to copy.
MColor ( float  rr,
float  gg,
float  bb = 0.0,
float  aa = 1.0 
) [inline]

RGB contructor.

Initializes the color with the explicit r, g, b, and a values provided as arguments.

Parameters:
[in] rr The r component of the color.
[in] gg The g component of the color.
[in] bb The b component of the color. Defaults to 0.0.
[in] aa The a component of the color. Defaults to 1.0.
MColor ( const float  d[3] ) [inline]

RGB contructor.

Initializes the color with the explicit red, green and blue values provided in the given float array.

The alpha value will be 1.0: The color is opaque.

Parameters:
[in] d The 3 element array containing the initial red, green, and blue values.
MColor ( float  alpha ) [inline]

Alpha contructor.

Initializes a black color with transparency.

The r, g, b components are set to 0.

Parameters:
[in] alpha The transparency component of the color.
MColor ( MColor::MColorType  colorModel,
unsigned char  c1,
unsigned char  c2,
unsigned char  c3,
unsigned char  alpha = 255U 
)

Color space contructor.

Initializes the color with the given color model using unsigned int data in range [0-255].

Parameters:
[in] colorModel The color model.
[in] c1 First component of color.
[in] c2 Second component of color.
[in] c3 Third component of color.
[in] alpha Transparency. Defaults to opaque (255).
MColor ( MColor::MColorType  colorModel,
unsigned short  c1,
unsigned short  c2,
unsigned short  c3,
unsigned short  alpha = 65535U 
)

Color space contructor.

Initializes the color with the given color model using unsigned int data in range [0-65535].

Parameters:
[in] colorModel The color model.
[in] c1 First component of color.
[in] c2 Second component of color.
[in] c3 Third component of color.
[in] alpha Transparency. Defaults to opaque (65535).
MColor ( MColor::MColorType  colorModel,
float  c1,
float  c2,
float  c3,
float  alpha = 1.0 
)

Color space contructor.

Initializes the color with the given color model using float data in range [0-1.0].

Parameters:
[in] colorModel The color model.
[in] c1 First component of color.
[in] c2 Second component of color.
[in] c3 Third component of color.
[in] alpha Transparency. Defaults to opaque (1.0).
MColor ( MColor::MColorType  colorModel,
double  c1,
double  c2,
double  c3,
double  alpha = 1.0 
)

Color space contructor.

Class constructor.

Initializes the color with the given color model using double precision data in range [0-1.0].

Parameters:
[in] colorModel The color model.
[in] c1 First component of color.
[in] c2 Second component of color.
[in] c3 Third component of color.
[in] alpha Transparency. Defaults to opaque (1.0).
~MColor ( )

Class destructor.

Deallocates the memory.


Member Function Documentation

MColor & operator= ( const MColor src ) [inline]

Assignment operator.

Copies a color.

Parameters:
[in] src The color object to copy.
Returns:
A reference to the object whose value was set.
float operator() ( unsigned int  i ) const [inline]

Index operator.

Accessor to one component of the color.

Parameters:
[in] i Value indicating which component to return.
Returns:
A reference to the appropriate component of the color:
  • Reference to the red channel when argument is 0.
  • Reference to the green channel when argument is 1.
  • Reference to the blue channel when argument is 2.
  • Reference to the alpha channel otherwise.
float operator[] ( unsigned int  i ) const [inline]

Index operator.

Accessor to one component of the color.

Parameters:
[in] i Value indicating which component to return.
Returns:
A reference to the appropriate component of the color:
  • Reference to the red channel when argument is 0.
  • Reference to the green channel when argument is 1.
  • Reference to the blue channel when argument is 2.
  • Reference to the alpha channel otherwise.
MColor & operator*= ( float  scalar )

In place multiply operator.

Parameters:
[in] scalar Color multiplication factor.
Returns:
A reference to the color object which was modified.
MColor operator* ( float  scalar ) const

Multiply operator.

Parameters:
[in] scalar Color multiplication factor.
Returns:
A new MColor object representing the product of the original MColor with the scalar value.
MColor & operator*= ( const MColor other )

In place multiply operator.

Performs a componentwise multiplication of two colors.

Parameters:
[in] other Color to be multiplied with this color.
Returns:
A reference to the color whose value was modified.
MColor operator* ( const MColor other ) const

Multiply operator.

Performs a componentwise multiplication of two colors.

Parameters:
[in] other Color to be multiplied with this color.
Returns:
A new MColor object representing the product of the two colors.
MColor & operator/= ( float  scalar )

In place divide operator.

Parameters:
[in] scalar Color division factor.
Returns:
A reference to the color whose value was modified.
MColor operator/ ( float  scalar ) const

Divide operator.

Parameters:
[in] scalar Color division factor.
Returns:
A new MColor object representing the color divided by the scalar.
MColor & operator+= ( const MColor other )

In place add operator.

Parameters:
[in] other Color to be added to this color.
Returns:
A reference to the color whose value was modified.
MColor operator+ ( const MColor other ) const

Add operator.

Parameters:
[in] other Color to be added to this color.
Returns:
A new MColor object representing the sum of this color and the specified color.
MColor operator- ( ) const

Unary minus operator.

Negates the value of each of the red, green and blue components of the color.

Transparency is set to opaque.

Returns:
The negated color.
MColor operator- ( const MColor other ) const

Substraction operator.

Parameters:
[in] other Color to be subtracted from this color.
Returns:
A new MColor object representing this color minus the specified other color.
bool operator== ( const MColor other ) const

Equality operator.

Compares the r, g, and b components of two color.

Parameters:
[in] other Color to which this color will be compared.
Returns:
A bool value:
  • true if the colors are identical
  • false otherwise
bool operator!= ( const MColor other ) const

Inequality operator.

Compares the r, g, and b components of two color.

Parameters:
[in] other Color to which this color will be compared.
Returns:
A bool value:
  • false if the colors are identical
  • true otherwise
bool get ( float  d[3] ) const [inline]

Color component accessor.

Extracts the r, g, and b components of the color and places them in elements 0, 1, and 2 of the float array passed.

Parameters:
[out] d The array of 3 floats into which the results are placed.
Returns:
Always returns bool true.
bool get ( MColor::MColorType  colorModel,
float &  c1,
float &  c2,
float &  c3 
) const

Color component accessor.

Retrieves the values of 3 components of the color using the specified color model.

Parameters:
[in] colorModel The color model.
[out] c1 Storage for the first component of color.
[out] c2 Storage for the second component of color.
[out] c3 Storage for the third component of color.
Returns:
Always returns bool true.
bool get ( MColor::MColorType  colorModel,
float &  c1,
float &  c2,
float &  c3,
float &  alpha 
) const

Color component accessor.

Retrieves the values of 4 components of the color using the specified color model.

Parameters:
[in] colorModel The color model.
[out] c1 Storage for the first component of color.
[out] c2 Storage for the second component of color.
[out] c3 Storage for the third component of color.
[out] alpha Storage for the alpha component of color.
Returns:
Always returns bool true.
bool set ( MColor::MColorType  colorModel,
float  c1,
float  c2,
float  c3,
float  alpha = 1.0 
)

Color component assigment.

Sets the values of the color components using the specified color model.

Parameters:
[in] colorModel The color model.
[in] c1 First component of color.
[in] c2 Second component of color.
[in] c3 Third component of color.
[in] alpha Alpha component of color.
Returns:
Always returns bool true.
float & operator() ( unsigned int  i ) [inline]

Index operator. NO SCRIPT SUPPORT.

Accessor to one component of the color.

Parameters:
[in] i Value indicating which component to return.
Returns:
A reference to the appropriate component of the color:
  • Reference to the red channel when argument is 0.
  • Reference to the green channel when argument is 1.
  • Reference to the blue channel when argument is 2.
  • Reference to the alpha channel otherwise.
float & operator[] ( unsigned int  i ) [inline]

Index operator. NO SCRIPT SUPPORT.

Accessor to one component of the color.

Parameters:
[in] i Value indicating which component to return.
Returns:
A reference to the appropriate component of the color:
  • Reference to the red channel when argument is 0.
  • Reference to the green channel when argument is 1.
  • Reference to the blue channel when argument is 2.
  • Reference to the alpha channel otherwise.

Friends And Related Function Documentation

OPENMAYA_EXPORT MColor operator* ( float  scalar,
const MColor other 
) [friend]

Multiply operator. NO SCRIPT SUPPORT.

Parameters:
[in] scalar Color multiplication factor.
[in] other Color object to be multiplied.
Returns:
A new MColor object representing the product of the specified scalar and color.
OPENMAYA_EXPORT std::ostream& operator<< ( std::ostream &  os,
const MColor c 
) [friend]

Print operator. NO SCRIPT SUPPORT.

The format used is [r, g, b, a].

Parameters:
[in] os The ostream to print to.
[in] c The MColor whose value is to be printed.
Returns:
The ostream reference, os, provided as the first parameter.

MColor MColor MColor MColor MColor MColor MColor MColor MColor MColor
MColor MColor MColor MColor MColor MColor MColor MColor MColor MColor