[Bf-blender-cvs] [ba714198913] master: Cleanup: improve const correctness of bvh tree

Jacques Lucke noreply at git.blender.org
Fri Jan 13 18:09:50 CET 2023


Commit: ba714198913cf580293ebd30fb638364b62f854b
Author: Jacques Lucke
Date:   Fri Jan 13 18:09:10 2023 +0100
Branches: master
https://developer.blender.org/rBba714198913cf580293ebd30fb638364b62f854b

Cleanup: improve const correctness of bvh tree

===================================================================

M	source/blender/blenlib/BLI_kdopbvh.h
M	source/blender/blenlib/intern/BLI_kdopbvh.c

===================================================================

diff --git a/source/blender/blenlib/BLI_kdopbvh.h b/source/blender/blenlib/BLI_kdopbvh.h
index 463c95cf4f3..ac083b71e33 100644
--- a/source/blender/blenlib/BLI_kdopbvh.h
+++ b/source/blender/blenlib/BLI_kdopbvh.h
@@ -203,7 +203,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap_self(const BVHTree *tree,
                                          BVHTree_OverlapCallback callback,
                                          void *userdata);
 
-int *BLI_bvhtree_intersect_plane(BVHTree *tree, float plane[4], uint *r_intersect_num);
+int *BLI_bvhtree_intersect_plane(const BVHTree *tree, float plane[4], uint *r_intersect_num);
 
 /**
  * Number of times #BLI_bvhtree_insert has been called.
@@ -218,20 +218,20 @@ float BLI_bvhtree_get_epsilon(const BVHTree *tree);
 /**
  * This function returns the bounding box of the BVH tree.
  */
-void BLI_bvhtree_get_bounding_box(BVHTree *tree, float r_bb_min[3], float r_bb_max[3]);
+void BLI_bvhtree_get_bounding_box(const BVHTree *tree, float r_bb_min[3], float r_bb_max[3]);
 
 /**
  * Find nearest node to the given coordinates
  * (if nearest is given it will only search nodes where
  * square distance is smaller than nearest->dist).
  */
