[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25653] trunk/blender/source/blender: made the array interpolation function from last commit into a generic function
Campbell Barton
ideasman42 at gmail.com
Fri Jan 1 16:57:17 CET 2010
Revision: 25653
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25653
Author: campbellbarton
Date: 2010-01-01 16:57:17 +0100 (Fri, 01 Jan 2010)
Log Message:
-----------
made the array interpolation function from last commit into a generic function
/* given an array with some invalid values this function interpolates valid values
* replacing the invalid ones */
int interp_sparse_array(float *array, int list_size, float skipval)
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_math_geom.h
trunk/blender/source/blender/blenlib/intern/math_geom.c
trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h 2010-01-01 15:48:14 UTC (rev 25652)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h 2010-01-01 15:57:17 UTC (rev 25653)
@@ -121,6 +121,8 @@
void interp_cubic_v3(float x[3], float v[3],
float x1[3], float v1[3], float x2[3], float v2[3], float t);
+int interp_sparse_array(float *array, int list_size, float invalid);
+
void barycentric_transform(float pt_tar[3], float const pt_src[3],
const float tri_tar_p1[3], const float tri_tar_p2[3], const float tri_tar_p3[3],
const float tri_src_p1[3], const float tri_src_p2[3], const float tri_src_p3[3]);
Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c 2010-01-01 15:48:14 UTC (rev 25652)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c 2010-01-01 15:57:17 UTC (rev 25653)
@@ -32,6 +32,7 @@
#include "BLI_math.h"
#include "BLI_memarena.h"
+#include "MEM_guardedalloc.h"
/********************************** Polygons *********************************/
@@ -1408,7 +1409,86 @@
madd_v3_v3v3fl(pt_tar, pt_tar, no_tar, (z_ofs_src / area_src) * area_tar);
}
+/* given an array with some invalid values this function interpolates valid values
+ * replacing the invalid ones */
+int interp_sparse_array(float *array, int list_size, float skipval)
+{
+ int found_invalid = 0;
+ int found_valid = 0;
+ int i;
+ for (i=0; i < list_size; i++) {
+ if(array[i] == skipval)
+ found_invalid= 1;
+ else
+ found_valid= 1;
+ }
+
+ if(found_valid==0) {
+ return -1;
+ }
+ else if (found_invalid==0) {
+ return 0;
+ }
+ else {
+ /* found invalid depths, interpolate */
+ float valid_last= skipval;
+ int valid_ofs= 0;
+
+ float *array_up= MEM_callocN(sizeof(float) * list_size, "interp_sparse_array up");
+ float *array_down= MEM_callocN(sizeof(float) * list_size, "interp_sparse_array up");
+
+ int *ofs_tot_up= MEM_callocN(sizeof(int) * list_size, "interp_sparse_array tup");
+ int *ofs_tot_down= MEM_callocN(sizeof(int) * list_size, "interp_sparse_array tdown");
+
+ for (i=0; i < list_size; i++) {
+ if(array[i] == skipval) {
+ array_up[i]= valid_last;
+ ofs_tot_up[i]= ++valid_ofs;
+ }
+ else {
+ valid_last= array[i];
+ valid_ofs= 0;
+ }
+ }
+
+ valid_last= skipval;
+ valid_ofs= 0;
+
+ for (i=list_size-1; i >= 0; i--) {
+ if(array[i] == skipval) {
+ array_down[i]= valid_last;
+ ofs_tot_down[i]= ++valid_ofs;
+ }
+ else {
+ valid_last= array[i];
+ valid_ofs= 0;
+ }
+ }
+
+ /* now blend */
+ for (i=0; i < list_size; i++) {
+ if(array[i] == skipval) {
+ if(array_up[i] != skipval && array_down[i] != skipval) {
+ array[i]= ((array_up[i] * ofs_tot_down[i]) + (array_down[i] * ofs_tot_up[i])) / (float)(ofs_tot_down[i] + ofs_tot_up[i]);
+ } else if (array_up[i] != skipval) {
+ array[i]= array_up[i];
+ } else if (array_down[i] != skipval) {
+ array[i]= array_down[i];
+ }
+ }
+ }
+
+ MEM_freeN(array_up);
+ MEM_freeN(array_down);
+
+ MEM_freeN(ofs_tot_up);
+ MEM_freeN(ofs_tot_down);
+ }
+
+ return 1;
+}
+
/* Mean value weights - smooth interpolation weights for polygons with
* more than 3 vertices */
static float mean_value_half_tan(float *v1, float *v2, float *v3)
Modified: trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_paint.c 2010-01-01 15:48:14 UTC (rev 25652)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_paint.c 2010-01-01 15:57:17 UTC (rev 25653)
@@ -537,59 +537,7 @@
depth_arr[i] = 0.9999f;
}
else if(interp_depth) {
- /* found invalid depths, interpolate */
- float valid_last= FLT_MAX;
- int valid_ofs= 0;
-
- float *depth_arr_up= MEM_callocN(sizeof(float) * gpd->sbuffer_size, "depth_points_up");
- float *depth_arr_down= MEM_callocN(sizeof(float) * gpd->sbuffer_size, "depth_points_down");
-
- int *depth_tot_up= MEM_callocN(sizeof(int) * gpd->sbuffer_size, "depth_tot_up");
- int *depth_tot_down= MEM_callocN(sizeof(int) * gpd->sbuffer_size, "depth_tot_down");
-
- for (i=0; i < gpd->sbuffer_size; i++) {
- if(depth_arr[i] == FLT_MAX) {
- depth_arr_up[i]= valid_last;
- depth_tot_up[i]= ++valid_ofs;
- }
- else {
- valid_last= depth_arr[i];
- valid_ofs= 0;
- }
- }
-
- valid_last= FLT_MAX;
- valid_ofs= 0;
-
- for (i=gpd->sbuffer_size-1; i >= 0; i--) {
- if(depth_arr[i] == FLT_MAX) {
- depth_arr_down[i]= valid_last;
- depth_tot_down[i]= ++valid_ofs;
- }
- else {
- valid_last= depth_arr[i];
- valid_ofs= 0;
- }
- }
-
- /* now blend */
- for (i=0; i < gpd->sbuffer_size; i++) {
- if(depth_arr[i] == FLT_MAX) {
- if(depth_arr_up[i] != FLT_MAX && depth_arr_down[i] != FLT_MAX) {
- depth_arr[i]= ((depth_arr_up[i] * depth_tot_down[i]) + (depth_arr_down[i] * depth_tot_up[i])) / (float)(depth_tot_down[i] + depth_tot_up[i]);
- } else if (depth_arr_up[i] != FLT_MAX) {
- depth_arr[i]= depth_arr_up[i];
- } else if (depth_arr_down[i] != FLT_MAX) {
- depth_arr[i]= depth_arr_down[i];
- }
- }
- }
-
- MEM_freeN(depth_arr_up);
- MEM_freeN(depth_arr_down);
-
- MEM_freeN(depth_tot_up);
- MEM_freeN(depth_tot_down);
+ interp_sparse_array(depth_arr, gpd->sbuffer_size, FLT_MAX);
}
}
More information about the Bf-blender-cvs
mailing list