commit ce320942390ef32c9928e218514c135c59cbae34
parent d45ffad5d51039b641be20cb7a15bdfd105a783d
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Wed, 9 Jul 2025 18:42:39 +0200
Extend BRDF API to allow retrieval of type
Implement a function that allows retrieving the type of a given BRDF.
Also, fix a typo in the reflectivity getter for Lambertian BRDFs, which
did not return the correct value. Although this was tested, the test
passed due to the specific reflectivity value used. This commit also
updates the test to use a more appropriate value for verification.
Diffstat:
3 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/src/sphin.h b/src/sphin.h
@@ -366,6 +366,11 @@ sphin_brdf_ref_put
(struct sphin_brdf* brdf);
SPHIN_API res_T
+sphin_brdf_get_type
+ (struct sphin_brdf* brdf,
+ enum sphin_brdf_type* type);
+
+SPHIN_API res_T
sphin_brdf_lambertian_get_reflectivity
(struct sphin_brdf* brdf,
double* reflectivity);
diff --git a/src/sphin_brdf.c b/src/sphin_brdf.c
@@ -180,6 +180,21 @@ sphin_brdf_ref_put
}
res_T
+sphin_brdf_get_type
+ (struct sphin_brdf* brdf,
+ enum sphin_brdf_type* type)
+{
+ res_T res = RES_OK;
+
+ if (NULL == brdf || NULL == type) {
+ return RES_BAD_ARG;
+ }
+
+ *type = brdf->type;
+ return res;
+}
+
+res_T
sphin_brdf_lambertian_get_reflectivity
(struct sphin_brdf* brdf,
double* reflectivity)
@@ -192,7 +207,7 @@ sphin_brdf_lambertian_get_reflectivity
if (SPHIN_BRDF_SPECULAR == brdf->type) {
return RES_BAD_ARG;
}
- *reflectivity = brdf->specular.reflectivity;
+ *reflectivity = brdf->lambertian.reflectivity;
return res;
}
diff --git a/src/test_sphin_load_surface.c b/src/test_sphin_load_surface.c
@@ -94,20 +94,21 @@ test_surface_api
double power, reflectivity;
struct sphin_surface* surface = NULL;
struct sphin_brdf* brdf = NULL;
+ enum sphin_brdf_type brdf_type = SPHIN_BRDF_NONE__;
size_t nsurfaces;
FILE* fp = NULL;
CHK(fp = fopen(path, "w+"));
fprintf(fp, "#Mot Clé Nom\n");
fprintf(fp, "\t\t surface : \"tube walls\"\n");
- fprintf(fp, "\tbrdf: LAMBERT 0 # my comment\n");
+ fprintf(fp, "\tbrdf: LAMBERT 0.1935 # my comment\n");
fprintf(fp, "\tgeometry: FRONT test_0.stl\n");
fprintf(fp, "\tgeometry: BACK test_3.stl\n");
fprintf(fp, " \n");
fprintf(fp, " # A line with a comment\n");
fprintf(fp, " \n");
fprintf(fp, "surface: \"other_tube walls\"\n");
- fprintf(fp, "\tbrdf\t : SPECULAR 0.5 \n");
+ fprintf(fp, "\tbrdf\t : SPECULAR 0.1935 \n");
fclose(fp);
CHK(sphin_load(sphin, path, &config) == RES_OK);
@@ -127,6 +128,8 @@ test_surface_api
CHK(sphin_surface_get_brdf(surface, NULL) == RES_BAD_ARG);
CHK(sphin_surface_get_brdf(NULL, &brdf) == RES_BAD_ARG);
CHK(sphin_surface_get_brdf(surface, &brdf) == RES_OK);
+ CHK(sphin_brdf_get_type(brdf, &brdf_type) == RES_OK);
+ CHK(brdf_type == SPHIN_BRDF_LAMBERT);
CHK(sphin_brdf_lambertian_get_reflectivity(NULL, NULL) == RES_BAD_ARG);
CHK(sphin_brdf_lambertian_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG);
CHK(sphin_brdf_specular_get_reflectivity(brdf, &reflectivity) == RES_BAD_ARG);
@@ -134,18 +137,20 @@ test_surface_api
CHK(sphin_brdf_lambertian_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG);
CHK(sphin_brdf_lambertian_get_reflectivity(brdf, NULL) == RES_BAD_ARG);
CHK(sphin_brdf_lambertian_get_reflectivity(brdf, &reflectivity) == RES_OK);
- CHK(eq_eps(reflectivity, 0, 1e-15));
+ CHK(eq_eps(reflectivity, 0.1935, 1e-15));
/* Test surface 1 */
CHK(sphin_config_get_surface(config, 1, &surface) == RES_OK);
CHK(sphin_surface_get_brdf(surface, &brdf) == RES_OK);
+ CHK(sphin_brdf_get_type(brdf, &brdf_type) == RES_OK);
+ CHK(brdf_type == SPHIN_BRDF_SPECULAR);
CHK(sphin_brdf_lambertian_get_reflectivity(brdf, &reflectivity) == RES_BAD_ARG);
CHK(sphin_brdf_specular_get_reflectivity(NULL, NULL) == RES_BAD_ARG);
CHK(sphin_brdf_specular_get_reflectivity(brdf, NULL) == RES_BAD_ARG);
CHK(sphin_brdf_specular_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG);
CHK(sphin_brdf_specular_get_reflectivity(brdf, &reflectivity) == RES_OK);
CHK(sphin_surface_source_get_power(surface, &power) == RES_BAD_ARG);
- CHK(eq_eps(reflectivity, 0.5, 1e-15));
+ 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_ref_get(surface) == RES_OK);