neuray API Programmer's Manual

spectrum.h File Reference

Description

Spectrum class with floating point elements and operations. See Spectrum Class.

Code Example

spectrum.h

‎//*****************************************************************************
// Copyright 1986, 2016 NVIDIA Corporation. All rights reserved.
//*****************************************************************************
//*****************************************************************************

#ifndef MI_MATH_SPECTRUM_H
#define MI_MATH_SPECTRUM_H

#include <mi/base/types.h>
#include <mi/math/assert.h>
#include <mi/math/function.h>
#include <mi/math/vector.h>
#include <mi/math/color.h>

namespace mi {

namespace math {

//------ Spectrum Class ---------------------------------------------------------

class Spectrum : public Spectrum_struct
{
public:
    typedef Spectrum_struct   
               Pod_type;         
    typedef Spectrum_struct   
               storage_type;     
    typedef Float32           
               value_type;       
    typedef Size              
               size_type;        
    typedef Difference        
               difference_type;  
    typedef Float32 *         pointer;          
    typedef const Float32 *   const_pointer;    
    typedef Float32 &         reference;        
    typedef const Float32 &   const_reference;  

    static const Size 
               SIZE      = 3;            

    static inline Size 
               size()     { return SIZE; }

    static inline Size 
               max_size() { return SIZE; }

    inline Float32*        begin()       { return &c[0]; }

    inline const Float32*  begin() const { return &c[0]; }

    inline Float32*        end()         { return begin() + SIZE; }

    inline const Float32*  end() const   { return begin() + SIZE; }

    inline Spectrum()
    {
#if defined(DEBUG) || (defined(_MSC_VER) && _MSC_VER <= 1310)
        // In debug mode, default-constructed spectra are initialized with signaling NaNs or, if not
        // applicable, with a maximum value to increase the chances of diagnosing incorrect use of
        // an uninitialized spectrum.
        //
        // When compiling with Visual C++ 7.1 or earlier, this code is enabled in all variants to
        // work around a very obscure compiler bug that causes the compiler to crash.
        typedef mi::base::numeric_traits< Float32> Traits;
        Float32 v = (Traits::has_signaling_NaN)
            ? Traits::signaling_NaN() : Traits::max MI_PREVENT_MACRO_EXPAND ();
        for( Size i = 0; i < SIZE; ++i)
            c[i] = v;
#endif
    }

    inline Spectrum( const Spectrum_struct& s)
    {
        for( Size i = 0; i < SIZE; ++i)
            c[i] = s.c[i];
    }


    inline explicit Spectrum( const Float32 s)
    {
        for( Size i = 0; i < SIZE; ++i)
            c[i] = s;
    }

    inline Spectrum( Float32 nr, Float32 ng, Float32 nb)
    {
        c[0] = nr;
        c[1] = ng;
        c[2] = nb;
    }

    inline explicit Spectrum( const Vector< Float32, 3>& v3)
    {
        c[0] = v3[0];
        c[1] = v3[1];
        c[2] = v3[2];
    }

    inline explicit Spectrum( const Vector< Float32, 4>& v4)
    {
        c[0] = v4[0];
        c[1] = v4[1];
        c[2] = v4[2];
    }

    inline explicit Spectrum( const Color& col)
    {
        c[0] = col.r;
        c[1] = col.g;
        c[2] = col.b;
    }

    inline Vector< Float32, 3> 
               to_vector3() const
    {
        Vector< Float32, 3> result;
        result[0] = c[0];
        result[1] = c[1];
        result[2] = c[2];
        return result;
    }

    inline Vector< Float32, 4> 
               to_vector4() const
    {
        Vector< Float32, 4> result;
        result[0] = c[0];
        result[1] = c[1];
        result[2] = c[2];
        result[3] = 1.0;
        return result;
    }

    inline Spectrum& operator=( const Spectrum& s)
    {
        Spectrum_struct::operator=( s);
        return *this;
    }

    inline const Float32& operator[]( Size i) const
    {
        mi_math_assert_msg( i < SIZE, "precondition");
        return c[i];
    }

