[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42360] trunk/blender/source/blender: de-duplicate dominant axis calculation, exact same checks were in 6 different places.

Campbell Barton ideasman42 at gmail.com
Fri Dec 2 23:14:21 CET 2011


Revision: 42360
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42360
Author:   campbellbarton
Date:     2011-12-02 22:14:20 +0000 (Fri, 02 Dec 2011)
Log Message:
-----------
de-duplicate dominant axis calculation, exact same checks were in 6 different places.
added function:  axis_dominant_v3(...)

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/blenlib/intern/scanfill.c
    trunk/blender/source/blender/editors/uvedit/uvedit_unwrap_ops.c
    trunk/blender/source/blender/render/intern/source/rayshade.c
    trunk/blender/source/blender/render/intern/source/render_texture.c
    trunk/blender/source/blender/render/intern/source/shadeinput.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h	2011-12-02 22:10:36 UTC (rev 42359)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h	2011-12-02 22:14:20 UTC (rev 42360)
@@ -260,6 +260,8 @@
 float form_factor_hemi_poly(float p[3], float n[3],
 	float v1[3], float v2[3], float v3[3], float v4[3]);
 
+void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3]);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2011-12-02 22:10:36 UTC (rev 42359)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2011-12-02 22:14:20 UTC (rev 42360)
@@ -133,7 +133,8 @@
 	float *cur, *prev;
 	int a, px=0, py=1;
 
-	/* first: find dominant axis: 0==X, 1==Y, 2==Z */
+	/* first: find dominant axis: 0==X, 1==Y, 2==Z
+	 * don't use 'axis_dominant_v3()' because we need max axis too */
 	x= fabsf(normal[0]);
 	y= fabsf(normal[1]);
 	z= fabsf(normal[2]);
@@ -1689,6 +1690,18 @@
 
 /****************************** Interpolation ********************************/
 
