BLI_kdopbvh: Pass center to to range callback
authorCampbell Barton <ideasman42@gmail.com>
Sat, 19 Mar 2016 06:16:50 +0000 (17:16 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 19 Mar 2016 07:31:56 +0000 (18:31 +1100)
Useful when BLI_bvhtree_range_query callback calculates a new position to measure from.

source/blender/blenkernel/BKE_particle.h
source/blender/blenkernel/intern/particle_system.c
source/blender/blenlib/BLI_kdopbvh.h
source/blender/blenlib/intern/BLI_kdopbvh.c
source/blender/render/intern/source/pointdensity.c

index b6b40ad081d1c7772acacd21e39c28f8b550a0ba..e17fb9f7a02b492f1d44607a8af6fc28d6db2334 100644 (file)
@@ -101,7 +101,7 @@ typedef struct SPHData {
 
        /* Integrator callbacks. This allows different SPH implementations. */
        void (*force_cb) (void *sphdata_v, ParticleKey *state, float *force, float *impulse);
-       void (*density_cb) (void *rangedata_v, int index, float squared_dist);
+       void (*density_cb) (void *rangedata_v, int index, const float co[3], float squared_dist);
 } SPHData;
 
 typedef struct ParticleTexture {
index e9ce5329ad00e4bf518d865feb9fb8b195259caf..10ca88cdeeb2de012597e63bc1f77687bc3ef034 100644 (file)
@@ -1584,13 +1584,15 @@ static void sph_evaluate_func(BVHTree *tree, ParticleSystem **psys, float co[3],
                }
        }
 }
-static void sph_density_accum_cb(void *userdata, int index, float squared_dist)
+static void sph_density_accum_cb(void *userdata, int index, const float co[3], float squared_dist)
 {
        SPHRangeData *pfr = (SPHRangeData *)userdata;
        ParticleData *npa = pfr->npsys->particles + index;
        float q;
        float dist;
 
+       UNUSED_VARS(co);
+
        if (npa == pfr->pa || squared_dist < FLT_EPSILON)
                return;
 
@@ -1767,7 +1769,7 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa
        sphdata->pass++;
 }
 
-static void sphclassical_density_accum_cb(void *userdata, int index, float UNUSED(squared_dist))
+static void sphclassical_density_accum_cb(void *userdata, int index, const float co[3], float UNUSED(squared_dist))
 {
        SPHRangeData *pfr = (SPHRangeData *)userdata;
        ParticleData *npa = pfr->npsys->particles + index;
@@ -1779,7 +1781,7 @@ static void sphclassical_density_accum_cb(void *userdata, int index, float UNUSE
        /* Exclude particles that are more than 2h away. Can't use squared_dist here
         * because it is not accurate enough. Use current state, i.e. the output of
         * basic_integrate() - z0r */
-       sub_v3_v3v3(vec, npa->state.co, pfr->pa->state.co);
+       sub_v3_v3v3(vec, npa->state.co, co);
        rij = len_v3(vec);
        rij_h = rij / pfr->h;
        if (rij_h > 2.0f)
@@ -1798,7 +1800,7 @@ static void sphclassical_density_accum_cb(void *userdata, int index, float UNUSE
        pfr->data[1] += q / npa->sphdensity;
 }
 
-static void sphclassical_neighbour_accum_cb(void *userdata, int index, float UNUSED(squared_dist))
+static void sphclassical_neighbour_accum_cb(void *userdata, int index, const float co[3], float UNUSED(squared_dist))
 {
        SPHRangeData *pfr = (SPHRangeData *)userdata;
        ParticleData *npa = pfr->npsys->particles + index;
@@ -1811,7 +1813,7 @@ static void sphclassical_neighbour_accum_cb(void *userdata, int index, float UNU
        /* Exclude particles that are more than 2h away. Can't use squared_dist here
         * because it is not accurate enough. Use current state, i.e. the output of
         * basic_integrate() - z0r */
-       sub_v3_v3v3(vec, npa->state.co, pfr->pa->state.co);
+       sub_v3_v3v3(vec, npa->state.co, co);
        rij = len_v3(vec);
        rij_h = rij / pfr->h;
        if (rij_h > 2.0f)
index f1ef1d9f9b944b0432770ec701e40f698da12348..be792669ef122df922ef335ae90d3e7fd6f017f6 100644 (file)
@@ -102,7 +102,7 @@ typedef void (*BVHTree_NearestToRayCallback)(void *userdata, int index, const BV
 typedef bool (*BVHTree_OverlapCallback)(void *userdata, int index_a, int index_b, int thread);
 
 /* callback to range search query */
-typedef void (*BVHTree_RangeQuery)(void *userdata, int index, float dist_sq);
+typedef void (*BVHTree_RangeQuery)(void *userdata, int index, const float co[3], float dist_sq);
 
 
 /* callbacks to BLI_bvhtree_walk_dfs */
index 22862b8e0d704c8b525cd04043767432ed05c75d..bba3fdb37bc9f86715012be5c4f300aacdaf04a0 100644 (file)
@@ -2009,7 +2009,7 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node)
                                /* Its a leaf.. call the callback */
                                if (node->children[i]->totnode == 0) {
                                        data->hits++;
-                                       data->callback(data->userdata, node->children[i]->index, dist_sq);
+                                       data->callback(data->userdata, node->children[i]->index, data->center, dist_sq);
                                }
                                else
                                        dfs_range_query(data, node->children[i]);
@@ -2040,7 +2040,7 @@ int BLI_bvhtree_range_query(
                        /* Its a leaf.. call the callback */
                        if (root->totnode == 0) {
                                data.hits++;
-                               data.callback(data.userdata, root->index, dist_sq);
+                               data.callback(data.userdata, root->index, co, dist_sq);
                        }
                        else
                                dfs_range_query(&data, root);
index 52c9edbef6eb5dada10ce597c6cf2a63c60e48e1..91ae29afea3356d436c89c58a566052fff84defe 100644 (file)
@@ -435,12 +435,14 @@ typedef struct PointDensityRangeData {
        float velscale;
 } PointDensityRangeData;
 
-static void accum_density(void *userdata, int index, float squared_dist)
+static void accum_density(void *userdata, int index, const float co[3], float squared_dist)
 {
        PointDensityRangeData *pdr = (PointDensityRangeData *)userdata;
        const float dist = (pdr->squared_radius - squared_dist) / pdr->squared_radius * 0.5f;
        float density = 0.0f;
 
+       UNUSED_VARS(co);
+
        if (pdr->point_data_used & POINT_DATA_VEL) {
                pdr->vec[0] += pdr->point_data[index * 3 + 0]; // * density;
                pdr->vec[1] += pdr->point_data[index * 3 + 1]; // * density;