solstice.h (6896B)
1 /* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) 2 * Copyright (C) 2016-2018 CNRS 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #ifndef SOLSTICE_H 18 #define SOLSTICE_H 19 20 #include "receivers/srcvl.h" 21 #include "solstice_args.h" 22 23 #include <rsys/dynamic_array_double.h> 24 #include <rsys/hash_table.h> 25 #include <rsys/logger.h> 26 #include <rsys/mem_allocator.h> 27 #include <rsys/str.h> 28 29 /* Library symbol management */ 30 #if defined(SCORE_SHARED_BUILD) /* Build shared library */ 31 #define SCORE_API extern EXPORT_SYM 32 #elif defined(SCORE_STATIC) /* Use/build static library */ 33 #define SCORE_API extern LOCAL_SYM 34 #else /* Use shared library */ 35 #define SCORE_API extern IMPORT_SYM 36 #endif 37 struct solparser; 38 struct solstice_node; 39 struct ssol_device; 40 struct ssol_material; 41 struct ssol_object; 42 struct sanim_node; 43 44 struct solstice_receiver { 45 struct str name; 46 struct solstice_node* node; 47 enum srcvl_side side; 48 enum srcvl_pp_output per_primitive_output; 49 }; 50 51 static INLINE void 52 solstice_receiver_init 53 (struct mem_allocator* allocator, struct solstice_receiver* rcv) 54 { 55 ASSERT(rcv); 56 str_init(allocator, &rcv->name); 57 rcv->node = NULL; 58 rcv->side = SRCVL_FRONT_AND_BACK; 59 rcv->per_primitive_output = SRCVL_PP_NONE; 60 } 61 62 static INLINE void 63 solstice_receiver_release(struct solstice_receiver* rcv) 64 { 65 ASSERT(rcv); 66 str_release(&rcv->name); 67 } 68 69 static INLINE res_T 70 solstice_receiver_copy 71 (struct solstice_receiver* dst, 72 const struct solstice_receiver* src) 73 { 74 ASSERT(dst && src); 75 dst->node = src->node; 76 dst->side = src->side; 77 dst->per_primitive_output = src->per_primitive_output; 78 return str_copy(&dst->name, &src->name); 79 } 80 81 static INLINE res_T 82 solstice_receiver_copy_and_release 83 (struct solstice_receiver* dst, 84 struct solstice_receiver* src) 85 { 86 res_T res = RES_OK; 87 ASSERT(dst && src); 88 dst->node = src->node; 89 dst->side = src->side; 90 dst->per_primitive_output = src->per_primitive_output; 91 res = str_copy_and_release(&dst->name, &src->name); 92 if(res != RES_OK) return res; 93 solstice_receiver_release(src); 94 return RES_OK; 95 } 96 97 static INLINE size_t 98 cstr_hash(const char* const* key) 99 { 100 const char* str; 101 ASSERT(key); 102 str = *key; 103 return hash_fnv64(str, strlen(str)); 104 } 105 106 static INLINE char 107 cstr_eq(const char* const* a, const char* const* b) 108 { 109 ASSERT(a && b); 110 return strcmp(*a, *b) == 0; 111 } 112 113 struct solstice_primary { 114 struct solstice_node* node; 115 }; 116 117 #define DARRAY_NAME nodes 118 #define DARRAY_DATA struct solstice_node* 119 #include <rsys/dynamic_array.h> 120 121 #define HTABLE_NAME material 122 #define HTABLE_KEY size_t 123 #define HTABLE_DATA struct ssol_material* 124 #include <rsys/hash_table.h> 125 #include <rsys/dynamic_array.h> 126 127 #define HTABLE_NAME object 128 #define HTABLE_KEY size_t 129 #define HTABLE_DATA struct ssol_object* 130 #include <rsys/hash_table.h> 131 132 #define HTABLE_NAME anchor 133 #define HTABLE_KEY size_t 134 #define HTABLE_DATA struct solstice_node* 135 #include <rsys/hash_table.h> 136 137 #define DARRAY_NAME receiver 138 #define DARRAY_DATA struct solstice_receiver 139 #define DARRAY_FUNCTOR_INIT solstice_receiver_init 140 #define DARRAY_FUNCTOR_RELEASE solstice_receiver_release 141 #define DARRAY_FUNCTOR_COPY solstice_receiver_copy 142 #define DARRAY_FUNCTOR_COPY_AND_RELEASE solstice_receiver_copy_and_release 143 #include <rsys/dynamic_array.h> 144 145 #define HTABLE_NAME receiver 146 #define HTABLE_KEY const char* /* Pointer toward the name of the receiver */ 147 #define HTABLE_KEY_FUNCTOR_HASH cstr_hash 148 #define HTABLE_KEY_FUNCTOR_EQ cstr_eq 149 #define HTABLE_DATA size_t /* Index of the receiver */ 150 #include <rsys/hash_table.h> 151 152 #define HTABLE_NAME primary 153 #define HTABLE_KEY struct str 154 #define HTABLE_KEY_FUNCTOR_INIT str_init 155 #define HTABLE_KEY_FUNCTOR_RELEASE str_release 156 #define HTABLE_KEY_FUNCTOR_COPY str_copy 157 #define HTABLE_KEY_FUNCTOR_COPY_AND_RELEASE str_copy_and_release 158 #define HTABLE_KEY_FUNCTOR_EQ str_eq 159 #define HTABLE_KEY_FUNCTOR_HASH str_hash 160 #define HTABLE_DATA struct solstice_primary 161 #include <rsys/hash_table.h> 162 163 enum solstice_sun_dir_type { 164 SOLSTICE_SUN_DIR_SPHERICAL, 165 SOLSTICE_SUN_DIR_LOCATION_TIME 166 }; 167 168 169 enum solstice_sun_direction_algorithm { 170 SOLSTICE_SUN_DIRECTION_ALGORITHM_MEEUS, 171 SOLSTICE_SUN_DIRECTION_ALGORITHM_PSA 172 }; 173 struct solstice_location_time { 174 struct tm time; 175 double latitude, longitude; 176 }; 177 178 struct solstice_spherical { 179 double azimuth; /* In radians */ 180 double elevation; /* In radians */ 181 }; 182 183 struct solstice_sun_dir { 184 enum solstice_sun_dir_type type; 185 union { 186 struct solstice_spherical spherical; 187 struct solstice_location_time location_time; 188 } u; 189 }; 190 191 #define DARRAY_NAME sun_dir 192 #define DARRAY_DATA struct solstice_sun_dir 193 #include <rsys/dynamic_array.h> 194 195 struct solstice { 196 struct ssol_device* ssol; 197 struct ssol_scene* scene; 198 struct ssol_sun* sun; 199 struct ssol_atmosphere* atmosphere; 200 201 struct solparser* parser; 202 203 struct htable_material materials; 204 struct htable_object objects; 205 struct htable_anchor anchors; 206 struct htable_receiver receivers; 207 struct htable_primary primaries; 208 struct darray_nodes roots; 209 struct darray_nodes pivots; 210 struct ssol_material* mtl_virtual; /* Shared virtual material */ 211 212 /* List of receivers ordered as submitted by the receiver file */ 213 struct darray_receiver rcvs_list; 214 215 /* Rendering */ 216 struct ssol_camera* camera; 217 struct ssol_image* framebuffer; 218 enum solstice_args_render_mode render_mode; 219 double up[3]; 220 unsigned spp; /* #Samples per pixel */ 221 222 /* Dump geometry */ 223 enum solstice_args_dump_format dump_format; 224 enum solstice_args_dump_split_mode dump_split_mode; 225 226 /* Dump radiative paths mode */ 227 struct ssol_path_tracker path_tracker; 228 229 /* Sun directions, either a spherical dir or by location+time */ 230 struct darray_sun_dir sun_dirs; 231 enum ssol_sun_direction_algorithm sun_algorithm; 232 233 size_t nexperiments; /* # MC experiments */ 234 FILE* output; /* Output stream */ 235 int dump_paths; 236 237 /* Stream used to load/store RNG state */ 238 FILE* rng_state_input; 239 FILE* rng_state_output; 240 241 struct logger logger; 242 struct mem_allocator* allocator; 243 }; 244 245 SCORE_API res_T 246 solstice_init 247 (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */ 248 const struct solstice_args* args, 249 struct solstice* solstice); 250 251 SCORE_API void 252 solstice_release 253 (struct solstice* solstice); 254 255 SCORE_API res_T 256 solstice_run 257 (struct solstice* solstice); 258 259 #endif /* SOLSTICE_H */ 260