schiff_mesh.h (4874B)
1 /* Copyright (C) 2015, 2016, 2026 Centre National de la Recherche Scientifique 2 * Copyright (C) 2026 Clermont Auvergne INP 3 * Copyright (C) 2026 Institut Mines Télécom Albi-Carmaux 4 * Copyright (C) 2017, 2019-2021, 2026 |Méso|Star> (contact@meso-star.com) 5 * Copyright (C) 2026 Université de Lorraine 6 * Copyright (C) 2026 Université de Toulouse 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 21 #ifndef SCHIFF_MESH_H 22 #define SCHIFF_MESH_H 23 24 #include <rsys/dynamic_array_float.h> 25 #include <rsys/dynamic_array_uint.h> 26 27 struct sin_cos { double angle, sinus, cosine; }; 28 29 #define DARRAY_NAME sincos 30 #define DARRAY_DATA struct sin_cos 31 #include <rsys/dynamic_array.h> 32 33 enum schiff_coordinates { 34 SCHIFF_NO_COORDINATE, /* No coordinate is setuped */ 35 SCHIFF_POLAR, 36 SCHIFF_CARTESIAN 37 }; 38 39 struct schiff_mesh { 40 enum schiff_coordinates coordinates; 41 union { 42 struct darray_float cartesian; 43 struct darray_uint polar; 44 } vertices; 45 struct darray_uint indices; 46 47 /* Used only by polar coordinates */ 48 struct darray_sincos thetas; /* List of thetas, cos(theta) , sin(theta) */ 49 struct darray_sincos phis; /* List of phis, cos(phi), sin(phi) */ 50 51 int is_init; 52 }; 53 54 extern LOCAL_SYM res_T 55 schiff_mesh_init_sphere 56 (struct mem_allocator* allocator, 57 struct schiff_mesh* mesh, 58 const unsigned nthetas); /* # discret points along 2PI */ 59 60 extern LOCAL_SYM res_T 61 schiff_mesh_init_sphere_polar 62 (struct mem_allocator* allocator, 63 struct schiff_mesh* mesh, 64 const unsigned nthetas); 65 66 extern LOCAL_SYM res_T 67 schiff_mesh_init_cylinder 68 (struct mem_allocator* allocator, 69 struct schiff_mesh* mesh, 70 const unsigned nslices); 71 72 /* Initialise the indices of the helical pipe. The vertices are still not 73 * defined. Use the schiff_mesh_setup_helical_pipe to define these data */ 74 extern LOCAL_SYM res_T 75 schiff_mesh_init_helical_pipe 76 (struct mem_allocator* allocator, 77 struct schiff_mesh* mesh, 78 const unsigned nsteps_helicoid, 79 const unsigned nsteps_circle); 80 81 extern LOCAL_SYM res_T 82 schiff_mesh_helical_pipe_create_vertices 83 (const struct schiff_mesh* mesh, 84 const double pitch, 85 const double height, 86 const double radius_helicoid, 87 const double radius_circle, 88 /* The 2 following attribs are assumed to be equal to attributes used by the 89 * init function */ 90 const unsigned nsteps_helicoid, 91 const unsigned nsteps_circle, 92 size_t* out_nvertices, 93 float** out_vertices); 94 95 extern LOCAL_SYM void 96 schiff_mesh_helical_pipe_destroy_vertices 97 (const struct schiff_mesh* mesh, 98 float* vertices); 99 100 extern LOCAL_SYM void 101 schiff_mesh_release 102 (struct schiff_mesh* mesh); 103 104 static INLINE void 105 schiff_mesh_get_indices 106 (const struct schiff_mesh* mesh, 107 const unsigned itri, 108 unsigned ids[3]) 109 { 110 const size_t i = itri * 3; 111 ASSERT(mesh); 112 ASSERT(darray_uint_size_get(&mesh->indices) % 3 == 0); 113 ASSERT(itri < darray_uint_size_get(&mesh->indices) / 3); 114 ids[0] = darray_uint_cdata_get(&mesh->indices)[i + 0]; 115 ids[1] = darray_uint_cdata_get(&mesh->indices)[i + 1]; 116 ids[2] = darray_uint_cdata_get(&mesh->indices)[i + 2]; 117 } 118 119 static INLINE void 120 schiff_mesh_get_cartesian_position 121 (const struct schiff_mesh* mesh, 122 const unsigned ivert, 123 float vertex[3]) 124 { 125 const size_t i = ivert * 3; 126 ASSERT(mesh && vertex && mesh->coordinates == SCHIFF_CARTESIAN); 127 ASSERT(darray_float_size_get(&mesh->vertices.cartesian) % 3 == 0); 128 ASSERT(ivert < darray_float_size_get(&mesh->vertices.cartesian) / 3); 129 vertex[0] = darray_float_cdata_get(&mesh->vertices.cartesian)[i + 0]; 130 vertex[1] = darray_float_cdata_get(&mesh->vertices.cartesian)[i + 1]; 131 vertex[2] = darray_float_cdata_get(&mesh->vertices.cartesian)[i + 2]; 132 } 133 134 static INLINE void 135 schiff_mesh_get_polar_position 136 (const struct schiff_mesh* mesh, 137 const unsigned ivert, 138 struct sin_cos angles[2]) 139 { 140 const size_t i = ivert * 2; 141 const unsigned* iangles; 142 ASSERT(mesh && angles && mesh->coordinates == SCHIFF_POLAR); 143 ASSERT(darray_uint_size_get(&mesh->vertices.polar) % 2 == 0); 144 ASSERT(ivert < darray_uint_size_get(&mesh->vertices.polar) / 2); 145 146 iangles = darray_uint_cdata_get(&mesh->vertices.polar) + i; 147 angles[0] = darray_sincos_cdata_get(&mesh->thetas)[iangles[0]]; 148 angles[1] = darray_sincos_cdata_get(&mesh->phis)[iangles[1]]; 149 } 150 151 #endif /* SBOX_SCHIFF_MESH_H */ 152