commit 57569615366a8ee30223b083742e4e48beb75c90
parent bd940db5a6c21743aa2f5e39e4589a7b43fa99b2
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Fri, 21 Feb 2025 17:54:26 +0100
Expand library API with new enums, structs and function prototypes
Diffstat:
5 files changed, 169 insertions(+), 12 deletions(-)
diff --git a/src/sphin.h b/src/sphin.h
@@ -56,14 +56,91 @@ enum sphin_brdf_type {
SPHIN_BRDF_NONE__ /* 2 */
};
+enum sphin_flux_density_unit {
+ SPHIN_FLUX_DENSITY_MOL, /* [mol hv/m^2/s] */
+ SPHIN_FLUX_DENSITY_POW, /* [W/m^2] */
+ SPHIN_FLUX_DENSITY_NONE__
+};
+
+enum sphin_source_direction_distribution_type {
+ SPHIN_SOURCE_DIRECTION_COLLIM,
+ SPHIN_SOURCE_DIRECTION_COS_POW_N,
+ SPHIN_SOURCE_DIRECTION_ISOTROPIC,
+ SPHIN_SOURCE_DIRECTION_NONE__
+};
+
struct sphin_create_args {
struct logger* logger; /* May be NULL <=> default logger */
struct mem_allocator* allocator; /* NULL <=> use default allocator */
int verbose; /* Verbosity level */
};
-static const struct sphin_create_args SPHIN_CREATE_ARGS_DEFAULT = {
- NULL, NULL, 0
+#define SPHIN_CREATE_ARGS_DEFAULT__ {NULL, NULL, 0}
+static const struct sphin_create_args SPHIN_CREATE_ARGS_DEFAULT =
+ SPHIN_CREATE_ARGS_DEFAULT__;
+
+struct sphin_brdf_lambertian {
+ double reflectivity;
+};
+#define SPHIN_BRDF_LAMBERTIAN_NULL__ {0}
+static const struct sphin_brdf_lambertian SPHIN_BRDF_LAMBERTIAN_NULL =
+ SPHIN_BRDF_LAMBERTIAN_NULL__;
+
+struct sphin_brdf_specular {
+ double reflectivity;
+};
+#define SPHIN_BRDF_SPECULAR_NULL__ {0}
+static const struct sphin_brdf_specular SPHIN_BRDF_SPECULAR_NULL =
+ SPHIN_BRDF_SPECULAR_NULL__;
+
+struct sphin_brdf {
+ enum sphin_brdf_type type;
+ struct sphin_brdf_lambertian lambertian;
+ struct sphin_brdf_specular specular;
+};
+#define SPHIN_BRDF_NULL__ { \
+ SPHIN_BRDF_NONE__, \
+ SPHIN_BRDF_LAMBERTIAN_NULL__, \
+ SPHIN_BRDF_SPECULAR_NULL__ \
+}
+static const struct sphin_brdf SPHIN_BRDF_NULL = SPHIN_BRDF_NULL__;
+
+struct sphin_flux_density {
+ double flux_density; /* either [mol hv/m^2/s] or [W/m^2] */
+ enum sphin_flux_density_unit unit;
+};
+#define SPHIN_FLUX_DENSITY_NULL__ {0, SPHIN_FLUX_DENSITY_NONE__}
+static const struct sphin_flux_density SPHIN_FLUX_DENSITY_NULL =
+ SPHIN_FLUX_DENSITY_NULL__;
+
+struct sphin_source_direction_distribution_cos_pow_n {
+ double collimation_degree;
+};
+#define SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COS_POW_N_NULL__ {0}
+static const struct sphin_source_direction_distribution_cos_pow_n
+ SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COS_POW_N_NULL =
+ SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COS_POW_N_NULL__;
+
+struct sphin_source_direction_distribution_collim {
+ double direction[3]; /* {0,0,0} <=> use surface normal */
+};
+#define SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL__ {{0,0,0}}
+static const struct sphin_source_direction_distribution_collim
+ SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL =
+ SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL__;
+
+struct sphin_source_direction_distribution {
+ enum sphin_source_direction_distribution_type type;
+ struct sphin_source_direction_distribution_cos_pow_n cos_pow_n;
+ struct sphin_source_direction_distribution_collim collim;
};
+#define SPHIN_SOURCE_DIRECTION_DISTRIBUTION_NULL__ { \
+ SPHIN_SOURCE_DIRECTION_NONE__, \
+ SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COS_POW_N_NULL__, \
+ SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL__ \
+}
+static const struct sphin_source_direction_distribution
+ SPHIN_SOURCE_DIRECTION_DISTRIBUTION_NULL =
+ SPHIN_SOURCE_DIRECTION_DISTRIBUTION_NULL__;
/* Forward declaration
* We declare the structure sphin, but its representation remains opaque to the
@@ -72,12 +149,13 @@ static const struct sphin_create_args SPHIN_CREATE_ARGS_DEFAULT = {
struct sphin; /* Library handler */
struct sphin_config; /* Physical configuration */
struct sphin_volume;
+struct sphin_source;
struct sphin_surface;
BEGIN_DECLS
/*******************************************************************************
- * API of the library loading sphin fileformat
+ * API of the sphin handle
******************************************************************************/
SPHIN_API res_T
sphin_create
@@ -92,6 +170,9 @@ SPHIN_API res_T
sphin_ref_put
(struct sphin* sphin);
+/*******************************************************************************
+ * API of the configuration
+ ******************************************************************************/
SPHIN_API res_T
sphin_load
(struct sphin* sphin,
@@ -125,6 +206,20 @@ sphin_config_get_volume
struct sphin_volume** volume);
SPHIN_API res_T
+sphin_config_get_surface_count
+ (struct sphin_config* config,
+ size_t* nsurfaces);
+
+SPHIN_API res_T
+sphin_config_get_surface
+ (struct sphin_config* config,
+ size_t isurface,
+ struct sphin_surface** surface);
+
+/*******************************************************************************
+ * API of the volume
+ ******************************************************************************/
+SPHIN_API res_T
sphin_volume_ref_get
(struct sphin_volume* volume);
@@ -132,6 +227,9 @@ SPHIN_API res_T
sphin_volume_ref_put
(struct sphin_volume* volume);
+/*******************************************************************************
+ * API of the surface
+ ******************************************************************************/
SPHIN_API res_T
sphin_surface_ref_get
(struct sphin_surface* surface);
@@ -140,6 +238,37 @@ SPHIN_API res_T
sphin_surface_ref_put
(struct sphin_surface* surface);
+SPHIN_API res_T
+sphin_surface_get_brdf
+ (const struct sphin_surface* surface,
+ struct sphin_brdf* brdf);
+
+SPHIN_API res_T
+sphin_surface_get_source
+ (const struct sphin_surface* surface,
+ struct sphin_source** source); /* May be NULL <=> no source */
+
+/*******************************************************************************
+ * API of the source
+ ******************************************************************************/
+SPHIN_API res_T
+sphin_source_ref_get
+ (struct sphin_source* source);
+
+SPHIN_API res_T
+sphin_source_ref_put
+ (struct sphin_source* source);
+
+SPHIN_API res_T
+sphin_source_get_flux_density
+ (const struct sphin_source* source,
+ struct sphin_flux_density* density);
+
+SPHIN_API res_T
+sphin_source_get_direction_distribution
+ (const struct sphin_source* source,
+ struct sphin_source_direction_distribution* distrib);
+
END_DECLS
#endif /* SPHIN_H */
diff --git a/src/sphin_brdf.c b/src/sphin_brdf.c
@@ -37,8 +37,8 @@ brdf_init
}
void
-geometry_release
- (struct brdf* geom)
+brdf_release
+ (struct brdf* brdf)
{
}
diff --git a/src/sphin_config.c b/src/sphin_config.c
@@ -139,7 +139,7 @@ load_stream
if (NULL == name){ res = RES_BAD_ARG; goto error; }
if (0 == strcmp(keyword, "volume")){
- res = parse_volume(config, txtrdr, name);
+ res = parse_volume(config, txtrdr, name);
}
else if (0 == strcmp(keyword, "surface")){
res = parse_surface(config, txtrdr, name);
diff --git a/src/sphin_surface.c b/src/sphin_surface.c
@@ -40,7 +40,7 @@ struct sphin_surface {
struct sphin* sphin;
struct darray_geometry geometries; /* dynamic array of struct geometry. see
rsys/dynamic_array.h */
- struct brdf* brdf;
+ struct sphin_brdf brdf;
ref_T ref;
};
@@ -66,6 +66,7 @@ surface_create
ref_init(&surface->ref);
SPHIN(ref_get(sphin));
surface->sphin = sphin;
+ surface->brdf = SPHIN_BRDF_NULL;
str_init(sphin->allocator, &surface->name);
res = str_set(&surface->name, name);
@@ -142,8 +143,8 @@ parse_brdf
/* Parse brdf type */
brdf_type = strtok_r(value, " \t", &token_ptr);
if (NULL == brdf_type){ res = RES_BAD_ARG; goto error; }
- if (0 == strcmp(brdf_type, "LAMBERT")){ surface->brdf->type = SPHIN_LAMBERT; }
- else if (0 == strcmp(brdf_type, "SPECULAR")){ surface->brdf->type = SPHIN_SPECULAR; }
+ if (0 == strcmp(brdf_type, "LAMBERT")){ surface->brdf.type = SPHIN_LAMBERT; }
+ else if (0 == strcmp(brdf_type, "SPECULAR")){ surface->brdf.type = SPHIN_SPECULAR; }
else { res = RES_BAD_ARG; goto error; }
/* Parse reflectivity value */
@@ -151,7 +152,16 @@ parse_brdf
res = cstr_to_double(str_reflectivity, &reflectivity);
if (RES_OK != res) { res = RES_BAD_ARG; goto error; }
if (reflectivity < 0 || reflectivity >1 ) { res = RES_BAD_ARG; goto error; }
- surface->brdf->reflectivity = reflectivity;
+
+ switch(surface->brdf.type) {
+ case SPHIN_LAMBERT:
+ surface->brdf.lambertian.reflectivity = reflectivity;
+ break;
+ case SPHIN_SPECULAR:
+ surface->brdf.specular.reflectivity = reflectivity;
+ break;
+ default: FATAL("Unreachable code\n"); break;
+ }
exit:
return res;
@@ -201,11 +211,14 @@ parse_surface
if (NULL == token){ res = RES_BAD_ARG; goto error; }
value = token;
if (0 == strcmp(keyword, "geometry")){
- res = parse_geometry(surface, txtrdr, value);
+ res = parse_geometry(surface, txtrdr, value);
}
else if (0 == strcmp(keyword, "brdf")){
- res = parse_brdf(surface, txtrdr, value);
+ res = parse_brdf(surface, txtrdr, value);
}
+ /*else if (0 == strcmp(keyword, "source")) {
+ res = parse_source(surface->sphin, txtrdr, &surface->source);
+ }*/
else {
break;
}
@@ -239,3 +252,15 @@ sphin_surface_ref_put(struct sphin_surface* surface)
ref_put(&surface->ref, release_surface);
return RES_OK;
}
+
+res_T
+sphin_surface_get_brdf
+ (const struct sphin_surface* surface,
+ struct sphin_brdf* brdf)
+{
+ if(NULL == surface || NULL ==brdf) {
+ return RES_BAD_ARG;
+ }
+ *brdf = surface->brdf;
+ return RES_OK;
+}
diff --git a/src/sphin_volume.c b/src/sphin_volume.c
@@ -209,6 +209,9 @@ parse_volume
break;
}
}
+
+ /* TODO add the volume to the config */
+
exit:
str_release(&line);
return res;