star-2d

Contour structuring for efficient 2D geometric queries
git clone git://git.meso-star.fr/star-2d.git
Log | Files | Refs | README | LICENSE

s2d_scene_view_c.h (2947B)


      1 /* Copyright (C) 2016-2021, 2023 |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 #ifndef S2D_SCENE_VIEW_C_H
     17 #define S2D_SCENE_VIEW_C_H
     18 
     19 #include "s2d_backend.h"
     20 #include "s2d_scene_c.h"
     21 
     22 #include <rsys/dynamic_array_uint.h>
     23 #include <rsys/hash_table.h>
     24 #include <rsys/list.h>
     25 #include <rsys/ref_count.h>
     26 
     27 /* Forward declarations */
     28 struct s2d_scene_view;
     29 
     30 /* Generate the htable_geom hash table */
     31 #define HTABLE_NAME geom
     32 #define HTABLE_DATA struct geometry*
     33 #define HTABLE_KEY unsigned /* Id of the shape */
     34 #include <rsys/hash_table.h>
     35 
     36 /* Generate the darray_fltui dynamic array */
     37 struct fltui { float flt; unsigned ui; };
     38 #define DARRAY_NAME fltui
     39 #define DARRAY_DATA struct fltui
     40 #include <rsys/dynamic_array.h>
     41 
     42 /* Generate the darray_geom_nprims array */
     43 struct nprims_cdf { unsigned nprims, ishape; };
     44 #define DARRAY_NAME nprims_cdf
     45 #define DARRAY_DATA struct nprims_cdf
     46 #include <rsys/dynamic_array.h>
     47 
     48 struct s2d_scene_view {
     49   struct list_node node; /* Attachment point to the scene scene_views pool */
     50 
     51   struct htable_geom cached_geoms; /* Cached shape geometries */
     52   struct darray_fltui cdf; /* Unormalized CDF */
     53   struct darray_nprims_cdf nprims_cdf;
     54 
     55    /* Id of Shapes detached while the scnview is active */
     56   struct darray_uint detached_shapes;
     57 
     58   float lower[2], upper[2]; /* AABB of the scene */
     59 
     60   /* Callback attached to the sig_shape_detach signal of scn */
     61   scene_shape_cb_T on_shape_detach_cb;
     62 
     63   int mask; /* Combination of enum s3d_scene_view_flag */
     64   int rtc_scn_update; /* Define if Embree geometries were deleted/added */
     65   int rtc_commit; /* Define whether or not the Embree scene was committed */
     66   RTCScene rtc_scn; /* Embree scene */
     67 
     68   ref_T ref;
     69   struct s2d_scene* scn;
     70 };
     71 
     72 extern LOCAL_SYM void
     73 rtc_hit_filter_wrapper
     74   (const struct RTCFilterFunctionNArguments* args);
     75 
     76 extern LOCAL_SYM void
     77 scene_view_destroy
     78   (struct s2d_scene_view* scnview);
     79 
     80 static FINLINE struct geometry*
     81 scene_view_geometry_from_embree_id
     82   (struct s2d_scene_view* scnview,
     83    const unsigned irtc)
     84 {
     85   struct geometry* geom;
     86   RTCGeometry rtc_geom;
     87   ASSERT(scnview && irtc != RTC_INVALID_GEOMETRY_ID);
     88   rtc_geom = rtcGetGeometry(scnview->rtc_scn, irtc);
     89   ASSERT(rtc_geom);
     90   geom = rtcGetGeometryUserData(rtc_geom);
     91   ASSERT(geom);
     92   return geom;
     93 }
     94 
     95 #endif /* S2D_SCENE_VIEW_C_H */