[Bf-blender-cvs] [1f58bfb] master: Code cleanup: de-duplicate cotangent weight function & add arg sizes

Campbell Barton noreply at git.blender.org
Sun Mar 30 01:10:11 CET 2014


Commit: 1f58bfb8bebf207d3020ff474ac5e018c8179f25
Author: Campbell Barton
Date:   Sun Mar 30 11:08:33 2014 +1100
https://developer.blender.org/rB1f58bfb8bebf207d3020ff474ac5e018c8179f25

Code cleanup: de-duplicate cotangent weight function & add arg sizes

===================================================================

M	intern/ghost/test/multitest/MultiTest.c
M	source/blender/blenkernel/BKE_fcurve.h
M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/BLI_noise.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/blenlib/intern/noise.c
M	source/blender/bmesh/operators/bmo_smooth_laplacian.c
M	source/blender/editors/armature/meshlaplacian.c
M	source/blender/editors/armature/reeb.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/space_clip/clip_graph_ops.c
M	source/blender/editors/space_node/node_draw.c
M	source/blender/editors/transform/transform.h
M	source/blender/modifiers/intern/MOD_laplaciandeform.c
M	source/blender/modifiers/intern/MOD_laplaciansmooth.c
M	source/blender/modifiers/intern/MOD_meshdeform.c

===================================================================

diff --git a/intern/ghost/test/multitest/MultiTest.c b/intern/ghost/test/multitest/MultiTest.c
index 8fb46ff..9a192c1 100644
--- a/intern/ghost/test/multitest/MultiTest.c
+++ b/intern/ghost/test/multitest/MultiTest.c
@@ -74,7 +74,7 @@ void multitestapp_exit(MultiTestApp *app);
 
 /**/
 
-void rect_bevel_side(int rect[2][2], int side, float *lt, float *dk, float *col, int width)
+void rect_bevel_side(int rect[2][2], int side, float *lt, float *dk, const float col[3], int width)
 {
 	int ltidx = (side / 2) % 4;
 	int dkidx = (ltidx + 1 + (side & 1)) % 4;
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index 13eca50..046bb8e 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -250,7 +250,7 @@ void testhandles_fcurve(struct FCurve *fcu, const bool use_handle);
 void sort_time_fcurve(struct FCurve *fcu);
 short test_time_fcurve(struct FCurve *fcu);
 
-void correct_bezpart(float *v1, float *v2, float *v3, float *v4);
+void correct_bezpart(float v1[2], float v2[2], float v3[2], float v4[2]);
 
 /* -------- Evaluation --------  */
 
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 2ad6c54..c1a76b6 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -129,7 +129,7 @@ bool BKE_boundbox_ray_hit_check(struct BoundBox *bb, const float ray_start[3], c
 
 struct BoundBox *BKE_object_boundbox_get(struct Object *ob);
 void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
-void BKE_object_dimensions_set(struct Object *ob, const float *value);
+void BKE_object_dimensions_set(struct Object *ob, const float value[3]);
 void BKE_object_empty_draw_type_set(struct Object *ob, const int value);
 void BKE_object_boundbox_flag(struct Object *ob, int flag, int set);
 void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 0ce2953..d564025 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -1929,7 +1929,8 @@ static int vergxcobev(const void *a1, const void *a2)
 
 /* this function cannot be replaced with atan2, but why? */
 
-static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *sina, float *cosa)
+static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2,
+                               float *r_sina, float *r_cosa)
 {
 	float t01, t02, x3, y3;
 
@@ -1967,8 +1968,8 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
 		y3 /= t01;
 	}
 
-	*sina = -y3 / t02;
-	*cosa = x3 / t02;
+	*r_sina = -y3 / t02;
+	*r_cosa =  x3 / t02;
 
 }
 
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 88bd7d7..be91cb5 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2519,7 +2519,7 @@ void BKE_object_dimensions_get(Object *ob, float vec[3])
 	}
 }
 
