20 #if !defined(__MITSUBA_CORE_SPECTRUM_H_)
21 #define __MITSUBA_CORE_SPECTRUM_H_
23 #include <mitsuba/mitsuba.h>
25 #if !defined(SPECTRUM_SAMPLES)
26 #error The desired number of spectral samples must be \
27 specified in the configuration file!
30 #define SPECTRUM_MIN_WAVELENGTH 360
31 #define SPECTRUM_MAX_WAVELENGTH 830
32 #define SPECTRUM_RANGE \
33 (SPECTRUM_MAX_WAVELENGTH-SPECTRUM_MIN_WAVELENGTH)
78 virtual std::string toString()
const = 0;
99 m_temperature = temperature;
216 const Float *values,
size_t nEntries);
300 const static int dim = N;
303 #if !defined(MTS_DEBUG_UNINITIALIZED)
307 for (
int i=0; i<N; i++)
308 s[i] = std::numeric_limits<Scalar>::quiet_NaN();
314 for (
int i=0; i<N; i++)
320 memcpy(s, spec,
sizeof(
Scalar)*N);
330 for (
int i=0; i<N; ++i)
337 for (
int i=0; i<N; i++)
338 value.
s[i] += spec.
s[i];
344 for (
int i=0; i<N; i++)
352 for (
int i=0; i<N; i++)
353 value.
s[i] -= spec.
s[i];
359 for (
int i=0; i<N; i++)
367 for (
int i=0; i<N; i++)
379 for (
int i=0; i<N; i++)
387 for (
int i=0; i<N; i++)
388 value.
s[i] *= spec.
s[i];
394 for (
int i=0; i<N; i++)
401 for (
int i=0; i<N; i++)
409 for (
int i=0; i<N; i++)
410 value.
s[i] /= spec.
s[i];
419 SLog(
EWarn,
"TSpectrum: Division by zero!");
422 for (
int i=0; i<N; i++)
429 for (
int i=0; i<N; i++) {
430 if (s[i] != spec.
s[i])
438 return !operator==(spec);
450 SLog(
EWarn,
"TTSpectrum: Division by zero!");
453 for (
int i=0; i<N; i++)
460 for (
int i=0; i<N; i++)
461 if (std::isnan(s[i]))
468 for (
int i=0; i<N; i++)
469 if (!std::isfinite(s[i]) || s[i] < 0.0f)
476 for (
int i=0; i<N; i++)
477 s[i] += weight * spec.
s[i];
483 for (
int i=0; i<N; i++)
485 return result * (1.0f / N);
491 for (
int i=0; i<N; i++)
492 value.
s[i] = std::abs(s[i]);
499 for (
int i=0; i<N; i++)
500 value.
s[i] = std::sqrt(s[i]);
507 for (
int i=0; i<N; i++)
515 for (
int i=0; i<N; i++)
523 for (
int i=0; i<N; i++)
531 for (
int i=0; i<N; i++)
532 value.
s[i] = std::pow(s[i], f);
538 for (
int i=0; i<N; i++)
539 s[i] = std::max((
Scalar) 0.0f, s[i]);
545 for (
int i=1; i<N; i++)
546 result = std::max(result, s[i]);
553 for (
int i=1; i<N; i++)
554 result = std::min(result, s[i]);
561 for (
int i=0; i<N; i++)
578 for (
int i=0; i<N; i++) {
591 std::ostringstream oss;
593 for (
int i=0; i<N; i++) {
617 #if !defined(MTS_DEBUG_UNINITIALIZED)
621 for (
int i=0; i<3; i++)
622 s[i] = std::numeric_limits<Scalar>::quiet_NaN();
634 s[0] = r; s[1] = g; s[2] = b;
639 return s[0] * 0.212671f + s[1] * 0.715160f + s[2] * 0.072169f;
682 #if !defined(MTS_DEBUG_UNINITIALIZED)
686 for (
int i=0; i<SPECTRUM_SAMPLES; i++)
687 s[i] = std::numeric_limits<Scalar>::quiet_NaN();
696 for (
int i=0; i<SPECTRUM_SAMPLES; ++i)
702 for (
int i=0; i<SPECTRUM_SAMPLES; i++)
708 memcpy(s, value,
sizeof(
Float)*SPECTRUM_SAMPLES);
721 static std::pair<Float, Float> getBinCoverage(
size_t index);
724 #if SPECTRUM_SAMPLES == 3
725 inline Float getLuminance()
const {
726 return s[0] * 0.212671f + s[1] * 0.715160f + s[2] * 0.072169f;
729 Float getLuminance()
const;
750 EConversionIntent intent = EReflectance);
778 EConversionIntent intent = EReflectance);
780 #if SPECTRUM_SAMPLES == 3
789 r = s[0]; g = s[1]; b = s[2];
794 EConversionIntent intent = EReflectance ) {
796 s[0] = r; s[1] = g; s[2] = b;
816 EConversionIntent intent = EReflectance);
847 void fromRGBE(
const uint8_t rgbe[4], EConversionIntent intent = EIlluminant);
850 void toRGBE(
uint8_t rgbe[4])
const;
853 void fromContinuousSpectrum(
const ContinuousSpectrum &smooth);
857 for (
int i=0; i<SPECTRUM_SAMPLES; i++) {
858 if (s[i] != val.
s[i])
889 static void staticInitialization();
890 static void staticShutdown();
892 #if SPECTRUM_SAMPLES != 3
894 static Float m_wavelengths[SPECTRUM_SAMPLES+1];
float fastlog(float value)
Definition: math.h:209
Color3()
Create a new color value, but don't initialize the contents.
Definition: spectrum.h:618
T Scalar
Definition: spectrum.h:297
Scalar max() const
Return the highest-valued spectral sample.
Definition: spectrum.h:543
bool operator!=(const TSpectrum &spec) const
Inequality test.
Definition: spectrum.h:437
static Spectrum CIE_Y
Definition: spectrum.h:898
Spectrum(const Parent &s)
Construct from a TSpectrum instance.
Definition: spectrum.h:692
static Spectrum rgbRefl2SpecGreen
Definition: spectrum.h:912
static Spectrum rgbRefl2SpecWhite
Definition: spectrum.h:907
Spectrum(Float v)
Create a new spectral power distribution with all samples set to the given value. ...
Definition: spectrum.h:701
Spectrum(Float value[SPECTRUM_SAMPLES])
Copy a spectral power distribution.
Definition: spectrum.h:707
friend TSpectrum operator/(Scalar f, TSpectrum &spec)
Divide by a scalar.
Definition: spectrum.h:442
virtual ~ContinuousSpectrum()
Virtual destructor.
Definition: spectrum.h:81
TSpectrum(Scalar v)
Create a new spectral power distribution with all samples set to the given value. ...
Definition: spectrum.h:313
TSpectrum operator*(Scalar f) const
Multiply by a scalar.
Definition: spectrum.h:365
Float getLuminance() const
Return the luminance (assuming the color value is expressed in linear sRGB)
Definition: spectrum.h:638
Abstract continous spectral power distribution data type, which supports evaluation at arbitrary wave...
Definition: spectrum.h:49
friend TSpectrum operator*(Scalar f, const TSpectrum &spec)
Multiply by a scalar.
Definition: spectrum.h:373
Compute the scattering coefficient.
Definition: spectrum.h:133
Scalar min() const
Return the lowest-valued spectral sample.
Definition: spectrum.h:551
TSpectrum< Float, SPECTRUM_SAMPLES > Parent
Definition: spectrum.h:665
Color3(Float value)
Initialize to a constant value.
Definition: spectrum.h:630
std::string toString() const
Definition: spectrum.h:590
TSpectrum()
Create a new spectral power distribution, but don't initialize the contents.
Definition: spectrum.h:304
bool operator==(const TSpectrum &spec) const
Equality test.
Definition: spectrum.h:428
TSpectrum(const TSpectrum< AltScalar, N > &v)
Initialize with a TSpectrum data type based on a alternate representation.
Definition: spectrum.h:329
bool isZero() const
Check if this spectrum is zero at all wavelengths.
Definition: spectrum.h:577
Spectral distribution for rendering participating media with Rayleigh scattering. ...
Definition: spectrum.h:129
Spectral power distribution based on Planck's black body law.
Definition: spectrum.h:92
virtual ~ProductSpectrum()
Virtual destructor.
Definition: spectrum.h:181
static const Spectrum & getD65()
Return a spectral color distribution of the D65 white point (with unit luminance) ...
Definition: spectrum.h:876
#define MTS_EXPORT_CORE
Definition: getopt.h:29
#define SLog(level, fmt,...)
Write a Log message to the console (static version - to be used outside of classes that derive from O...
Definition: logger.h:49
TSpectrum operator/(const TSpectrum &spec) const
Perform a component-wise division by another spectrum.
Definition: spectrum.h:407
virtual ~InterpolatedSpectrum()
Virtual destructor.
Definition: spectrum.h:280
Spectrum()
Create a new spectral power distribution, but don't initialize the contents.
Definition: spectrum.h:683
virtual Float average(Float lambdaMin, Float lambdaMax) const
Integrate the spectral power distribution over a given interval and return the average value...
static Spectrum rgbRefl2SpecRed
Definition: spectrum.h:911
void writeArray(const T *array, size_t count)
Write an array to the stream (uses partial template specialization to select a method appropriate to ...
Definition: stream.h:520
TSpectrum sqrt() const
Component-wise square root.
Definition: spectrum.h:497
virtual ~RayleighSpectrum()
Definition: spectrum.h:147
Linearly interpolated spectral power distribution.
Definition: spectrum.h:203
TSpectrum & operator/=(Scalar f)
Divide by a scalar.
Definition: spectrum.h:447
static Float CIE_normalization
Definition: spectrum.h:900
virtual std::string toString() const =0
Return a string representation.
Spectrum(Stream *stream)
Unserialize a spectral power distribution from a binary data stream.
Definition: spectrum.h:712
TSpectrum< Float, 3 > Parent
Definition: spectrum.h:614
EMode
Definition: spectrum.h:131
static Spectrum rgbRefl2SpecYellow
Definition: spectrum.h:910
TSpectrum & operator-=(const TSpectrum &spec)
Subtract a spectral power distribution from this instance.
Definition: spectrum.h:358
RGB color data type.
Definition: spectrum.h:612
TSpectrum operator/(Scalar f) const
Divide by a scalar.
Definition: spectrum.h:415
bool operator!=(const Spectrum &val) const
Inequality test.
Definition: spectrum.h:865
static Spectrum rgbRefl2SpecCyan
Definition: spectrum.h:908
bool isNaN() const
Check for NaNs.
Definition: spectrum.h:459
Abstract spectral power distribution data type.
Definition: spectrum.h:295
TSpectrum operator-() const
Negate.
Definition: spectrum.h:559
TSpectrum operator*(const TSpectrum &spec) const
Perform a component-wise multiplication by another spectrum.
Definition: spectrum.h:385
static Spectrum rgbRefl2SpecMagenta
Definition: spectrum.h:909
static Spectrum rgbIllum2SpecYellow
Definition: spectrum.h:917
void serialize(Stream *stream) const
Serialize this spectrum to a stream.
Definition: spectrum.h:586
TSpectrum operator+(const TSpectrum &spec) const
Add two spectral power distributions.
Definition: spectrum.h:335
virtual Float eval(Float lambda) const =0
Unitless reflectance data is converted.
Definition: spectrum.h:675
static Spectrum CIE_X
Definition: spectrum.h:897
Spectrum(const TSpectrum< AltScalar, SPECTRUM_SAMPLES > &v)
Initialize with a TSpectrum data type based on a alternate representation.
Definition: spectrum.h:695
This spectral power distribution is defined as the product of two other continuous spectra...
Definition: spectrum.h:166
Abstract seekable stream class.
Definition: stream.h:58
static Spectrum rgbIllum2SpecMagenta
Definition: spectrum.h:916
static Spectrum rgbRefl2SpecBlue
Definition: spectrum.h:913
std::vector< Float > m_wavelengths
Definition: spectrum.h:282
BlackBodySpectrum(Float temperature)
Construct a new black body spectrum given the emitter's temperature in Kelvin.
Definition: spectrum.h:98
static Spectrum rgbIllum2SpecRed
Definition: spectrum.h:918
Warning message.
Definition: formatter.h:32
EConversionIntent
When converting from RGB reflectance values to discretized color spectra, the following `intent' flag...
Definition: spectrum.h:673
Scalar & operator[](int entry)
Indexing operator.
Definition: spectrum.h:567
static Spectrum rgbIllum2SpecWhite
Definition: spectrum.h:914
TSpectrum exp() const
Component-wise exponentation.
Definition: spectrum.h:521
TSpectrum log() const
Component-wise logarithm.
Definition: spectrum.h:513
TSpectrum & operator/=(const TSpectrum &spec)
Perform a component-wise division by another spectrum.
Definition: spectrum.h:400
ProductSpectrum(const ContinuousSpectrum &s1, const ContinuousSpectrum &s2)
Return the value of the spectral power distribution at the given wavelength.
Definition: spectrum.h:171
bool operator==(const Spectrum &val) const
Equality test.
Definition: spectrum.h:856
Scalar s[N]
Definition: spectrum.h:603
static Spectrum CIE_D65
Pre-integrated D65 illuminant.
Definition: spectrum.h:925
static Spectrum CIE_Z
Definition: spectrum.h:899
bool isValid() const
Returns whether the spectrum only contains valid (non-NaN, nonnegative) samples.
Definition: spectrum.h:467
TSpectrum safe_sqrt() const
Component-wise square root.
Definition: spectrum.h:505
TSpectrum(Scalar spec[N])
Copy a spectral power distribution.
Definition: spectrum.h:319
void clampNegative()
Clamp negative values.
Definition: spectrum.h:537
TSpectrum & operator*=(const TSpectrum &spec)
Perform a component-wise multiplication by another spectrum.
Definition: spectrum.h:393
Color3(Float r, Float g, Float b)
Initialize to the given RGB value.
Definition: spectrum.h:633
float safe_sqrt(float value)
Square root variant that gracefully handles arguments < 0 that are due to roundoff errors...
Definition: math.h:260
void readArray(T *array, size_t count)
Read an array from the stream (uses partial template specialization to select a method appropriate to...
Definition: stream.h:516
TSpectrum(Stream *stream)
Unserialize a spectral power distribution from a binary data stream.
Definition: spectrum.h:324
static Spectrum rgbIllum2SpecBlue
Definition: spectrum.h:920
TSpectrum & operator+=(const TSpectrum &spec)
Add a spectral power distribution to this instance.
Definition: spectrum.h:343
static Spectrum rgbIllum2SpecCyan
Definition: spectrum.h:915
virtual ~BlackBodySpectrum()
Definition: spectrum.h:102
Scalar average() const
Return the average over all wavelengths.
Definition: spectrum.h:481
TSpectrum operator-(const TSpectrum &spec) const
Subtract a spectral power distribution.
Definition: spectrum.h:350
Discrete spectral power distribution based on a number of wavelength bins over the 360-830 nm range...
Definition: spectrum.h:663
float fastexp(float value)
Definition: math.h:201
TSpectrum abs() const
Component-wise absolute value.
Definition: spectrum.h:489
TSpectrum pow(Scalar f) const
Component-wise power.
Definition: spectrum.h:529
Color3(const Parent &s)
Copy constructor.
Definition: spectrum.h:627
void addWeighted(Scalar weight, const TSpectrum &spec)
Multiply-accumulate operation, adds weight * spec.
Definition: spectrum.h:475
TSpectrum & operator*=(Scalar f)
Multiply by a scalar.
Definition: spectrum.h:378
static Spectrum rgbIllum2SpecGreen
Definition: spectrum.h:919
Scalar operator[](int entry) const
Indexing operator.
Definition: spectrum.h:572