* Re-coded the point density range checking to be a bit cleaner, and
not necessary to modify the BVH functions.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
typedef struct PointDensityRangeData
|
||||
{
|
||||
float *density = userdata;
|
||||
const float dist = squared_radius - squared_dist;
|
||||
float *density;
|
||||
float squared_radius;
|
||||
float *point_data;
|
||||
short falloff_type;
|
||||
} PointDensityRangeData;
|
||||
|
||||
void accum_density(void *userdata, int index, float squared_dist)
|
||||
{
|
||||
PointDensityRangeData *pdr = (PointDensityRangeData *)userdata;
|
||||
const float dist = pdr->squared_radius - squared_dist;
|
||||
|
||||
*density+= 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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
float *density = userdata;
|
||||
|
||||
*density+= squared_radius;
|
||||
}
|
||||
|
||||
void accum_density_root(void *userdata, int index, float squared_dist, float squared_radius)
|
||||
{
|
||||
float *density = userdata;
|
||||
const float dist = squared_radius - squared_dist;
|
||||
|
||||
*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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user