Bug fixes:
authorMartin Poirier <theeth@yahoo.com>
Tue, 29 Jul 2008 20:20:24 +0000 (20:20 +0000)
committerMartin Poirier <theeth@yahoo.com>
Tue, 29 Jul 2008 20:20:24 +0000 (20:20 +0000)
Retag subgraphs when merging, to prevent loops
Mark missing up link in multi resolution as NULL
Ignore hidden vertices when propagating weight between islands

source/blender/blenlib/BLI_graph.h
source/blender/blenlib/intern/graph.c
source/blender/src/reeb.c

index be5d1f5d10c9a753f420d0c456ab59ef245162b6..66cf2a2284254cded416b52990442db07701a6b2 100644 (file)
@@ -80,6 +80,7 @@ void BLI_rebuildAdjacencyListForNode(BGraph* rg, BNode *node);
 void BLI_freeAdjacencyList(BGraph *rg);
 
 int BLI_FlagSubgraphs(BGraph *graph);
+void BLI_ReflagSubgraph(BGraph *graph, int old_subgraph, int new_subgraph);
 
 #define SHAPE_RADIX 10 /* each shape level is encoded this base */
 
index abdf2969e491963d642fe962953e3153731b4be8..aa899042a58117e831135b28ff738e933f5c9c04 100644 (file)
@@ -275,6 +275,19 @@ int BLI_FlagSubgraphs(BGraph *graph)
        return subgraph;
 }
 
+void BLI_ReflagSubgraph(BGraph *graph, int old_subgraph, int new_subgraph)
+{
+       BNode *node;
+
+       for (node = graph->nodes.first; node; node = node->next)
+       {
+               if (node->flag == old_subgraph)
+               {
+                       node->flag = new_subgraph;
+               }
+       }
+}
+
 /*************************************** CYCLE DETECTION ***********************************************/
 
 int detectCycle(BNode *node, BArc *src_arc)
index 728dc2d7996debd9a07bb6d1149b30d211a6abc6..be5f754d5f08987da63312b7f18434bea1ed6f21 100644 (file)
@@ -350,7 +350,8 @@ void printArc(ReebArc *arc)
 {
        ReebEdge *edge;
        ReebNode *head = (ReebNode*)arc->head;
-       printf("arc: (%i)%f -> (%i)%f\n", head->index, head->weight, head->index, head->weight);
+       ReebNode *tail = (ReebNode*)arc->tail;
+       printf("arc: (%i) %f -> (%i) %f\n", head->index, head->weight, tail->index, tail->weight);
        
        for(edge = arc->edges.first; edge ; edge = edge->next)
        {
@@ -499,7 +500,7 @@ void verifyFaces(ReebGraph *rg)
 #endif
 }
 
-void verifyMultiResolutionLinks(ReebGraph *rg)
+void verifyMultiResolutionLinks(ReebGraph *rg, int level)
 {
 #ifdef DEBUG_REEB
        ReebGraph *lower_rg = rg->link_up;
@@ -512,12 +513,16 @@ void verifyMultiResolutionLinks(ReebGraph *rg)
                {
                        if (BLI_findindex(&lower_rg->arcs, arc->link_up) == -1)
                        {
-                               printf("missing arc %p\n", arc->link_up);
+                               printf("missing arc %p for level %i\n", arc->link_up, level);
+                               printf("Source arc was ---\n");
+                               printArc(arc);
+
+                               arc->link_up = NULL;
                        }
                }
                
                
-               verifyMultiResolutionLinks(lower_rg);
+               verifyMultiResolutionLinks(lower_rg, level + 1);
        }
 #endif
 }
@@ -1160,7 +1165,9 @@ int joinSubgraphsEnds(ReebGraph *rg, float threshold, int nb_subgraphs)
                                        
 
                                        if (merging)
-                                       {                                       
+                                       {
+                                               BLI_ReflagSubgraph((BGraph*)rg, end_node->flag, subgraph);
+                                                                                       
                                                resizeArcBuckets(start_arc);
                                                fillArcEmptyBuckets(start_arc);
                                                
@@ -1334,7 +1341,7 @@ void filterNullReebGraph(ReebGraph *rg)
                        
                        blend = (float)newNode->degree / (float)(newNode->degree + removedNode->degree); // blending factors
                        
-                       VecLerpf(newNode->p, newNode->p, removedNode->p, blend);
+                       VecLerpf(newNode->p, removedNode->p, newNode->p, blend);
                        
                        filterArc(rg, newNode, removedNode, arc, 0);
 
@@ -1440,9 +1447,6 @@ int filterExternalReebGraph(ReebGraph *rg, float threshold)
                        if (middleNode->degree == 2)
                        {
                                continue;
-//                             removedNode = middleNode;
-//
-//                             filterArc(rg, terminalNode, removedNode, arc, 1);
                        }
                        // Otherwise, just plain remove of the arc
                        else
@@ -1463,9 +1467,6 @@ int filterExternalReebGraph(ReebGraph *rg, float threshold)
                        value = 1;
                }
        }
-
-       /* join on normal nodes */      
-       removeNormalNodes(rg);
        
        return value;
 }
@@ -1690,19 +1691,19 @@ void filterGraph(ReebGraph *rg, short options, float threshold_internal, float t
        {
                done = 0; /* no work done yet */
                
-               if (options & SKGEN_FILTER_EXTERNAL)
-               {
-//                     done |= filterExternalReebGraph(rg, threshold_external * rg->resolution);
-                       done |= filterExternalReebGraph(rg, threshold_external);
-                       verifyNodeDegree(rg);
-               }
-       
                if (options & SKGEN_FILTER_INTERNAL)
                {
 //                     done |= filterInternalReebGraph(rg, threshold_internal * rg->resolution);
                        done |= filterInternalReebGraph(rg, threshold_internal);
                        verifyNodeDegree(rg);
                }
+
+               if (options & SKGEN_FILTER_EXTERNAL)
+               {
+//                     done |= filterExternalReebGraph(rg, threshold_external * rg->resolution);
+                       done |= filterExternalReebGraph(rg, threshold_external);
+                       verifyNodeDegree(rg);
+               }
        }
 
        if (options & SKGEN_FILTER_SMART)
@@ -2842,10 +2843,12 @@ int weightFromDistance(EditMesh *em)
                        
                        for (eve = em->verts.first; eve; eve = eve->next)
                        {
-                               if (eve->f1 != 1)
+                               /* for every vertex visible that hasn't been processed yet */
+                               if (eve->h == 0 && eve->f1 != 1)
                                {
                                        EditVert *closest_eve;
                                        
+                                       /* find the closest processed vertex */
                                        for (closest_eve = em->verts.first; closest_eve; closest_eve = closest_eve->next)
                                        {
                                                /* vertex is already processed and distance is smaller than current minimum */
@@ -3292,7 +3295,7 @@ ReebGraph *BIF_ReebGraphMultiFromEditMesh(void)
                relinkNodes(previous, rgi);
        }
        
-       verifyMultiResolutionLinks(rg);
+       verifyMultiResolutionLinks(rg, 0);
 
        return rg;
 }