[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17695] branches/projection-paint/source/ blender/src/imagepaint.c: * remove warnings

Campbell Barton ideasman42 at gmail.com
Wed Dec 3 17:18:02 CET 2008


Revision: 17695
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17695
Author:   campbellbarton
Date:     2008-12-03 17:17:59 +0100 (Wed, 03 Dec 2008)

Log Message:
-----------
* remove warnings
* style fits with blenders more
* use rctf and rcti and rctf types rather then float[4]
* some loops were confusing, use for loops rather then while or do/while

Modified Paths:
--------------
    branches/projection-paint/source/blender/src/imagepaint.c

Modified: branches/projection-paint/source/blender/src/imagepaint.c
===================================================================
--- branches/projection-paint/source/blender/src/imagepaint.c	2008-12-03 15:49:41 UTC (rev 17694)
+++ branches/projection-paint/source/blender/src/imagepaint.c	2008-12-03 16:17:59 UTC (rev 17695)
@@ -181,12 +181,6 @@
 /* vert flags */
 #define PROJ_VERT_CULL 1
 
-/* only for readability */
-#define PROJ_BUCKET_LEFT	0
-#define PROJ_BUCKET_RIGHT	1
-#define PROJ_BUCKET_BOTTOM	2
-#define PROJ_BUCKET_TOP		3
-
 /* This is mainly a convenience struct used so we can keep an array of images we use
  * Thir imbufs, etc, in 1 array, When using threads this array is copied for each thread
  * because 'partRedrawRect' and 'touch' values would not be thread safe */
@@ -219,14 +213,14 @@
 	MemArena *arena_mt[BLENDER_MAX_THREADS];		/* Same as above but use for multithreading */
 	LinkNode **bucketRect;				/* screen sized 2D array, each pixel has a linked list of ProjPixel's */
 	LinkNode **bucketFaces;				/* bucketRect alligned array linkList of faces overlapping each bucket */
-	char *bucketFlags;					/* store if the bucks have been initialized  */
+	unsigned char *bucketFlags;					/* store if the bucks have been initialized  */
 #ifndef PROJ_DEBUG_NOSEAMBLEED
 	char *faceSeamFlags;				/* store info about faces, if they are initialized etc*/
 	float (*faceSeamUVs)[4][2];			/* expanded UVs for faces to use as seams */
 	LinkNode **vertFaces;				/* Only needed for when seam_bleed_px is enabled, use to find UV seams */
 	char *vertFlags;					/* store options per vert, now only store if the vert is pointing away from the view */
 #endif
-	int buckets_x;						/* The size of the bucket grid, the grid span's screen_min/screen_max so you can paint outsize the screen or with 2 brushes at once */
+	int buckets_x;						/* The size of the bucket grid, the grid span's screenMin/screenMax so you can paint outsize the screen or with 2 brushes at once */
 	int buckets_y;
 	
 	ProjPaintImage *projImages;
@@ -235,6 +229,11 @@
 	
 	float (*screenCoords)[4];	/* verts projected into floating point screen space */
 	
+	float screenMin[2];			/* 2D bounds for mesh verts on the screen's plane (screenspace) */
+	float screenMax[2]; 
+	float screen_width;			/* Calculated from screenMin & screenMax */
+	float screen_height;
+	
 	/* options for projection painting */
 	short do_occlude;			/* Use raytraced occlusion? - ortherwise will paint right through to the back*/
 	short do_backfacecull;	/* ignore faces with normals pointing away, skips a lot of raycasts if your normals are correctly flipped */
@@ -246,7 +245,7 @@
 	float seam_bleed_px;
 #endif
 	/* clone vars */
-	float clone_offset[2];
+	float cloneOffset[2];
 	int clone_layer;			/* -1 when not in use */
 	
 	float projectMat[4][4];		/* Projection matrix, use for getting screen coords */
@@ -255,15 +254,10 @@
 	float viewPos[3];			/* View location in object relative 3D space, so can compare to verts  */
 	float clipsta, clipend;
 	
-	float screen_min[2];			/* 2D bounds for mesh verts on the screen's plane (screenspace) */
-	float screen_max[2]; 
-	float screen_width;			/* Calculated from screen_min & screen_max */
-	float screen_height;
-	
 	/* threads */
 	int thread_tot;
-	int bucket_min[2];
-	int bucket_max[2];
+	int bucketMin[2];
+	int bucketMax[2];
 	int context_bucket_x, context_bucket_y; /* must lock threads while accessing these */
 } ProjPaintState;
 
@@ -488,14 +482,14 @@
 	 * ps->bucketRect[x + (y*ps->buckets_y)] */
 	
 	/* please explain?
-	 * projCoSS[0] - ps->screen_min[0]	: zero origin
+	 * projCoSS[0] - ps->screenMin[0]	: zero origin
 	 * ... / ps->screen_width				: range from 0.0 to 1.0
 	 * ... * ps->buckets_x		: use as a bucket index
 	 *
 	 * Second multiplication does similar but for vertical offset
 	 */
