commit 613e91a73513277160ca4f6ed74b6b0200e54c6e
parent ec938886fb5456883cdbc0ed91b12c5eb4acb8f4
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Thu, 13 Nov 2025 16:44:17 +0100
Fix: Expose getter function for sensor in surfaces
Sensors were already supported in surfaces via the input file, but a
getter function was missing in Sphin. This commit adds the getter
function and includes it in the surface API tests.
Diffstat:
3 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/src/sphin.h b/src/sphin.h
@@ -318,7 +318,7 @@ sphin_volume_get_ka
SPHIN_API res_T
sphin_volume_get_sensor
(struct sphin_volume* volume,
- struct sphin_sensor_volume** sensor_volume);
+ struct sphin_sensor_volume** sensor_volume); /* May be NULL <=> no sensor */
SPHIN_API res_T
sphin_volume_get_geometry_count
@@ -401,6 +401,11 @@ sphin_surface_get_name
char** name);
SPHIN_API res_T
+sphin_surface_get_sensor
+ (struct sphin_surface* surface,
+ struct sphin_sensor_surface** sensor_surface); /* May be NULL <=> no sensor */
+
+SPHIN_API res_T
sphin_surface_get_brdf
(const struct sphin_surface* surface,
struct sphin_brdf** brdf); /* May be NULL <=> no brdf */
@@ -427,7 +432,7 @@ sphin_surface_source_get_power
double* power);
/*******************************************************************************
- * API of the source
+ * API of the surface source
******************************************************************************/
SPHIN_API res_T
sphin_source_surface_ref_get
diff --git a/src/sphin_surface.c b/src/sphin_surface.c
@@ -291,6 +291,19 @@ sphin_surface_get_name
}
res_T
+sphin_surface_get_sensor
+ (struct sphin_surface* surface,
+ struct sphin_sensor_surface** sensor_surface)
+{
+ if (NULL == surface
+ || NULL == sensor_surface) {
+ return RES_BAD_ARG;
+ }
+ *sensor_surface = surface->sensor_surface;
+ return RES_OK;
+}
+
+res_T
sphin_surface_get_brdf
(const struct sphin_surface* surface,
struct sphin_brdf** brdf)
diff --git a/src/test_sphin_load_surface.c b/src/test_sphin_load_surface.c
@@ -92,9 +92,10 @@ test_surface_api
struct sphin_config* config = NULL;
const char* path = "file.txt";
char* name = NULL;
- double power, reflectivity;
+ double power, reflectivity, response_function;
struct sphin_surface* surface = NULL;
struct sphin_brdf* brdf = NULL;
+ struct sphin_sensor_surface* sensor_surface = NULL;
enum sphin_brdf_type brdf_type = SPHIN_BRDF_NONE__;
size_t nsurfaces;
FILE* fp = NULL;
@@ -110,6 +111,8 @@ test_surface_api
fprintf(fp, " \n");
fprintf(fp, "surface: \"other_tube walls\"\n");
fprintf(fp, "\tbrdf\t : SPECULAR 0.1935 \n");
+ fprintf(fp, "\tsensor: \n");
+ fprintf(fp, "\t\tresponse_function: 1\n");
fclose(fp);
CHK(sphin_load(sphin, path, &config) == RES_OK);
@@ -159,6 +162,15 @@ test_surface_api
CHK(eq_eps(reflectivity, 0.1935, 1e-15));
CHK(sphin_brdf_ref_get(brdf) == RES_OK);
CHK(sphin_brdf_ref_put(brdf) == RES_OK);
+ CHK(sphin_surface_get_sensor(NULL, NULL) == RES_BAD_ARG);
+ CHK(sphin_surface_get_sensor(NULL, &sensor_surface) == RES_BAD_ARG);
+ CHK(sphin_surface_get_sensor(surface, NULL) == RES_BAD_ARG);
+ CHK(sphin_surface_get_sensor(surface, &sensor_surface) == RES_OK);
+ CHK(sphin_sensor_surface_get_response_function(NULL, NULL) == RES_BAD_ARG);
+ CHK(sphin_sensor_surface_get_response_function(NULL, &response_function) == RES_BAD_ARG);
+ CHK(sphin_sensor_surface_get_response_function(sensor_surface, NULL) == RES_BAD_ARG);
+ CHK(sphin_sensor_surface_get_response_function(sensor_surface, &response_function) == RES_OK);
+ CHK(eq_eps(response_function, 1, 1e-15));
CHK(sphin_surface_ref_get(surface) == RES_OK);
CHK(sphin_surface_ref_get(surface) == RES_OK);
CHK(sphin_surface_ref_put(surface) == RES_OK);