commit 298810fc0ea5276050006a0f27f42e83dce1ca16
parent 82dc870b3514ca1675d99bec881dfbe6071efc85
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 22 Sep 2020 14:06:12 +0200
Add radiance component to htrdr_compute_radiance_sw function
Diffstat:
3 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/htrdr_compute_radiance_sw.c b/src/htrdr_compute_radiance_sw.c
@@ -252,6 +252,7 @@ htrdr_compute_radiance_sw
(struct htrdr* htrdr,
const size_t ithread,
struct ssp_rng* rng,
+ const int cpnt_mask, /* Combination of enum htrdr_radiance_cpnt_flag */
const double pos_in[3],
const double dir_in[3],
const double wlen, /* In nanometer */
@@ -309,12 +310,10 @@ htrdr_compute_radiance_sw
d3_set(pos, pos_in);
d3_set(dir, dir_in);
- /* Add the directly contribution of the sun */
- if(htrdr_sun_is_dir_in_solar_cone(htrdr->sun, dir)) {
- /* Add the direct contribution of the sun */
- d2(range, 0, FLT_MAX);
-
+ if((cpnt_mask & HTRDR_RADIANCE_DIRECT) /* Handle direct contribuation */
+ && htrdr_sun_is_dir_in_solar_cone(htrdr->sun, dir)) {
/* Check that the ray is not occlude along the submitted range */
+ d2(range, 0, FLT_MAX);
HTRDR(ground_trace_ray(htrdr->ground, pos, dir, range, NULL, &s3d_hit_tmp));
if(!S3D_HIT_NONE(&s3d_hit_tmp)) {
Tr = 0;
@@ -325,6 +324,9 @@ htrdr_compute_radiance_sw
}
}
+ if((cpnt_mask & HTRDR_RADIANCE_DIFFUSE) == 0)
+ goto exit; /* Discard diffuse contribution */
+
/* Radiative random walk */
for(;;) {
struct scattering_context scattering_ctx = SCATTERING_CONTEXT_NULL;
@@ -458,6 +460,8 @@ htrdr_compute_radiance_sw
}
SSF(phase_ref_put(phase_hg));
SSF(phase_ref_put(phase_rayleigh));
+
+exit:
return w;
}
diff --git a/src/htrdr_draw_map.c b/src/htrdr_draw_map.c
@@ -561,8 +561,8 @@ draw_pixel_image
iquad = htsky_spectral_band_sample_quadrature(htrdr->sky, r2, iband);
/* Compute the radiance in W/m^2/sr/m */
- weight = htrdr_compute_radiance_sw
- (htrdr, ithread, rng, ray_org, ray_dir, wlen, iband, iquad);
+ weight = htrdr_compute_radiance_sw(htrdr, ithread, rng,
+ HTRDR_RADIANCE_ALL, ray_org, ray_dir, wlen, iband, iquad);
ASSERT(weight >= 0);
pdf *= 1.e9; /* Transform the pdf from nm^-1 to m^-1 */
@@ -638,7 +638,8 @@ draw_pixel_xwave
size_t isamp;
double temp_min, temp_max;
ASSERT(ipix && ipix && pix_sz && sensor && rng && pixel);
- ASSERT(htrdr->spectral_type == HTRDR_SPECTRAL_LW
+ ASSERT(sensor->type == HTRDR_SENSOR_CAMERA);
+ ASSERT(htrdr->spectral_type == HTRDR_SPECTRAL_LW
|| htrdr->spectral_type == HTRDR_SPECTRAL_SW);
/* Reset the pixel accumulators */
@@ -661,7 +662,7 @@ draw_pixel_xwave
/* Begin the registration of the time spent in the realisation */
time_current(&t0);
- res = htrdr_sensor_sample_primary_ray(&htrdr->sensor, htrdr->ground, ipix,
+ res = htrdr_sensor_sample_primary_ray(sensor, htrdr->ground, ipix,
pix_sz, rng, ray_org, ray_dir);
if(res != RES_OK) continue; /* Reject the current sample */
@@ -683,13 +684,12 @@ draw_pixel_xwave
ray_dir, wlen, iband, iquad);
break;
case HTRDR_SPECTRAL_SW:
- weight = htrdr_compute_radiance_sw(htrdr, ithread, rng, ray_org,
- ray_dir, wlen, iband, iquad);
+ weight = htrdr_compute_radiance_sw(htrdr, ithread, rng,
+ HTRDR_RADIANCE_ALL, ray_org, ray_dir, wlen, iband, iquad);
break;
default: FATAL("Unreachable code.\n"); break;
}
ASSERT(weight >= 0);
-
/* Importance sampling: correct weight with pdf */
weight /= band_pdf; /* In W/m^2/sr */
diff --git a/src/htrdr_solve.h b/src/htrdr_solve.h
@@ -19,6 +19,13 @@
#include <rsys/rsys.h>
+/* Define the radiance component */
+enum htrdr_radiance_cpnt_flag {
+ HTRDR_RADIANCE_DIRECT = BIT(0),
+ HTRDR_RADIANCE_DIFFUSE = BIT(1),
+ HTRDR_RADIANCE_ALL = HTRDR_RADIANCE_DIRECT | HTRDR_RADIANCE_DIFFUSE
+};
+
/* Monte carlo accumulator */
struct htrdr_accum {
double sum_weights; /* Sum of Monte-Carlo weights */
@@ -62,6 +69,7 @@ htrdr_compute_radiance_sw
(struct htrdr* htrdr,
const size_t ithread,
struct ssp_rng* rng,
+ const int cpnt_mask, /* Combination of enum htrdr_radiance_cpnt_flag */
const double pos[3],
const double dir[3],
const double wlen, /* In nanometer */