star-phor-input

File format for describing photoreactor configurations
git clone https://www.edstar.cnrs.fr/git/star-phor-input.git
Log | Files | Refs | README | LICENSE

commit ceda1f093bce8ca07861f661c86067b40febb55b
parent db820201ae9a8f31d402e242938b4fa4aeccd353
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Wed, 25 Feb 2026 18:39:20 +0100

Implement BTDF parsing and its public API

This commit adds support for parsing the new Bidirectional
Transmissivity Distribution Function (BTDF), recently introduced in the
configuration file specification. It also extends the public Sphin API
with new elements that allow clients to retrieve BTDF properties.

Since BTDF and BRDF are closely related concepts, the BTDF API (both
public and internal) was designed based on its reflectivity counterpart.

BRDF and BTDF tests were refactored and moved to a dedicated test file
as test_sphin_load_surface was becoming overly large.

Diffstat:
M.gitignore | 1+
MMakefile | 3+++
Msrc/sphin.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Asrc/sphin_btdf.c | 248+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/sphin_btdf.h | 39+++++++++++++++++++++++++++++++++++++++
Msrc/sphin_surface.c | 24++++++++++++++++++++++++
Asrc/test_sphin_load_brdf_btdf.c | 324+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_sphin_load_surface.c | 51---------------------------------------------------
8 files changed, 685 insertions(+), 51 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -16,6 +16,7 @@ sphin-lint sphin-lint.1 sphin.3 test_sphin +test_sphin_load_brdf_btdf test_sphin_load_geometry test_sphin_load_prop_rad test_sphin_load_source diff --git a/Makefile b/Makefile @@ -39,6 +39,7 @@ all: library tool tests SRC =\ src/sphin.c\ src/sphin_brdf.c\ + src/sphin_btdf.c\ src/sphin_config.c\ src/sphin_geometry.c\ src/sphin_prop_rad.c\ @@ -178,6 +179,7 @@ clean: clean_test clean_tool ################################################################################ TEST_SRC =\ src/test_sphin.c\ + src/test_sphin_load_brdf_btdf.c\ src/test_sphin_load_geometry.c\ src/test_sphin_load_prop_rad.c\ src/test_sphin_load_source.c\ @@ -229,6 +231,7 @@ $(TEST_OBJ): config.mk sphin-local.pc $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ test_sphin \ +test_sphin_load_brdf_btdf \ test_sphin_load_geometry \ test_sphin_load_prop_rad \ test_sphin_load_source \ diff --git a/src/sphin.h b/src/sphin.h @@ -63,6 +63,20 @@ enum sphin_brdf_reflectivity_type { SPHIN_BRDF_REFLECTIVITY_NONE__ }; +enum sphin_btdf_direction_distribution { + SPHIN_BTDF_DIRECTION_LAMBERT, + SPHIN_BTDF_DIRECTION_SNELL_DIELECTRIC, + SPHIN_BTDF_DIRECTION_KEEP_CURRENT_DIR, + SPHIN_BTDF_DIRECTION_NONE__ +}; + +enum sphin_btdf_transmissivity_type { + SPHIN_BTDF_TRANSMISSIVITY_TABULATED, + SPHIN_BTDF_TRANSMISSIVITY_FRESNEL_DIELECTRIC, + SPHIN_BTDF_TRANSMISSIVITY_FRESNEL_DIELECTRIC_CONDUCTOR, + SPHIN_BTDF_TRANSMISSIVITY_NONE__ +}; + enum sphin_photon_unit { SPHIN_PHOTON_UNIT_MOL, /* [mol] */ SPHIN_PHOTON_UNIT_JOULE, /* [J] */ @@ -207,6 +221,7 @@ static const struct sphin_spectral_property_descriptor struct sphin; /* Library handler */ struct sphin_config; /* Physical configuration */ struct sphin_brdf; +struct sphin_btdf; struct sphin_geometry; struct sphin_prop_rad; struct sphin_refractive_index; @@ -436,6 +451,11 @@ sphin_surface_get_brdf struct sphin_brdf** brdf); /* May be NULL <=> no brdf */ SPHIN_API res_T +sphin_surface_get_btdf + (const struct sphin_surface* surface, + struct sphin_btdf** btdf); /* May be NULL <=> no btdf */ + +SPHIN_API res_T sphin_surface_get_source (const struct sphin_surface* surface, struct sphin_source_surface** source_surface); /* May be NULL <=> no src */ @@ -504,6 +524,32 @@ sphin_brdf_get_reflectivity_value struct sphin_spectral_property** reflectivity); /******************************************************************************* + * API of the BTDF + ******************************************************************************/ +SPHIN_API res_T +sphin_btdf_ref_get + (struct sphin_btdf* btdf); + +SPHIN_API res_T +sphin_btdf_ref_put + (struct sphin_btdf* btdf); + +SPHIN_API res_T +sphin_btdf_get_direction_distribution +(struct sphin_btdf* btdf, + enum sphin_btdf_direction_distribution* direction_distribution); + +SPHIN_API res_T +sphin_btdf_get_transmissivity_type + (struct sphin_btdf* btdf, + enum sphin_btdf_transmissivity_type* transmissivity_type); + +SPHIN_API res_T +sphin_btdf_get_transmissivity_value + (struct sphin_btdf* btdf, /* Only for SPHIN_BTDF_TRANSMISSIVITY_CONSTANT */ + struct sphin_spectral_property** transmissivity); + +/******************************************************************************* * API of the sensor_volume ******************************************************************************/ SPHIN_API res_T diff --git a/src/sphin_btdf.c b/src/sphin_btdf.c @@ -0,0 +1,248 @@ +/* Copyright (C) 2024-2026 Centre National de la Recherche Scientifique + * Copyright (C) 2024-2026 Clermont Auvergne INP + * Copyright (C) 2024-2026 INSA Lyon + * Copyright (C) 2024-2026 Institut Mines Télécom Albi-Carmaux + * Copyright (C) 2024-2026 Institut National Polytechnique de Toulouse + * Copyright (C) 2024-2026 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2024-2026 PhotonLyX (info@photonlyx.com) + * Copyright (C) 2024-2026 Université de Lorraine + * Copyright (C) 2024-2026 Université Paul Sabatier + * Copyright (C) 2024-2026 Université Toulouse - Jean Jaurès + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#define _POSIX_C_SOURCE 200112L /* for strtok_r support */ + +#include "sphin.h" +#include "sphin_c.h" +#include "sphin_btdf.h" +#include "sphin_config.h" +#include "sphin_spectral_property.h" + +#include <rsys/cstr.h> +#include <rsys/mem_allocator.h> +#include <rsys/ref_count.h> +#include <rsys/rsys.h> +#include <rsys/text_reader.h> + +struct sphin_btdf { + enum sphin_btdf_direction_distribution direction_distribution; + enum sphin_btdf_transmissivity_type transmissivity_type; /* Constant, Frensel */ + struct sphin_spectral_property* transmissivity; /* Only used if reflectivity is + * a constant */ + struct sphin* sphin; + ref_T ref; +}; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static res_T +btdf_create + (struct sphin* sphin, + struct sphin_btdf** out_btdf) +{ + struct sphin_btdf* btdf = NULL; + res_T res = RES_OK; + + ASSERT(NULL != sphin); + ASSERT(NULL != out_btdf); + + btdf = MEM_CALLOC(sphin->allocator, 1, sizeof(struct sphin_btdf)); + if (NULL == btdf) { res = RES_MEM_ERR; goto error; } + ref_init(&btdf->ref); + SPHIN(ref_get(sphin)); + btdf->sphin = sphin; + btdf->transmissivity_type = SPHIN_BTDF_TRANSMISSIVITY_NONE__; + btdf->direction_distribution = SPHIN_BTDF_DIRECTION_NONE__; + btdf->transmissivity = NULL; + +exit: + *out_btdf = btdf; + return res; +error: + if (NULL != btdf) { + SPHIN(btdf_ref_put(btdf)); + btdf = NULL; + } + goto exit; +} + +static void +release_btdf + (ref_T* address) +{ + struct sphin_btdf* btdf = NULL; + struct sphin* sphin = NULL; + + ASSERT(NULL != address); + + btdf = CONTAINER_OF(address, struct sphin_btdf, ref); + sphin = btdf->sphin; + if (NULL != btdf->transmissivity) { + SPHIN(spectral_property_ref_put(btdf->transmissivity)); + } + MEM_RM(sphin->allocator, btdf); + SPHIN(ref_put(sphin)); +} + +/******************************************************************************* + * Local functions + ******************************************************************************/ +res_T +parse_btdf + (struct sphin* sphin, + struct txtrdr* txtrdr, + char* value, + struct sphin_btdf** out_btdf) +{ + char* btdf_type = NULL; + char* str_transmissivity = NULL; + char* token_ptr = NULL; + char* filename = NULL; + struct sphin_btdf* btdf = NULL; + res_T res = RES_OK; + + ASSERT(NULL != sphin); + ASSERT(NULL != txtrdr); + ASSERT(NULL != out_btdf); + + if (NULL == value) { res = RES_BAD_ARG; goto error; } + + res = btdf_create(sphin, &btdf); + if (RES_OK != res) { goto error; } + /* Parse btdf type */ + btdf_type = strtok_r(value, " \t", &token_ptr); + if (NULL == btdf_type){ res = RES_BAD_ARG; goto error; } + if (0 == strcmp(btdf_type, "LAMBERT")) { + btdf->direction_distribution = SPHIN_BTDF_DIRECTION_LAMBERT; + } + else if (0 == strcmp(btdf_type, "SNELL_DIELECTRIC")) { + btdf->direction_distribution = SPHIN_BTDF_DIRECTION_SNELL_DIELECTRIC; + } + else if (0 == strcmp(btdf_type, "KEEP_CURRENT_DIR")) { + btdf->direction_distribution = SPHIN_BTDF_DIRECTION_KEEP_CURRENT_DIR; + } + else { res = RES_BAD_ARG; goto error; } + + /* Parse transmissivity value */ + str_transmissivity = strtok_r(NULL, " \t", &token_ptr); + if (NULL == str_transmissivity){ res = RES_BAD_ARG; goto error; } + + if (0 == strcmp(str_transmissivity, "FRESNEL_DIELECTRIC")) { + btdf->transmissivity_type = SPHIN_BTDF_TRANSMISSIVITY_FRESNEL_DIELECTRIC; + } + else if (0 == strcmp(str_transmissivity, "FRESNEL_DIELECTRIC_CONDUCTOR")) { + btdf->transmissivity_type + = SPHIN_BTDF_TRANSMISSIVITY_FRESNEL_DIELECTRIC_CONDUCTOR; + } + else { + filename = trim_keyword(str_transmissivity); + if (NULL == filename) { res = RES_BAD_ARG; goto error; } + + res = parse_spectral_property(sphin, filename, &btdf->transmissivity); + if (RES_OK != res) { goto error; } + + btdf->transmissivity_type = SPHIN_BTDF_TRANSMISSIVITY_TABULATED; + } + + res = txtrdr_read_line(txtrdr); + if (RES_OK != res) { goto error; } + +exit: + *out_btdf = btdf; + return res; +error: + if (btdf != NULL){ + SPHIN(btdf_ref_put(btdf)); + btdf = NULL; + } + goto exit; +} + +/******************************************************************************* + * Exported functions + ******************************************************************************/ +res_T +sphin_btdf_ref_get + (struct sphin_btdf* btdf) +{ + if (NULL == btdf) { + return RES_BAD_ARG; + } + ref_get(&btdf->ref); + return RES_OK; +} + +res_T +sphin_btdf_ref_put + (struct sphin_btdf* btdf) +{ + if (NULL == btdf) { + return RES_BAD_ARG; + } + ref_put(&btdf->ref, release_btdf); + return RES_OK; +} + +res_T +sphin_btdf_get_direction_distribution + (struct sphin_btdf* btdf, + enum sphin_btdf_direction_distribution* direction_distribution) +{ + res_T res = RES_OK; + + if (NULL == btdf || NULL == direction_distribution) { + return RES_BAD_ARG; + } + + *direction_distribution = btdf->direction_distribution; + return res; +} + +res_T +sphin_btdf_get_transmissivity_type + (struct sphin_btdf* btdf, + enum sphin_btdf_transmissivity_type* transmissivity_type) +{ + res_T res = RES_OK; + + if (NULL == btdf || NULL == transmissivity_type) { + return RES_BAD_ARG; + } + + *transmissivity_type= btdf->transmissivity_type; + return res; +} + +res_T +sphin_btdf_get_transmissivity_value + (struct sphin_btdf* btdf, + struct sphin_spectral_property** transmissivity) +{ + res_T res = RES_OK; + + if (NULL == btdf || NULL == transmissivity) { + return RES_BAD_ARG; + } + + /* Not defined for Fresnel reflectivities types */ + if (SPHIN_BTDF_TRANSMISSIVITY_TABULATED != btdf->transmissivity_type) { + return RES_BAD_ARG; + } + + *transmissivity = btdf->transmissivity; + + return res; +} diff --git a/src/sphin_btdf.h b/src/sphin_btdf.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2024-2026 Centre National de la Recherche Scientifique + * Copyright (C) 2024-2026 Clermont Auvergne INP + * Copyright (C) 2024-2026 INSA Lyon + * Copyright (C) 2024-2026 Institut Mines Télécom Albi-Carmaux + * Copyright (C) 2024-2026 Institut National Polytechnique de Toulouse + * Copyright (C) 2024-2026 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2024-2026 PhotonLyX (info@photonlyx.com) + * Copyright (C) 2024-2026 Université de Lorraine + * Copyright (C) 2024-2026 Université Paul Sabatier + * Copyright (C) 2024-2026 Université Toulouse - Jean Jaurès + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SPHIN_BTDF_H +#define SPHIN_BTDF_H + +#include <rsys/rsys.h> + +struct txtrdr; + +extern LOCAL_SYM res_T +parse_btdf + (struct sphin* sphin, + struct txtrdr* txtrdr, + char* value, + struct sphin_btdf** out_btdf); + +#endif /* SPHIN_BTDF_H*/ diff --git a/src/sphin_surface.c b/src/sphin_surface.c @@ -25,6 +25,7 @@ #include "sphin.h" #include "sphin_brdf.h" +#include "sphin_btdf.h" #include "sphin_c.h" #include "sphin_config.h" #include "sphin_geometry.h" @@ -39,6 +40,7 @@ #include <rsys/text_reader.h> struct sphin_brdf; +struct sphin_btdf; struct sphin_sensor_surface; struct sphin_source_surface; @@ -46,6 +48,7 @@ struct sphin_surface { struct str name; struct sphin* sphin; struct sphin_brdf* brdf; + struct sphin_btdf* btdf; struct darray_sphin_geometry_ptr geometries; /* dynamic array of struct geometry. see rsys/dynamic_array.h */ struct sphin_sensor_surface* sensor_surface; @@ -78,6 +81,7 @@ surface_create SPHIN(ref_get(sphin)); surface->sphin = sphin; surface->brdf = NULL; + surface->btdf = NULL; surface->sensor_surface= NULL; surface->source_surface = NULL; @@ -104,6 +108,7 @@ release_surface size_t i, ngeometries; struct sphin* sphin = NULL; struct sphin_brdf* brdf = NULL; + struct sphin_btdf* btdf = NULL; struct sphin_geometry** geometries = NULL; struct sphin_sensor_surface* sensor_surface = NULL; struct sphin_source_surface* source_surface = NULL; @@ -129,6 +134,7 @@ release_surface sphin = surface->sphin; brdf = surface->brdf; + btdf = surface->btdf; sensor_surface = surface->sensor_surface; source_surface = surface->source_surface; MEM_RM(sphin->allocator, surface); @@ -141,6 +147,9 @@ release_surface if (NULL != brdf) { SPHIN(brdf_ref_put(brdf)); } + if (NULL != btdf) { + SPHIN(btdf_ref_put(btdf)); + } SPHIN(ref_put(sphin)); } @@ -220,6 +229,9 @@ parse_surface else if (0 == strcmp(keyword, "brdf")){ res = parse_brdf(surface->sphin, txtrdr, token, &surface->brdf); } + else if (0 == strcmp(keyword, "btdf")){ + res = parse_btdf(surface->sphin, txtrdr, token, &surface->btdf); + } else if (0 == strcmp(keyword, "source")) { /* source should not have a name. * strings are not allowed in the input file after the : @@ -322,6 +334,18 @@ sphin_surface_get_brdf } res_T +sphin_surface_get_btdf + (const struct sphin_surface* surface, + struct sphin_btdf** btdf) +{ + if (NULL == surface || NULL == btdf) { + return RES_BAD_ARG; + } + *btdf = surface->btdf; + return RES_OK; +} + +res_T sphin_surface_get_source (const struct sphin_surface* surface, struct sphin_source_surface** source_surface) diff --git a/src/test_sphin_load_brdf_btdf.c b/src/test_sphin_load_brdf_btdf.c @@ -0,0 +1,324 @@ +/* Copyright (C) 2024-2026 Centre National de la Recherche Scientifique + * Copyright (C) 2024-2026 Clermont Auvergne INP + * Copyright (C) 2024-2026 INSA Lyon + * Copyright (C) 2024-2026 Institut Mines Télécom Albi-Carmaux + * Copyright (C) 2024-2026 Institut National Polytechnique de Toulouse + * Copyright (C) 2024-2026 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2024-2026 PhotonLyX (info@photonlyx.com) + * Copyright (C) 2024-2026 Université de Lorraine + * Copyright (C) 2024-2026 Université Paul Sabatier + * Copyright (C) 2024-2026 Université Toulouse - Jean Jaurès + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "sphin.h" + +#include <rsys/math.h> +#include <rsys/mem_allocator.h> +#include <rsys/rsys.h> + +#include <stdio.h> +#include <string.h> + +struct sphin; + +static void +write_stl_test_files + (void) +{ + FILE* file; + static const char* test0 = + "solid\n" + " facet normal 0.0 -1.0 0.0\n" + " outer loop\n" + " vertex 0.0 0.0 0.0\n" + " vertex 1.0 0.0 0.0\n" + " vertex 0.0 0.0 1.0\n" + " endloop\n" + " endfacet\n" + "endsolid"; + static const char* test1 = + "solid my_solid\n" + "endsolid my_solid\n"; + static const char* test2 = /* Bad geometry => sstl should return + RES_BAD_ARG */ + "solid\n" + " facet normal 0.0 -1.0 0.0\n" + " outer loop\n" + " vertex 0.0 0.0 0.0\n" + " vertex 1.0 0.0\n" + " vertex 0.0 0.0 1.0\n" + " endloop\n" + " endfacet\n" + "endsolid"; + static const char* test3 = /* Noisy geometry => sstl should accept it */ + "solid my_solid\n" + "\n" + " facet normal 0.0 -1.0 0.0\n" + " outer loop hophophophophop\n" + " vertex\t 0.0 0.0 0.0\n" + " vertex 1.0 0.0 0.0 \taaa\n" + " vertex 0.0 0.0\t 1.0\n" + " endloop \n" + " endfacet \t\t\t noise\n" + "endsolid pouet\n"; + file = fopen("test_0.stl", "w"); + CHK(file != NULL); + fwrite(test0, sizeof(char), strlen(test0), file); + fclose(file); + file = fopen("test_1.stl", "w"); + CHK(file != NULL); + fwrite(test1, sizeof(char), strlen(test1), file); + fclose(file); + file = fopen("test_2.stl", "w"); + CHK(file != NULL); + fwrite(test2, sizeof(char), strlen(test2), file); + fclose(file); + file = fopen("test_3.stl", "w"); + CHK(file != NULL); + fwrite(test3, sizeof(char), strlen(test3), file); + fclose(file); +} + +static void +write_spec_rad_test_files + (void) +{ + FILE* file; + static const char* test0 = + "100 1\n" + "200 2\n" + "300 3\n" + "400 4\n"; + file = fopen("spectral_property.txt", "w"); + CHK(file != NULL); + fwrite(test0, sizeof(char), strlen(test0), file); + fclose(file); +} + +static void +test_brdf_btdf_api + (struct sphin* sphin) +{ + const char* path = "file.txt"; + enum sphin_brdf_direction_distribution brdf_dir_dist + = SPHIN_BRDF_DIRECTION_NONE__; + enum sphin_brdf_reflectivity_type reflectivity_type + = SPHIN_BRDF_REFLECTIVITY_NONE__; + enum sphin_btdf_direction_distribution btdf_dir_dist + = SPHIN_BTDF_DIRECTION_NONE__; + enum sphin_btdf_transmissivity_type transmissivity_type + = SPHIN_BTDF_TRANSMISSIVITY_NONE__; + struct sphin_brdf* brdf = NULL; + struct sphin_btdf* btdf = NULL; + struct sphin_config* config = NULL; + struct sphin_surface* surface = NULL; + struct sphin_spectral_property* spec_prop; + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "\t\t surface : \"surface\"\n"); + fprintf(fp, "\tbrdf: LAMBERT spectral_property.txt # my comment\n"); + fprintf(fp, "\tbtdf: LAMBERT spectral_property.txt # my comment\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\n"); + + fprintf(fp, "surface: \"other surface\"\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\n"); + fprintf(fp, "\tbrdf\t : SPECULAR FRESNEL_DIELECTRIC_CONDUCTOR \n"); + fprintf(fp, "\tbtdf\t : KEEP_CURRENT_DIR FRESNEL_DIELECTRIC_CONDUCTOR\n"); + + fprintf(fp, "surface: \"yet another surface\"\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\n"); + fprintf(fp, "\tbrdf\t : SPECULAR FRESNEL_DIELECTRIC \n"); + fprintf(fp, "\tbtdf\t : SNELL_DIELECTRIC FRESNEL_DIELECTRIC \t \n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_OK); + /* Test surface 0 */ + CHK(sphin_config_get_surface(config, 0, &surface) == RES_OK); + /* Test brdf */ + CHK(sphin_surface_get_brdf(NULL, NULL) == RES_BAD_ARG); + 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_direction_distribution(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_get_direction_distribution(NULL, &brdf_dir_dist) == RES_BAD_ARG); + CHK(sphin_brdf_get_direction_distribution(brdf, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_get_direction_distribution(brdf, &brdf_dir_dist) == RES_OK); + CHK(brdf_dir_dist == SPHIN_BRDF_DIRECTION_LAMBERT); + CHK(sphin_brdf_get_reflectivity_type(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_get_reflectivity_type(NULL, &reflectivity_type) == RES_BAD_ARG); + CHK(sphin_brdf_get_reflectivity_type(brdf, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_get_reflectivity_type(brdf, &reflectivity_type) == RES_OK); + CHK(reflectivity_type == SPHIN_BRDF_REFLECTIVITY_TABULATED); + CHK(sphin_brdf_get_reflectivity_value(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_get_reflectivity_value(brdf, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_get_reflectivity_value(NULL, &spec_prop) == RES_BAD_ARG); + CHK(sphin_brdf_get_reflectivity_value(brdf, &spec_prop) == RES_OK); + /* Test btdf */ + CHK(sphin_surface_get_btdf(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_surface_get_btdf(surface, NULL) == RES_BAD_ARG); + CHK(sphin_surface_get_btdf(NULL, &btdf) == RES_BAD_ARG); + CHK(sphin_surface_get_btdf(surface, &btdf) == RES_OK); + CHK(sphin_btdf_get_direction_distribution(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_btdf_get_direction_distribution(NULL, &btdf_dir_dist) == RES_BAD_ARG); + CHK(sphin_btdf_get_direction_distribution(btdf, NULL) == RES_BAD_ARG); + CHK(sphin_btdf_get_direction_distribution(btdf, &btdf_dir_dist) == RES_OK); + CHK(btdf_dir_dist == SPHIN_BTDF_DIRECTION_LAMBERT); + CHK(sphin_btdf_get_transmissivity_type(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_btdf_get_transmissivity_type(NULL, &transmissivity_type) == RES_BAD_ARG); + CHK(sphin_btdf_get_transmissivity_type(btdf, NULL) == RES_BAD_ARG); + CHK(sphin_btdf_get_transmissivity_type(btdf, &transmissivity_type) == RES_OK); + CHK(transmissivity_type == SPHIN_BTDF_TRANSMISSIVITY_TABULATED); + CHK(sphin_btdf_get_transmissivity_value(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_btdf_get_transmissivity_value(btdf, NULL) == RES_BAD_ARG); + CHK(sphin_btdf_get_transmissivity_value(NULL, &spec_prop) == RES_BAD_ARG); + CHK(sphin_btdf_get_transmissivity_value(btdf, &spec_prop) == RES_OK); + + /* Test surface 1 */ + CHK(sphin_config_get_surface(config, 1, &surface) == RES_OK); + /* Test brdf */ + CHK(sphin_surface_get_brdf(surface, &brdf) == RES_OK); + CHK(sphin_brdf_get_direction_distribution(brdf, &brdf_dir_dist) == RES_OK); + CHK(brdf_dir_dist == SPHIN_BRDF_DIRECTION_SPECULAR); + CHK(sphin_brdf_get_reflectivity_type(brdf, &reflectivity_type) == RES_OK); + CHK(reflectivity_type + == SPHIN_BRDF_REFLECTIVITY_FRESNEL_DIELECTRIC_CONDUCTOR); + CHK(sphin_brdf_get_reflectivity_value(brdf, &spec_prop) == RES_BAD_ARG); + CHK(sphin_brdf_ref_get(brdf) == RES_OK); + CHK(sphin_brdf_ref_put(brdf) == RES_OK); + /* Test btdf */ + CHK(sphin_surface_get_btdf(surface, &btdf) == RES_OK); + CHK(sphin_btdf_get_direction_distribution(btdf, &btdf_dir_dist) == RES_OK); + CHK(btdf_dir_dist == SPHIN_BTDF_DIRECTION_KEEP_CURRENT_DIR); + CHK(sphin_btdf_get_transmissivity_type(btdf, &transmissivity_type) == RES_OK); + CHK(transmissivity_type + == SPHIN_BTDF_TRANSMISSIVITY_FRESNEL_DIELECTRIC_CONDUCTOR); + CHK(sphin_btdf_get_transmissivity_value(btdf, &spec_prop) == RES_BAD_ARG); + CHK(sphin_btdf_ref_get(btdf) == RES_OK); + CHK(sphin_btdf_ref_put(btdf) == RES_OK); + + /* Test surface 2 */ + CHK(sphin_config_get_surface(config, 2, &surface) == RES_OK); + /* Test brdf */ + CHK(sphin_surface_get_brdf(surface, &brdf) == RES_OK); + CHK(sphin_brdf_get_direction_distribution(brdf, &brdf_dir_dist) == RES_OK); + CHK(brdf_dir_dist == SPHIN_BRDF_DIRECTION_SPECULAR); + CHK(sphin_brdf_get_reflectivity_type(brdf, &reflectivity_type) == RES_OK); + CHK(reflectivity_type == SPHIN_BRDF_REFLECTIVITY_FRESNEL_DIELECTRIC); + CHK(sphin_brdf_get_reflectivity_value(brdf, &spec_prop) == RES_BAD_ARG); + /* Test btdf */ + CHK(sphin_surface_get_btdf(surface, &btdf) == RES_OK); + CHK(sphin_btdf_get_direction_distribution(btdf, &btdf_dir_dist) == RES_OK); + CHK(btdf_dir_dist == SPHIN_BTDF_DIRECTION_SNELL_DIELECTRIC); + CHK(sphin_btdf_get_transmissivity_type(btdf, &transmissivity_type) == RES_OK); + CHK(transmissivity_type == SPHIN_BTDF_TRANSMISSIVITY_FRESNEL_DIELECTRIC); + CHK(sphin_btdf_get_transmissivity_value(btdf, &spec_prop) == RES_BAD_ARG); + + CHK(sphin_config_ref_put(config) == RES_OK); +} + +static void +test_load_brdf_bad_type + (struct sphin* sphin) +{ + struct sphin_config* config = NULL; + const char* path = "file.txt"; + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "#Mot Clé Nom\n"); + fprintf(fp, " surface\t: \"tube_walls\" blabla\n"); + fprintf(fp, "\tbrdf\t : SPETACULAR 0.5\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +static void +test_load_brdf_bad_value + (struct sphin* sphin) +{ + struct sphin_config* config = NULL; + const char* path = "file.txt"; + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "#Mot Clé Nom\n"); + fprintf(fp, " surface\t: \"tube_walls\" blabla\n"); + fprintf(fp, "\tbrdf\t : SPECULAR x\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +static void +test_load_btdf_bad_type + (struct sphin* sphin) +{ + struct sphin_config* config = NULL; + const char* path = "file.txt"; + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "#Mot Clé Nom\n"); + fprintf(fp, " surface\t: \"tube_walls\" blabla\n"); + fprintf(fp, "\tbtdf\t : CHANGE_DIR spec_file.txt\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +static void +test_load_btdf_bad_value + (struct sphin* sphin) +{ + struct sphin_config* config = NULL; + const char* path = "file.txt"; + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "#Mot Clé Nom\n"); + fprintf(fp, " surface\t: \"tube_walls\" blabla\n"); + fprintf(fp, "\tbtdf\t : SNELL_DIELECTRIC x\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +int +main(int argc, char** argv) +{ + struct sphin* sphin = NULL; + struct sphin_create_args args = SPHIN_CREATE_ARGS_DEFAULT; + + (void)argc; + (void)argv; + + args.verbose = 1; + sphin_create(&args, &sphin); + + write_stl_test_files(); + write_spec_rad_test_files(); + test_brdf_btdf_api(sphin); + test_load_brdf_bad_type(sphin); + test_load_brdf_bad_value(sphin); + test_load_btdf_bad_type(sphin); + test_load_btdf_bad_value(sphin); + + CHK(sphin_ref_put(sphin) == RES_OK); + + CHK(mem_allocated_size() == 0); + return 0; +} diff --git a/src/test_sphin_load_surface.c b/src/test_sphin_load_surface.c @@ -116,8 +116,6 @@ test_surface_api double area, power, response_function; enum sphin_brdf_direction_distribution dir_dist = SPHIN_BRDF_DIRECTION_NONE__; - enum sphin_brdf_reflectivity_type reflectivity_type - = SPHIN_BRDF_REFLECTIVITY_NONE__; size_t nsurfaces; struct sphin_brdf* brdf = NULL; struct sphin_config* config = NULL; @@ -159,19 +157,6 @@ test_surface_api CHK(sphin_surface_get_name(NULL, &name) == RES_BAD_ARG); CHK(sphin_surface_get_name(surface, &name) == RES_OK); CHK(strcmp(name, "tube walls") == 0); - CHK(sphin_surface_get_brdf(NULL, NULL) == RES_BAD_ARG); - 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_direction_distribution(NULL, NULL) == RES_BAD_ARG); - CHK(sphin_brdf_get_direction_distribution(NULL, &dir_dist) == RES_BAD_ARG); - CHK(sphin_brdf_get_direction_distribution(brdf, NULL) == RES_BAD_ARG); - CHK(sphin_brdf_get_direction_distribution(brdf, &dir_dist) == RES_OK); - CHK(dir_dist == SPHIN_BRDF_DIRECTION_LAMBERT); - CHK(sphin_brdf_get_reflectivity_type(NULL, NULL) == RES_BAD_ARG); - CHK(sphin_brdf_get_reflectivity_type(NULL, &reflectivity_type) == RES_BAD_ARG); - CHK(sphin_brdf_get_reflectivity_type(brdf, NULL) == RES_BAD_ARG); - CHK(sphin_brdf_get_reflectivity_type(brdf, &reflectivity_type) == RES_OK); /* Test surface 1 */ CHK(sphin_config_get_surface(config, 1, &surface) == RES_OK); @@ -205,40 +190,6 @@ test_surface_api } static void -test_surface_api_bad_brdf_key - (struct sphin* sphin) -{ - struct sphin_config* config = NULL; - const char* path = "file.txt"; - FILE* fp = NULL; - - CHK(fp = fopen(path, "w+")); - fprintf(fp, "#Mot Clé Nom\n"); - fprintf(fp, " surface\t: \"tube_walls\" blabla\n"); - fprintf(fp, "\tbrdf\t : SPETACULAR 0.5\n"); - fclose(fp); - - CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); -} - -static void -test_surface_api_bad_brdf_value - (struct sphin* sphin) -{ - struct sphin_config* config = NULL; - const char* path = "file.txt"; - FILE* fp = NULL; - - CHK(fp = fopen(path, "w+")); - fprintf(fp, "#Mot Clé Nom\n"); - fprintf(fp, " surface\t: \"tube_walls\" blabla\n"); - fprintf(fp, "\tbrdf\t : SPECULAR x\n"); - fclose(fp); - - CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); -} - -static void test_surface_api_bad_name (struct sphin* sphin) { @@ -286,8 +237,6 @@ main(int argc, char** argv) write_stl_test_files(); write_spec_rad_test_files(); test_surface_api(sphin); - test_surface_api_bad_brdf_key(sphin); - test_surface_api_bad_brdf_value(sphin); test_surface_api_bad_name(sphin); test_surface_api_bad_geometry(sphin);