test_export.c (3177B)
1 /* Copyright (C) 2022-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 #include "scad.h" 17 #include "scad_geometry.h" 18 #include "test_common.h" 19 20 #include <rsys/rsys.h> 21 #include <rsys/math.h> 22 #include <rsys/mem_allocator.h> 23 24 #include <stdlib.h> 25 26 int 27 main(int argc, char* argv[]) 28 { 29 res_T res = RES_OK; 30 double p1[3] = {0, 0, 0}; 31 double p2[3] = {4.25, 4.25, 4.8}; 32 double d1[3] = {1, 1, 1}; 33 struct scad_geometry* rectangle = NULL; 34 struct scad_geometry* cube = NULL; 35 struct scad_geometry* fused = NULL; 36 struct scad_geometry* geoms[2]; 37 struct mem_allocator allocator; 38 struct scad_options options = SCAD_DEFAULT_OPTIONS; 39 40 (void)argc; (void)argv; 41 42 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 43 OK(scad_initialize(NULL, &allocator, 3)); 44 options.Misc.LogRefCounting = SCAD_LOG_DIMTAGS_ALL | SCAD_LOG_GEOMETRY; 45 OK(scad_set_options(&options)); 46 47 OK(scad_add_rectangle(p1, d1, &rectangle)); 48 OK(scad_geometry_set_name(rectangle, "rectangle")); 49 OK(scad_add_box(p1, d1, &cube)); 50 OK(scad_geometry_set_name(cube, "cube")); 51 OK(scad_add_cylinder(p2, d1, 0.5, 2*PI, geoms+1)); 52 53 geoms[0] = cube; 54 OK(scad_geometries_fuse(geoms, 1, geoms+1, 1, &fused)); 55 OK(scad_geometry_set_name(fused, "fused")); 56 57 OK(scad_scene_mesh()); 58 59 /* Do not define a volume */ 60 BAD(scad_stl_export(rectangle, "not-a-volume.stl", SCAD_FORCE_NORMALS_OUTWARD, 0)); 61 62 OK(scad_stl_export(rectangle, NULL, SCAD_KEEP_NORMALS_UNCHANGED, 0)); 63 OK(scad_stl_export(rectangle, "bin_rectangle", SCAD_KEEP_NORMALS_UNCHANGED, 1)); 64 65 OK(scad_stl_export(cube, NULL, SCAD_FORCE_NORMALS_OUTWARD, 0)); 66 OK(scad_stl_export(cube, "bin_cube", SCAD_FORCE_NORMALS_OUTWARD, 1)); 67 68 OK(scad_stl_export(fused, NULL, SCAD_FORCE_NORMALS_OUTWARD, 0)); 69 OK(scad_stl_export(fused, "bin_fused", SCAD_FORCE_NORMALS_OUTWARD, 1)); 70 71 /* New meshing algorithm */ 72 OK(scad_geometries_set_mesh_algorithm(geoms, 2, SCAD_QUASI_STRUCTURED)); 73 OK(scad_scene_mesh()); 74 OK(scad_stl_export(rectangle, "rectangle_quasi", SCAD_KEEP_NORMALS_UNCHANGED, 0)); 75 OK(scad_stl_export(cube, "cube_quasi", SCAD_FORCE_NORMALS_OUTWARD, 0)); 76 OK(scad_stl_export(fused, "fused_quasi", SCAD_FORCE_NORMALS_OUTWARD, 0)); 77 78 OK(scad_geometry_ref_put(rectangle)); 79 OK(scad_geometry_ref_put(cube)); 80 OK(scad_geometry_ref_put(geoms[1])); 81 OK(scad_geometry_ref_put(fused)); 82 83 OK(scad_finalize()); 84 85 check_memory_allocator(&allocator); 86 mem_shutdown_proxy_allocator(&allocator); 87 CHK(mem_allocated_size() == 0); 88 89 return (res == RES_OK) ? EXIT_SUCCESS : EXIT_FAILURE; 90 }