-void BKE_object_dimensions_set(Object *ob, const float *value)
+void BKE_object_dimensions_set(Object *ob, const float value[3])
 {
 	BoundBox *bb = NULL;
 	
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 29ebf9f..7dcee51 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -57,6 +57,7 @@ float area_tri_signed_v3(const float v1[3], const float v2[3], const float v3[3]
 float area_quad_v3(const float a[3], const float b[3], const float c[3], const float d[3]);
 float area_poly_v3(const float verts[][3], unsigned int nr, const float normal[3]);
 float area_poly_v2(const float verts[][2], unsigned int nr);
+float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float v3[3]);
 
 MINLINE float cross_tri_v2(const float v1[2], const float v2[2], const float v3[2]);
 float cross_poly_v2(const float verts[][2], unsigned int nr);
diff --git a/source/blender/blenlib/BLI_noise.h b/source/blender/blenlib/BLI_noise.h
index d9457fb..f3292d2 100644
--- a/source/blender/blenlib/BLI_noise.h
+++ b/source/blender/blenlib/BLI_noise.h
@@ -57,7 +57,7 @@ float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity
 void voronoi(float x, float y, float z, float *da, float *pa, float me, int dtype);
 /* newnoise: cellNoise & cellNoiseV (for vector/point/color) */
 float cellNoise(float x, float y, float z);
-void cellNoiseV(float x, float y, float z, float *ca);
+void cellNoiseV(float x, float y, float z, float r_ca[3]);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 7665b8e..71a6e19 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -179,6 +179,24 @@ float area_poly_v2(const float verts[][2], unsigned int nr)
 	return fabsf(0.5f * cross_poly_v2(verts, nr));
 }
 
+float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float v3[3])
+{
+	float a[3], b[3], c[3], c_len;
+
+	sub_v3_v3v3(a, v2, v1);
+	sub_v3_v3v3(b, v3, v1);
+	cross_v3_v3v3(c, a, b);
+
+	c_len = len_v3(c);
+
+	if (c_len > FLT_EPSILON) {
+		return dot_v3v3(a, b) / c_len;
+	}
+	else {
+		return 0.0f;
+	}
+}
+
 /********************************* Planes **********************************/
 
 /**
diff --git a/source/blender/blenlib/intern/noise.c b/source/blender/blenlib/intern/noise.c
index 982a74b..f002ea5 100644
--- a/source/blender/blenlib/intern/noise.c
+++ b/source/blender/blenlib/intern/noise.c
@@ -1407,7 +1407,7 @@ float cellNoise(float x, float y, float z)
 }
 
 /* returns a vector/point/color in ca, using point hasharray directly */
-void cellNoiseV(float x, float y, float z, float *ca)
+void cellNoiseV(float x, float y, float z, float ca[3])
 {
 	int xi = (int)(floor(x));
 	int yi = (int)(floor(y));
diff --git a/source/blender/bmesh/operators/bmo_smooth_laplacian.c b/source/blender/bmesh/operators/bmo_smooth_laplacian.c
index e632134..af5f35f 100644
--- a/source/blender/bmesh/operators/bmo_smooth_laplacian.c
+++ b/source/blender/bmesh/operators/bmo_smooth_laplacian.c
@@ -66,7 +66,6 @@ struct BLaplacianSystem {
 };
 typedef struct BLaplacianSystem LaplacianSystem;
 
-static float cotan_weight(float *v1, float *v2, float *v3);
 static bool vert_is_boundary(BMVert *v);
 static LaplacianSystem *init_laplacian_system(int a_numEdges, int a_numFaces, int a_numVerts);
 static void init_laplacian_matrix(LaplacianSystem *sys);
@@ -261,9 +260,9 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
 					v3 = vf[(j + 2) % 4]->co;
 					v4 = vf[(j + 3) % 4]->co;
 
-					w2 = cotan_weight(v4, v1, v2) + cotan_weight(v3, v1, v2);
-					w3 = cotan_weight(v2, v3, v1) + cotan_weight(v4, v1, v3);
-					w4 = cotan_weight(v2, v4, v1) + cotan_weight(v3, v4, v1);
+					w2 = cotangent_tri_weight_v3(v4, v1, v2) + cotangent_tri_weight_v3(v3, v1, v2);
+					w3 = cotangent_tri_weight_v3(v2, v3, v1) + cotangent_tri_weight_v3(v4, v1, v3);
+					w4 = cotangent_tri_weight_v3(v2, v4, v1) + cotangent_tri_weight_v3(v3, v4, v1);
 
 					sys->vweights[idv1] += (w2 + w3 + w4) / 4.0f;
 				}
