MDL SDK API nvidia_logo_transpbg.gif Up
color.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2025 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
8
9#ifndef MI_MATH_COLOR_H
10#define MI_MATH_COLOR_H
11
12#include <mi/base/types.h>
13#include <mi/math/assert.h>
14#include <mi/math/function.h>
15#include <mi/math/vector.h>
16
17namespace mi {
18
19namespace math {
20
32// Color and Spectrum can be converted into each other. To avoid cyclic dependencies among the
33// headers, the Spectrum_struct class is already defined here.
34
35//------- POD struct that provides storage for spectrum elements --------
36
47{
50};
51
52//------ Color Class ---------------------------------------------------------
53
61};
62
80class Color : public Color_struct //-V690 PVS
81{
82public:
86 using size_type = Size;
88 using pointer = Float32 *;
89 using const_pointer = const Float32*;
90 using reference = Float32 &;
91 using const_reference = const Float32&;
92
93 static constexpr Size SIZE = 4;
94
96 static constexpr inline Size size() { return SIZE; }
97
99 static constexpr inline Size max_size() { return SIZE; }
100
102 inline Float32* begin() { return &r; }
103
105 inline const Float32* begin() const { return &r; }
106
110 inline Float32* end() { return begin() + SIZE; }
111
115 inline const Float32* end() const { return begin() + SIZE; }
116
118 inline Color()
119 {
120#ifndef NDEBUG
121 // In debug mode, default-constructed colors are initialized with signaling NaNs or, if not
122 // applicable, with a maximum value to increase the chances of diagnosing incorrect use of
123 // an uninitialized color.
125 Float32 v = (Traits::has_signaling_NaN)
126 ? Traits::signaling_NaN() : Traits::max MI_PREVENT_MACRO_EXPAND ();
127 r = v;
128 g = v;
129 b = v;
130 a = v;
131#endif
132 }
133
135 Color( const Color& c) = default;
136
138#if (__cplusplus >= 201402L)
139 constexpr
140#endif
141 inline Color( const Color_struct& c) : Color_struct{c.r,c.g,c.b,c.a}
142 {
143 }
144
146#if (__cplusplus >= 201402L)
147 constexpr
148#endif
149 inline explicit Color( const Float32 s) : Color_struct{s,s,s,s}
150 {
151 }
152
154#if (__cplusplus >= 201402L)
155 constexpr
156#endif
157 inline Color( Float32 nr, Float32 ng, Float32 nb, Float32 na = 1.0f) : Color_struct{nr,ng,nb,na}
158 {
159 }
160
172 template <typename T>
173#if (__cplusplus >= 201402L)
174 constexpr
175#endif
176 inline explicit Color( T array[4]) : Color_struct{array[0],array[1],array[2],array[3]}
177 {
178 }
179
182#if (__cplusplus >= 201402L)
183 constexpr
184#endif
185 inline explicit Color( const Vector<Float32,4>& v) : Color_struct{v.x,v.y,v.z,v.w}
186 {
187 }
188
190#if (__cplusplus >= 201402L)
191 constexpr
192#endif
193 inline explicit Color( const Spectrum_struct& s) : Color_struct{s.c[0],s.c[1],s.c[2],1.0f}
194 {
195 }
196
198 inline Color& operator=( const Color& c) = default;
199
203 {
204 r = v.x;
205 g = v.y;
206 b = v.z;
207 a = v.w;
208 return *this;
209 }
210
212 inline const Float32& operator[]( Size i) const
213 {
214 mi_math_assert_msg( i < 4, "precondition");
215 return (&r)[i];
216 }
217
220 {
221 mi_math_assert_msg( i < 4, "precondition");
222 return (&r)[i];
223 }
224
225
227 inline Float32 get( Size i) const
228 {
229 mi_math_assert_msg( i < 4, "precondition");
230 return (&r)[i];
231 }
232
234 inline void set( Size i, Float32 value)
235 {
236 mi_math_assert_msg( i < 4, "precondition");
237 (&r)[i] = value;
238 }
239
241 inline bool is_black() const
242 {
243 return (r == 0.0f) && (g == 0.0f) && (b == 0.0f);
244 }
245
248 {
249 return (r + g + b) * Float32(1.0 / 3.0);
250 }
251
256 inline Float32 ntsc_intensity() const
257 {
258 return r * 0.299f + g * 0.587f + b * 0.114f;
259 }
260
265 inline Float32 cie_intensity() const
266 {
267 return r * 0.212671f + g * 0.715160f + b * 0.072169f;
268 }
269
274 inline Color clip( Clip_mode mode = CLIP_RGB, bool desaturate = false) const;
275
276
286 inline Color desaturate( Float32 maxval = 1.0f) const;
287};
288
289//------ Free comparison operators ==, !=, <, <=, >, >= for colors ------------
290
292inline bool operator==( const Color& lhs, const Color& rhs)
293{
294 return is_equal( lhs, rhs);
295}
296
298inline bool operator!=( const Color& lhs, const Color& rhs)
299{
300 return is_not_equal( lhs, rhs);
301}
302
306inline bool operator<( const Color& lhs, const Color& rhs)
307{
308 return lexicographically_less( lhs, rhs);
309}
310
314inline bool operator<=( const Color& lhs, const Color& rhs)
315{
316 return lexicographically_less_or_equal( lhs, rhs);
317}
318
322inline bool operator>( const Color& lhs, const Color& rhs)
323{
324 return lexicographically_greater( lhs, rhs);
325}
326
330inline bool operator>=( const Color& lhs, const Color& rhs)
331{
332 return lexicographically_greater_or_equal( lhs, rhs);
333}
334
335
336
337//------ Free operators +=, -=, *=, /=, +, -, *, and / for colors --------------
338
340inline Color& operator+=( Color& lhs, const Color& rhs)
341{
342 lhs.r += rhs.r;
343 lhs.g += rhs.g;
344 lhs.b += rhs.b;
345 lhs.a += rhs.a;
346 return lhs;
347}
348
350inline Color& operator-=( Color& lhs, const Color& rhs)
351{
352 lhs.r -= rhs.r;
353 lhs.g -= rhs.g;
354 lhs.b -= rhs.b;
355 lhs.a -= rhs.a;
356 return lhs;
357}
358
360inline Color& operator*=( Color& lhs, const Color& rhs)
361{
362 lhs.r *= rhs.r;
363 lhs.g *= rhs.g;
364 lhs.b *= rhs.b;
365 lhs.a *= rhs.a;
366 return lhs;
367}
368
370inline Color& operator/=( Color& lhs, const Color& rhs)
371{
372 lhs.r /= rhs.r;
373 lhs.g /= rhs.g;
374 lhs.b /= rhs.b;
375 lhs.a /= rhs.a;
376 return lhs;
377}
378
380inline Color operator+( const Color& lhs, const Color& rhs)
381{
382 return { lhs.r + rhs.r, lhs.g + rhs.g, lhs.b + rhs.b, lhs.a + rhs.a};
383}
384
386inline Color operator-( const Color& lhs, const Color& rhs)
387{
388 return { lhs.r - rhs.r, lhs.g - rhs.g, lhs.b - rhs.b, lhs.a - rhs.a};
389}
390
392inline Color operator*( const Color& lhs, const Color& rhs)
393{
394 return { lhs.r * rhs.r, lhs.g * rhs.g, lhs.b * rhs.b, lhs.a * rhs.a};
395}
396
398inline Color operator/( const Color& lhs, const Color& rhs)
399{
400 return { lhs.r / rhs.r, lhs.g / rhs.g, lhs.b / rhs.b, lhs.a / rhs.a};
401}
402
404inline Color operator-( const Color& c)
405{
406 return { -c.r, -c.g, -c.b, -c.a};
407}
408
409
410
411//------ Free operator *=, /=, *, and / definitions for scalars ---------------
412
415{
416 c.r *= s;
417 c.g *= s;
418 c.b *= s;
419 c.a *= s;
420 return c;
421}
422
425{
426 const Float32 f = 1.0f / s;
427 c.r *= f;
428 c.g *= f;
429 c.b *= f;
430 c.a *= f;
431 return c;
432}
433
435inline Color operator*( const Color& c, Float32 s)
436{
437 return { c.r * s, c.g * s, c.b * s, c.a * s};
438}
439
442inline Color operator*( Float32 s, const Color& c)
443{
444 return { s * c.r, s * c.g, s* c.b, s * c.a};
445}
446
448inline Color operator/( const Color& c, Float32 s)
449{
450 const Float32 f = 1.0f / s;
451 return { c.r * f, c.g * f, c.b * f, c.a * f};
452}
453
454
455//------ Function Overloads for Color Algorithms ------------------------------
456
457
459inline Color abs( const Color& c)
460{
461 return { abs( c.r), abs( c.g), abs( c.b), abs( c.a)};
462}
463
465inline Color acos( const Color& c)
466{
467 return { acos( c.r), acos( c.g), acos( c.b), acos( c.a)};
468}
469
471inline bool all( const Color& c)
472{
473 return (c.r != 0.0f) && (c.g != 0.0f) && (c.b != 0.0f) && (c.a != 0.0f);
474}
475
477inline bool any( const Color& c)
478{
479 return (c.r != 0.0f) || (c.g != 0.0f) || (c.b != 0.0f) || (c.a != 0.0f);
480}
481
483inline Color asin( const Color& c)
484{
485 return { asin( c.r), asin( c.g), asin( c.b), asin( c.a)};
486}
487
489inline Color atan( const Color& c)
490{
491 return { atan( c.r), atan( c.g), atan( c.b), atan( c.a)};
492}
493
497inline Color atan2( const Color& c, const Color& d)
498{
499 return { atan2( c.r, d.r), atan2( c.g, d.g), atan2( c.b, d.b), atan2( c.a, d.a)};
500}
501
504inline Color ceil( const Color& c)
505{
506 return { ceil( c.r), ceil( c.g), ceil( c.b), ceil( c.a)};
507}
508
510inline Color clamp( const Color& c, const Color& low, const Color& high)
511{
512 return { clamp( c.r, low.r, high.r),
513 clamp( c.g, low.g, high.g),
514 clamp( c.b, low.b, high.b),
515 clamp( c.a, low.a, high.a)};
516}
517
519inline Color clamp( const Color& c, const Color& low, Float32 high)
520{
521 return { clamp( c.r, low.r, high),
522 clamp( c.g, low.g, high),
523 clamp( c.b, low.b, high),
524 clamp( c.a, low.a, high)};
525}
526
528inline Color clamp( const Color& c, Float32 low, const Color& high)
529{
530 return { clamp( c.r, low, high.r),
531 clamp( c.g, low, high.g),
532 clamp( c.b, low, high.b),
533 clamp( c.a, low, high.a)};
534}
535
537inline Color clamp( const Color& c, Float32 low, Float32 high)
538{
539 return { clamp( c.r, low, high),
540 clamp( c.g, low, high),
541 clamp( c.b, low, high),
542 clamp( c.a, low, high)};
543}
544
546inline Color cos( const Color& c)
547{
548 return { cos( c.r), cos( c.g), cos( c.b), cos( c.a)};
549}
550
552inline Color degrees( const Color& c)
553{
554 return { degrees( c.r), degrees( c.g), degrees( c.b), degrees( c.a)};
555}
556
559inline Color elementwise_max( const Color& lhs, const Color& rhs)
560{
561 return { base::max MI_PREVENT_MACRO_EXPAND ( lhs.r, rhs.r),
562 base::max MI_PREVENT_MACRO_EXPAND ( lhs.g, rhs.g),
563 base::max MI_PREVENT_MACRO_EXPAND ( lhs.b, rhs.b),
564 base::max MI_PREVENT_MACRO_EXPAND ( lhs.a, rhs.a)};
565}
566
569inline Color elementwise_min( const Color& lhs, const Color& rhs)
570{
571 return { base::min MI_PREVENT_MACRO_EXPAND ( lhs.r, rhs.r),
572 base::min MI_PREVENT_MACRO_EXPAND ( lhs.g, rhs.g),
573 base::min MI_PREVENT_MACRO_EXPAND ( lhs.b, rhs.b),
574 base::min MI_PREVENT_MACRO_EXPAND ( lhs.a, rhs.a)};
575}
576
578inline Color exp( const Color& c)
579{
580 return { exp( c.r), exp( c.g), exp( c.b), exp( c.a)};
581}
582
584inline Color exp2( const Color& c)
585{
586 return { exp2( c.r), exp2( c.g), exp2( c.b), exp2( c.a)};
587}
588
591inline Color floor( const Color& c)
592{
593 return { floor( c.r), floor( c.g), floor( c.b), floor( c.a)};
594}
595
599inline Color fmod( const Color& a, const Color& b)
600{
601 return { fmod( a.r, b.r), fmod( a.g, b.g), fmod( a.b, b.b), fmod( a.a, b.a)};
602}
603
607inline Color fmod( const Color& a, Float32 b)
608{
609 return { fmod( a.r, b), fmod( a.g, b), fmod( a.b, b), fmod( a.a, b)};
610}
611
613inline Color frac( const Color& c)
614{
615 return { frac( c.r), frac( c.g), frac( c.b), frac( c.a)};
616}
617
626 const Color& color,
627 Float32 gamma_factor)
628{
629 mi_math_assert( gamma_factor > 0);
630 const Float32 f = Float32(1.0) / gamma_factor;
631 return { fast_pow( color.r, f),
632 fast_pow( color.g, f),
633 fast_pow( color.b, f),
634 fast_pow( color.a, f)};
635}
636
638inline bool is_approx_equal(
639 const Color& lhs,
640 const Color& rhs,
641 Float32 e)
642{
643 return is_approx_equal( lhs.r, rhs.r, e)
644 && is_approx_equal( lhs.g, rhs.g, e)
645 && is_approx_equal( lhs.b, rhs.b, e)
646 && is_approx_equal( lhs.a, rhs.a, e);
647}
648
651inline Color lerp(
652 const Color& c1,
653 const Color& c2,
654 const Color& t)
655{
656 return { lerp( c1.r, c2.r, t.r),
657 lerp( c1.g, c2.g, t.g),
658 lerp( c1.b, c2.b, t.b),
659 lerp( c1.a, c2.a, t.a)};
660}
661
664inline Color lerp(
665 const Color& c1,
666 const Color& c2,
667 Float32 t)
668{
669 // equivalent to: return c1 * (Float32(1)-t) + c2 * t;
670 return { lerp( c1.r, c2.r, t),
671 lerp( c1.g, c2.g, t),
672 lerp( c1.b, c2.b, t),
673 lerp( c1.a, c2.a, t)};
674}
675
677inline Color log( const Color& c)
678{
679 return { log( c.r), log( c.g), log( c.b), log( c.a)};
680}
681
684{
685 return { log2 MI_PREVENT_MACRO_EXPAND (c.r),
689}
690
692inline Color log10( const Color& c)
693{
694 return { log10( c.r), log10( c.g), log10( c.b), log10( c.a)};
695}
696
701inline Color modf( const Color& c, Color& i)
702{
703 return { modf( c.r, i.r), modf( c.g, i.g), modf( c.b, i.b), modf( c.a, i.a)};
704}
705
707inline Color pow( const Color& a, const Color& b)
708{
709 return { pow( a.r, b.r), pow( a.g, b.g), pow( a.b, b.b), pow( a.a, b.a)};
710}
711
713inline Color pow( const Color& a, Float32 b)
714{
715 return { pow( a.r, b), pow( a.g, b), pow( a.b, b), pow( a.a, b)};
716}
717
719inline Color radians( const Color& c)
720{
721 return { radians( c.r), radians( c.g), radians( c.b), radians( c.a)};
722}
723
725inline Color round( const Color& c)
726{
727 return { round( c.r), round( c.g), round( c.b), round( c.a)};
728}
729
731inline Color rsqrt( const Color& c)
732{
733 return { rsqrt( c.r), rsqrt( c.g), rsqrt( c.b), rsqrt( c.a)};
734}
735
737inline Color saturate( const Color& c)
738{
739 return { saturate( c.r), saturate( c.g), saturate( c.b), saturate( c.a)};
740}
741
743inline Color sign( const Color& c)
744{
745 return { sign( c.r), sign( c.g), sign( c.b), sign( c.a)};
746}
747
749inline Color sin( const Color& c)
750{
751 return { sin( c.r), sin( c.g), sin( c.b), sin( c.a)};
752}
753
757inline void sincos( const Color& a, Color& s, Color& c)
758{
759 sincos( a.r, s.r, c.r);
760 sincos( a.g, s.g, c.g);
761 sincos( a.b, s.b, c.b);
762 sincos( a.a, s.a, c.a);
763}
764
770inline Color smoothstep( const Color& a, const Color& b, const Color& c)
771{
772 return { smoothstep( a.r, b.r, c.r),
773 smoothstep( a.g, b.g, c.g),
774 smoothstep( a.b, b.b, c.b),
775 smoothstep( a.a, b.a, c.a)};
776}
777
783inline Color smoothstep( const Color& a, const Color& b, Float32 x)
784{
785 return { smoothstep( a.r, b.r, x),
786 smoothstep( a.g, b.g, x),
787 smoothstep( a.b, b.b, x),
788 smoothstep( a.a, b.a, x)};
789}
790
792inline Color sqrt( const Color& c)
793{
794 return { sqrt( c.r), sqrt( c.g), sqrt( c.b), sqrt( c.a)};
795}
796
798inline Color step( const Color& a, const Color& c)
799{
800 return { step( a.r, c.r), step( a.g, c.g), step( a.g, c.b), step( a.a, c.a)};
801}
802
804inline Color tan( const Color& c)
805{
806 return { tan( c.r), tan( c.g), tan( c.b), tan( c.a)};
807}
808
811{
816}
817
820{
825}
826
828inline bool isnan MI_PREVENT_MACRO_EXPAND (const Color& c)
829{
834}
835
839MI_HOST_DEVICE_INLINE void to_rgbe( const Color& color, Uint32& rgbe)
840{
841 to_rgbe( &color.r, rgbe);
842}
843
847MI_HOST_DEVICE_INLINE void to_rgbe( const Color& color, Uint8 rgbe[4])
848{
849 to_rgbe( &color.r, rgbe);
850}
851
855MI_HOST_DEVICE_INLINE void from_rgbe( const Uint8 rgbe[4], Color& color)
856{
857 from_rgbe( rgbe, &color.r);
858 color.a = 1.0f;
859}
860
864MI_HOST_DEVICE_INLINE void from_rgbe( const Uint32 rgbe, Color& color)
865{
866 from_rgbe( rgbe, &color.r);
867 color.a = 1.0f;
868}
869
870//------ Definitions of member functions --------------------------------------
871
872#ifndef MI_FOR_DOXYGEN_ONLY
873
874inline Color Color::clip(
875 Clip_mode mode,
876 bool desaturate) const
877{
878 Float32 max_val = 1.0f;
879 Color col = *this;
880 if( col.a < 0.0f)
881 col.a = 0.0f;
882 if( mode == CLIP_RGB) {
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;
886 }
887 if( col.a > 1.0f)
888 col.a = 1.0f;
889 if( mode == CLIP_ALPHA)
890 max_val = col.a;
891 if( desaturate)
892 return col.desaturate(max_val);
893 return { math::clamp( col.r, 0.0f, max_val),
894 math::clamp( col.g, 0.0f, max_val),
895 math::clamp( col.b, 0.0f, max_val),
896 col.a};
897}
898
899inline Color Color::desaturate( Float32 maxval) const
900{
901 // We compute a new color based on s with the vector formula c(s) = (N + s(I-N)) c0 where N is
902 // the 3 by 3 matrix with the [1,3] vector b with the NTSC values as its rows, and c0 is the
903 // original color. All c(s) have the same brightness, b*c0, as the original color. It can be
904 // algebraically shown that the hue of the c(s) is the same as for c0. Hue can be expressed with
905 // the formula h(c) = (I-A)c, where A is a 3 by 3 matrix with all 1/3 values. Essentially,
906 // h(c(s)) == h(c0), since A*N == N
907
908 Float32 t; // temp for saturation calc
909
910 Float32 axis = ntsc_intensity();
911 if( axis < 0) // negative: black, exit.
912 return { 0, 0, 0, a};
913 if( axis > maxval) // too bright: all white, exit.
914 return { maxval, maxval, maxval, a};
915
916 Float32 drds = r - axis; // calculate color axis and
917 Float32 dgds = g - axis; // dcol/dsat. sat==1 at the
918 Float32 dbds = b - axis; // outset.
919
920 Float32 sat = 1.0f; // initial saturation
921 bool clip = false; // outside range, desaturate
922
923 if( r > maxval) { // red > maxval?
924 clip = true;
925 t = (maxval - axis) / drds;
926 if( t < sat) sat = t;
927 } else if( r < 0) { // red < 0?
928 clip = true;
929 t = -axis / drds;
930 if( t < sat) sat = t;
931 }
932 if( g > maxval) { // green > maxval?
933 clip = true;
934 t = (maxval - axis) / dgds;
935 if( t < sat) sat = t;
936 } else if( g < 0) { // green < 0?
937 clip = true;
938 t = -axis / dgds;
939 if( t < sat) sat = t;
940 }
941 if( b > maxval) { // blue > maxval?
942 clip = true;
943 t = (maxval - axis) / dbds;
944 if( t < sat) sat = t;
945 } else if( b < 0) { // blue < 0?
946 clip = true;
947 t = -axis / dbds;
948 if( t < sat) sat = t;
949 }
950 if( clip) {
951 // negative solutions should not be possible
952 mi_math_assert( sat >= 0);
953 // clamp to avoid numerical imprecision
954 return { math::clamp( axis + drds * sat, 0.0f, maxval),
955 math::clamp( axis + dgds * sat, 0.0f, maxval),
956 math::clamp( axis + dbds * sat, 0.0f, maxval),
957 a};
958 }
959 mi_math_assert( r >= 0 && r <= maxval);
960 mi_math_assert( g >= 0 && g <= maxval);
961 mi_math_assert( b >= 0 && b <= maxval);
962 return *this;
963}
964
965#endif // MI_FOR_DOXYGEN_ONLY
966 // end group mi_math_color
968
969} // namespace math
970
971} // namespace mi
972
973#endif // MI_MATH_COLOR_H
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
Basic types.
Math vector class template of fixed dimension with arithmetic operators and generic functions.