rngrd

Describe a surface and its physical properties
git clone git://git.meso-star.com/rngrd.git
Log | Files | Refs | README | LICENSE

rngrd.h (7677B)


      1 /* Copyright (C) 2022, 2023, 2025 Centre National de la Recherche Scientifique
      2  * Copyright (C) 2022, 2023, 2025 Institut Pierre-Simon Laplace
      3  * Copyright (C) 2022, 2023, 2025 Institut de Physique du Globe de Paris
      4  * Copyright (C) 2022, 2023, 2025, 2026 |Méso|Star> (contact@meso-star.com)
      5  * Copyright (C) 2022, 2023, 2025 Observatoire de Paris
      6  * Copyright (C) 2022, 2023, 2025 Université de Reims Champagne-Ardenne
      7  * Copyright (C) 2022, 2023, 2025 Université de Versaille Saint-Quentin
      8  * Copyright (C) 2022, 2023, 2025 Université Paul Sabatier
      9  *
     10  * This program is free software: you can redistribute it and/or modify
     11  * it under the terms of the GNU General Public License as published by
     12  * the Free Software Foundation, either version 3 of the License, or
     13  * (at your option) any later version.
     14  *
     15  * This program is distributed in the hope that it will be useful,
     16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     18  * GNU General Public License for more details.
     19  *
     20  * You should have received a copy of the GNU General Public License
     21  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     22 
     23 #ifndef RNGRD_H
     24 #define RNGRD_H
     25 
     26 #include <star/s3d.h>
     27 
     28 #include <rsys/rsys.h>
     29 
     30 /* Library symbol management */
     31 #if defined(RNGRD_SHARED_BUILD) /* Build shared library */
     32   #define RNGRD_API extern EXPORT_SYM
     33 #elif defined(RNGRD_STATIC) /* Use/build static library */
     34   #define RNGRD_API extern LOCAL_SYM
     35 #else /* Use shared library */
     36   #define RNGRD_API extern IMPORT_SYM
     37 #endif
     38 
     39 /* Helper macro that asserts if the invocation of the rngrd function `Func'
     40  * returns an error. One should use this macro on suvm function calls for
     41  * which no explicit error checking is performed */
     42 #ifndef NDEBUG
     43   #define RNGRD(Func) ASSERT(rngrd_ ## Func == RES_OK)
     44 #else
     45   #define RNGRD(Func) rngrd_ ## Func
     46 #endif
     47 
     48 /* Forward declaration of external data types */
     49 struct logger;
     50 struct mem_allocator;
     51 struct ssf_bsdf;
     52 
     53 struct rngrd_create_args {
     54   const char* smsh_filename; /* The Star-Mesh geometry */
     55   const char* props_filename; /* Per triangle physical properties */
     56   const char* mtllst_filename; /* List of used materials */
     57   const char* name; /* Name of the ground */
     58 
     59   struct logger* logger; /* NULL <=> use default logger */
     60   struct mem_allocator* allocator; /* NULL <=> use default allocator */
     61   int verbose; /* Verbosity level */
     62 };
     63 #define RNGRD_CREATE_ARGS_DEFAULT__ {                                          \
     64   NULL, /* Star-Mesh geometry */                                               \
     65   NULL, /* Per-triangle properties */                                          \
     66   NULL, /* List of used materials */                                           \
     67   "ground geometry", /* Name */                                                \
     68                                                                                \
     69   NULL, /* Logger */                                                           \
     70   NULL, /* Allocator */                                                        \
     71   0 /* Verbosity level */                                                      \
     72 }
     73 static const struct rngrd_create_args RNGRD_CREATE_ARGS_DEFAULT =
     74   RNGRD_CREATE_ARGS_DEFAULT__;
     75 
     76 struct rngrd_trace_ray_args {
     77   double ray_org[3]; /* Ray origin */
     78   double ray_dir[3]; /* Ray direction */
     79   double ray_range[2]; /* Ray range */
     80 
     81   /* Intersection from which the ray starts. Used to avoid self intersection */
     82   struct s3d_hit hit_from;
     83 
     84   s3d_hit_filter_function_T filter; /* NULL <=> Stop RT at 1st hit triangle */
     85   void* filter_data; /* User data send to the filter function */
     86 };
     87 #define RNGRD_TRACE_RAY_ARGS_DEFAULT__ {                                       \
     88   {0,0,0}, /* Ray origin */                                                    \
     89   {0,0,1}, /* Ray direction */                                                 \
     90   {0,DBL_MAX}, /* Ray range */                                                 \
     91                                                                                \
     92   S3D_HIT_NULL__, /* Hit from */                                               \
     93                                                                                \
     94   NULL, /* Filter function */                                                  \
     95   NULL /* Filter data */                                                       \
     96 }
     97 static const struct rngrd_trace_ray_args RNGRD_TRACE_RAY_ARGS_DEFAULT =
     98   RNGRD_TRACE_RAY_ARGS_DEFAULT__;
     99 
    100 struct rngrd_closest_point_args {
    101   double position[3];
    102   double radius; /* Search radius around the position */
    103 
    104   s3d_hit_filter_function_T filter; /* NULL <=> Return closest triangle */
    105   void* filter_data; /* User data send to the filter function */
    106 };
    107 #define RNGRD_CLOSEST_POINT_ARGS_DEFAULT__ {                                   \
    108   {0,0,0}, /* Position */                                                      \
    109   DBL_MAX, /* Radius */                                                        \
    110                                                                                \
    111   NULL, /* Filter function */                                                  \
    112   NULL /* Filter data */                                                       \
    113 }
    114 static const struct rngrd_closest_point_args
    115 RNGRD_CLOSEST_POINT_ARGS_DEFAULT = RNGRD_CLOSEST_POINT_ARGS_DEFAULT__;
    116 
    117 struct rngrd_create_bsdf_args {
    118   struct s3d_primitive prim; /* Surface primitive to query */
    119   double barycentric_coords[3]; /* Position into and relative to `prim' */
    120   double wavelength; /* In nanometers */
    121   double r; /* Random number uniformly distributed in [0, 1[ */
    122 };
    123 #define RNGRD_CREATE_BSDF_ARGS_NULL__ {S3D_PRIMITIVE_NULL__, {0,0,0}, 0, 0}
    124 static const struct rngrd_create_bsdf_args RNGRD_CREATE_BSDF_ARGS_NULL =
    125   RNGRD_CREATE_BSDF_ARGS_NULL__;
    126 
    127 struct rngrd_get_temperature_args {
    128   struct s3d_primitive prim; /* Surface primitive to query */
    129   double barycentric_coords[3]; /* Position into and relative to `prim' */
    130 };
    131 #define RNGRD_GET_TEMPERATURE_ARGS_NULL__ {S3D_PRIMITIVE_NULL__, {0,0,0}}
    132 static const struct rngrd_get_temperature_args RNGRD_GET_TEMPERATURE_ARGS_NULL =
    133   RNGRD_GET_TEMPERATURE_ARGS_NULL__;
    134 
    135 /* Opaque data types */
    136 struct rngrd;
    137 
    138 BEGIN_DECLS
    139 
    140 /*******************************************************************************
    141  * API of the Rad-Net GRounD library
    142  ******************************************************************************/
    143 RNGRD_API res_T
    144 rngrd_create
    145   (const struct rngrd_create_args* args,
    146    struct rngrd** ground);
    147 
    148 RNGRD_API res_T
    149 rngrd_ref_get
    150   (struct rngrd* ground);
    151 
    152 RNGRD_API res_T
    153 rngrd_ref_put
    154   (struct rngrd* ground);
    155 
    156 /* Validates ground data. Data checks have already been done on load, but this
    157  * function performs longer tests: for example, it iterates over all surface
    158  * properties to check their validity against the mesh they are associated with
    159  * and the material list loaded */
    160 RNGRD_API res_T
    161 rngrd_validate
    162   (const struct rngrd* ground);
    163 
    164 RNGRD_API res_T
    165 rngrd_trace_ray
    166   (const struct rngrd* ground,
    167    struct rngrd_trace_ray_args* args,
    168    struct s3d_hit* hit);
    169 
    170 RNGRD_API res_T
    171 rngrd_closest_point
    172   (const struct rngrd* ground,
    173    struct rngrd_closest_point_args* args,
    174    struct s3d_hit* hit);
    175 
    176 RNGRD_API res_T
    177 rngrd_create_bsdf
    178   (struct rngrd* ground,
    179    const struct rngrd_create_bsdf_args* args,
    180    struct ssf_bsdf** bsdf);
    181 
    182 RNGRD_API res_T
    183 rngrd_get_temperature
    184   (const struct rngrd* ground,
    185    const struct rngrd_get_temperature_args* args,
    186    double* temperature);
    187 
    188 RNGRD_API res_T
    189 rngrd_get_temperature_range
    190   (const struct rngrd* rngrd,
    191    double T_range[2]);
    192 
    193 END_DECLS
    194 
    195 #endif /* RNGRD_H */