sgf_scene_c.h (2981B)
1 /* Copyright (C) 2021, 2024 |Meso|Star> (contact@meso-star.com) 2 * Copyright (C) 2015-2018 EDF S.A., France (syrthes-support@edf.fr) 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 SGF_SCENE_C_H 18 #define SGF_SCENE_C_H 19 20 #include <rsys/dynamic_array_double.h> 21 #include <rsys/ref_count.h> 22 #include <rsys/rsys.h> 23 24 struct s2d_scene; 25 struct s2d_shape; 26 struct s3d_scene; 27 struct s3d_shape; 28 struct sgf_device; 29 30 struct sgf_scene { 31 int dimensionality; 32 33 union { 34 struct { 35 struct s2d_scene* scn; 36 struct s2d_shape* shape; 37 struct s2d_scene_view* view; 38 } s2d; 39 struct { 40 struct s3d_scene* scn; 41 struct s3d_shape* shape; 42 struct s3d_scene_view* view; 43 } s3d; 44 } geometry; 45 46 struct darray_double abs; /* Per primitive absorption */ 47 struct darray_double emi; /* Per primitive emissivity */ 48 struct darray_double refl; /* Per primitive reflectivity */ 49 struct darray_double spec; /* Per primitive specularity */ 50 unsigned nprims; /* #primitives */ 51 unsigned nbands; /* #spectral bands */ 52 int has_medium; 53 54 ref_T ref; 55 struct sgf_device* dev; 56 }; 57 58 59 static FINLINE double 60 get_property__ 61 (const struct darray_double* property, 62 const size_t nprims, 63 const size_t nbands, 64 const size_t iprim, 65 const size_t iband) 66 { 67 size_t i; 68 ASSERT(iband < nbands && iprim < nprims && property); 69 (void)nbands; 70 i = iband * nprims + iprim; 71 ASSERT(i < darray_double_size_get(property)); 72 return darray_double_cdata_get(property)[i]; 73 } 74 75 static FINLINE double 76 scene_get_absorption 77 (const struct sgf_scene* scn, const size_t iprim, const size_t iband) 78 { 79 ASSERT(scn && scn->has_medium); 80 return get_property__(&scn->abs, scn->nprims, scn->nbands, iprim, iband); 81 } 82 83 static FINLINE double 84 scene_get_emissivity 85 (const struct sgf_scene* scn, const size_t iprim, const size_t iband) 86 { 87 ASSERT(scn); 88 return get_property__(&scn->emi, scn->nprims, scn->nbands, iprim, iband); 89 } 90 91 static FINLINE double 92 scene_get_reflectivity 93 (const struct sgf_scene* scn, const size_t iprim, const size_t iband) 94 { 95 ASSERT(scn); 96 return get_property__(&scn->refl, scn->nprims, scn->nbands, iprim, iband); 97 } 98 99 static FINLINE double 100 scene_get_specularity 101 (const struct sgf_scene* scn, const size_t iprim, const size_t iband) 102 { 103 ASSERT(scn); 104 return get_property__(&scn->spec, scn->nprims, scn->nbands, iprim, iband); 105 } 106 107 #endif /* SGF_SCENE_C_H */ 108