-int BLI_bvhtree_find_nearest_ex(BVHTree *tree,
+int BLI_bvhtree_find_nearest_ex(const BVHTree *tree,
                                 const float co[3],
                                 BVHTreeNearest *nearest,
                                 BVHTree_NearestPointCallback callback,
                                 void *userdata,
                                 int flag);
-int BLI_bvhtree_find_nearest(BVHTree *tree,
+int BLI_bvhtree_find_nearest(const BVHTree *tree,
                              const float co[3],
                              BVHTreeNearest *nearest,
                              BVHTree_NearestPointCallback callback,
@@ -241,13 +241,13 @@ int BLI_bvhtree_find_nearest(BVHTree *tree,
  * Find the first node nearby.
  * Favors speed over quality since it doesn't find the best target node.
  */
-int BLI_bvhtree_find_nearest_first(BVHTree *tree,
+int BLI_bvhtree_find_nearest_first(const BVHTree *tree,
                                    const float co[3],
                                    float dist_sq,
                                    BVHTree_NearestPointCallback callback,
                                    void *userdata);
 
-int BLI_bvhtree_ray_cast_ex(BVHTree *tree,
+int BLI_bvhtree_ray_cast_ex(const BVHTree *tree,
                             const float co[3],
                             const float dir[3],
                             float radius,
@@ -255,7 +255,7 @@ int BLI_bvhtree_ray_cast_ex(BVHTree *tree,
                             BVHTree_RayCastCallback callback,
                             void *userdata,
                             int flag);
-int BLI_bvhtree_ray_cast(BVHTree *tree,
+int BLI_bvhtree_ray_cast(const BVHTree *tree,
                          const float co[3],
                          const float dir[3],
                          float radius,
@@ -272,7 +272,7 @@ int BLI_bvhtree_ray_cast(BVHTree *tree,
  * It also avoid redundant argument and return value which aren't meaningful
  * when collecting multiple hits.
  */
-void BLI_bvhtree_ray_cast_all_ex(BVHTree *tree,
+void BLI_bvhtree_ray_cast_all_ex(const BVHTree *tree,
                                  const float co[3],
                                  const float dir[3],
                                  float radius,
@@ -280,7 +280,7 @@ void BLI_bvhtree_ray_cast_all_ex(BVHTree *tree,
                                  BVHTree_RayCastCallback callback,
                                  void *userdata,
                                  int flag);
-void BLI_bvhtree_ray_cast_all(BVHTree *tree,
+void BLI_bvhtree_ray_cast_all(const BVHTree *tree,
                               const float co[3],
                               const float dir[3],
                               float radius,
@@ -296,10 +296,13 @@ float BLI_bvhtree_bb_raycast(const float bv[6],
 /**
  * Range query.
  */
-int BLI_bvhtree_range_query(
-    BVHTree *tree, const float co[3], float radius, BVHTree_RangeQuery callback, void *userdata);
+int BLI_bvhtree_range_query(const BVHTree *tree,
+                            const float co[3],
+                            float radius,
+                            BVHTree_RangeQuery callback,
+                            void *userdata);
 
-int BLI_bvhtree_find_nearest_projected(BVHTree *tree,
+int BLI_bvhtree_find_nearest_projected(const BVHTree *tree,
                                        float projmat[4][4],
                                        float winsize[2],
                                        float mval[2],
@@ -321,7 +324,7 @@ int BLI_bvhtree_find_nearest_projected(BVHTree *tree,
  * either from the node with the lower or higher K-DOP axis value.
  * \param userdata: Argument passed to all callbacks.
  */
-void BLI_bvhtree_walk_dfs(BVHTree *tree,
+void BLI_bvhtree_walk_dfs(const BVHTree *tree,
                           BVHTree_WalkParentCallback walk_parent_cb,
                           BVHTree_WalkLeafCallback walk_leaf_cb,
                           BVHTree_WalkOrderCallback walk_order_cb,
@@ -346,7 +349,7 @@ namespace blender {
 using BVHTree_RayCastCallback_CPP =
     FunctionRef<void(int index, const BVHTreeRay &ray, BVHTreeRayHit &hit)>;
 
-inline void BLI_bvhtree_ray_cast_all_cpp(BVHTree &tree,
+inline void BLI_bvhtree_ray_cast_all_cpp(const BVHTree &tree,
                                          const float3 co,
                                          const float3 dir,
                                          float radius,
@@ -368,7 +371,7 @@ inline void BLI_bvhtree_ray_cast_all_cpp(BVHTree &tree,
 
 using BVHTree_RangeQuery_CPP = FunctionRef<void(int index, const float3 &co, float dist_sq)>;
 
-inline void BLI_bvhtree_range_query_cpp(BVHTree &tree,
+inline void BLI_bvhtree_range_query_cpp(const BVHTree &tree,
                                         const float3 co,
                                         float radius,
                                         BVHTree_RangeQuery_CPP fn)
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 4e958209f78..d68ea3db013 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -1047,7 +1047,7 @@ float BLI_bvhtree_get_epsilon(const BVHTree *tree)
   return tree->epsilon;
 }
 
-void BLI_bvhtree_get_bounding_box(BVHTree *tree, float r_bb_min[3], float r_bb_max[3])
+void BLI_bvhtree_get_bounding_box(const BVHTree *tree, float r_bb_min[3], float r_bb_max[3])
 {
   BVHNode *root = tree->nodes[tree->leaf_num];
   if (root != NULL) {
@@ -1494,7 +1494,7 @@ static void bvhtree_intersect_plane_dfs_recursive(BVHIntersectPlaneData *__restr
   }
 }
 
-int *BLI_bvhtree_intersect_plane(BVHTree *tree, float plane[4], uint *r_intersect_num)
+int *BLI_bvhtree_intersect_plane(const BVHTree *tree, float plane[4], uint *r_intersect_num)
 {
   int *intersect = NULL;
   size_t total = 0;
@@ -1641,7 +1641,7 @@ static void heap_find_nearest_begin(BVHNearestData *data, BVHNode *root)
   }
 }
 
-int BLI_bvhtree_find_nearest_ex(BVHTree *tree,
+int BLI_bvhtree_find_nearest_ex(const BVHTree *tree,
                                 const float co[3],
                                 BVHTreeNearest *nearest,
                                 BVHTree_NearestPointCallback callback,
@@ -1690,7 +1690,7 @@ int BLI_bvhtree_find_nearest_ex(BVHTree *tree,
   return data.nearest.index;
 }
 
-int BLI_bvhtree_find_nearest(BVHTree *tree,
+int BLI_bvhtree_find_nearest(const BVHTree *tree,
                              const float co[3],
                              BVHTreeNearest *nearest,
                              BVHTree_NearestPointCallback callback,
@@ -1756,7 +1756,7 @@ static bool dfs_find_duplicate_fast_dfs(BVHNearestData *data, BVHNode *node)
   return false;
 }
 
-int BLI_bvhtree_find_nearest_first(BVHTree *tree,
+int BLI_bvhtree_find_nearest_first(const BVHTree *tree,
                                    const float co[3],
                                    const float dist_sq,
                                    BVHTree_NearestPointCallback callback,
@@ -1971,7 +1971,7 @@ static void bvhtree_ray_cast_data_precalc(BVHRayCastData *data, int flag)
 #endif
 }
 
-int BLI_bvhtree_ray_cast_ex(BVHTree *tree,
+int BLI_bvhtree_ray_cast_ex(const BVHTree *tree,
                             const float co[3],
                             const float dir[3],
                             float radius,
@@ -2016,7 +2016,7 @@ int BLI_bvhtree_ray_cast_ex(BVHTree *tree,
   return data.hit.index;
 }
 
-int BLI_bvhtree_ray_cast(BVHTree *tree,
+int BLI_bvhtree_ray_cast(const BVHTree *tree,
                          const float co[3],
                          const float dir[3],
                          float radius,
@@ -2055,7 +2055,7 @@ float BLI_bvhtree_bb_raycast(const float bv[6],
   return dist;
 }
 
-void BLI_bvhtree_ray_cast_all_ex(BVHTree *tree,
+void BLI_bvhtree_ray_cast_all_ex(const BVHTree *tree,
                                  const float co[3],
                                  const float dir[3],
                                  float radius,
@@ -2089,7 +2089,7 @@ void BLI_bvhtree_ray_cast_all_ex(BVHTree *tree,
   }
 }
 
-void BLI_bvhtree_ray_cast_all(BVHTree *tree,
+void BLI_bvhtree_ray_cast_all(const BVHTree *tree,
                               const float co[3],
                               const float dir[3],
                               float radius,
@@ -2113,7 +2113,7 @@ void BLI_bvhtree_ray_cast_all(BVHTree *tree,
  * \{ */
 
 typedef struct RangeQueryData {
-  BVHTree *tree;
+  const BVHTree *tree;
   const float *center;
   float radius_sq; /* squared radius */
 
@@ -2154,8 +2154,11 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node)
   }
 }
 
-int BLI_bvhtree_range_query(
-    BVHTree *tree, const float co[3], float radius, BVHTree_RangeQuery callback, void *userdata)
+int BLI_bvhtree_range_query(const BVHTree *tree,
+                            const float co[3],
+                            float radius,
+                            BVHTree_RangeQuery callback,
+                            void *

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list