test_senc3d_cube_on_cube.c (4905B)
1 /* Copyright (C) 2018-2020, 2023, 2024 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 /* This test has been created using the sg3_geometry_dump_as_C_code feature 17 * of star-geometry. It uses output from test_sg3_cube_on_cube. */ 18 19 #define _POSIX_C_SOURCE 200112L /* snprintf */ 20 21 #include "senc3d.h" 22 #include "test_senc3d_utils.h" 23 24 #include <rsys/double3.h> 25 26 #include <stdio.h> 27 28 /* 29 +-----------------------+ 30 | 3 31 | +------+ | 32 m2 | m1 | m0 2 | 33 | | |--> N | 34 | +------+ | 35 | | m0 1 | 36 | | |--> N | 37 | +------+ | 38 |--> N | 39 +-----------------------+ 40 */ 41 42 /* Dump of star-geometry 'cube_on_cube'. */ 43 static const unsigned cube_on_cube_vertices_count = 20; 44 static const double cube_on_cube_vertices[60] = 45 { 46 1, 1, 2, 47 2, 1, 2, 48 1, 2, 2, 49 2, 2, 2, 50 1, 1, 3, 51 2, 1, 3, 52 1, 2, 3, 53 2, 2, 3, 54 1, 1, 1, 55 2, 1, 1, 56 1, 2, 1, 57 2, 2, 1, 58 0.4, 0, 0, 59 4, 0, 0, 60 0, 4, 0, 61 4, 4, 0, 62 0, 0, 4.4, 63 4, 0, 4, 64 0, 4, 4, 65 4, 4.4, 4 66 }; 67 static const unsigned cube_on_cube_triangles_count = 34; 68 static const unsigned cube_on_cube_triangles[102] = 69 { 70 0, 2, 1, 71 1, 2, 3, 72 0, 4, 2, 73 2, 4, 6, 74 4, 5, 6, 75 6, 5, 7, 76 3, 7, 1, 77 1, 7, 5, 78 2, 6, 3, 79 3, 6, 7, 80 0, 1, 4, 81 4, 1, 5, 82 8, 10, 9, 83 9, 10, 11, 84 8, 0, 10, 85 10, 0, 2, 86 11, 3, 9, 87 9, 3, 1, 88 10, 2, 11, 89 11, 2, 3, 90 8, 9, 0, 91 0, 9, 1, 92 12, 13, 14, 93 13, 15, 14, 94 12, 14, 16, 95 14, 18, 16, 96 16, 18, 17, 97 18, 19, 17, 98 15, 13, 19, 99 13, 17, 19, 100 14, 15, 18, 101 15, 19, 18, 102 12, 16, 13, 103 16, 17, 13 104 }; 105 static const unsigned cube_on_cube_properties[102] = 106 { 107 0, 0, 0, 108 0, 0, 0, 109 1, 0, 0, 110 1, 0, 0, 111 1, 0, 0, 112 1, 0, 0, 113 1, 0, 0, 114 1, 0, 0, 115 1, 0, 0, 116 1, 0, 0, 117 1, 0, 0, 118 1, 0, 0, 119 1, 0, 0, 120 1, 0, 0, 121 1, 0, 0, 122 1, 0, 0, 123 1, 0, 0, 124 1, 0, 0, 125 1, 0, 0, 126 1, 0, 0, 127 1, 0, 0, 128 1, 0, 0, 129 1, 2, 0, 130 1, 2, 0, 131 1, 2, 0, 132 1, 2, 0, 133 1, 2, 0, 134 1, 2, 0, 135 1, 2, 0, 136 1, 2, 0, 137 1, 2, 0, 138 1, 2, 0, 139 1, 2, 0, 140 1, 2, 0 141 }; 142 143 int 144 main(int argc, char** argv) 145 { 146 struct mem_allocator allocator; 147 struct senc3d_device* dev = NULL; 148 struct senc3d_scene* scn = NULL; 149 struct context ctx = CONTEXT_NULL__; 150 unsigned count, e; 151 (void)argc, (void)argv; 152 153 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 154 OK(senc3d_device_create(NULL, &allocator, SENC3D_NTHREADS_DEFAULT, 1, &dev)); 155 156 /* Create a scene with the cubes. 157 * The enclosures in the small cubes contain medium 0, the external enclosure 158 * contains medium 2, the enclosure between the small and big cubes 159 * contains medium 1. */ 160 ctx.positions = cube_on_cube_vertices; 161 ctx.indices = cube_on_cube_triangles; 162 ctx.properties = cube_on_cube_properties; 163 OK(senc3d_scene_create(dev, 164 SENC3D_CONVENTION_NORMAL_FRONT | SENC3D_CONVENTION_NORMAL_INSIDE, 165 cube_on_cube_triangles_count, get_indices, get_media_from_properties, 166 cube_on_cube_vertices_count, get_position, &ctx, &scn)); 167 168 OK(senc3d_scene_get_enclosure_count(scn, &count)); 169 CHK(count == 4); 170 171 OK(senc3d_scene_get_vertices_count(scn, &count)); 172 CHK(count == cube_on_cube_vertices_count); 173 174 OK(senc3d_scene_get_triangles_count(scn, &count)); 175 CHK(count == cube_on_cube_triangles_count); 176 177 OK(senc3d_scene_get_enclosure_count(scn, &count)); 178 CHK(count == 4); 179 FOR_EACH(e, 0, count) { 180 struct senc3d_enclosure* enclosure; 181 struct senc3d_enclosure_header header; 182 unsigned m; 183 char name[128]; (void)name; 184 OK(senc3d_scene_get_enclosure(scn, e, &enclosure)); 185 OK(senc3d_enclosure_get_header(enclosure, &header)); 186 CHK(header.enclosed_media_count == 1); 187 OK(senc3d_enclosure_get_medium(enclosure, 0, &m)); 188 if(header.is_infinite) { 189 CHK(m == 2); /* External */ 190 } 191 else if(header.primitives_count == 12) { 192 CHK(m == 0); /* Internal */ 193 } else { 194 CHK(m == 1); /* In between */ 195 } 196 OK(senc3d_enclosure_ref_put(enclosure)); 197 #ifdef DUMP_ENCLOSURES 198 snprintf(name, sizeof(name), "test_cube_on_cube_%u.obj", e); 199 dump_enclosure(scn, e, name); 200 #endif 201 } 202 203 OK(senc3d_scene_ref_put(scn)); 204 OK(senc3d_device_ref_put(dev)); 205 206 check_memory_allocator(&allocator); 207 mem_shutdown_proxy_allocator(&allocator); 208 CHK(mem_allocated_size() == 0); 209 return 0; 210 }