star-3d

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

s3d_scene_view_c.h (3508B)


      1 /* Copyright (C) 2015-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 S3D_SCENE_VIEW_C_H
     17 #define S3D_SCENE_VIEW_C_H
     18 
     19 #include "s3d_backend.h"
     20 #include "s3d_scene_c.h"
     21 
     22 #include <rsys/dynamic_array.h>
     23 #include <rsys/dynamic_array_uint.h>
     24 #include <rsys/hash_table.h>
     25 #include <rsys/list.h>
     26 #include <rsys/ref_count.h>
     27 
     28 /* Forward declarations */
     29 struct s3d_scene_view;
     30 struct geometry;
     31 
     32 /* Generate the htable_geom hash table */
     33 #define HTABLE_NAME geom
     34 #define HTABLE_DATA struct geometry*
     35 #define HTABLE_KEY unsigned /* Id of the shape */
     36 #include <rsys/hash_table.h>
     37 
     38 /* Generate the darray_fltui dynamic array */
     39 struct fltui { float flt; unsigned ui; };
     40 #define DARRAY_NAME fltui
     41 #define DARRAY_DATA struct fltui
     42 #include <rsys/dynamic_array.h>
     43 
     44 /* Generate the darray_geom_nprims array */
     45 struct nprims_cdf { unsigned nprims, ishape; };
     46 #define DARRAY_NAME nprims_cdf
     47 #define DARRAY_DATA struct nprims_cdf
     48 #include <rsys/dynamic_array.h>
     49 
     50 /* Generate the htable_instview hash table */
     51 #define HTABLE_NAME instview
     52 #define HTABLE_DATA struct s3d_scene_view*
     53 #define HTABLE_KEY struct s3d_scene*
     54 #include <rsys/hash_table.h>
     55 
     56 struct s3d_scene_view {
     57   struct list_node node; /* Attachment point to the scene scene_views pool */
     58 
     59   struct htable_geom cached_geoms; /* Cached shape geometries */
     60   struct darray_fltui cdf; /* Unormalized cumulative of the primitive areas */
     61   struct darray_nprims_cdf nprims_cdf;
     62 
     63   /* Map an instantiated scene to its scene view */
     64   struct htable_instview instviews;
     65 
     66   /* Id of Shapes detached while the scnview is active */
     67   struct darray_uint detached_shapes;
     68 
     69   float lower[3], upper[3]; /* AABB of the scene */
     70 
     71   /* Callback attached to the sig_shape_detach signal of scn */
     72   scene_shape_cb_T on_shape_detach_cb;
     73 
     74   int aabb_update; /* Define if the geometry AABB must be updated */
     75   int mask; /* Combination of enum s3d_scene_view_flag */
     76   int rtc_scn_update; /* Define if Embree geometries were deleted/added */
     77   int rtc_commit; /* Define whether or not the Embree scene was committed */
     78   int rtc_scn_flags; /* Flags used to configure the Embree scene */
     79   enum RTCBuildQuality rtc_scn_build_quality; /* Build quality of the BVH */
     80   RTCScene rtc_scn; /* Embree scene */
     81 
     82   ref_T ref;
     83   struct s3d_scene* scn;
     84 };
     85 
     86 extern LOCAL_SYM void
     87 rtc_hit_filter_wrapper
     88   (const struct RTCFilterFunctionNArguments* args);
     89 
     90 extern LOCAL_SYM void
     91 scene_view_destroy
     92   (struct s3d_scene_view* scnview);
     93 
     94 static FINLINE struct geometry*
     95 scene_view_geometry_from_embree_id
     96   (struct s3d_scene_view* scnview,
     97    const unsigned irtc)
     98 {
     99   struct geometry* geom;
    100   RTCGeometry rtc_geom;
    101   ASSERT(scnview && irtc != RTC_INVALID_GEOMETRY_ID);
    102   rtc_geom = rtcGetGeometry(scnview->rtc_scn, irtc);
    103   ASSERT(rtc_geom);
    104   geom = rtcGetGeometryUserData(rtc_geom);
    105   ASSERT(geom);
    106   return geom;
    107 }
    108 
    109 #endif /* S3D_SCENE_VIEW_C_H */
    110