MDL SDK API nvidia_logo_transpbg.gif Up
spectrum.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2024 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#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( Size i = 0; i < SIZE; ++i)
100 c[i] = v;
101#endif
102 }
103
104#if (__cplusplus >= 201103L)
106 Spectrum( const Spectrum& s) = default;
107
109 Spectrum& operator=( const Spectrum& s) = default;
110#endif
111
113 inline Spectrum( const Spectrum_struct& s)
114 {
115 for( Size i = 0; i < SIZE; ++i)
116 c[i] = s.c[i];
117 }
118
119
121 inline explicit Spectrum( const Float32 s)
122 {
123 for( Size i = 0; i < SIZE; ++i)
124 c[i] = s;
125 }
126
128 inline Spectrum( Float32 nr, Float32 ng, Float32 nb)
129 {
130 c[0] = nr;
131 c[1] = ng;
132 c[2] = nb;
133 }
134
136 inline explicit Spectrum( const Vector<Float32,3>& v3)
137 {
138 c[0] = v3[0];
139 c[1] = v3[1];
140 c[2] = v3[2];
141 }
142
144 inline explicit Spectrum( const Vector<Float32,4>& v4)
145 {
146 c[0] = v4[0];
147 c[1] = v4[1];
148 c[2] = v4[2];
149 }
150
152 inline explicit Spectrum( const Color& col)
153 {
154 c[0] = col.r;
155 c[1] = col.g;
156 c[2] = col.b;
157 }
158
161 {
162 Vector<Float32,3> result;
163 result[0] = c[0];
164 result[1] = c[1];
165 result[2] = c[2];
166 return result;
167 }
168
171 {
172 Vector<Float32,4> result;
173 result[0] = c[0];
174 result[1] = c[1];
175 result[2] = c[2];
176 result[3] = 1.0;
177 return result;
178 }
179
181 MI_HOST_DEVICE_INLINE const Float32& operator[]( Size i) const
182 {
183 mi_math_assert_msg( i < SIZE, "precondition");
184 return c[i];
185 }
186
188 MI_HOST_DEVICE_INLINE Float32& operator[]( Size i)
189 {
190 mi_math_assert_msg( i < SIZE, "precondition");
191 return c[i];
192 }
193
194
196 inline Float32 get( Size i) const
197 {
198 mi_math_assert_msg( i < SIZE, "precondition");
199 return c[i];
200 }
201
203 inline void set( Size i, Float32 value)
204 {
205 mi_math_assert_msg( i < SIZE, "precondition");
206 c[i] = value;
207 }
208
210 inline bool is_black() const
211 {
212 for( Size i = 0; i < SIZE; ++i)
213 if( c[i] != 0.0f)
214 return false;
215 return true;
216 }
217
220 {
221 Float32 sum = 0.f;
222 for( Size i = 0; i < SIZE; ++i)
223 sum += c[i];
224 return sum / Float32( SIZE);
225 }
226};
227
228//------ Free comparison operators ==, !=, <, <=, >, >= for spectra ------------
229
231inline bool operator==( const Spectrum& lhs, const Spectrum& rhs)
232{
233 return is_equal( lhs, rhs);
234}
235
237inline bool operator!=( const Spectrum& lhs, const Spectrum& rhs)
238{
239 return is_not_equal( lhs, rhs);
240}
241
245inline bool operator<( const Spectrum& lhs, const Spectrum& rhs)
246{
247 return lexicographically_less( lhs, rhs);
248}
249
253inline bool operator<=( const Spectrum& lhs, const Spectrum& rhs)
254{
255 return lexicographically_less_or_equal( lhs, rhs);
256}
257
261inline bool operator>( const Spectrum& lhs, const Spectrum& rhs)
262{
263 return lexicographically_greater( lhs, rhs);
264}
265
269inline bool operator>=( const Spectrum& lhs, const Spectrum& rhs)
270{
271 return lexicographically_greater_or_equal( lhs, rhs);
272}
273
274
275
276//------ Free operators +=, -=, *=, /=, +, -, *, and / for spectra --------------
277
279inline Spectrum& operator+=( Spectrum& lhs, const Spectrum& rhs)
280{
281 mi_math_assert_msg( lhs.size() == 3, "precondition");
282 mi_math_assert_msg( rhs.size() == 3, "precondition");
283 lhs[0] += rhs[0];
284 lhs[1] += rhs[1];
285 lhs[2] += rhs[2];
286 return lhs;
287}
288
290inline Spectrum& operator-=( Spectrum& lhs, const Spectrum& rhs)
291{
292 mi_math_assert_msg( lhs.size() == 3, "precondition");
293 mi_math_assert_msg( rhs.size() == 3, "precondition");
294 lhs[0] -= rhs[0];
295 lhs[1] -= rhs[1];
296 lhs[2] -= rhs[2];
297 return lhs;
298}
299
301inline Spectrum& operator*=( Spectrum& lhs, const Spectrum& rhs)
302{
303 mi_math_assert_msg( lhs.size() == 3, "precondition");
304 mi_math_assert_msg( rhs.size() == 3, "precondition");
305 lhs[0] *= rhs[0];
306 lhs[1] *= rhs[1];
307 lhs[2] *= rhs[2];
308 return lhs;
309}
310
312inline Spectrum& operator/=( Spectrum& lhs, const Spectrum& rhs)
313{
314 mi_math_assert_msg( lhs.size() == 3, "precondition");
315 mi_math_assert_msg( rhs.size() == 3, "precondition");
316 lhs[0] /= rhs[0];
317 lhs[1] /= rhs[1];
318 lhs[2] /= rhs[2];
319 return lhs;
320}
321
323inline Spectrum operator+( const Spectrum& lhs, const Spectrum& rhs)
324{
325 mi_math_assert_msg( lhs.size() == 3, "precondition");
326 mi_math_assert_msg( rhs.size() == 3, "precondition");
327 return Spectrum( lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2]);
328}
329
331inline Spectrum operator-( const Spectrum& lhs, const Spectrum& rhs)
332{
333 mi_math_assert_msg( lhs.size() == 3, "precondition");
334 mi_math_assert_msg( rhs.size() == 3, "precondition");
335 return Spectrum( lhs[0] - rhs[0], lhs[1] - rhs[1], lhs[2] - rhs[2]);
336}
337
339inline Spectrum operator*( const Spectrum& lhs, const Spectrum& rhs)
340{
341 mi_math_assert_msg( lhs.size() == 3, "precondition");
342 mi_math_assert_msg( rhs.size() == 3, "precondition");
343 return Spectrum( lhs[0] * rhs[0], lhs[1] * rhs[1], lhs[2] * rhs[2]);
344}
345
347inline Spectrum operator/( const Spectrum& lhs, const Spectrum& rhs)
348{
349 mi_math_assert_msg( lhs.size() == 3, "precondition");
350 mi_math_assert_msg( rhs.size() == 3, "precondition");
351 return Spectrum( lhs[0] / rhs[0], lhs[1] / rhs[1], lhs[2] / rhs[2]);
352}
353
355inline Spectrum operator-( const Spectrum& c)
356{
357 mi_math_assert_msg( c.size() == 3, "precondition");
358 return Spectrum( -c[0], -c[1], -c[2]);
359}
360
361
362
363//------ Free operator *=, /=, *, and / definitions for scalars ---------------
364
368{
369 mi_math_assert_msg( c.size() == 3, "precondition");
370 c[0] *= s;
371 c[1] *= s;
372 c[2] *= s;
373 return c;
374}
375
378{
379 mi_math_assert_msg( c.size() == 3, "precondition");
380 const Float32 f = 1.0f / s;
381 c[0] *= f;
382 c[1] *= f;
383 c[2] *= f;
384 return c;
385}
386
388inline Spectrum operator*( const Spectrum& c, Float32 s)
389{
390 mi_math_assert_msg( c.size() == 3, "precondition");
391 return Spectrum( c[0] * s, c[1] * s, c[2] * s);
392}
393
395inline Spectrum operator*( Float32 s, const Spectrum& c)
396{
397 mi_math_assert_msg( c.size() == 3, "precondition");
398 return Spectrum( s * c[0], s * c[1], s* c[2]);
399}
400
402inline Spectrum operator/( const Spectrum& c, Float32 s)
403{
404 mi_math_assert_msg( c.size() == 3, "precondition");
405 Float32 f = 1.0f / s;
406 return Spectrum( c[0] * f, c[1] * f, c[2] * f);
407}
408
409
410//------ Function Overloads for Spectrum Algorithms ------------------------------
411
412
414inline Spectrum abs( const Spectrum& c)
415{
416 mi_math_assert_msg( c.size() == 3, "precondition");
417 return Spectrum( abs( c[0]), abs( c[1]), abs( c[2]));
418}
419
421inline Spectrum acos( const Spectrum& c)
422{
423 mi_math_assert_msg( c.size() == 3, "precondition");
424 return Spectrum( acos( c[0]), acos( c[1]), acos( c[2]));
425}
426
428inline bool all( const Spectrum& c)
429{
430 mi_math_assert_msg( c.size() == 3, "precondition");
431 return (c[0] != 0.0f) && (c[1] != 0.0f) && (c[2] != 0.0f);
432}
433
435inline bool any( const Spectrum& c)
436{
437 mi_math_assert_msg( c.size() == 3, "precondition");
438 return (c[0] != 0.0f) || (c[1] != 0.0f) || (c[2] != 0.0f);
439}
440
442inline Spectrum asin( const Spectrum& c)
443{
444 mi_math_assert_msg( c.size() == 3, "precondition");
445 return Spectrum( asin( c[0]), asin( c[1]), asin( c[2]));
446}
447
449inline Spectrum atan( const Spectrum& c)
450{
451 mi_math_assert_msg( c.size() == 3, "precondition");
452 return Spectrum( atan( c[0]), atan( c[1]), atan( c[2]));
453}
454
458inline Spectrum atan2( const Spectrum& c, const Spectrum& d)
459{
460 mi_math_assert_msg( c.size() == 3 && d.size() == 3, "precondition");
461 return Spectrum( atan2( c[0], d[0]), atan2( c[1], d[1]), atan2( c[2], d[2]));
462}
463
466inline Spectrum ceil( const Spectrum& c)
467{
468 mi_math_assert_msg( c.size() == 3, "precondition");
469 return Spectrum( ceil( c[0]), ceil( c[1]), ceil( c[2]));
470}
471
473inline Spectrum clamp( const Spectrum& c, const Spectrum& low, const Spectrum& high)
474{
475 mi_math_assert_msg( c.size() == 3, "precondition");
476 mi_math_assert_msg( low.size() == 3, "precondition");
477 mi_math_assert_msg( high.size() == 3, "precondition");
478 return Spectrum( clamp( c[0], low[0], high[0]),
479 clamp( c[1], low[1], high[1]),
480 clamp( c[2], low[2], high[2]));
481}
482
484inline Spectrum clamp( const Spectrum& c, const Spectrum& low, Float32 high)
485{
486 mi_math_assert_msg( c.size() == 3, "precondition");
487 mi_math_assert_msg( low.size() == 3, "precondition");
488 return Spectrum( clamp( c[0], low[0], high),
489 clamp( c[1], low[1], high),
490 clamp( c[2], low[2], high));
491}
492
494inline Spectrum clamp( const Spectrum& c, Float32 low, const Spectrum& high)
495{
496 mi_math_assert_msg( c.size() == 3, "precondition");
497 mi_math_assert_msg( high.size() == 3, "precondition");
498 return Spectrum( clamp( c[0], low, high[0]),
499 clamp( c[1], low, high[1]),
500 clamp( c[2], low, high[2]));
501}
502
504inline Spectrum clamp( const Spectrum& c, Float32 low, Float32 high)
505{
506 mi_math_assert_msg( c.size() == 3, "precondition");
507 return Spectrum( clamp( c[0], low, high),
508 clamp( c[1], low, high),
509 clamp( c[2], low, high));
510}
511
513inline Spectrum cos( const Spectrum& c)
514{
515 mi_math_assert_msg( c.size() == 3, "precondition");
516 return Spectrum( cos( c[0]), cos( c[1]), cos( c[2]));
517}
518
520inline Spectrum degrees( const Spectrum& c)
521{
522 mi_math_assert_msg( c.size() == 3, "precondition");
523 return Spectrum( degrees( c[0]), degrees( c[1]), degrees( c[2]));
524}
525
528inline Spectrum elementwise_max( const Spectrum& lhs, const Spectrum& rhs)
529{
530 mi_math_assert_msg( lhs.size() == 3, "precondition");
531 mi_math_assert_msg( rhs.size() == 3, "precondition");
532 return Spectrum( base::max MI_PREVENT_MACRO_EXPAND ( lhs[0], rhs[0]),
533 base::max MI_PREVENT_MACRO_EXPAND ( lhs[1], rhs[1]),
534 base::max MI_PREVENT_MACRO_EXPAND ( lhs[2], rhs[2]));
535}
536
539inline Spectrum elementwise_min( const Spectrum& lhs, const Spectrum& rhs)
540{
541 mi_math_assert_msg( lhs.size() == 3, "precondition");
542 mi_math_assert_msg( rhs.size() == 3, "precondition");
543 return Spectrum( base::min MI_PREVENT_MACRO_EXPAND ( lhs[0], rhs[0]),
544 base::min MI_PREVENT_MACRO_EXPAND ( lhs[1], rhs[1]),
545 base::min MI_PREVENT_MACRO_EXPAND ( lhs[2], rhs[2]));
546}
547
549inline Spectrum exp( const Spectrum& c)
550{
551 mi_math_assert_msg( c.size() == 3, "precondition");
552 return Spectrum( exp( c[0]), exp( c[1]), exp( c[2]));
553}
554
556inline Spectrum exp2( const Spectrum& c)
557{
558 mi_math_assert_msg( c.size() == 3, "precondition");
559 return Spectrum( exp2( c[0]), exp2( c[1]), exp2( c[2]));
560}
561
564inline Spectrum floor( const Spectrum& c)
565{
566 mi_math_assert_msg( c.size() == 3, "precondition");
567 return Spectrum( floor( c[0]), floor( c[1]), floor( c[2]));
568}
569
573inline Spectrum fmod( const Spectrum& a, const Spectrum& b)
574{
575 mi_math_assert_msg( a.size() == 3, "precondition");
576 mi_math_assert_msg( b.size() == 3, "precondition");
577 return Spectrum( fmod( a[0], b[0]), fmod( a[1], b[1]), fmod( a[2], b[2]));
578}
579
583inline Spectrum fmod( const Spectrum& a, Float32 b)
584{
585 mi_math_assert_msg( a.size() == 3, "precondition");
586 return Spectrum( fmod( a[0], b), fmod( a[1], b), fmod( a[2], b));
587}
588
590inline Spectrum frac( const Spectrum& c)
591{
592 mi_math_assert_msg( c.size() == 3, "precondition");
593 return Spectrum( frac( c[0]), frac( c[1]), frac( c[2]));
594}
595
604 const Spectrum& spectrum,
605 Float32 gamma_factor)
606{
607 mi_math_assert_msg( spectrum.size() == 3, "precondition");
608 mi_math_assert( gamma_factor > 0);
609 const Float32 f = Float32(1.0) / gamma_factor;
610 return Spectrum( fast_pow( spectrum[0], f),
611 fast_pow( spectrum[1], f),
612 fast_pow( spectrum[2], f));
613}
614
616inline bool is_approx_equal(
617 const Spectrum& lhs,
618 const Spectrum& rhs,
619 Float32 e)
620{
621 mi_math_assert_msg( lhs.size() == 3, "precondition");
622 mi_math_assert_msg( rhs.size() == 3, "precondition");
623 return is_approx_equal( lhs[0], rhs[0], e)
624 && is_approx_equal( lhs[1], rhs[1], e)
625 && is_approx_equal( lhs[2], rhs[2], e);
626}
627
631 const Spectrum& c1,
632 const Spectrum& c2,
633 const Spectrum& t)
634{
635 mi_math_assert_msg( c1.size() == 3, "precondition");
636 mi_math_assert_msg( c2.size() == 3, "precondition");
637 mi_math_assert_msg( t.size() == 3, "precondition");
638 return Spectrum( lerp( c1[0], c2[0], t[0]),
639 lerp( c1[1], c2[1], t[1]),
640 lerp( c1[2], c2[2], t[2]));
641}
642
646 const Spectrum& c1,
647 const Spectrum& c2,
648 Float32 t)
649{
650 mi_math_assert_msg( c1.size() == 3, "precondition");
651 mi_math_assert_msg( c2.size() == 3, "precondition");
652 // equivalent to: return c1 * (Float32(1)-t) + c2 * t;
653 return Spectrum( lerp( c1[0], c2[0], t),
654 lerp( c1[1], c2[1], t),
655 lerp( c1[2], c2[2], t));
656}
657
659inline Spectrum log( const Spectrum& c)
660{
661 mi_math_assert_msg( c.size() == 3, "precondition");
662 return Spectrum( log( c[0]), log( c[1]), log( c[2]));
663}
664
667{
668 mi_math_assert_msg( c.size() == 3, "precondition");
672}
673
675inline Spectrum log10( const Spectrum& c)
676{
677 mi_math_assert_msg( c.size() == 3, "precondition");
678 return Spectrum( log10( c[0]), log10( c[1]), log10( c[2]));
679}
680
685inline Spectrum modf( const Spectrum& c, Spectrum& i)
686{
687 mi_math_assert_msg( c.size() == 3, "precondition");
688 mi_math_assert_msg( i.size() == 3, "precondition");
689 return Spectrum( modf( c[0], i[0]), modf( c[1], i[1]), modf( c[2], i[2]));
690}
691
693inline Spectrum pow( const Spectrum& a, const Spectrum& b)
694{
695 mi_math_assert_msg( a.size() == 3, "precondition");
696 mi_math_assert_msg( b.size() == 3, "precondition");
697 return Spectrum( pow( a[0], b[0]), pow( a[1], b[1]), pow( a[2], b[2]));
698}
699
701inline Spectrum pow( const Spectrum& a, Float32 b)
702{
703 mi_math_assert_msg( a.size() == 3, "precondition");
704 return Spectrum( pow( a[0], b), pow( a[1], b), pow( a[2], b));
705}
706
708inline Spectrum radians( const Spectrum& c)
709{
710 mi_math_assert_msg( c.size() == 3, "precondition");
711 return Spectrum( radians( c[0]), radians( c[1]), radians( c[2]));
712}
713
715inline Spectrum round( const Spectrum& c)
716{
717 mi_math_assert_msg( c.size() == 3, "precondition");
718 return Spectrum( round( c[0]), round( c[1]), round( c[2]));
719}
720
722inline Spectrum rsqrt( const Spectrum& c)
723{
724 mi_math_assert_msg( c.size() == 3, "precondition");
725 return Spectrum( rsqrt( c[0]), rsqrt( c[1]), rsqrt( c[2]));
726}
727
729inline Spectrum saturate( const Spectrum& c)
730{
731 mi_math_assert_msg( c.size() == 3, "precondition");
732 return Spectrum( saturate( c[0]), saturate( c[1]), saturate( c[2]));
733}
734
736inline Spectrum sign( const Spectrum& c)
737{
738 mi_math_assert_msg( c.size() == 3, "precondition");
739 return Spectrum( sign( c[0]), sign( c[1]), sign( c[2]));
740}
741
743inline Spectrum sin( const Spectrum& c)
744{
745 mi_math_assert_msg( c.size() == 3, "precondition");
746 return Spectrum( sin( c[0]), sin( c[1]), sin( c[2]));
747}
748
752inline void sincos( const Spectrum& a, Spectrum& s, Spectrum& c)
753{
754 mi_math_assert_msg( a.size() == 3, "precondition");
755 mi_math_assert_msg( s.size() == 3, "precondition");
756 mi_math_assert_msg( c.size() == 3, "precondition");
757 sincos( a[0], s[0], c[0]);
758 sincos( a[1], s[1], c[1]);
759 sincos( a[2], s[2], c[2]);
760}
761
767inline Spectrum smoothstep( const Spectrum& a, const Spectrum& b, const Spectrum& c)
768{
769 mi_math_assert_msg( a.size() == 3, "precondition");
770 mi_math_assert_msg( b.size() == 3, "precondition");
771 mi_math_assert_msg( c.size() == 3, "precondition");
772 return Spectrum( smoothstep( a[0], b[0], c[0]),
773 smoothstep( a[1], b[1], c[1]),
774 smoothstep( a[2], b[2], c[2]));
775}
776
782inline Spectrum smoothstep( const Spectrum& a, const Spectrum& b, Float32 x)
783{
784 mi_math_assert_msg( a.size() == 3, "precondition");
785 mi_math_assert_msg( b.size() == 3, "precondition");
786 return Spectrum( smoothstep( a[0], b[0], x),
787 smoothstep( a[1], b[1], x),
788 smoothstep( a[2], b[2], x));
789}
790
792inline Spectrum sqrt( const Spectrum& c)
793{
794 mi_math_assert_msg( c.size() == 3, "precondition");
795 return Spectrum( sqrt( c[0]), sqrt( c[1]), sqrt( c[2]));
796}
797
799inline Spectrum step( const Spectrum& a, const Spectrum& c)
800{
801 mi_math_assert_msg( a.size() == 3, "precondition");
802 mi_math_assert_msg( c.size() == 3, "precondition");
803 return Spectrum( step( a[0], c[0]), step( a[1], c[1]), step( a[1], c[2]));
804}
805
807inline Spectrum tan( const Spectrum& c)
808{
809 mi_math_assert_msg( c.size() == 3, "precondition");
810 return Spectrum( tan( c[0]), tan( c[1]), tan( c[2]));
811}
812
815{
816 mi_math_assert_msg( c.size() == 3, "precondition");
820}
821
824{
825 mi_math_assert_msg( c.size() == 3, "precondition");
829}
830
833{
834 mi_math_assert_msg( c.size() == 3, "precondition");
835 return isnan MI_PREVENT_MACRO_EXPAND (c[0])
838}
839
841MI_HOST_DEVICE_INLINE void to_rgbe( const Spectrum& c, Uint32& rgbe)
842{
843 mi_math_assert_msg( c.size() == 3, "precondition");
844 to_rgbe( &c[0], rgbe);
845}
846
848MI_HOST_DEVICE_INLINE void to_rgbe( const Spectrum& c, Uint8 rgbe[4])
849{
850 mi_math_assert_msg( c.size() == 3, "precondition");
851 to_rgbe( &c[0], rgbe);
852}
853
855MI_HOST_DEVICE_INLINE void from_rgbe( const Uint8 rgbe[4], Spectrum& c)
856{
857 mi_math_assert_msg( c.size() == 3, "precondition");
858 from_rgbe( rgbe, &c[0]);
859}
860
862MI_HOST_DEVICE_INLINE void from_rgbe( const Uint32 rgbe, Spectrum& c)
863{
864 mi_math_assert_msg( c.size() == 3, "precondition");
865 from_rgbe( rgbe, &c[0]);
866}
867 // end group mi_math_spectrum
869
870} // namespace math
871
872} // namespace mi
873
874#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:625
Color sqrt(const Color &c)
Returns the square root of each element of c.
Definition: color.h:804
bool isinfinite(const Color &c)
Indicates whether any component of the color is infinite.
Definition: color.h:831
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
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 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
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
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 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
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
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 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
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
Color cos(const Color &c)
Returns a color with the elementwise cosine of the color c.
Definition: color.h:558
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
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 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 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
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 asin(const Color &c)
Returns a color with the elementwise arc sine of the color c.
Definition: color.h:495
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:219
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:181
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:170
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:160
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:136
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:128
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:210
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:203
Spectrum(const Color &col)
Conversion from Color.
Definition: spectrum.h:152
Spectrum(const Vector<Float32, 4> &v4)
Conversion from Vector<Float32,4>.
Definition: spectrum.h:144
Spectrum(const Spectrum_struct &s)
Constructor from underlying storage type.
Definition: spectrum.h:113
Spectrum(const Float32 s)
Constructor initializes all vector elements to the value s.
Definition: spectrum.h:121
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:196
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: 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.