Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-03-30 09:26:42 +0300
committerCampbell Barton <campbell@blender.org>2022-03-30 10:01:22 +0300
commita8ec7845e0bdb9e63e9d3dbd7f4cd7caad36b5a2 (patch)
tree4531232281ddc4cda4df3fb1ccc0822018fe5682 /source/blender/blenlib/intern/BLI_kdopbvh.c
parentaf3aaf80344e745e6c207102941513cb631194c3 (diff)
Cleanup: use "num" as a suffix in: source/blender/blenlib
Also replace "num" with: - "number" when it's not used to denote the number of items. - "digits" when digits in a string are being manipulated.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_kdopbvh.c')
-rw-r--r--source/blender/blenlib/intern/BLI_kdopbvh.c214
1 files changed, 107 insertions, 107 deletions
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 0c3497d3edf..0f52c84c45e 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -68,7 +68,7 @@ typedef struct BVHNode {
#endif
float *bv; /* Bounding volume of all nodes, max 13 axis */
int index; /* face, edge, vertex index */
- char totnode; /* how many nodes are used, used for speedup */
+ char node_num; /* how many nodes are used, used for speedup */
char main_axis; /* Axis used to split this node */
} BVHNode;
@@ -79,8 +79,8 @@ struct BVHTree {
BVHNode **nodechild; /* pre-alloc children for nodes */
float *nodebv; /* pre-alloc bounding-volumes for nodes */
float epsilon; /* Epsilon is used for inflation of the K-DOP. */
- int totleaf; /* leafs */
- int totbranch;
+ int leaf_num; /* leafs */
+ int branch_num;
axis_t start_axis, stop_axis; /* bvhtree_kdop_axes array indices according to axis */
axis_t axis; /* KDOP type (6 => OBB, 7 => AABB, ...) */
char tree_type; /* type of tree (4 => quad-tree). */
@@ -325,8 +325,8 @@ static void build_skip_links(BVHTree *tree, BVHNode *node, BVHNode *left, BVHNod
node->skip[0] = left;
node->skip[1] = right;
- for (i = 0; i < node->totnode; i++) {
- if (i + 1 < node->totnode) {
+ for (i = 0; i < node->node_num; i++) {
+ if (i + 1 < node->node_num) {
build_skip_links(tree, node->children[i], left, node->children[i + 1]);
}
else {
@@ -485,9 +485,9 @@ static void bvhtree_info(BVHTree *tree)
tree->axis,
tree->epsilon);
printf("nodes = %d, branches = %d, leafs = %d\n",
- tree->totbranch + tree->totleaf,
- tree->totbranch,
- tree->totleaf);
+ tree->branch_num + tree->leaf_num,
+ tree->branch_num,
+ tree->leaf_num);
printf(
"Memory per node = %ubytes\n",
(uint)(sizeof(BVHNode) + sizeof(BVHNode *) * tree->tree_type + sizeof(float) * tree->axis));
@@ -497,7 +497,7 @@ static void bvhtree_info(BVHTree *tree)
(uint)(sizeof(BVHTree) + MEM_allocN_len(tree->nodes) + MEM_allocN_len(tree->nodearray) +
MEM_allocN_len(tree->nodechild) + MEM_allocN_len(tree->nodebv)));
- bvhtree_print_tree(tree, tree->nodes[tree->totleaf], 0);
+ bvhtree_print_tree(tree, tree->nodes[tree->leaf_num], 0);
}
#endif /* USE_PRINT_TREE */
@@ -508,7 +508,7 @@ static void bvhtree_verify(BVHTree *tree)
int i, j, check = 0;
/* check the pointer list */
- for (i = 0; i < tree->totleaf; i++) {
+ for (i = 0; i < tree->leaf_num; i++) {
if (tree->nodes[i]->parent == NULL) {
printf("Leaf has no parent: %d\n", i);
}
@@ -526,7 +526,7 @@ static void bvhtree_verify(BVHTree *tree)
}
/* check the leaf list */
- for (i = 0; i < tree->totleaf; i++) {
+ for (i = 0; i < tree->leaf_num; i++) {
if (tree->nodearray[i].parent == NULL) {
printf("Leaf has no parent: %d\n", i);
}
@@ -544,9 +544,9 @@ static void bvhtree_verify(BVHTree *tree)
}
printf("branches: %d, leafs: %d, total: %d\n",
- tree->totbranch,
- tree->totleaf,
- tree->totbranch + tree->totleaf);
+ tree->branch_num,
+ tree->leaf_num,
+ tree->branch_num + tree->leaf_num);
}
#endif /* USE_VERIFY_TREE */
@@ -555,7 +555,7 @@ static void bvhtree_verify(BVHTree *tree)
* (basically this is only method to calculate pow(k, n) in O(1).. and stuff like that) */
typedef struct BVHBuildHelper {
int tree_type;
- int totleafs;
+ int leafs_num;
/** Min number of leafs that are achievable from a node at depth `N`. */
int leafs_per_child[32];
@@ -573,11 +573,11 @@ static void build_implicit_tree_helper(const BVHTree *tree, BVHBuildHelper *data
int remain;
int nnodes;
- data->totleafs = tree->totleaf;
+ data->leafs_num = tree->leaf_num;
data->tree_type = tree->tree_type;
- /* Calculate the smallest tree_type^n such that tree_type^n >= num_leafs */
- for (data->leafs_per_child[0] = 1; data->leafs_per_child[0] < data->totleafs;
+ /* Calculate the smallest tree_type^n such that tree_type^n >= leafs_num */
+ for (data->leafs_per_child[0] = 1; data->leafs_per_child[0] < data->leafs_num;
data->leafs_per_child[0] *= data->tree_type) {
/* pass */
}
@@ -589,7 +589,7 @@ static void build_implicit_tree_helper(const BVHTree *tree, BVHBuildHelper *data
data->leafs_per_child[depth] = data->leafs_per_child[depth - 1] / data->tree_type;
}
- remain = data->totleafs - data->leafs_per_child[1];
+ remain = data->leafs_num - data->leafs_per_child[1];
nnodes = (remain + data->tree_type - 2) / (data->tree_type - 1);
data->remain_leafs = remain + nnodes;
}
@@ -604,7 +604,7 @@ static int implicit_leafs_index(const BVHBuildHelper *data, const int depth, con
return min_leaf_index;
}
if (data->leafs_per_child[depth]) {
- return data->totleafs -
+ return data->leafs_num -
(data->branches_on_level[depth - 1] - child_index) * data->leafs_per_child[depth];
}
return data->remain_leafs;
@@ -725,7 +725,7 @@ static void non_recursive_bvh_div_nodes_task_cb(void *__restrict userdata,
split_leafs(data->leafs_array, nth_positions, data->tree_type, split_axis);
- /* Setup children and totnode counters
+ /* Setup `children` and `node_num` counters
* Not really needed but currently most of BVH code
* relies on having an explicit children structure */
for (k = 0; k < data->tree_type; k++) {
@@ -750,7 +750,7 @@ static void non_recursive_bvh_div_nodes_task_cb(void *__restrict userdata,
break;
}
}
- parent->totnode = (char)k;
+ parent->node_num = (char)k;
}
/**
@@ -774,7 +774,7 @@ static void non_recursive_bvh_div_nodes_task_cb(void *__restrict userdata,
static void non_recursive_bvh_div_nodes(const BVHTree *tree,
BVHNode *branches_array,
BVHNode **leafs_array,
- int num_leafs)
+ int leafs_num)
{
int i;
@@ -782,7 +782,7 @@ static void non_recursive_bvh_div_nodes(const BVHTree *tree,
/* this value is 0 (on binary trees) and negative on the others */
const int tree_offset = 2 - tree->tree_type;
- const int num_branches = implicit_needed_branches(tree_type, num_leafs);
+ const int branches_num = implicit_needed_branches(tree_type, leafs_num);
BVHBuildHelper data;
int depth;
@@ -794,10 +794,10 @@ static void non_recursive_bvh_div_nodes(const BVHTree *tree,
/* Most of bvhtree code relies on 1-leaf trees having at least one branch
* We handle that special case here */
- if (num_leafs == 1) {
- refit_kdop_hull(tree, root, 0, num_leafs);
+ if (leafs_num == 1) {
+ refit_kdop_hull(tree, root, 0, leafs_num);
root->main_axis = get_largest_axis(root->bv) / 2;
- root->totnode = 1;
+ root->node_num = 1;
root->children[0] = leafs_array[0];
root->children[0]->parent = root;
return;
@@ -819,10 +819,10 @@ static void non_recursive_bvh_div_nodes(const BVHTree *tree,
};
/* Loop tree levels (log N) loops */
- for (i = 1, depth = 1; i <= num_branches; i = i * tree_type + tree_offset, depth++) {
+ for (i = 1, depth = 1; i <= branches_num; i = i * tree_type + tree_offset, depth++) {
const int first_of_next_level = i * tree_type + tree_offset;
/* index of last branch on this level */
- const int i_stop = min_ii(first_of_next_level, num_branches + 1);
+ const int i_stop = min_ii(first_of_next_level, branches_num + 1);
/* Loop all branches on this level */
cb_data.first_of_next_level = first_of_next_level;
@@ -832,7 +832,7 @@ static void non_recursive_bvh_div_nodes(const BVHTree *tree,
if (true) {
TaskParallelSettings settings;
BLI_parallel_range_settings_defaults(&settings);
- settings.use_threading = (num_leafs > KDOPBVH_THREAD_LEAF_THRESHOLD);
+ settings.use_threading = (leafs_num > KDOPBVH_THREAD_LEAF_THRESHOLD);
BLI_task_parallel_range(i, i_stop, &cb_data, non_recursive_bvh_div_nodes_task_cb, &settings);
}
else {
@@ -940,21 +940,21 @@ void BLI_bvhtree_balance(BVHTree *tree)
/* This function should only be called once
* (some big bug goes here if its being called more than once per tree) */
- BLI_assert(tree->totbranch == 0);
+ BLI_assert(tree->branch_num == 0);
/* Build the implicit tree */
non_recursive_bvh_div_nodes(
- tree, tree->nodearray + (tree->totleaf - 1), leafs_array, tree->totleaf);
+ tree, tree->nodearray + (tree->leaf_num - 1), leafs_array, tree->leaf_num);
/* current code expects the branches to be linked to the nodes array
* we perform that linkage here */
- tree->totbranch = implicit_needed_branches(tree->tree_type, tree->totleaf);
- for (int i = 0; i < tree->totbranch; i++) {
- tree->nodes[tree->totleaf + i] = &tree->nodearray[tree->totleaf + i];
+ tree->branch_num = implicit_needed_branches(tree->tree_type, tree->leaf_num);
+ for (int i = 0; i < tree->branch_num; i++) {
+ tree->nodes[tree->leaf_num + i] = &tree->nodearray[tree->leaf_num + i];
}
#ifdef USE_SKIP_LINKS
- build_skip_links(tree, tree->nodes[tree->totleaf], NULL, NULL);
+ build_skip_links(tree, tree->nodes[tree->leaf_num], NULL, NULL);
#endif
#ifdef USE_VERIFY_TREE
@@ -980,12 +980,12 @@ void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoin
{
BVHNode *node = NULL;
- /* insert should only possible as long as tree->totbranch is 0 */
- BLI_assert(tree->totbranch <= 0);
- BLI_assert((size_t)tree->totleaf < MEM_allocN_len(tree->nodes) / sizeof(*(tree->nodes)));
+ /* insert should only possible as long as tree->branch_num is 0 */
+ BLI_assert(tree->branch_num <= 0);
+ BLI_assert((size_t)tree->leaf_num < MEM_allocN_len(tree->nodes) / sizeof(*(tree->nodes)));
- node = tree->nodes[tree->totleaf] = &(tree->nodearray[tree->totleaf]);
- tree->totleaf++;
+ node = tree->nodes[tree->leaf_num] = &(tree->nodearray[tree->leaf_num]);
+ tree->leaf_num++;
create_kdop_hull(tree, node, co, numpoints, 0);
node->index = index;
@@ -1000,7 +1000,7 @@ bool BLI_bvhtree_update_node(
BVHNode *node = NULL;
/* check if index exists */
- if (index > tree->totleaf) {
+ if (index > tree->leaf_num) {
return false;
}
@@ -1024,8 +1024,8 @@ void BLI_bvhtree_update_tree(BVHTree *tree)
* TRICKY: the way we build the tree all the children have an index greater than the parent
* This allows us todo a bottom up update by starting on the bigger numbered branch. */
- BVHNode **root = tree->nodes + tree->totleaf;
- BVHNode **index = tree->nodes + tree->totleaf + tree->totbranch - 1;
+ BVHNode **root = tree->nodes + tree->leaf_num;
+ BVHNode **index = tree->nodes + tree->leaf_num + tree->branch_num - 1;
for (; index >= root; index--) {
node_join(tree, *index);
@@ -1033,7 +1033,7 @@ void BLI_bvhtree_update_tree(BVHTree *tree)
}
int BLI_bvhtree_get_len(const BVHTree *tree)
{
- return tree->totleaf;
+ return tree->leaf_num;
}
int BLI_bvhtree_get_tree_type(const BVHTree *tree)
@@ -1048,7 +1048,7 @@ float BLI_bvhtree_get_epsilon(const BVHTree *tree)
void BLI_bvhtree_get_bounding_box(BVHTree *tree, float r_bb_min[3], float r_bb_max[3])
{
- BVHNode *root = tree->nodes[tree->totleaf];
+ BVHNode *root = tree->nodes[tree->leaf_num];
if (root != NULL) {
const float bb_min[3] = {root->bv[0], root->bv[2], root->bv[4]};
const float bb_max[3] = {root->bv[1], root->bv[3], root->bv[5]};
@@ -1099,9 +1099,9 @@ static void tree_overlap_traverse(BVHOverlapData_Thread *data_thread,
if (tree_overlap_test(node1, node2, data->start_axis, data->stop_axis)) {
/* check if node1 is a leaf */
- if (!node1->totnode) {
+ if (!node1->node_num) {
/* check if node2 is a leaf */
- if (!node2->totnode) {
+ if (!node2->node_num) {
BVHTreeOverlap *overlap;
if (UNLIKELY(node1 == node2)) {
@@ -1143,9 +1143,9 @@ static void tree_overlap_traverse_cb(BVHOverlapData_Thread *data_thread,
if (tree_overlap_test(node1, node2, data->start_axis, data->stop_axis)) {
/* check if node1 is a leaf */
- if (!node1->totnode) {
+ if (!node1->node_num) {
/* check if node2 is a leaf */
- if (!node2->totnode) {
+ if (!node2->node_num) {
BVHTreeOverlap *overlap;
if (UNLIKELY(node1 == node2)) {
@@ -1190,9 +1190,9 @@ static bool tree_overlap_traverse_num(BVHOverlapData_Thread *data_thread,
if (tree_overlap_test(node1, node2, data->start_axis, data->stop_axis)) {
/* check if node1 is a leaf */
- if (!node1->totnode) {
+ if (!node1->node_num) {
/* check if node2 is a leaf */
- if (!node2->totnode) {
+ if (!node2->node_num) {
BVHTreeOverlap *overlap;
if (UNLIKELY(node1 == node2)) {
@@ -1212,7 +1212,7 @@ static bool tree_overlap_traverse_num(BVHOverlapData_Thread *data_thread,
}
}
else {
- for (j = 0; j < node2->totnode; j++) {
+ for (j = 0; j < node2->node_num; j++) {
if (tree_overlap_traverse_num(data_thread, node1, node2->children[j])) {
return true;
}
@@ -1221,7 +1221,7 @@ static bool tree_overlap_traverse_num(BVHOverlapData_Thread *data_thread,
}
else {
const uint max_interactions = data_thread->max_interactions;
- for (j = 0; j < node1->totnode; j++) {
+ for (j = 0; j < node1->node_num; j++) {
if (tree_overlap_traverse_num(data_thread, node1->children[j], node2)) {
data_thread->max_interactions = max_interactions;
}
@@ -1233,7 +1233,7 @@ static bool tree_overlap_traverse_num(BVHOverlapData_Thread *data_thread,
int BLI_bvhtree_overlap_thread_num(const BVHTree *tree)
{
- return (int)MIN2(tree->tree_type, tree->nodes[tree->totleaf]->totnode);
+ return (int)MIN2(tree->tree_type, tree->nodes[tree->leaf_num]->node_num);
}
static void bvhtree_overlap_task_cb(void *__restrict userdata,
@@ -1245,25 +1245,25 @@ static void bvhtree_overlap_task_cb(void *__restrict userdata,
if (data->max_interactions) {
tree_overlap_traverse_num(data,
- data_shared->tree1->nodes[data_shared->tree1->totleaf]->children[j],
- data_shared->tree2->nodes[data_shared->tree2->totleaf]);
+ data_shared->tree1->nodes[data_shared->tree1->leaf_num]->children[j],
+ data_shared->tree2->nodes[data_shared->tree2->leaf_num]);
}
else if (data_shared->callback) {
tree_overlap_traverse_cb(data,
- data_shared->tree1->nodes[data_shared->tree1->totleaf]->children[j],
- data_shared->tree2->nodes[data_shared->tree2->totleaf]);
+ data_shared->tree1->nodes[data_shared->tree1->leaf_num]->children[j],
+ data_shared->tree2->nodes[data_shared->tree2->leaf_num]);
}
else {
tree_overlap_traverse(data,
- data_shared->tree1->nodes[data_shared->tree1->totleaf]->children[j],
- data_shared->tree2->nodes[data_shared->tree2->totleaf]);
+ data_shared->tree1->nodes[data_shared->tree1->leaf_num]->children[j],
+ data_shared->tree2->nodes[data_shared->tree2->leaf_num]);
}
}
BVHTreeOverlap *BLI_bvhtree_overlap_ex(
const BVHTree *tree1,
const BVHTree *tree2,
- uint *r_overlap_tot,
+ uint *r_overlap_num,
/* optional callback to test the overlap before adding (must be thread-safe!) */
BVHTree_OverlapCallback callback,
void *userdata,
@@ -1272,7 +1272,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
{
bool overlap_pairs = (flag & BVH_OVERLAP_RETURN_PAIRS) != 0;
bool use_threading = (flag & BVH_OVERLAP_USE_THREADING) != 0 &&
- (tree1->totleaf > KDOPBVH_THREAD_LEAF_THRESHOLD);
+ (tree1->leaf_num > KDOPBVH_THREAD_LEAF_THRESHOLD);
/* 'RETURN_PAIRS' was not implemented without 'max_interactions'. */
BLI_assert(overlap_pairs || max_interactions);
@@ -1293,8 +1293,8 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
return NULL;
}
- const BVHNode *root1 = tree1->nodes[tree1->totleaf];
- const BVHNode *root2 = tree2->nodes[tree2->totleaf];
+ const BVHNode *root1 = tree1->nodes[tree1->leaf_num];
+ const BVHNode *root2 = tree2->nodes[tree2->leaf_num];
start_axis = min_axis(tree1->start_axis, tree2->start_axis);
stop_axis = min_axis(tree1->stop_axis, tree2->stop_axis);
@@ -1354,7 +1354,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
BLI_stack_free(data[j].overlap);
to += count;
}
- *r_overlap_tot = (uint)total;
+ *r_overlap_num = (uint)total;
}
return overlap;
@@ -1363,14 +1363,14 @@ BVHTreeOverlap *BLI_bvhtree_overlap_ex(
BVHTreeOverlap *BLI_bvhtree_overlap(
const BVHTree *tree1,
const BVHTree *tree2,
- uint *r_overlap_tot,
+ uint *r_overlap_num,
/* optional callback to test the overlap before adding (must be thread-safe!) */
BVHTree_OverlapCallback callback,
void *userdata)
{
return BLI_bvhtree_overlap_ex(tree1,
tree2,
- r_overlap_tot,
+ r_overlap_num,
callback,
userdata,
0,
@@ -1403,7 +1403,7 @@ static void bvhtree_intersect_plane_dfs_recursive(BVHIntersectPlaneData *__restr
{
if (tree_intersect_plane_test(node->bv, data->plane)) {
/* check if node is a leaf */
- if (!node->totnode) {
+ if (!node->node_num) {
int *intersect = BLI_stack_push_r(data->intersect);
*intersect = node->index;
}
@@ -1417,18 +1417,18 @@ static void bvhtree_intersect_plane_dfs_recursive(BVHIntersectPlaneData *__restr
}
}
-int *BLI_bvhtree_intersect_plane(BVHTree *tree, float plane[4], uint *r_intersect_tot)
+int *BLI_bvhtree_intersect_plane(BVHTree *tree, float plane[4], uint *r_intersect_num)
{
int *intersect = NULL;
size_t total = 0;
- if (tree->totleaf) {
+ if (tree->leaf_num) {
BVHIntersectPlaneData data;
data.tree = tree;
copy_v4_v4(data.plane, plane);
data.intersect = BLI_stack_new(sizeof(int), __func__);
- BVHNode *root = tree->nodes[tree->totleaf];
+ BVHNode *root = tree->nodes[tree->leaf_num];
bvhtree_intersect_plane_dfs_recursive(&data, root);
total = BLI_stack_count(data.intersect);
@@ -1438,7 +1438,7 @@ int *BLI_bvhtree_intersect_plane(BVHTree *tree, float plane[4], uint *r_intersec
}
BLI_stack_free(data.intersect);
}
- *r_intersect_tot = (uint)total;
+ *r_intersect_num = (uint)total;
return intersect;
}
@@ -1473,7 +1473,7 @@ static float calc_nearest_point_squared(const float proj[3], BVHNode *node, floa
/* Depth first search method */
static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node)
{
- if (node->totnode == 0) {
+ if (node->node_num == 0) {
if (data->callback) {
data->callback(data->userdata, node->index, data->co, &data->nearest);
}
@@ -1489,7 +1489,7 @@ static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node)
if (data->proj[node->main_axis] <= node->children[0]->bv[node->main_axis * 2 + 1]) {
- for (i = 0; i != node->totnode; i++) {
+ for (i = 0; i != node->node_num; i++) {
if (calc_nearest_point_squared(data->proj, node->children[i], nearest) >=
data->nearest.dist_sq) {
continue;
@@ -1498,7 +1498,7 @@ static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node)
}
}
else {
- for (i = node->totnode - 1; i >= 0; i--) {
+ for (i = node->node_num - 1; i >= 0; i--) {
if (calc_nearest_point_squared(data->proj, node->children[i], nearest) >=
data->nearest.dist_sq) {
continue;
@@ -1522,7 +1522,7 @@ static void dfs_find_nearest_begin(BVHNearestData *data, BVHNode *node)
/* Priority queue method */
static void heap_find_nearest_inner(BVHNearestData *data, HeapSimple *heap, BVHNode *node)
{
- if (node->totnode == 0) {
+ if (node->node_num == 0) {
if (data->callback) {
data->callback(data->userdata, node->index, data->co, &data->nearest);
}
@@ -1534,7 +1534,7 @@ static void heap_find_nearest_inner(BVHNearestData *data, HeapSimple *heap, BVHN
else {
float nearest[3];
- for (int i = 0; i != node->totnode; i++) {
+ for (int i = 0; i != node->node_num; i++) {
float dist_sq = calc_nearest_point_squared(data->proj, node->children[i], nearest);
if (dist_sq < data->nearest.dist_sq) {
@@ -1574,7 +1574,7 @@ int BLI_bvhtree_find_nearest_ex(BVHTree *tree,
axis_t axis_iter;
BVHNearestData data;
- BVHNode *root = tree->nodes[tree->totleaf];
+ BVHNode *root = tree->nodes[tree->leaf_num];
/* init data to search */
data.tree = tree;
@@ -1642,7 +1642,7 @@ static bool isect_aabb_v3(BVHNode *node, const float co[3])
static bool dfs_find_duplicate_fast_dfs(BVHNearestData *data, BVHNode *node)
{
- if (node->totnode == 0) {
+ if (node->node_num == 0) {
if (isect_aabb_v3(node, data->co)) {
if (data->callback) {
const float dist_sq = data->nearest.dist_sq;
@@ -1658,7 +1658,7 @@ static bool dfs_find_duplicate_fast_dfs(BVHNearestData *data, BVHNode *node)
int i;
if (data->proj[node->main_axis] <= node->children[0]->bv[node->main_axis * 2 + 1]) {
- for (i = 0; i != node->totnode; i++) {
+ for (i = 0; i != node->node_num; i++) {
if (isect_aabb_v3(node->children[i], data->co)) {
if (dfs_find_duplicate_fast_dfs(data, node->children[i])) {
return true;
@@ -1667,7 +1667,7 @@ static bool dfs_find_duplicate_fast_dfs(BVHNearestData *data, BVHNode *node)
}
}
else {
- for (i = node->totnode; i--;) {
+ for (i = node->node_num; i--;) {
if (isect_aabb_v3(node->children[i], data->co)) {
if (dfs_find_duplicate_fast_dfs(data, node->children[i])) {
return true;
@@ -1686,7 +1686,7 @@ int BLI_bvhtree_find_nearest_first(BVHTree *tree,
void *userdata)
{
BVHNearestData data;
- BVHNode *root = tree->nodes[tree->totleaf];
+ BVHNode *root = tree->nodes[tree->leaf_num];
/* init data to search */
data.tree = tree;
@@ -1796,7 +1796,7 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node)
return;
}
- if (node->totnode == 0) {
+ if (node->node_num == 0) {
if (data->callback) {
data->callback(data->userdata, node->index, &data->ray, &data->hit);
}
@@ -1809,12 +1809,12 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node)
else {
/* pick loop direction to dive into the tree (based on ray direction and split axis) */
if (data->ray_dot_axis[node->main_axis] > 0.0f) {
- for (i = 0; i != node->totnode; i++) {
+ for (i = 0; i != node->node_num; i++) {
dfs_raycast(data, node->children[i]);
}
}
else {
- for (i = node->totnode - 1; i >= 0; i--) {
+ for (i = node->node_num - 1; i >= 0; i--) {
dfs_raycast(data, node->children[i]);
}
}
@@ -1837,7 +1837,7 @@ static void dfs_raycast_all(BVHRayCastData *data, BVHNode *node)
return;
}
- if (node->totnode == 0) {
+ if (node->node_num == 0) {
/* no need to check for 'data->callback' (using 'all' only makes sense with a callback). */
dist = data->hit.dist;
data->callback(data->userdata, node->index, &data->ray, &data->hit);
@@ -1847,12 +1847,12 @@ static void dfs_raycast_all(BVHRayCastData *data, BVHNode *node)
else {
/* pick loop direction to dive into the tree (based on ray direction and split axis) */
if (data->ray_dot_axis[node->main_axis] > 0.0f) {
- for (i = 0; i != node->totnode; i++) {
+ for (i = 0; i != node->node_num; i++) {
dfs_raycast_all(data, node->children[i]);
}
}
else {
- for (i = node->totnode - 1; i >= 0; i--) {
+ for (i = node->node_num - 1; i >= 0; i--) {
dfs_raycast_all(data, node->children[i]);
}
}
@@ -1904,7 +1904,7 @@ int BLI_bvhtree_ray_cast_ex(BVHTree *tree,
int flag)
{
BVHRayCastData data;
- BVHNode *root = tree->nodes[tree->totleaf];
+ BVHNode *root = tree->nodes[tree->leaf_num];
BLI_ASSERT_UNIT_V3(dir);
@@ -1988,7 +1988,7 @@ void BLI_bvhtree_ray_cast_all_ex(BVHTree *tree,
int flag)
{
BVHRayCastData data;
- BVHNode *root = tree->nodes[tree->totleaf];
+ BVHNode *root = tree->nodes[tree->leaf_num];
BLI_ASSERT_UNIT_V3(dir);
BLI_assert(callback != NULL);
@@ -2048,7 +2048,7 @@ typedef struct RangeQueryData {
static void dfs_range_query(RangeQueryData *data, BVHNode *node)
{
- if (node->totnode == 0) {
+ if (node->node_num == 0) {
#if 0 /*UNUSED*/
/* Calculate the node min-coords
* (if the node was a point then this is the point coordinates) */
@@ -2060,12 +2060,12 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node)
}
else {
int i;
- for (i = 0; i != node->totnode; i++) {
+ for (i = 0; i != node->node_num; i++) {
float nearest[3];
float dist_sq = calc_nearest_point_squared(data->center, node->children[i], nearest);
if (dist_sq < data->radius_sq) {
/* Its a leaf.. call the callback */
- if (node->children[i]->totnode == 0) {
+ if (node->children[i]->node_num == 0) {
data->hits++;
data->callback(data->userdata, node->children[i]->index, data->center, dist_sq);
}
@@ -2080,7 +2080,7 @@ 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)
{
- BVHNode *root = tree->nodes[tree->totleaf];
+ BVHNode *root = tree->nodes[tree->leaf_num];
RangeQueryData data;
data.tree = tree;
@@ -2096,7 +2096,7 @@ int BLI_bvhtree_range_query(
float dist_sq = calc_nearest_point_squared(data.center, root, nearest);
if (dist_sq < data.radius_sq) {
/* Its a leaf.. call the callback */
- if (root->totnode == 0) {
+ if (root->node_num == 0) {
data.hits++;
data.callback(data.userdata, root->index, co, dist_sq);
}
@@ -2118,7 +2118,7 @@ int BLI_bvhtree_range_query(
static void bvhtree_nearest_projected_dfs_recursive(BVHNearestProjectedData *__restrict data,
const BVHNode *node)
{
- if (node->totnode == 0) {
+ if (node->node_num == 0) {
if (data->callback) {
data->callback(data->userdata, node->index, &data->precalc, NULL, 0, &data->nearest);
}
@@ -2134,7 +2134,7 @@ static void bvhtree_nearest_projected_dfs_recursive(BVHNearestProjectedData *__r
else {
/* First pick the closest node to recurse into */
if (data->closest_axis[node->main_axis]) {
- for (int i = 0; i != node->totnode; i++) {
+ for (int i = 0; i != node->node_num; i++) {
const float *bv = node->children[i]->bv;
if (dist_squared_to_projected_aabb(&data->precalc,
@@ -2146,7 +2146,7 @@ static void bvhtree_nearest_projected_dfs_recursive(BVHNearestProjectedData *__r
}
}
else {
- for (int i = node->totnode; i--;) {
+ for (int i = node->node_num; i--;) {
const float *bv = node->children[i]->bv;
if (dist_squared_to_projected_aabb(&data->precalc,
@@ -2163,7 +2163,7 @@ static void bvhtree_nearest_projected_dfs_recursive(BVHNearestProjectedData *__r
static void bvhtree_nearest_projected_with_clipplane_test_dfs_recursive(
BVHNearestProjectedData *__restrict data, const BVHNode *node)
{
- if (node->totnode == 0) {
+ if (node->node_num == 0) {
if (data->callback) {
data->callback(data->userdata,
node->index,
@@ -2184,7 +2184,7 @@ static void bvhtree_nearest_projected_with_clipplane_test_dfs_recursive(
else {
/* First pick the closest node to recurse into */
if (data->closest_axis[node->main_axis]) {
- for (int i = 0; i != node->totnode; i++) {
+ for (int i = 0; i != node->node_num; i++) {
const float *bv = node->children[i]->bv;
const float bb_min[3] = {bv[0], bv[2], bv[4]};
const float bb_max[3] = {bv[1], bv[3], bv[5]};
@@ -2206,7 +2206,7 @@ static void bvhtree_nearest_projected_with_clipplane_test_dfs_recursive(
}
}
else {
- for (int i = node->totnode; i--;) {
+ for (int i = node->node_num; i--;) {
const float *bv = node->children[i]->bv;
const float bb_min[3] = {bv[0], bv[2], bv[4]};
const float bb_max[3] = {bv[1], bv[3], bv[5]};
@@ -2240,7 +2240,7 @@ int BLI_bvhtree_find_nearest_projected(BVHTree *tree,
BVHTree_NearestProjectedCallback callback,
void *userdata)
{
- BVHNode *root = tree->nodes[tree->totleaf];
+ BVHNode *root = tree->nodes[tree->leaf_num];
if (root != NULL) {
BVHNearestProjectedData data;
dist_squared_to_projected_aabb_precalc(&data.precalc, projmat, winsize, mval);
@@ -2314,7 +2314,7 @@ typedef struct BVHTree_WalkData {
*/
static bool bvhtree_walk_dfs_recursive(BVHTree_WalkData *walk_data, const BVHNode *node)
{
- if (node->totnode == 0) {
+ if (node->node_num == 0) {
return walk_data->walk_leaf_cb(
(const BVHTreeAxisRange *)node->bv, node->index, walk_data->userdata);
}
@@ -2322,7 +2322,7 @@ static bool bvhtree_walk_dfs_recursive(BVHTree_WalkData *walk_data, const BVHNod
/* First pick the closest node to recurse into */
if (walk_data->walk_order_cb(
(const BVHTreeAxisRange *)node->bv, node->main_axis, walk_data->userdata)) {
- for (int i = 0; i != node->totnode; i++) {
+ for (int i = 0; i != node->node_num; i++) {
if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv,
walk_data->userdata)) {
if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) {
@@ -2332,7 +2332,7 @@ static bool bvhtree_walk_dfs_recursive(BVHTree_WalkData *walk_data, const BVHNod
}
}
else {
- for (int i = node->totnode - 1; i >= 0; i--) {
+ for (int i = node->node_num - 1; i >= 0; i--) {
if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv,
walk_data->userdata)) {
if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) {
@@ -2350,7 +2350,7 @@ void BLI_bvhtree_walk_dfs(BVHTree *tree,
BVHTree_WalkOrderCallback walk_order_cb,
void *userdata)
{
- const BVHNode *root = tree->nodes[tree->totleaf];
+ const BVHNode *root = tree->nodes[tree->leaf_num];
if (root != NULL) {
BVHTree_WalkData walk_data = {walk_parent_cb, walk_leaf_cb, walk_order_cb, userdata};
/* first make sure the bv of root passes in the test too */