[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16602] branches/harmonic-skeleton/source/ blender/src/autoarmature.c: Memoization: Remove need to keep full position lists on each node.

Martin Poirier theeth at yahoo.com
Thu Sep 18 23:45:58 CEST 2008


Revision: 16602
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16602
Author:   theeth
Date:     2008-09-18 23:45:57 +0200 (Thu, 18 Sep 2008)

Log Message:
-----------
Memoization: Remove need to keep full position lists on each node.

Modified Paths:
--------------
    branches/harmonic-skeleton/source/blender/src/autoarmature.c

Modified: branches/harmonic-skeleton/source/blender/src/autoarmature.c
===================================================================
--- branches/harmonic-skeleton/source/blender/src/autoarmature.c	2008-09-18 21:18:53 UTC (rev 16601)
+++ branches/harmonic-skeleton/source/blender/src/autoarmature.c	2008-09-18 21:45:57 UTC (rev 16602)
@@ -168,7 +168,7 @@
 
 typedef struct MemoNode {
 	float	weight;
-	int		*positions;
+	int 	next;
 } MemoNode;
 
 typedef struct RetargetParam {
@@ -1931,17 +1931,26 @@
 	return 1;
 }
 
-static void copyMemoNode(MemoNode *dst, MemoNode *src, int size)
+static int indexMemoNode(int nb_positions, int previous, int current, int joints_left)
 {
-	if (size > 0)
-	{
-		memcpy(dst->positions + 1, src->positions, size * sizeof(int));
-	}
+	return joints_left * nb_positions * nb_positions + current * nb_positions + previous;
 }
 
-static int indexMemoNode(int nb_positions, int previous, int current, int joints_done)
+static void copyMemoPositions(int *positions, MemoNode *table, int nb_positions, int joints_left)
 {
-	return joints_done * nb_positions * nb_positions + current * nb_positions + previous;
+	int previous = 0, current = 0;
+	int i = 0;
+	
+	for (i = 0; joints_left > 0; joints_left--, i++)
+	{
+		MemoNode *node;
+		node = table + indexMemoNode(nb_positions, previous, current, joints_left);
+		
+		positions[i] = node->next;
+		
+		previous = current;
+		current = node->next;
+	}
 }
 
 static MemoNode * solveJoints(MemoNode *table, ReebArcIterator *iter, float **vec_cache, int nb_joints, int nb_positions, int previous, int current, RigEdge *edge, int joints_left)
@@ -2001,15 +2010,12 @@
 		
 		if (min_node)
 		{
-			node->positions = MEM_callocN(sizeof(int) * joints_left, "Memoization indexes array");
 			node->weight = min_weight;
-			copyMemoNode(node, min_node, joints_left - 1);
-			node->positions[0] = min_next;
+			node->next = min_next;
 			return node;
 		}
 		else
 		{
-			node->positions = MEM_callocN(sizeof(int) * joints_left, "Memoization indexes array");
 			node->weight = MAX_COST;
 			return node;
 		}
@@ -2112,16 +2118,8 @@
 		result = solveJoints(table, &iter, positions_cache, nb_joints, earc->bcount, 0, 0, iarc->edges.first, nb_joints);
 		
 		min_cost = result->weight;
-		memcpy(best_positions, result->positions, sizeof(int) * nb_joints);
+		copyMemoPositions(best_positions, table, earc->bcount, nb_joints);
 		
-		for ( i = 0; i < nb_memo_nodes; i++)
-		{
-			if (table[i].positions)
-			{
-				MEM_freeN(table[i].positions);
-			}
-		}
-		
 		MEM_freeN(table);
 		MEM_freeN(positions_cache);
 	}





More information about the Bf-blender-cvs mailing list