[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16876] branches/sim_physics/source/ blender: * Re-coded the point density range checking to be a bit cleaner, and
Matt Ebb
matt at mke3.net
Thu Oct 2 03:38:20 CEST 2008
Revision: 16876
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16876
Author: broken
Date: 2008-10-02 03:38:12 +0200 (Thu, 02 Oct 2008)
Log Message:
-----------
* Re-coded the point density range checking to be a bit cleaner, and
not necessary to modify the BVH functions.
Modified Paths:
--------------
branches/sim_physics/source/blender/blenkernel/intern/texture.c
branches/sim_physics/source/blender/blenlib/BLI_kdopbvh.h
branches/sim_physics/source/blender/blenlib/intern/BLI_kdopbvh.c
branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
branches/sim_physics/source/blender/render/intern/source/pointdensity.c
Modified: branches/sim_physics/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/sim_physics/source/blender/blenkernel/intern/texture.c 2008-10-02 01:12:37 UTC (rev 16875)
+++ branches/sim_physics/source/blender/blenkernel/intern/texture.c 2008-10-02 01:38:12 UTC (rev 16876)
@@ -877,7 +877,7 @@
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 @@
pdn= MEM_dupallocN(pd);
pdn->point_tree = NULL;
- //pdn->point_data = NULL;
+ pdn->point_data = NULL;
return pd;
}
@@ -899,12 +899,10 @@
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)
Modified: branches/sim_physics/source/blender/blenlib/BLI_kdopbvh.h
===================================================================
--- branches/sim_physics/source/blender/blenlib/BLI_kdopbvh.h 2008-10-02 01:12:37 UTC (rev 16875)
+++ branches/sim_physics/source/blender/blenlib/BLI_kdopbvh.h 2008-10-02 01:38:12 UTC (rev 16876)
@@ -72,7 +72,7 @@
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);
Modified: branches/sim_physics/source/blender/blenlib/intern/BLI_kdopbvh.c
===================================================================
--- branches/sim_physics/source/blender/blenlib/intern/BLI_kdopbvh.c 2008-10-02 01:12:37 UTC (rev 16875)
+++ branches/sim_physics/source/blender/blenlib/intern/BLI_kdopbvh.c 2008-10-02 01:38:12 UTC (rev 16876)
@@ -1570,7 +1570,7 @@
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 @@
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 );
Modified: branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_texture_types.h 2008-10-02 01:12:37 UTC (rev 16875)
+++ branches/sim_physics/source/blender/makesdna/DNA_texture_types.h 2008-10-02 01:38:12 UTC (rev 16876)
@@ -144,8 +144,8 @@
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;
Modified: branches/sim_physics/source/blender/render/intern/source/pointdensity.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/pointdensity.c 2008-10-02 01:12:37 UTC (rev 16875)
+++ branches/sim_physics/source/blender/render/intern/source/pointdensity.c 2008-10-02 01:38:12 UTC (rev 16876)
@@ -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 @@
pd->point_tree = NULL;
}
- /*
if (pd->point_data) {
MEM_freeN(pd->point_data);
pd->point_data = NULL;
}
- */
}
@@ -226,51 +227,37 @@
}
}
-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;
-
- *density+= dist;
-}
+ float *density;
+ float squared_radius;
+ float *point_data;
+ short falloff_type;
+} PointDensityRangeData;
-void accum_density_smooth(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;
+ PointDensityRangeData *pdr = (PointDensityRangeData *)userdata;
+ const float dist = pdr->squared_radius - squared_dist;
- *density+= 3.0f*dist*dist - 2.0f*dist*dist*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_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,17 +265,13 @@
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;
/*
More information about the Bf-blender-cvs
mailing list