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_bad_grouping2.c (7212B)


      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 a star-cad scene that crashed. */
     18 
     19 #include "senc3d.h"
     20 #include "test_senc3d_utils.h"
     21 
     22 #include <rsys/double3.h>
     23 
     24 #include <stdio.h>
     25 
     26 /*
     27  *    +--------------------------+
     28  *    |                          |
     29  *    |   +--+                   |
     30  *    |   |  |                   |
     31  *    |   |  |                   |
     32  *    |   |  |                   |
     33  *    |   |  | ++                |
     34  *    |   |  | ++                |
     35  *    |   |  |                   |
     36  *    |   |  |                   |
     37  *    |   +--+                   |
     38  *    |                          |
     39  *    +--------------------------+
     40 */
     41 
     42 static const unsigned bad2_vertices_count = 24;
     43 static const double bad2_vertices[72] =
     44 {
     45     0, 10, 10,
     46     0, 0, 0,
     47     0, 0, 10,
     48     0, 10, 0,
     49     10, 10, 10,
     50     10, 0, 10,
     51     10, 0, 0,
     52     10, 10, 0,
     53     1, 9, 9,
     54     1, 1, 1,
     55     1, 1, 9,
     56     1, 9, 1,
     57     2, 9, 9,
     58     2, 1, 9,
     59     2, 1, 1,
     60     2, 9, 1,
     61     3, 5, 5,
     62     3, 4, 4,
     63     3, 4, 5,
     64     3, 5, 4,
     65     4, 5, 5,
     66     4, 4, 5,
     67     4, 4, 4,
     68     4, 5, 4,
     69 };
     70 unsigned bad2_triangles_count = 36;
     71 unsigned bad2_triangles[600] =
     72 {
     73   0, 1, 2,
     74   0, 3, 1,
     75   4, 5, 6,
     76   4, 6, 7,
     77   6, 2, 1,
     78   5, 2, 6,
     79   7, 3, 0,
     80   4, 7, 0,
     81   3, 6, 1,
     82   7, 6, 3,
     83   0, 2, 5,
     84   4, 0, 5,
     85   8, 9, 10,
     86   8, 11, 9,
     87   12, 13, 14,
     88   12, 14, 15,
     89   14, 10, 9,
     90   13, 10, 14,
     91   15, 11, 8,
     92   12, 15, 8,
     93   11, 14, 9,
     94   15, 14, 11,
     95   8, 10, 13,
     96   12, 8, 13,
     97   16, 17, 18,
     98   16, 19, 17,
     99   20, 21, 22,
    100   20, 22, 23,
    101   22, 18, 17,
    102   21, 18, 22,
    103   23, 19, 16,
    104   20, 23, 16,
    105   19, 22, 17,
    106   23, 22, 19,
    107   16, 18, 21,
    108   20, 16, 21
    109 };
    110 unsigned bad2_properties[108] =
    111 {
    112    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    113    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    114    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    115    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    116    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    117    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    118    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    119    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    120    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    121    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    122    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    123    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    124    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    125    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    126    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    127    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    128    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    129    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    130    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    131    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    132    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    133    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    134    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    135    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    136    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    137    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    138    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    139    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    140    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    141    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    142    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    143    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    144    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    145    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    146    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM,
    147    SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM
    148 };
    149 
    150 int
    151 main(int argc, char** argv)
    152 {
    153   struct mem_allocator allocator;
    154   struct senc3d_device* dev = NULL;
    155   struct senc3d_scene* scn = NULL;
    156   struct context ctx = CONTEXT_NULL__;
    157   unsigned count, e;
    158   const double volumes[] = { -1000, 935, 64, 1};
    159   int volume_used[] = {0, 0, 0, 0};
    160   (void)argc, (void)argv;
    161 
    162   OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
    163   OK(senc3d_device_create(NULL, &allocator, SENC3D_NTHREADS_DEFAULT, 1, &dev));
    164 
    165   ctx.positions = bad2_vertices;
    166   ctx.indices = bad2_triangles;
    167   ctx.properties = bad2_properties;
    168   OK(senc3d_scene_create(dev,
    169     SENC3D_CONVENTION_NORMAL_BACK | SENC3D_CONVENTION_NORMAL_OUTSIDE,
    170     bad2_triangles_count, get_indices, get_media_from_properties,
    171     bad2_vertices_count, get_position, &ctx, &scn));
    172 
    173   OK(senc3d_scene_get_vertices_count(scn, &count));
    174   CHK(count == bad2_vertices_count);
    175 
    176   OK(senc3d_scene_get_triangles_count(scn, &count));
    177   CHK(count == bad2_triangles_count);
    178 
    179   OK(senc3d_scene_get_enclosure_count(scn, &count));
    180   CHK(count == 4);
    181   FOR_EACH(e, 0, count) {
    182     struct senc3d_enclosure* enclosure;
    183     struct senc3d_enclosure_header header;
    184     size_t i;
    185     int found = 0;
    186     OK(senc3d_scene_get_enclosure(scn, e, &enclosure));
    187     OK(senc3d_enclosure_get_header(enclosure, &header));
    188     OK(senc3d_enclosure_ref_put(enclosure));
    189     for(i = 0; i < sizeof(volumes)/sizeof(*volumes); i++) {
    190       if(!volume_used[i] && fabs(volumes[i] - header.volume) < DBL_EPSILON) {
    191         volume_used[i] = 1;
    192         found = 1;
    193         break;
    194       }
    195     }
    196     if(!found) return 1;
    197   }
    198 
    199   OK(senc3d_scene_ref_put(scn));
    200   OK(senc3d_device_ref_put(dev));
    201 
    202   check_memory_allocator(&allocator);
    203   mem_shutdown_proxy_allocator(&allocator);
    204   CHK(mem_allocated_size() == 0);
    205   return 0;
    206 }