star-enclosures-2d

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

test_senc2d_many_enclosures.c (3877B)


      1 /* Copyright (C) |Meso|Star> 2016-2020 (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_senc2d_some_enclosures, but involves 64*64*64
     17  * circles instead of 4*4*4, thus making it impossible to define the geometry
     18  * through static arrays. */
     19 
     20 #define NB_CIRC_X 32
     21 #define NB_CIRC_Y 32
     22 #define NB_CIRC_Z 64
     23 /* 64^3 = 262144 circles */
     24 #define NB_CIRC (NB_CIRC_X * NB_CIRC_Y * NB_CIRC_Z)
     25 
     26 #include "senc2d.h"
     27 #include "test_senc2d_utils.h"
     28 #include "test_senc2d_utils2.h"
     29 
     30 #include <rsys/clock_time.h>
     31 #include <rsys/double2.h>
     32 
     33 #include <stdio.h>
     34 #include <limits.h>
     35 
     36 int
     37 main(int argc, char** argv)
     38 {
     39   struct mem_allocator allocator;
     40   struct senc2d_device* dev = NULL;
     41   struct senc2d_scene* scn = NULL;
     42   struct context ctx = CONTEXT_NULL__;
     43   unsigned count;
     44   unsigned circ_seg_count, circ_vrtx_count, e;
     45   char dump[64];
     46   struct time t0, t1;
     47   (void)argc, (void)argv;
     48 
     49   OK(mem_init_regular_allocator(&allocator));
     50   OK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev));
     51 
     52   /* A 16 segments circle template */
     53   create_circle(1, 16, &ctx);
     54   ASSERT(sa_size(ctx.positions) % 2 == 0
     55     && sa_size(ctx.positions) / 2 < UINT_MAX);
     56   ASSERT(sa_size(ctx.indices) % 2 == 0
     57     && sa_size(ctx.indices) / 2 < UINT_MAX);
     58   circ_seg_count = (unsigned)sa_size(ctx.indices) / 2;
     59   circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2;
     60 
     61   /* Create the scene with NB_CIRC circles.
     62    * There are NB_CIRC_X * NB_CIRC_Y imbrications of NB_CIRC_Z circles each.
     63    * Each imbrication is located on a grid.
     64    * The get_ctx_xxx getters have to retrieve the circle from the
     65    * primitive and vertice indexes. */
     66   time_current(&t0);
     67   OK(senc2d_scene_create(dev,
     68     SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE,
     69     NB_CIRC * circ_seg_count, get_ctx_indices, get_ctx_media,
     70     NB_CIRC * circ_vrtx_count, get_ctx_position, &ctx, &scn));
     71   time_sub(&t0, time_current(&t1), &t0);
     72   time_dump(&t0, TIME_MSEC | TIME_SEC | TIME_MIN, NULL, dump, sizeof(dump));
     73   printf("Scene created in: %s\n", dump);
     74   circle_release(&ctx);
     75 
     76   OK(senc2d_scene_get_vertices_count(scn, &count));
     77   CHK(count == NB_CIRC * circ_vrtx_count);
     78   OK(senc2d_scene_get_segments_count(scn, &count));
     79   CHK(count == NB_CIRC * circ_seg_count);
     80 
     81   OK(senc2d_scene_get_enclosure_count(scn, &count));
     82   CHK(count == 1 + NB_CIRC);
     83   FOR_EACH(e, 0, count) {
     84     struct senc2d_enclosure* enclosure;
     85     struct senc2d_enclosure_header header;
     86     unsigned m;
     87     OK(senc2d_scene_get_enclosure(scn, e, &enclosure));
     88     OK(senc2d_enclosure_get_header(enclosure, &header));
     89     CHK(header.enclosed_media_count == 1);
     90     OK(senc2d_enclosure_get_medium(enclosure, 0, &m));
     91     CHK(header.primitives_count ==
     92       (header.is_infinite /* Outermost enclosure: NB_CIRC_X*NB_CIRC_Y circles */
     93         ? NB_CIRC_X * NB_CIRC_Y * circ_seg_count
     94         : (m == 0
     95           ? circ_seg_count /* Innermost enclosures: 1 circles */
     96           : 2 * circ_seg_count))); /* Other enclosures: 2 circles */
     97     OK(senc2d_enclosure_ref_put(enclosure));
     98   }
     99 
    100   OK(senc2d_scene_ref_put(scn));
    101   OK(senc2d_device_ref_put(dev));
    102 
    103   check_memory_allocator(&allocator);
    104   mem_shutdown_regular_allocator(&allocator);
    105   CHK(mem_allocated_size() == 0);
    106   return 0;
    107 }