    inline Float32& operator[]( Size i)
    {
        mi_math_assert_msg( i < SIZE, "precondition");
        return c[i];
    }


    inline Float32 get( Size i) const
    {
        mi_math_assert_msg( i < SIZE, "precondition");
        return c[i];
    }

    inline void set( Size i, Float32 value)
    {
        mi_math_assert_msg( i < SIZE, "precondition");
        c[i] = value;
    }

    inline bool is_black() const
    {
        for( Size i = 0; i < SIZE; ++i)
            if( c[i] != 0.0f)
                return false;
        return true;
    }

    inline Float32 
               linear_intensity() const
    {
        Float32 sum = 0.f;
        for( Size i = 0; i < SIZE; ++i)
            sum += c[i];
        return sum / Float32( SIZE);
    }
};

//------ Free comparison operators ==, !=, <, <=, >, >= for spectra  ------------

inline bool  operator==( const Spectrum& lhs, const Spectrum& rhs)
{
    return is_equal( lhs, rhs);
}

inline bool  operator!=( const Spectrum& lhs, const Spectrum& rhs)
{
    return is_not_equal( lhs, rhs);
}

inline bool operator< ( const Spectrum& lhs, const Spectrum& rhs)
{
    return lexicographically_less( lhs, rhs);
}

inline bool operator< =( const Spectrum& lhs, const Spectrum& rhs)
{
    return lexicographically_less_or_equal( lhs, rhs);
}

inline bool operator>( const Spectrum& lhs, const Spectrum& rhs)
{
    return lexicographically_greater( lhs, rhs);
}

inline bool operator>=( const Spectrum& lhs, const Spectrum& rhs)
{
    return lexicographically_greater_or_equal( lhs, rhs);
}



//------ Free operators +=, -=, *=, /=, +, -, *, and / for spectra --------------

inline Spectrum& operator+=( Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    lhs[0] += rhs[0];
    lhs[1] += rhs[1];
    lhs[2] += rhs[2];
    return lhs;
}

inline Spectrum& operator-=( Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    lhs[0] -= rhs[0];
    lhs[1] -= rhs[1];
    lhs[2] -= rhs[2];
    return lhs;
}

inline Spectrum& operator*=( Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    lhs[0] *= rhs[0];
    lhs[1] *= rhs[1];
    lhs[2] *= rhs[2];
    return lhs;
}

inline Spectrum& operator/=( Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    lhs[0] /= rhs[0];
    lhs[1] /= rhs[1];
    lhs[2] /= rhs[2];
    return lhs;
}

inline Spectrum 
               operator+( const Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    return Spectrum( lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2]);
}

inline Spectrum 
               operator-( const Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    return Spectrum( lhs[0] - rhs[0], lhs[1] - rhs[1], lhs[2] - rhs[2]);
}

inline Spectrum 
               operator*( const Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    return Spectrum( lhs[0] * rhs[0], lhs[1] * rhs[1], lhs[2] * rhs[2]);
}

inline Spectrum 
               operator/( const Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    return Spectrum( lhs[0] / rhs[0], lhs[1] / rhs[1], lhs[2] / rhs[2]);
}

inline Spectrum 
               operator-( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( -c[0], -c[1], -c[2]);
}



//------ Free operator *=, /=, *, and / definitions for scalars ---------------

inline Spectrum& operator*=( Spectrum& c, Float32 s)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    c[0] *= s;
    c[1] *= s;
    c[2] *= s;
    return c;
}

inline Spectrum& operator/=( Spectrum& c, Float32 s)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    const Float32 f = 1.0f / s;
    c[0] *= f;
    c[1] *= f;
    c[2] *= f;
    return c;
}

inline Spectrum 
               operator*( const Spectrum& c, Float32 s)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( c[0] * s, c[1] * s, c[2] * s);
}

inline Spectrum 
               operator*( Float32 s, const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( s * c[0], s * c[1], s* c[2]);
}

inline Spectrum 
               operator/( const Spectrum& c, Float32 s)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    Float32 f = 1.0f / s;
    return Spectrum( c[0] * f, c[1] * f, c[2] * f);
}


