MDL SDK API nvidia_logo_transpbg.gif Up
spectrum.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2025 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 using size_type = Size;
60 using pointer = Float32*;
61 using const_pointer = const Float32*;
62 using reference = Float32&;
63 using const_reference = const Float32&;
64
65 static constexpr Size SIZE = 3;
66
68 static constexpr inline Size size() { return SIZE; }
69
71 static constexpr 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#ifndef NDEBUG
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.
97 Float32 v = (Traits::has_signaling_NaN)
98 ? Traits::signaling_NaN() : Traits::max MI_PREVENT_MACRO_EXPAND ();
99 for( float& cc : c)
100 cc = v;
101#endif
102 }
103
105 Spectrum( const Spectrum& s) = default;
106
108 Spectrum& operator=( const Spectrum& s) = default;
109
111 inline Spectrum( const Spectrum_struct& s)
112 {
113 for( Size i = 0; i < SIZE; ++i)
114 c[i] = s.c[i];
115 }
116
117
119 inline explicit Spectrum( const Float32 s)
120 {
121 for( float& cc : c)
122 cc = s;
123 }
124
126#if (__cplusplus >= 201402L)
127 constexpr
128#endif
129 inline Spectrum( Float32 nr, Float32 ng, Float32 nb) : Spectrum_struct{nr,ng,nb}
130 {
131 }
132
134#if (__cplusplus >= 201402L)
135 //constexpr
136#endif
137 inline explicit Spectrum( const Vector<Float32,3>& v3) : Spectrum_struct{v3[0],v3[1],v3[2]}
138 {
139 }
140
142#if (__cplusplus >= 201402L)
143 //constexpr
144#endif
145 inline explicit Spectrum( const Vector<Float32,4>& v4) : Spectrum_struct{v4[0],v4[1],v4[2]}
146 {
147 }
148
150#if (__cplusplus >= 201402L)
151 constexpr
152#endif
153 inline explicit Spectrum( const Color& col) : Spectrum_struct{col.r,col.g,col.b}
154 {
155 }
156
158#if (__cplusplus >= 201402L)
159 constexpr
160#endif
162 {
163 return { c[0],c[1],c[2]};
164 }
165
167#if (__cplusplus >= 201402L)
168 constexpr
169#endif
171 {
172 return { c[0],c[1],c[2],1.0f};
173 }
174
176 MI_HOST_DEVICE_INLINE const Float32& operator[]( Size i) const
177 {
178 mi_math_assert_msg( i < SIZE, "precondition");
179 return c[i];
180 }
181
183 MI_HOST_DEVICE_INLINE Float32& operator[]( Size i)
184 {
185 mi_math_assert_msg( i < SIZE, "precondition");
186 return c[i];
187 }
188
189
191 inline Float32 get( Size i) const
192 {
193 mi_math_assert_msg( i < SIZE, "precondition");
194 return c[i];
195 }
196
198 inline void set( Size i, Float32 value)
199 {
200 mi_math_assert_msg( i < SIZE, "precondition");
201 c[i] = value;
202 }
203
205 inline bool is_black() const
206 {
207 for( float cc : c)
208 if( cc != 0.0f)
209 return false;
210 return true;
211 }
212
215 {
216 Float32 sum = 0.f;
217 for( float cc : c)
218 sum += cc;
219 return sum * Float32( 1.0 / SIZE);
220 }
221};
222
223//------ Free comparison operators ==, !=, <, <=, >, >= for spectra ------------
224
226inline bool operator==( const Spectrum& lhs, const Spectrum& rhs)
227{
228 return is_equal( lhs, rhs);
229}
230
232inline bool operator!=( const Spectrum& lhs, const Spectrum& rhs)
233{
234 return is_not_equal( lhs, rhs);
235}
236
240inline bool operator<( const Spectrum& lhs, const Spectrum& rhs)
241{
242 return lexicographically_less( lhs, rhs);
243}
244
248inline bool operator<=( const Spectrum& lhs, const Spectrum& rhs)
249{
250 return lexicographically_less_or_equal( lhs, rhs);
251}
252
256inline bool operator>( const Spectrum& lhs, const Spectrum& rhs)
257{
258 return lexicographically_greater( lhs, rhs);
259}
260
264inline bool operator>=( const Spectrum& lhs, const Spectrum& rhs)
265{
266 return lexicographically_greater_or_equal( lhs, rhs);
267}
268
269
270
271//------ Free operators +=, -=, *=, /=, +, -, *, and / for spectra --------------
272
274inline Spectrum& operator+=( Spectrum& lhs, const Spectrum& rhs)
275{
276 mi_math_assert_msg( lhs.size() == 3, "precondition");
277 mi_math_assert_msg( rhs.size() == 3, "precondition");
278 lhs[0] += rhs[0];
279 lhs[1] += rhs[1];
280 lhs[2] += rhs[2];
281 return lhs;
282}
283
285inline Spectrum& operator-=( Spectrum& lhs, const Spectrum& rhs)
286{
287 mi_math_assert_msg( lhs.size() == 3, "precondition");
288 mi_math_assert_msg( rhs.size() == 3, "precondition");
289 lhs[0] -= rhs[0];
290 lhs[1] -= rhs[1];
291 lhs[2] -= rhs[2];
292 return lhs;
293}
294
296inline Spectrum& operator*=( Spectrum& lhs, const Spectrum& rhs)
297{
298 mi_math_assert_msg( lhs.size() == 3, "precondition");
299 mi_math_assert_msg( rhs.size() == 3, "precondition");
300 lhs[0] *= rhs[0];
301 lhs[1] *= rhs[1];
302 lhs[2] *= rhs[2];
303 return lhs;
304}
305
307inline Spectrum& operator/=( Spectrum& lhs, const Spectrum& rhs)
308{
309 mi_math_assert_msg( lhs.size() == 3, "precondition");
310 mi_math_assert_msg( rhs.size() == 3, "precondition");
311 lhs[0] /= rhs[0];
312 lhs[1] /= rhs[1];
313 lhs[2] /= rhs[2];
314 return lhs;
315}
316
318inline Spectrum operator+( const Spectrum& lhs, const Spectrum& rhs)
319{
320 mi_math_assert_msg( lhs.size() == 3, "precondition");
321 mi_math_assert_msg( rhs.size() == 3, "precondition");
322 return { lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2]};
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 { 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 { 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 { lhs[0] / rhs[0], lhs[1] / rhs[1], lhs[2] / rhs[2]};
347}
348
350inline Spectrum operator-( const Spectrum& c)
351{
352 mi_math_assert_msg( c.size() == 3, "precondition");
353 return { -c[0], -c[1], -c[2]};
354}
355
356
357
358//------ Free operator *=, /=, *, and / definitions for scalars ---------------
359
363{
364 mi_math_assert_msg( c.size() == 3, "precondition");
365 c[0] *= s;
366 c[1] *= s;
367 c[2] *= s;
368 return c;
369}
370
373{
374 mi_math_assert_msg( c.size() == 3, "precondition");
375 const Float32 f = 1.0f / s;
376 c[0] *= f;
377 c[1] *= f;
378 c[2] *= f;
379 return c;
380}
381
383inline Spectrum operator*( const Spectrum& c, Float32 s)
384{
385 mi_math_assert_msg( c.size() == 3, "precondition");
386 return { c[0] * s, c[1] * s, c[2] * s};
387}
388
390inline Spectrum operator*( Float32 s, const Spectrum& c)
391{
392 mi_math_assert_msg( c.size() == 3, "precondition");
393 return { s * c[0], s * c[1], s* c[2]};
394}
395
397inline Spectrum operator/( const Spectrum& c, Float32 s)
398{
399 mi_math_assert_msg( c.size() == 3, "precondition");
400 Float32 f = 1.0f / s;
401 return { c[0] * f, c[1] * f, c[2] * f};
402}
403
404
405//------ Function Overloads for Spectrum Algorithms ------------------------------
406
407
409inline Spectrum abs( const Spectrum& c)
410{
411 mi_math_assert_msg( c.size() == 3, "precondition");
412 return { abs( c[0]), abs( c[1]), abs( c[2])};
413}
414
416inline Spectrum acos( const Spectrum& c)
417{
418 mi_math_assert_msg( c.size() == 3, "precondition");
419 return { acos( c[0]), acos( c[1]), acos( c[2])};
420}
421
423inline bool all( const Spectrum& c)
424{
425 mi_math_assert_msg( c.size() == 3, "precondition");
426 return (c[0] != 0.0f) && (c[1] != 0.0f) && (c[2] != 0.0f);
427}
428
430inline bool any( const Spectrum& c)
431{
432 mi_math_assert_msg( c.size() == 3, "precondition");
433 return (c[0] != 0.0f) || (c[1] != 0.0f) || (c[2] != 0.0f);
434}
435
437inline Spectrum asin( const Spectrum& c)
438{
439 mi_math_assert_msg( c.size() == 3, "precondition");
440 return { asin( c[0]), asin( c[1]), asin( c[2])};
441}
442
444inline Spectrum atan( const Spectrum& c)
445{
446 mi_math_assert_msg( c.size() == 3, "precondition");
447 return { atan( c[0]), atan( c[1]), atan( c[2])};
448}
449
453inline Spectrum atan2( const Spectrum& c, const Spectrum& d)
454{
455 mi_math_assert_msg( c.size() == 3 && d.size() == 3, "precondition");
456 return { atan2( c[0], d[0]), atan2( c[1], d[1]), atan2( c[2], d[2])};
457}
458
461inline Spectrum ceil( const Spectrum& c)
462{
463 mi_math_assert_msg( c.size() == 3, "precondition");
464 return { ceil( c[0]), ceil( c[1]), ceil( c[2])};
465}
466
468inline Spectrum clamp( const Spectrum& c, const Spectrum& low, const Spectrum& high)
469{
470 mi_math_assert_msg( c.size() == 3, "precondition");
471 mi_math_assert_msg( low.size() == 3, "precondition");
472 mi_math_assert_msg( high.size() == 3, "precondition");
473 return { clamp( c[0], low[0], high[0]),
474 clamp( c[1], low[1], high[1]),
475 clamp( c[2], low[2], high[2])};
476}
477
479inline Spectrum clamp( const Spectrum& c, const Spectrum& low, Float32 high)
480{
481 mi_math_assert_msg( c.size() == 3, "precondition");
482 mi_math_assert_msg( low.size() == 3, "precondition");
483 return { clamp( c[0], low[0], high),
484 clamp( c[1], low[1], high),
485 clamp( c[2], low[2], high)};
486}
487
489inline Spectrum clamp( const Spectrum& c, Float32 low, const Spectrum& high)
490{
491 mi_math_assert_msg( c.size() == 3, "precondition");
492 mi_math_assert_msg( high.size() == 3, "precondition");
493 return { clamp( c[0], low, high[0]),
494 clamp( c[1], low, high[1]),
495 clamp( c[2], low, high[2])};
496}
497
499inline Spectrum clamp( const Spectrum& c, Float32 low, Float32 high)
500{
501 mi_math_assert_msg( c.size() == 3, "precondition");
502 return { clamp( c[0], low, high),
503 clamp( c[1], low, high),
504 clamp( c[2], low, high)};
505}
506
508inline Spectrum cos( const Spectrum& c)
509{
510 mi_math_assert_msg( c.size() == 3, "precondition");
511 return { cos( c[0]), cos( c[1]), cos( c[2])};
512}
513
515inline Spectrum degrees( const Spectrum& c)
516{
517 mi_math_assert_msg( c.size() == 3, "precondition");
518 return { degrees( c[0]), degrees( c[1]), degrees( c[2])};
519}
520
523inline Spectrum elementwise_max( const Spectrum& lhs, const Spectrum& rhs)
524{
525 mi_math_assert_msg( lhs.size() == 3, "precondition");
526 mi_math_assert_msg( rhs.size() == 3, "precondition");
527 return { base::max MI_PREVENT_MACRO_EXPAND ( lhs[0], rhs[0]),
528 base::max MI_PREVENT_MACRO_EXPAND ( lhs[1], rhs[1]),
529 base::max MI_PREVENT_MACRO_EXPAND ( lhs[2], rhs[2])};
530}
531
534inline Spectrum elementwise_min( const Spectrum& lhs, const Spectrum& rhs)
535{
536 mi_math_assert_msg( lhs.size() == 3, "precondition");
537 mi_math_assert_msg( rhs.size() == 3, "precondition");
538 return { base::min MI_PREVENT_MACRO_EXPAND ( lhs[0], rhs[0]),
539 base::min MI_PREVENT_MACRO_EXPAND ( lhs[1], rhs[1]),
540 base::min MI_PREVENT_MACRO_EXPAND ( lhs[2], rhs[2])};
541}
542
544inline Spectrum exp( const Spectrum& c)
545{
546 mi_math_assert_msg( c.size() == 3, "precondition");
547 return { exp( c[0]), exp( c[1]), exp( c[2])};
548}
549
551inline Spectrum exp2( const Spectrum& c)
552{
553 mi_math_assert_msg( c.size() == 3, "precondition");
554 return { exp2( c[0]), exp2( c[1]), exp2( c[2])};
555}
556
559inline Spectrum floor( const Spectrum& c)
560{
561 mi_math_assert_msg( c.size() == 3, "precondition");
562 return { floor( c[0]), floor( c[1]), floor( c[2])};
563}
564
568inline Spectrum fmod( const Spectrum& a, const Spectrum& b)
569{
570 mi_math_assert_msg( a.size() == 3, "precondition");
571 mi_math_assert_msg( b.size() == 3, "precondition");
572 return { fmod( a[0], b[0]), fmod( a[1], b[1]), fmod( a[2], b[2])};
573}
574
578inline Spectrum fmod( const Spectrum& a, Float32 b)
579{
580 mi_math_assert_msg( a.size() == 3, "precondition");
581 return { fmod( a[0], b), fmod( a[1], b), fmod( a[2], b)};
582}
583
585inline Spectrum frac( const Spectrum& c)
586{
587 mi_math_assert_msg( c.size() == 3, "precondition");
588 return { frac( c[0]), frac( c[1]), frac( c[2])};
589}
590
599 const Spectrum& spectrum,
600 Float32 gamma_factor)
601{
602 mi_math_assert_msg( spectrum.size() == 3, "precondition");
603 mi_math_assert( gamma_factor > 0);
604 const Float32 f = 1.0f / gamma_factor;
605 return { fast_pow( spectrum[0], f),
606 fast_pow( spectrum[1], f),
607 fast_pow( spectrum[2], f)};
608}
609
611inline bool is_approx_equal(
612 const Spectrum& lhs,
613 const Spectrum& rhs,
614 Float32 e)
615{
616 mi_math_assert_msg( lhs.size() == 3, "precondition");
617 mi_math_assert_msg( rhs.size() == 3, "precondition");
618 return is_approx_equal( lhs[0], rhs[0], e)
619 && is_approx_equal( lhs[1], rhs[1], e)
620 && is_approx_equal( lhs[2], rhs[2], e);
621}
622
626 const Spectrum& c1,
627 const Spectrum& c2,
628 const Spectrum& t)
629{
630 mi_math_assert_msg( c1.size() == 3, "precondition");
631 mi_math_assert_msg( c2.size() == 3, "precondition");
632 mi_math_assert_msg( t.size() == 3, "precondition");
633 return { lerp( c1[0], c2[0], t[0]),
634 lerp( c1[1], c2[1], t[1]),
635 lerp( c1[2], c2[2], t[2])};
636}
637
641 const Spectrum& c1,
642 const Spectrum& c2,
643 Float32 t)
644{
645 mi_math_assert_msg( c1.size() == 3, "precondition");
646 mi_math_assert_msg( c2.size() == 3, "precondition");
647 // equivalent to: return c1 * (1-t) + c2 * t;
648 return { lerp( c1[0], c2[0], t),
649 lerp( c1[1], c2[1], t),
650 lerp( c1[2], c2[2], t)};
651}
652
654inline Spectrum log( const Spectrum& c)
655{
656 mi_math_assert_msg( c.size() == 3, "precondition");
657 return { log( c[0]), log( c[1]), log( c[2])};
658}
659
662{
663 mi_math_assert_msg( c.size() == 3, "precondition");
664 return { log2 MI_PREVENT_MACRO_EXPAND (c[0]),
667}
668
670inline Spectrum log10( const Spectrum& c)
671{
672 mi_math_assert_msg( c.size() == 3, "precondition");
673 return { log10( c[0]), log10( c[1]), log10( c[2])};
674}
675
680inline Spectrum modf( const Spectrum& c, Spectrum& i)
681{
682 mi_math_assert_msg( c.size() == 3, "precondition");
683 mi_math_assert_msg( i.size() == 3, "precondition");
684 return { modf( c[0], i[0]), modf( c[1], i[1]), modf( c[2], i[2])};
685}
686
688inline Spectrum pow( const Spectrum& a, const Spectrum& b)
689{
690 mi_math_assert_msg( a.size() == 3, "precondition");
691 mi_math_assert_msg( b.size() == 3, "precondition");
692 return { pow( a[0], b[0]), pow( a[1], b[1]), pow( a[2], b[2])};
693}
694
696inline Spectrum pow( const Spectrum& a, Float32 b)
697{
698 mi_math_assert_msg( a.size() == 3, "precondition");
699 return { pow( a[0], b), pow( a[1], b), pow( a[2], b)};
700}
701
703inline Spectrum radians( const Spectrum& c)
704{
705 mi_math_assert_msg( c.size() == 3, "precondition");
706 return { radians( c[0]), radians( c[1]), radians( c[2])};
707}
708
710inline Spectrum round( const Spectrum& c)
711{
712 mi_math_assert_msg( c.size() == 3, "precondition");
713 return { round( c[0]), round( c[1]), round( c[2])};
714}
715
717inline Spectrum rsqrt( const Spectrum& c)
718{
719 mi_math_assert_msg( c.size() == 3, "precondition");
720 return { rsqrt( c[0]), rsqrt( c[1]), rsqrt( c[2])};
721}
722
724inline Spectrum saturate( const Spectrum& c)
725{
726 mi_math_assert_msg( c.size() == 3, "precondition");
727 return { saturate( c[0]), saturate( c[1]), saturate( c[2])};
728}
729
731inline Spectrum sign( const Spectrum& c)
732{
733 mi_math_assert_msg( c.size() == 3, "precondition");
734 return { sign( c[0]), sign( c[1]), sign( c[2])};
735}
736
738inline Spectrum sin( const Spectrum& c)
739{
740 mi_math_assert_msg( c.size() == 3, "precondition");
741 return { sin( c[0]), sin( c[1]), sin( c[2])};
742}
743
747inline void sincos( const Spectrum& a, Spectrum& s, Spectrum& c)
748{
749 mi_math_assert_msg( a.size() == 3, "precondition");
750 mi_math_assert_msg( s.size() == 3, "precondition");
751 mi_math_assert_msg( c.size() == 3, "precondition");
752 sincos( a[0], s[0], c[0]);
753 sincos( a[1], s[1], c[1]);
754 sincos( a[2], s[2], c[2]);
755}
756
762inline Spectrum smoothstep( const Spectrum& a, const Spectrum& b, const Spectrum& c)
763{
764 mi_math_assert_msg( a.size() == 3, "precondition");
765 mi_math_assert_msg( b.size() == 3, "precondition");
766 mi_math_assert_msg( c.size() == 3, "precondition");
767 return { smoothstep( a[0], b[0], c[0]),
768 smoothstep( a[1], b[1], c[1]),
769 smoothstep( a[2], b[2], c[2])};
770}
771
777inline Spectrum smoothstep( const Spectrum& a, const Spectrum& b, Float32 x)
778{
779 mi_math_assert_msg( a.size() == 3, "precondition");
780 mi_math_assert_msg( b.size() == 3, "precondition");
781 return { smoothstep( a[0], b[0], x),
782 smoothstep( a[1], b[1], x),
783 smoothstep( a[2], b[2], x)};
784}
785
787inline Spectrum sqrt( const Spectrum& c)
788{
789 mi_math_assert_msg( c.size() == 3, "precondition");
790 return { sqrt( c[0]), sqrt( c[1]), sqrt( c[2])};
791}
792
794inline Spectrum step( const Spectrum& a, const Spectrum& c)
795{
796 mi_math_assert_msg( a.size() == 3, "precondition");
797 mi_math_assert_msg( c.size() == 3, "precondition");
798 return { step( a[0], c[0]), step( a[1], c[1]), step( a[1], c[2])};
799}
800
802inline Spectrum tan( const Spectrum& c)
803{
804 mi_math_assert_msg( c.size() == 3, "precondition");
805 return { tan( c[0]), tan( c[1]), tan( c[2])};
806}
807
810{
811 mi_math_assert_msg( c.size() == 3, "precondition");
815}
816
819{
820 mi_math_assert_msg( c.size() == 3, "precondition");
824}
825
828{
829 mi_math_assert_msg( c.size() == 3, "precondition");
830 return isnan MI_PREVENT_MACRO_EXPAND (c[0])
833}
834
836MI_HOST_DEVICE_INLINE void to_rgbe( const Spectrum& c, Uint32& rgbe)
837{
838 mi_math_assert_msg( c.size() == 3, "precondition");
839 to_rgbe( &c[0], rgbe);
840}
841
843MI_HOST_DEVICE_INLINE void to_rgbe( const Spectrum& c, Uint8 rgbe[4])
844{
845 mi_math_assert_msg( c.size() == 3, "precondition");
846 to_rgbe( &c[0], rgbe);
847}
848
850MI_HOST_DEVICE_INLINE void from_rgbe( const Uint8 rgbe[4], Spectrum& c)
851{
852 mi_math_assert_msg( c.size() == 3, "precondition");
853 from_rgbe( rgbe, &c[0]);
854}
855
857MI_HOST_DEVICE_INLINE void from_rgbe( const Uint32 rgbe, Spectrum& c)
858{
859 mi_math_assert_msg( c.size() == 3, "precondition");
860 from_rgbe( rgbe, &c[0]);
861}
862 // end group mi_math_spectrum
864
865} // namespace math
866
867} // namespace mi
868
869#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 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 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
bool isinfinite(const Color &c)
Indicates whether any component of the color is infinite.
Definition: color.h:819
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
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
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
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
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
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
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
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
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
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
Color cos(const Color &c)
Returns a color with the elementwise cosine of the color c.
Definition: color.h:546
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
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:471
bool isnan(const Color &c)
Indicates whether any component of the color is "not a number".
Definition: color.h:828
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 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 asin(const Color &c)
Returns a color with the elementwise arc sine of the color c.
Definition: color.h:483
Float32 * end()
Returns the past-the-end pointer.
Definition: spectrum.h:82
static constexpr Size SIZE
Constant size of the spectrum.
Definition: spectrum.h:65
Spectrum & operator=(const Spectrum &s)=default
Default assignment operator.
Float32 & reference
Mutable reference to element.
Definition: spectrum.h:62
Float32 value_type
Element type.
Definition: spectrum.h:57
const Float32 & const_reference
Const reference to element.
Definition: spectrum.h:63
Float32 linear_intensity() const
Returns the intensity of the RGB components, equally weighted.
Definition: spectrum.h:214
MI_HOST_DEVICE_INLINE const Float32 & operator[](Size i) const
Accesses the i-th spectrum element, 0 <= i < 3.
Definition: spectrum.h:176
const Float32 * begin() const
Returns the pointer to the first spectrum element.
Definition: spectrum.h:77
Vector<Float32, 4> to_vector4() const
Conversion to Vector<Float32,4>.
Definition: spectrum.h:170
Difference difference_type
Difference type, signed.
Definition: spectrum.h:59
const Float32 * end() const
Returns the past-the-end pointer.
Definition: spectrum.h:87
static constexpr Size max_size()
Constant maximum size of the spectrum.
Definition: spectrum.h:71
Vector<Float32, 3> to_vector3() const
Conversion to Vector<Float32,3>.
Definition: spectrum.h:161
static constexpr 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:137
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:129
bool is_black() const
Returns true if the spectrum is black ignoring the alpha value.
Definition: spectrum.h:205
void set(Size i, Float32 value)
Sets the i-th spectrum element to value, 0 <= i < 3.
Definition: spectrum.h:198
Spectrum(const Color &col)
Conversion from Color.
Definition: spectrum.h:153
Spectrum(const Vector<Float32, 4> &v4)
Conversion from Vector<Float32,4>.
Definition: spectrum.h:145
const Float32 * const_pointer
Const pointer to element.
Definition: spectrum.h:61
Spectrum(const Spectrum_struct &s)
Constructor from underlying storage type.
Definition: spectrum.h:111
Float32 * pointer
Mutable pointer to element.
Definition: spectrum.h:60
Size size_type
Size type, unsigned.
Definition: spectrum.h:58
Spectrum(const Float32 s)
Constructor initializes all vector elements to the value s.
Definition: spectrum.h:119
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:191
Spectrum(const Spectrum &s)=default
Default copy constructor.
math::Spectrum_struct Spectrum_struct
Spectrum class (underlying POD type).
Definition: typedefs.h:53
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 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.