sgs_geometry.h (4591B)
1 /* Copyright (C) 2021-2023 Centre National de la Recherche Scientifique 2 * Copyright (C) 2021-2023 INSA Lyon 3 * Copyright (C) 2021-2023 Institut Mines Télécom Albi-Carmaux 4 * Copyright (C) 2021-2023 |Méso|Star> (contact@meso-star.com) 5 * Copyright (C) 2021-2023 Institut Pascal 6 * Copyright (C) 2021-2023 PhotonLyX (info@photonlyx.com) 7 * Copyright (C) 2021-2023 Université de Lorraine 8 * Copyright (C) 2021-2023 Université Paul Sabatier 9 * Copyright (C) 2021-2023 Université Toulouse - Jean Jaurès 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 SGS_GEOMETRY_H 25 #define SGS_GEOMETRY_H 26 27 #include <star/s3d.h> 28 #include <rsys/rsys.h> 29 30 enum sgs_surface_type { 31 SGS_SURFACE_X_MIN = BIT(0), /* -X face */ 32 SGS_SURFACE_X_MAX = BIT(1), /* +X face */ 33 SGS_SURFACE_Y_MIN = BIT(2), /* -Y face */ 34 SGS_SURFACE_Y_MAX = BIT(3), /* +Y face */ 35 SGS_SURFACE_Z_MIN = BIT(4), /* -Z face */ 36 SGS_SURFACE_Z_MAX = BIT(5), /* +Z face */ 37 SGS_SURFACE_NONE = 0 38 }; 39 40 /* A simple axis-aligned bounding box whose top face is translated by pi 41 * 42 * o--------o 43 * / / 44 * . . .o--------o 45 * ^ 46 * Z pi o--------u upper 47 * ^ Y | /| /| 48 * |/ . . .o--------o | 49 * o--> X | ' | | 50 * | o......|.o 51 * |. |/ 52 * lower l--------o 53 */ 54 struct sgs_geometry_box_args { 55 double lower[3]; /* Lower bound */ 56 double upper[3]; /* Upper bound */ 57 double pi; 58 int sampling_mask; /* Surface that can be uniformly sampled */ 59 }; 60 #define SGS_GEOMETRY_BOX_ARGS_DEFAULT__ {{0,0,0}, {1,1,1}, 0, SGS_SURFACE_Z_MAX} 61 static const struct sgs_geometry_box_args SGS_GEOMETRY_BOX_ARGS_DEFAULT = 62 SGS_GEOMETRY_BOX_ARGS_DEFAULT__; 63 64 /* Position onto a geometry surface */ 65 struct sgs_fragment { 66 double normal[3]; /* Normalized */ 67 double position[3]; 68 enum sgs_surface_type surface; /* Surface to which the fragment belongs */ 69 70 }; 71 #define SGS_FRAGMENT_NULL__ {{0,0,0},{0,0,0},0} 72 static const struct sgs_fragment SGS_FRAGMENT_NULL = SGS_FRAGMENT_NULL__; 73 74 /* Intersection along a ray */ 75 struct sgs_hit { 76 double normal[3]; /* Normalized */ 77 double distance; /* Distance up to the intersection */ 78 enum sgs_surface_type surface; /* Surface to which the hit belongs */ 79 }; 80 #define SGS_HIT_NULL__ {{0,0,0},DBL_MAX,0} 81 static const struct sgs_hit SGS_HIT_NULL = SGS_HIT_NULL__; 82 83 /* Helper macro */ 84 #define SGS_HIT_NONE(Hit) ((Hit)->distance >= FLT_MAX) 85 86 /* Forward declarations */ 87 struct sgs; 88 struct sgs_geometry; 89 struct ssp_rng; 90 91 /******************************************************************************* 92 * Geometry API 93 ******************************************************************************/ 94 extern LOCAL_SYM res_T 95 sgs_geometry_box_create 96 (struct sgs* sgs, 97 const struct sgs_geometry_box_args* args, 98 struct sgs_geometry** geom); 99 100 extern LOCAL_SYM void 101 sgs_geometry_ref_get 102 (struct sgs_geometry* geom); 103 104 extern LOCAL_SYM void 105 sgs_geometry_ref_put 106 (struct sgs_geometry* geom); 107 108 extern LOCAL_SYM void 109 sgs_geometry_get_aabb 110 (const struct sgs_geometry* geom, 111 double low[3], 112 double upp[3]); 113 114 extern LOCAL_SYM int 115 sgs_geometry_get_sampling_mask 116 (const struct sgs_geometry* geom); 117 118 extern LOCAL_SYM double 119 sgs_geometry_compute_sampling_area 120 (const struct sgs_geometry* geom); 121 122 extern LOCAL_SYM void 123 sgs_geometry_trace_ray 124 (const struct sgs_geometry* geom, 125 const double ray_org[3], 126 const double ray_dir[3], 127 const double ray_range[2], 128 const enum sgs_surface_type surface_from, /* To avoid self hit */ 129 struct sgs_hit* hit); 130 131 /* Uniformly sample a point onto the faces of the geometry defined in the 132 * sampling_mask on geometry creation */ 133 extern LOCAL_SYM void 134 sgs_geometry_sample_sensitivity_source 135 (const struct sgs_geometry* geom, 136 struct ssp_rng* rng, 137 struct sgs_fragment* frag); 138 139 extern LOCAL_SYM res_T 140 sgs_geometry_dump_vtk 141 (const struct sgs_geometry* geom, 142 FILE* stream); 143 144 #endif /* SGS_GEOMETRY_H */