[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43165] branches/soc-2011-onion-uv-tools/ source/blender/editors/uvedit/uvedit_smart_stitch.c: smart stitch

Antony Riakiotakis kalast at gmail.com
Thu Jan 5 13:51:23 CET 2012


Revision: 43165
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43165
Author:   psy-fi
Date:     2012-01-05 12:51:22 +0000 (Thu, 05 Jan 2012)
Log Message:
-----------
smart stitch
============

-move edge related code to initialisation, remove from state.

Modified Paths:
--------------
    branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c

Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c	2012-01-05 12:50:23 UTC (rev 43164)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c	2012-01-05 12:51:22 UTC (rev 43165)
@@ -129,11 +129,6 @@
 	int selection_size;
 	/* island that stays in place */
 	int static_island;
-	/* for fast edge lookup... */
-	GHash *edgeHash;
-	/* ...and actual edge storage */
-	UvEdge *edges;
-	int total_edges;
 	/* store number of primitives per face so that we can allocate the active island buffer later */
 	unsigned int *quads_per_island;
 	unsigned int *tris_per_island;
@@ -372,12 +367,6 @@
 		if(stitch_state->map){
 			MEM_freeN(stitch_state->map);
 		}
-		if(stitch_state->edgeHash){
-			BLI_ghash_free(stitch_state->edgeHash, NULL, NULL);
-		}
-		if(stitch_state->edges){
-			MEM_freeN(stitch_state->edges);
-		}
 		if(stitch_state->quads_per_island){
 			MEM_freeN(stitch_state->quads_per_island);
 		}
@@ -825,11 +814,16 @@
 
 static int stitch_init(bContext *C, wmOperator *op)
 {
+	/* for fast edge lookup... */
+	GHash *edgeHash;
+	/* ...and actual edge storage */
+	UvEdge *edges;
+	int total_edges;
 	int counter = 0, i;
 	EditFace *efa;
 	EditMesh *em;
 	GHashIterator* ghi;
-	UvEdge *edges;
+	UvEdge *all_edges;
 	StitchState *state = MEM_mallocN(sizeof(StitchState), "stitch state");
 	Scene *scene = CTX_data_scene(C);
 	ToolSettings *ts = scene->toolsettings;
@@ -877,11 +871,11 @@
 	 * unique uvs for processing but I am accounting for all bizarre cases, especially for edges, this way */
 	state->selection_stack = MEM_mallocN(sizeof(*state->selection_stack)*state->element_map->totalUVs, "uv_stitch_selection_stack");
 	state->map = MEM_mallocN(sizeof(*state->map)*state->element_map->totalUVs, "uv_stitch_unique_map");
-	/* Allcate the edge stack */
-	state->edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "stitch_edge_hash");
-	edges = MEM_mallocN(sizeof(*edges)*state->element_map->totalUVs, "stitch_all_edges");
+	/* Allocate the edge stack */
+	edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "stitch_edge_hash");
+	all_edges = MEM_mallocN(sizeof(*all_edges)*state->element_map->totalUVs, "stitch_all_edges");
 
