commit fbd485c3aec744d8f8572181e6e542be22697a84 Author: Campbell Barton Date: Thu Apr 24 19:52:05 2014 +1000 cleanup diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index ffd190c..09311a4 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -2517,17 +2517,15 @@ void CDDM_calc_normals_tessface(DerivedMesh *dm) #if 1 /** * Poly compare with vtargetmap - * Function used by CDDM_merge_verts. + * Function used by #CDDM_merge_verts. * The function compares poly_source after applying vtargetmap, with poly_target. * The two polys are identical if they share the same vertices in the same order, or in reverse order. * The function is called with direct_reverse=1 for same order, and may be called again with direct_reverse=-1 for reverse order. - * Returns 1 if polys are identical, 0 if polys are different. + * \return 1 if polys are identical, 0 if polys are different. */ -int CDDM_poly_compare(DerivedMesh *dm, MPoly *mpoly_source, MPoly *mpoly_target, const int *vtargetmap, const int direct_reverse) +static int cddm_poly_compare(MLoop *mloop_array, MPoly *mpoly_source, MPoly *mpoly_target, const int *vtargetmap, const int direct_reverse) { - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - int vert_source, first_vert_source, vert_target; int i_loop_source; int i_loop_target, i_loop_target_start, i_loop_target_offset, i_loop_target_adjusted; @@ -2539,7 +2537,7 @@ int CDDM_poly_compare(DerivedMesh *dm, MPoly *mpoly_source, MPoly *mpoly_target, BLI_assert(direct_reverse == 1 || direct_reverse == -1); i_loop_source = 0; - mloop_source = cddm->mloop + mpoly_source->loopstart; + mloop_source = mloop_array + mpoly_source->loopstart; vert_source = mloop_source->v; if (vtargetmap[vert_source] != -1) @@ -2550,15 +2548,15 @@ int CDDM_poly_compare(DerivedMesh *dm, MPoly *mpoly_source, MPoly *mpoly_target, } /* Find same vertex within mpoly_target's loops */ - mloop_target = cddm->mloop + mpoly_target->loopstart; + mloop_target = mloop_array + mpoly_target->loopstart; for (i_loop_target = 0; i_loop_target < mpoly_target->totloop; i_loop_target++, mloop_target++) { if (mloop_target->v == vert_source) break; } - + /* If same vertex not found, then polys cannot be equal */ if (i_loop_target >= mpoly_target->totloop) { - return false; + return false; } /* Now mloop_source and m_loop_target have one identical vertex */ @@ -2617,7 +2615,7 @@ int CDDM_poly_compare(DerivedMesh *dm, MPoly *mpoly_source, MPoly *mpoly_target, if (i_loop_target_offset == mpoly_target->totloop) { /* End of loops for target only, that means no match */ /* except if all remaining source vertices are mapped to first target */ - for (; i_loop_source < mpoly_source->totloop; i_loop_source++, mloop_source++){ + for (; i_loop_source < mpoly_source->totloop; i_loop_source++, mloop_source++) { vert_source = vtargetmap[mloop_source->v]; if (vert_source != first_vert_source) { compare_completed = true; @@ -2635,45 +2633,49 @@ int CDDM_poly_compare(DerivedMesh *dm, MPoly *mpoly_source, MPoly *mpoly_target, i_loop_target_adjusted = (i_loop_target_start + direct_reverse * i_loop_target_offset) % mpoly_target->totloop; if (i_loop_target_adjusted < 0) i_loop_target_adjusted += mpoly_target->totloop; - mloop_target = cddm->mloop + mpoly_target->loopstart + i_loop_target_adjusted; + mloop_target = mloop_array + mpoly_target->loopstart + i_loop_target_adjusted; vert_target = mloop_target->v; if (vert_target != vert_source) { - same_loops= false; /* Polys are different */ + same_loops = false; /* Polys are different */ break; } } - return same_loops; + return same_loops; } /* Utility stuff for using GHash with polys */ -typedef struct poly_summary { +typedef struct PolyKey { int poly_index; /* index of the MPoly within the derived mesh */ int totloops; /* number of loops in the poly */ unsigned int hash_sum; /* Sum of all vertices indices */ unsigned int hash_xor; /* Xor of all vertices indices */ -} poly_summary; - +} PolyKey; -unsigned int poly_ghash_hash_fn(const void *key) { - poly_summary *ps = (poly_summary*)key; +static unsigned int poly_ghash_hash_fn(const void *key) +{ + PolyKey *ps = (PolyKey *)key; return ps->hash_sum; } -int poly_ghash_compare_fn(const void *k1, const void *k2) { - poly_summary *ps1 = (poly_summary*)k1; - poly_summary *ps2 = (poly_summary*)k2; - if (ps1->hash_sum == ps2->hash_sum - && ps1->hash_xor == ps2->hash_xor - && ps1->totloops == ps2->totloops) - return 0; /* Equality - note that this does not mean equality of polys */ - else +static int poly_ghash_compare_fn(const void *k1, const void *k2) +{ + PolyKey *ps1 = (PolyKey *)k1; + PolyKey *ps2 = (PolyKey *)k2; + if (ps1->hash_sum == ps2->hash_sum && + ps1->hash_xor == ps2->hash_xor && + ps1->totloops == ps2->totloops) + { + /* Equality - note that this does not mean equality of polys */ + return 0; + } + else { return 1; + } } - /** * Merge Verts * @@ -2688,13 +2690,13 @@ int poly_ghash_compare_fn(const void *k1, const void *k2) { * * note, CDDM_recalc_tessellation has to run on the returned DM if you want to access tessfaces. * - * Note: This function has two modes. + * Note: This function has two modes. * When called by the Mirror Modifier, it uses merge_mode= MERGE_MIRROR (=1). * In this mode it skips any faces that have all vertices merged (to avoid creating pairs * of faces sharing the same set of vertices) * When called by the Array Modifier, it uses merge_mode= MERGE_ARRAY (=2). * In this mode, faces where all vertices are merged are double-checked, to see whether - * all target vertices actually make up a poly already. Indeed it could be that all of a poly's + * all target vertices actually make up a poly already. Indeed it could be that all of a poly's * vertices are merged, but merged to vertices that do not make up a single poly, in which case * the original poly should not be dumped. * Actually this latter behaviour could apply to MERGE_MIRROR as well, but the additionnal checks are @@ -2742,6 +2744,11 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int int i, j, c; + PolyKey *poly_summarys; + + GHash *poly_ghash; + int tot_processed = 0, tot_allmerged = 0, tot_hashmatch = 0, tot_finalmatch = 0; + STACK_INIT(oldv); STACK_INIT(olde); STACK_INIT(oldl); @@ -2752,10 +2759,6 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int STACK_INIT(mloop); STACK_INIT(mpoly); - poly_summary *poly_summarys; - GHash *poly_ghash; - int tot_processed = 0, tot_allmerged = 0, tot_hashmatch = 0, tot_finalmatch = 0; - /* fill newl with destination vertex indices */ mv = cddm->mvert; c = 0; @@ -2812,10 +2815,9 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int /* In this mode, we need to determine, whenever a poly' vertices are all mapped */ /* if the targets already make up a poly, in which case the new poly is dropped */ /* This poly equality check is rather complex. We use a BLI_ghash to speed it up with a first level check */ - poly_summary *mpgh; - poly_summarys = (poly_summary*) MEM_mallocN(sizeof(poly_summary)* totpoly, "CDDM_merge_verts poly summarys"); - poly_ghash = BLI_ghash_new_ex(poly_ghash_hash_fn, poly_ghash_compare_fn, "CDDM merge verts poly hash", - totpoly); + PolyKey *mpgh; + poly_summarys = MEM_mallocN(sizeof(PolyKey) * totpoly, "CDDM_merge_verts poly summarys"); + poly_ghash = BLI_ghash_new_ex(poly_ghash_hash_fn, poly_ghash_compare_fn, "CDDM merge verts poly hash", totpoly); BLI_ghash_flag_set(poly_ghash, GHASH_FLAG_ALLOW_DUPES); /* Duplicates allowed because our compare function is not pure equality */ mp = cddm->mpoly; @@ -2839,9 +2841,10 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int /* Can we reuse an old pmap, when was it built, when does it become stale ? */ /* When called by MOD_array.c, the cddm has just been created, so it has no valid pmap. */ BKE_mesh_vert_poly_map_create(&cddm->pmap, &cddm->pmap_mem, - cddm->mpoly, cddm->mloop, - totvert, totpoly, totloop); - } /* Done preparing for fast poly compare */ + cddm->mpoly, cddm->mloop, + totvert, totpoly, totloop); + } + /* Done preparing for fast poly compare */ mp = cddm->mpoly; @@ -2873,8 +2876,8 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int /* We will need a map of vertices to polys */ int i_poly, v_target, v_prev; bool found = false; - poly_summary psummary; - poly_summary *psummary_found; + PolyKey psummary; + PolyKey *psummary_found; tot_allmerged++; @@ -2897,7 +2900,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int v_prev = v_target; } - if (psummary_found = BLI_ghash_lookup(poly_ghash, &psummary)) { + if ((psummary_found = BLI_ghash_lookup(poly_ghash, &psummary))) { /* There might be a poly that matches this one */ /* We might just leave it there and say there is, and do a "continue". */ @@ -2916,8 +2919,9 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int for (i_poly = 0; i_poly < cddm->pmap[v_target].count; i_poly++) { MPoly *target_poly = cddm->mpoly + *(cddm->pmap[v_target].indices + i_poly); - if (CDDM_poly_compare(dm, mp, target_poly, vtargetmap, +1) - || CDDM_poly_compare(dm, mp, target_poly, vtargetmap, -1)) { + if (cddm_poly_compare(cddm->mloop, mp, target_poly, vtargetmap, +1) || + cddm_poly_compare(cddm->mloop, mp, target_poly, vtargetmap, -1)) + { found = true; break; } diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index 6d4ad58..e85f4d2 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -256,7 +256,7 @@ static void map_doubles( int source_start, int source_num_verts, float dist, - bool with_follow, + bool with_follow, float *duration) { const float dist3 = 3 * dist; @@ -553,7 +553,6 @@ static DerivedMesh *arrayModifier_doArray_2( float final_offset[4][4]; int *full_doubles_map = NULL; int tot_doubles; - bool exist_double; float tot_time_doubles = 0; int start_cap_nverts = 0, start_cap_nedges = 0, start_cap_npolys = 0, start_cap_nloops = 0; @@ -741,7 +740,7 @@ static DerivedMesh *arrayModifier_doArray_2( /* Mapping chunk 3 to chunk 2 is a translation of mapping 2 to 1 */ /* ... that is except if scaling makes the distance grow */ int k; - int this_chunk_index = c* chunk_nverts; + int this_chunk_index = c * chunk_nverts; int prev_chunk_index = (c - 1) * chunk_nverts; for (k = 0; k < chunk_nverts; k++, this_chunk_index++, prev_chunk_index++) { int target = full_doubles_map[prev_chunk_index]; @@ -757,14 +756,14 @@ static DerivedMesh *arrayModifier_doArray_2( } else { map_doubles(full_doubles_map, - result_dm_verts, - (c - 1) * chunk_nverts, - chunk_nverts, - c * chunk_nverts, - chunk_nverts, - amd->merge_dist, - false, - &tot_time_doubles); + result_dm_verts, + (c - 1) * chunk_nverts, + chunk_nverts, + c * chunk_nverts, + chunk_nverts, + amd->merge_dist, + false, + &tot_time_doubles); } } } @@ -786,7 +785,7 @@ static DerivedMesh *arrayModifier_doArray_2( last_chunk_start, last_chunk_nverts, amd->merge_dist, - false, + false, &tot_time_doubles); } @@ -813,7 +812,7 @@ static DerivedMesh *arrayModifier_doArray_2( start_cap_start, start_cap_nverts, amd->merge_dist, - false, + false, &tot_time_doubles); } } @@ -838,7 +837,7 @@ static DerivedMesh *arrayModifier_doArray_2( end_cap_start, end_cap_nverts, amd->merge_dist, - false, + false, &tot_time_doubles); } } @@ -852,7 +851,7 @@ static DerivedMesh *arrayModifier_doArray_2( tot_doubles++; } - if (tot_doubles>0) { + if (tot_doubles > 0) { double t1, t2; t1 = PIL_check_seconds_timer(); result_dm = CDDM_merge_verts(result_dm, full_doubles_map, tot_doubles, CDDM_MERGE_VERTS_ARRAY);