mrumtl

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

commit 3259d80973fb7e0f561cd9e401bae3c8497a8169
parent ef5e5669e9e765c0b6079f25735de493cf802785
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  8 Jul 2022 12:24:02 +0200

Add the test_mrumtl_load program

Diffstat:
Mcmake/CMakeLists.txt | 5+----
Asrc/test_mrumtl_load.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -86,10 +86,7 @@ if(NOT NO_TEST) new_test(test_mrumtl_wlens) new_test(test_mrumtl_bands) - if(CMAKE_COMPILER_IS_GNUCC) - target_link_libraries(test_mrumtl_wlens m) - target_link_libraries(test_mrumtl_bands m) - endif() + build_test(test_mrumtl_load) endif() ################################################################################ diff --git a/src/test_mrumtl_load.c b/src/test_mrumtl_load.c @@ -0,0 +1,88 @@ +/* Copyright (C) 2020, 2021, 2022 |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/>. */ + +#include "mrumtl.h" +#include <rsys/mem_allocator.h> + +static void +check_brdf_lambertian(const struct mrumtl_brdf* brdf) +{ + struct mrumtl_brdf_lambertian lambertian = MRUMTL_BRDF_LAMBERTIAN_NULL; + + CHK(mrumtl_brdf_get_lambertian(brdf, &lambertian) == RES_OK); + + /* !NaN */ + CHK(lambertian.wavelengths[0] == lambertian.wavelengths[0]); + CHK(lambertian.wavelengths[1] == lambertian.wavelengths[1]); + CHK(lambertian.reflectivity = lambertian.reflectivity); + + CHK(lambertian.wavelengths[0] <= lambertian.wavelengths[1]); + CHK(0 <= lambertian.reflectivity && lambertian.reflectivity <= 1); +} + + +static void +check_brdf_specular(const struct mrumtl_brdf* brdf) +{ + struct mrumtl_brdf_specular specular = MRUMTL_BRDF_SPECULAR_NULL; + + CHK(mrumtl_brdf_get_specular(brdf, &specular) == RES_OK); + + /* !NaN */ + CHK(specular.wavelengths[0] == specular.wavelengths[0]); + CHK(specular.wavelengths[1] == specular.wavelengths[1]); + CHK(specular.reflectivity = specular.reflectivity); + + CHK(specular.wavelengths[0] <= specular.wavelengths[1]); + CHK(0 <= specular.reflectivity && specular.reflectivity <= 1); +} + +int +main(int argc, char** argv) +{ + struct mrumtl_create_args args = MRUMTL_CREATE_ARGS_DEFAULT; + struct mrumtl* mrumtl = NULL; + int i; + (void)argc, (void)argv; + + args.verbose = 1; + CHK(mrumtl_create(&args, &mrumtl) == RES_OK); + + FOR_EACH(i, 1, argc) { + size_t ibrdf; + size_t nbrdfs; + + printf("Load %s\n", argv[i]); + CHK(mrumtl_load(mrumtl, argv[i]) == RES_OK); + + nbrdfs = mrumtl_get_brdfs_count(mrumtl); + FOR_EACH(ibrdf, 0, nbrdfs) { + const struct mrumtl_brdf* brdf = mrumtl_get_brdf(mrumtl, ibrdf); + + switch(mrumtl_brdf_get_type(brdf)) { + case MRUMTL_BRDF_LAMBERTIAN: + check_brdf_lambertian(brdf); + break; + case MRUMTL_BRDF_SPECULAR: + check_brdf_specular(brdf); + break; + default: FATAL("Unreachable code\n"); break; + } + } + } + CHK(mrumtl_ref_put(mrumtl) == RES_OK); + CHK(mem_allocated_size() == 0); + return 0; +}