htsky

Load and structure a vertically stratified atmosphere
git clone git://git.meso-star.fr/htsky.git
Log | Files | Refs | README | LICENSE

htsky.h (8204B)


      1 /* Copyright (C) 2018, 2019, 2020, 2021 |Méso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2018, 2019 Centre National de la Recherche Scientifique
      3  * Copyright (C) 2018, 2019 Université Paul Sabatier
      4  *
      5  * This program is free software: you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation, either version 3 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     17 
     18 #ifndef HTSKY_H
     19 #define HTSKY_H
     20 
     21 #include <rsys/rsys.h>
     22 #include <star/svx.h>
     23 #include <limits.h> /* UINT_MAX support */
     24 
     25 /* Library symbol management */
     26 #if defined(HTSKY_SHARED_BUILD) /* Build shared library */
     27   #define HTSKY_API extern EXPORT_SYM
     28 #elif defined(HTSKY_STATIC) /* Use/build static library */
     29   #define HTSKY_API extern LOCAL_SYM
     30 #else /* Use shared library */
     31   #define HTSKY_API extern IMPORT_SYM
     32 #endif
     33 
     34 #ifndef NDEBUG
     35   #define HTSKY(Func) ASSERT(htsky_ ## Func == RES_OK)
     36 #else
     37   #define HTSKY(Func) htsky_ ## Func
     38 #endif
     39 
     40 enum htsky_property {
     41   HTSKY_Ks, /* Scattering coefficient */
     42   HTSKY_Ka, /* Absorption coefficient */
     43   HTSKY_Kext, /* Extinction coefficient = Ks + Ka */
     44   HTSKY_PROPS_COUNT__
     45 };
     46 
     47 /* List of sky components */
     48 enum htsky_component {
     49   HTSKY_CPNT_GAS,
     50   HTSKY_CPNT_PARTICLES,
     51   HTSKY_CPNTS_COUNT__
     52 };
     53 
     54 /* Component of the sky for which the properties are queried */
     55 enum htrdr_sky_component_flag {
     56   HTSKY_CPNT_FLAG_GAS = BIT(HTSKY_CPNT_GAS),
     57   HTSKY_CPNT_FLAG_PARTICLES = BIT(HTSKY_CPNT_PARTICLES),
     58   HTSKY_CPNT_MASK_ALL = HTSKY_CPNT_FLAG_GAS | HTSKY_CPNT_FLAG_PARTICLES
     59 };
     60 
     61 enum htsky_svx_op {
     62   HTSKY_SVX_MIN,
     63   HTSKY_SVX_MAX,
     64   HTSKY_SVX_OPS_COUNT__
     65 };
     66 
     67 enum htsky_spectral_type {
     68   HTSKY_SPECTRAL_LW, /* Longwave */
     69   HTSKY_SPECTRAL_SW, /* Shortwave */
     70   HTSKY_SPECTRAL_TYPES_COUNT__
     71 };
     72 
     73 struct htsky_args {
     74   const char* htcp_filename;
     75   const char* htgop_filename;
     76   const char* htmie_filename;
     77   const char* cache_filename; /* May be NULL <=> no cached data structure */
     78   const char* name; /* Name of the sky */
     79   enum htsky_spectral_type spectral_type;
     80   double wlen_range[2]; /* Spectral range to handle. In nm */
     81   unsigned grid_max_definition[3]; /* Maximum definition of the grid */
     82   double optical_thickness; /* Threshold used during octree building */
     83   unsigned nthreads; /* Hint on the number of threads to use */
     84   int repeat_clouds; /* Define if the clouds are infinitely repeated in X and Y */
     85   int verbose; /* Verbosity level */
     86 };
     87 
     88 #define HTSKY_ARGS_DEFAULT__ {                                                 \
     89   NULL, /* htcp_filename */                                                    \
     90   NULL, /* htgop_filename */                                                   \
     91   NULL, /* htmie filename */                                                   \
     92   NULL, /* cache filename */                                                   \
     93   "sky", /* Name */                                                            \
     94   HTSKY_SPECTRAL_TYPES_COUNT__, /* spectral type */                            \
     95   {DBL_MAX,-DBL_MAX}, /* Spectral integration range */                         \
     96   {UINT_MAX, UINT_MAX, UINT_MAX}, /* Maximum definition of the grid */         \
     97   1, /* Optical thickness */                                                   \
     98   (unsigned)~0, /* #threads */                                                 \
     99   0, /* Repeat clouds */                                                       \
    100   0 /* Verbosity level */                                                      \
    101 }
    102 static const struct htsky_args HTSKY_ARGS_DEFAULT = HTSKY_ARGS_DEFAULT__;
    103 
    104 /* Forward declarations of external data types */
    105 struct logger;
    106 struct mem_allocator;
    107 struct ssp_rng;
    108 struct svx_voxel;
    109 
    110 /* Opaque data type */
    111 struct htsky;
    112 
    113 BEGIN_DECLS
    114 
    115 /*******************************************************************************
    116  * HTSky API
    117  ******************************************************************************/
    118 HTSKY_API res_T
    119 htsky_create
    120   (struct logger* logger, /* NULL <=> use default logger */
    121    struct mem_allocator* allocator, /* NULL <=> use default allocator */
    122    const struct htsky_args* args,
    123    struct htsky** htsky);
    124 
    125 HTSKY_API res_T
    126 htsky_ref_get
    127   (struct htsky* htsky);
    128 
    129 HTSKY_API res_T
    130 htsky_ref_put
    131   (struct htsky* htsky);
    132 
    133 HTSKY_API const char*
    134 htsky_get_name
    135   (const struct htsky* htsky);
    136 
    137 HTSKY_API double
    138 htsky_fetch_particle_phase_function_asymmetry_parameter
    139   (const struct htsky* sky,
    140    const size_t ispectral_band,
    141    const size_t iquad);
    142 
    143 HTSKY_API double
    144 htsky_fetch_per_wavelength_particle_phase_function_asymmetry_parameter
    145   (const struct htsky* sky,
    146    const double wavelength); /* In nanometer */
    147 
    148 HTSKY_API double
    149 htsky_fetch_raw_property
    150   (const struct htsky* sky,
    151    const enum htsky_property prop,
    152    const int components_mask, /* Combination of htsky_component_flag */
    153    const size_t iband, /* Index of the spectral band */
    154    const size_t iquad, /* Index of the quadrature point in the spectral band */
    155    const double pos[3],
    156    /* For debug only. Assert if the fetched property is not in [k_min, k_max] */
    157    const double k_min,
    158    const double k_max);
    159 
    160 HTSKY_API double
    161 htsky_fetch_temperature
    162   (const struct htsky* sky,
    163    const double pos[3]);
    164 
    165 HTSKY_API double
    166 htsky_fetch_svx_property
    167   (const struct htsky* sky,
    168    const enum htsky_property prop,
    169    const enum htsky_svx_op op,
    170    const int components_mask, /* Combination of htsky_component_flag */
    171    const size_t iband, /* Index of the spectral band */
    172    const size_t iquad, /* Index of the quadrature point in the spectral band */
    173    const double pos[3]);
    174 
    175 HTSKY_API double
    176 htsky_fetch_svx_voxel_property
    177   (const struct htsky* sky,
    178    const enum htsky_property prop,
    179    const enum htsky_svx_op op,
    180    const int components_mask,
    181    const size_t ispectral_band, /* Index of the spectral band */
    182    const size_t iquad, /* Index of the quadrature point in the spectral band */
    183    const struct svx_voxel* voxel);
    184 
    185 HTSKY_API res_T
    186 htsky_trace_ray
    187   (struct htsky* sky,
    188    const double org[3],
    189    const double dir[3], /* Must be normalized */
    190    const double range[2],
    191    const svx_hit_challenge_T challenge, /* NULL <=> Traversed up to the leaves */
    192    const svx_hit_filter_T filter, /* NULL <=> Stop RT at the 1st hit voxel */
    193    void* context, /* Data sent to the filter functor */
    194    const size_t ispectral_band,
    195    const size_t iquadrature_pt,
    196    struct svx_hit* hit);
    197 
    198 HTSKY_API size_t
    199 htsky_get_spectral_bands_count
    200   (const struct htsky* sky);
    201 
    202 HTSKY_API size_t
    203 htsky_get_spectral_band_id
    204   (const struct htsky* sky,
    205    const size_t i);
    206 
    207 HTSKY_API size_t
    208 htsky_get_spectral_band_quadrature_length
    209   (const struct htsky* sky,
    210    const size_t iband);
    211 
    212 HTSKY_API res_T
    213 htsky_get_spectral_band_bounds
    214   (const struct htsky* sky,
    215    const size_t iband,
    216    double wavelengths[2]);
    217 
    218 /* Retrieve the spectral range of the loaded sky data overlapped by the user
    219  * defined wavelength range. */
    220 HTSKY_API res_T
    221 htsky_get_raw_spectral_bounds
    222   (const struct htsky* sky,
    223    double wavelengths[2]);
    224 
    225 HTSKY_API enum htsky_spectral_type
    226 htsky_get_spectral_type
    227   (const struct htsky* sky);
    228 
    229 /* Return the index of the band containing the submitted wavelength or SIZE_MAX
    230  * if `wavelength' is not included in any band */
    231 HTSKY_API size_t
    232 htsky_find_spectral_band
    233   (const struct htsky* sky,
    234    const double wavelength); /* In nanometer */
    235 
    236 /* Return the sampled quadrature point */
    237 HTSKY_API size_t
    238 htsky_spectral_band_sample_quadrature
    239   (const struct htsky* sky,
    240    const double r, /* Random number in [0, 1[ */
    241    const size_t ispectral_band);
    242 
    243 HTSKY_API res_T
    244 htsky_dump_cloud_vtk
    245   (const struct htsky* sky,
    246    const size_t iband, /* Index of the spectral band */
    247    const size_t iquad, /* Index of the quadrature point */
    248    FILE* stream);
    249 
    250 END_DECLS
    251 
    252 #endif /* HTSKY_H */
    253