Drake
Drake C++ Documentation
Rgba Class Reference

Detailed Description

Defines RGBA (red, green, blue, alpha) values on the range [0, 1].

#include <drake/geometry/rgba.h>

Public Member Functions

 Rgba ()=default
 Default constructor produces fully opaque white. More...
 
 Rgba (double r, double g, double b, double a=1.0)
 Constructs with given (r, g, b, a) values. More...
 
double r () const
 Red. More...
 
double g () const
 Green. More...
 
double b () const
 Blue. More...
 
double a () const
 Alpha. More...
 
Eigen::Vector4d rgba () const
 Returns all four elements in order. More...
 
void set (double r, double g, double b, double a=1.0)
 Sets (r, g, b, a) values. More...
 
void set (const Eigen::Ref< const Eigen::VectorXd > &rgba)
 Sets an (r, g, b, a) from a vector. More...
 
void update (std::optional< double > r={}, std::optional< double > g={}, std::optional< double > b={}, std::optional< double > a={})
 Updates individual (r, g, b, a) values; any values not provided will remain unchanged. More...
 
bool AlmostEqual (const Rgba &other, double tolerance=0.0) const
 Reports if two Rgba values are equal within a given absolute tolerance. More...
 
bool operator== (const Rgba &other) const
 
bool operator!= (const Rgba &other) const
 
Rgba operator * (const Rgba &other) const
 Computes the element-wise product of two rgba colors. More...
 
Rgba scale_rgb (double scale) const
 Computes a new Rgba color by multiplying the color channels (rgb) by the given scalar scalar. More...
 
template<typename Archive >
void Serialize (Archive *a)
 Passes this object to an Archive. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 Rgba (const Rgba &)=default
 
Rgbaoperator= (const Rgba &)=default
 
 Rgba (Rgba &&)=default
 
Rgbaoperator= (Rgba &&)=default
 

Friends

std::ostream & operator<< (std::ostream &out, const Rgba &rgba)
 

Constructor & Destructor Documentation

◆ Rgba() [1/4]

Rgba ( const Rgba )
default

◆ Rgba() [2/4]

Rgba ( Rgba &&  )
default

◆ Rgba() [3/4]

Rgba ( )
default

Default constructor produces fully opaque white.

◆ Rgba() [4/4]

Rgba ( double  r,
double  g,
double  b,
double  a = 1.0 
)

Constructs with given (r, g, b, a) values.

Precondition
All values are within the range of [0, 1].

Member Function Documentation

◆ a()

double a ( ) const

Alpha.

◆ AlmostEqual()

bool AlmostEqual ( const Rgba other,
double  tolerance = 0.0 
) const

Reports if two Rgba values are equal within a given absolute tolerance.

They are "equal" so long as the difference in no single channel is larger than the specified tolerance.

◆ b()

double b ( ) const

Blue.

◆ g()

double g ( ) const

Green.

◆ operator *()

Rgba operator * ( const Rgba other) const

Computes the element-wise product of two rgba colors.

This type of calculation is frequently used to modulate one color with another (e.g., for lighting or texturing).

◆ operator!=()

bool operator!= ( const Rgba other) const

◆ operator=() [1/2]

Rgba& operator= ( Rgba &&  )
default

◆ operator=() [2/2]

Rgba& operator= ( const Rgba )
default

◆ operator==()

bool operator== ( const Rgba other) const

◆ r()

double r ( ) const

Red.

◆ rgba()

Eigen::Vector4d rgba ( ) const

Returns all four elements in order.

◆ scale_rgb()

Rgba scale_rgb ( double  scale) const

Computes a new Rgba color by multiplying the color channels (rgb) by the given scalar scalar.

All resultant channel values saturate at one. The result has this Rgba's alpha values.

Precondition
scale >= 0.

◆ Serialize()

void Serialize ( Archive *  a)

Passes this object to an Archive.

In YAML, an Rgba is represented by an array-like list of three or four numbers. E.g.,

 rgba: [0.5, 0.5, 1.0]

or

 rgba: [0.5, 0.5, 1.0, 0.5]

such that the first three values are red, green, and blue, respectively. If no fourth value is provided, alpha is defined a 1.0.

Refer to YAML Serialization for background.

◆ set() [1/2]

void set ( double  r,
double  g,
double  b,
double  a = 1.0 
)

Sets (r, g, b, a) values.

Exceptions
std::exceptionif any values are outside of the range [0, 1].

◆ set() [2/2]

void set ( const Eigen::Ref< const Eigen::VectorXd > &  rgba)

Sets an (r, g, b, a) from a vector.

Exceptions
std::exceptionif the vector is not size 3 or 4.
std::exceptionif any values are outside of the range [0, 1].

◆ update()

void update ( std::optional< double r = {},
std::optional< double g = {},
std::optional< double b = {},
std::optional< double a = {} 
)

Updates individual (r, g, b, a) values; any values not provided will remain unchanged.

Exceptions
std::exceptionif any values are outside of the range [0, 1].

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const Rgba rgba 
)
friend

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