-	return	(	(int)(( (projCoSS[0] - ps->screen_min[0]) / ps->screen_width)  * ps->buckets_x)) + 
-		(	(	(int)(( (projCoSS[1] - ps->screen_min[1])  / ps->screen_height) * ps->buckets_y)) * ps->buckets_x );
+	return	(	(int)(((projCoSS[0] - ps->screenMin[0]) / ps->screen_width)  * ps->buckets_x)) + 
+		(	(	(int)(((projCoSS[1] - ps->screenMin[1])  / ps->screen_height) * ps->buckets_y)) * ps->buckets_x);
 }
 
 static int project_bucket_offset_safe(const ProjPaintState *ps, const float projCoSS[2])
@@ -504,13 +498,15 @@
 	
 	if (bucket_index < 0 || bucket_index >= ps->buckets_x*ps->buckets_y) {	
 		return -1;
-	} else {
+	}
+	else {
 		return bucket_index;
 	}
 }
 
 /* The point must be inside the triangle */
-static void BarycentricWeightsSimple2f(const float v1[2], const float v2[2], const float v3[2], const float pt[2], float w[3]) {
+static void BarycentricWeightsSimple2f(float v1[2], float v2[2], float v3[2], float pt[2], float w[3])
+{
 	float wtot, wtot_inv;
 	w[0] = AreaF2Dfl(v2, v3, pt);
 	w[1] = AreaF2Dfl(v3, v1, pt);
@@ -521,14 +517,16 @@
 		w[0]*=wtot_inv;
 		w[1]*=wtot_inv;
 		w[2]*=wtot_inv;
-	} else {
+	}
+	else {
 		w[0] = w[1] = w[2] = 1.0/3.0; /* dummy values for zero area face */
 	}
 }
 
 /* also works for points outside the triangle */
-#define SIDE_OF_LINE(pa,pb,pp)	((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1]))
-static void BarycentricWeights2f(const float v1[2], const float v2[2], const float v3[2], const float pt[2], float w[3]) {
+#define SIDE_OF_LINE(pa, pb, pp)	((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1]))
+static void BarycentricWeights2f(float v1[2], float v2[2], float v3[2], float pt[2], float w[3])
+{
 	float wtot_inv, wtot = AreaF2Dfl(v1, v2, v3);
 	if (wtot > 0.0f) {
 		wtot_inv = 1.0f / wtot;
@@ -545,16 +543,18 @@
 
 		if ((SIDE_OF_LINE(v1,v2, pt)>0.0f) != (SIDE_OF_LINE(v1,v2, v3)>0.0f))	w[2]*= -wtot_inv;
 		else																w[2]*=  wtot_inv;
-	} else {
+	}
+	else {
 		w[0] = w[1] = w[2] = 1.0f/3.0f; /* dummy values for zero area face */
 	}
 }
 
 /* still use 2D X,Y space but this works for verts transformed by a perspective matrix, using their 4th component as a weight */
 
-static void BarycentricWeightsPersp2f(const float v1[4], const float v2[4], const float v3[4], const float pt[2], float w[3]) {
+static void BarycentricWeightsPersp2f(float v1[4], float v2[4], float v3[4], float pt[2], float w[3])
+{
 	float persp_tot, persp_tot_inv;
-	BarycentricWeights2f(v1,v2,v3,pt,w);
+	BarycentricWeights2f(v1, v2, v3, pt, w);
 	
 	w[0] /= v1[3];
 	w[1] /= v2[3];
@@ -566,15 +566,16 @@
 		w[0] *= persp_tot_inv;
 		w[1] *= persp_tot_inv;
 		w[2] *= persp_tot_inv;
-	} else {
+	}
+	else {
 		w[0] = w[1] = w[2] = 1.0f/3.0f; /* dummy values for zero area face */
 	}
 }
 
-static void BarycentricWeightsSimplePersp2f(const float v1[4], const float v2[4], const float v3[4], const float pt[2], float w[3])
+static void BarycentricWeightsSimplePersp2f(float v1[4], float v2[4], float v3[4], float pt[2], float w[3])
 {
 	float persp_tot_inv, persp_tot;
-	BarycentricWeightsSimple2f(v1,v2,v3,pt,w);
+	BarycentricWeightsSimple2f(v1, v2, v3, pt, w);
 	
 	w[0] /= v1[3];
 	w[1] /= v2[3];
@@ -586,7 +587,8 @@
 		w[0] *= persp_tot_inv;
 		w[1] *= persp_tot_inv;
 		w[2] *= persp_tot_inv;
-	} else {
+	}
+	else {
 		w[0] = w[1] = w[2] = 1.0f/3.0f; /* dummy values for zero area face */
 	}
 }
