diff options
author | Martin Poirier <theeth@yahoo.com> | 2008-07-06 02:01:46 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2008-07-06 02:01:46 +0400 |
commit | de286af3f1f8fa42aaaaed6c0214531ed3cc6114 (patch) | |
tree | 1cd69374dc9e5c177854de79965ca82397c737b6 | |
parent | 44e13eb8d556796df7380c3eb5b5b7f850e87287 (diff) |
Filter according to arc length, not weight different (more logic physical filtering)
-rw-r--r-- | source/blender/blenlib/BLI_graph.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/graph.c | 9 | ||||
-rw-r--r-- | source/blender/src/reeb.c | 48 |
3 files changed, 34 insertions, 24 deletions
diff --git a/source/blender/blenlib/BLI_graph.h b/source/blender/blenlib/BLI_graph.h index 44131fbbff8..a814b6f8c96 100644 --- a/source/blender/blenlib/BLI_graph.h +++ b/source/blender/blenlib/BLI_graph.h @@ -66,6 +66,7 @@ typedef struct RadialArc 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); diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c index 8c7e8ce8cd6..1371e59a77a 100644 --- a/source/blender/blenlib/intern/graph.c +++ b/source/blender/blenlib/intern/graph.c @@ -53,6 +53,12 @@ void BLI_freeNode(BGraph *graph, BNode *node) } } +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 @@ void BLI_removeDoubleNodes(BGraph *graph, float limit) { BLI_replaceNode(graph, node_src, node_replaced); - BLI_freeNode(graph, node_replaced); - BLI_freelinkN(&graph->nodes, node_replaced); + BLI_removeNode(graph, node_replaced); } } } diff --git a/source/blender/src/reeb.c b/source/blender/src/reeb.c index 3701f825b4c..c47ae155a3a 100644 --- a/source/blender/src/reeb.c +++ b/source/blender/src/reeb.c @@ -127,11 +127,7 @@ void REEB_freeGraph(ReebGraph *rg) // 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 @@ void sortArcs(ReebGraph *rg) 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 @@ void filterNullReebGraph(ReebGraph *rg) 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 @@ int filterInternalReebGraph(ReebGraph *rg, float threshold) 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 @@ int filterInternalReebGraph(ReebGraph *rg, float threshold) 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 @@ int filterExternalReebGraph(ReebGraph *rg, float threshold) 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 @@ int filterExternalReebGraph(ReebGraph *rg, float threshold) 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 @@ int filterExternalReebGraph(ReebGraph *rg, float threshold) 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 @@ int filterSmartReebGraph(ReebGraph *rg, float threshold) 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 @@ void filterGraph(ReebGraph *rg, short options, float threshold_internal, float t 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 @@ void finalizeGraph(ReebGraph *rg, char passes, char method) { postprocessGraph(rg, method); } - - calculateGraphLength(rg); } /************************************** WEIGHT SPREADING ***********************************************/ @@ -1703,6 +1705,8 @@ int mergeConnectedArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) int result = 0; ReebNode *removedNode = NULL; + a0->length += a1->length; + mergeArcEdges(rg, a0, a1, MERGE_APPEND); mergeArcFaces(rg, a0, a1); @@ -1726,7 +1730,7 @@ int mergeConnectedArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) BLI_remlink(&rg->arcs, a1); REEB_freeArc((BArc*)a1); - BLI_freelinkN(&rg->nodes, removedNode); + BLI_removeNode((BGraph*)rg, (BNode*)removedNode); result = 1; return result; |