commit 8971f39ef4fe90551b051830e84ed801ea3e9668
parent 7e33f1e1fe57faf8c0c4c5a26f93122e28d1f459
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 15 Apr 2020 10:17:49 +0200
Rm the CIE XYZ functions and add the find spectral band one
Diffstat:
4 files changed, 24 insertions(+), 90 deletions(-)
diff --git a/src/htsky.c b/src/htsky.c
@@ -113,28 +113,6 @@ error:
goto exit;
}
-static void
-sample_sw_spectral_data
- (struct htgop* htgop,
- const double r0,
- const double r1,
- res_T (*sample_sw_band)(const struct htgop*, const double, size_t*),
- size_t* ispectral_band,
- size_t* iquadrature_pt)
-{
- struct htgop_spectral_interval specint;
- res_T res = RES_OK;
- ASSERT(htgop && sample_sw_band && ispectral_band && iquadrature_pt);
- ASSERT(ispectral_band && iquadrature_pt);
- ASSERT(r0 >= 0 && r0 < 1);
- ASSERT(r1 >= 0 && r1 < 1);
- (void)res;
- res = sample_sw_band(htgop, r0, ispectral_band);
- ASSERT(res == RES_OK);
- HTGOP(get_sw_spectral_interval(htgop, *ispectral_band, &specint));
- HTGOP(spectral_interval_sample_quadrature(&specint, r1, iquadrature_pt));
-}
-
static INLINE double
particle_fetch_raw_property
(const struct htsky* sky,
@@ -972,46 +950,18 @@ htsky_is_long_wave(const struct htsky* htsky)
return htsky->is_long_wave;
}
-void
-htsky_sample_sw_spectral_data_CIE_1931_X
- (const struct htsky* sky,
- const double r0, /* Random number in [0, 1[ */
- const double r1, /* Random number in [0, 1[ */
- size_t* ispectral_band,
- size_t* iquadrature_pt)
-{
- ASSERT(!sky->is_long_wave);
- sample_sw_spectral_data
- (sky->htgop, r0, r1, htgop_sample_sw_spectral_interval_CIE_1931_X,
- ispectral_band, iquadrature_pt);
-}
-
-void
-htsky_sample_sw_spectral_data_CIE_1931_Y
- (const struct htsky* sky,
- const double r0, /* Random number in [0, 1[ */
- const double r1, /* Random number in [0, 1[ */
- size_t* ispectral_band,
- size_t* iquadrature_pt)
-{
- ASSERT(!sky->is_long_wave);
- sample_sw_spectral_data
- (sky->htgop, r0, r1, htgop_sample_sw_spectral_interval_CIE_1931_Y,
- ispectral_band, iquadrature_pt);
-}
-
-void
-htsky_sample_sw_spectral_data_CIE_1931_Z
- (const struct htsky* sky,
- const double r0, /* Random number in [0, 1[ */
- const double r1, /* Random number in [0, 1[ */
- size_t* ispectral_band,
- size_t* iquadrature_pt)
+size_t
+htsky_find_spectral_band(const struct htsky* sky, const double wavelength)
{
- ASSERT(!sky->is_long_wave);
- sample_sw_spectral_data
- (sky->htgop, r0, r1, htgop_sample_sw_spectral_interval_CIE_1931_Z,
- ispectral_band, iquadrature_pt);
+ const double wnum = wavelength_to_wavenumber(wavelength);
+ size_t iband;
+ ASSERT(sky);
+ if(sky->is_long_wave) {
+ HTGOP(find_lw_spectral_interval_id(sky->htgop, wnum, &iband));
+ } else {
+ HTGOP(find_sw_spectral_interval_id(sky->htgop, wnum, &iband));
+ }
+ return iband;
}
size_t
@@ -1022,6 +972,7 @@ htsky_spectral_band_sample_quadrature
{
struct htgop_spectral_interval band;
size_t iquad;
+ ASSERT(sky);
ASSERT(sky->bands_range[0] <= iband || iband <= sky->bands_range[1]);
if(sky->is_long_wave) {
diff --git a/src/htsky.h b/src/htsky.h
@@ -209,31 +209,14 @@ HTSKY_API int
htsky_is_long_wave
(const struct htsky* sky);
-HTSKY_API void
-htsky_sample_sw_spectral_data_CIE_1931_X
- (const struct htsky* sky,
- const double r0, /* Random number in [0, 1[ */
- const double r1, /* Random number in [0, 1[ */
- size_t* ispectral_band,
- size_t* iquadrature_pt);
-
-HTSKY_API void
-htsky_sample_sw_spectral_data_CIE_1931_Y
- (const struct htsky* sky,
- const double r0, /* Random number in [0, 1[ */
- const double r1, /* Random number in [0, 1[ */
- size_t* ispectral_band,
- size_t* iquadrature_pt);
-
-HTSKY_API void
-htsky_sample_sw_spectral_data_CIE_1931_Z
+/* Return the index of the band containing the submitted wavelength or SIZE_MAX
+ * if `wavelength' is not included in any band */
+HTSKY_API size_t
+htsky_find_spectral_band
(const struct htsky* sky,
- const double r0, /* Random number in [0, 1[ */
- const double r1, /* Random number in [0, 1[ */
- size_t* ispectral_band,
- size_t* iquadrature_pt);
+ const double wavelength); /* In nanometer */
-/* Returned the sampled quadrature point */
+/* Return the sampled quadrature point */
HTSKY_API size_t
htsky_spectral_band_sample_quadrature
(const struct htsky* sky,
diff --git a/src/htsky_atmosphere.c b/src/htsky_atmosphere.c
@@ -201,7 +201,7 @@ atmosphere_setup(struct htsky* sky, const double optical_thickness_threshold)
(sky->allocator, nbands, sizeof(*sky->atmosphere));
if(!sky->atmosphere) {
log_err(sky,
- "could not create the list of per SW band atmospheric data structure.\n");
+ "Could not create the list of per SW band atmospheric data structure.\n");
res = RES_MEM_ERR;
goto error;
}
@@ -221,7 +221,7 @@ atmosphere_setup(struct htsky* sky, const double optical_thickness_threshold)
band.quadrature_length, sizeof(*sky->atmosphere[i]));
if(!sky->atmosphere[i]) {
log_err(sky,
- "could not create the list of per quadrature point atmospheric data "
+ "Could not create the list of per quadrature point atmospheric data "
"for the band %lu.\n", (unsigned long)ctx.iband);
res = RES_MEM_ERR;
goto error;
@@ -237,7 +237,7 @@ atmosphere_setup(struct htsky* sky, const double optical_thickness_threshold)
res = svx_bintree_create(sky->svx, low, upp, definition, SVX_AXIS_Z,
&vox_desc, &sky->atmosphere[i][iquad].bitree);
if(res != RES_OK) {
- log_err(sky, "could not create the binary tree of the "
+ log_err(sky, "Could not create the binary tree of the "
"atmospheric properties for the band %lu.\n", (unsigned long)ctx.iband);
goto error;
}
diff --git a/src/htsky_cloud.c b/src/htsky_cloud.c
@@ -81,7 +81,7 @@ setup_svx2htcp_z_lut(struct htsky* sky, double* cloud_upp_z)
res = darray_split_resize(&sky->svx2htcp_z, nsplits);
if(res != RES_OK) {
log_err(sky,
- "could not allocate the table mapping regular to irregular Z.\n");
+ "Could not allocate the table mapping regular to irregular Z.\n");
goto error;
}
@@ -854,7 +854,7 @@ cloud_setup
res = htcp_get_desc(sky->htcp, &sky->htcp_desc);
if(res != RES_OK) {
- log_err(sky, "could not retrieve the HTCP descriptor.\n");
+ log_err(sky, "Could not retrieve the HTCP descriptor.\n");
goto error;
}
@@ -885,7 +885,7 @@ cloud_setup
sky->clouds = MEM_CALLOC(sky->allocator, nbands, sizeof(*sky->clouds));
if(!sky->clouds) {
log_err(sky,
- "could not create the list of per SW band cloud data structure.\n");
+ "Could not create the list of per SW band cloud data structure.\n");
res = RES_MEM_ERR;
goto error;
}