mrumtl

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

test_mrumtl_load.c (2737B)


      1 /* Copyright (C) 2020-2023 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #include "mrumtl.h"
     17 #include <rsys/mem_allocator.h>
     18 
     19 static void
     20 check_brdf_lambertian(const struct mrumtl_brdf* brdf)
     21 {
     22   struct mrumtl_brdf_lambertian lambertian = MRUMTL_BRDF_LAMBERTIAN_NULL;
     23 
     24   CHK(mrumtl_brdf_get_lambertian(brdf, &lambertian) == RES_OK);
     25 
     26   /* !NaN */
     27   CHK(lambertian.wavelengths[0] == lambertian.wavelengths[0]);
     28   CHK(lambertian.wavelengths[1] == lambertian.wavelengths[1]);
     29   CHK(lambertian.reflectivity == lambertian.reflectivity);
     30 
     31   CHK(lambertian.wavelengths[0] <= lambertian.wavelengths[1]);
     32   CHK(0 <= lambertian.reflectivity && lambertian.reflectivity <= 1);
     33 }
     34 
     35 
     36 static void
     37 check_brdf_specular(const struct mrumtl_brdf* brdf)
     38 {
     39   struct mrumtl_brdf_specular specular = MRUMTL_BRDF_SPECULAR_NULL;
     40 
     41   CHK(mrumtl_brdf_get_specular(brdf, &specular) == RES_OK);
     42 
     43   /* !NaN */
     44   CHK(specular.wavelengths[0] == specular.wavelengths[0]);
     45   CHK(specular.wavelengths[1] == specular.wavelengths[1]);
     46   CHK(specular.reflectivity == specular.reflectivity);
     47 
     48   CHK(specular.wavelengths[0] <= specular.wavelengths[1]);
     49   CHK(0 <= specular.reflectivity && specular.reflectivity <= 1);
     50 }
     51 
     52 int
     53 main(int argc, char** argv)
     54 {
     55   struct mrumtl_create_args args = MRUMTL_CREATE_ARGS_DEFAULT;
     56   struct mrumtl* mrumtl = NULL;
     57   int i;
     58   (void)argc, (void)argv;
     59 
     60   args.verbose = 1;
     61   CHK(mrumtl_create(&args, &mrumtl) == RES_OK);
     62 
     63   FOR_EACH(i, 1, argc) {
     64     size_t ibrdf;
     65     size_t nbrdfs;
     66 
     67     printf("Load %s\n", argv[i]);
     68     CHK(mrumtl_load(mrumtl, argv[i]) == RES_OK);
     69 
     70     nbrdfs = mrumtl_get_brdfs_count(mrumtl);
     71     FOR_EACH(ibrdf, 0, nbrdfs) {
     72       const struct mrumtl_brdf* brdf = mrumtl_get_brdf(mrumtl, ibrdf);
     73 
     74       switch(mrumtl_brdf_get_type(brdf)) {
     75         case MRUMTL_BRDF_LAMBERTIAN:
     76           check_brdf_lambertian(brdf);
     77           break;
     78         case MRUMTL_BRDF_SPECULAR:
     79           check_brdf_specular(brdf);
     80           break;
     81         default: FATAL("Unreachable code\n"); break;
     82       }
     83     }
     84   }
     85   CHK(mrumtl_ref_put(mrumtl) == RES_OK);
     86   CHK(mem_allocated_size() == 0);
     87   return 0;
     88 }