star-vx

Structuring voxels for ray-tracing
git clone git://git.meso-star.fr/star-vx.git
Log | Files | Refs | README | LICENSE

svx_tree.h (2811B)


      1 /* Copyright (C) 2018, 2020-2025 |Méso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2018 Université Paul Sabatier
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #ifndef SVX_TREE_H
     18 #define SVX_TREE_H
     19 
     20 #include "svx_buffer.h"
     21 #include <rsys/ref_count.h>
     22 
     23 /* Current version the tree data structure. One should increment it and perform
     24  * a version management onto serialized data when the tree data structure is
     25  * updated. */
     26 static const int SVX_TREE_VERSION = 0;
     27 
     28 struct svx_tree {
     29   size_t definition; /* #voxels of the tree along its dimensions */
     30 
     31   /* Submitted AABB */
     32   double lower[3], upper[3];
     33 
     34   /* Adjusted World space AABB of the tree. The submitted AABB is increased to
     35    * encompass the whole tree voxels. The number of tree voxels might be
     36    * greater than the submitted voxels count in order to ensure that definition
     37    * is a power of two. */
     38   double tree_low[3], tree_upp[3];
     39   double tree_size[3]; /* World space size of the tree AABB */
     40 
     41   struct buffer buffer; /* Buffer of voxel data */
     42   struct buffer_index root; /* Index toward the children of the root */
     43   ALIGN(16) char root_attr[SVX_MAX_SIZEOF_VOXEL]; /* Attribute of the root */
     44 
     45   size_t nleaves; /* #leaves */
     46   size_t depth; /* Maximum depth of the tree */
     47 
     48   enum svx_axis frame[3]; /* Define the frame (i.e. basis) of the tree */
     49   enum svx_tree_type type;
     50   struct svx_device* dev;
     51   ref_T ref;
     52 };
     53 
     54 extern LOCAL_SYM res_T
     55 tree_create
     56   (struct svx_device* dev,
     57    const enum svx_tree_type type,
     58    const size_t vxsz,
     59    struct svx_tree** out_tree);
     60 
     61 extern LOCAL_SYM res_T
     62 octree_trace_ray
     63   (struct svx_tree* oct,
     64    const double ray_origin[3],
     65    const double ray_direction[3],
     66    const double ray_range[2],
     67    const svx_hit_challenge_T challenge,
     68    const svx_hit_filter_T filter,
     69    void* context,
     70    struct svx_hit* hit);
     71 
     72 extern LOCAL_SYM res_T
     73 bintree_trace_ray
     74   (struct svx_tree* btree,
     75    const double ray_origin[3],
     76    const double ray_direction[3],
     77    const double ray_range[2],
     78    const svx_hit_challenge_T challenge,
     79    const svx_hit_filter_T filter,
     80    void* context,
     81    struct svx_hit* hit);
     82 
     83 extern LOCAL_SYM res_T
     84 tree_read
     85   (struct svx_tree* tree,
     86    FILE* stream);
     87 
     88 #endif /* SVX_TREE_H */
     89