mrumtl

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

mrumtl.h (5027B)


      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 #ifndef MRUMTL_H
     17 #define MRUMTL_H
     18 
     19 #include <rsys/rsys.h>
     20 
     21 /* Library symbol management */
     22 #if defined(MRUMTL_SHARED_BUILD) /* Build shared library */
     23   #define MRUMTL_API extern EXPORT_SYM
     24 #elif defined(MRUMTL_STATIC) /* Use/build static library */
     25   #define MRUMTL_API extern LOCAL_SYM
     26 #else /* Use shared library */
     27   #define MRUMTL_API extern IMPORT_SYM
     28 #endif
     29 
     30 /* Helper macro that asserts if the invocation of the mrumtl function `Func'
     31  * returns an error. One should use this macro on mrumtl function calls for
     32  * which no explicit error checking is performed */
     33 #ifndef NDEBUG
     34   #define MRUMTL(Func) ASSERT(mrumtl_ ## Func == RES_OK)
     35 #else
     36   #define MRUMTL(Func) mrumtl_ ## Func
     37 #endif
     38 
     39 /* Forward declaration of external data types */
     40 struct logger;
     41 struct mem_allocator;
     42 
     43 enum mrumtl_brdf_type {
     44   MRUMTL_BRDF_LAMBERTIAN,
     45   MRUMTL_BRDF_SPECULAR,
     46   MRUMTL_BRDF_NONE__
     47 };
     48 
     49 struct mrumtl_create_args {
     50   struct logger* logger; /* NULL <=> use default logger */
     51   struct mem_allocator* allocator; /* NULL <=> use default allocator */
     52   int verbose; /* Verbosity level */
     53 };
     54 #define MRUMTL_CREATE_ARGS_DEFAULT__ {NULL, NULL, 0}
     55 static const struct mrumtl_create_args MRUMTL_CREATE_ARGS_DEFAULT =
     56   MRUMTL_CREATE_ARGS_DEFAULT__;
     57 
     58 /* Specular BRDF */
     59 struct mrumtl_brdf_specular {
     60   double wavelengths[2]; /* Inclusive wavelength range in nanometers */
     61   double reflectivity;
     62 };
     63 #define MRUMTL_BRDF_SPECULAR_NULL__ {0}
     64 static const struct mrumtl_brdf_specular MRUMTL_BRDF_SPECULAR_NULL =
     65   MRUMTL_BRDF_SPECULAR_NULL__;
     66 
     67 /* Lambertian BRDF */
     68 struct mrumtl_brdf_lambertian {
     69   double wavelengths[2]; /* Inclusive wavelength range in nanometers */
     70   double reflectivity;
     71 };
     72 #define MRUMTL_BRDF_LAMBERTIAN_NULL__ {0}
     73 static const struct mrumtl_brdf_lambertian MRUMTL_BRDF_LAMBERTIAN_NULL =
     74   MRUMTL_BRDF_LAMBERTIAN_NULL__;
     75 
     76 /* Forward declaration of opaque data types */
     77 struct mrumtl;
     78 struct mrumtl_brdf;
     79 
     80 BEGIN_DECLS
     81 
     82 /*******************************************************************************
     83  * MRUMTL API
     84  ******************************************************************************/
     85 MRUMTL_API res_T
     86 mrumtl_create
     87   (const struct mrumtl_create_args* args,
     88    struct mrumtl** mrumtl);
     89 
     90 MRUMTL_API res_T
     91 mrumtl_ref_get
     92   (struct mrumtl* mrumtl);
     93 
     94 MRUMTL_API res_T
     95 mrumtl_ref_put
     96   (struct mrumtl* mrumtl);
     97 
     98 MRUMTL_API res_T /* Clean up the previously loaded material */
     99 mrumtl_load
    100   (struct mrumtl* mrumtl,
    101    const char* path);
    102 
    103 MRUMTL_API res_T /* Clean up the previously created material */
    104 mrumtl_load_stream
    105   (struct mrumtl* mrumtl,
    106    FILE* stream,
    107    const char* stream_name); /* May be NULL */
    108 
    109 MRUMTL_API size_t
    110 mrumtl_get_brdfs_count
    111   (const struct mrumtl* mrumtl);
    112 
    113 MRUMTL_API const struct mrumtl_brdf*
    114 mrumtl_get_brdf
    115   (const struct mrumtl* mrumtl,
    116    const size_t ibrdf);
    117 
    118 MRUMTL_API enum mrumtl_brdf_type
    119 mrumtl_brdf_get_type
    120   (const struct mrumtl_brdf* brdf);
    121 
    122 MRUMTL_API res_T
    123 mrumtl_brdf_get_lambertian
    124   (const struct mrumtl_brdf* brdf,
    125    struct mrumtl_brdf_lambertian* lambertian);
    126 
    127 MRUMTL_API res_T
    128 mrumtl_brdf_get_specular
    129   (const struct mrumtl_brdf* brdf,
    130    struct mrumtl_brdf_specular* specular);
    131 
    132 /* Fetch a BRDF with respect to the submitted wavelength and the given sample.
    133  * The BRDF is chosen according to the alpha coefficient between [0, 1] defined
    134  * as below:
    135  *
    136  *    alpha = (lambda1 - wavelength) / (lambda1 - lambda0)
    137  *
    138  * with lambda0 < lambda1, the BRDF wavelengths surrounding the submitted
    139  * wavelength. The index returned refers to the BRDF corresponding to lambda0
    140  * or lambda1 depending on whether the given sample is less than or greater
    141  * than alpha, respectively.
    142  *
    143  * If the BRDF are stored by spectral band, lambda0 and lambda1 are the upper
    144  * boundary of the lower band and the lower boundary of the upper band,
    145  * respectively, which surround the wavelength. If the wavelength is in a
    146  * specific band, the index for that band is simply returned.
    147  *
    148  * If the wavelength is outside the domain, the index returned refers to either
    149  * the first or the last BRDF depending on whether the wavelength is below or
    150  * above the domain, respectively. */
    151 MRUMTL_API res_T
    152 mrumtl_fetch_brdf
    153   (const struct mrumtl* mrumtl,
    154    const double wavelength,
    155    const double sample, /* In [0, 1[ */
    156    size_t* ibrdf);
    157 
    158 END_DECLS
    159 
    160 #endif /* MRUMTL_H */
    161