34// FillPhongParms() checks to see if Phong parameters (params[8-11]) have been set already (contain >0 values). If any are not, sets them using JRM SigSim BRDF values (params[1-3]).
35// FillPhongParms is optional if the material table already has canonical Phong model parameter arrays set, and required otherwise. It translates DHR, %spec, etc. to Phong A,D,S,Shine.
36// FillPhongParms() inputs a nmatls-element MATL_PROP_TABLE array which is assumed to contain valid spectral BRDF parameters in the SigSim Modified Phong Model format.
37// It then converts these parameters (for each wavelength) into canonical Phong Model format (ambient, diffuse, specular, shininess) and writes them back to the mp_table.
38// Also band-averages DHR to determine AND OVERWRITE material solar absorptivity and Lambertian emissivity on disk, if necessary.
39// Inputs: sigsim_data_dir = string giving path to the main data directory.
40// nmatls = number of entries in mp_table array.
41// mp_table = array of MATL_PROP_TABLEs for which Phong parameters, absorptivities, and Lambertian emissivities should be calculated.
42// Outputs: Modified material files if discrepancies in solar absorptivity or Lambertian emissivity are found.
43// Returns: SIGSIM_MEMORY_ALLOCATION_ERROR if internal wavelength and DHR arrays cannot be allocated.
44// SIGSIM_FILE_NOT_FOUND if a material file cannot be rewritten.
83// FIXEDANGLE : If TRUE, uses original Phong prescription (builds lobeintegral into Kspec, limits Shine<128). Otherwise uses new prescription which evaluates lobeint and K's at runtime.
84// DHR [unitless] : hemispherical reflectivity
85// thetafix_deg [deg]: angle at which DHR was measured
86// pct_spec [%] : Percent Specularity
87// lobedeg [deg]: Lobe width
88// b [unitless] : For angle-dependent (hemispherical) output, set b=0. Otherwise Phong params will be angle-independent.
96// Converts Sandford Robertson BRDF params (b, width, difref, hemiemit, xmit) to SigSim BRDF params (DHR, pct_spec, lobedeg), given theta_fix angle at which DHR is to be quoted.
385// WARNING : Fill_MATL_PROP_TABLE_IOSpectrum deletes the current IO spectrum from the mp_table, and replaces it with an unpolarized spectrum given by {lambda,DHR,pctspec,lobewidth}.
386// nspecrecs is the number of elements in these input arrays (assumed the same)
387// The Sandford Robertson and Standard Phong parameters are set to -1, so it is recommended that one run FillPhongParams() after this routine.
408// IntensityModulation calculates three parameters related to the difference in at-surface response between a pixel RGB value and its approximated Phong-model material prediction.
409// See "Dual-factor Intensity Modulation" JRM whitepaper (Chris Fink 061008).
410// NOTE : Requires output of FindSDASystem as input.
411//
412// --- Inputs ---
413// Ls = Specular at-surface incident pseudoradiance [units immaterial] in 3 bands (usually RGB)
414// Ld = Diffuse (=ambient) at-surface incident pseudoradiance [units immaterial but same as Ls] in 3 bands (usually RGB)
415// costheta = [unitless] cosine of angle between surface normal and direction to specular incident pseudoradiance
416// shadow = [unitless] fraction of specular incident pseudoradiance that is unshadowed. Note 0=fully shadowed, 1=unshadowed.
417// DHR = [unitless] material DHR value in 3 bands (usually RGB bands).
418// Predict = Predicted at-surface reflected material radiance [units same as Ls and Ld] in 3 bands (usually RGB)
419// Pixel = At-surface reflected material radiance from image pixel [units same as Ls and Ld] in 3 bands (usually RGB)
420// shat = Direction of Ls. ( = X-direction)
421// dhat = Direction of projection of Ld perpendicular to Ls ( = Y-direction)
422// ahat = Direction out-of-plane of {Ls, Ld} ( = Z-direction)
423// dmag = magnitude of projection of Ld perpendicular to Ls
424// M = rotation matrix defined by transpose of {shat, dhat, ahat}. Converts RGB-system vectors to SDA-system representation.
425// --- Outputs ---
426// (*drsin) = [unitless] |dr| sin(theta_delta) = magnitude of DHR reflectance difference in plane of Ls and Ld
427// (*phi) = [radians] angle of DHR reflectance difference in {Ls, Ld} plane measured from Ls.
428// (*dshadow) = [unitless] Difference in shadowing fraction between pixel and prediction.
467// Outputs: *RCS = mean unpolarized terrain radar cross section (sigma_0) [dB] for the specified waveband and angle.
468// *STD = standard deviation of the RCS value [dB] for the specified waveband and angle.
469// Assumes: mp_table.lambda_um values are at beginning of bins, and are in increasing order for a given polarization.
470// Returns: SIGSIM_DATA_NOT_FOUND if there exist no spectral records in mp_table for which (mp_table.reflectflag[i]==rf)&&(mp_table.polarflag[i]==PL)&&(lambda>mp_table.lambda_um[i]).
480// Outputs: *RCS = mean unpolarized terrain radar cross section (sigma_0) [dB] for the specified wavelength and angle.
481// *STD = standard deviation of the RCS value [dB] for the specified wavelength and angle.
482// Assumes: mp_table.lambda_um values are at beginning of bins, and are in increasing order for a given polarization.
483// Returns: SIGSIM_DATA_NOT_FOUND if there exist no spectral records in mp_table for which (mp_table.reflectflag[i]==rf)&&(mp_table.polarflag[i]==PL)&&(lambda>mp_table.lambda_um[i]).
494// Assumes: mp_table.lambda_um values are at beginning of bins, and are in increasing order for a given polarization.
495// Returns: SIGSIM_DATA_NOT_FOUND if there exist no spectral records in mp_table for which (mp_table.reflectflag[i]==rf)&&(mp_table.polarflag[i]==PL)&&(lambda>mp_table.lambda_um[i]).