Class Color¶
Defined in File common.h
Page Contents
Class Documentation¶
-
class
Color
: public Vector4f¶ Stores an RGBA floating point color value.
This class simply wraps around an
Eigen::Vector4f
, providing some convenient methods and terminology for thinking of it as a color. The data operates in the same way asEigen::Vector4f
, and the following values are identical:Channel
Array Index
Eigen::Vector4f Value
Color Value
Red
0
x()
r()
Green
1
y()
g()
Blue
2
z()
b()
Alpha
3
w()
w()
Note
The method for the alpha component is always
w()
.You can and should still use the various convenience methods such as
any()
,all()
,head<index>()
, etc provided by Eigen.Public Functions
-
Color
()¶ Default constructor: represents black (
r, g, b, a = 0
)
-
Color
(const Eigen::Vector4f &color)¶ Makes an exact copy of the data represented by the input parameter.
- Parameters
color
: The four dimensional float vector being copied.
-
Color
(const Eigen::Vector3f &color, float alpha)¶ Copies (x, y, z) from the input vector, and uses the value specified by the
alpha
parameter for this Color object’s alpha component.- Parameters
color
: The three dimensional float vector being copied.alpha
: The value to set this object’s alpha component to.
-
Color
(const Eigen::Vector3i &color, int alpha)¶ Copies (x, y, z) from the input vector, casted as floats first and then divided by
255.0
, and uses the value specified by thealpha
parameter, casted to a float and divided by255.0
as well, for this Color object’s alpha component.- Parameters
color
: The three dimensional integer vector being copied, will be divided by255.0
.alpha
: The value to set this object’s alpha component to, will be divided by255.0
.
-
Color
(const Eigen::Vector3f &color)¶ Copies (x, y, z) from the input vector, and sets the alpha of this color to be
1.0
.- Parameters
color
: The three dimensional float vector being copied.
-
Color
(const Eigen::Vector3i &color)¶ Copies (x, y, z) from the input vector, casting to floats and dividing by
255.0
. The alpha of this color will be set to1.0
.- Parameters
color
: The three dimensional integer vector being copied, will be divided by255.0
.
-
Color
(const Eigen::Vector4i &color)¶ Copies (x, y, z, w) from the input vector, casting to floats and dividing by
255.0
.- Parameters
color
: The three dimensional integer vector being copied, will be divided by255.0
.
-
Color
(float intensity, float alpha)¶ Creates the Color
(intensity, intensity, intensity, alpha)
.- Parameters
intensity
: The value to be used for red, green, and blue.alpha
: The alpha component of the color.
-
Color
(int intensity, int alpha)¶ Creates the Color
(intensity, intensity, intensity, alpha) / 255.0
. Values are casted to floats before division.- Parameters
intensity
: The value to be used for red, green, and blue, will be divided by255.0
.alpha
: The alpha component of the color, will be divided by255.0
.
-
Color
(float r, float g, float b, float a)¶ Explicit constructor: creates the Color
(r, g, b, a)
.- Parameters
r
: The red component of the color.g
: The green component of the color.b
: The blue component of the color.a
: The alpha component of the color.
-
Color
(int r, int g, int b, int a)¶ Explicit constructor: creates the Color
(r, g, b, a) / 255.0
. Values are casted to floats before division.- Parameters
r
: The red component of the color, will be divided by255.0
.g
: The green component of the color, will be divided by255.0
.b
: The blue component of the color, will be divided by255.0
.a
: The alpha component of the color, will be divided by255.0
.
-
template<typename
Derived
>Color
(const Eigen::MatrixBase<Derived> &p)¶ Construct a color vector from MatrixBase (needed to play nice with Eigen)
-
template<typename
Derived
>
Color &operator=
(const Eigen::MatrixBase<Derived> &p)¶ Assign a color vector from MatrixBase (needed to play nice with Eigen)
-
float &
r
()¶ Return a reference to the red channel.
-
const float &
r
() const¶ Return a reference to the red channel (const version)
-
float &
g
()¶ Return a reference to the green channel.
-
const float &
g
() const¶ Return a reference to the green channel (const version)
-
float &
b
()¶ Return a reference to the blue channel.
-
const float &
b
() const¶ Return a reference to the blue channel (const version)
-
Color
contrastingColor
() const¶ Computes the luminance as
l = 0.299r + 0.587g + 0.144b + 0.0a
. If the luminance is less than 0.5, white is returned. If the luminance is greater than or equal to 0.5, black is returned. Both returns will have an alpha component of 1.0.
-
operator const NVGcolor&
() const¶ Allows for conversion between this Color and NanoVG’s representation.
Allows for conversion between nanogui::Color and the NanoVG NVGcolor class.
-