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 bd940db5a6c21743aa2f5e39e4589a7b43fa99b2
parent 12f153a9044ce5d888fa647e9c3603e6189ef787
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Mon, 17 Feb 2025 19:15:19 +0100

Implement `parse_brdf`

Diffstat:
Msrc/sphin.h | 6++++++
Asrc/sphin_brdf.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/sphin_brdf.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/sphin_surface.c | 35++++++++++++++++++++++++++++-------
4 files changed, 143 insertions(+), 7 deletions(-)

diff --git a/src/sphin.h b/src/sphin.h @@ -50,6 +50,12 @@ enum sphin_side { SPHIN_SIDE_NONE__ /* 2 */ }; +enum sphin_brdf_type { + SPHIN_LAMBERT, /* 0 */ + SPHIN_SPECULAR, /* 1 */ + SPHIN_BRDF_NONE__ /* 2 */ +}; + struct sphin_create_args { struct logger* logger; /* May be NULL <=> default logger */ struct mem_allocator* allocator; /* NULL <=> use default allocator */ diff --git a/src/sphin_brdf.c b/src/sphin_brdf.c @@ -0,0 +1,55 @@ +/* Copyright (C) 2024 Centre National de la Recherche Scientifique + * Copyright (C) 2024 Clermont Auvergne INP + * Copyright (C) 2024 INSA Lyon + * Copyright (C) 2024 Institut Mines Télécom Albi-Carmaux + * Copyright (C) 2024 Institut National Polytechnique de Toulouse + * Copyright (C) 2024 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2024 PhotonLyX (info@photonlyx.com) + * Copyright (C) 2024 Université de Lorraine + * Copyright (C) 2024 Université Paul Sabatier + * Copyright (C) 2024 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_brdf.h" + +/****************************************************************************** + * Local functions + ******************************************************************************/ +void +brdf_init + (struct mem_allocator* allocator, + struct brdf* brdf) +{ + ASSERT(NULL != brdf); + brdf->type= SPHIN_BRDF_NONE__; +} + +void +geometry_release + (struct brdf* geom) +{ +} + +res_T +brdf_copy + (struct brdf* dst, + const struct brdf* src) +{ + res_T res = RES_OK; + ASSERT(NULL != dst); + ASSERT(NULL != src); + dst->type = src->type; + return res; +} diff --git a/src/sphin_brdf.h b/src/sphin_brdf.h @@ -0,0 +1,54 @@ +/* Copyright (C) 2024 Centre National de la Recherche Scientifique + * Copyright (C) 2024 Clermont Auvergne INP + * Copyright (C) 2024 INSA Lyon + * Copyright (C) 2024 Institut Mines Télécom Albi-Carmaux + * Copyright (C) 2024 Institut National Polytechnique de Toulouse + * Copyright (C) 2024 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2024 PhotonLyX (info@photonlyx.com) + * Copyright (C) 2024 Université de Lorraine + * Copyright (C) 2024 Université Paul Sabatier + * Copyright (C) 2024 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_BRDF_H +#define SPHIN_BRDF_H + +#include "sphin.h" + +#include <rsys/rsys.h> + +struct mem_allocator; + +struct brdf { + enum sphin_brdf_type type; + double reflectivity; +}; + +extern LOCAL_SYM void +brdf_init + (struct mem_allocator* allocator, + struct brdf* brdf); + +extern LOCAL_SYM void +brdf_release + (struct brdf* brdf); + +extern LOCAL_SYM res_T +brdf_copy + (struct brdf* dst, + const struct brdf* src); + +#endif /* SPHIN_BRDF_H*/ diff --git a/src/sphin_surface.c b/src/sphin_surface.c @@ -24,6 +24,7 @@ #define _POSIX_C_SOURCE 200112L /* for strtok_r support */ #include "sphin.h" +#include "sphin_brdf.h" #include "sphin_c.h" #include "sphin_config.h" #include "sphin_geometry.h" @@ -123,14 +124,34 @@ error: goto exit; } - token = strtok_r(NULL, " ", &token_ptr); - if (NULL == token){ res = RES_BAD_ARG; goto error; } - res = str_set(&filename, trim_keyword(token)); - if (RES_OK != res) { goto error; } +static res_T +parse_brdf + (struct sphin_surface* surface, + struct txtrdr* txtrdr, + char* value) +{ + char* brdf_type; + char* str_reflectivity; + char* token_ptr; + double reflectivity; + res_T res = RES_OK; + + ASSERT(NULL != surface); + (void) txtrdr; /* Disable unused variable warning */ - str_copy(&geom.stl_filename, &filename); + /* 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; } + else { res = RES_BAD_ARG; goto error; } - /* TODO: Add geometry to surface->geometries */ + /* Parse reflectivity value */ + str_reflectivity = strtok_r(value, " \t", &token_ptr); + 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; exit: return res; @@ -183,7 +204,7 @@ parse_surface 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 { break;