star-enclosures-3d

Extract enclosures from 3D geometry
git clone git://git.meso-star.fr/star-enclosures-3d.git
Log | Files | Refs | README | LICENSE

test_senc3d_many_triangles.c (3536B)


      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 is similar to test_senc3d_some_triangles, but involves 4*2562560
     17  * triangles instead of 4*1054, thus making it impossible to define the geometry
     18  * through static arrays. */
     19 
     20 #define NB_CYL_X 2
     21 #define NB_CYL_Y 1
     22 #define NB_CYL_Z 1
     23  /* 4 cylinders */
     24 #define NB_CYL (NB_CYL_X * NB_CYL_Y * NB_CYL_Z)
     25 
     26 #include "senc3d.h"
     27 #include "test_senc3d_utils.h"
     28 #include "test_senc3d_utils2.h"
     29 
     30 #include <star/s3dut.h>
     31 #include <rsys/clock_time.h>
     32 #include <rsys/double3.h>
     33 
     34 #include <stdio.h>
     35 #include <limits.h>
     36 
     37 int
     38 main(int argc, char** argv)
     39 {
     40   struct mem_allocator allocator;
     41   struct senc3d_device* dev = NULL;
     42   struct senc3d_scene* scn = NULL;
     43   struct s3dut_mesh* cyl = NULL;
     44   struct s3dut_context ctx = { {NULL,NULL,0,0}, CONTEXT_NULL__ };
     45   unsigned m0 = 0;
     46   unsigned count;
     47   unsigned cyl_trg_count, cyl_vrtx_count, e;
     48   char dump[64];
     49   struct time t0, t1;
     50   (void)argc, (void)argv;
     51 
     52   OK(mem_init_regular_allocator(&allocator));
     53   OK(senc3d_device_create (NULL, &allocator, SENC3D_NTHREADS_DEFAULT, 1, &dev));
     54 
     55   /* A 2,562,560 triangles 1,281,282 vertices cylinder template */
     56   S3DUT(create_cylinder(&allocator, 1, 2, 1280, 1000, &cyl));
     57   S3DUT(mesh_get_data(cyl, &ctx.data));
     58   ASSERT(ctx.data.nprimitives < UINT_MAX);
     59   ASSERT(ctx.data.nvertices < UINT_MAX);
     60   cyl_trg_count = (unsigned)ctx.data.nprimitives;
     61   cyl_vrtx_count = (unsigned)ctx.data.nvertices;
     62 
     63   /* Create the scene with 4 cylinders.
     64    * The get_s3du_xxx getters have to retrieve the cylinder from the
     65    * primitive and vertice indexes. */
     66   ctx.ctx.back_media = &m0;
     67   time_current(&t0);
     68   OK(senc3d_scene_create(dev,
     69     SENC3D_CONVENTION_NORMAL_FRONT | SENC3D_CONVENTION_NORMAL_INSIDE,
     70     NB_CYL* cyl_trg_count, get_s3dut_indices, get_s3dut_media,
     71     NB_CYL* cyl_vrtx_count, get_s3dut_position, &ctx, &scn));
     72   time_sub(&t0, time_current(&t1), &t0);
     73   time_dump(&t0, TIME_MSEC | TIME_SEC | TIME_MIN, NULL, dump, sizeof(dump));
     74   printf("Scene created in: %s\n", dump);
     75   S3DUT(mesh_ref_put(cyl));
     76 
     77   OK(senc3d_scene_get_vertices_count(scn, &count));
     78   CHK(count == NB_CYL * cyl_vrtx_count);
     79   OK(senc3d_scene_get_triangles_count(scn, &count));
     80   CHK(count == NB_CYL * cyl_trg_count);
     81 
     82   OK(senc3d_scene_get_enclosure_count(scn, &count));
     83   CHK(count == 1 + NB_CYL);
     84   FOR_EACH(e, 0, count) {
     85     struct senc3d_enclosure* enclosure;
     86     struct senc3d_enclosure_header header;
     87     OK(senc3d_scene_get_enclosure(scn, e, &enclosure));
     88     OK(senc3d_enclosure_get_header(enclosure, &header));
     89     CHK(header.primitives_count ==
     90       e ? cyl_trg_count : NB_CYL * cyl_trg_count);
     91     OK(senc3d_enclosure_ref_put(enclosure));
     92   }
     93 
     94   OK(senc3d_scene_ref_put(scn));
     95   OK(senc3d_device_ref_put(dev));
     96 
     97   check_memory_allocator(&allocator);
     98   mem_shutdown_regular_allocator(&allocator);
     99   CHK(mem_allocated_size() == 0);
    100   return 0;
    101 }