//------ Function Overloads for Spectrum Algorithms ------------------------------


inline Spectrum 
               abs( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( abs( c[0]), abs( c[1]), abs( c[2]));
}

inline Spectrum 
               acos( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( acos( c[0]), acos( c[1]), acos( c[2]));
}

inline bool all( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return (c[0] != 0.0f) && (c[1] != 0.0f) && (c[2] != 0.0f);
}

inline bool any( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return (c[0] != 0.0f) || (c[1] != 0.0f) || (c[2] != 0.0f);
}

inline Spectrum 
               asin( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( asin( c[0]), asin( c[1]), asin( c[2]));
}

inline Spectrum 
               atan( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( atan( c[0]), atan( c[1]), atan( c[2]));
}

inline Spectrum 
               atan2( const Spectrum& c, const Spectrum& d)
{
    mi_math_assert_msg( c.size() == 3 && d.size() == 3, "precondition");
    return Spectrum( atan2( c[0], d[0]), atan2( c[1], d[1]), atan2( c[2], d[2]));
}

inline Spectrum 
               ceil( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( ceil( c[0]), ceil( c[1]), ceil( c[2]));
}

inline Spectrum 
               clamp( const Spectrum& c, const Spectrum& low, const Spectrum& high)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    mi_math_assert_msg( low.size() == 3, "precondition");
    mi_math_assert_msg( high.size() == 3, "precondition");
    return Spectrum( clamp( c[0], low[0], high[0]),
                     clamp( c[1], low[1], high[1]),
                     clamp( c[2], low[2], high[2]));
}

inline Spectrum 
               clamp( const Spectrum& c, const Spectrum& low, Float32 high)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    mi_math_assert_msg( low.size() == 3, "precondition");
    return Spectrum( clamp( c[0], low[0], high),
                     clamp( c[1], low[1], high),
                     clamp( c[2], low[2], high));
}

inline Spectrum 
               clamp( const Spectrum& c, Float32 low, const Spectrum& high)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    mi_math_assert_msg( high.size() == 3, "precondition");
    return Spectrum( clamp( c[0], low, high[0]),
                     clamp( c[1], low, high[1]),
                     clamp( c[2], low, high[2]));
}

inline Spectrum 
               clamp( const Spectrum& c, Float32 low, Float32 high)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( clamp( c[0], low, high),
                     clamp( c[1], low, high),
                     clamp( c[2], low, high));
}

inline Spectrum 
               cos( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( cos( c[0]), cos( c[1]), cos( c[2]));
}

inline Spectrum 
               degrees( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( degrees( c[0]), degrees( c[1]), degrees( c[2]));
}

inline Spectrum 
               elementwise_max( const Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    return Spectrum( base::max MI_PREVENT_MACRO_EXPAND ( lhs[0], rhs[0]),
                     base::max MI_PREVENT_MACRO_EXPAND ( lhs[1], rhs[1]),
                     base::max MI_PREVENT_MACRO_EXPAND ( lhs[2], rhs[2]));
}

inline Spectrum 
               elementwise_min( const Spectrum& lhs, const Spectrum& rhs)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    return Spectrum( base::min MI_PREVENT_MACRO_EXPAND ( lhs[0], rhs[0]),
                     base::min MI_PREVENT_MACRO_EXPAND ( lhs[1], rhs[1]),
                     base::min MI_PREVENT_MACRO_EXPAND ( lhs[2], rhs[2]));
}

inline Spectrum 
               exp( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( exp( c[0]), exp( c[1]), exp( c[2]));
}

inline Spectrum 
               exp2( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( exp2( c[0]), exp2( c[1]), exp2( c[2]));
}

inline Spectrum 
               floor( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( floor( c[0]), floor( c[1]), floor( c[2]));
}

inline Spectrum 
               fmod( const Spectrum& a, const Spectrum& b)
{
    mi_math_assert_msg( a.size() == 3, "precondition");
    mi_math_assert_msg( b.size() == 3, "precondition");
    return Spectrum( fmod( a[0], b[0]), fmod( a[1], b[1]), fmod( a[2], b[2]));
}

