10#define MI_MATH_COLOR_H
125 Float32 v = (Traits::has_signaling_NaN)
138#if (__cplusplus >= 201402L)
146#if (__cplusplus >= 201402L)
154#if (__cplusplus >= 201402L)
172 template <
typename T>
173#if (__cplusplus >= 201402L)
182#if (__cplusplus >= 201402L)
190#if (__cplusplus >= 201402L)
243 return (
r == 0.0f) && (
g == 0.0f) && (
b == 0.0f);
258 return r * 0.299f +
g * 0.587f +
b * 0.114f;
267 return r * 0.212671f +
g * 0.715160f +
b * 0.072169f;
382 return { lhs.
r + rhs.
r, lhs.
g + rhs.
g, lhs.
b + rhs.
b, lhs.
a + rhs.
a};
388 return { lhs.
r - rhs.
r, lhs.
g - rhs.
g, lhs.
b - rhs.
b, lhs.
a - rhs.
a};
394 return { lhs.
r * rhs.
r, lhs.
g * rhs.
g, lhs.
b * rhs.
b, lhs.
a * rhs.
a};
400 return { lhs.
r / rhs.
r, lhs.
g / rhs.
g, lhs.
b / rhs.
b, lhs.
a / rhs.
a};
406 return { -c.
r, -c.
g, -c.
b, -c.
a};
437 return { c.
r * s, c.
g * s, c.
b * s, c.
a * s};
444 return { s * c.
r, s * c.
g, s* c.
b, s * c.
a};
451 return { c.
r * f, c.
g * f, c.
b * f, c.
a * f};
473 return (c.
r != 0.0f) && (c.
g != 0.0f) && (c.
b != 0.0f) && (c.
a != 0.0f);
479 return (c.
r != 0.0f) || (c.
g != 0.0f) || (c.
b != 0.0f) || (c.
a != 0.0f);
512 return {
clamp( c.
r, low.
r, high.
r),
521 return {
clamp( c.
r, low.
r, high),
530 return {
clamp( c.
r, low, high.
r),
539 return {
clamp( c.
r, low, high),
656 return {
lerp( c1.
r, c2.
r, t.
r),
670 return {
lerp( c1.
r, c2.
r, t),
872#ifndef MI_FOR_DOXYGEN_ONLY
876 bool desaturate)
const
883 if( col.
a < col.
r) col.
a = col.
r;
884 if( col.
a < col.
g) col.
a = col.
g;
885 if( col.
a < col.
b) col.
a = col.
b;
912 return { 0, 0, 0,
a};
914 return { maxval, maxval, maxval,
a};
925 t = (maxval - axis) / drds;
926 if( t < sat) sat = t;
930 if( t < sat) sat = t;
934 t = (maxval - axis) / dgds;
935 if( t < sat) sat = t;
939 if( t < sat) sat = t;
943 t = (maxval - axis) / dbds;
944 if( t < sat) sat = t;
948 if( t < sat) sat = t;
954 return {
math::clamp( axis + drds * sat, 0.0f, maxval),
Standard RGBA color class with floating point elements and operations.
Definition: color.h:81
Fixed-size math vector class template with generic operations.
Definition: vector.h:286
Math functions and function templates on simple types or generic container and vector concepts.
#define MI_PREVENT_MACRO_EXPAND
Empty macro that can be used after function names to prevent macro expansion that happen to have the ...
Definition: config.h:97
unsigned char Uint8
8-bit unsigned integer.
Definition: types.h:47
float Float32
32-bit float.
Definition: types.h:51
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
Sint64 Difference
Signed integral type that is large enough to hold the difference of two pointers.
Definition: types.h:122
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
bool lexicographically_less(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically less than vector rhs, and false otherwise.
Definition: function.h:1114
bool lexicographically_less_or_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically less than or equal to vector rhs, and false otherwise...
Definition: function.h:1130
Float32 fast_pow(Float32 b, Float32 e)
A fast implementation of pow(x,y) for floats.
Definition: function.h:405
bool lexicographically_greater_or_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically greater than or equal to vector rhs,...
Definition: function.h:1162
bool is_not_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is elementwise not equal to vector rhs, and false otherwise.
Definition: function.h:1101
bool lexicographically_greater(const V &lhs, const V &rhs)
Returns true if vector lhs is lexicographically greater than vector rhs, and false otherwise.
Definition: function.h:1146
bool is_equal(const V &lhs, const V &rhs)
Returns true if vector lhs is elementwise equal to vector rhs, and false otherwise.
Definition: function.h:1090
#define mi_math_assert_msg(expr, msg)
Math API assertion macro (with message).
Definition: assert.h:80
#define mi_math_assert(expr)
Math API assertion macro (without message).
Definition: assert.h:61
bool operator>=(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically greater than or equal to rhs.
Definition: bbox.h:650
Bbox<T, DIM> operator+(const Bbox<T, DIM> &bbox, T value)
Returns a bounding box that is the bbox increased by a constant value at each face,...
Definition: bbox.h:468
bool operator<(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically less than rhs.
Definition: bbox.h:605
Bbox<T, DIM> & operator*=(Bbox<T, DIM> &bbox, T factor)
Scales bbox by factor, i.e., bbox.max and bbox.min are multiplied by factor.
Definition: bbox.h:562
Bbox<T, DIM> & operator+=(Bbox<T, DIM> &bbox, T value)
Increases bbox by a constant value at each face, i.e., value is added to bbox.max and subtracted from...
Definition: bbox.h:533
bool operator==(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is elementwise equal to rhs.
Definition: bbox.h:589
bool operator>(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically greater than rhs.
Definition: bbox.h:635
Bbox<T, DIM> & operator/=(Bbox<T, DIM> &bbox, T divisor)
Divide bbox by divisor, i.e., bbox.max and bbox.min are divided by divisor.
Definition: bbox.h:576
Bbox<T, DIM> operator/(const Bbox<T, DIM> &bbox, T divisor)
Returns a bounding box that is a version of bbox divided by divisor, i.e., bbox.max and bbox....
Definition: bbox.h:516
bool operator!=(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is elementwise not equal to rhs.
Definition: bbox.h:596
bool operator<=(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically less than or equal to rhs.
Definition: bbox.h:620
Bbox<T, DIM> & operator-=(Bbox<T, DIM> &bbox, T value)
Shrinks bbox by a constant value at each face, i.e., value is subtracted from bbox....
Definition: bbox.h:548
Bbox<T, DIM> operator-(const Bbox<T, DIM> &bbox, T value)
Returns a bounding box that is the bbox shrunk by a constant value at each face, i....
Definition: bbox.h:484
Bbox<T, DIM> operator*(const Bbox<T, DIM> &bbox, T factor)
Returns a bounding box that is a version of bbox scaled by factor, i.e., bbox.max and bbox....
Definition: bbox.h:500
Bbox<T, DIM> lerp(const Bbox<T, DIM> &bbox1, const Bbox<T, DIM> &bbox2, T t)
Returns the linear interpolation between bbox1 and bbox2, i.e., it returns (1-t) * bbox1 + t * bbox2.
Definition: bbox.h:670
Color & operator=(const Color &c)=default
Assignment operator.
Color desaturate(Float32 maxval=1.0f) const
Returns this color clipped to the range [0,maxval] using color desaturation.
Color frac(const Color &c)
Returns a color with the elementwise positive fractional part of the color c.
Definition: color.h:613
Color sqrt(const Color &c)
Returns the square root of each element of c.
Definition: color.h:792
Float32 linear_intensity() const
Returns the intensity of the RGB components, equally weighted.
Definition: color.h:247
bool isinfinite(const Color &c)
Indicates whether any component of the color is infinite.
Definition: color.h:819
Color(T array[4])
Constructor initializes the color elements from a 4-dimensional array.
Definition: color.h:176
Color acos(const Color &c)
Returns a color with the elementwise arc cosine of the color c.
Definition: color.h:465
Color ceil(const Color &c)
Returns a color with the elementwise smallest integral value that is not less than the element in col...
Definition: color.h:504
bool is_black() const
Returns true if the color is black ignoring the alpha value.
Definition: color.h:241
Color clamp(const Color &c, const Color &low, const Color &high)
Returns the color c elementwise clamped to the range [low, high].
Definition: color.h:510
Color abs(const Color &c)
Returns a color with the elementwise absolute values of the color c.
Definition: color.h:459
Float32 & reference
Mutable reference to element.
Definition: color.h:90
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.
Definition: color.h:185
const Float32 * end() const
Returns the past-the-end pointer.
Definition: color.h:115
const Float32 * const_pointer
Const pointer to element.
Definition: color.h:89
Color round(const Color &c)
Returns a color with the elements of color c rounded to nearest integers.
Definition: color.h:725
Color modf(const Color &c, Color &i)
Returns the elementwise fractional part of c and stores the elementwise integral part of c in i.
Definition: color.h:701
Float32 ntsc_intensity() const
Returns the intensity of the RGB components, weighted according to the NTSC standard.
Definition: color.h:256
Color(const Color_struct &c)
Constructor from underlying storage type.
Definition: color.h:141
MI_HOST_DEVICE_INLINE void from_rgbe(const Uint8 rgbe[4], Color &color)
Decodes a color from RGBE representation.
Definition: color.h:855
Color atan(const Color &c)
Returns a color with the elementwise arc tangent of the color c.
Definition: color.h:489
bool isfinite(const Color &c)
Indicates whether all components of the color are finite.
Definition: color.h:810
Float32 * end()
Returns the past-the-end pointer.
Definition: color.h:110
Float32 * begin()
Returns the pointer to the first color element.
Definition: color.h:102
Color step(const Color &a, const Color &c)
Returns elementwise 0 if c is less than a and 1 otherwise.
Definition: color.h:798
Color elementwise_min(const Color &lhs, const Color &rhs)
Returns elementwise min for each element in color lhs that is less than the corresponding element in ...
Definition: color.h:569
Float32 * pointer
Mutable pointer to element.
Definition: color.h:88
void set(Size i, Float32 value)
Sets the i-th color element to value, 0 <= i < 4.
Definition: color.h:234
Color tan(const Color &c)
Returns a color with the elementwise tangent of the color c.
Definition: color.h:804
Color atan2(const Color &c, const Color &d)
Returns a color with the elementwise arc tangent of the color c / d.
Definition: color.h:497
Difference difference_type
Difference type, signed.
Definition: color.h:87
Color(Float32 nr, Float32 ng, Float32 nb, Float32 na=1.0f)
Constructor initializes (r,g,b,a) from (nr,ng,nb,na).
Definition: color.h:157
Color sin(const Color &c)
Returns a color with the elementwise sine of the color c.
Definition: color.h:749
Color degrees(const Color &c)
Converts elementwise radians in c to degrees.
Definition: color.h:552
Color saturate(const Color &c)
Returns the color c clamped elementwise to the range [0,1].
Definition: color.h:737
Color rsqrt(const Color &c)
Returns the reciprocal of the square root of each element of c.
Definition: color.h:731
bool any(const Color &c)
Returns true if any element of c is not equal to zero.
Definition: color.h:477
Color radians(const Color &c)
Converts elementwise degrees in c to radians.
Definition: color.h:719
static constexpr Size max_size()
Constant maximum size of the color.
Definition: color.h:99
const Float32 * begin() const
Returns the pointer to the first color element.
Definition: color.h:105
Color exp2(const Color &c)
Returns a color with elementwise 2 to the power of the element in the color c.
Definition: color.h:584
Color elementwise_max(const Color &lhs, const Color &rhs)
Returns elementwise max for each element in color lhs that is less than the corresponding element in ...
Definition: color.h:559
Size size_type
Size type, unsigned.
Definition: color.h:86
static constexpr Size size()
Constant size of the color.
Definition: color.h:96
Color log(const Color &c)
Returns a color with elementwise natural logarithm of the color c.
Definition: color.h:677
Color floor(const Color &c)
Returns a color with the elementwise largest integral value that is not greater than the element in c...
Definition: color.h:591
Color smoothstep(const Color &a, const Color &b, const Color &c)
Returns 0 if c is less than a and 1 if c is greater than b in an elementwise fashion.
Definition: color.h:770
Float32 & operator[](Size i)
Accesses the i-th color element, 0 <= i < 4.
Definition: color.h:219
Color sign(const Color &c)
Returns the elementwise sign of color c.
Definition: color.h:743
Color fmod(const Color &a, const Color &b)
Returns elementwise a modulo b, in other words, the remainder of a/b.
Definition: color.h:599
Float32 cie_intensity() const
Returns the intensity of the RGB components, weighted according to the CIE standard.
Definition: color.h:265
Color cos(const Color &c)
Returns a color with the elementwise cosine of the color c.
Definition: color.h:546
Color(const Color &c)=default
Default copy constructor.
Float32 value_type
Element type.
Definition: color.h:85
MI_HOST_DEVICE_INLINE void to_rgbe(const Color &color, Uint32 &rgbe)
Encodes a color into RGBE representation.
Definition: color.h:839
Color pow(const Color &a, const Color &b)
Returns the color a elementwise to the power of b.
Definition: color.h:707
const Float32 & const_reference
Const reference to element.
Definition: color.h:91
Float32 c[3]
Three color bands.
Definition: color.h:49
Float32 get(Size i) const
Returns the i-th color element, 0 <= i < 4.
Definition: color.h:227
bool all(const Color &c)
Returns true if all elements of c are not equal to zero.
Definition: color.h:471
bool isnan(const Color &c)
Indicates whether any component of the color is "not a number".
Definition: color.h:828
Color(const Spectrum_struct &s)
Conversion from Spectrum.
Definition: color.h:193
Color & operator=(const Vector<Float32, 4> &v)
Assignment operator from compatible 4D vector, setting (r,g,b,a) to (v.x, v.y, v.z,...
Definition: color.h:202
Clip_mode
Supported clipping modes.
Definition: color.h:57
const Float32 & operator[](Size i) const
Accesses the i-th color element, 0 <= i < 4.
Definition: color.h:212
static constexpr Size SIZE
Constant size of the color.
Definition: color.h:93
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 overbrigh...
Color gamma_correction(const Color &color, Float32 gamma_factor)
Returns a gamma corrected color.
Definition: color.h:625
Color log10(const Color &c)
Returns a color with elementwise base 10 logarithm of the color c.
Definition: color.h:692
Color()
The default constructor leaves the color elements uninitialized.
Definition: color.h:118
Color log2(const Color &c)
Returns a color with elementwise base 2 logarithm of the color c.
Definition: color.h:683
Color exp(const Color &c)
Returns a color with elementwise e to the power of the element in the color c.
Definition: color.h:578
bool is_approx_equal(const Color &lhs, const Color &rhs, Float32 e)
Compares the two given values elementwise for equality within the given epsilon.
Definition: color.h:638
void sincos(const Color &a, Color &s, Color &c)
Computes elementwise the sine s and cosine c of angles a simultaneously.
Definition: color.h:757
Color(const Float32 s)
Constructor initializes all vector elements to the value s.
Definition: color.h:149
Color asin(const Color &c)
Returns a color with the elementwise arc sine of the color c.
Definition: color.h:483
@ CLIP_RAW
Clip RGB and A to [0,1].
Definition: color.h:60
@ CLIP_ALPHA
First clip A to [0,1], then clip RGB to [0,A].
Definition: color.h:59
@ CLIP_RGB
First clip RGB to [0,1], then clip A to [max(R,G,B),1].
Definition: color.h:58
Float32 g
Green color component.
Definition: vector.h:71
Float32 a
Alpha value, 0.0 is fully transparent and 1.0 is opaque; value can lie outside that range.
Definition: vector.h:75
Float32 r
Red color component.
Definition: vector.h:69
Float32 b
Blue color component.
Definition: vector.h:73
math::Color_struct Color_struct
RGBA color class (underlying POD type).
Definition: typedefs.h:34
math::Color Color
RGBA color class.
Definition: typedefs.h:28
Assertions and compile-time assertions.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: example_derivatives.dox:5
Numeric traits specialization for mi::Float32.
Definition: types.h:531
Generic storage class template for an RGBA color representation storing four floating points elements...
Definition: vector.h:67
Generic storage class template for a Spectrum representation storing three floating point elements.
Definition: color.h:47
Math vector class template of fixed dimension with arithmetic operators and generic functions.