[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15446] branches/harmonic-skeleton/source/ blender: Filter according to arc length, not weight different ( more logic physical filtering)

Martin Poirier theeth at yahoo.com
Sun Jul 6 00:03:03 CEST 2008


Revision: 15446
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15446
Author:   theeth
Date:     2008-07-06 00:01:46 +0200 (Sun, 06 Jul 2008)

Log Message:
-----------
Filter according to arc length, not weight different (more logic physical filtering)

Modified Paths:
--------------
    branches/harmonic-skeleton/source/blender/blenlib/BLI_graph.h
    branches/harmonic-skeleton/source/blender/blenlib/intern/graph.c
    branches/harmonic-skeleton/source/blender/src/reeb.c

Modified: branches/harmonic-skeleton/source/blender/blenlib/BLI_graph.h
===================================================================
--- branches/harmonic-skeleton/source/blender/blenlib/BLI_graph.h	2008-07-05 19:53:36 UTC (rev 15445)
+++ branches/harmonic-skeleton/source/blender/blenlib/BLI_graph.h	2008-07-05 22:01:46 UTC (rev 15446)
@@ -66,6 +66,7 @@
 BNode *BLI_otherNode(BArc *arc, BNode *node);
 
 void BLI_freeNode(BGraph *graph, BNode *node);
+void BLI_removeNode(BGraph *graph, BNode *node);
 
 void BLI_flagNodes(BGraph *graph, int flag);
 void BLI_flagArcs(BGraph *graph, int flag);

Modified: branches/harmonic-skeleton/source/blender/blenlib/intern/graph.c
===================================================================
--- branches/harmonic-skeleton/source/blender/blenlib/intern/graph.c	2008-07-05 19:53:36 UTC (rev 15445)
+++ branches/harmonic-skeleton/source/blender/blenlib/intern/graph.c	2008-07-05 22:01:46 UTC (rev 15446)
@@ -53,6 +53,12 @@
 	}
 }
 
+void BLI_removeNode(BGraph *graph, BNode *node)
+{
+	BLI_freeNode(graph, node);
+	BLI_freelinkN(&graph->nodes, node);
+}
+
 BNode *BLI_otherNode(BArc *arc, BNode *node)
 {
 	return (arc->head == node) ? arc->tail : arc->head;
@@ -194,8 +200,7 @@
 			{
 				BLI_replaceNode(graph, node_src, node_replaced);
 				
-				BLI_freeNode(graph, node_replaced);
-				BLI_freelinkN(&graph->nodes, node_replaced);
+				BLI_removeNode(graph, node_replaced);
 			}
 		}
 	}

Modified: branches/harmonic-skeleton/source/blender/src/reeb.c
===================================================================
--- branches/harmonic-skeleton/source/blender/src/reeb.c	2008-07-05 19:53:36 UTC (rev 15445)
+++ branches/harmonic-skeleton/source/blender/src/reeb.c	2008-07-05 22:01:46 UTC (rev 15446)
@@ -127,11 +127,7 @@
 	// free nodes
 	for( node = rg->nodes.first; node; node = node->next )
 	{
-		// Free adjacency lists
-		if (node->arcs != NULL)
-		{
-			MEM_freeN(node->arcs);
-		}
+		BLI_freeNode((BGraph*)rg, (BNode*)node);
 	}
 	BLI_freelistN(&rg->nodes);
 	
@@ -896,10 +892,14 @@
 
 float lengthArc(ReebArc *arc)
 {
+#if 0
 	ReebNode *head = (ReebNode*)arc->head;
 	ReebNode *tail = (ReebNode*)arc->tail;
 	
 	return tail->weight - head->weight;
+#else
+	return arc->length;
+#endif
 }
 
 int compareArcs(void *varc1, void *varc2)
@@ -1031,7 +1031,7 @@
 			BLI_remlink(&rg->arcs, arc);
 			REEB_freeArc((BArc*)arc);
 			
-			BLI_freelinkN(&rg->nodes, removedNode);
+			BLI_removeNode((BGraph*)rg, (BNode*)removedNode);
 		}
 		
 		arc = nextArc;
@@ -1051,7 +1051,7 @@
 		nextArc = arc->next;
 
 		// Only collapse non-terminal arcs that are shorter than threshold
