rngrd.h (6674B)
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 |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_create_bsdf_args { 101 struct s3d_primitive prim; /* Surface primitive to query */ 102 double barycentric_coords[3]; /* Position into and relative to `prim' */ 103 double wavelength; /* In nanometers */ 104 double r; /* Random number uniformly distributed in [0, 1[ */ 105 }; 106 #define RNGRD_CREATE_BSDF_ARGS_NULL__ {S3D_PRIMITIVE_NULL__, {0,0,0}, 0, 0} 107 static const struct rngrd_create_bsdf_args RNGRD_CREATE_BSDF_ARGS_NULL = 108 RNGRD_CREATE_BSDF_ARGS_NULL__; 109 110 struct rngrd_get_temperature_args { 111 struct s3d_primitive prim; /* Surface primitive to query */ 112 double barycentric_coords[3]; /* Position into and relative to `prim' */ 113 }; 114 #define RNGRD_GET_TEMPERATURE_ARGS_NULL__ {S3D_PRIMITIVE_NULL__, {0,0,0}} 115 static const struct rngrd_get_temperature_args RNGRD_GET_TEMPERATURE_ARGS_NULL = 116 RNGRD_GET_TEMPERATURE_ARGS_NULL__; 117 118 /* Opaque data types */ 119 struct rngrd; 120 121 BEGIN_DECLS 122 123 /******************************************************************************* 124 * API of the Rad-Net GRounD library 125 ******************************************************************************/ 126 RNGRD_API res_T 127 rngrd_create 128 (const struct rngrd_create_args* args, 129 struct rngrd** ground); 130 131 RNGRD_API res_T 132 rngrd_ref_get 133 (struct rngrd* ground); 134 135 RNGRD_API res_T 136 rngrd_ref_put 137 (struct rngrd* ground); 138 139 /* Validates ground data. Data checks have already been done on load, but this 140 * function performs longer tests: for example, it iterates over all surface 141 * properties to check their validity against the mesh they are associated with 142 * and the material list loaded */ 143 RNGRD_API res_T 144 rngrd_validate 145 (const struct rngrd* ground); 146 147 RNGRD_API res_T 148 rngrd_trace_ray 149 (const struct rngrd* ground, 150 struct rngrd_trace_ray_args* args, 151 struct s3d_hit* hit); 152 153 RNGRD_API res_T 154 rngrd_create_bsdf 155 (struct rngrd* ground, 156 const struct rngrd_create_bsdf_args* args, 157 struct ssf_bsdf** bsdf); 158 159 RNGRD_API res_T 160 rngrd_get_temperature 161 (const struct rngrd* ground, 162 const struct rngrd_get_temperature_args* args, 163 double* temperature); 164 165 RNGRD_API res_T 166 rngrd_get_temperature_range 167 (const struct rngrd* rngrd, 168 double T_range[2]); 169 170 END_DECLS 171 172 #endif /* RNGRD_H */