Drake
Drake C++ Documentation
Loading...
Searching...
No Matches
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.
 Rgba (double r, double g, double b, double a=1.0)
 Constructs with given (r, g, b, a) values.
double r () const
 Red.
double g () const
 Green.
double b () const
 Blue.
double a () const
 Alpha.
Eigen::Vector4d rgba () const
 Returns all four elements in order.
void set (double r, double g, double b, double a=1.0)
 Sets (r, g, b, a) values.
void set (const Eigen::Ref< const Eigen::VectorXd > &rgba)
 Sets an (r, g, b, a) from a vector.
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.
bool AlmostEqual (const Rgba &other, double tolerance=0.0) const
 Reports if two Rgba values are equal within a given absolute tolerance.
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.
Rgba scale_rgb (double scale) const
 Computes a new Rgba color by multiplying the color channels (rgb) by the given scalar scalar.
std::string to_string () const
 Converts the Rgba value to a string representation.
template<typename Archive>
void Serialize (Archive *a)
 Passes this object to an Archive.
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 Rgba (const Rgba &)=default
Rgbaoperator= (const Rgba &)=default
 Rgba (Rgba &&)=default
Rgbaoperator= (Rgba &&)=default

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!=()

bool operator!= ( const Rgba & other) const

◆ 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=() [1/2]

Rgba & operator= ( const Rgba & )
default

◆ operator=() [2/2]

Rgba & operator= ( 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()

template<typename Archive>
void Serialize ( Archive * a)

Passes this object to an Archive.

In YAML, an Rgba is represented by a mapping of the symbol rgba to 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.

When another struct has an Rgba-valued member (e.g., systems::sensors::CameraConfig::background), remember to include the full mapping. For example, imagine the struct:

struct Foo {
Rgba color1;
Rgba color2;
};
Rgba(const Rgba &)=default

The correct yaml representation of this would be:

color1:
rgba: [0.5, 0.5, 1.0]
color2:
rgba: [1.0, 0.0, 0.0, 0.5]

The values of color1 and color2 are the mapping from rgba to the desired color tuples.

Refer to YAML Serialization for background.

◆ set() [1/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].

◆ set() [2/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].

◆ to_string()

std::string to_string ( ) const

Converts the Rgba value to a string representation.

◆ 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].

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