inline Spectrum 
               fmod( const Spectrum& a, Float32 b)
{
    mi_math_assert_msg( a.size() == 3, "precondition");
    return Spectrum( fmod( a[0], b), fmod( a[1], b), fmod( a[2], b));
}

inline Spectrum 
               frac( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( frac( c[0]), frac( c[1]), frac( c[2]));
}

inline Spectrum 
               gamma_correction(
    const Spectrum& spectrum,    
    Float32 gamma_factor)        
{
    mi_math_assert_msg( spectrum.size() == 3, "precondition");
    mi_math_assert( gamma_factor > 0);
    const Float32 f = Float32(1.0) / gamma_factor;
    return Spectrum( fast_pow( spectrum[0], f),
                     fast_pow( spectrum[1], f),
                     fast_pow( spectrum[2], f));
}

inline bool is_approx_equal(
    const Spectrum& lhs,
    const Spectrum& rhs,
    Float32         e)
{
    mi_math_assert_msg( lhs.size() == 3, "precondition");
    mi_math_assert_msg( rhs.size() == 3, "precondition");
    return is_approx_equal( lhs[0], rhs[0], e)
        && is_approx_equal( lhs[1], rhs[1], e)
        && is_approx_equal( lhs[2], rhs[2], e);
}

inline Spectrum 
               lerp(
    const Spectrum& c1,  
    const Spectrum& c2,  
    const Spectrum& t)   
{
    mi_math_assert_msg( c1.size() == 3, "precondition");
    mi_math_assert_msg( c2.size() == 3, "precondition");
    mi_math_assert_msg( t.size() == 3, "precondition");
    return Spectrum( lerp( c1[0], c2[0], t[0]),
                     lerp( c1[1], c2[1], t[1]),
                     lerp( c1[2], c2[2], t[2]));
}

inline Spectrum 
               lerp(
    const Spectrum& c1,  
    const Spectrum& c2,  
    Float32         t)   
{
    mi_math_assert_msg( c1.size() == 3, "precondition");
    mi_math_assert_msg( c2.size() == 3, "precondition");
    // equivalent to: return c1 * (Float32(1)-t) + c2 * t;
    return Spectrum( lerp( c1[0], c2[0], t),
                     lerp( c1[1], c2[1], t),
                     lerp( c1[2], c2[2], t));
}

inline Spectrum 
               log( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( log( c[0]), log( c[1]), log( c[2]));
}

inline Spectrum 
               log2 
               MI_PREVENT_MACRO_EXPAND ( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( log2 
               MI_PREVENT_MACRO_EXPAND (c[0]),
                     log2 
               MI_PREVENT_MACRO_EXPAND (c[1]),
                     log2 
               MI_PREVENT_MACRO_EXPAND (c[2]));
}

inline Spectrum 
               log10( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( log10( c[0]), log10( c[1]), log10( c[2]));
}

inline Spectrum 
               modf( const Spectrum& c, Spectrum& i)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    mi_math_assert_msg( i.size() == 3, "precondition");
    return Spectrum( modf( c[0], i[0]), modf( c[1], i[1]), modf( c[2], i[2]));
}

inline Spectrum 
               pow( const Spectrum& a,  const Spectrum& b)
{
    mi_math_assert_msg( a.size() == 3, "precondition");
    mi_math_assert_msg( b.size() == 3, "precondition");
    return Spectrum( pow( a[0], b[0]), pow( a[1], b[1]), pow( a[2], b[2]));
}

inline Spectrum 
               pow( const Spectrum& a,  Float32 b)
{
    mi_math_assert_msg( a.size() == 3, "precondition");
    return Spectrum( pow( a[0], b), pow( a[1], b), pow( a[2], b));
}

inline Spectrum 
               radians( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( radians( c[0]), radians( c[1]), radians( c[2]));
}

inline Spectrum 
               round( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( round( c[0]), round( c[1]), round( c[2]));
}

inline Spectrum 
               rsqrt( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( rsqrt( c[0]), rsqrt( c[1]), rsqrt( c[2]));
}

