DiCE API nvidia_logo_transpbg.gif Up
spectrum.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2023 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
8
9#ifndef MI_MATH_SPECTRUM_H
10#define MI_MATH_SPECTRUM_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#include <mi/math/color.h>
17
18namespace mi {
19
20namespace math {
21
33//------ Spectrum Class ---------------------------------------------------------
34
53{
54public:
58 typedef Size size_type;
60 typedef Float32 * pointer;
61 typedef const Float32 * const_pointer;
62 typedef Float32 & reference;
63 typedef const Float32 & const_reference;
64
65 static const Size SIZE = 3;
66
68 static inline Size size() { return SIZE; }
69
71 static inline Size max_size() { return SIZE; }
72
74 inline Float32* begin() { return &c[0]; }
75
77 inline const Float32* begin() const { return &c[0]; }
78
82 inline Float32* end() { return begin() + SIZE; }
83
87 inline const Float32* end() const { return begin() + SIZE; }
88
90 inline Spectrum()
91 {
92#if defined(DEBUG) || (defined(_MSC_VER) && _MSC_VER <= 1310)
93 // In debug mode, default-constructed spectra are initialized with signaling NaNs or, if not
94 // applicable, with a maximum value to increase the chances of diagnosing incorrect use of
95 // an uninitialized spectrum.
96 //
97 // When compiling with Visual C++ 7.1 or earlier, this code is enabled in all variants to
98 // work around a very obscure compiler bug that causes the compiler to crash.
100 Float32 v = (Traits::has_signaling_NaN)
101 ? Traits::signaling_NaN() : Traits::max MI_PREVENT_MACRO_EXPAND ();
102 for( Size i = 0; i < SIZE; ++i)
103 c[i] = v;
104#endif
105 }
106
107#if (__cplusplus >= 201103L)
109 Spectrum( const Spectrum& s) = default;
110
112 Spectrum& operator=( const Spectrum& s) = default;
113#endif
114
116 inline Spectrum( const Spectrum_struct& s)
117 {
118 for( Size i = 0; i < SIZE; ++i)
119 c[i] = s.c[i];
120 }
121
122
124 inline explicit Spectrum( const Float32 s)
125 {
126 for( Size i = 0; i < SIZE; ++i)
127 c[i] = s;
128 }
129
131 inline Spectrum( Float32 nr, Float32 ng, Float32 nb)
132 {
133 c[0] = nr;
134 c[1] = ng;
135 c[2] = nb;
136 }
137
139 inline explicit Spectrum( const Vector<Float32,3>& v3)
140 {
141 c[0] = v3[0];
142 c[1] = v3[1];
143 c[2] = v3[2];
144 }
145
147 inline explicit Spectrum( const Vector<Float32,4>& v4)
148 {
149 c[0] = v4[0];
150 c[1] = v4[1];
151 c[2] = v4[2];
152 }
153
155 inline explicit Spectrum( const Color& col)
156 {
157 c[0] = col.r;
158 c[1] = col.g;
159 c[2] = col.b;
160 }
161
164 {
165 Vector<Float32,3> result;
166 result[0] = c[0];
167 result[1] = c[1];
168 result[2] = c[2];
169 return result;
170 }
171
174 {
175 Vector<Float32,4> result;
176 result[0] = c[0];
177 result[1] = c[1];
178 result[2] = c[2];
179 result[3] = 1.0;
180 return result;
181 }
182
184 MI_HOST_DEVICE_INLINE const Float32& operator[]( Size i) const
185 {
186 mi_math_assert_msg( i < SIZE, "precondition");
187 return c[i];
188 }
189
191 MI_HOST_DEVICE_INLINE Float32& operator[]( Size i)
192 {
193 mi_math_assert_msg( i < SIZE, "precondition");
194 return c[i];
195 }
196
197
199 inline Float32 get( Size i) const
200 {
201 mi_math_assert_msg( i < SIZE, "precondition");
202 return c[i];
203 }
204
206 inline void set( Size i, Float32 value)
207 {
208 mi_math_assert_msg( i < SIZE, "precondition");
209 c[i] = value;
210 }
211
213 inline bool is_black() const
214 {
215 for( Size i = 0; i < SIZE; ++i)
216 if( c[i] != 0.0f)
217 return false;
218 return true;
219 }
220
223 {
224 Float32 sum = 0.f;
225 for( Size i = 0; i < SIZE; ++i)
226 sum += c[i];
227 return sum / Float32( SIZE);
228 }
229};
230
231//------ Free comparison operators ==, !=, <, <=, >, >= for spectra ------------
232
234inline bool operator==( const Spectrum& lhs, const Spectrum& rhs)
235{
236 return is_equal( lhs, rhs);
237}
238
240inline bool operator!=( const Spectrum& lhs, const Spectrum& rhs)
241{
242 return is_not_equal( lhs, rhs);
243}
244
248inline bool operator<( const Spectrum& lhs, const Spectrum& rhs)
249{
250 return lexicographically_less( lhs, rhs);
251}
252
256inline bool operator<=( const Spectrum& lhs, const Spectrum& rhs)
257{
258 return lexicographically_less_or_equal( lhs, rhs);
259}
260
264inline bool operator>( const Spectrum& lhs, const Spectrum& rhs)
265{
266 return lexicographically_greater( lhs, rhs);
267}
268
272inline bool operator>=( const Spectrum& lhs, const Spectrum& rhs)
273{
274 return lexicographically_greater_or_equal( lhs, rhs);
275}
276
277
278
279//------ Free operators +=, -=, *=, /=, +, -, *, and / for spectra --------------
280
282inline Spectrum& operator+=( Spectrum& lhs, const Spectrum& rhs)
283{
284 mi_math_assert_msg( lhs.size() == 3, "precondition");
285 mi_math_assert_msg( rhs.size() == 3, "precondition");
286 lhs[0] += rhs[0];
287 lhs[1] += rhs[1];
288 lhs[2] += rhs[2];
289 return lhs;
290}
291
293inline Spectrum& operator-=( Spectrum& lhs, const Spectrum& rhs)
294{
295 mi_math_assert_msg( lhs.size() == 3, "precondition");
296 mi_math_assert_msg( rhs.size() == 3, "precondition");
297 lhs[0] -= rhs[0];
298 lhs[1] -= rhs[1];
299 lhs[2] -= rhs[2];
300 return lhs;
301}
302
304inline Spectrum& operator*=( Spectrum& lhs, const Spectrum& rhs)
305{
306 mi_math_assert_msg( lhs.size() == 3, "precondition");
307 mi_math_assert_msg( rhs.size() == 3, "precondition");
308 lhs[0] *= rhs[0];
309 lhs[1] *= rhs[1];
310 lhs[2] *= rhs[2];
311 return lhs;
312}
313
315inline Spectrum& operator/=( Spectrum& lhs, const Spectrum& rhs)
316{
317 mi_math_assert_msg( lhs.size() == 3, "precondition");
318 mi_math_assert_msg( rhs.size() == 3, "precondition");
319 lhs[0] /= rhs[0];
320 lhs[1] /= rhs[1];
321 lhs[2] /= rhs[2];
322 return lhs;
323}
324
326inline Spectrum operator+( const Spectrum& lhs, const Spectrum& rhs)
327{
328 mi_math_assert_msg( lhs.size() == 3, "precondition");
329 mi_math_assert_msg( rhs.size() == 3, "precondition");
330 return Spectrum( lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2]);
331}
332
334inline Spectrum operator-( const Spectrum& lhs, const Spectrum& rhs)
335{
336 mi_math_assert_msg( lhs.size() == 3, "precondition");
337 mi_math_assert_msg( rhs.size() == 3, "precondition");
338 return Spectrum( lhs[0] - rhs[0], lhs[1] - rhs[1], lhs[2] - rhs[2]);
339}
340
342inline Spectrum operator*( const Spectrum& lhs, const Spectrum& rhs)
343{
344 mi_math_assert_msg( lhs.size() == 3, "precondition");
345 mi_math_assert_msg( rhs.size() == 3, "precondition");
346 return Spectrum( lhs[0] * rhs[0], lhs[1] * rhs[1], lhs[2] * rhs[2]);
347}
348
350inline Spectrum operator/( const Spectrum& lhs, const Spectrum& rhs)
351{
352 mi_math_assert_msg( lhs.size() == 3, "precondition");
353 mi_math_assert_msg( rhs.size() == 3, "precondition");
354 return Spectrum( lhs[0] / rhs[0], lhs[1] / rhs[1], lhs[2] / rhs[2]);
355}
356
358inline Spectrum operator-( const Spectrum& c)
359{
360 mi_math_assert_msg( c.size() == 3, "precondition");
361 return Spectrum( -c[0], -c[1], -c[2]);
362}
363
364
365
366//------ Free operator *=, /=, *, and / definitions for scalars ---------------
367
371{
372 mi_math_assert_msg( c.size() == 3, "precondition");
373 c[0] *= s;
374 c[1] *= s;
375 c[2] *= s;
376 return c;
377}
378
381{
382 mi_math_assert_msg( c.size() == 3, "precondition");
383 const Float32 f = 1.0f / s;
384 c[0] *= f;
385 c[1] *= f;
386 c[2] *= f;
387 return c;
388}
389
391inline Spectrum operator*( const Spectrum& c, Float32 s)
392{
393 mi_math_assert_msg( c.size() == 3, "precondition");
394 return Spectrum( c[0] * s, c[1] * s, c[2] * s);
395}
396
398inline Spectrum operator*( Float32 s, const Spectrum& c)
399{
400 mi_math_assert_msg( c.size() == 3, "precondition");
401 return Spectrum( s * c[0], s * c[1], s* c[2]);
402}
403
405inline Spectrum operator/( const Spectrum& c, Float32 s)
406{
407 mi_math_assert_msg( c.size() == 3, "precondition");
408 Float32 f = 1.0f / s;
409 return Spectrum( c[0] * f, c[1] * f, c[2] * f);
410}
411
412
413//------ Function Overloads for Spectrum Algorithms ------------------------------
414
415
417inline Spectrum abs( const Spectrum& c)
418{
419 mi_math_assert_msg( c.size() == 3, "precondition");
420 return Spectrum( abs( c[0]), abs( c[1]), abs( c[2]));
421}
422
424inline Spectrum acos( const Spectrum& c)
425{
426 mi_math_assert_msg( c.size() == 3, "precondition");
427 return Spectrum( acos( c[0]), acos( c[1]), acos( c[2]));
428}
429
431inline bool all( const Spectrum& c)
432{
433 mi_math_assert_msg( c.size() == 3, "precondition");
434 return (c[0] != 0.0f) && (c[1] != 0.0f) && (c[2] != 0.0f);
435}
436
438inline bool any( const Spectrum& c)
439{
440 mi_math_assert_msg( c.size() == 3, "precondition");
441 return (c[0] != 0.0f) || (c[1] != 0.0f) || (c[2] != 0.0f);
442}
443
445inline Spectrum asin( const Spectrum& c)
446{
447 mi_math_assert_msg( c.size() == 3, "precondition");
448 return Spectrum( asin( c[0]), asin( c[1]), asin( c[2]));
449}
450
452inline Spectrum atan( const Spectrum& c)
453{
454 mi_math_assert_msg( c.size() == 3, "precondition");
455 return Spectrum( atan( c[0]), atan( c[1]), atan( c[2]));
456}
457
461inline Spectrum atan2( const Spectrum& c, const Spectrum& d)
462{
463 mi_math_assert_msg( c.size() == 3 && d.size() == 3, "precondition");
464 return Spectrum( atan2( c[0], d[0]), atan2( c[1], d[1]), atan2( c[2], d[2]));
465}
466
469inline Spectrum ceil( const Spectrum& c)
470{
471 mi_math_assert_msg( c.size() == 3, "precondition");
472 return Spectrum( ceil( c[0]), ceil( c[1]), ceil( c[2]));
473}
474
476inline Spectrum clamp( const Spectrum& c, const Spectrum& low, const Spectrum& high)
477{
478 mi_math_assert_msg( c.size() == 3, "precondition");
479 mi_math_assert_msg( low.size() == 3, "precondition");
480 mi_math_assert_msg( high.size() == 3, "precondition");
481 return Spectrum( clamp( c[0], low[0], high[0]),
482 clamp( c[1], low[1], high[1]),
483 clamp( c[2], low[2], high[2]));
484}
485
487inline Spectrum clamp( const Spectrum& c, const Spectrum& low, Float32 high)
488{
489 mi_math_assert_msg( c.size() == 3, "precondition");
490 mi_math_assert_msg( low.size() == 3, "precondition");
491 return Spectrum( clamp( c[0], low[0], high),
492 clamp( c[1], low[1], high),
493 clamp( c[2], low[2], high));
494}
495
497inline Spectrum clamp( const Spectrum& c, Float32 low, const Spectrum& high)
498{
499 mi_math_assert_msg( c.size() == 3, "precondition");
500 mi_math_assert_msg( high.size() == 3, "precondition");
501 return Spectrum( clamp( c[0], low, high[0]),
502 clamp( c[1], low, high[1]),
503 clamp( c[2], low, high[2]));
504}
505
507inline Spectrum clamp( const Spectrum& c, Float32 low, Float32 high)
508{
509 mi_math_assert_msg( c.size() == 3, "precondition");
510 return Spectrum( clamp( c[0], low, high),
511 clamp( c[1], low, high),
512 clamp( c[2], low, high));
513}
514
516inline Spectrum cos( const Spectrum& c)
517{
518 mi_math_assert_msg( c.size() == 3, "precondition");
519 return Spectrum( cos( c[0]), cos( c[1]), cos( c[2]));
520}
521
523inline Spectrum degrees( const Spectrum& c)
524{
525 mi_math_assert_msg( c.size() == 3, "precondition");
526 return Spectrum( degrees( c[0]), degrees( c[1]), degrees( c[2]));
527}
528
531inline Spectrum elementwise_max( const Spectrum& lhs, const Spectrum& rhs)
532{
533 mi_math_assert_msg( lhs.size() == 3, "precondition");
534 mi_math_assert_msg( rhs.size() == 3, "precondition");
535 return Spectrum( base::max MI_PREVENT_MACRO_EXPAND ( lhs[0], rhs[0]),
536 base::max MI_PREVENT_MACRO_EXPAND ( lhs[1], rhs[1]),
537 base::max MI_PREVENT_MACRO_EXPAND ( lhs[2], rhs[2]));
538}
539
542inline Spectrum elementwise_min( const Spectrum& lhs, const Spectrum& rhs)
543{
544 mi_math_assert_msg( lhs.size() == 3, "precondition");
545 mi_math_assert_msg( rhs.size() == 3, "precondition");
546 return Spectrum( base::min MI_PREVENT_MACRO_EXPAND ( lhs[0], rhs[0]),
547 base::min MI_PREVENT_MACRO_EXPAND ( lhs[1], rhs[1]),
548 base::min MI_PREVENT_MACRO_EXPAND ( lhs[2], rhs[2]));
549}
550
552inline Spectrum exp( const Spectrum& c)
553{
554 mi_math_assert_msg( c.size() == 3, "precondition");
555 return Spectrum( exp( c[0]), exp( c[1]), exp( c[2]));
556}
557
559inline Spectrum exp2( const Spectrum& c)
560{
561 mi_math_assert_msg( c.size() == 3, "precondition");
562 return Spectrum( exp2( c[0]), exp2( c[1]), exp2( c[2]));
563}
564
567inline Spectrum floor( const Spectrum& c)
568{
569 mi_math_assert_msg( c.size() == 3, "precondition");
570 return Spectrum( floor( c[0]), floor( c[1]), floor( c[2]));
571}
572
576inline Spectrum fmod( const Spectrum& a, const Spectrum& b)
577{
578 mi_math_assert_msg( a.size() == 3, "precondition");
579 mi_math_assert_msg( b.size() == 3, "precondition");
580 return Spectrum( fmod( a[0], b[0]), fmod( a[1], b[1]), fmod( a[2], b[2]));
581}
582
586inline Spectrum fmod( const Spectrum& a, Float32 b)
587{
588 mi_math_assert_msg( a.size() == 3, "precondition");
589 return Spectrum( fmod( a[0], b), fmod( a[1], b), fmod( a[2], b));
590}
591
593inline Spectrum frac( const Spectrum& c)
594{
595 mi_math_assert_msg( c.size() == 3, "precondition");
596 return Spectrum( frac( c[0]), frac( c[1]), frac( c[2]));
597}
598
607 const Spectrum& spectrum,
608 Float32 gamma_factor)
609{
610 mi_math_assert_msg( spectrum.size() == 3, "precondition");
611 mi_math_assert( gamma_factor > 0);
612 const Float32 f = Float32(1.0) / gamma_factor;
613 return Spectrum( fast_pow( spectrum[0], f),
614 fast_pow( spectrum[1], f),
615 fast_pow( spectrum[2], f));
616}
617
619inline bool is_approx_equal(
620 const Spectrum& lhs,
621 const Spectrum& rhs,
622 Float32 e)
623{
624 mi_math_assert_msg( lhs.size() == 3, "precondition");
625 mi_math_assert_msg( rhs.size() == 3, "precondition");
626 return is_approx_equal( lhs[0], rhs[0], e)
627 && is_approx_equal( lhs[1], rhs[1], e)
628 && is_approx_equal( lhs[2], rhs[2], e);
629}
630
634 const Spectrum& c1,
635 const Spectrum& c2,
636 const Spectrum& t)
637{
638 mi_math_assert_msg( c1.size() == 3, "precondition");
639 mi_math_assert_msg( c2.size() == 3, "precondition");
640 mi_math_assert_msg( t.size() == 3, "precondition");
641 return Spectrum( lerp( c1[0], c2[0], t[0]),
642 lerp( c1[1], c2[1], t[1]),
643 lerp( c1[2], c2[2], t[2]));
644}
645
649 const Spectrum& c1,
650 const Spectrum& c2,
651 Float32 t)
652{
653 mi_math_assert_msg( c1.size() == 3, "precondition");
654 mi_math_assert_msg( c2.size() == 3, "precondition");
655 // equivalent to: return c1 * (Float32(1)-t) + c2 * t;
656 return Spectrum( lerp( c1[0], c2[0], t),
657 lerp( c1[1], c2[1], t),
658 lerp( c1[2], c2[2], t));
659}
660
662inline Spectrum log( const Spectrum& c)
663{
664 mi_math_assert_msg( c.size() == 3, "precondition");
665 return Spectrum( log( c[0]), log( c[1]), log( c[2]));
666}
667
670{
671 mi_math_assert_msg( c.size() == 3, "precondition");
675}
676
678inline Spectrum log10( const Spectrum& c)
679{
680 mi_math_assert_msg( c.size() == 3, "precondition");
681 return Spectrum( log10( c[0]), log10( c[1]), log10( c[2]));
682}
683
688inline Spectrum modf( const Spectrum& c, Spectrum& i)
689{
690 mi_math_assert_msg( c.size() == 3, "precondition");
691 mi_math_assert_msg( i.size() == 3, "precondition");
692 return Spectrum( modf( c[0], i[0]), modf( c[1], i[1]), modf( c[2], i[2]));
693}
694
696inline Spectrum pow( const Spectrum& a, const Spectrum& b)
697{
698 mi_math_assert_msg( a.size() == 3, "precondition");
699 mi_math_assert_msg( b.size() == 3, "precondition");
700 return Spectrum( pow( a[0], b[0]), pow( a[1], b[1]), pow( a[2], b[2]));
701}
702
704inline Spectrum pow( const Spectrum& a, Float32 b)
705{
706 mi_math_assert_msg( a.size() == 3, "precondition");
707 return Spectrum( pow( a[0], b), pow( a[1], b), pow( a[2], b));
708}
709
711inline Spectrum radians( const Spectrum& c)
712{
713 mi_math_assert_msg( c.size() == 3, "precondition");
714 return Spectrum( radians( c[0]), radians( c[1]), radians( c[2]));
715}
716
718inline Spectrum round( const Spectrum& c)
719{
720 mi_math_assert_msg( c.size() == 3, "precondition");
721 return Spectrum( round( c[0]), round( c[1]), round( c[2]));
722}
723
725inline Spectrum rsqrt( const Spectrum& c)
726{
727 mi_math_assert_msg( c.size() == 3, "precondition");
728 return Spectrum( rsqrt( c[0]), rsqrt( c[1]), rsqrt( c[2]));
729}
730
732inline Spectrum saturate( const Spectrum& c)
733{
734 mi_math_assert_msg( c.size() == 3, "precondition");
735 return Spectrum( saturate( c[0]), saturate( c[1]), saturate( c[2]));
736}
737
739inline Spectrum sign( const Spectrum& c)
740{
741 mi_math_assert_msg( c.size() == 3, "precondition");
742 return Spectrum( sign( c[0]), sign( c[1]), sign( c[2]));
743}
744
746inline Spectrum sin( const Spectrum& c)
747{
748 mi_math_assert_msg( c.size() == 3, "precondition");
749 return Spectrum( sin( c[0]), sin( c[1]), sin( c[2]));
750}
751
755inline void sincos( const Spectrum& a, Spectrum& s, Spectrum& c)
756{
757 mi_math_assert_msg( a.size() == 3, "precondition");
758 mi_math_assert_msg( s.size() == 3, "precondition");
759 mi_math_assert_msg( c.size() == 3, "precondition");
760 sincos( a[0], s[0], c[0]);
761 sincos( a[1], s[1], c[1]);
762 sincos( a[2], s[2], c[2]);
763}
764
770inline Spectrum smoothstep( const Spectrum& a, const Spectrum& b, const Spectrum& c)
771{
772 mi_math_assert_msg( a.size() == 3, "precondition");
773 mi_math_assert_msg( b.size() == 3, "precondition");
774 mi_math_assert_msg( c.size() == 3, "precondition");
775 return Spectrum( smoothstep( a[0], b[0], c[0]),
776 smoothstep( a[1], b[1], c[1]),
777 smoothstep( a[2], b[2], c[2]));
778}
779
785inline Spectrum smoothstep( const Spectrum& a, const Spectrum& b, Float32 x)
786{
787 mi_math_assert_msg( a.size() == 3, "precondition");
788 mi_math_assert_msg( b.size() == 3, "precondition");
789 return Spectrum( smoothstep( a[0], b[0], x),
790 smoothstep( a[1], b[1], x),
791 smoothstep( a[2], b[2], x));
792}
793
795inline Spectrum sqrt( const Spectrum& c)
796{
797 mi_math_assert_msg( c.size() == 3, "precondition");
798 return Spectrum( sqrt( c[0]), sqrt( c[1]), sqrt( c[2]));
799}
800
802inline Spectrum step( const Spectrum& a, const Spectrum& c)
803{
804 mi_math_assert_msg( a.size() == 3, "precondition");
805 mi_math_assert_msg( c.size() == 3, "precondition");
806 return Spectrum( step( a[0], c[0]), step( a[1], c[1]), step( a[1], c[2]));
807}
808
810inline Spectrum tan( const Spectrum& c)
811{
812 mi_math_assert_msg( c.size() == 3, "precondition");
813 return Spectrum( tan( c[0]), tan( c[1]), tan( c[2]));
814}
815
818{
819 mi_math_assert_msg( c.size() == 3, "precondition");
823}
824
827{
828 mi_math_assert_msg( c.size() == 3, "precondition");
832}
833
836{
837 mi_math_assert_msg( c.size() == 3, "precondition");
838 return isnan MI_PREVENT_MACRO_EXPAND (c[0])
841}
842
844MI_HOST_DEVICE_INLINE void to_rgbe( const Spectrum& c, Uint32& rgbe)
845{
846 mi_math_assert_msg( c.size() == 3, "precondition");
847 to_rgbe( &c[0], rgbe);
848}
849
851MI_HOST_DEVICE_INLINE void to_rgbe( const Spectrum& c, Uint8 rgbe[4])
852{
853 mi_math_assert_msg( c.size() == 3, "precondition");
854 to_rgbe( &c[0], rgbe);
855}
856
858MI_HOST_DEVICE_INLINE void from_rgbe( const Uint8 rgbe[4], Spectrum& c)
859{
860 mi_math_assert_msg( c.size() == 3, "precondition");
861 from_rgbe( rgbe, &c[0]);
862}
863
865MI_HOST_DEVICE_INLINE void from_rgbe( const Uint32 rgbe, Spectrum& c)
866{
867 mi_math_assert_msg( c.size() == 3, "precondition");
868 from_rgbe( rgbe, &c[0]);
869}
870 // end group mi_math_spectrum
872
873} // namespace math
874
875} // namespace mi
876
877#endif // MI_MATH_SPECTRUM_H
Standard RGBA color class with floating point elements and operations.
Definition: color.h:81
Spectrum with floating point elements and operations.
Definition: spectrum.h:53
Fixed-size math vector class template with generic operations.
Definition: vector.h:286
Standard RGBA color class with floating point elements and operations.
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:1181
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:1197
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:1229
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:1168
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:1213
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:1157
#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 frac(const Color &c)
Returns a color with the elementwise positive fractional part of the color c.
Definition: color.h:628
Color sqrt(const Color &c)
Returns the square root of each element of c.
Definition: color.h:807
bool isinfinite(const Color &c)
Indicates whether any component of the color is infinite.
Definition: color.h:834
Color acos(const Color &c)
Returns a color with the elementwise arc cosine of the color c.
Definition: color.h:480
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:519
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:525
Color abs(const Color &c)
Returns a color with the elementwise absolute values of the color c.
Definition: color.h:474
Color round(const Color &c)
Returns a color with the elements of color c rounded to nearest integers.
Definition: color.h:740
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:716
MI_HOST_DEVICE_INLINE void from_rgbe(const Uint8 rgbe[4], Color &color)
Decodes a color from RGBE representation.
Definition: color.h:870
Color atan(const Color &c)
Returns a color with the elementwise arc tangent of the color c.
Definition: color.h:504
bool isfinite(const Color &c)
Indicates whether all components of the color are finite.
Definition: color.h:825
Color step(const Color &a, const Color &c)
Returns elementwise 0 if c is less than a and 1 otherwise.
Definition: color.h:813
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:584
Color tan(const Color &c)
Returns a color with the elementwise tangent of the color c.
Definition: color.h:819
Color atan2(const Color &c, const Color &d)
Returns a color with the elementwise arc tangent of the color c / d.
Definition: color.h:512
Color sin(const Color &c)
Returns a color with the elementwise sine of the color c.
Definition: color.h:764
Color degrees(const Color &c)
Converts elementwise radians in c to degrees.
Definition: color.h:567
Color saturate(const Color &c)
Returns the color c clamped elementwise to the range [0,1].
Definition: color.h:752
Color rsqrt(const Color &c)
Returns the reciprocal of the square root of each element of c.
Definition: color.h:746
bool any(const Color &c)
Returns true if any element of c is not equal to zero.
Definition: color.h:492
Color radians(const Color &c)
Converts elementwise degrees in c to radians.
Definition: color.h:734
Color exp2(const Color &c)
Returns a color with elementwise 2 to the power of the element in the color c.
Definition: color.h:599
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:574
Color log(const Color &c)
Returns a color with elementwise natural logarithm of the color c.
Definition: color.h:692
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:606
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:785
Color sign(const Color &c)
Returns the elementwise sign of color c.
Definition: color.h:758
Color fmod(const Color &a, const Color &b)
Returns elementwise a modulo b, in other words, the remainder of a/b.
Definition: color.h:614
Color cos(const Color &c)
Returns a color with the elementwise cosine of the color c.
Definition: color.h:561
MI_HOST_DEVICE_INLINE void to_rgbe(const Color &color, Uint32 &rgbe)
Encodes a color into RGBE representation.
Definition: color.h:854
Color pow(const Color &a, const Color &b)
Returns the color a elementwise to the power of b.
Definition: color.h:722
Float32 c[3]
Three color bands.
Definition: color.h:49
bool all(const Color &c)
Returns true if all elements of c are not equal to zero.
Definition: color.h:486
bool isnan(const Color &c)
Indicates whether any component of the color is "not a number".
Definition: color.h:843
Color gamma_correction(const Color &color, Float32 gamma_factor)
Returns a gamma corrected color.
Definition: color.h:640
Color log10(const Color &c)
Returns a color with elementwise base 10 logarithm of the color c.
Definition: color.h:707
Color log2(const Color &c)
Returns a color with elementwise base 2 logarithm of the color c.
Definition: color.h:698
Color exp(const Color &c)
Returns a color with elementwise e to the power of the element in the color c.
Definition: color.h:593
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:653
void sincos(const Color &a, Color &s, Color &c)
Computes elementwise the sine s and cosine c of angles a simultaneously.
Definition: color.h:772
Color asin(const Color &c)
Returns a color with the elementwise arc sine of the color c.
Definition: color.h:498
Float32 * end()
Returns the past-the-end pointer.
Definition: spectrum.h:82
Size size_type
Size type, unsigned.
Definition: spectrum.h:58
Spectrum & operator=(const Spectrum &s)=default
Default assignment operator.
const Float32 * const_pointer
Const pointer to element.
Definition: spectrum.h:61
Float32 linear_intensity() const
Returns the intensity of the RGB components, equally weighted.
Definition: spectrum.h:222
const Float32 & const_reference
Const reference to element.
Definition: spectrum.h:63
MI_HOST_DEVICE_INLINE const Float32 & operator[](Size i) const
Accesses the i-th spectrum element, 0 <= i < 3.
Definition: spectrum.h:184
const Float32 * begin() const
Returns the pointer to the first spectrum element.
Definition: spectrum.h:77
Float32 & reference
Mutable reference to element.
Definition: spectrum.h:62
Vector<Float32, 4> to_vector4() const
Conversion to Vector<Float32,4>.
Definition: spectrum.h:173
const Float32 * end() const
Returns the past-the-end pointer.
Definition: spectrum.h:87
Vector<Float32, 3> to_vector3() const
Conversion to Vector<Float32,3>.
Definition: spectrum.h:163
static Size size()
Constant size of the spectrum.
Definition: spectrum.h:68
Spectrum(const Vector<Float32, 3> &v3)
Conversion from Vector<Float32,3>.
Definition: spectrum.h:139
Spectrum()
The default constructor leaves the spectrum elements uninitialized.
Definition: spectrum.h:90
Spectrum(Float32 nr, Float32 ng, Float32 nb)
Constructor initializes (r,g,b) from (nr,ng,nb).
Definition: spectrum.h:131
Spectrum_struct Pod_type
POD class corresponding to this spectrum.
Definition: spectrum.h:55
bool is_black() const
Returns true if the spectrum is black ignoring the alpha value.
Definition: spectrum.h:213
Float32 * pointer
Mutable pointer to element.
Definition: spectrum.h:60
Spectrum_struct storage_type
Storage class used by this spectrum.
Definition: spectrum.h:56
Difference difference_type
Difference type, signed.
Definition: spectrum.h:59
void set(Size i, Float32 value)
Sets the i-th spectrum element to value, 0 <= i < 3.
Definition: spectrum.h:206
Spectrum(const Color &col)
Conversion from Color.
Definition: spectrum.h:155
Spectrum(const Vector<Float32, 4> &v4)
Conversion from Vector<Float32,4>.
Definition: spectrum.h:147
Spectrum(const Spectrum_struct &s)
Constructor from underlying storage type.
Definition: spectrum.h:116
Spectrum(const Float32 s)
Constructor initializes all vector elements to the value s.
Definition: spectrum.h:124
Float32 * begin()
Returns the pointer to the first spectrum element.
Definition: spectrum.h:74
Float32 get(Size i) const
Returns the i-th spectrum element, 0 <= i < 3.
Definition: spectrum.h:199
Spectrum(const Spectrum &s)=default
Default copy constructor.
static const Size SIZE
Constant size of the spectrum.
Definition: spectrum.h:65
static Size max_size()
Constant maximum size of the spectrum.
Definition: spectrum.h:71
Float32 value_type
Element type.
Definition: spectrum.h:57
Float32 g
Green color component.
Definition: vector.h:71
Float32 r
Red color component.
Definition: vector.h:69
Float32 b
Blue color component.
Definition: vector.h:73
math::Spectrum Spectrum
Spectrum class.
Definition: typedefs.h:47
Assertions and compile-time assertions.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: dice.h:89
Numeric traits specialization for mi::Float32.
Definition: types.h:531
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.