-		if ((arc->head->degree > 1 && arc->tail->degree > 1 && ((ReebNode*)arc->tail)->weight - ((ReebNode*)arc->head)->weight < threshold))
+		if (arc->head->degree > 1 && arc->tail->degree > 1 && (lengthArc(arc) < threshold))
 		{
 			ReebNode *newNode = NULL;
 			ReebNode *removedNode = NULL;
@@ -1082,7 +1082,7 @@
 			BLI_remlink(&rg->arcs, arc);
 			REEB_freeArc((BArc*)arc);
 			
-			BLI_freelinkN(&rg->nodes, removedNode);
+			BLI_removeNode((BGraph*)rg, (BNode*)removedNode);
 			value = 1;
 		}
 		
@@ -1099,13 +1099,13 @@
 	
 	BLI_sortlist(&rg->arcs, compareArcs);
 
-	arc = rg->arcs.first;
-	while(arc)
+	
+	for (arc = rg->arcs.first; arc; arc = nextArc)
 	{
 		nextArc = arc->next;
 
 		// Only collapse terminal arcs that are shorter than threshold
-		if ((arc->head->degree == 1 || arc->tail->degree == 1) && ((ReebNode*)arc->tail)->weight - ((ReebNode*)arc->head)->weight < threshold)
+		if ((arc->head->degree == 1 || arc->tail->degree == 1) && (lengthArc(arc) < threshold))
 		{
 			ReebNode *terminalNode = NULL;
 			ReebNode *middleNode = NULL;
@@ -1125,9 +1125,10 @@
 				middleNode = arc->head;
 			}
 			
-			// If middle node is a normal node, merge to terminal node
+			// If middle node is a normal node, it will be removed later
 			if (middleNode->degree == 2)
 			{
+//				continue;
 				merging = 1;
 				newNode = terminalNode;
 				removedNode = middleNode;
@@ -1158,12 +1159,13 @@
 			BLI_remlink(&rg->arcs, arc);
 			REEB_freeArc((BArc*)arc);
 			
-			BLI_freelinkN(&rg->nodes, removedNode);
+			BLI_removeNode((BGraph*)rg, (BNode*)removedNode);
 			value = 1;
 		}
-		
-		arc = nextArc;
 	}
+
+	/* join on normal nodes */	
+	removeNormalNodes(rg);
 	
 	return value;
 }
@@ -1378,6 +1380,8 @@
 void filterGraph(ReebGraph *rg, short options, float threshold_internal, float threshold_external)
 {
 	int done = 1;
+	
+	calculateGraphLength(rg);
 
 	/* filter until there's nothing more to do */
 	while (done == 1)
@@ -1386,14 +1390,14 @@
 		
 		if (options & SKGEN_FILTER_EXTERNAL)
 		{
-			done |= filterExternalReebGraph(rg, threshold_external * rg->resolution);
+//			done |= filterExternalReebGraph(rg, threshold_external * rg->resolution);
+			done |= filterExternalReebGraph(rg, threshold_external);
 		}
 	
-		verifyBuckets(rg);
-	
 		if (options & SKGEN_FILTER_INTERNAL)
 		{
-			done |= filterInternalReebGraph(rg, threshold_internal * rg->resolution);
+//			done |= filterInternalReebGraph(rg, threshold_internal * rg->resolution);
+			done |= filterInternalReebGraph(rg, threshold_internal);
 		}
 	}
 
@@ -1424,8 +1428,6 @@
 	{
 		postprocessGraph(rg, method);
 	}
-	
-	calculateGraphLength(rg);
 }
 
 /************************************** WEIGHT SPREADING ***********************************************/
@@ -1703,6 +1705,8 @@
 	int result = 0;
 	ReebNode *removedNode = NULL;
 	
+	a0->length += a1->length;
+	
 	mergeArcEdges(rg, a0, a1, MERGE_APPEND);
 	mergeArcFaces(rg, a0, a1);
 	
@@ -1726,7 +1730,7 @@
 	BLI_remlink(&rg->arcs, a1);
 	REEB_freeArc((BArc*)a1);
 	
-	BLI_freelinkN(&rg->nodes, removedNode);
+	BLI_removeNode((BGraph*)rg, (BNode*)removedNode);
 	result = 1;
 	
 	return result;





More information about the Bf-blender-cvs mailing list