-	if(!state->selection_stack || !state->uvs || !state->map || !state->edgeHash || !edges){
+	if(!state->selection_stack || !state->uvs || !state->map || !edgeHash || !all_edges){
 		stitch_state_delete(state);
 		return 0;
 	}
@@ -893,10 +887,6 @@
 		UvElement *element = state->element_map->vert[i];
 		for(; element; element = element->next){
 			if(element->separate){
-				MTFace *mt;
-				efa = element->face;
-				mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
-
 				counter++;
 				state->uvs[counter] = element;
 			}
@@ -918,27 +908,27 @@
 				offset1 = state->map[itmp1];
 				offset2 = state->map[itmp2];
 
-				edges[counter].flag = 0;
-				edges[counter].element = element;
+				all_edges[counter].flag = 0;
+				all_edges[counter].element = element;
 				/* using an order policy, sort uvs according to address space. This avoids
 				 * Having two different UvEdges with the same uvs on different positions  */
 				if(offset1 < offset2){
-					edges[counter].uv1 = offset1;
-					edges[counter].uv2 = offset2;
+					all_edges[counter].uv1 = offset1;
+					all_edges[counter].uv2 = offset2;
 				}
 				else{
-					edges[counter].uv1 = offset2;
-					edges[counter].uv2 = offset1;
+					all_edges[counter].uv1 = offset2;
+					all_edges[counter].uv2 = offset1;
 				}
 				/* Hack! Set the value of the key to its flag. Now we can set the flag when an edge exists twice :) */
-				if(BLI_ghash_haskey(state->edgeHash, &edges[counter])){
-					char *flag = BLI_ghash_lookup(state->edgeHash, &edges[counter]);
+				if(BLI_ghash_haskey(edgeHash, &all_edges[counter])){
+					char *flag = BLI_ghash_lookup(edgeHash, &all_edges[counter]);
 					*flag = 0;
 				}
 				else{
 					/* Hack mentioned */
-					BLI_ghash_insert(state->edgeHash, &edges[counter], &(edges[counter].flag));
-					edges[counter].flag = STITCH_BOUNDARY;
+					BLI_ghash_insert(edgeHash, &all_edges[counter], &(all_edges[counter].flag));
+					all_edges[counter].flag = STITCH_BOUNDARY;
 				}
 				counter++;
 			}
@@ -946,40 +936,40 @@
 	}
 
 
-	ghi = BLI_ghashIterator_new(state->edgeHash);
-	state->edges = MEM_mallocN(sizeof(*state->edges)*BLI_ghash_size(state->edgeHash), "stitch_edges");
-	if(!ghi || !state->edges){
-		MEM_freeN(edges);
+	ghi = BLI_ghashIterator_new(edgeHash);
+	edges = MEM_mallocN(sizeof(*edges)*BLI_ghash_size(edgeHash), "stitch_edges");
+	if(!ghi || !edges){
+		MEM_freeN(all_edges);
 		stitch_state_delete(state);
 		return 0;
 	}
 	/* fill the edges with data */
 	for(i = 0; !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)){
-		state->edges[i++] = *((UvEdge *)BLI_ghashIterator_getKey(ghi));
+		edges[i++] = *((UvEdge *)BLI_ghashIterator_getKey(ghi));
 	}
-	state->total_edges = BLI_ghash_size(state->edgeHash);
+	total_edges = BLI_ghash_size(edgeHash);
 
 	/* cleanup temporary stuff */
 	BLI_ghashIterator_free(ghi);
-	MEM_freeN(edges);
+	MEM_freeN(all_edges);
 
-	/* refill hash with new pointers */
-	BLI_ghash_free(state->edgeHash, NULL, NULL);
-	state->edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "stitch_edge_hash");
-	for(i = 0; i < state->total_edges; i++){
-		BLI_ghash_insert(state->edgeHash, state->edges + i, state->edges + i);
+	/* refill hash with new pointers to cleanup duplicates */
+	BLI_ghash_free(edgeHash, NULL, NULL);
+	edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "stitch_edge_hash");
+	for(i = 0; i < total_edges; i++){
+		BLI_ghash_insert(edgeHash, edges + i, edges + i);
 	}
 
-	for(i = 0; i < state->total_edges; i++){
-		if(state->edges[i].flag & STITCH_BOUNDARY){
-			state->uvs[state->edges[i].uv1]->flag |= STITCH_BOUNDARY;
-			state->uvs[state->edges[i].uv2]->flag |= STITCH_BOUNDARY;
+	for(i = 0; i < total_edges; i++){
+		if(edges[i].flag & STITCH_BOUNDARY){
+			state->uvs[edges[i].uv1]->flag |= STITCH_BOUNDARY;
+			state->uvs[edges[i].uv2]->flag |= STITCH_BOUNDARY;
 		}
 	}
 
 	state->selection_size = 0;
 
-	/***** Fill selection stack *******/
+	/***** fill selection stack *******/
 
 	/* Load old selection if redoing operator with different settings */
 	if(RNA_property_is_set(op->ptr, "selection")){
@@ -1011,16 +1001,15 @@
 
 			for(i = 0; i < numOfVerts; i++){
 				if(uvedit_uv_selected(scene, efa, mt, i)){
-					int uniqueIndex;
 					UvElement *element = ED_get_uv_element(state->element_map, efa, i);
-					uniqueIndex = state->map[element - state->element_map->buf];
 					stitch_select_uv(element, state, state->selection_stack, &state->selection_size, 1);
 				}
 			}
 		}
 	}
 
-	/* initialise static island preview */
+	/***** initialise static island preview data *****/
+
 	state->quads_per_island = MEM_mallocN(sizeof(*state->quads_per_island)*state->element_map->totalIslands,
 			"stitch island quads");
 	state->tris_per_island = MEM_mallocN(sizeof(*state->tris_per_island)*state->element_map->totalIslands,
@@ -1041,6 +1030,9 @@
 		}
 	}
 
+	BLI_ghash_free(edgeHash, NULL, NULL);
+	MEM_freeN(edges);
+
 	if(!stitch_process_data(state, scene, 0)){
 		stitch_state_delete(state);
 		return 0;
@@ -1143,11 +1135,7 @@
 static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
 	StitchState *stitch_state;
-	Object *obedit;
-	StitchPreviewer *preview;
 	Scene *scene = CTX_data_scene(C);
-	obedit= CTX_data_edit_object(C);
-	preview = uv_get_stitch_previewer();
 
 	stitch_state = (StitchState *)op->customdata;
 
@@ -1230,7 +1218,7 @@
 			}
 			break;
 
-		/* Select geometry based on mode (vertex or edges)*/
+		/* Select geometry*/
 		case RIGHTMOUSE:
 			if(!event->shift){
 					return stitch_cancel(C, op);



More information about the Bf-blender-cvs mailing list