+/* get the 2 dominant axis values, 0==X, 1==Y, 2==Z */
+void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3])
+{
+	const float xn= fabsf(axis[0]);
+	const float yn= fabsf(axis[1]);
+	const float zn= fabsf(axis[2]);
+
+	if      (zn >= xn && zn >= yn) { *axis_a= 0; *axis_b= 1; }
+	else if (yn >= xn && yn >= zn) { *axis_a= 0; *axis_b= 2; }
+	else                           { *axis_a= 1; *axis_b= 2; }
+}
+
 static float tri_signed_area(const float v1[3], const float v2[3], const float v3[3], const int i, const int j)
 {
 	return 0.5f*((v1[i]-v2[i])*(v2[j]-v3[j]) + (v1[j]-v2[j])*(v3[i]-v2[i]));
@@ -1696,17 +1709,10 @@
 
 static int barycentric_weights(const float v1[3], const float v2[3], const float v3[3], const float co[3], const float n[3], float w[3])
 {
-	float xn, yn, zn, a1, a2, a3, asum;
-	short i, j;
+	float a1, a2, a3, asum;
+	int i, j;
 
-	/* find best projection of face XY, XZ or YZ: barycentric weights of
-	   the 2d projected coords are the same and faster to compute */
-	xn= fabsf(n[0]);
-	yn= fabsf(n[1]);
-	zn= fabsf(n[2]);
-	if(zn>=xn && zn>=yn) {i= 0; j= 1;}
-	else if(yn>=xn && yn>=zn) {i= 0; j= 2;}
-	else {i= 1; j= 2;} 
+	axis_dominant_v3(&i, &j, n);
 
 	a1= tri_signed_area(v2, v3, co, i, j);
 	a2= tri_signed_area(v3, v1, co, i, j);

Modified: trunk/blender/source/blender/blenlib/intern/scanfill.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/scanfill.c	2011-12-02 22:10:36 UTC (rev 42359)
+++ trunk/blender/source/blender/blenlib/intern/scanfill.c	2011-12-02 22:14:20 UTC (rev 42360)
@@ -96,7 +96,7 @@
 ListBase filledgebase = {NULL, NULL};
 ListBase fillfacebase = {NULL, NULL};
 
-static short cox, coy;
+static int cox, coy;
 
 /* ****  FUBCTIONS FOR QSORT *************************** */
 
@@ -825,19 +825,7 @@
 
 	if(len==0.0f) return 0;	/* no fill possible */
 
-	norm[0]= fabs(norm[0]);
-	norm[1]= fabs(norm[1]);
-	norm[2]= fabs(norm[2]);
-	
-	if(norm[2]>=norm[0] && norm[2]>=norm[1]) {
-		cox= 0; coy= 1;
-	}
-	else if(norm[1]>=norm[0] && norm[1]>=norm[2]) {
-		cox= 0; coy= 2;
-	}
-	else {
-		cox= 1; coy= 2;
-	}
+	axis_dominant_v3(&cox, &coy, norm);
 
 	/* STEP 1: COUNT POLYS */
 	eve= fillvertbase.first;

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_unwrap_ops.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_unwrap_ops.c	2011-12-02 22:10:36 UTC (rev 42359)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_unwrap_ops.c	2011-12-02 22:14:20 UTC (rev 42360)
@@ -1342,16 +1342,9 @@
 		if(efa->f & SELECT) {
 			tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
 			normal_tri_v3( no,efa->v1->co, efa->v2->co, efa->v3->co);
-			
-			no[0]= fabs(no[0]);
-			no[1]= fabs(no[1]);
-			no[2]= fabs(no[2]);
-			
-			cox=0; coy= 1;
-			if(no[2]>=no[0] && no[2]>=no[1]);
-			else if(no[1]>=no[0] && no[1]>=no[2]) coy= 2;
-			else { cox= 1; coy= 2; }
-			
+
+			axis_dominant_v3(&cox, &coy, no);
+
 			tf->uv[0][0]= 0.5f+0.5f*cube_size*(loc[cox] + efa->v1->co[cox]);
 			tf->uv[0][1]= 0.5f+0.5f*cube_size*(loc[coy] + efa->v1->co[coy]);
 			dx = floor(tf->uv[0][0]);

Modified: trunk/blender/source/blender/render/intern/source/rayshade.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/rayshade.c	2011-12-02 22:10:36 UTC (rev 42359)
+++ trunk/blender/source/blender/render/intern/source/rayshade.c	2011-12-02 22:14:20 UTC (rev 42360)
@@ -485,18 +485,12 @@
 /* 	if(shi->osatex)  */
 static void shade_ray_set_derivative(ShadeInput *shi)
 {
-	float detsh, t00, t10, t01, t11, xn, yn, zn;
+	float detsh, t00, t10, t01, t11;
 	int axis1, axis2;
 
 	/* find most stable axis to project */
-	xn= fabs(shi->facenor[0]);
-	yn= fabs(shi->facenor[1]);
-	zn= fabs(shi->facenor[2]);
-	
-	if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
-	else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
-	else { axis1= 1; axis2= 2; }
-	
+	axis_dominant_v3(&axis1, &axis2, shi->facenor);
+
 	/* compute u,v and derivatives */
 	if(shi->obi->flag & R_TRANSFORMED) {
 		float v1[3], v2[3], v3[3];

Modified: trunk/blender/source/blender/render/intern/source/render_texture.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/render_texture.c	2011-12-02 22:10:36 UTC (rev 42359)
+++ trunk/blender/source/blender/render/intern/source/render_texture.c	2011-12-02 22:14:20 UTC (rev 42360)
@@ -3494,18 +3494,12 @@
 static void textured_face_generate_uv(float *uv, float *normal, float *hit, float *v1, float *v2, float *v3)
 {
 
-	float detsh, t00, t10, t01, t11, xn, yn, zn;
+	float detsh, t00, t10, t01, t11;
 	int axis1, axis2;
 
 	/* find most stable axis to project */
-	xn= fabs(normal[0]);
-	yn= fabs(normal[1]);
-	zn= fabs(normal[2]);
+	axis_dominant_v3(&axis1, &axis2, normal);
 
-	if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
-	else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
-	else { axis1= 1; axis2= 2; }
-
 	/* compute u,v and derivatives */
 	t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];
 	t10= v3[axis1]-v2[axis1]; t11= v3[axis2]-v2[axis2];

Modified: trunk/blender/source/blender/render/intern/source/shadeinput.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/shadeinput.c	2011-12-02 22:10:36 UTC (rev 42359)
+++ trunk/blender/source/blender/render/intern/source/shadeinput.c	2011-12-02 22:14:20 UTC (rev 42360)
@@ -756,18 +756,12 @@
 		}
 		else {
 			/* most of this could become re-used for faces */
-			float detsh, t00, t10, t01, t11, xn, yn, zn;
+			float detsh, t00, t10, t01, t11;
 			int axis1, axis2;
 
 			/* find most stable axis to project */
-			xn= fabs(shi->facenor[0]);
-			yn= fabs(shi->facenor[1]);
-			zn= fabs(shi->facenor[2]);
+			axis_dominant_v3(&axis1, &axis2, shi->facenor);
 
-			if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
-			else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
-			else { axis1= 1; axis2= 2; }
-
 			/* compute u,v and derivatives */
 			t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];
 			t10= v3[axis1]-v2[axis1]; t11= v3[axis2]-v2[axis2];




More information about the Bf-blender-cvs mailing list