inline Spectrum 
               saturate( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( saturate( c[0]), saturate( c[1]), saturate( c[2]));
}

inline Spectrum 
               sign( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( sign( c[0]), sign( c[1]), sign( c[2]));
}

inline Spectrum 
               sin( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( sin( c[0]), sin( c[1]), sin( c[2]));
}

inline void sincos( const Spectrum& a, Spectrum& s, Spectrum& c)
{
    mi_math_assert_msg( a.size() == 3, "precondition");
    mi_math_assert_msg( s.size() == 3, "precondition");
    mi_math_assert_msg( c.size() == 3, "precondition");
    sincos( a[0], s[0], c[0]);
    sincos( a[1], s[1], c[1]);
    sincos( a[2], s[2], c[2]);
}

inline Spectrum 
               smoothstep( const Spectrum& a, const Spectrum& b, const Spectrum& c)
{
    mi_math_assert_msg( a.size() == 3, "precondition");
    mi_math_assert_msg( b.size() == 3, "precondition");
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( smoothstep( a[0], b[0], c[0]),
                     smoothstep( a[1], b[1], c[1]),
                     smoothstep( a[2], b[2], c[2]));
}

inline Spectrum 
               smoothstep( const Spectrum& a, const Spectrum& b, Float32 x)
{
    mi_math_assert_msg( a.size() == 3, "precondition");
    mi_math_assert_msg( b.size() == 3, "precondition");
    return Spectrum( smoothstep( a[0], b[0], x),
                     smoothstep( a[1], b[1], x),
                     smoothstep( a[2], b[2], x));
}

inline Spectrum 
               sqrt( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( sqrt( c[0]), sqrt( c[1]), sqrt( c[2]));
}

inline Spectrum 
               step( const Spectrum& a, const Spectrum& c)
{
    mi_math_assert_msg( a.size() == 3, "precondition");
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( step( a[0], c[0]), step( a[1], c[1]), step( a[1], c[2]));
}

inline Spectrum 
               tan( const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return Spectrum( tan( c[0]), tan( c[1]), tan( c[2]));
}

inline bool isfinite 
               MI_PREVENT_MACRO_EXPAND (const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return isfinite 
               MI_PREVENT_MACRO_EXPAND (c[0])
        && isfinite 
               MI_PREVENT_MACRO_EXPAND (c[1])
        && isfinite 
               MI_PREVENT_MACRO_EXPAND (c[2]);
}

inline bool isinfinite 
               MI_PREVENT_MACRO_EXPAND (const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return isinfinite 
               MI_PREVENT_MACRO_EXPAND (c[0])
        || isinfinite 
               MI_PREVENT_MACRO_EXPAND (c[1])
        || isinfinite 
               MI_PREVENT_MACRO_EXPAND (c[2]);
}

inline bool isnan 
               MI_PREVENT_MACRO_EXPAND (const Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    return isnan 
               MI_PREVENT_MACRO_EXPAND (c[0])
        || isnan 
               MI_PREVENT_MACRO_EXPAND (c[1])
        || isnan 
               MI_PREVENT_MACRO_EXPAND (c[2]);
}

inline void to_rgbe( const Spectrum& c, Uint32& rgbe)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    to_rgbe( &c[0], rgbe);
}

inline void to_rgbe( const Spectrum& c, Uint8 rgbe[4])
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    to_rgbe( &c[0], rgbe);
}

inline void from_rgbe( const Uint8 rgbe[4], Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    from_rgbe( rgbe, &c[0]);
}

inline void from_rgbe( const Uint32 rgbe, Spectrum& c)
{
    mi_math_assert_msg( c.size() == 3, "precondition");
    from_rgbe( rgbe, &c[0]);
}
 // end group mi_math_spectrum

} // namespace math

} // namespace mi

#endif // MI_MATH_SPECTRUM_H

Namespaces

namespace 
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH. More...
namespace 
Namespace for the Math API. More...

Classes

class 
Spectrum with floating point elements and operations. More...

