mrumtl

Describe materials that vary spectrally
git clone git://git.meso-star.fr/mrumtl.git
Log | Files | Refs | README | LICENSE

commit ff2435ff22ca67927aac42beb59e657ba32d15d3
parent bbd2ece72073444bb6c2378f22848acb13c0af88
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  3 Mar 2020 10:59:11 +0100

Test the SMTL binding

Diffstat:
Mcmake/CMakeLists.txt | 9++++++++-
Msrc/mrumtl.c | 26+++++++++-----------------
Msrc/mrumtl.h | 4----
Msrc/mrumtl_smtl.c | 10++--------
Msrc/mrumtl_smtl.h | 6+-----
Msrc/test_mrumtl.c | 2--
Asrc/test_mrumtl_smtl.c | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 99 insertions(+), 37 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -64,7 +64,6 @@ rcmake_prepend_path(MRUMTL_FILES_DOC ${PROJECT_SOURCE_DIR}/../) add_library(mrumtl SHARED ${MRUMTL_FILES_SRC} ${MRUMTL_FILES_INC} ${MRUMTL_FILES_INC_API}) target_link_libraries(mrumtl RSys) - set_target_properties(mrumtl PROPERTIES DEFINE_SYMBOL MRUMTL_SHARED_BUILD VERSION ${VERSION} @@ -96,6 +95,14 @@ if(NOT NO_TEST) target_link_libraries(test_mrumtl_band m) endif() + if(StarMTL_FOUND) + new_test(test_mrumtl_smtl) + target_link_libraries(test_mrumtl_smtl StarMTL) + if(CMAKE_COMPILER_IS_GNUCC) + target_link_libraries(test_mrumtl_smtl m) + endif() + endif() + endif() ################################################################################ diff --git a/src/mrumtl.c b/src/mrumtl.c @@ -75,7 +75,7 @@ struct mrumtl { enum brdf_list_type brdf_list_type; struct darray_brdf_wlen brdf_wlens; struct darray_brdf_band brdf_bands; - struct str name; + struct str name; /* Name of the loaded material */ int verbose; struct logger* logger; @@ -600,7 +600,10 @@ clear_mrumtl(struct mrumtl* mrumtl) } static res_T -load_stream(struct mrumtl* mrumtl, FILE* stream, const char* stream_name) +load_stream + (struct mrumtl* mrumtl, + FILE* stream, + const char* stream_name) { char* tk = NULL; char* tk_ctx = NULL; @@ -610,13 +613,6 @@ load_stream(struct mrumtl* mrumtl, FILE* stream, const char* stream_name) clear_mrumtl(mrumtl); - res = str_set(&mrumtl->name, stream_name); - if(res != RES_OK) { - log_err(mrumtl, "Could not copy the stream name `%s' -- %s.\n", - stream_name, res_to_cstr(res)); - goto error; - } - res = txtrdr_stream(mrumtl->allocator, stream, stream_name, '#', &txtrdr); if(res != RES_OK) { log_err(mrumtl, "Could not create the text reader to parse `%s' -- %s.\n", @@ -926,7 +922,10 @@ error: } res_T -mrumtl_load_stream(struct mrumtl* mrumtl, FILE* stream, const char* stream_name) +mrumtl_load_stream + (struct mrumtl* mrumtl, + FILE* stream, + const char* stream_name) { res_T res = RES_OK; @@ -944,13 +943,6 @@ error: goto exit; } -const char* -mrumtl_get_name(const struct mrumtl* mrumtl) -{ - ASSERT(mrumtl && !str_is_empty(&mrumtl->name)); - return str_cget(&mrumtl->name); -} - res_T mrumtl_fetch_brdf (const struct mrumtl* mrumtl, diff --git a/src/mrumtl.h b/src/mrumtl.h @@ -81,10 +81,6 @@ mrumtl_load_stream FILE* stream, const char* stream_name); /* May be NULL */ -MRUMTL_API const char* -mrumtl_get_name - (const struct mrumtl* mrumtl); - MRUMTL_API res_T mrumtl_fetch_brdf (const struct mrumtl* mrumtl, diff --git a/src/mrumtl_smtl.c b/src/mrumtl_smtl.c @@ -126,12 +126,6 @@ smtl_program_release(void* program) MRUMTL(ref_put(program)); } -const char* -smtl_program_get_mtl_name(void* program) -{ - return mrumtl_get_name(program); -} - enum smtl_mtl_type smtl_program_get_mtl_type(void* program) { @@ -162,7 +156,7 @@ smtl_program_get_brdf_type } double -smtl_program_brdf_lambertian_get_reflectivity +smtl_program_brdf_lambert_get_reflectivity (void* program, const double wavelength, const struct smtl_fragment* frag) @@ -189,7 +183,7 @@ smtl_program_brdf_specular_get_reflectivity ASSERT(program && frag); MRUMTL(fetch_brdf(mrumtl, wavelength, &brdf)); - ASSERT(mrumtl_brdf_get_type(brdf) == MRUMTL_BRDF_LAMBERTIAN); + ASSERT(mrumtl_brdf_get_type(brdf) == MRUMTL_BRDF_SPECULAR); return mrumtl_brdf_specular_get_reflectivity(brdf); } diff --git a/src/mrumtl_smtl.h b/src/mrumtl_smtl.h @@ -47,10 +47,6 @@ smtl_program_release /******************************************************************************* * General material attribs ******************************************************************************/ -MRUMTL_API const char* -smtl_program_get_mtl_name - (void* program); - MRUMTL_API enum smtl_mtl_type smtl_program_get_mtl_type (void* program); @@ -65,7 +61,7 @@ smtl_program_get_brdf_type const struct smtl_fragment* frag); MRUMTL_API double -smtl_program_brdf_lambertian_get_reflectivity +smtl_program_brdf_lambert_get_reflectivity (void* program, const double wavelength, const struct smtl_fragment* frag); diff --git a/src/test_mrumtl.c b/src/test_mrumtl.c @@ -64,7 +64,6 @@ main(int argc, char** argv) CHK(mrumtl_load(mrumtl, NULL) == RES_BAD_ARG); CHK(mrumtl_load(mrumtl, "undefined_file") == RES_IO_ERR); CHK(mrumtl_load(mrumtl, "my_mat.mrumtl") == RES_OK); - CHK(!strcmp(mrumtl_get_name(mrumtl), "my_mat.mrumtl")); CHK(mrumtl_ref_put(mrumtl) == RES_OK); rewind(fp); @@ -72,7 +71,6 @@ main(int argc, char** argv) CHK(mrumtl_load_stream(NULL, fp, NULL) == RES_BAD_ARG); CHK(mrumtl_load_stream(mrumtl, NULL, NULL) == RES_BAD_ARG); CHK(mrumtl_load_stream(mrumtl, fp, NULL) == RES_OK); - CHK(mrumtl_get_name(mrumtl) != NULL); CHK(mrumtl_ref_put(mrumtl) == RES_OK); diff --git a/src/test_mrumtl_smtl.c b/src/test_mrumtl_smtl.c @@ -0,0 +1,79 @@ +/* Copyright (C) 2020 |Meso|Star> (contact@meso-star.com) + * + * 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 + +#include "mrumtl.h" + +#include <rsys/mem_allocator.h> +#include <star/smtl.h> + +#include <math.h> +#include <string.h> + +int +main(int argc, char** argv) +{ + struct smtl_fragment frag = SMTL_FRAGMENT_NULL; + struct smtl* smtl = NULL; + struct smtl_material* mtl = NULL; + const struct smtl_brdf* brdf = NULL; + FILE* fp = NULL; + (void)argc, (void)argv; + + CHK(fp = fopen("brdf.mrumtl", "w")); + fprintf(fp, "bands 2\n"); + fprintf(fp, "380 780 lambertian 0.3\n"); + fprintf(fp, "1e3 100e3 specular 1e-1\n"); + fclose(fp); + + CHK(fp = fopen("my_mat.smtl", "w")); +#ifdef NDEBUG + fprintf(fp, "lib mrumtl ./libmrumtl.so\n"); +#else + fprintf(fp, "lib mrumtl ./libmrumtl-dbg.so\n"); +#endif + fprintf(fp, "prog my_prog mrumtl -b brdf.mrumtl -v\n"); + fprintf(fp, "mtl my_material opaque\n"); + fprintf(fp, "BRDF program my_prog\n"); + fclose(fp); + + CHK(smtl_create(NULL, NULL, 1, &smtl) == RES_OK); + CHK(smtl_load(smtl, "my_mat.smtl") == RES_OK); + + CHK(smtl_get_materials_count(smtl) == 1); + CHK(mtl = smtl_get_material(smtl, 0)); + CHK(!strcmp(smtl_material_get_name(mtl), "my_material")); + CHK(brdf = smtl_material_get_brdf(mtl)); + + CHK(smtl_brdf_get_type(brdf, 0, &frag) == SMTL_BRDF_LAMBERTIAN); + CHK(smtl_brdf_get_type(brdf, 380, &frag) == SMTL_BRDF_LAMBERTIAN); + CHK(smtl_brdf_get_type(brdf, 700, &frag) == SMTL_BRDF_LAMBERTIAN); + CHK(smtl_brdf_get_type(brdf, nextafter(890, 780), &frag) == SMTL_BRDF_LAMBERTIAN); + CHK(smtl_brdf_get_type(brdf, nextafter(890, 1e3), &frag) == SMTL_BRDF_SPECULAR); + CHK(smtl_brdf_get_type(brdf, 200e3, &frag) == SMTL_BRDF_SPECULAR); + + CHK(smtl_brdf_lambertian_get_reflectivity(brdf, 0, &frag) == 0.3); + CHK(smtl_brdf_lambertian_get_reflectivity(brdf, 380, &frag) == 0.3); + CHK(smtl_brdf_lambertian_get_reflectivity(brdf, 700, &frag) == 0.3); + CHK(smtl_brdf_lambertian_get_reflectivity(brdf, nextafter(890, 780), &frag) == 0.3); + CHK(smtl_brdf_specular_get_reflectivity(brdf, nextafter(890, 1e3), &frag) == 1e-1); + CHK(smtl_brdf_specular_get_reflectivity(brdf, 200e3, &frag) == 1e-1); + + CHK(smtl_ref_put(smtl) == RES_OK); + CHK(mem_allocated_size() == 0); + return 0; +} +