@@ -604,15 +606,16 @@
 	p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
 }
 
-static float tri_depth_2d(const float v1[3], const float v2[3], const float v3[3], const float pt[2], float w[3])
+static float tri_depth_2d(float v1[3], float v2[3], float v3[3], float pt[2], float w[3])
 {
-	BarycentricWeightsSimple2f(v1,v2,v3,pt,w);
+	BarycentricWeightsSimple2f(v1, v2, v3, pt, w);
 	return (v1[2]*w[0]) + (v2[2]*w[1]) + (v3[2]*w[2]);
 }
 
 
 /* Return the top-most face index that the screen space coord 'pt' touches (or -1) */
-static int project_paint_PickFace(const ProjPaintState *ps, const float pt[2], float w[3], int *side) {
+static int project_paint_PickFace(const ProjPaintState *ps, float pt[2], float w[3], int *side)
+{
 	LinkNode *node;
 	float w_tmp[3];
 	float *v1, *v2, *v3, *v4;
@@ -627,42 +630,41 @@
 	if (bucket_index==-1)
 		return -1;
 	
-	node = ps->bucketFaces[bucket_index];
 	
+	
 	/* we could return 0 for 1 face buckets, as long as this function assumes
 	 * that the point its testing is only every originated from an existing face */
 	
-	while (node) {
-		face_index = (int)node->link;
-		mf = ps->dm_mface + face_index;
+	for (node= ps->bucketFaces[bucket_index]; node; node= node->next) {
+		face_index = GET_INT_FROM_POINTER(node->link);
+		mf= ps->dm_mface + face_index;
 		
-		v1 = ps->screenCoords[mf->v1];
-		v2 = ps->screenCoords[mf->v2];
-		v3 = ps->screenCoords[mf->v3];
+		v1= ps->screenCoords[mf->v1];
+		v2= ps->screenCoords[mf->v2];
+		v3= ps->screenCoords[mf->v3];
 		
-		if ( IsectPT2Df(pt, v1, v2, v3) ) {
-			z_depth = tri_depth_2d(v1,v2,v3,pt,w_tmp);
+		if (IsectPT2Df(pt, v1, v2, v3)) {
+			z_depth= tri_depth_2d(v1, v2, v3, pt, w_tmp);
 			if (z_depth < z_depth_best) {
 				best_face_index = face_index;
 				best_side = 0;
 				z_depth_best = z_depth;
 				VECCOPY(w, w_tmp);
 			}
-		} else if (mf->v4) {
-			v4 = ps->screenCoords[mf->v4];
+		}
+		else if (mf->v4) {
+			v4= ps->screenCoords[mf->v4];
 			
-			if ( IsectPT2Df(pt, v1, v3, v4) ) {
-				z_depth = tri_depth_2d(v1,v3,v4,pt,w_tmp);
+			if (IsectPT2Df(pt, v1, v3, v4)) {
+				z_depth= tri_depth_2d(v1, v3, v4, pt, w_tmp);
 				if (z_depth < z_depth_best) {
 					best_face_index = face_index;
-					best_side = 1;
+					best_side= 1;
 					z_depth_best = z_depth;
 					VECCOPY(w, w_tmp);
 				}
 			}
 		}
-		
-		node = node->next;
 	}
 	
 	*side = best_side;
@@ -670,17 +672,17 @@
 }
 
 /* Set the top-most face color that the screen space coord 'pt' touches (or return 0 if none touch) */
-static int project_paint_PickColor(const ProjPaintState *ps, const float pt[2], float *rgba_fp, unsigned char *rgba, const int interp)
+static int project_paint_PickColor(const ProjPaintState *ps, float pt[2], float *rgba_fp, unsigned char *rgba, const int interp)
 {
 	float w[3], uv[2];
 	int side;
 	int face_index;
 	MTFace *tf;
 	ImBuf *ibuf;
-	int xi,yi;
+	int xi, yi;
 	
 	
-	face_index = project_paint_PickFace(ps,pt,w, &side);
+	face_index = project_paint_PickFace(ps, pt, w, &side);
 	
 	if (face_index == -1)
 		return 0;
@@ -689,7 +691,8 @@
 	
 	if (side == 0) {
 		Vec2Weightf(uv, tf->uv[0], tf->uv[1], tf->uv[2], w);
-	} else { /* QUAD */
+	}
+	else { /* QUAD */
 		Vec2Weightf(uv, tf->uv[0], tf->uv[2], tf->uv[3], w);
 	}
 	
@@ -698,7 +701,7 @@
 
 	
 	if (interp) {
-		float x,y;
+		float x, y;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list