star-geometry-3d

Clean and decorate 3D geometries
git clone git://git.meso-star.fr/star-geometry-3d.git
Log | Files | Refs | README | LICENSE

test_sg3d_multi_media.c (2449B)


      1 /* Copyright (C) 2019, 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 #include "sg3d.h"
     17 #include "test_sg3d_utils.h"
     18 
     19 #include <rsys/double3.h>
     20 
     21 #include <stdio.h>
     22 
     23 static const unsigned multi_media[12] = { 4, 4, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1 };
     24 static const unsigned multi_intface[12] = { 4, 4, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1 };
     25 
     26 int
     27 main(int argc, char** argv)
     28 {
     29   struct mem_allocator allocator;
     30   struct sg3d_device* dev;
     31   struct sg3d_geometry* geom;
     32   struct context ctx = CONTEXT_NULL__;
     33   struct sg3d_geometry_add_callbacks callbacks = SG3D_ADD_CALLBACKS_NULL__;
     34   unsigned count;
     35   (void)argc, (void)argv;
     36 
     37   OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
     38   OK(sg3d_device_create(NULL, &allocator, 1, &dev));
     39   OK(sg3d_geometry_create(dev, &geom));
     40   SG3D(device_ref_put(dev));
     41 
     42   callbacks.get_indices = get_indices;
     43   callbacks.get_properties = get_properties;
     44   callbacks.get_position = get_position;
     45 
     46   ctx.positions = cube_vertices;
     47   ctx.indices = cube_indices;
     48   ctx.front_media = medium0;
     49   ctx.back_media = multi_media;
     50   ctx.intface = multi_intface;
     51 
     52   OK(sg3d_geometry_add(geom, nvertices, ntriangles, &callbacks, &ctx));
     53 
     54   OK(sg3d_geometry_get_unique_triangles_with_merge_conflict_count(geom, &count));
     55   CHK(count == 0);
     56   OK(sg3d_geometry_get_unique_triangles_with_unspecified_interface_count(geom, &count));
     57   CHK(count == 0);
     58   OK(sg3d_geometry_get_unique_triangles_with_unspecified_side_count(geom, &count));
     59   CHK(count == 0);
     60   OK(sg3d_geometry_dump_as_c_code(geom, stdout, "multi_media",
     61     SG3D_C_DUMP_CONST | SG3D_C_DUMP_STATIC));
     62 
     63   OK(sg3d_geometry_dump_as_vtk(geom, stdout));
     64 
     65   SG3D(geometry_ref_put(geom));
     66 
     67   check_memory_allocator(&allocator);
     68   mem_shutdown_proxy_allocator(&allocator);
     69   CHK(mem_allocated_size() == 0);
     70   return 0;
     71 }