commit c565ae49a99be1f1466f3708ea50e7355192123d
parent a6a4e2fb795b1bfd39fac462c298cae60a30e819
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 9 Dec 2022 16:12:25 +0100
planeto: add the htrdr_planeto_source_spectrum_at function
Make its profile compatible with the type of function expected by the
discrete distribution of wavelengths.
Diffstat:
2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/src/planeto/htrdr_planeto_source.c b/src/planeto/htrdr_planeto_source.c
@@ -447,3 +447,34 @@ exit:
error:
goto exit;
}
+
+void
+htrdr_planeto_source_spectrum_at
+ (void* source_spectrum,
+ const size_t i, /* between [0, spectrum->size[ */
+ double* wavelength, /* In nm */
+ double* radiance) /* In W/m²/sr/m */
+{
+ struct htrdr_planeto_source_spectrum* spectrum = source_spectrum;
+ ASSERT(spectrum && i < spectrum->size && wavelength && radiance);
+
+ /* Lower limit */
+ if(i == 0) {
+ *wavelength = spectrum->range[0];
+ *radiance = htrdr_planeto_source_get_radiance
+ (spectrum->source, spectrum->range[0]);
+
+ /* Upper limit */
+ } else if(i == spectrum->size-1) {
+ *wavelength = spectrum->range[1];
+ *radiance = htrdr_planeto_source_get_radiance
+ (spectrum->source, spectrum->range[1]);
+
+ /* Discrete element */
+ } else {
+ const source_radiance_T* item =
+ (const source_radiance_T*)spectrum->buffer + (i-1);
+ *wavelength = item->wavelength;
+ *radiance = item->radiance;
+ }
+}
diff --git a/src/planeto/htrdr_planeto_source.h b/src/planeto/htrdr_planeto_source.h
@@ -94,4 +94,14 @@ htrdr_planeto_source_get_spectrum
const double range[2], /* In nm. Limits are inclusive */
struct htrdr_planeto_source_spectrum* spectrum);
+/* Note that the following function profile corresponds to the type expected by
+ * the discrete wavelength distribution
+ * (see htrdr_ran_wlen_discrete_create_args structure) */
+extern LOCAL_SYM void
+htrdr_planeto_source_spectrum_at
+ (void* spectrum,
+ size_t i, /* between [0, spectrum->size[ */
+ double* wavelength, /* In nm */
+ double* radiance); /* In W/m²/sr/m */
+
#endif /* HTRDR_PLANETO_SOURCE_H */