BRL-CAD
spectrum.c File Reference
#include "common.h"
#include <math.h>
#include "bio.h"
#include "bu/debug.h"
#include "vmath.h"
#include "raytrace.h"
#include "spectrum.h"
Include dependency graph for spectrum.c:

Go to the source code of this file.

Macros

#define PLANCK_C1   37415 /* watts um^4 cm^-2 */
 
#define PLANCK_C2   14387.86 /* um K */
 
#define PLANCK(_w, _tempK)   (PLANCK_C1/(_w*_w*_w*_w*_w*(exp(PLANCK_C2/(_w*_tempK))-1)))
 

Functions

void rt_spect_make_CIE_XYZ (struct bn_tabdata **x, struct bn_tabdata **y, struct bn_tabdata **z, const struct bn_table *tabp)
 
void rt_spect_reflectance_rgb (struct bn_tabdata *curve, const float *rgb)
 
void rt_spect_black_body (struct bn_tabdata *data, double temp, unsigned int n)
 
void rt_spect_black_body_fast (struct bn_tabdata *data, double temp)
 
void rt_spect_black_body_points (struct bn_tabdata *data, double temp)
 

Detailed Description

An application of the 'tabdata' package to spectral data.

(Note that there is also a rttherm/spectrum.c)

Inspired by - Roy Hall and his book "Illumination and Color in Computer Generated Imagery", Springer Verlag, New York, 1989. ISBN 0-387-96774-5

With thanks to Russ Moulton Jr, EOSoft Inc. for his "rad.c" module.

Definition in file spectrum.c.

Macro Definition Documentation

#define PLANCK_C1   37415 /* watts um^4 cm^-2 */

Definition at line 219 of file spectrum.c.

#define PLANCK_C2   14387.86 /* um K */

Definition at line 220 of file spectrum.c.

#define PLANCK (   _w,
  _tempK 
)    (PLANCK_C1/(_w*_w*_w*_w*_w*(exp(PLANCK_C2/(_w*_tempK))-1)))

Function Documentation

void rt_spect_make_CIE_XYZ ( struct bn_tabdata **  x,
struct bn_tabdata **  y,
struct bn_tabdata **  z,
const struct bn_table tabp 
)

Given as input a spectral sampling distribution, generate the 3 curves to match the human eye's response in CIE color parameters X, Y, and Z. XYZ space can be readily converted to RGB with a 3x3 matrix.

The tabulated data is linearly interpolated.

Pointers to the three spectral weighting functions are "returned", storage for the X, Y, and Z curves is allocated by this routine and must be freed by the caller.

Definition at line 111 of file spectrum.c.

References BN_CK_TABLE, BN_GET_TABDATA, bn_tabdata_area2(), bn_tabdata_scale(), bn_table_interval_num_samples(), bu_bomb(), bu_log(), bn_table::nx, bn_table::x, and bn_tabdata::y.

Here is the call graph for this function:

void rt_spect_reflectance_rgb ( struct bn_tabdata curve,
const float *  rgb 
)

Given reflectance data (in range 0..1) in terms of RGB color, convert that to a spectral reflectance curve.

The assumption here is that the spectrum is made up of exactly three non-overlapping bands, and the reflectance is constant over each:

red ===> 572nm to 1, 000, 000nm (includes the full IR band) green => 492nm to 572nm (just green) blue ==> 1nm to 492nm (includes Ultraviolet)

As the caller may be doing a lot of this, the caller is expected to provide a pointer to a valid bn_tabdata structure which is to be filled in. Allowing caller to re-cycle them rather than doing constant malloc/free cycle.

Definition at line 191 of file spectrum.c.

References BN_CK_TABDATA, BN_CK_TABLE, bn_table::nx, bn_tabdata::table, bn_table::x, and bn_tabdata::y.

Referenced by camo_render(), light_maker(), light_setup(), marble_render(), phong_render(), shade_inputs(), and viewshade().

void rt_spect_black_body ( struct bn_tabdata data,
double  temp,
unsigned int  n 
)

Integrate Planck's Radiation Formula for a black body radiator across the given spectrum. Returns radiant emittance in W/cm**2 for each wavelength interval.

Based upon code kindly provided by Russ Moulton, Jr., EOSoft Inc. Compute at 'n-1' wavelengths evenly spaced between ax and bx.

Definition at line 238 of file spectrum.c.

References BN_CK_TABDATA, BN_CK_TABLE, bu_debug, BU_DEBUG_TABDATA, bu_log(), bn_table::nx, PLANCK, bn_tabdata::table, bn_table::x, and bn_tabdata::y.

Referenced by light_render(), and light_setup().

Here is the call graph for this function:

void rt_spect_black_body_fast ( struct bn_tabdata data,
double  temp 
)

Returns radiant emittance for each spectral interval in the given spectrum in units of watts/cm**2. Integrate each wavelength interval of spectral radiant emittance, by fitting with a rectangle (approximating curve with a horizontal line). For narrow spacing in wavelength this is OK, but with large spacing this tends to over-predict the power by 20%, due to the sharp (exponential) slope of the curve. With coarse spacing, or when unsure, use rt_spect_black_body().

Definition at line 296 of file spectrum.c.

References BN_CK_TABDATA, BN_CK_TABLE, bu_debug, BU_DEBUG_TABDATA, bu_log(), bn_table::nx, PLANCK, bn_tabdata::table, bn_table::x, and bn_tabdata::y.

Here is the call graph for this function:

void rt_spect_black_body_points ( struct bn_tabdata data,
double  temp 
)

Returns point-sampled values of spectral radiant emittance, in units of watts/cm**2/um, straight from Planck's black-body radiation formula.

Definition at line 325 of file spectrum.c.

References BN_CK_TABDATA, BN_CK_TABLE, bu_debug, BU_DEBUG_TABDATA, bu_log(), bn_table::nx, PLANCK, bn_tabdata::table, bn_table::x, and bn_tabdata::y.

Here is the call graph for this function: