diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2017-05-08 01:19:22 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2017-05-08 01:19:22 +0300 |
commit | 9181f13af710f39e28368461f9979ce2052a55ee (patch) | |
tree | bb4dae8ee41e31d25ba980aa996c3e62539a59e0 /source/blender/blenlib | |
parent | c47926542acf1fc342b4d0b8f7ccaf1e3a8be6d8 (diff) | |
parent | ce28025eaf5014f16460dd1cb798ce5292087d94 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/BLI_kdopbvh.c | 26 | ||||
-rw-r--r-- | source/blender/blenlib/intern/polyfill2d.c | 96 |
2 files changed, 62 insertions, 60 deletions
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 084ae4c222e..857c2a5201c 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -55,9 +55,10 @@ #include "BLI_stack.h" #include "BLI_kdopbvh.h" #include "BLI_math.h" -#include "BLI_strict_flags.h" #include "BLI_task.h" +#include "BLI_strict_flags.h" + /* used for iterative_raycast */ // #define USE_SKIP_LINKS @@ -468,7 +469,7 @@ static void build_skip_links(BVHTree *tree, BVHNode *node, BVHNode *left, BVHNod /* * BVHTree bounding volumes functions */ -static void create_kdop_hull(BVHTree *tree, BVHNode *node, const float *co, int numpoints, int moving) +static void create_kdop_hull(const BVHTree *tree, BVHNode *node, const float *co, int numpoints, int moving) { float newminmax; float *bv = node->bv; @@ -495,7 +496,7 @@ static void create_kdop_hull(BVHTree *tree, BVHNode *node, const float *co, int /** * \note depends on the fact that the BVH's for each face is already build */ -static void refit_kdop_hull(BVHTree *tree, BVHNode *node, int start, int end) +static void refit_kdop_hull(const BVHTree *tree, BVHNode *node, int start, int end) { float newmin, newmax; float *bv = node->bv; @@ -676,7 +677,7 @@ typedef struct BVHBuildHelper { } BVHBuildHelper; -static void build_implicit_tree_helper(BVHTree *tree, BVHBuildHelper *data) +static void build_implicit_tree_helper(const BVHTree *tree, BVHBuildHelper *data) { int depth = 0; int remain; @@ -706,7 +707,7 @@ static void build_implicit_tree_helper(BVHTree *tree, BVHBuildHelper *data) } // return the min index of all the leafs archivable with the given branch -static int implicit_leafs_index(BVHBuildHelper *data, int depth, int child_index) +static int implicit_leafs_index(const BVHBuildHelper *data, const int depth, const int child_index) { int min_leaf_index = child_index * data->leafs_per_child[depth - 1]; if (min_leaf_index <= data->remain_leafs) @@ -775,14 +776,14 @@ static void split_leafs(BVHNode **leafs_array, const int nth[], const int partit } typedef struct BVHDivNodesData { - BVHTree *tree; + const BVHTree *tree; BVHNode *branches_array; BVHNode **leafs_array; int tree_type; int tree_offset; - BVHBuildHelper *data; + const BVHBuildHelper *data; int depth; int i; @@ -795,7 +796,7 @@ static void non_recursive_bvh_div_nodes_task_cb(void *userdata, const int j) int k; const int parent_level_index = j - data->i; - BVHNode *parent = data->branches_array + j; + BVHNode *parent = &data->branches_array[j]; int nth_positions[MAX_TREETYPE + 1]; char split_axis; @@ -834,7 +835,7 @@ static void non_recursive_bvh_div_nodes_task_cb(void *userdata, const int j) const int child_leafs_end = implicit_leafs_index(data->data, data->depth + 1, child_level_index + 1); if (child_leafs_end - child_leafs_begin > 1) { - parent->children[k] = data->branches_array + child_index; + parent->children[k] = &data->branches_array[child_index]; parent->children[k]->parent = parent; } else if (child_leafs_end - child_leafs_begin == 1) { @@ -865,7 +866,8 @@ static void non_recursive_bvh_div_nodes_task_cb(void *userdata, const int j) * To archive this is necessary to find how much leafs are accessible from a certain branch, BVHBuildHelper * implicit_needed_branches and implicit_leafs_index are auxiliary functions to solve that "optimal-split". */ -static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, BVHNode **leafs_array, int num_leafs) +static void non_recursive_bvh_div_nodes( + const BVHTree *tree, BVHNode *branches_array, BVHNode **leafs_array, int num_leafs) { int i; @@ -877,13 +879,13 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, int depth; /* set parent from root node to NULL */ - BVHNode *tmp = branches_array + 0; + BVHNode *tmp = &branches_array[0]; tmp->parent = NULL; /* Most of bvhtree code relies on 1-leaf trees having at least one branch * We handle that special case here */ if (num_leafs == 1) { - BVHNode *root = branches_array + 0; + BVHNode *root = &branches_array[0]; refit_kdop_hull(tree, root, 0, num_leafs); root->main_axis = get_largest_axis(root->bv) / 2; root->totnode = 1; diff --git a/source/blender/blenlib/intern/polyfill2d.c b/source/blender/blenlib/intern/polyfill2d.c index 2969b0eccf4..5f9b92198a5 100644 --- a/source/blender/blenlib/intern/polyfill2d.c +++ b/source/blender/blenlib/intern/polyfill2d.c @@ -105,24 +105,24 @@ typedef bool axis_t; /* use for sorting */ typedef struct KDTreeNode2D_head { - unsigned int neg, pos; - unsigned int index; + uint neg, pos; + uint index; } KDTreeNode2D_head; typedef struct KDTreeNode2D { - unsigned int neg, pos; - unsigned int index; + uint neg, pos; + uint index; axis_t axis; /* range is only (0-1) */ - unsigned short flag; - unsigned int parent; + ushort flag; + uint parent; } KDTreeNode2D; struct KDTree2D { KDTreeNode2D *nodes; const float (*coords)[2]; - unsigned int root; - unsigned int totnode; - unsigned int *nodes_map; /* index -> node lookup */ + uint root; + uint totnode; + uint *nodes_map; /* index -> node lookup */ }; struct KDRange2D { @@ -140,14 +140,14 @@ typedef struct PolyFill { struct PolyIndex *indices; /* vertex aligned */ const float (*coords)[2]; - unsigned int coords_tot; + uint coords_tot; #ifdef USE_CONVEX_SKIP - unsigned int coords_tot_concave; + uint coords_tot_concave; #endif /* A polygon with n vertices has a triangulation of n-2 triangles. */ - unsigned int (*tris)[3]; - unsigned int tris_tot; + uint (*tris)[3]; + uint tris_tot; #ifdef USE_KDTREE struct KDTree2D kdtree; @@ -158,7 +158,7 @@ typedef struct PolyFill { /* circular linklist */ typedef struct PolyIndex { struct PolyIndex *next, *prev; - unsigned int index; + uint index; eSign sign; } PolyIndex; @@ -212,7 +212,7 @@ static eSign span_tri_v2_sign(const float v1[2], const float v2[2], const float #ifdef USE_KDTREE -#define KDNODE_UNSET ((unsigned int)-1) +#define KDNODE_UNSET ((uint)-1) enum { KDNODE_FLAG_REMOVED = (1 << 0), @@ -220,7 +220,7 @@ enum { static void kdtree2d_new( struct KDTree2D *tree, - unsigned int tot, + uint tot, const float (*coords)[2]) { /* set by caller */ @@ -235,11 +235,11 @@ static void kdtree2d_new( */ static void kdtree2d_init( struct KDTree2D *tree, - const unsigned int coords_tot, + const uint coords_tot, const PolyIndex *indices) { KDTreeNode2D *node; - unsigned int i; + uint i; for (i = 0, node = tree->nodes; i < coords_tot; i++) { if (indices[i].sign != CONVEX) { @@ -251,15 +251,15 @@ static void kdtree2d_init( } } - BLI_assert(tree->totnode == (unsigned int)(node - tree->nodes)); + BLI_assert(tree->totnode == (uint)(node - tree->nodes)); } -static unsigned int kdtree2d_balance_recursive( - KDTreeNode2D *nodes, unsigned int totnode, axis_t axis, - const float (*coords)[2], const unsigned int ofs) +static uint kdtree2d_balance_recursive( + KDTreeNode2D *nodes, uint totnode, axis_t axis, + const float (*coords)[2], const uint ofs) { KDTreeNode2D *node; - unsigned int neg, pos, median, i, j; + uint neg, pos, median, i, j; if (totnode <= 0) { return KDNODE_UNSET; @@ -317,7 +317,7 @@ static void kdtree2d_balance( static void kdtree2d_init_mapping( struct KDTree2D *tree) { - unsigned int i; + uint i; KDTreeNode2D *node; for (i = 0, node = tree->nodes; i < tree->totnode; i++, node++) { @@ -338,9 +338,9 @@ static void kdtree2d_init_mapping( static void kdtree2d_node_remove( struct KDTree2D *tree, - unsigned int index) + uint index) { - unsigned int node_index = tree->nodes_map[index]; + uint node_index = tree->nodes_map[index]; KDTreeNode2D *node; if (node_index == KDNODE_UNSET) { @@ -362,7 +362,7 @@ static void kdtree2d_node_remove( { KDTreeNode2D *node_parent = &tree->nodes[node->parent]; - BLI_assert((unsigned int)(node - tree->nodes) == node_index); + BLI_assert((uint)(node - tree->nodes) == node_index); if (node_parent->neg == node_index) { node_parent->neg = KDNODE_UNSET; } @@ -383,7 +383,7 @@ static void kdtree2d_node_remove( static bool kdtree2d_isect_tri_recursive( const struct KDTree2D *tree, - const unsigned int tri_index[3], + const uint tri_index[3], const float *tri_coords[3], const float tri_center[2], const struct KDRange2D bounds[2], @@ -446,10 +446,10 @@ static bool kdtree2d_isect_tri_recursive( static bool kdtree2d_isect_tri( struct KDTree2D *tree, - const unsigned int ind[3]) + const uint ind[3]) { const float *vs[3]; - unsigned int i; + uint i; struct KDRange2D bounds[2] = { {FLT_MAX, -FLT_MAX}, {FLT_MAX, -FLT_MAX}, @@ -475,7 +475,7 @@ static bool kdtree2d_isect_tri( #endif /* USE_KDTREE */ -static unsigned int *pf_tri_add(PolyFill *pf) +static uint *pf_tri_add(PolyFill *pf) { return pf->tris[pf->tris_tot++]; } @@ -496,7 +496,7 @@ static void pf_coord_remove(PolyFill *pf, PolyIndex *pi) pf->indices = pi->next; } #ifdef DEBUG - pi->index = (unsigned int)-1; + pi->index = (uint)-1; pi->next = pi->prev = NULL; #endif @@ -594,7 +594,7 @@ static void pf_triangulate(PolyFill *pf) } if (pf->coords_tot == 3) { - unsigned int *tri = pf_tri_add(pf); + uint *tri = pf_tri_add(pf); pi_ear = pf->indices; tri[0] = pi_ear->index; pi_ear = pi_ear->next; tri[1] = pi_ear->index; pi_ear = pi_ear->next; @@ -627,10 +627,10 @@ static PolyIndex *pf_ear_tip_find( ) { /* localize */ - const unsigned int coords_tot = pf->coords_tot; + const uint coords_tot = pf->coords_tot; PolyIndex *pi_ear; - unsigned int i; + uint i; #ifdef USE_CLIP_EVEN pi_ear = pi_ear_init; @@ -688,7 +688,7 @@ static bool pf_ear_tip_check(PolyFill *pf, PolyIndex *pi_ear_tip) #endif #if defined(USE_CONVEX_SKIP) && !defined(USE_KDTREE) - unsigned int coords_tot_concave_checked = 0; + uint coords_tot_concave_checked = 0; #endif @@ -697,8 +697,8 @@ static bool pf_ear_tip_check(PolyFill *pf, PolyIndex *pi_ear_tip) #ifdef USE_CONVEX_SKIP_TEST /* check if counting is wrong */ { - unsigned int coords_tot_concave_test = 0; - unsigned int i = pf->coords_tot; + uint coords_tot_concave_test = 0; + uint i = pf->coords_tot; while (i--) { if (coords_sign[indices[i]] != CONVEX) { coords_tot_concave_test += 1; @@ -720,7 +720,7 @@ static bool pf_ear_tip_check(PolyFill *pf, PolyIndex *pi_ear_tip) #ifdef USE_KDTREE { - const unsigned int ind[3] = { + const uint ind[3] = { pi_ear_tip->index, pi_ear_tip->next->index, pi_ear_tip->prev->index}; @@ -771,7 +771,7 @@ static bool pf_ear_tip_check(PolyFill *pf, PolyIndex *pi_ear_tip) static void pf_ear_tip_cut(PolyFill *pf, PolyIndex *pi_ear_tip) { - unsigned int *tri = pf_tri_add(pf); + uint *tri = pf_tri_add(pf); tri[0] = pi_ear_tip->prev->index; tri[1] = pi_ear_tip->index; @@ -786,15 +786,15 @@ static void pf_ear_tip_cut(PolyFill *pf, PolyIndex *pi_ear_tip) static void polyfill_prepare( PolyFill *pf, const float (*coords)[2], - const unsigned int coords_tot, + const uint coords_tot, int coords_sign, - unsigned int (*r_tris)[3], + uint (*r_tris)[3], PolyIndex *r_indices) { /* localize */ PolyIndex *indices = r_indices; - unsigned int i; + uint i; /* assign all polyfill members here */ pf->indices = r_indices; @@ -832,7 +832,7 @@ static void polyfill_prepare( } else { /* reversed */ - unsigned int n = coords_tot - 1; + uint n = coords_tot - 1; for (i = 0; i < coords_tot; i++) { indices[i].next = &indices[i + 1]; indices[i].prev = &indices[i - 1]; @@ -876,9 +876,9 @@ static void polyfill_calc( */ void BLI_polyfill_calc_arena( const float (*coords)[2], - const unsigned int coords_tot, + const uint coords_tot, const int coords_sign, - unsigned int (*r_tris)[3], + uint (*r_tris)[3], struct MemArena *arena) { @@ -932,9 +932,9 @@ void BLI_polyfill_calc_arena( */ void BLI_polyfill_calc( const float (*coords)[2], - const unsigned int coords_tot, + const uint coords_tot, const int coords_sign, - unsigned int (*r_tris)[3]) + uint (*r_tris)[3]) { PolyFill pf; PolyIndex *indices = BLI_array_alloca(indices, coords_tot); |