diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-28 10:31:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-28 10:31:57 +0400 |
commit | b340f930ec5639f24e7e2d47fab221fb752b61dd (patch) | |
tree | 0e880a36bb528d133af6d10701fc090716b3b7f8 /source/blender/editors/armature/reeb.c | |
parent | 09dc600839904a198ab4ba3fad62ce58c2d3aa07 (diff) |
style cleanup: changes to brace placement / newlines - for/while/if/switch
Diffstat (limited to 'source/blender/editors/armature/reeb.c')
-rw-r--r-- | source/blender/editors/armature/reeb.c | 793 |
1 files changed, 270 insertions, 523 deletions
diff --git a/source/blender/editors/armature/reeb.c b/source/blender/editors/armature/reeb.c index 546bcb1f40f..f5e7770a7fc 100644 --- a/source/blender/editors/armature/reeb.c +++ b/source/blender/editors/armature/reeb.c @@ -183,16 +183,14 @@ void REEB_freeGraph(ReebGraph *rg) ReebNode *node; // free nodes - for ( node = rg->nodes.first; node; node = node->next ) - { + for (node = rg->nodes.first; node; node = node->next) { BLI_freeNode((BGraph*)rg, (BNode*)node); } BLI_freelistN(&rg->nodes); // free arcs arc = rg->arcs.first; - while ( arc ) - { + while ( arc ) { ReebArc *next = arc->next; REEB_freeArc((BArc*)arc); arc = next; @@ -202,8 +200,7 @@ void REEB_freeGraph(ReebGraph *rg) BLI_edgehash_free(rg->emap, NULL); /* free linked graph */ - if (rg->link_up) - { + if (rg->link_up) { REEB_freeGraph(rg->link_up); } @@ -229,8 +226,7 @@ ReebGraph * newReebGraph(void) void BIF_flagMultiArcs(ReebGraph *rg, int flag) { - for ( ; rg; rg = rg->link_up) - { + for ( ; rg; rg = rg->link_up) { BLI_flagArcs((BGraph*)rg, flag); } } @@ -318,8 +314,7 @@ ReebNode *BIF_NodeFromIndex(ReebArc *arc, ReebNode *node) ReebNode *BIF_lowestLevelNode(ReebNode *node) { - while (node->link_down) - { + while (node->link_down) { node = node->link_down; } @@ -407,8 +402,7 @@ ReebGraph *BIF_graphForMultiNode(ReebGraph *rg, ReebNode *node) { ReebGraph *multi_rg = rg; - while (multi_rg && multi_rg->multi_level != node->multi_level) - { + while (multi_rg && multi_rg->multi_level != node->multi_level) { multi_rg = multi_rg->link_up; } @@ -484,15 +478,12 @@ void repositionNodes(ReebGraph *rg) BNode *node = NULL; // Reset node positions - for (node = rg->nodes.first; node; node = node->next) - { + for (node = rg->nodes.first; node; node = node->next) { node->p[0] = node->p[1] = node->p[2] = 0; } - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (((ReebArc*)arc)->bcount > 0) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (((ReebArc*)arc)->bcount > 0) { float p[3]; copy_v3_v3(p, ((ReebArc*)arc)->buckets[0].p); @@ -512,22 +503,17 @@ void verifyNodeDegree(ReebGraph *rg) ReebNode *node = NULL; ReebArc *arc = NULL; - for (node = rg->nodes.first; node; node = node->next) - { + for (node = rg->nodes.first; node; node = node->next) { int count = 0; - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (arc->head == node || arc->tail == node) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (arc->head == node || arc->tail == node) { count++; } } - if (count != node->degree) - { + if (count != node->degree) { printf("degree error in node %i: expected %i got %i\n", node->index, count, node->degree); } - if (node->degree == 0) - { + if (node->degree == 0) { printf("zero degree node %i with weight %f\n", node->index, node->weight); } } @@ -539,25 +525,20 @@ static void verifyBucketsArc(ReebGraph *UNUSED(rg), ReebArc *arc) ReebNode *head = (ReebNode*)arc->head; ReebNode *tail = (ReebNode*)arc->tail; - if (arc->bcount > 0) - { + if (arc->bcount > 0) { int i; - for (i = 0; i < arc->bcount; i++) - { - if (arc->buckets[i].nv == 0) - { + for (i = 0; i < arc->bcount; i++) { + if (arc->buckets[i].nv == 0) { printArc(arc); printf("count error in bucket %i/%i\n", i+1, arc->bcount); } } - if (ceilf(head->weight) != arc->buckets[0].val) - { + if (ceilf(head->weight) != arc->buckets[0].val) { printArc(arc); printf("alloc error in first bucket: %f should be %f\n", arc->buckets[0].val, ceil(head->weight)); } - if (floorf(tail->weight) != arc->buckets[arc->bcount - 1].val) - { + if (floorf(tail->weight) != arc->buckets[arc->bcount - 1].val) { printArc(arc); printf("alloc error in last bucket: %f should be %f\n", arc->buckets[arc->bcount - 1].val, floor(tail->weight)); } @@ -568,8 +549,7 @@ void verifyBuckets(ReebGraph *rg) { #ifdef DEBUG_REEB ReebArc *arc = NULL; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { verifyBucketsArc(rg, arc); } #endif @@ -580,8 +560,7 @@ void verifyFaces(ReebGraph *rg) #ifdef DEBUG_REEB int total = 0; ReebArc *arc = NULL; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { total += BLI_ghash_size(arc->faces); } @@ -592,10 +571,8 @@ void verifyArcs(ReebGraph *rg) { ReebArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (arc->head->weight > arc->tail->weight) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (arc->head->weight > arc->tail->weight) { printf("FLIPPED ARC!\n"); } } @@ -606,14 +583,11 @@ static void verifyMultiResolutionLinks(ReebGraph *rg, int level) #ifdef DEBUG_REEB ReebGraph *lower_rg = rg->link_up; - if (lower_rg) - { + if (lower_rg) { ReebArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (BLI_findindex(&lower_rg->arcs, arc->link_up) == -1) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (BLI_findindex(&lower_rg->arcs, arc->link_up) == -1) { printf("missing arc %p for level %i\n", (void *)arc->link_up, level); printf("Source arc was ---\n"); printArc(arc); @@ -647,13 +621,11 @@ static void removeVertFromBucket(EmbedBucket *b, float co[3]) static void mergeBuckets(EmbedBucket *bDst, EmbedBucket *bSrc) { - if (bDst->nv > 0 && bSrc->nv > 0) - { + if (bDst->nv > 0 && bSrc->nv > 0) { bDst->nv += bSrc->nv; interp_v3_v3v3(bDst->p, bDst->p, bSrc->p, (float)bSrc->nv / (float)(bDst->nv)); } - else if (bSrc->nv > 0) - { + else if (bSrc->nv > 0) { bDst->nv = bSrc->nv; copy_v3_v3(bDst->p, bSrc->p); } @@ -661,19 +633,16 @@ static void mergeBuckets(EmbedBucket *bDst, EmbedBucket *bSrc) static void mergeArcBuckets(ReebArc *aDst, ReebArc *aSrc, float start, float end) { - if (aDst->bcount > 0 && aSrc->bcount > 0) - { + if (aDst->bcount > 0 && aSrc->bcount > 0) { int indexDst = 0, indexSrc = 0; start = MAX3(start, aDst->buckets[0].val, aSrc->buckets[0].val); - while (indexDst < aDst->bcount && aDst->buckets[indexDst].val < start) - { + while (indexDst < aDst->bcount && aDst->buckets[indexDst].val < start) { indexDst++; } - while (indexSrc < aSrc->bcount && aSrc->buckets[indexSrc].val < start) - { + while (indexSrc < aSrc->bcount && aSrc->buckets[indexSrc].val < start) { indexSrc++; } @@ -693,8 +662,7 @@ void flipArcBuckets(ReebArc *arc) { int i, j; - for (i = 0, j = arc->bcount - 1; i < j; i++, j--) - { + for (i = 0, j = arc->bcount - 1; i < j; i++, j--) { EmbedBucket tmp; tmp = arc->buckets[i]; @@ -714,20 +682,16 @@ static void allocArcBuckets(ReebArc *arc) float start = ceil(arc->head->weight); arc->bcount = countArcBuckets(arc); - if (arc->bcount > 0) - { + if (arc->bcount > 0) { arc->buckets = MEM_callocN(sizeof(EmbedBucket) * arc->bcount, "embed bucket"); - for (i = 0; i < arc->bcount; i++) - { + for (i = 0; i < arc->bcount; i++) { arc->buckets[i].val = start + i; } } - else - { + else { arc->buckets = NULL; } - } static void resizeArcBuckets(ReebArc *arc) @@ -735,15 +699,13 @@ static void resizeArcBuckets(ReebArc *arc) EmbedBucket *oldBuckets = arc->buckets; int oldBCount = arc->bcount; - if (countArcBuckets(arc) == oldBCount) - { + if (countArcBuckets(arc) == oldBCount) { return; } allocArcBuckets(arc); - if (oldBCount != 0 && arc->bcount != 0) - { + if (oldBCount != 0 && arc->bcount != 0) { int oldStart = (int)oldBuckets[0].val; int oldEnd = (int)oldBuckets[oldBCount - 1].val; int newStart = (int)arc->buckets[0].val; @@ -752,12 +714,10 @@ static void resizeArcBuckets(ReebArc *arc) int newOffset = 0; int len; - if (oldStart < newStart) - { + if (oldStart < newStart) { oldOffset = newStart - oldStart; } - else - { + else { newOffset = oldStart - newStart; } @@ -766,8 +726,7 @@ static void resizeArcBuckets(ReebArc *arc) memcpy(arc->buckets + newOffset, oldBuckets + oldOffset, len * sizeof(EmbedBucket)); } - if (oldBuckets != NULL) - { + if (oldBuckets != NULL) { MEM_freeN(oldBuckets); } } @@ -777,10 +736,8 @@ static void reweightBuckets(ReebArc *arc) int i; float start = ceil((arc->head)->weight); - if (arc->bcount > 0) - { - for (i = 0; i < arc->bcount; i++) - { + if (arc->bcount > 0) { + for (i = 0; i < arc->bcount; i++) { arc->buckets[i].val = start + i; } } @@ -793,8 +750,7 @@ static void interpolateBuckets(ReebArc *arc, float *start_p, float *end_p, int s total = end_index - start_index + 2; - for (j = start_index; j <= end_index; j++) - { + for (j = start_index; j <= end_index; j++) { EmbedBucket *empty = arc->buckets + j; empty->nv = 1; interp_v3_v3v3(empty->p, start_p, end_p, (float)(j - start_index + 1) / total); @@ -810,14 +766,11 @@ static void fillArcEmptyBuckets(ReebArc *arc) start_p = arc->head->p; - for (i = 0; i < arc->bcount; i++) - { + for (i = 0; i < arc->bcount; i++) { EmbedBucket *bucket = arc->buckets + i; - if (missing) - { - if (bucket->nv > 0) - { + if (missing) { + if (bucket->nv > 0) { missing = 0; end_p = bucket->p; @@ -826,14 +779,11 @@ static void fillArcEmptyBuckets(ReebArc *arc) interpolateBuckets(arc, start_p, end_p, start_index, end_index); } } - else - { - if (bucket->nv == 0) - { + else { + if (bucket->nv == 0) { missing = 1; - if (i > 0) - { + if (i > 0) { start_p = arc->buckets[i - 1].p; } start_index = i; @@ -841,8 +791,7 @@ static void fillArcEmptyBuckets(ReebArc *arc) } } - if (missing) - { + if (missing) { end_p = arc->tail->p; end_index = arc->bcount - 1; @@ -859,8 +808,7 @@ static void ExtendArcBuckets(ReebArc *arc) float average_length = 0, length; int padding_head = 0, padding_tail = 0; - if (arc->bcount == 0) - { + if (arc->bcount == 0) { return; /* failsafe, shouldn't happen */ } @@ -881,19 +829,16 @@ static void ExtendArcBuckets(ReebArc *arc) last_bucket = arc->buckets + (arc->bcount - 1); length = len_v3v3(first_bucket->p, arc->head->p); - if (length > 2 * average_length) - { + if (length > 2 * average_length) { padding_head = (int)floor(length / average_length); } length = len_v3v3(last_bucket->p, arc->tail->p); - if (length > 2 * average_length) - { + if (length > 2 * average_length) { padding_tail = (int)floor(length / average_length); } - if (padding_head + padding_tail > 0) - { + if (padding_head + padding_tail > 0) { EmbedBucket *old_buckets = arc->buckets; arc->buckets = MEM_callocN(sizeof(EmbedBucket) * (padding_head + arc->bcount + padding_tail), "embed bucket"); @@ -904,13 +849,11 @@ static void ExtendArcBuckets(ReebArc *arc) MEM_freeN(old_buckets); } - if (padding_head > 0) - { + if (padding_head > 0) { interpolateBuckets(arc, arc->head->p, first_bucket->p, 0, padding_head); } - if (padding_tail > 0) - { + if (padding_tail > 0) { interpolateBuckets(arc, last_bucket->p, arc->tail->p, arc->bcount - padding_tail, arc->bcount - 1); } } @@ -920,8 +863,7 @@ static void extendGraphBuckets(ReebGraph *rg) { ReebArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { ExtendArcBuckets(arc); } } @@ -941,8 +883,7 @@ static void calculateArcLength(ReebArc *arc) vec0 = arc->head->p; vec1 = arc->head->p; /* in case there's no embedding */ - while (IT_next(iter)) - { + while (IT_next(iter)) { vec1 = iter->p; arc->length += len_v3v3(vec0, vec1); @@ -957,8 +898,7 @@ static void calculateGraphLength(ReebGraph *rg) { ReebArc *arc; - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { calculateArcLength(arc); } } @@ -975,8 +915,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) copy_v3_v3(axis, root_node->symmetry_axis); /* first pass, merge incrementally */ - for (i = 0; i < count - 1; i++) - { + for (i = 0; i < count - 1; i++) { ReebNode *node1, *node2; ReebArc *arc1, *arc2; float tangent[3]; @@ -999,8 +938,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) /* Merge buckets * there shouldn't be any null arcs here, but just to be safe * */ - if (arc1->bcount > 0 && arc2->bcount > 0) - { + if (arc1->bcount > 0 && arc2->bcount > 0) { ReebArcIterator arc_iter1, arc_iter2; BArcIterator *iter1 = (BArcIterator*)&arc_iter1; BArcIterator *iter2 = (BArcIterator*)&arc_iter2; @@ -1013,19 +951,16 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) bucket2 = IT_next(iter2); /* Make sure they both start at the same value */ - while (bucket1 && bucket2 && bucket1->val < bucket2->val) - { + while (bucket1 && bucket2 && bucket1->val < bucket2->val) { bucket1 = IT_next(iter1); } - while (bucket1 && bucket2 && bucket2->val < bucket1->val) - { + while (bucket1 && bucket2 && bucket2->val < bucket1->val) { bucket2 = IT_next(iter2); } - for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) - { + for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) { bucket2->nv += bucket1->nv; /* add counts */ /* mirror on axis */ @@ -1037,8 +972,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) } /* second pass, mirror back on previous arcs */ - for (i = count - 1; i > 0; i--) - { + for (i = count - 1; i > 0; i--) { ReebNode *node1, *node2; ReebArc *arc1, *arc2; float tangent[3]; @@ -1061,8 +995,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) /* Copy buckets * there shouldn't be any null arcs here, but just to be safe * */ - if (arc1->bcount > 0 && arc2->bcount > 0) - { + if (arc1->bcount > 0 && arc2->bcount > 0) { ReebArcIterator arc_iter1, arc_iter2; BArcIterator *iter1 = (BArcIterator*)&arc_iter1; BArcIterator *iter2 = (BArcIterator*)&arc_iter2; @@ -1075,19 +1008,16 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) bucket2 = IT_next(iter2); /* Make sure they both start at the same value */ - while (bucket1 && bucket1->val < bucket2->val) - { + while (bucket1 && bucket1->val < bucket2->val) { bucket1 = IT_next(iter1); } - while (bucket2 && bucket2->val < bucket1->val) - { + while (bucket2 && bucket2->val < bucket1->val) { bucket2 = IT_next(iter2); } - for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) - { + for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) { /* copy and mirror back to bucket2 */ bucket2->nv = bucket1->nv; copy_v3_v3(bucket2->p, bucket1->p); @@ -1122,8 +1052,7 @@ void REEB_AxialSymmetry(BNode* root_node, BNode* node1, BNode* node2, struct BAr /* Merge buckets * there shouldn't be any null arcs here, but just to be safe * */ - if (arc1->bcount > 0 && arc2->bcount > 0) - { + if (arc1->bcount > 0 && arc2->bcount > 0) { ReebArcIterator arc_iter1, arc_iter2; BArcIterator *iter1 = (BArcIterator*)&arc_iter1; BArcIterator *iter2 = (BArcIterator*)&arc_iter2; @@ -1136,19 +1065,16 @@ void REEB_AxialSymmetry(BNode* root_node, BNode* node1, BNode* node2, struct BAr bucket2 = IT_next(iter2); /* Make sure they both start at the same value */ - while (bucket1 && bucket1->val < bucket2->val) - { + while (bucket1 && bucket1->val < bucket2->val) { bucket1 = IT_next(iter1); } - while (bucket2 && bucket2->val < bucket1->val) - { + while (bucket2 && bucket2->val < bucket1->val) { bucket2 = IT_next(iter2); } - for ( ;bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) - { + for ( ; bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) { bucket1->nv += bucket2->nv; /* add counts */ /* mirror on axis */ @@ -1175,7 +1101,7 @@ void postprocessGraph(ReebGraph *rg, char mode) ReebArc *arc; float fac1 = 0, fac2 = 1, fac3 = 0; - switch(mode) + switch (mode) { case SKGEN_AVERAGE: fac1 = fac2 = fac3 = 1.0f / 3.0f; @@ -1490,16 +1416,13 @@ static int compareArcs(void *varc1, void *varc2) float len1 = lengthArc(arc1); float len2 = lengthArc(arc2); - if (len1 < len2) - { + if (len1 < len2) { return -1; } - if (len1 > len2) - { + if (len1 > len2) { return 1; } - else - { + else { return 0; } } @@ -1508,13 +1431,10 @@ static void filterArc(ReebGraph *rg, ReebNode *newNode, ReebNode *removedNode, R { ReebArc *arc = NULL, *nextArc = NULL; - if (merging) - { + if (merging) { /* first pass, merge buckets for arcs that spawned the two nodes into the source arc*/ - for (arc = rg->arcs.first; arc; arc = arc->next) - { - if (arc->head == srcArc->head && arc->tail == srcArc->tail && arc != srcArc) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { + if (arc->head == srcArc->head && arc->tail == srcArc->tail && arc != srcArc) { ReebNode *head = srcArc->head; ReebNode *tail = srcArc->tail; mergeArcBuckets(srcArc, arc, head->weight, tail->weight); @@ -1524,47 +1444,38 @@ static void filterArc(ReebGraph *rg, ReebNode *newNode, ReebNode *removedNode, R /* second pass, replace removedNode by newNode, remove arcs that are collapsed in a loop */ arc = rg->arcs.first; - while (arc) - { + while (arc) { nextArc = arc->next; - if (arc->head == removedNode || arc->tail == removedNode) - { - if (arc->head == removedNode) - { + if (arc->head == removedNode || arc->tail == removedNode) { + if (arc->head == removedNode) { arc->head = newNode; } - else - { + else { arc->tail = newNode; } // Remove looped arcs - if (arc->head == arc->tail) - { + if (arc->head == arc->tail) { // v1 or v2 was already newNode, since we're removing an arc, decrement degree NodeDegreeDecrement(rg, newNode); // If it's srcArc, it'll be removed later, so keep it for now - if (arc != srcArc) - { + if (arc != srcArc) { BLI_remlink(&rg->arcs, arc); REEB_freeArc((BArc*)arc); } } - else - { + else { /* flip arcs that flipped, can happen on diamond shapes, mostly on null arcs */ - if (arc->head->weight > arc->tail->weight) - { + if (arc->head->weight > arc->tail->weight) { flipArc(arc); } //newNode->degree++; // incrementing degree since we're adding an arc NodeDegreeIncrement(rg, newNode); mergeArcFaces(rg, arc, srcArc); - if (merging) - { + if (merging) { ReebNode *head = arc->head; ReebNode *tail = arc->tail; @@ -1587,12 +1498,10 @@ void filterNullReebGraph(ReebGraph *rg) ReebArc *arc = NULL, *nextArc = NULL; arc = rg->arcs.first; - while (arc) - { + while (arc) { nextArc = arc->next; // Only collapse arcs too short to have any embed bucket - if (arc->bcount == 0) - { + if (arc->bcount == 0) { ReebNode *newNode = (ReebNode*)arc->head; ReebNode *removedNode = (ReebNode*)arc->tail; float blend; @@ -1623,12 +1532,14 @@ static int filterInternalExternalReebGraph(ReebGraph *rg, float threshold_intern BLI_sortlist(&rg->arcs, compareArcs); - for (arc = rg->arcs.first; arc; arc = nextArc) - { + for (arc = rg->arcs.first; arc; arc = nextArc) { nextArc = arc->next; - // Only collapse non-terminal arcs that are shorter than threshold - if (threshold_internal > 0 && arc->head->degree > 1 && arc->tail->degree > 1 && (lengthArc(arc) < threshold_internal)) + /* Only collapse non-terminal arcs that are shorter than threshold */ + if ((threshold_internal > 0) && + (arc->head->degree > 1) && + (arc->tail->degree > 1) && + (lengthArc(arc) < threshold_internal)) { ReebNode *newNode = NULL; ReebNode *removedNode = NULL; @@ -1650,26 +1561,25 @@ static int filterInternalExternalReebGraph(ReebGraph *rg, float threshold_intern } // Only collapse terminal arcs that are shorter than threshold - else if (threshold_external > 0 && (arc->head->degree == 1 || arc->tail->degree == 1) && (lengthArc(arc) < threshold_external)) + else if ((threshold_external > 0) && + (arc->head->degree == 1 || arc->tail->degree == 1) && + (lengthArc(arc) < threshold_external)) { ReebNode *terminalNode = NULL; ReebNode *middleNode = NULL; ReebNode *removedNode = NULL; // Assign terminal and middle nodes - if (arc->head->degree == 1) - { + if (arc->head->degree == 1) { terminalNode = arc->head; middleNode = arc->tail; } - else - { + else { terminalNode = arc->tail; middleNode = arc->head; } - if (middleNode->degree == 2 && middleNode != rg->nodes.first) - { + if (middleNode->degree == 2 && middleNode != rg->nodes.first) { #if 1 // If middle node is a normal node, it will be removed later // Only if middle node is not the root node @@ -1685,8 +1595,7 @@ static int filterInternalExternalReebGraph(ReebGraph *rg, float threshold_intern #endif } // Otherwise, just plain remove of the arc - else - { + else { removedNode = terminalNode; // removing arc, so we need to decrease the degree of the remaining node @@ -1713,13 +1622,10 @@ static int filterCyclesReebGraph(ReebGraph *rg, float UNUSED(distance_threshold) ReebArc *next2; int filtered = 0; - for (arc1 = rg->arcs.first; arc1; arc1 = arc1->next) - { - for (arc2 = arc1->next; arc2; arc2 = next2) - { + for (arc1 = rg->arcs.first; arc1; arc1 = arc1->next) { + for (arc2 = arc1->next; arc2; arc2 = next2) { next2 = arc2->next; - if (arc1 != arc2 && arc1->head == arc2->head && arc1->tail == arc2->tail) - { + if (arc1 != arc2 && arc1->head == arc2->head && arc1->tail == arc2->tail) { mergeArcEdges(rg, arc1, arc2, MERGE_APPEND); mergeArcFaces(rg, arc1, arc2); mergeArcBuckets(arc1, arc2, arc1->head->weight, arc1->tail->weight); @@ -1848,8 +1754,7 @@ int filterSmartReebGraph(ReebGraph *UNUSED(rg), float UNUSED(threshold)) if (avg_angle > threshold) merging = 1; - if (merging) - { + if (merging) { ReebNode *terminalNode = NULL; ReebNode *middleNode = NULL; ReebNode *newNode = NULL; @@ -1857,39 +1762,33 @@ int filterSmartReebGraph(ReebGraph *UNUSED(rg), float UNUSED(threshold)) int merging = 0; // Assign terminal and middle nodes - if (arc->head->degree == 1) - { + if (arc->head->degree == 1) { terminalNode = arc->head; middleNode = arc->tail; } - else - { + else { terminalNode = arc->tail; middleNode = arc->head; } // If middle node is a normal node, merge to terminal node - if (middleNode->degree == 2) - { + if (middleNode->degree == 2) { merging = 1; newNode = terminalNode; removedNode = middleNode; } // Otherwise, just plain remove of the arc - else - { + else { merging = 0; newNode = middleNode; removedNode = terminalNode; } // Merging arc - if (merging) - { + if (merging) { filterArc(rg, newNode, removedNode, arc, 1); } - else - { + else { // removing arc, so we need to decrease the degree of the remaining node //newNode->degree--; NodeDegreeDecrement(rg, newNode); @@ -1920,29 +1819,24 @@ static void filterGraph(ReebGraph *rg, short options, float threshold_internal, calculateGraphLength(rg); - if ((options & SKGEN_FILTER_EXTERNAL) == 0) - { + if ((options & SKGEN_FILTER_EXTERNAL) == 0) { threshold_external = 0; } - if ((options & SKGEN_FILTER_INTERNAL) == 0) - { + if ((options & SKGEN_FILTER_INTERNAL) == 0) { threshold_internal = 0; } - if (threshold_internal > 0 || threshold_external > 0) - { + if (threshold_internal > 0 || threshold_external > 0) { /* filter until there's nothing more to do */ - while (done == 1) - { + while (done == 1) { done = 0; /* no work done yet */ done = filterInternalExternalReebGraph(rg, threshold_internal, threshold_external); } } - if (options & SKGEN_FILTER_SMART) - { + if (options & SKGEN_FILTER_SMART) { filterSmartReebGraph(rg, 0.5); filterCyclesReebGraph(rg, 0.5); } @@ -1963,8 +1857,7 @@ static void finalizeGraph(ReebGraph *rg, char passes, char method) sortArcs(rg); - for (i = 0; i < passes; i++) - { + for (i = 0; i < passes; i++) { postprocessGraph(rg, method); } @@ -1979,12 +1872,10 @@ static int compareVerts( const void* a, const void* b ) EditVert *vb = *(EditVert**)b; int value = 0; - if (weightData(va) < weightData(vb)) - { + if (weightData(va) < weightData(vb)) { value = -1; } - else if (weightData(va) > weightData(vb)) - { + else if (weightData(va) > weightData(vb)) { value = 1; } @@ -2001,26 +1892,21 @@ static void spreadWeight(EditMesh *em) verts = MEM_callocN(sizeof(EditVert*) * totvert, "verts array"); - for (eve = em->verts.first, i = 0; eve; eve = eve->next, i++) - { + for (eve = em->verts.first, i = 0; eve; eve = eve->next, i++) { verts[i] = eve; } - while (work_needed == 1) - { + while (work_needed == 1) { work_needed = 0; qsort(verts, totvert, sizeof(EditVert*), compareVerts); - for (i = 0; i < totvert; i++) - { + for (i = 0; i < totvert; i++) { eve = verts[i]; - if (i == 0 || (weightData(eve) - lastWeight) > FLT_EPSILON) - { + if (i == 0 || (weightData(eve) - lastWeight) > FLT_EPSILON) { lastWeight = weightData(eve); } - else - { + else { work_needed = 1; weightSetData(eve, lastWeight + FLT_EPSILON * 2); lastWeight = weightData(eve); @@ -2044,8 +1930,7 @@ void REEB_exportGraph(ReebGraph *rg, int count) char filename[128]; FILE *f; - if (count == -1) - { + if (count == -1) { strcpy(filename, "test.txt"); } else { @@ -2053,15 +1938,13 @@ void REEB_exportGraph(ReebGraph *rg, int count) } f = BLI_fopen(filename, "w"); - for (arc = rg->arcs.first; arc; arc = arc->next) - { + for (arc = rg->arcs.first; arc; arc = arc->next) { int i; float p[3]; exportNode(f, "v1", arc->head); - for (i = 0; i < arc->bcount; i++) - { + for (i = 0; i < arc->bcount; i++) { fprintf(f, "b nv:%i %f %f %f\n", arc->buckets[i].nv, arc->buckets[i].p[0], arc->buckets[i].p[1], arc->buckets[i].p[2]); } @@ -2082,12 +1965,10 @@ static void removeZeroNodes(ReebGraph *rg) { ReebNode *node, *next_node; - for (node = rg->nodes.first; node; node = next_node) - { + for (node = rg->nodes.first; node; node = next_node) { next_node = node->next; - if (node->degree == 0) - { + if (node->degree == 0) { BLI_removeNode((BGraph*)rg, (BNode*)node); } } @@ -2098,63 +1979,51 @@ void removeNormalNodes(ReebGraph *rg) ReebArc *arc, *nextArc; // Merge degree 2 nodes - for (arc = rg->arcs.first; arc; arc = nextArc) - { + for (arc = rg->arcs.first; arc; arc = nextArc) { nextArc = arc->next; - while (arc->head->degree == 2 || arc->tail->degree == 2) - { + while (arc->head->degree == 2 || arc->tail->degree == 2) { // merge at v1 - if (arc->head->degree == 2) - { + if (arc->head->degree == 2) { ReebArc *connectedArc = (ReebArc*)BLI_findConnectedArc((BGraph*)rg, (BArc*)arc, (BNode*)arc->head); /* If arcs are one after the other */ - if (arc->head == connectedArc->tail) - { + if (arc->head == connectedArc->tail) { /* remove furthest arc */ - if (arc->tail->weight < connectedArc->head->weight) - { + if (arc->tail->weight < connectedArc->head->weight) { mergeConnectedArcs(rg, arc, connectedArc); nextArc = arc->next; } - else - { + else { mergeConnectedArcs(rg, connectedArc, arc); break; /* arc was removed, move to next */ } } /* Otherwise, arcs are side by side */ - else - { + else { /* Don't do anything, we need to keep the lowest node, even if degree 2 */ break; } } - // merge at v2 - if (arc->tail->degree == 2) - { + /* merge at v2 */ + if (arc->tail->degree == 2) { ReebArc *connectedArc = (ReebArc*)BLI_findConnectedArc((BGraph*)rg, (BArc*)arc, (BNode*)arc->tail); /* If arcs are one after the other */ - if (arc->tail == connectedArc->head) - { + if (arc->tail == connectedArc->head) { /* remove furthest arc */ - if (arc->head->weight < connectedArc->tail->weight) - { + if (arc->head->weight < connectedArc->tail->weight) { mergeConnectedArcs(rg, arc, connectedArc); nextArc = arc->next; } - else - { + else { mergeConnectedArcs(rg, connectedArc, arc); break; /* arc was removed, move to next */ } } /* Otherwise, arcs are side by side */ - else - { + else { /* Don't do anything, we need to keep the lowest node, even if degree 2 */ break; } @@ -2176,13 +2045,11 @@ static ReebArc *nextArcMappedToEdge(ReebArc *arc, ReebEdge *e) ReebArc *result = NULL; /* Find the ReebEdge in the edge list */ - for (edge = arc->edges.first; edge && !edgeEquals(edge, e); edge = edge->next) - { } + for (edge = arc->edges.first; edge && !edgeEquals(edge, e); edge = edge->next) { } nextEdge = edge->nextEdge; - if (nextEdge != NULL) - { + if (nextEdge != NULL) { result = nextEdge->arc; } @@ -2211,51 +2078,42 @@ void mergeArcEdges(ReebGraph *rg, ReebArc *aDst, ReebArc *aSrc, MergeDirection d { ReebEdge *e = NULL; - if (direction == MERGE_APPEND) - { - for (e = aSrc->edges.first; e; e = e->next) - { + if (direction == MERGE_APPEND) { + for (e = aSrc->edges.first; e; e = e->next) { e->arc = aDst; // Edge is stolen by new arc } BLI_movelisttolist(&aDst->edges , &aSrc->edges); } - else - { - for (e = aSrc->edges.first; e; e = e->next) - { + else { + for (e = aSrc->edges.first; e; e = e->next) { ReebEdge *newEdge = copyEdge(e); newEdge->arc = aDst; BLI_addtail(&aDst->edges, newEdge); - if (direction == MERGE_LOWER) - { + if (direction == MERGE_LOWER) { void **p = BLI_edgehash_lookup_p(rg->emap, e->v1->index, e->v2->index); newEdge->nextEdge = e; // if edge was the first in the list, point the edit edge to the new reeb edge instead. - if (*p == e) - { + if (*p == e) { *p = (void*)newEdge; } // otherwise, advance in the list until the predecessor is found then insert it there - else - { + else { ReebEdge *previous = (ReebEdge*)*p; - while (previous->nextEdge != e) - { + while (previous->nextEdge != e) { previous = previous->nextEdge; } previous->nextEdge = newEdge; } } - else - { + else { newEdge->nextEdge = e->nextEdge; e->nextEdge = newEdge; } @@ -2275,13 +2133,11 @@ int mergeConnectedArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) mergeArcFaces(rg, a0, a1); // Bring a0 to the combine length of both arcs - if (a0->tail == a1->head) - { + if (a0->tail == a1->head) { removedNode = a0->tail; a0->tail = a1->tail; } - else if (a0->head == a1->tail) - { + else if (a0->head == a1->tail) { removedNode = a0->head; a0->head = a1->head; } @@ -2303,11 +2159,9 @@ int mergeConnectedArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) { int result = 0; - // TRIANGLE POINTS DOWN - if (a0->head->weight == a1->head->weight) // heads are the same - { - if (a0->tail->weight == a1->tail->weight) // tails also the same, arcs can be totally merge together - { + /* TRIANGLE POINTS DOWN */ + if (a0->head->weight == a1->head->weight) { /* heads are the same */ + if (a0->tail->weight == a1->tail->weight) { /* tails also the same, arcs can be totally merge together */ mergeArcEdges(rg, a0, a1, MERGE_APPEND); mergeArcFaces(rg, a0, a1); @@ -2325,8 +2179,7 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) REEB_freeArc((BArc*)a1); result = 1; } - else if (a0->tail->weight > a1->tail->weight) // a1->tail->weight is in the middle - { + else if (a0->tail->weight > a1->tail->weight) { /* a1->tail->weight is in the middle */ mergeArcEdges(rg, a1, a0, MERGE_LOWER); mergeArcFaces(rg, a1, a0); @@ -2340,8 +2193,7 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) a0->head = a1->tail; resizeArcBuckets(a0); } - else // a0>n2 is in the middle - { + else { /* a0>n2 is in the middle */ mergeArcEdges(rg, a0, a1, MERGE_LOWER); mergeArcFaces(rg, a0, a1); @@ -2356,11 +2208,9 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) resizeArcBuckets(a1); } } - // TRIANGLE POINTS UP - else if (a0->tail->weight == a1->tail->weight) // tails are the same - { - if (a0->head->weight > a1->head->weight) // a0->head->weight is in the middle - { + /* TRIANGLE POINTS UP */ + else if (a0->tail->weight == a1->tail->weight) { /* tails are the same */ + if (a0->head->weight > a1->head->weight) { /* a0->head->weight is in the middle */ mergeArcEdges(rg, a0, a1, MERGE_HIGHER); mergeArcFaces(rg, a0, a1); @@ -2374,8 +2224,7 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) a1->tail = a0->head; resizeArcBuckets(a1); } - else // a1->head->weight is in the middle - { + else { /* a1->head->weight is in the middle */ mergeArcEdges(rg, a1, a0, MERGE_HIGHER); mergeArcFaces(rg, a1, a0); @@ -2390,9 +2239,8 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) resizeArcBuckets(a0); } } - else - { - // Need something here (OR NOT) + else { + /* Need something here (OR NOT) */ } return result; @@ -2401,18 +2249,14 @@ int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1) static void glueByMergeSort(ReebGraph *rg, ReebArc *a0, ReebArc *a1, ReebEdge *e0, ReebEdge *e1) { int total = 0; - while (total == 0 && a0 != a1 && a0 != NULL && a1 != NULL) - { + while (total == 0 && a0 != a1 && a0 != NULL && a1 != NULL) { total = mergeArcs(rg, a0, a1); - if (total == 0) // if it wasn't a total merge, go forward - { - if (a0->tail->weight < a1->tail->weight) - { + if (total == 0) // if it wasn't a total merge, go forward { + if (a0->tail->weight < a1->tail->weight) { a0 = nextArcMappedToEdge(a0, e0); } - else - { + else { a1 = nextArcMappedToEdge(a1, e1); } } @@ -2437,8 +2281,7 @@ static ReebEdge * createArc(ReebGraph *rg, ReebNode *node1, ReebNode *node2) edge = BLI_edgehash_lookup(rg->emap, node1->index, node2->index); // Only add existing edges that haven't been added yet - if (edge == NULL) - { + if (edge == NULL) { ReebArc *arc; ReebNode *v1, *v2; float len, offset; @@ -2451,13 +2294,11 @@ static ReebEdge * createArc(ReebGraph *rg, ReebNode *node1, ReebNode *node2) arc->symmetry_level = 0; arc->faces = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "createArc gh"); - if (node1->weight <= node2->weight) - { + if (node1->weight <= node2->weight) { v1 = node1; v2 = node2; } - else - { + else { v1 = node2; v2 = node1; } @@ -2497,8 +2338,7 @@ static ReebEdge * createArc(ReebGraph *rg, ReebNode *node1, ReebNode *node2) addVertToBucket(&(arc->buckets[arc->bcount - 1]), arc->tail->co); } #else - for (i = 0; i < arc->bcount; i++) - { + for (i = 0; i < arc->bcount; i++) { float co[3]; float f = (arc->buckets[i].val - offset) / len; @@ -2532,20 +2372,17 @@ static void addTriangleToGraph(ReebGraph *rg, ReebNode * n1, ReebNode * n2, Reeb /* The rest of the algorithm assumes that e1 is the longest edge */ - if (len1 >= len2 && len1 >= len3) - { + if (len1 >= len2 && len1 >= len3) { e1 = re1; e2 = re2; e3 = re3; } - else if (len2 >= len1 && len2 >= len3) - { + else if (len2 >= len1 && len2 >= len3) { e1 = re2; e2 = re1; e3 = re3; } - else - { + else { e1 = re3; e2 = re2; e3 = re1; @@ -2554,8 +2391,7 @@ static void addTriangleToGraph(ReebGraph *rg, ReebNode * n1, ReebNode * n2, Reeb /* And e2 is the lowest edge * If e3 is lower than e2, swap them */ - if (e3->v1->weight < e2->v1->weight) - { + if (e3->v1->weight < e2->v1->weight) { ReebEdge *etmp = e2; e2 = e3; e3 = etmp; @@ -2595,10 +2431,8 @@ ReebGraph * generateReebGraph(EditMesh *em, int subdivisions) renormalizeWeight(em, (float)rg->resolution); /* Adding vertice */ - for (index = 0, eve = em->verts.first; eve; eve = eve->next) - { - if (eve->h == 0) - { + for (index = 0, eve = em->verts.first; eve; eve = eve->next) { + if (eve->h == 0) { addNode(rg, eve); eve->f2 = 0; index++; @@ -2606,10 +2440,8 @@ ReebGraph * generateReebGraph(EditMesh *em, int subdivisions) } /* Adding face, edge per edge */ - for (efa = em->faces.first; efa; efa = efa->next) - { - if (efa->h == 0) - { + for (efa = em->faces.first; efa; efa = efa->next) { + if (efa->h == 0) { ReebNode *n1, *n2, *n3; n1 = nodeData(efa->v1); @@ -2618,15 +2450,13 @@ ReebGraph * generateReebGraph(EditMesh *em, int subdivisions) addTriangleToGraph(rg, n1, n2, n3, efa); - if (efa->v4) - { + if (efa->v4) { ReebNode *n4 = nodeData(efa->v4); addTriangleToGraph(rg, n1, n3, n4, efa); } #ifdef DEBUG_REEB countfaces++; - if (countfaces % 100 == 0) - { + if (countfaces % 100 == 0) { printf("\rface %i of %i", countfaces, totfaces); } #endif @@ -2656,8 +2486,7 @@ void renormalizeWeight(EditMesh *em, float newmax) eve = em->verts.first; minimum = weightData(eve); maximum = minimum; - for (; eve; eve = eve->next) - { + for (; eve; eve = eve->next) { maximum = MAX2(maximum, weightData(eve)); minimum = MIN2(minimum, weightData(eve)); } @@ -2665,8 +2494,7 @@ void renormalizeWeight(EditMesh *em, float newmax) range = maximum - minimum; /* Normalize weights */ - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { float weight = (weightData(eve) - minimum) / range * newmax; weightSetData(eve, weight); } @@ -2681,8 +2509,7 @@ int weightFromLoc(EditMesh *em, int axis) return 0; /* Copy coordinate in weight */ - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { weightSetData(eve, eve->co[axis]); } @@ -2745,8 +2572,7 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) int rval; /* Find local extrema */ - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { totvert++; } @@ -2759,52 +2585,42 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) nlBegin(NL_SYSTEM); /* Find local extrema */ - for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) - { - if (eve->h == 0) - { + for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) { + if (eve->h == 0) { EditEdge *eed; int maximum = 1; int minimum = 1; NextEdgeForVert(indexed_edges, -1); /* Reset next edge */ - for (eed = NextEdgeForVert(indexed_edges, index); eed && (maximum || minimum); eed = NextEdgeForVert(indexed_edges, index)) - { + for (eed = NextEdgeForVert(indexed_edges, index); eed && (maximum || minimum); eed = NextEdgeForVert(indexed_edges, index)) { EditVert *eve2; - if (eed->v1 == eve) - { + if (eed->v1 == eve) { eve2 = eed->v2; } - else - { + else { eve2 = eed->v1; } - if (eve2->h == 0) - { + if (eve2->h == 0) { /* Adjacent vertex is bigger, not a local maximum */ - if (weightData(eve2) > weightData(eve)) - { + if (weightData(eve2) > weightData(eve)) { maximum = 0; } /* Adjacent vertex is smaller, not a local minimum */ - else if (weightData(eve2) < weightData(eve)) - { + else if (weightData(eve2) < weightData(eve)) { minimum = 0; } } } - if (maximum || minimum) - { + if (maximum || minimum) { float w = weightData(eve); eve->f1 = 0; nlSetVariable(0, index, w); nlLockVariable(index); } - else - { + else { eve->f1 = 1; } } @@ -2813,38 +2629,30 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) nlBegin(NL_MATRIX); /* Zero edge weight */ - for (eed = em->edges.first; eed; eed = eed->next) - { + for (eed = em->edges.first; eed; eed = eed->next) { eed->tmp.l = 0; } /* Add faces count to the edge weight */ - for (efa = em->faces.first; efa; efa = efa->next) - { - if (efa->h == 0) - { + for (efa = em->faces.first; efa; efa = efa->next) { + if (efa->h == 0) { efa->e1->tmp.l++; efa->e2->tmp.l++; efa->e3->tmp.l++; - if (efa->e4) - { + if (efa->e4) { efa->e4->tmp.l++; } } } /* Add faces angle to the edge weight */ - for (efa = em->faces.first; efa; efa = efa->next) - { - if (efa->h == 0) - { - if (efa->v4 == NULL) - { + for (efa = em->faces.first; efa; efa = efa->next) { + if (efa->h == 0) { + if (efa->v4 == NULL) { addTriangle(efa->v1, efa->v2, efa->v3, efa->e1->tmp.l, efa->e2->tmp.l, efa->e3->tmp.l); } - else - { + else { addTriangle(efa->v1, efa->v2, efa->v3, efa->e1->tmp.l, efa->e2->tmp.l, 2); addTriangle(efa->v3, efa->v4, efa->v1, efa->e3->tmp.l, efa->e4->tmp.l, 2); } @@ -2857,16 +2665,13 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) success = nlSolveAdvanced(NULL, NL_TRUE); - if (success) - { + if (success) { rval = 1; - for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) - { + for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) { weightSetData(eve, nlGetVariable(0, index)); } } - else - { + else { rval = 0; } @@ -2881,20 +2686,17 @@ EditEdge * NextEdgeForVert(EdgeIndex *indexed_edges, int index) static int offset = -1; /* Reset method, call with NULL mesh pointer */ - if (index == -1) - { + if (index == -1) { offset = -1; return NULL; } /* first pass, start at the head of the list */ - if (offset == -1) - { + if (offset == -1) { offset = indexed_edges->offset[index]; } /* subsequent passes, start on the next edge */ - else - { + else { offset++; } @@ -2916,23 +2718,19 @@ static void shortestPathsFromVert(EditMesh *em, EditVert *starting_vert, EdgeInd BLI_heap_insert(edge_heap, FLT_MAX, NULL); /* Initialize edge flag */ - for (eed= em->edges.first; eed; eed= eed->next) - { + for (eed= em->edges.first; eed; eed= eed->next) { eed->f1 = 0; } - while (BLI_heap_size(edge_heap) > 0) - { + while (BLI_heap_size(edge_heap) > 0) { float current_weight; current_eve->f1 = 1; /* mark vertex as selected */ /* Add all new edges connected to current_eve to the list */ NextEdgeForVert(indexed_edges, -1); // Reset next edge - for (eed = NextEdgeForVert(indexed_edges, indexData(current_eve)); eed; eed = NextEdgeForVert(indexed_edges, indexData(current_eve))) - { - if (eed->f1 == 0) - { + for (eed = NextEdgeForVert(indexed_edges, indexData(current_eve)); eed; eed = NextEdgeForVert(indexed_edges, indexData(current_eve))) { + if (eed->f1 == 0) { BLI_heap_insert(edge_heap, weightData(current_eve) + eed->tmp.fp, eed); eed->f1 = 1; } @@ -2945,16 +2743,13 @@ static void shortestPathsFromVert(EditMesh *em, EditVert *starting_vert, EdgeInd select_eed = BLI_heap_popmin(edge_heap); } while (select_eed != NULL && select_eed->v1->f1 != 0 && select_eed->v2->f1); - if (select_eed != NULL) - { + if (select_eed != NULL) { select_eed->f1 = 2; - if (select_eed->v1->f1 == 0) /* v1 is the new vertex */ - { + if (select_eed->v1->f1 == 0) /* v1 is the new vertex */ { current_eve = select_eed->v1; } - else /* otherwise, it's v2 */ - { + else { /* otherwise, it's v2 */ current_eve = select_eed->v2; } @@ -2983,10 +2778,8 @@ static void buildIndexedEdges(EditMesh *em, EdgeIndex *indexed_edges) indexed_edges->offset = MEM_callocN(totvert * sizeof(int), "EdgeIndex offset"); - for (eed = em->edges.first; eed; eed = eed->next) - { - if (eed->v1->h == 0 && eed->v2->h == 0) - { + for (eed = em->edges.first; eed; eed = eed->next) { + if (eed->v1->h == 0 && eed->v2->h == 0) { tot_indexed += 2; indexed_edges->offset[indexData(eed->v1)]++; indexed_edges->offset[indexData(eed->v2)]++; @@ -2998,10 +2791,8 @@ static void buildIndexedEdges(EditMesh *em, EdgeIndex *indexed_edges) indexed_edges->edges = MEM_callocN(tot_indexed * sizeof(EditEdge*), "EdgeIndex edges"); /* setting vert offsets */ - for (eve = em->verts.first; eve; eve = eve->next) - { - if (eve->h == 0) - { + for (eve = em->verts.first; eve; eve = eve->next) { + if (eve->h == 0) { int d = indexed_edges->offset[indexData(eve)]; indexed_edges->offset[indexData(eve)] = offset; offset += d + 1; @@ -3009,24 +2800,18 @@ static void buildIndexedEdges(EditMesh *em, EdgeIndex *indexed_edges) } /* adding edges in array */ - for (eed = em->edges.first; eed; eed= eed->next) - { - if (eed->v1->h == 0 && eed->v2->h == 0) - { + for (eed = em->edges.first; eed; eed= eed->next) { + if (eed->v1->h == 0 && eed->v2->h == 0) { int i; - for (i = indexed_edges->offset[indexData(eed->v1)]; i < tot_indexed; i++) - { - if (indexed_edges->edges[i] == NULL) - { + for (i = indexed_edges->offset[indexData(eed->v1)]; i < tot_indexed; i++) { + if (indexed_edges->edges[i] == NULL) { indexed_edges->edges[i] = eed; break; } } - for (i = indexed_edges->offset[indexData(eed->v2)]; i < tot_indexed; i++) - { - if (indexed_edges->edges[i] == NULL) - { + for (i = indexed_edges->offset[indexData(eed->v2)]; i < tot_indexed; i++) { + if (indexed_edges->edges[i] == NULL) { indexed_edges->edges[i] = eed; break; } @@ -3044,80 +2829,64 @@ int weightFromDistance(EditMesh *em, EdgeIndex *indexed_edges) totvert = BLI_countlist(&em->verts); - if (em == NULL || totvert == 0) - { + if (em == NULL || totvert == 0) { return 0; } totedge = BLI_countlist(&em->edges); - if (totedge == 0) - { + if (totedge == 0) { return 0; } /* Initialize vertice flag and find at least one selected vertex */ - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { eve->f1 = 0; - if (eve->f & SELECT) - { + if (eve->f & SELECT) { vCount = 1; } } - if (vCount == 0) - { + if (vCount == 0) { return 0; /* no selected vert, failure */ } - else - { + else { EditEdge *eed; int allDone = 0; /* Calculate edge weight */ - for (eed = em->edges.first; eed; eed= eed->next) - { - if (eed->v1->h == 0 && eed->v2->h == 0) - { + for (eed = em->edges.first; eed; eed= eed->next) { + if (eed->v1->h == 0 && eed->v2->h == 0) { eed->tmp.fp = len_v3v3(eed->v1->co, eed->v2->co); } } /* Apply dijkstra spf for each selected vert */ - for (eve = em->verts.first; eve; eve = eve->next) - { - if (eve->f & SELECT) - { + for (eve = em->verts.first; eve; eve = eve->next) { + if (eve->f & SELECT) { shortestPathsFromVert(em, eve, indexed_edges); } } /* connect unselected islands */ - while (allDone == 0) - { + while (allDone == 0) { EditVert *selected_eve = NULL; float selected_weight = 0; float min_distance = FLT_MAX; allDone = 1; - for (eve = em->verts.first; eve; eve = eve->next) - { + for (eve = em->verts.first; eve; eve = eve->next) { /* for every vertex visible that hasn't been processed yet */ - if (eve->h == 0 && eve->f1 != 1) - { + 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) - { + for (closest_eve = em->verts.first; closest_eve; closest_eve = closest_eve->next) { /* vertex is already processed and distance is smaller than current minimum */ - if (closest_eve->f1 == 1) - { + if (closest_eve->f1 == 1) { float distance = len_v3v3(closest_eve->co, eve->co); - if (distance < min_distance) - { + if (distance < min_distance) { min_distance = distance; selected_eve = eve; selected_weight = weightData(closest_eve); @@ -3127,8 +2896,7 @@ int weightFromDistance(EditMesh *em, EdgeIndex *indexed_edges) } } - if (selected_eve) - { + if (selected_eve) { allDone = 0; weightSetData(selected_eve, selected_weight + min_distance); @@ -3137,10 +2905,8 @@ int weightFromDistance(EditMesh *em, EdgeIndex *indexed_edges) } } - for (eve = em->verts.first; eve && vCount == 0; eve = eve->next) - { - if (eve->f1 == 0) - { + for (eve = em->verts.first; eve && vCount == 0; eve = eve->next) { + if (eve->f1 == 0) { printf("vertex not reached\n"); break; } @@ -3173,13 +2939,11 @@ static void initIteratorFct(ReebArcIterator *iter) static void setIteratorValues(ReebArcIterator *iter, EmbedBucket *bucket) { - if (bucket) - { + if (bucket) { iter->p = bucket->p; iter->no = bucket->no; } - else - { + else { iter->p = NULL; iter->no = NULL; } @@ -3193,14 +2957,12 @@ void initArcIterator(BArcIterator *arg, ReebArc *arc, ReebNode *head) initIteratorFct(iter); iter->arc = arc; - if (head == arc->head) - { + if (head == arc->head) { iter->start = 0; iter->end = arc->bcount - 1; iter->stride = 1; } - else - { + else { iter->start = arc->bcount - 1; iter->end = 0; iter->stride = -1; @@ -3218,14 +2980,12 @@ void initArcIteratorStart(BArcIterator *arg, struct ReebArc *arc, struct ReebNod initIteratorFct(iter); iter->arc = arc; - if (head == arc->head) - { + if (head == arc->head) { iter->start = start; iter->end = arc->bcount - 1; iter->stride = 1; } - else - { + else { iter->start = arc->bcount - 1 - start; iter->end = 0; iter->stride = -1; @@ -3235,8 +2995,7 @@ void initArcIteratorStart(BArcIterator *arg, struct ReebArc *arc, struct ReebNod iter->length = arc->bcount - start; - if (start >= arc->bcount) - { + if (start >= arc->bcount) { iter->start = iter->end; /* stop iterator since it's past its end */ } } @@ -3251,12 +3010,10 @@ void initArcIterator2(BArcIterator *arg, ReebArc *arc, int start, int end) iter->start = start; iter->end = end; - if (end > start) - { + if (end > start) { iter->stride = 1; } - else - { + else { iter->stride = -1; } @@ -3270,12 +3027,10 @@ static void* headNode(void *arg) ReebArcIterator *iter = (ReebArcIterator*)arg; ReebNode *node; - if (iter->start < iter->end) - { + if (iter->start < iter->end) { node = iter->arc->head; } - else - { + else { node = iter->arc->tail; } @@ -3291,12 +3046,10 @@ static void* tailNode(void *arg) ReebArcIterator *iter = (ReebArcIterator*)arg; ReebNode *node; - if (iter->start < iter->end) - { + if (iter->start < iter->end) { node = iter->arc->tail; } - else - { + else { node = iter->arc->head; } @@ -3314,8 +3067,7 @@ static void* nextBucket(void *arg) iter->index++; - if (iter->index < iter->length) - { + if (iter->index < iter->length) { result = &(iter->arc->buckets[iter->start + (iter->stride * iter->index)]); } @@ -3331,8 +3083,7 @@ static void* nextNBucket(void *arg, int n) iter->index += n; /* check if passed end */ - if (iter->index < iter->length) - { + if (iter->index < iter->length) { result = &(iter->arc->buckets[iter->start + (iter->stride * iter->index)]); } @@ -3347,8 +3098,7 @@ static void* peekBucket(void *arg, int n) int index = iter->index + n; /* check if passed end */ - if (index < iter->length) - { + if (index < iter->length) { result = &(iter->arc->buckets[iter->start + (iter->stride * index)]); } @@ -3361,8 +3111,7 @@ static void* previousBucket(void *arg) ReebArcIterator *iter = (ReebArcIterator*)arg; EmbedBucket *result = NULL; - if (iter->index > 0) - { + if (iter->index > 0) { iter->index--; result = &(iter->arc->buckets[iter->start + (iter->stride * iter->index)]); } @@ -3375,12 +3124,10 @@ static int iteratorStopped(void *arg) { ReebArcIterator *iter = (ReebArcIterator*)arg; - if (iter->index >= iter->length) - { + if (iter->index >= iter->length) { return 1; } - else - { + else { return 0; } } |