@@ -271,9 +270,9 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
 			else {
 				i = BM_elem_index_get(f);
 
-				w1 = cotan_weight(v1, v2, v3);
-				w2 = cotan_weight(v2, v3, v1);
-				w3 = cotan_weight(v3, v1, v2);
+				w1 = cotangent_tri_weight_v3(v1, v2, v3);
+				w2 = cotangent_tri_weight_v3(v2, v3, v1);
+				w3 = cotangent_tri_weight_v3(v3, v1, v2);
 
 				sys->fweights[i][0] += w1;
 				sys->fweights[i][1] += w2;
@@ -325,9 +324,9 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
 					v3 = vf[(j + 2) % 4]->co;
 					v4 = vf[(j + 3) % 4]->co;
 
-					w2 = cotan_weight(v4, v1, v2) + cotan_weight(v3, v1, v2);
-					w3 = cotan_weight(v2, v3, v1) + cotan_weight(v4, v1, v3);
-					w4 = cotan_weight(v2, v4, v1) + cotan_weight(v3, v4, v1);
+					w2 = cotangent_tri_weight_v3(v4, v1, v2) + cotangent_tri_weight_v3(v3, v1, v2);
+					w3 = cotangent_tri_weight_v3(v2, v3, v1) + cotangent_tri_weight_v3(v4, v1, v3);
+					w4 = cotangent_tri_weight_v3(v2, v4, v1) + cotangent_tri_weight_v3(v3, v4, v1);
 
 					w2 = w2 / 4.0f;
 					w3 = w3 / 4.0f;
@@ -376,22 +375,6 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
 	}
 }
 
-static float cotan_weight(float *v1, float *v2, float *v3)
-{
-	float a[3], b[3], c[3], clen;
-
-	sub_v3_v3v3(a, v2, v1);
-	sub_v3_v3v3(b, v3, v1);
-	cross_v3_v3v3(c, a, b);
-
-	clen = len_v3(c);
-
-	if (clen == 0.0f)
-		return 0.0f;
-
-	return dot_v3v3(a, b) / clen;
-}
-
 static bool vert_is_boundary(BMVert *v)
 {
 	BMEdge *ed;
diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c
index 017d278..bc47a67 100644
--- a/source/blender/editors/armature/meshlaplacian.c
+++ b/source/blender/editors/armature/meshlaplacian.c
@@ -140,22 +140,6 @@ static int laplacian_edge_count(EdgeHash *edgehash, int v1, int v2)
 	return (int)(intptr_t)BLI_edgehash_lookup(edgehash, v1, v2);
 }
 
-static float cotan_weight(float *v1, float *v2, float *v3)
-{
-	float a[3], b[3], c[3], clen;
-
-	sub_v3_v3v3(a, v2, v1);
-	sub_v3_v3v3(b, v3, v1);
-	cross_v3_v3v3(c, a, b);
-
-	clen = len_v3(c);
-
-	if (clen == 0.0f)
-		return 0.0f;
-	
-	return dot_v3v3(a, b) / clen;
-}
-
 static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3)
 {
 	float t1, t2, t3, len1, len2, len3, area;
@@ -166,9 +150,9 @@ static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3
 	v2 = sys->verts[i2];
 	v3 = sys->verts[i3];
 
-	t1 = cotan_weight(v1, v2, v3);
-	t2 = cotan_weight(v2, v3, v1);
-	t3 = cotan_weight(v3, v1, v2);
+	t1 = cotangent_tri_weight_v3(v1, v2, v3);
+	t2 = cotangent_tri_weight_v3(v2, v3, v1);
+	t3 = cotangent_tri_weight_v3(v3, v1, v2);
 
 	if      (angle_v3v3v3(v2, v1, v3) > DEG2RADF(90.0f)) obtuse = 1;
 	else if (angle_v3v3v3(v1, v2, v3) > DEG2RADF(90.0f)) obtuse = 2;
@@ -207,9 +191,9 @@ static void laplacian_triangle_weights(LaplacianSystem *sys, int f, int i1, int
 
 	/* instead of *0.5 we divided 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list