MDL SDK API nvidia_logo_transpbg.gif Up
color.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2024 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 typedef Size size_type;
88 typedef Float32 * pointer;
89 typedef const Float32 * const_pointer;
90 typedef Float32 & reference;
91 typedef const Float32 & const_reference;
92
93 static const Size SIZE = 4;
94
96 static inline Size size() { return SIZE; }
97
99 static 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
134#if (__cplusplus >= 201103L)
136 Color( const Color& c) = default;
137#endif
138
140 inline Color( const Color_struct& c)
141 {
142 r = c.r;
143 g = c.g;
144 b = c.b;
145 a = c.a;
146 }
147
149 inline explicit Color( const Float32 s)
150 {
151 r = s;
152 g = s;
153 b = s;
154 a = s;
155 }
156
158 inline Color( Float32 nr, Float32 ng, Float32 nb, Float32 na = 1.0)
159 {
160 r = nr;
161 g = ng;
162 b = nb;
163 a = na;
164 }
165
177 template <typename T>
178 inline explicit Color( T array[4])
179 {
180 r = array[0];
181 g = array[1];
182 b = array[2];
183 a = array[3];
184 }
185
188 inline explicit Color( const Vector<Float32,4>& v)
189 {
190 r = v.x;
191 g = v.y;
192 b = v.z;
193 a = v.w;
194 }
195
197 inline explicit Color( const Spectrum_struct& s)
198 {
199 r = s.c[0];
200 g = s.c[1];
201 b = s.c[2];
202 a = 1.0f;
203 }
204
206 inline Color& operator=( const Color& c)
207 {
208 Color_struct::operator=( c);
209 return *this;
210 }
211
215 {
216 r = v.x;
217 g = v.y;
218 b = v.z;
219 a = v.w;
220 return *this;
221 }
222
224 inline const Float32& operator[]( Size i) const
225 {
226 mi_math_assert_msg( i < 4, "precondition");
227 return (&r)[i];
228 }
229
232 {
233 mi_math_assert_msg( i < 4, "precondition");
234 return (&r)[i];
235 }
236
237
239 inline Float32 get( Size i) const
240 {
241 mi_math_assert_msg( i < 4, "precondition");
242 return (&r)[i];
243 }
244
246 inline void set( Size i, Float32 value)
247 {
248 mi_math_assert_msg( i < 4, "precondition");
249 (&r)[i] = value;
250 }
251
253 inline bool is_black() const
254 {
255 return (r == 0.0f) && (g == 0.0f) && (b == 0.0f);
256 }
257
260 {
261 return (r + g + b) * Float32(1.0 / 3.0);
262 }
263
268 inline Float32 ntsc_intensity() const
269 {
270 return r * 0.299f + g * 0.587f + b * 0.114f;
271 }
272
277 inline Float32 cie_intensity() const
278 {
279 return r * 0.212671f + g * 0.715160f + b * 0.072169f;
280 }
281
286 inline Color clip( Clip_mode mode = CLIP_RGB, bool desaturate = false) const;
287
288
298 inline Color desaturate( Float32 maxval = 1.0f) const;
299};
300
301//------ Free comparison operators ==, !=, <, <=, >, >= for colors ------------
302
304inline bool operator==( const Color& lhs, const Color& rhs)
305{
306 return is_equal( lhs, rhs);
307}
308
310inline bool operator!=( const Color& lhs, const Color& rhs)
311{
312 return is_not_equal( lhs, rhs);
313}
314
318inline bool operator<( const Color& lhs, const Color& rhs)
319{
320 return lexicographically_less( lhs, rhs);
321}
322
326inline bool operator<=( const Color& lhs, const Color& rhs)
327{
328 return lexicographically_less_or_equal( lhs, rhs);
329}
330
334inline bool operator>( const Color& lhs, const Color& rhs)
335{
336 return lexicographically_greater( lhs, rhs);
337}
338
342inline bool operator>=( const Color& lhs, const Color& rhs)
343{
344 return lexicographically_greater_or_equal( lhs, rhs);
345}
346
347
348
349//------ Free operators +=, -=, *=, /=, +, -, *, and / for colors --------------
350
352inline Color& operator+=( Color& lhs, const Color& rhs)
353{
354 lhs.r += rhs.r;
355 lhs.g += rhs.g;
356 lhs.b += rhs.b;
357 lhs.a += rhs.a;
358 return lhs;
359}
360
362inline Color& operator-=( Color& lhs, const Color& rhs)
363{
364 lhs.r -= rhs.r;
365 lhs.g -= rhs.g;
366 lhs.b -= rhs.b;
367 lhs.a -= rhs.a;
368 return lhs;
369}
370
372inline Color& operator*=( Color& lhs, const Color& rhs)
373{
374 lhs.r *= rhs.r;
375 lhs.g *= rhs.g;
376 lhs.b *= rhs.b;
377 lhs.a *= rhs.a;
378 return lhs;
379}
380
382inline Color& operator/=( Color& lhs, const Color& rhs)
383{
384 lhs.r /= rhs.r;
385 lhs.g /= rhs.g;
386 lhs.b /= rhs.b;
387 lhs.a /= rhs.a;
388 return lhs;
389}
390
392inline Color operator+( const Color& lhs, const Color& rhs)
393{
394 return Color( 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 Color( lhs.r - rhs.r, lhs.g - rhs.g, lhs.b - rhs.b, lhs.a - rhs.a);
401}
402
404inline Color operator*( const Color& lhs, const Color& rhs)
405{
406 return Color( lhs.r * rhs.r, lhs.g * rhs.g, lhs.b * rhs.b, lhs.a * rhs.a);
407}
408
410inline Color operator/( const Color& lhs, const Color& rhs)
411{
412 return Color( lhs.r / rhs.r, lhs.g / rhs.g, lhs.b / rhs.b, lhs.a / rhs.a);
413}
414
416inline Color operator-( const Color& c)
417{
418 return Color( -c.r, -c.g, -c.b, -c.a);
419}
420
421
422
423//------ Free operator *=, /=, *, and / definitions for scalars ---------------
424
427{
428 c.r *= s;
429 c.g *= s;
430 c.b *= s;
431 c.a *= s;
432 return c;
433}
434
437{
438 const Float32 f = 1.0f / s;
439 c.r *= f;
440 c.g *= f;
441 c.b *= f;
442 c.a *= f;
443 return c;
444}
445
447inline Color operator*( const Color& c, Float32 s)
448{
449 return Color( c.r * s, c.g * s, c.b * s, c.a * s);
450}
451
454inline Color operator*( Float32 s, const Color& c)
455{
456 return Color( s * c.r, s * c.g, s* c.b, s * c.a);
457}
458
460inline Color operator/( const Color& c, Float32 s)
461{
462 const Float32 f = 1.0f / s;
463 return Color( c.r * f, c.g * f, c.b * f, c.a * f);
464}
465
466
467//------ Function Overloads for Color Algorithms ------------------------------
468
469
471inline Color abs( const Color& c)
472{
473 return Color( abs( c.r), abs( c.g), abs( c.b), abs( c.a));
474}
475
477inline Color acos( const Color& c)
478{
479 return Color( acos( c.r), acos( c.g), acos( c.b), acos( c.a));
480}
481
483inline bool all( const Color& c)
484{
485 return (c.r != 0.0f) && (c.g != 0.0f) && (c.b != 0.0f) && (c.a != 0.0f);
486}
487
489inline bool any( const Color& c)
490{
491 return (c.r != 0.0f) || (c.g != 0.0f) || (c.b != 0.0f) || (c.a != 0.0f);
492}
493
495inline Color asin( const Color& c)
496{
497 return Color( asin( c.r), asin( c.g), asin( c.b), asin( c.a));
498}
499
501inline Color atan( const Color& c)
502{
503 return Color( atan( c.r), atan( c.g), atan( c.b), atan( c.a));
504}
505
509inline Color atan2( const Color& c, const Color& d)
510{
511 return Color( atan2( c.r, d.r), atan2( c.g, d.g), atan2( c.b, d.b), atan2( c.a, d.a));
512}
513
516inline Color ceil( const Color& c)
517{
518 return Color( ceil( c.r), ceil( c.g), ceil( c.b), ceil( c.a));
519}
520
522inline Color clamp( const Color& c, const Color& low, const Color& high)
523{
524 return Color( clamp( c.r, low.r, high.r),
525 clamp( c.g, low.g, high.g),
526 clamp( c.b, low.b, high.b),
527 clamp( c.a, low.a, high.a));
528}
529
531inline Color clamp( const Color& c, const Color& low, Float32 high)
532{
533 return Color( clamp( c.r, low.r, high),
534 clamp( c.g, low.g, high),
535 clamp( c.b, low.b, high),
536 clamp( c.a, low.a, high));
537}
538
540inline Color clamp( const Color& c, Float32 low, const Color& high)
541{
542 return Color( clamp( c.r, low, high.r),
543 clamp( c.g, low, high.g),
544 clamp( c.b, low, high.b),
545 clamp( c.a, low, high.a));
546}
547
549inline Color clamp( const Color& c, Float32 low, Float32 high)
550{
551 return Color( clamp( c.r, low, high),
552 clamp( c.g, low, high),
553 clamp( c.b, low, high),
554 clamp( c.a, low, high));
555}
556
558inline Color cos( const Color& c)
559{
560 return Color( cos( c.r), cos( c.g), cos( c.b), cos( c.a));
561}
562
564inline Color degrees( const Color& c)
565{
566 return Color( degrees( c.r), degrees( c.g), degrees( c.b), degrees( c.a));
567}
568
571inline Color elementwise_max( const Color& lhs, const Color& rhs)
572{
573 return Color( base::max MI_PREVENT_MACRO_EXPAND ( lhs.r, rhs.r),
574 base::max MI_PREVENT_MACRO_EXPAND ( lhs.g, rhs.g),
575 base::max MI_PREVENT_MACRO_EXPAND ( lhs.b, rhs.b),
576 base::max MI_PREVENT_MACRO_EXPAND ( lhs.a, rhs.a));
577}
578
581inline Color elementwise_min( const Color& lhs, const Color& rhs)
582{
583 return Color( base::min MI_PREVENT_MACRO_EXPAND ( lhs.r, rhs.r),
584 base::min MI_PREVENT_MACRO_EXPAND ( lhs.g, rhs.g),
585 base::min MI_PREVENT_MACRO_EXPAND ( lhs.b, rhs.b),
586 base::min MI_PREVENT_MACRO_EXPAND ( lhs.a, rhs.a));
587}
588
590inline Color exp( const Color& c)
591{
592 return Color( exp( c.r), exp( c.g), exp( c.b), exp( c.a));
593}
594
596inline Color exp2( const Color& c)
597{
598 return Color( exp2( c.r), exp2( c.g), exp2( c.b), exp2( c.a));
599}
600
603inline Color floor( const Color& c)
604{
605 return Color( floor( c.r), floor( c.g), floor( c.b), floor( c.a));
606}
607
611inline Color fmod( const Color& a, const Color& b)
612{
613 return Color( fmod( a.r, b.r), fmod( a.g, b.g), fmod( a.b, b.b), fmod( a.a, b.a));
614}
615
619inline Color fmod( const Color& a, Float32 b)
620{
621 return Color( fmod( a.r, b), fmod( a.g, b), fmod( a.b, b), fmod( a.a, b));
622}
623
625inline Color frac( const Color& c)
626{
627 return Color( frac( c.r), frac( c.g), frac( c.b), frac( c.a));
628}
629
638 const Color& color,
639 Float32 gamma_factor)
640{
641 mi_math_assert( gamma_factor > 0);
642 const Float32 f = Float32(1.0) / gamma_factor;
643 return Color( fast_pow( color.r, f),
644 fast_pow( color.g, f),
645 fast_pow( color.b, f),
646 fast_pow( color.a, f));
647}
648
650inline bool is_approx_equal(
651 const Color& lhs,
652 const Color& rhs,
653 Float32 e)
654{
655 return is_approx_equal( lhs.r, rhs.r, e)
656 && is_approx_equal( lhs.g, rhs.g, e)
657 && is_approx_equal( lhs.b, rhs.b, e)
658 && is_approx_equal( lhs.a, rhs.a, e);
659}
660
663inline Color lerp(
664 const Color& c1,
665 const Color& c2,
666 const Color& t)
667{
668 return Color( lerp( c1.r, c2.r, t.r),
669 lerp( c1.g, c2.g, t.g),
670 lerp( c1.b, c2.b, t.b),
671 lerp( c1.a, c2.a, t.a));
672}
673
676inline Color lerp(
677 const Color& c1,
678 const Color& c2,
679 Float32 t)
680{
681 // equivalent to: return c1 * (Float32(1)-t) + c2 * t;
682 return Color( lerp( c1.r, c2.r, t),
683 lerp( c1.g, c2.g, t),
684 lerp( c1.b, c2.b, t),
685 lerp( c1.a, c2.a, t));
686}
687
689inline Color log( const Color& c)
690{
691 return Color( log( c.r), log( c.g), log( c.b), log( c.a));
692}
693
696{
701}
702
704inline Color log10( const Color& c)
705{
706 return Color( log10( c.r), log10( c.g), log10( c.b), log10( c.a));
707}
708
713inline Color modf( const Color& c, Color& i)
714{
715 return Color( modf( c.r, i.r), modf( c.g, i.g), modf( c.b, i.b), modf( c.a, i.a));
716}
717
719inline Color pow( const Color& a, const Color& b)
720{
721 return Color( pow( a.r, b.r), pow( a.g, b.g), pow( a.b, b.b), pow( a.a, b.a));
722}
723
725inline Color pow( const Color& a, Float32 b)
726{
727 return Color( pow( a.r, b), pow( a.g, b), pow( a.b, b), pow( a.a, b));
728}
729
731inline Color radians( const Color& c)
732{
733 return Color( radians( c.r), radians( c.g), radians( c.b), radians( c.a));
734}
735
737inline Color round( const Color& c)
738{
739 return Color( round( c.r), round( c.g), round( c.b), round( c.a));
740}
741
743inline Color rsqrt( const Color& c)
744{
745 return Color( rsqrt( c.r), rsqrt( c.g), rsqrt( c.b), rsqrt( c.a));
746}
747
749inline Color saturate( const Color& c)
750{
751 return Color( saturate( c.r), saturate( c.g), saturate( c.b), saturate( c.a));
752}
753
755inline Color sign( const Color& c)
756{
757 return Color( sign( c.r), sign( c.g), sign( c.b), sign( c.a));
758}
759
761inline Color sin( const Color& c)
762{
763 return Color( sin( c.r), sin( c.g), sin( c.b), sin( c.a));
764}
765
769inline void sincos( const Color& a, Color& s, Color& c)
770{
771 sincos( a.r, s.r, c.r);
772 sincos( a.g, s.g, c.g);
773 sincos( a.b, s.b, c.b);
774 sincos( a.a, s.a, c.a);
775}
776
782inline Color smoothstep( const Color& a, const Color& b, const Color& c)
783{
784 return Color( smoothstep( a.r, b.r, c.r),
785 smoothstep( a.g, b.g, c.g),
786 smoothstep( a.b, b.b, c.b),
787 smoothstep( a.a, b.a, c.a));
788}
789
795inline Color smoothstep( const Color& a, const Color& b, Float32 x)
796{
797 return Color( smoothstep( a.r, b.r, x),
798 smoothstep( a.g, b.g, x),
799 smoothstep( a.b, b.b, x),
800 smoothstep( a.a, b.a, x));
801}
802
804inline Color sqrt( const Color& c)
805{
806 return Color( sqrt( c.r), sqrt( c.g), sqrt( c.b), sqrt( c.a));
807}
808
810inline Color step( const Color& a, const Color& c)
811{
812 return Color( step( a.r, c.r), step( a.g, c.g), step( a.g, c.b), step( a.a, c.a));
813}
814
816inline Color tan( const Color& c)
817{
818 return Color( tan( c.r), tan( c.g), tan( c.b), tan( c.a));
819}
820
823{
828}
829
832{
837}
838
840inline bool isnan MI_PREVENT_MACRO_EXPAND (const Color& c)
841{
846}
847
851MI_HOST_DEVICE_INLINE void to_rgbe( const Color& color, Uint32& rgbe)
852{
853 to_rgbe( &color.r, rgbe);
854}
855
859MI_HOST_DEVICE_INLINE void to_rgbe( const Color& color, Uint8 rgbe[4])
860{
861 to_rgbe( &color.r, rgbe);
862}
863
867MI_HOST_DEVICE_INLINE void from_rgbe( const Uint8 rgbe[4], Color& color)
868{
869 from_rgbe( rgbe, &color.r);
870 color.a = 1.0f;
871}
872
876MI_HOST_DEVICE_INLINE void from_rgbe( const Uint32 rgbe, Color& color)
877{
878 from_rgbe( rgbe, &color.r);
879 color.a = 1.0f;
880}
881
882//------ Definitions of member functions --------------------------------------
883
884#ifndef MI_FOR_DOXYGEN_ONLY
885
886inline Color Color::clip(
887 Clip_mode mode,
888 bool desaturate) const
889{
890 Float32 max_val = 1.0f;
891 Color col = *this;
892 if( col.a < 0.0f)
893 col.a = 0.0f;
894 if( mode == CLIP_RGB) {
895 if( col.a < col.r) col.a = col.r;
896 if( col.a < col.g) col.a = col.g;
897 if( col.a < col.b) col.a = col.b;
898 }
899 if( col.a > 1.0f)
900 col.a = 1.0f;
901 if( mode == CLIP_ALPHA)
902 max_val = col.a;
903 if( desaturate)
904 return col.desaturate(max_val);
905 return Color( math::clamp( col.r, 0.0f, max_val),
906 math::clamp( col.g, 0.0f, max_val),
907 math::clamp( col.b, 0.0f, max_val),
908 col.a);
909}
910
911inline Color Color::desaturate( Float32 maxval) const
912{
913 // We compute a new color based on s with the vector formula c(s) = (N + s(I-N)) c0 where N is
914 // the 3 by 3 matrix with the [1,3] vector b with the NTSC values as its rows, and c0 is the
915 // original color. All c(s) have the same brightness, b*c0, as the original color. It can be
916 // algebraically shown that the hue of the c(s) is the same as for c0. Hue can be expressed with
917 // the formula h(c) = (I-A)c, where A is a 3 by 3 matrix with all 1/3 values. Essentially,
918 // h(c(s)) == h(c0), since A*N == N
919
920 Float32 t; // temp for saturation calc
921
922 Float32 axis = ntsc_intensity();
923 if( axis < 0) // negative: black, exit.
924 return Color( 0, 0, 0, a);
925 if( axis > maxval) // too bright: all white, exit.
926 return Color( maxval, maxval, maxval, a);
927
928 Float32 drds = r - axis; // calculate color axis and
929 Float32 dgds = g - axis; // dcol/dsat. sat==1 at the
930 Float32 dbds = b - axis; // outset.
931
932 Float32 sat = 1.0f; // initial saturation
933 bool clip = false; // outside range, desaturate
934
935 if( r > maxval) { // red > maxval?
936 clip = true;
937 t = (maxval - axis) / drds;
938 if( t < sat) sat = t;
939 } else if( r < 0) { // red < 0?
940 clip = true;
941 t = -axis / drds;
942 if( t < sat) sat = t;
943 }
944 if( g > maxval) { // green > maxval?
945 clip = true;
946 t = (maxval - axis) / dgds;
947 if( t < sat) sat = t;
948 } else if( g < 0) { // green < 0?
949 clip = true;
950 t = -axis / dgds;
951 if( t < sat) sat = t;
952 }
953 if( b > maxval) { // blue > maxval?
954 clip = true;
955 t = (maxval - axis) / dbds;
956 if( t < sat) sat = t;
957 } else if( b < 0) { // blue < 0?
958 clip = true;
959 t = -axis / dbds;
960 if( t < sat) sat = t;
961 }
962 if( clip) {
963 // negative solutions should not be possible
964 mi_math_assert( sat >= 0);
965 // clamp to avoid numerical imprecision
966 return Color( math::clamp( axis + drds * sat, 0.0f, maxval),
967 math::clamp( axis + dgds * sat, 0.0f, maxval),
968 math::clamp( axis + dbds * sat, 0.0f, maxval),
969 a);
970 }
971 mi_math_assert( r >= 0 && r <= maxval);
972 mi_math_assert( g >= 0 && g <= maxval);
973 mi_math_assert( b >= 0 && b <= maxval);
974 return *this;
975}
976
977#endif // MI_FOR_DOXYGEN_ONLY
978 // end group mi_math_color
980
981} // namespace math
982
983} // namespace mi
984
985#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 int Uint32
32-bit unsigned integer.
Definition: types.h:49
unsigned char Uint8
8-bit unsigned integer.
Definition: types.h:47
Sint64 Difference
Signed integral type that is large enough to hold the difference of two pointers.
Definition: types.h:122
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
float Float32
32-bit float.
Definition: types.h:51
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:1174
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:1190
Float32 fast_pow(Float32 b, Float32 e)
A fast implementation of pow(x,y) for floats.
Definition: function.h:403
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:1222
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:1161
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:1206
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:1150
#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:652
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:470
bool operator<(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically less than rhs.
Definition: bbox.h:607
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:564
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:535
bool operator==(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is elementwise equal to rhs.
Definition: bbox.h:591
bool operator>(const Bbox<T, DIM> &lhs, const Bbox<T, DIM> &rhs)
Returns true if lhs is lexicographically greater than rhs.
Definition: bbox.h:637
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:578
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:518
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:598
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:622
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:550
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:486
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:502
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:672
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:625
const Float32 * const_pointer
Const pointer to element.
Definition: color.h:89
Color sqrt(const Color &c)
Returns the square root of each element of c.
Definition: color.h:804
Float32 linear_intensity() const
Returns the intensity of the RGB components, equally weighted.
Definition: color.h:259
bool isinfinite(const Color &c)
Indicates whether any component of the color is infinite.
Definition: color.h:831
Color_struct storage_type
Storage class used by this color.
Definition: color.h:84
static Size size()
Constant size of the color.
Definition: color.h:96
Color(T array[4])
Constructor initializes the color elements from a 4-dimensional array.
Definition: color.h:178
Color acos(const Color &c)
Returns a color with the elementwise arc cosine of the color c.
Definition: color.h:477
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:516
bool is_black() const
Returns true if the color is black ignoring the alpha value.
Definition: color.h:253
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:522
Color abs(const Color &c)
Returns a color with the elementwise absolute values of the color c.
Definition: color.h:471
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:188
const Float32 * end() const
Returns the past-the-end pointer.
Definition: color.h:115
Color round(const Color &c)
Returns a color with the elements of color c rounded to nearest integers.
Definition: color.h:737
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:713
Float32 ntsc_intensity() const
Returns the intensity of the RGB components, weighted according to the NTSC standard.
Definition: color.h:268
Color(const Color_struct &c)
Constructor from underlying storage type.
Definition: color.h:140
Float32 & reference
Mutable reference to element.
Definition: color.h:90
MI_HOST_DEVICE_INLINE void from_rgbe(const Uint8 rgbe[4], Color &color)
Decodes a color from RGBE representation.
Definition: color.h:867
Color atan(const Color &c)
Returns a color with the elementwise arc tangent of the color c.
Definition: color.h:501
bool isfinite(const Color &c)
Indicates whether all components of the color are finite.
Definition: color.h:822
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
static const Size SIZE
Constant size of the color.
Definition: color.h:93
Size size_type
Size type, unsigned.
Definition: color.h:86
Color step(const Color &a, const Color &c)
Returns elementwise 0 if c is less than a and 1 otherwise.
Definition: color.h:810
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:581
Color(Float32 nr, Float32 ng, Float32 nb, Float32 na=1.0)
Constructor initializes (r,g,b,a) from (nr,ng,nb,na).
Definition: color.h:158
void set(Size i, Float32 value)
Sets the i-th color element to value, 0 <= i < 4.
Definition: color.h:246
Color tan(const Color &c)
Returns a color with the elementwise tangent of the color c.
Definition: color.h:816
Color atan2(const Color &c, const Color &d)
Returns a color with the elementwise arc tangent of the color c / d.
Definition: color.h:509
Color sin(const Color &c)
Returns a color with the elementwise sine of the color c.
Definition: color.h:761
Float32 * pointer
Mutable pointer to element.
Definition: color.h:88
Color degrees(const Color &c)
Converts elementwise radians in c to degrees.
Definition: color.h:564
Color saturate(const Color &c)
Returns the color c clamped elementwise to the range [0,1].
Definition: color.h:749
Color rsqrt(const Color &c)
Returns the reciprocal of the square root of each element of c.
Definition: color.h:743
bool any(const Color &c)
Returns true if any element of c is not equal to zero.
Definition: color.h:489
Color radians(const Color &c)
Converts elementwise degrees in c to radians.
Definition: color.h:731
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:596
Color & operator=(const Color &c)
Assignment operator.
Definition: color.h:206
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:571
Color log(const Color &c)
Returns a color with elementwise natural logarithm of the color c.
Definition: color.h:689
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:603
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:782
Float32 & operator[](Size i)
Accesses the i-th color element, 0 <= i < 4.
Definition: color.h:231
Color sign(const Color &c)
Returns the elementwise sign of color c.
Definition: color.h:755
Color fmod(const Color &a, const Color &b)
Returns elementwise a modulo b, in other words, the remainder of a/b.
Definition: color.h:611
Float32 cie_intensity() const
Returns the intensity of the RGB components, weighted according to the CIE standard.
Definition: color.h:277
Color cos(const Color &c)
Returns a color with the elementwise cosine of the color c.
Definition: color.h:558
Color(const Color &c)=default
Default copy constructor.
MI_HOST_DEVICE_INLINE void to_rgbe(const Color &color, Uint32 &rgbe)
Encodes a color into RGBE representation.
Definition: color.h:851
Color pow(const Color &a, const Color &b)
Returns the color a elementwise to the power of b.
Definition: color.h:719
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:239
Float32 value_type
Element type.
Definition: color.h:85
bool all(const Color &c)
Returns true if all elements of c are not equal to zero.
Definition: color.h:483
bool isnan(const Color &c)
Indicates whether any component of the color is "not a number".
Definition: color.h:840
Color_struct Pod_type
POD class corresponding to this color.
Definition: color.h:83
Color(const Spectrum_struct &s)
Conversion from Spectrum.
Definition: color.h:197
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:214
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:224
const Float32 & const_reference
Const reference to element.
Definition: color.h:91
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:637
Color log10(const Color &c)
Returns a color with elementwise base 10 logarithm of the color c.
Definition: color.h:704
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:695
Color exp(const Color &c)
Returns a color with elementwise e to the power of the element in the color c.
Definition: color.h:590
Difference difference_type
Difference type, signed.
Definition: color.h:87
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:650
void sincos(const Color &a, Color &s, Color &c)
Computes elementwise the sine s and cosine c of angles a simultaneously.
Definition: color.h:769
Color(const Float32 s)
Constructor initializes all vector elements to the value s.
Definition: color.h:149
static Size max_size()
Constant maximum size of the color.
Definition: color.h:99
Color asin(const Color &c)
Returns a color with the elementwise arc sine of the color c.
Definition: color.h:495
@ 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 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.