htrdr

Solving radiative transfer in heterogeneous media
git clone git://git.meso-star.fr/htrdr.git
Log | Files | Refs | README | LICENSE

commit 7784a2feab50a1deaa101d628f0c04cb82ddc628
parent cbb0e0652c75724d72cccef31c14d35ff536dc9e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 12 Jul 2018 17:02:56 +0200

Add the htrdr_sun_get_XYZ_spectral_bands_range function

Diffstat:
Msrc/htrdr_sky.c | 8++++----
Msrc/htrdr_sun.c | 42++++++++++++++++++++++++++++++++++++++----
Msrc/htrdr_sun.h | 7+++++++
3 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/src/htrdr_sky.c b/src/htrdr_sky.c @@ -487,7 +487,7 @@ htrdr_sky_fetch_raw_property || pos[0] > sky->cloud_desc.upper[0] || pos[1] > sky->cloud_desc.upper[1] || pos[2] > sky->cloud_desc.upper[2]) { - comp_mask &= ~HTRDR_PARTICLES; /* No particle */ + comp_mask &= ~HTRDR_PARTICLES; /* No particle */ } /* Compute the index of the voxel to fetch */ @@ -497,9 +497,9 @@ htrdr_sky_fetch_raw_property /* The voxels along the Z dimension have the same size */ ivox[2] = (size_t)((pos[2] - sky->cloud_desc.lower[2])/sky->htcp_desc.vxsz_z[0]); } else { - /* Irregular voxel size along the Z dimension. Compute the index Z position - * in the svx2htcp_z Look Up Table and use the LUT to define the voxel - * index into the HTCP descripptor */ + /* Irregular voxel size along the Z dimension. Compute the index of the Z + * position in the svx2htcp_z Look Up Table and use the LUT to define the + * voxel index into the HTCP descripptor */ const struct split* splits = darray_split_cdata_get(&sky->svx2htcp_z); const size_t n = darray_split_size_get(&sky->svx2htcp_z); const double sz = sky->cloud_desc.upper[2] - sky->cloud_desc.lower[2]; diff --git a/src/htrdr_sun.c b/src/htrdr_sun.c @@ -94,8 +94,8 @@ htrdr_sun_create(struct htrdr* htrdr, struct htrdr_sun** out_sun) if(!sun) { htrdr_log_err(htrdr, "could not allocate the sun data structure.\n"); res = RES_MEM_ERR; - goto error; - } + goto error; +} ref_init(&sun->ref); sun->htrdr = htrdr; darray_double_init(htrdr->allocator, &sun->radiances_sw); @@ -234,12 +234,46 @@ htrdr_sun_get_spectral_band_bounds const size_t ispectral_band, double bounds[2]) { + size_t iband_wlen; const double* wnums; ASSERT(sun && ispectral_band < htrdr_sun_get_spectral_bands_count(sun)); ASSERT(ispectral_band + 1 < darray_double_size_get(&sun->wavenumbers_sw)); + + /* The spectral bands are internally defined with wavenumbers, while the sun + * API uses wavelengths. But since wavelengths are inversely proportionnal to + * wavenumbers, one have to reversed the spectral band index */ + iband_wlen = htrdr_sun_get_spectral_bands_count(sun) - 1 - ispectral_band; wnums = darray_double_cdata_get(&sun->wavenumbers_sw); - bounds[0] = wavenumber_to_wavelength(wnums[ispectral_band+0]); - bounds[1] = wavenumber_to_wavelength(wnums[ispectral_band+1]); + bounds[1] = wavenumber_to_wavelength(wnums[iband_wlen+0]); + bounds[0] = wavenumber_to_wavelength(wnums[iband_wlen+1]); ASSERT(bounds[0] <= bounds[1]); } +void +htrdr_sun_get_XYZ_spectral_bands_range + (const struct htrdr_sun* sun, size_t band_range[2]) +{ + /* Bounds of the X, Y and Z functions as defined by the CIE */ + const double nu_min = wavelength_to_wavenumber(780); /* In cm^-1 */ + const double nu_max = wavelength_to_wavenumber(380); /* In cm^-1 */ + const double* wnums = NULL; + size_t iband_low_nu = SIZE_MAX; + size_t iband_upp_nu = SIZE_MAX; + size_t i; + ASSERT(sun && band_range); + + wnums = darray_double_cdata_get(&sun->wavenumbers_sw); + + /* Perform a linear search since the number of spectral bands is small */ + FOR_EACH(i, 0, htrdr_sun_get_spectral_bands_count(sun)) { + if(wnums[i] <= nu_min && nu_min < wnums[i+1]) iband_low_nu = i; + if(wnums[i] <= nu_max && nu_max < wnums[i+1]) iband_upp_nu = i; + } + ASSERT(iband_low_nu <= iband_upp_nu); + + /* Transform the band index from "wavenumber space" to "wavelength space" */ + band_range[0] = htrdr_sun_get_spectral_bands_count(sun) - 1 - iband_upp_nu; + band_range[1] = htrdr_sun_get_spectral_bands_count(sun) - 1 - iband_low_nu; + ASSERT(band_range[0] <= band_range[1]); +} + diff --git a/src/htrdr_sun.h b/src/htrdr_sun.h @@ -73,4 +73,11 @@ htrdr_sun_get_spectral_band_bounds const size_t ispectral_band, double bounds[2]); /* Lower and upper wavelength in nanometer */ +/* Return the ranges of the spectral bands where the XYZ color space is defined + * XYZ in [band_min, band_max] */ +extern LOCAL_SYM void +htrdr_sun_get_XYZ_spectral_bands_range + (const struct htrdr_sun* sun, + size_t band_range[2]); + #endif /* HTRDR_SUN_H */