sphor_sources.h (4071B)
1 /* Copyright (C) 2024-2026 Centre National de la Recherche Scientifique 2 * Copyright (C) 2024-2026 Clermont Auvergne INP 3 * Copyright (C) 2024-2026 INSA Lyon 4 * Copyright (C) 2024-2026 Institut Mines Télécom Albi-Carmaux 5 * Copyright (C) 2024-2026 Institut National Polytechnique de Toulouse 6 * Copyright (C) 2024-2026 |Méso|Star> (contact@meso-star.com) 7 * Copyright (C) 2024-2026 PhotonLyX (info@photonlyx.com) 8 * Copyright (C) 2024-2026 Université de Lorraine 9 * Copyright (C) 2024-2026 Université Paul Sabatier 10 * 11 * This program is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation, either version 3 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 23 24 #ifndef SPHOR_SOURCES_H 25 #define SPHOR_SOURCES_H 26 27 #include <star/s3d.h> 28 #include <star/ssp.h> 29 #include <rsys/dynamic_array.h> 30 #include <rsys/dynamic_array_size_t.h> 31 #include <rsys/rsys.h> 32 33 struct mem_allocator; 34 struct sphor; 35 struct sphor_create_args; 36 struct suniq; 37 38 struct source_view { 39 struct s3d_scene_view* view; /* View of the source */ 40 /* Map the prim id of a source to its prim in the scene */ 41 struct darray_size_t src2scn; 42 /* Normalized probability density function derived from emission spectrum */ 43 struct ssp_ranst_piecewise_linear* emission_spectrum_pdf; 44 45 size_t sphin_id; /* Surface identifier in star-phor-input */ 46 }; 47 48 #define SOURCE_VIEW_NULL__ {0} 49 static const struct source_view SOURCE_VIEW_NULL = SOURCE_VIEW_NULL__; 50 51 static INLINE void 52 source_init 53 (struct mem_allocator* allocator, 54 struct source_view* source) 55 { 56 ASSERT(NULL != allocator); 57 ASSERT(NULL != source); 58 59 *source = SOURCE_VIEW_NULL; 60 darray_size_t_init(allocator, &source->src2scn); 61 } 62 63 static INLINE void 64 source_release 65 (struct source_view* source) 66 { 67 ASSERT(NULL != source); 68 69 if (NULL != source->view) { 70 S3D(scene_view_ref_put(source->view)); 71 source->view = NULL; 72 } 73 if (NULL != source->emission_spectrum_pdf) { 74 SSP(ranst_piecewise_linear_ref_put(source->emission_spectrum_pdf)); 75 source->emission_spectrum_pdf = NULL; 76 } 77 darray_size_t_release(&source->src2scn); 78 } 79 80 static INLINE res_T 81 source_copy 82 (struct source_view* dst, 83 const struct source_view* src) 84 { 85 ASSERT(NULL != dst); 86 ASSERT(NULL != src); 87 88 dst->sphin_id = src->sphin_id; 89 S3D(scene_view_ref_get(src->view)); 90 dst->view = src->view; 91 if (src->emission_spectrum_pdf != NULL) { 92 SSP(ranst_piecewise_linear_ref_get(src->emission_spectrum_pdf)); 93 dst->emission_spectrum_pdf = src->emission_spectrum_pdf; 94 } 95 return darray_size_t_copy(&dst->src2scn, &src->src2scn); 96 } 97 98 static INLINE res_T 99 source_copy_and_release 100 (struct source_view* dst, 101 struct source_view* src) 102 { 103 ASSERT(NULL != dst); 104 ASSERT(NULL != src); 105 106 dst->sphin_id = src->sphin_id; 107 dst->view = src->view; 108 dst->emission_spectrum_pdf = src->emission_spectrum_pdf; 109 110 src->view = NULL; 111 src->emission_spectrum_pdf = NULL; 112 return darray_size_t_copy_and_release(&dst->src2scn, &src->src2scn); 113 } 114 115 /* Generate darray_source_view data type and API */ 116 #define DARRAY_NAME source_view 117 #define DARRAY_DATA struct source_view 118 #define DARRAY_FUNCTOR_INIT source_init 119 #define DARRAY_FUNCTOR_RELEASE source_release 120 #define DARRAY_FUNCTOR_COPY source_copy 121 #define DARRAY_FUNCTOR_COPY_AND_RELEASE source_copy_and_release 122 #include <rsys/dynamic_array.h> 123 124 extern LOCAL_SYM res_T 125 setup_source_views 126 (struct sphor* sphor, 127 const struct sphor_create_args* args, 128 struct suniq* suniq_scene); 129 130 extern LOCAL_SYM res_T 131 setup_source_distrib_power 132 (struct sphor* sphor, 133 const struct sphor_create_args* args); 134 135 #endif /* SPHOR_SOURCES_H */