diff options
-rw-r--r-- | source/blender/blenkernel/intern/texture.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_kdopbvh.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_kdopbvh.c | 4 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_texture_types.h | 4 | ||||
-rw-r--r-- | source/blender/render/intern/source/pointdensity.c | 77 |
5 files changed, 37 insertions, 56 deletions
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index ec34fcf4103..7b558008a92 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -877,7 +877,7 @@ PointDensity *BKE_add_pointdensity(void) pd->falloff_type = TEX_PD_FALLOFF_STD; pd->source = TEX_PD_PSYS; pd->point_tree = NULL; - //pd->point_data = NULL; + pd->point_data = NULL; return pd; } @@ -888,7 +888,7 @@ PointDensity *BKE_copy_pointdensity(PointDensity *pd) pdn= MEM_dupallocN(pd); pdn->point_tree = NULL; - //pdn->point_data = NULL; + pdn->point_data = NULL; return pd; } @@ -899,12 +899,10 @@ void BKE_free_pointdensitydata(PointDensity *pd) BLI_bvhtree_free(pd->point_tree); pd->point_tree = NULL; } - /* if (pd->point_data) { MEM_freeN(pd->point_data); pd->point_data = NULL; } - */ } void BKE_free_pointdensity(PointDensity *pd) diff --git a/source/blender/blenlib/BLI_kdopbvh.h b/source/blender/blenlib/BLI_kdopbvh.h index 8912ac5bd13..dabf12d48d3 100644 --- a/source/blender/blenlib/BLI_kdopbvh.h +++ b/source/blender/blenlib/BLI_kdopbvh.h @@ -72,7 +72,7 @@ typedef void (*BVHTree_NearestPointCallback) (void *userdata, int index, const f typedef void (*BVHTree_RayCastCallback) (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit); /* callback to range search query */ -typedef void (*BVHTree_RangeQuery) (void *userdata, int index, float squared_dist, float radius); +typedef void (*BVHTree_RangeQuery) (void *userdata, int index, float squared_dist); BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis); diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index f82b6b7f162..df37ff457f6 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -1570,7 +1570,7 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node) if(node->children[i]->totnode == 0) { data->hits++; - data->callback( data->userdata, node->children[i]->index, dist, data->radius ); + data->callback( data->userdata, node->children[i]->index, dist ); } else dfs_range_query( data, node->children[i] ); @@ -1602,7 +1602,7 @@ int BLI_bvhtree_range_query(BVHTree *tree, const float *co, float radius, BVHTre if(root->totnode == 0) { data.hits++; - data.callback( data.userdata, root->index, dist, data.radius ); + data.callback( data.userdata, root->index, dist ); } else dfs_range_query( &data, root ); diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h index 9c608302b22..95bacbbd4c6 100644 --- a/source/blender/makesdna/DNA_texture_types.h +++ b/source/blender/makesdna/DNA_texture_types.h @@ -144,8 +144,8 @@ typedef struct PointDensity { short pdpad2; void *point_tree; /* the acceleration tree containing points */ - //void *point_data; /* dynamically allocated extra for extra information, like particle age */ - //int pdpad3; + void *point_data; /* dynamically allocated extra for extra information, like particle age */ + int pdpad3[2]; } PointDensity; diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c index a3f174be68b..7998fa82836 100644 --- a/source/blender/render/intern/source/pointdensity.c +++ b/source/blender/render/intern/source/pointdensity.c @@ -23,9 +23,12 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include <math.h> #include <stdlib.h> #include <stdio.h> +#include "MEM_guardedalloc.h" + #include "BLI_arithb.h" #include "BLI_kdopbvh.h" @@ -185,12 +188,10 @@ static void free_pointdensity(Render *re, Tex *tex) pd->point_tree = NULL; } - /* if (pd->point_data) { MEM_freeN(pd->point_data); pd->point_data = NULL; } - */ } @@ -226,51 +227,37 @@ void free_pointdensities(Render *re) } } -void accum_density_std(void *userdata, int index, float squared_dist, float squared_radius) -{ - float *density = userdata; - const float dist = squared_radius - squared_dist; - - *density+= dist; -} - -void accum_density_smooth(void *userdata, int index, float squared_dist, float squared_radius) -{ - float *density = userdata; - const float dist = squared_radius - squared_dist; - - *density+= 3.0f*dist*dist - 2.0f*dist*dist*dist; -} - -void accum_density_sharp(void *userdata, int index, float squared_dist, float squared_radius) -{ - float *density = userdata; - const float dist = squared_radius - squared_dist; - - *density+= dist*dist; -} - -void accum_density_constant(void *userdata, int index, float squared_dist, float squared_radius) +typedef struct PointDensityRangeData { - float *density = userdata; - - *density+= squared_radius; -} + float *density; + float squared_radius; + float *point_data; + short falloff_type; +} PointDensityRangeData; -void accum_density_root(void *userdata, int index, float squared_dist, float squared_radius) +void accum_density(void *userdata, int index, float squared_dist) { - float *density = userdata; - const float dist = squared_radius - squared_dist; - - *density+= sqrt(dist); + PointDensityRangeData *pdr = (PointDensityRangeData *)userdata; + const float dist = pdr->squared_radius - squared_dist; + + if (pdr->falloff_type == TEX_PD_FALLOFF_STD) + *pdr->density += dist; + else if (pdr->falloff_type == TEX_PD_FALLOFF_SMOOTH) + *pdr->density+= 3.0f*dist*dist - 2.0f*dist*dist*dist; + else if (pdr->falloff_type == TEX_PD_FALLOFF_SHARP) + *pdr->density+= dist*dist; + else if (pdr->falloff_type == TEX_PD_FALLOFF_CONSTANT) + *pdr->density+= pdr->squared_radius; + else if (pdr->falloff_type == TEX_PD_FALLOFF_ROOT) + *pdr->density+= sqrt(dist); } - #define MAX_POINTS_NEAREST 25 int pointdensitytex(Tex *tex, float *texvec, TexResult *texres) { int rv = TEX_INT; PointDensity *pd = tex->pd; + PointDensityRangeData pdr; float density=0.0f; if ((!pd) || (!pd->point_tree)) { @@ -278,16 +265,12 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres) return 0; } - if (pd->falloff_type == TEX_PD_FALLOFF_STD) - BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density_std, &density); - else if (pd->falloff_type == TEX_PD_FALLOFF_SMOOTH) - BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density_smooth, &density); - else if (pd->falloff_type == TEX_PD_FALLOFF_SHARP) - BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density_sharp, &density); - else if (pd->falloff_type == TEX_PD_FALLOFF_CONSTANT) - BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density_constant, &density); - else if (pd->falloff_type == TEX_PD_FALLOFF_ROOT) - BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density_root, &density); + pdr.squared_radius = pd->radius*pd->radius; + pdr.density = &density; + pdr.point_data = pd->point_data; + pdr.falloff_type = pd->falloff_type; + + BLI_bvhtree_range_query(pd->point_tree, texvec, pd->radius, accum_density, &pdr); texres->tin = density; |