Functions

Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise absolute values of the spectrum c. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise arc cosine of the spectrum c. More...
bool   ( const Spectrum& c)
Returns true if all elements of c are not equal to zero. More...
bool   ( const Spectrum& c)
Returns true if any element of c is not equal to zero. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise arc sine of the spectrum c. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise arc tangent of the spectrum c. More...
Spectrum  ( const Spectrum& c, const Spectrum& d)
Returns a spectrum with the elementwise arc tangent of the spectrum c / d. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise smallest integral value that is not less than the element in spectrum c. More...
Spectrum  ( const Spectrum& c, const Spectrum& low, const Spectrum& high)
Returns the spectrum c elementwise clamped to the range [low, high]. More...
Spectrum  ( const Spectrum& c, const Spectrum& low, Float32 high)
Returns the spectrum c elementwise clamped to the range [low, high]. More...
Spectrum  ( const Spectrum& c, Float32 low, const Spectrum& high)
Returns the spectrum c elementwise clamped to the range [low, high]. More...
Spectrum  ( const Spectrum& c, Float32 low, Float32 high)
Returns the spectrum c elementwise clamped to the range [low, high]. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise cosine of the spectrum c. More...
Spectrum  ( const Spectrum& c)
Converts elementwise radians in c to degrees. More...
Spectrum  ( const Spectrum& lhs, const Spectrum& rhs)
Returns elementwise max for each element in spectrum lhs that is less than the corresponding element in spectrum rhs. More...
Spectrum  ( const Spectrum& lhs, const Spectrum& rhs)
Returns elementwise min for each element in spectrum lhs that is less than the corresponding element in spectrum rhs. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with elementwise e to the power of the element in the spectrum c. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with elementwise 2 to the power of the element in the spectrum c. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise largest integral value that is not greater than the element in spectrum c. More...
Spectrum  ( const Spectrum& a, const Spectrum& b)
Returns elementwise a modulo b, in other words, the remainder of a/b. More...
Spectrum  ( const Spectrum& a, Float32 b)
Returns elementwise a modulo b, in other words, the remainder of a/b. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise positive fractional part of the spectrum c. More...
void  ( const Uint8 rgbe[4], Spectrum& c)
Decodes a color from RGBE representation. More...
void  ( const Uint32 rgbe, Spectrum& c)
Decodes a color from RGBE representation. More...
Spectrum  ( const Spectrum& spectrum, Float32 gamma_factor)
Returns a gamma corrected spectrum. More...
bool   ( const Spectrum& lhs, const Spectrum& rhs, Float32 e)
Compares the two given values elementwise for equality within the given epsilon. More...
bool   ( const Spectrum& c)
Indicates whether all components of the spectrum are finite. More...
bool   ( const Spectrum& c)
Indicates whether any component of the spectrum is infinite. More...
bool   ( const Spectrum& c)
Indicates whether any component of the spectrum is "not a number". More...
Spectrum  ( const Spectrum& c1, const Spectrum& c2, const Spectrum& t)
Returns the elementwise linear interpolation between c1 and c2, i.e., it returns (1-t) * c1 + t * c2. More...
Spectrum  ( const Spectrum& c1, const Spectrum& c2, Float32 t)
Returns the linear interpolation between c1 and c2, i.e., it returns (1-t) * c1 + t * c2. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with elementwise natural logarithm of the spectrum c. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with elementwise base 10 logarithm of the spectrum c. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with elementwise base 2 logarithm of the spectrum c. More...
Spectrum  ( const Spectrum& c, Spectrum& i)
Returns the elementwise fractional part of c and stores the elementwise integral part of c in i. More...
bool   ( const Spectrum& lhs, const Spectrum& rhs)
Returns true if lhs is elementwise not equal to rhs. More...
Spectrum  ( const Spectrum& lhs, const Spectrum& rhs)
Multiplies rhs elementwise with lhs and returns the new result. More...
Spectrum  ( const Spectrum& c, Float32 s)
Multiplies the spectrum c elementwise with the scalar s and returns the new result. More...
Spectrum  ( Float32 s, const Spectrum& c)
Multiplies the spectrum c elementwise with the scalar s and returns the new result. More...
Spectrum&  ( Spectrum& lhs, const Spectrum& rhs)
Multiplies rhs elementwise with lhs and returns the modified lhs. More...
Spectrum&  ( Spectrum& c, Float32 s)
Multiplies the spectrum c elementwise with the scalar s and returns the modified spectrum c. More...
Spectrum  ( const Spectrum& lhs, const Spectrum& rhs)
Adds lhs and rhs elementwise and returns the new result. More...
Spectrum&  ( Spectrum& lhs, const Spectrum& rhs)
Adds rhs elementwise to lhs and returns the modified lhs. More...
Spectrum  ( const Spectrum& lhs, const Spectrum& rhs)
Subtracts rhs elementwise from lhs and returns the new result. More...
Spectrum  ( const Spectrum& c)
Negates the spectrum c elementwise and returns the new result. More...
Spectrum&  ( Spectrum& lhs, const Spectrum& rhs)
Subtracts rhs elementwise from lhs and returns the modified lhs. More...
Spectrum  ( const Spectrum& lhs, const Spectrum& rhs)
Divides rhs elementwise by lhs and returns the new result. More...
Spectrum  ( const Spectrum& c, Float32 s)
Divides the spectrum c elementwise by the scalar s and returns the new result. More...
Spectrum&  ( Spectrum& lhs, const Spectrum& rhs)
Divides lhs elementwise by rhs and returns the modified lhs. More...
Spectrum&  ( Spectrum& c, Float32 s)
Divides the spectrum c elementwise by the scalar s and returns the modified spectrum c. More...
bool   ( const Spectrum& lhs, const Spectrum& rhs)
Returns true if lhs is lexicographically less than rhs. More...
bool   ( const Spectrum& lhs, const Spectrum& rhs)
Returns true if lhs is lexicographically less than or equal to rhs. More...
bool   ( const Spectrum& lhs, const Spectrum& rhs)
Returns true if lhs is elementwise equal to rhs. More...
bool   ( const Spectrum& lhs, const Spectrum& rhs)
Returns true if lhs is lexicographically greater than rhs. More...
bool   ( const Spectrum& lhs, const Spectrum& rhs)
Returns true if lhs is lexicographically greater than or equal to rhs. More...
Spectrum  ( const Spectrum& a, const Spectrum& b)
Returns the spectrum a elementwise to the power of b. More...
Spectrum  ( const Spectrum& a, Float32 b)
Returns the spectrum a elementwise to the power of b. More...
Spectrum  ( const Spectrum& c)
Converts elementwise degrees in c to radians. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elements of spectrum c rounded to nearest integers. More...
Spectrum  ( const Spectrum& c)
Returns the reciprocal of the square root of each element of c. More...
Spectrum  ( const Spectrum& c)
Returns the spectrum c clamped elementwise to the range [0,1]. More...
Spectrum  ( const Spectrum& c)
Returns the elementwise sign of spectrum c. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise sine of the spectrum c. More...
void  ( const Spectrum& a, Spectrum& s, Spectrum& c)
Computes elementwise the sine s and cosine c of angles a simultaneously. More...
Spectrum  ( const Spectrum& a, const Spectrum& b, const Spectrum& c)
Returns 0 if c is less than a and 1 if c is greater than b in an elementwise fashion. More...
Spectrum  ( const Spectrum& a, const Spectrum& b, Float32 x)
Returns 0 if c is less than a and 1 if c is greater than b in an elementwise fashion. More...
Spectrum  ( const Spectrum& c)
Returns the square root of each element of c. More...
Spectrum  ( const Spectrum& a, const Spectrum& c)
Returns elementwise 0 if c is less than a and 1 otherwise. More...
Spectrum  ( const Spectrum& c)
Returns a spectrum with the elementwise tangent of the spectrum c. More...
void  ( const Spectrum& c, Uint32& rgbe)
Encodes a spectrum into RGBE representation. More...
void  ( const Spectrum& c, Uint8 rgbe[4])
Encodes a spectrum into RGBE representation. More...