diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-03-18 02:05:07 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-03-18 02:14:47 +0400 |
commit | 7da21752716a0e9e6e6ad8ccbda20fb1c5e8e123 (patch) | |
tree | d72216f3cdf2e5887282fbce2e0eec28d025392d /source/blender | |
parent | a861e5572a70111bbe3ae84d82595eddc43b7d88 (diff) |
KDTree: deprecate 'normal' argument
Normals for each kdtree node were allocated but never used,
and search args only use in particles/boids code.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/boids.c | 33 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/dynamicpaint.c | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 16 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/smoke.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_kdtree.h | 32 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_kdtree.c | 46 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 6 | ||||
-rw-r--r-- | source/blender/editors/object/object_relations.c | 4 | ||||
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 20 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_explode.c | 4 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_kdtree.c | 8 |
13 files changed, 105 insertions, 90 deletions
diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index 157de3e2f1c..5731455fc01 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -255,8 +255,9 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * //check boids in own system if (acbr->options & BRULE_ACOLL_WITH_BOIDS) { - neighbors = BLI_kdtree_range_search(bbd->sim->psys->tree, pa->prev_state.co, pa->prev_state.ave, - &ptn, acbr->look_ahead * len_v3(pa->prev_state.vel)); + neighbors = BLI_kdtree_range_search__normal( + bbd->sim->psys->tree, pa->prev_state.co, pa->prev_state.ave, + &ptn, acbr->look_ahead * len_v3(pa->prev_state.vel)); if (neighbors > 1) for (n=1; n<neighbors; n++) { copy_v3_v3(co1, pa->prev_state.co); copy_v3_v3(vel1, pa->prev_state.vel); @@ -302,8 +303,10 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * ParticleSystem *epsys = psys_get_target_system(bbd->sim->ob, pt); if (epsys) { - neighbors = BLI_kdtree_range_search(epsys->tree, pa->prev_state.co, pa->prev_state.ave, - &ptn, acbr->look_ahead * len_v3(pa->prev_state.vel)); + neighbors = BLI_kdtree_range_search__normal( + epsys->tree, pa->prev_state.co, pa->prev_state.ave, + &ptn, acbr->look_ahead * len_v3(pa->prev_state.vel)); + if (neighbors > 0) for (n=0; n<neighbors; n++) { copy_v3_v3(co1, pa->prev_state.co); copy_v3_v3(vel1, pa->prev_state.vel); @@ -358,8 +361,9 @@ static int rule_separate(BoidRule *UNUSED(rule), BoidBrainData *bbd, BoidValues ParticleTarget *pt; float len = 2.0f * val->personal_space * pa->size + 1.0f; float vec[3] = {0.0f, 0.0f, 0.0f}; - int neighbors = BLI_kdtree_range_search(bbd->sim->psys->tree, pa->prev_state.co, NULL, - &ptn, 2.0f * val->personal_space * pa->size); + int neighbors = BLI_kdtree_range_search( + bbd->sim->psys->tree, pa->prev_state.co, + &ptn, 2.0f * val->personal_space * pa->size); int ret = 0; if (neighbors > 1 && ptn[1].dist!=0.0f) { @@ -377,8 +381,9 @@ static int rule_separate(BoidRule *UNUSED(rule), BoidBrainData *bbd, BoidValues ParticleSystem *epsys = psys_get_target_system(bbd->sim->ob, pt); if (epsys) { - neighbors = BLI_kdtree_range_search(epsys->tree, pa->prev_state.co, NULL, - &ptn, 2.0f * val->personal_space * pa->size); + neighbors = BLI_kdtree_range_search( + epsys->tree, pa->prev_state.co, + &ptn, 2.0f * val->personal_space * pa->size); if (neighbors > 0 && ptn[0].dist < len) { sub_v3_v3v3(vec, pa->prev_state.co, ptn[0].co); @@ -398,7 +403,7 @@ static int rule_flock(BoidRule *UNUSED(rule), BoidBrainData *bbd, BoidValues *UN { KDTreeNearest ptn[11]; float vec[3] = {0.0f, 0.0f, 0.0f}, loc[3] = {0.0f, 0.0f, 0.0f}; - int neighbors = BLI_kdtree_find_nearest_n(bbd->sim->psys->tree, pa->state.co, pa->prev_state.ave, ptn, 11); + int neighbors = BLI_kdtree_find_nearest_n__normal(bbd->sim->psys->tree, pa->state.co, pa->prev_state.ave, ptn, 11); int n; int ret = 0; @@ -625,8 +630,9 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti int n, ret = 0; /* calculate own group strength */ - int neighbors = BLI_kdtree_range_search(bbd->sim->psys->tree, pa->prev_state.co, NULL, - &ptn, fbr->distance); + int neighbors = BLI_kdtree_range_search( + bbd->sim->psys->tree, pa->prev_state.co, + &ptn, fbr->distance); for (n=0; n<neighbors; n++) { bpa = bbd->sim->psys->particles[ptn[n].index].boid; health += bpa->data.health; @@ -642,8 +648,9 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti if (epsys) { epars = epsys->particles; - neighbors = BLI_kdtree_range_search(epsys->tree, pa->prev_state.co, NULL, - &ptn, fbr->distance); + neighbors = BLI_kdtree_range_search( + epsys->tree, pa->prev_state.co, + &ptn, fbr->distance); health = 0.0f; diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index b56522034c5..24ccc663878 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -3716,7 +3716,7 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* make sure particle is close enough to canvas */ if (!boundIntersectPoint(&grid->grid_bounds, pa->state.co, range)) continue; - BLI_kdtree_insert(tree, p, pa->state.co, NULL); + BLI_kdtree_insert(tree, p, pa->state.co); /* calc particle system bounds */ boundInsert(&part_bb, pa->state.co); @@ -3773,7 +3773,7 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, float smooth_range, part_solidradius; /* Find nearest particle and get distance to it */ - BLI_kdtree_find_nearest(tree, bData->realCoord[bData->s_pos[index]].v, NULL, &nearest); + BLI_kdtree_find_nearest(tree, bData->realCoord[bData->s_pos[index]].v, &nearest); /* if outside maximum range, no other particle can influence either */ if (nearest.dist > range) continue; @@ -3813,7 +3813,7 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* Make gcc happy! */ dist = max_range; - particles = BLI_kdtree_range_search(tree, bData->realCoord[bData->s_pos[index]].v, NULL, + particles = BLI_kdtree_range_search(tree, bData->realCoord[bData->s_pos[index]].v, &nearest, max_range); /* Find particle that produces highest influence */ diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index de9dd011e04..fb4fde91d8b 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -3667,7 +3667,7 @@ KDTree *BKE_object_as_kdtree(Object *ob, int *r_tot) if (index[i] != ORIGINDEX_NONE) { float co[3]; mul_v3_m4v3(co, ob->obmat, mvert[i].co); - BLI_kdtree_insert(tree, index[i], co, NULL); + BLI_kdtree_insert(tree, index[i], co); tot++; } } @@ -3681,7 +3681,7 @@ KDTree *BKE_object_as_kdtree(Object *ob, int *r_tot) for (i = 0; i < tot; i++) { float co[3]; mul_v3_m4v3(co, ob->obmat, mvert[i].co); - BLI_kdtree_insert(tree, i, co, NULL); + BLI_kdtree_insert(tree, i, co); } } @@ -3711,7 +3711,7 @@ KDTree *BKE_object_as_kdtree(Object *ob, int *r_tot) while (a--) { float co[3]; mul_v3_m4v3(co, ob->obmat, bezt->vec[1]); - BLI_kdtree_insert(tree, i++, co, NULL); + BLI_kdtree_insert(tree, i++, co); bezt++; } } @@ -3723,7 +3723,7 @@ KDTree *BKE_object_as_kdtree(Object *ob, int *r_tot) while (a--) { float co[3]; mul_v3_m4v3(co, ob->obmat, bp->vec); - BLI_kdtree_insert(tree, i++, co, NULL); + BLI_kdtree_insert(tree, i++, co); bp++; } } @@ -3747,7 +3747,7 @@ KDTree *BKE_object_as_kdtree(Object *ob, int *r_tot) for (bp = lt->def; i < tot; bp++) { float co[3]; mul_v3_m4v3(co, ob->obmat, bp->vec); - BLI_kdtree_insert(tree, i++, co, NULL); + BLI_kdtree_insert(tree, i++, co); } BLI_kdtree_balance(tree); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 3a6e710d68c..2c7d58586cf 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -2406,14 +2406,14 @@ void psys_find_parents(ParticleSimulationData *sim) for (p = 0, cpa = sim->psys->child; p < totparent; p++, cpa++) { psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco, 0); - BLI_kdtree_insert(tree, p, orco, NULL); + BLI_kdtree_insert(tree, p, orco); } BLI_kdtree_balance(tree); for (; p < totchild; p++, cpa++) { psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco, 0); - cpa->parent = BLI_kdtree_find_nearest(tree, orco, NULL, NULL); + cpa->parent = BLI_kdtree_find_nearest(tree, orco, NULL); } BLI_kdtree_free(tree); diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 3f4c53692e5..92b2876cb78 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -815,7 +815,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch psys_particle_on_dm(ctx->dm,from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co1,0,0,0,orco1,0); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); - maxw = BLI_kdtree_find_nearest_n(ctx->tree,orco1,NULL,ptn,3); + maxw = BLI_kdtree_find_nearest_n(ctx->tree,orco1,ptn,3); for (w=0; w<maxw; w++) { pa->verts[w]=ptn->num; @@ -940,7 +940,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch psys_particle_on_dm(dm,cfrom,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,co1,nor1,NULL,NULL,orco1,NULL); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); - maxw = BLI_kdtree_find_nearest_n(ctx->tree,orco1,NULL,ptn,3); + maxw = BLI_kdtree_find_nearest_n(ctx->tree,orco1,ptn,3); maxd=ptn[maxw-1].dist; /* mind=ptn[0].dist; */ /* UNUSED */ @@ -1077,7 +1077,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D int totelem=0, totpart, *particle_element=0, children=0, totseam=0; int jitlevel= 1, distr; float *element_weight=NULL,*element_sum=NULL,*jitter_offset=NULL, *vweight=NULL; - float cur, maxweight=0.0, tweight, totweight, inv_totweight, co[3], nor[3], orco[3], ornor[3]; + float cur, maxweight=0.0, tweight, totweight, inv_totweight, co[3], nor[3], orco[3]; if (ELEM3(NULL, ob, psys, psys->part)) return 0; @@ -1128,9 +1128,9 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D tree=BLI_kdtree_new(totpart); for (p=0,pa=psys->particles; p<totpart; p++,pa++) { - psys_particle_on_dm(dm,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco,ornor); + psys_particle_on_dm(dm,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco,NULL); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco, 1, 1); - BLI_kdtree_insert(tree, p, orco, ornor); + BLI_kdtree_insert(tree, p, orco); } BLI_kdtree_balance(tree); @@ -1170,7 +1170,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D } else copy_v3_v3(co,mv[p].co); - BLI_kdtree_insert(tree,p,co,NULL); + BLI_kdtree_insert(tree, p, co); } BLI_kdtree_balance(tree); @@ -2249,9 +2249,9 @@ void psys_update_particle_tree(ParticleSystem *psys, float cfra) LOOP_SHOWN_PARTICLES { if (pa->alive == PARS_ALIVE) { if (pa->state.time == cfra) - BLI_kdtree_insert(psys->tree, p, pa->prev_state.co, NULL); + BLI_kdtree_insert(psys->tree, p, pa->prev_state.co); else - BLI_kdtree_insert(psys->tree, p, pa->state.co, NULL); + BLI_kdtree_insert(psys->tree, p, pa->state.co); } } BLI_kdtree_balance(psys->tree); diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 0ec277aeed6..d8c27d4468c 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -1297,7 +1297,7 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke mul_mat3_m4_v3(sds->imat, &particle_vel[valid_particles * 3]); if (sfs->flags & MOD_SMOKE_FLOW_USE_PART_SIZE) { - BLI_kdtree_insert(tree, valid_particles, pos, NULL); + BLI_kdtree_insert(tree, valid_particles, pos); } /* calculate emission map bounds */ @@ -1379,7 +1379,7 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke /* find particle distance from the kdtree */ KDTreeNearest nearest; float range = solid + smooth; - BLI_kdtree_find_nearest(tree, ray_start, NULL, &nearest); + BLI_kdtree_find_nearest(tree, ray_start, &nearest); if (nearest.dist < range) { em->influence[index] = (nearest.dist < solid) ? 1.0f : (1.0f - (nearest.dist-solid) / smooth); @@ -1404,7 +1404,7 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke /* find particle distance from the kdtree */ KDTreeNearest nearest; float range = solid + hr_smooth; - BLI_kdtree_find_nearest(tree, ray_start, NULL, &nearest); + BLI_kdtree_find_nearest(tree, ray_start, &nearest); if (nearest.dist < range) { em->influence_high[index] = (nearest.dist < solid) ? 1.0f : (1.0f - (nearest.dist-solid) / smooth); diff --git a/source/blender/blenlib/BLI_kdtree.h b/source/blender/blenlib/BLI_kdtree.h index e3c81021351..ebf03b5bc67 100644 --- a/source/blender/blenlib/BLI_kdtree.h +++ b/source/blender/blenlib/BLI_kdtree.h @@ -44,17 +44,29 @@ typedef struct KDTreeNearest { KDTree *BLI_kdtree_new(unsigned int maxsize); void BLI_kdtree_free(KDTree *tree); - -void BLI_kdtree_insert(KDTree *tree, int index, const float co[3], const float nor[3]) ATTR_NONNULL(1, 3); void BLI_kdtree_balance(KDTree *tree) ATTR_NONNULL(1); -int BLI_kdtree_find_nearest(KDTree *tree, const float co[3], const float nor[3], - KDTreeNearest *r_nearest) ATTR_NONNULL(1, 2); -int BLI_kdtree_find_nearest_n(KDTree *tree, const float co[3], const float nor[3], - KDTreeNearest *r_nearest, - unsigned int n) ATTR_NONNULL(1, 2, 4); -int BLI_kdtree_range_search(KDTree *tree, const float co[3], const float nor[3], - KDTreeNearest **r_nearest, - float range) ATTR_NONNULL(1, 2, 4) ATTR_WARN_UNUSED_RESULT; +void BLI_kdtree_insert( + KDTree *tree, int index, + const float co[3]) ATTR_NONNULL(1, 3); +int BLI_kdtree_find_nearest( + KDTree *tree, const float co[3], + KDTreeNearest *r_nearest) ATTR_NONNULL(1, 2); + +#define BLI_kdtree_find_nearest_n(tree, co, r_nearest, n) \ + BLI_kdtree_find_nearest_n__normal(tree, co, NULL, r_nearest, n) +#define BLI_kdtree_range_search(tree, co, r_nearest, range) \ + BLI_kdtree_range_search__normal(tree, co, NULL, r_nearest, range) + +/* Normal use is deprecated */ +/* remove __normal functions when last users drop */ +int BLI_kdtree_find_nearest_n__normal( + KDTree *tree, const float co[3], const float nor[3], + KDTreeNearest *r_nearest, + unsigned int n) ATTR_NONNULL(1, 2, 4); +int BLI_kdtree_range_search__normal( + KDTree *tree, const float co[3], const float nor[3], + KDTreeNearest **r_nearest, + float range) ATTR_NONNULL(1, 2, 4) ATTR_WARN_UNUSED_RESULT; #endif /* __BLI_KDTREE_H__ */ diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c index c8ee0c11fc7..1a4d8bc7f78 100644 --- a/source/blender/blenlib/intern/BLI_kdtree.c +++ b/source/blender/blenlib/intern/BLI_kdtree.c @@ -35,7 +35,7 @@ typedef struct KDTreeNode { struct KDTreeNode *left, *right; - float co[3], nor[3]; + float co[3]; int index; unsigned int d; /* range is only (0-2) */ } KDTreeNode; @@ -85,7 +85,7 @@ void BLI_kdtree_free(KDTree *tree) /** * Construction: first insert points, then call balance. Normal is optional. */ -void BLI_kdtree_insert(KDTree *tree, int index, const float co[3], const float nor[3]) +void BLI_kdtree_insert(KDTree *tree, int index, const float co[3]) { KDTreeNode *node = &tree->nodes[tree->totnode++]; @@ -98,11 +98,6 @@ void BLI_kdtree_insert(KDTree *tree, int index, const float co[3], const float n node->left = node->right = NULL; copy_v3_v3(node->co, co); - if (nor) - copy_v3_v3(node->nor, nor); - else - zero_v3(node->nor); - node->index = index; node->d = 0; @@ -167,7 +162,7 @@ void BLI_kdtree_balance(KDTree *tree) #endif } -static float squared_distance(const float v2[3], const float v1[3], const float UNUSED(n1[3]), const float n2[3]) +static float squared_distance(const float v2[3], const float v1[3], const float n2[3]) { float d[3], dist; @@ -177,8 +172,6 @@ static float squared_distance(const float v2[3], const float v1[3], const float dist = dot_v3v3(d, d); - //if (n1 && n2 && (dot_v3v3(n1, n2) < 0.0f)) - /* can someone explain why this is done?*/ if (n2 && (dot_v3v3(d, n2) < 0.0f)) { dist *= 10.0f; @@ -201,8 +194,9 @@ static KDTreeNode **realloc_nodes(KDTreeNode **stack, unsigned int *totstack, co /** * Find nearest returns index, and -1 if no node is found. */ -int BLI_kdtree_find_nearest(KDTree *tree, const float co[3], const float nor[3], - KDTreeNearest *r_nearest) +int BLI_kdtree_find_nearest( + KDTree *tree, const float co[3], + KDTreeNearest *r_nearest) { KDTreeNode *root, *node, *min_node; KDTreeNode **stack, *defaultstack[KD_STACK_INIT]; @@ -221,7 +215,7 @@ int BLI_kdtree_find_nearest(KDTree *tree, const float co[3], const float nor[3], root = tree->root; min_node = root; - min_dist = squared_distance(root->co, co, root->nor, nor); + min_dist = len_squared_v3v3(root->co, co); if (co[root->d] < root->co[root->d]) { if (root->right) @@ -245,7 +239,7 @@ int BLI_kdtree_find_nearest(KDTree *tree, const float co[3], const float nor[3], cur_dist = -cur_dist * cur_dist; if (-cur_dist < min_dist) { - cur_dist = squared_distance(node->co, co, node->nor, nor); + cur_dist = len_squared_v3v3(node->co, co); if (cur_dist < min_dist) { min_dist = cur_dist; min_node = node; @@ -260,7 +254,7 @@ int BLI_kdtree_find_nearest(KDTree *tree, const float co[3], const float nor[3], cur_dist = cur_dist * cur_dist; if (cur_dist < min_dist) { - cur_dist = squared_distance(node->co, co, node->nor, nor); + cur_dist = len_squared_v3v3(node->co, co); if (cur_dist < min_dist) { min_dist = cur_dist; min_node = node; @@ -313,9 +307,10 @@ static void add_nearest(KDTreeNearest *ptn, unsigned int *found, unsigned int n, * * \param r_nearest An array of nearest, sized at least \a n. */ -int BLI_kdtree_find_nearest_n(KDTree *tree, const float co[3], const float nor[3], - KDTreeNearest r_nearest[], - unsigned int n) +int BLI_kdtree_find_nearest_n__normal( + KDTree *tree, const float co[3], const float nor[3], + KDTreeNearest r_nearest[], + unsigned int n) { KDTreeNode *root, *node = NULL; KDTreeNode **stack, *defaultstack[KD_STACK_INIT]; @@ -335,7 +330,7 @@ int BLI_kdtree_find_nearest_n(KDTree *tree, const float co[3], const float nor[3 root = tree->root; - cur_dist = squared_distance(root->co, co, root->nor, nor); + cur_dist = squared_distance(root->co, co, nor); add_nearest(r_nearest, &found, n, root->index, cur_dist, root->co); if (co[root->d] < root->co[root->d]) { @@ -360,7 +355,7 @@ int BLI_kdtree_find_nearest_n(KDTree *tree, const float co[3], const float nor[3 cur_dist = -cur_dist * cur_dist; if (found < n || -cur_dist < r_nearest[found - 1].dist) { - cur_dist = squared_distance(node->co, co, node->nor, nor); + cur_dist = squared_distance(node->co, co, nor); if (found < n || cur_dist < r_nearest[found - 1].dist) add_nearest(r_nearest, &found, n, node->index, cur_dist, node->co); @@ -375,7 +370,7 @@ int BLI_kdtree_find_nearest_n(KDTree *tree, const float co[3], const float nor[3 cur_dist = cur_dist * cur_dist; if (found < n || cur_dist < r_nearest[found - 1].dist) { - cur_dist = squared_distance(node->co, co, node->nor, nor); + cur_dist = squared_distance(node->co, co, nor); if (found < n || cur_dist < r_nearest[found - 1].dist) add_nearest(r_nearest, &found, n, node->index, cur_dist, node->co); @@ -436,8 +431,9 @@ static void add_in_range(KDTreeNearest **ptn, unsigned int found, unsigned int * * Normal is optional, but if given will limit results to points in normal direction from co. * Remember to free nearest after use! */ -int BLI_kdtree_range_search(KDTree *tree, const float co[3], const float nor[3], - KDTreeNearest **r_nearest, float range) +int BLI_kdtree_range_search__normal( + KDTree *tree, const float co[3], const float nor[3], + KDTreeNearest **r_nearest, float range) { KDTreeNode *root, *node = NULL; KDTreeNode **stack, *defaultstack[KD_STACK_INIT]; @@ -466,7 +462,7 @@ int BLI_kdtree_range_search(KDTree *tree, const float co[3], const float nor[3], stack[cur++] = root->right; } else { - dist2 = squared_distance(root->co, co, root->nor, nor); + dist2 = squared_distance(root->co, co, nor); if (dist2 <= range2) add_in_range(&foundstack, found++, &totfoundstack, root->index, dist2, root->co); @@ -488,7 +484,7 @@ int BLI_kdtree_range_search(KDTree *tree, const float co[3], const float nor[3], stack[cur++] = node->right; } else { - dist2 = squared_distance(node->co, co, node->nor, nor); + dist2 = squared_distance(node->co, co, nor); if (dist2 <= range2) add_in_range(&foundstack, found++, &totfoundstack, node->index, dist2, node->co); diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 5558e6fae72..c1d1c10124e 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -681,7 +681,7 @@ int ED_mesh_mirror_spatial_table(Object *ob, BMEditMesh *em, const float co[3], int i; - i = BLI_kdtree_find_nearest(MirrKdStore.tree, co, NULL, &nearest); + i = BLI_kdtree_find_nearest(MirrKdStore.tree, co, &nearest); if (i != -1) { if (nearest.dist < KD_THRESH) { @@ -717,7 +717,7 @@ int ED_mesh_mirror_spatial_table(Object *ob, BMEditMesh *em, const float co[3], BM_mesh_elem_table_ensure(em->bm, BM_VERT); BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) { - BLI_kdtree_insert(MirrKdStore.tree, i, eve->co, NULL); + BLI_kdtree_insert(MirrKdStore.tree, i, eve->co); } } else { @@ -725,7 +725,7 @@ int ED_mesh_mirror_spatial_table(Object *ob, BMEditMesh *em, const float co[3], int i; for (i = 0, mvert = me->mvert; i < me->totvert; i++, mvert++) { - BLI_kdtree_insert(MirrKdStore.tree, i, mvert->co, NULL); + BLI_kdtree_insert(MirrKdStore.tree, i, mvert->co); } } diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index f1a04f81979..5fd6fcfaa47 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -785,7 +785,7 @@ static void parent_set_vert_find(KDTree *tree, Object *child, int vert_par[3], b KDTreeNearest nearest[3]; int tot; - tot = BLI_kdtree_find_nearest_n(tree, co_find, NULL, nearest, 3); + tot = BLI_kdtree_find_nearest_n(tree, co_find, nearest, 3); BLI_assert(tot == 3); vert_par[0] = nearest[0].index; @@ -795,7 +795,7 @@ static void parent_set_vert_find(KDTree *tree, Object *child, int vert_par[3], b BLI_assert(min_iii(UNPACK3(vert_par)) >= 0); } else { - vert_par[0] = BLI_kdtree_find_nearest(tree, co_find, NULL, NULL); + vert_par[0] = BLI_kdtree_find_nearest(tree, co_find, NULL); BLI_assert(vert_par[0] >= 0); vert_par[1] = 0; vert_par[2] = 0; diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 0dee36d31cd..aa1d01775f5 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -749,7 +749,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) psys_mat_hair_to_orco(ob, psmd->dm, psys->part->from, pa, mat); copy_v3_v3(co, key->co); mul_m4_v3(mat, co); - BLI_kdtree_insert(tree, p, co, NULL); + BLI_kdtree_insert(tree, p, co); } BLI_kdtree_balance(tree); @@ -765,7 +765,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) mul_m4_v3(mat, co); co[0] = -co[0]; - index= BLI_kdtree_find_nearest(tree, co, NULL, &nearest); + index= BLI_kdtree_find_nearest(tree, co, &nearest); /* this needs a custom threshold still, duplicated for editmode mirror */ if (index != -1 && index != p && (nearest.dist <= 0.0002f)) @@ -939,7 +939,7 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, PTCacheEdit *edit) dist_1st *= dist * pset->emitterdist; } else { - index= BLI_kdtree_find_nearest(edit->emitter_field, key->co, NULL, NULL); + index= BLI_kdtree_find_nearest(edit->emitter_field, key->co, NULL); vec=edit->emitter_cosnos +index*6; nor=vec+3; @@ -1123,7 +1123,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys) normalize_v3(nor); - BLI_kdtree_insert(edit->emitter_field, i, vec, NULL); + BLI_kdtree_insert(edit->emitter_field, i, vec); } BLI_kdtree_balance(edit->emitter_field); @@ -2459,7 +2459,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, psys->particles+p, mat); copy_v3_v3(co, point->keys->co); mul_m4_v3(mat, co); - BLI_kdtree_insert(tree, p, co, NULL); + BLI_kdtree_insert(tree, p, co); } BLI_kdtree_balance(tree); @@ -2470,7 +2470,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) copy_v3_v3(co, point->keys->co); mul_m4_v3(mat, co); - totn = BLI_kdtree_find_nearest_n(tree, co, NULL, nearest, 10); + totn = BLI_kdtree_find_nearest_n(tree, co, nearest, 10); for (n=0; n<totn; n++) { /* this needs a custom threshold still */ @@ -3023,7 +3023,7 @@ static void brush_puff(PEData *data, int point_index) mul_m4_v3(mat, co); mul_v3_m4v3(kco, data->ob->imat, co); /* use 'kco' as the object space version of worldspace 'co', ob->imat is set before calling */ - point_index= BLI_kdtree_find_nearest(edit->emitter_field, kco, NULL, NULL); + point_index= BLI_kdtree_find_nearest(edit->emitter_field, kco, NULL); if (point_index == -1) return; copy_v3_v3(co_root, co); @@ -3107,7 +3107,7 @@ static void brush_puff(PEData *data, int point_index) mul_m4_v3(mat, oco); mul_v3_m4v3(kco, data->ob->imat, oco); /* use 'kco' as the object space version of worldspace 'co', ob->imat is set before calling */ - point_index= BLI_kdtree_find_nearest(edit->emitter_field, kco, NULL, NULL); + point_index= BLI_kdtree_find_nearest(edit->emitter_field, kco, NULL); if (point_index != -1) { copy_v3_v3(onor, &edit->emitter_cosnos[point_index*6+3]); mul_mat3_m4_v3(data->ob->obmat, onor); /* normal into worldspace */ @@ -3434,7 +3434,7 @@ static int brush_add(PEData *data, short number) for (i=0, pa=psys->particles; i<totpart; i++, pa++) { psys_particle_on_dm(psmd->dm, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, cur_co, 0, 0, 0, 0, 0); - BLI_kdtree_insert(tree, i, cur_co, NULL); + BLI_kdtree_insert(tree, i, cur_co); } BLI_kdtree_balance(tree); @@ -3478,7 +3478,7 @@ static int brush_add(PEData *data, short number) float maxd, totw=0.0, weight[3]; psys_particle_on_dm(psmd->dm, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co1, 0, 0, 0, 0, 0); - maxw = BLI_kdtree_find_nearest_n(tree, co1, NULL, ptn, 3); + maxw = BLI_kdtree_find_nearest_n(tree, co1, ptn, 3); maxd= ptn[maxw-1].dist; diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index aef6a12e8ff..e26cf6ad4d8 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -150,7 +150,7 @@ static void createFacepa(ExplodeModifierData *emd, tree = BLI_kdtree_new(totpart); for (p = 0, pa = psys->particles; p < totpart; p++, pa++) { psys_particle_on_emitter(psmd, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, NULL, NULL, NULL, NULL, NULL); - BLI_kdtree_insert(tree, p, co, NULL); + BLI_kdtree_insert(tree, p, co); } BLI_kdtree_balance(tree); @@ -165,7 +165,7 @@ static void createFacepa(ExplodeModifierData *emd, else mul_v3_fl(center, 1.0f / 3.0f); - p = BLI_kdtree_find_nearest(tree, center, NULL, NULL); + p = BLI_kdtree_find_nearest(tree, center, NULL); v1 = vertpa[fa->v1]; v2 = vertpa[fa->v2]; diff --git a/source/blender/python/mathutils/mathutils_kdtree.c b/source/blender/python/mathutils/mathutils_kdtree.c index d48ab803740..0833d522a60 100644 --- a/source/blender/python/mathutils/mathutils_kdtree.c +++ b/source/blender/python/mathutils/mathutils_kdtree.c @@ -161,7 +161,7 @@ static PyObject *py_kdtree_insert(PyKDTree *self, PyObject *args, PyObject *kwar return NULL; } - BLI_kdtree_insert(self->obj, index, co, NULL); + BLI_kdtree_insert(self->obj, index, co); self->count++; Py_RETURN_NONE; @@ -213,7 +213,7 @@ static PyObject *py_kdtree_find(PyKDTree *self, PyObject *args, PyObject *kwargs nearest.index = -1; - BLI_kdtree_find_nearest(self->obj, co, NULL, &nearest); + BLI_kdtree_find_nearest(self->obj, co, &nearest); return kdtree_nearest_to_py_and_check(&nearest); } @@ -261,7 +261,7 @@ static PyObject *py_kdtree_find_n(PyKDTree *self, PyObject *args, PyObject *kwar nearest = MEM_mallocN(sizeof(KDTreeNearest) * n, __func__); - found = BLI_kdtree_find_nearest_n(self->obj, co, NULL, nearest, n); + found = BLI_kdtree_find_nearest_n(self->obj, co, nearest, n); py_list = PyList_New(found); @@ -316,7 +316,7 @@ static PyObject *py_kdtree_find_range(PyKDTree *self, PyObject *args, PyObject * return NULL; } - found = BLI_kdtree_range_search(self->obj, co, NULL, &nearest, radius); + found = BLI_kdtree_range_search(self->obj, co, &nearest, radius); py_list = PyList_New(found); |