mrumtl

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

commit d00d1088f08f0473f404fc1750e82743a9acd7bd
parent ff2435ff22ca67927aac42beb59e657ba32d15d3
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  3 Mar 2020 16:26:26 +0100

Remove the StarMTL bindings

Diffstat:
Mcmake/CMakeLists.txt | 18------------------
Dsrc/mrumtl_smtl.c | 189-------------------------------------------------------------------------------
Dsrc/mrumtl_smtl.h | 78------------------------------------------------------------------------------
Dsrc/test_mrumtl_smtl.c | 79-------------------------------------------------------------------------------
4 files changed, 0 insertions(+), 364 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -25,7 +25,6 @@ option(NO_TEST "Do not build tests" OFF) ################################################################################ find_package(RCMake 0.4 REQUIRED) find_package(RSys 0.9 REQUIRED) -find_package(StarMTL) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) include(rcmake) @@ -46,15 +45,6 @@ set(MRUMTL_FILES_INC ) set(MRUMTL_FILES_INC_API mrumtl.h) set(MRUMTL_FILES_DOC COPYING README.md) -if(NOT StarMTL_FOUND) - message(WARNING "Cannot find StarMTL. " - "Build the MruMtl library without the StarMTL binding.") -else() - set(MRUMTL_FILES_SRC ${MRUMTL_FILES_SRC} mrumtl_smtl.c) - set(MRUMTL_FILES_INC_API ${MRUMTL_FILES_INC_API} mrumtl_smtl.h) -endif() - - # Prepend each file in the `MRUMTL_FILES_<SRC|INC>' list by `MRUMTL_SOURCE_DIR' rcmake_prepend_path(MRUMTL_FILES_SRC ${MRUMTL_SOURCE_DIR}) rcmake_prepend_path(MRUMTL_FILES_INC ${MRUMTL_SOURCE_DIR}) @@ -95,14 +85,6 @@ 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_smtl.c b/src/mrumtl_smtl.c @@ -1,189 +0,0 @@ -/* 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 /* getopt support */ - -#include "mrumtl.h" -#include "mrumtl_smtl.h" - -#include <getopt.h> - -struct args { - const char* brdf_filename; - int verbose; -}; -static const struct args ARGS_NULL; - -/******************************************************************************* - * Helper functions - ******************************************************************************/ -static void -args_release(struct args* args) -{ - ASSERT(args); - *args = ARGS_NULL; -} - -static res_T -args_init(struct args* args, int argc, char** argv) -{ - int opt; - res_T res = RES_OK; - ASSERT(args); - - *args = ARGS_NULL; - - /* Reset the getopt global variables */ - optind = 0; - opterr = 0; - - while((opt = getopt(argc, argv, "b:v")) != -1) { - switch(opt) { - case 'b': args->brdf_filename = optarg; break; - case 'v': args->verbose = 1; break; - default: res = RES_BAD_ARG; break; - } - if(res != RES_OK) { - if(optarg) { - fprintf(stderr, "%s: invalid option argument '%s' -- '%c'\n", - argv[0], optarg, opt); - } - goto error; - } - } - - if(!args->brdf_filename) { - fprintf(stderr, - "%s: missing the no BRDF filename -- option '-b'\n", - argv[0]); - res = RES_BAD_ARG; - goto error; - } - -exit: - return res; -error: - args_release(args); - goto exit; -} - -/******************************************************************************* - * Exported functions - ******************************************************************************/ -res_T -smtl_program_init - (struct logger* logger, - struct mem_allocator* allocator, - int argc, - char** argv, - void** out_prog) -{ - struct args args = ARGS_NULL; - struct mrumtl* mrumtl = NULL; - res_T res = RES_OK; - - if(!argc || !argv || !out_prog) { - res = RES_BAD_ARG; - goto error; - } - - res = args_init(&args, argc, argv); - if(res != RES_OK) goto error; - - res = mrumtl_create(logger, allocator, args.verbose, &mrumtl); - if(res != RES_OK) goto error; - - res = mrumtl_load(mrumtl, args.brdf_filename); - if(res != RES_OK) goto error; - -exit: - args_release(&args); - if(out_prog) *out_prog = mrumtl; - return res; -error: - if(mrumtl) { - MRUMTL(ref_put(mrumtl)); - mrumtl = NULL; - } - goto exit; -} - -void -smtl_program_release(void* program) -{ - MRUMTL(ref_put(program)); -} - -enum smtl_mtl_type -smtl_program_get_mtl_type(void* program) -{ - (void)program; - return SMTL_MTL_OPAQUE; -} - -enum smtl_brdf_type -smtl_program_get_brdf_type - (void* program, - const double wavelength, - const struct smtl_fragment* frag) -{ - const struct mrumtl* mrumtl = program; - const struct mrumtl_brdf* brdf = NULL; - enum smtl_brdf_type type = SMTL_BRDF_NONE__; - (void)frag; - ASSERT(program && frag); - - MRUMTL(fetch_brdf(mrumtl, wavelength, &brdf)); - - switch(mrumtl_brdf_get_type(brdf)) { - case MRUMTL_BRDF_LAMBERTIAN: type = SMTL_BRDF_LAMBERTIAN; break; - case MRUMTL_BRDF_SPECULAR: type = SMTL_BRDF_SPECULAR; break; - default: FATAL("Unreachable code.\n"); break; - } - return type; -} - -double -smtl_program_brdf_lambert_get_reflectivity - (void* program, - const double wavelength, - const struct smtl_fragment* frag) -{ - const struct mrumtl* mrumtl = program; - const struct mrumtl_brdf* brdf = NULL; - (void)frag; - ASSERT(program && frag); - - MRUMTL(fetch_brdf(mrumtl, wavelength, &brdf)); - ASSERT(mrumtl_brdf_get_type(brdf) == MRUMTL_BRDF_LAMBERTIAN); - return mrumtl_brdf_lambertian_get_reflectivity(brdf); -} - -double -smtl_program_brdf_specular_get_reflectivity - (void* program, - const double wavelength, - const struct smtl_fragment* frag) -{ - const struct mrumtl* mrumtl = program; - const struct mrumtl_brdf* brdf = NULL; - (void)frag; - ASSERT(program && frag); - - MRUMTL(fetch_brdf(mrumtl, wavelength, &brdf)); - 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 @@ -1,78 +0,0 @@ -/* 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/>. */ - -#ifndef MRUMTL_SMTL_H -#define MRUMTL_SMTL_H - -#include <star/smtl.h> -#include <rsys/rsys.h> - -/* - * Usage: mrumtl [OPTION]... -b BRDF - * Manage the BRDF of a surface - * - * -b BRDF MruMtl file storing BRDF data - * -v make mrumtl verbose - */ - -BEGIN_DECLS - -/******************************************************************************* - * Common functions - ******************************************************************************/ -MRUMTL_API res_T -smtl_program_init - (struct logger* logger, /* NULL <=> use default logger */ - struct mem_allocator* allocator, /* NULL <=> use default allocator */ - int argc, - char* argv[], - void** out_prog); - -MRUMTL_API void -smtl_program_release - (void* program); - -/******************************************************************************* - * General material attribs - ******************************************************************************/ -MRUMTL_API enum smtl_mtl_type -smtl_program_get_mtl_type - (void* program); - -/******************************************************************************* - * BRDF attribs - ******************************************************************************/ -MRUMTL_API enum smtl_brdf_type -smtl_program_get_brdf_type - (void* program, - const double wavelength, - const struct smtl_fragment* frag); - -MRUMTL_API double -smtl_program_brdf_lambert_get_reflectivity - (void* program, - const double wavelength, - const struct smtl_fragment* frag); - -MRUMTL_API double -smtl_program_brdf_specular_get_reflectivity - (void* program, - const double wavelength, - const struct smtl_fragment* frag); - -END_DECLS - -#endif /* MRUMTL_SMTL_H */ - diff --git a/src/test_mrumtl_smtl.c b/src/test_mrumtl_smtl.c @@ -1,79 +0,0 @@ -/* 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; -} -