From 69e6894b15271884623ea6f56ead06db83acbe99 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 24 Mar 2012 06:18:31 +0000 Subject: style cleanup: follow style guide for formatting of if/for/while loops, and else if's --- source/blender/blenkernel/intern/shrinkwrap.c | 103 +++++++++++++------------- 1 file changed, 52 insertions(+), 51 deletions(-) (limited to 'source/blender/blenkernel/intern/shrinkwrap.c') diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 664a1d0d7f9..6513399c962 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -75,7 +75,7 @@ _t1 = ( double ) _tstart.tv_sec + ( double ) _tstart.tv_usec/ ( 1000*1000 ); \ _t2 = ( double ) _tend.tv_sec + ( double ) _tend.tv_usec/ ( 1000*1000 ); \ printf("%s: %fs (real) %fs (cpu)\n", #a, _t2-_t1, (float)(clock()-_clock_init)/CLOCKS_PER_SEC);\ - } while(0) + } while (0) #else @@ -92,7 +92,7 @@ DerivedMesh *object_get_derived_final(Object *ob) Mesh *me= ob->data; BMEditMesh *em = me->edit_btmesh; - if(em) { + if (em) { DerivedMesh *dm = em->derivedFinal; return dm; } @@ -146,7 +146,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) BENCH(bvhtree_from_mesh_verts(&treeData, calc->target, 0.0, 2, 6)); - if(treeData.tree == NULL) + if (treeData.tree == NULL) { OUT_OF_MEMORY(); return; @@ -158,16 +158,16 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) #ifndef __APPLE__ #pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData,calc) schedule(static) #endif - for(i = 0; inumVerts; ++i) + for (i = 0; inumVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3]; float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup); - if(weight == 0.0f) continue; + if (weight == 0.0f) continue; //Convert the vertex to tree coordinates - if(calc->vert) { + if (calc->vert) { copy_v3_v3(tmp_co, calc->vert[i].co); } else { @@ -180,7 +180,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) //If we already had an hit before.. we assume this vertex is going to have a close hit to that other vertex //so we can initiate the "nearest.dist" with the expected value to that last hit. //This will lead in prunning of the search tree. - if(nearest.index != -1) + if (nearest.index != -1) nearest.dist = len_squared_v3v3(tmp_co, nearest.co); else nearest.dist = FLT_MAX; @@ -189,11 +189,11 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) //Found the nearest vertex - if(nearest.index != -1) + if (nearest.index != -1) { //Adjusting the vertex weight, so that after interpolating it keeps a certain distance from the nearest position float dist = sasqrt(nearest.dist); - if(dist > FLT_EPSILON) weight *= (dist - calc->keepDist)/dist; + if (dist > FLT_EPSILON) weight *= (dist - calc->keepDist)/dist; //Convert the coordinates back to mesh coordinates copy_v3_v3(tmp_co, nearest.co); @@ -224,7 +224,7 @@ int normal_projection_project_vertex(char options, const float *vert, const floa memcpy( &hit_tmp, hit, sizeof(hit_tmp) ); //Apply space transform (TODO readjust dist) - if(transf) + if (transf) { copy_v3_v3( tmp_co, vert ); space_transform_apply( transf, tmp_co ); @@ -245,23 +245,23 @@ int normal_projection_project_vertex(char options, const float *vert, const floa BLI_bvhtree_ray_cast(tree, co, no, 0.0f, &hit_tmp, callback, userdata); - if(hit_tmp.index != -1) { + if (hit_tmp.index != -1) { /* invert the normal first so face culling works on rotated objects */ - if(transf) { + if (transf) { space_transform_invert_normal(transf, hit_tmp.no); } if (options & (MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE|MOD_SHRINKWRAP_CULL_TARGET_BACKFACE)) { /* apply backface */ const float dot= dot_v3v3(dir, hit_tmp.no); - if( ((options & MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE) && dot <= 0.0f) || + if ( ((options & MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE) && dot <= 0.0f) || ((options & MOD_SHRINKWRAP_CULL_TARGET_BACKFACE) && dot >= 0.0f) ) { return FALSE; /* Ignore hit */ } } - if(transf) { + if (transf) { /* Inverting space transform (TODO make coeherent with the initial dist readjust) */ space_transform_invert(transf, hit_tmp.co); hit_tmp.dist = len_v3v3((float *)vert, hit_tmp.co); @@ -293,62 +293,63 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) //If the user doesn't allows to project in any direction of projection axis //then theres nothing todo. - if((use_normal & (MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR | MOD_SHRINKWRAP_PROJECT_ALLOW_NEG_DIR)) == 0) + if ((use_normal & (MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR | MOD_SHRINKWRAP_PROJECT_ALLOW_NEG_DIR)) == 0) return; //Prepare data to retrieve the direction in which we should project each vertex - if(calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) + if (calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) { - if(calc->vert == NULL) return; + if (calc->vert == NULL) return; } else { //The code supports any axis that is a combination of X,Y,Z //although currently UI only allows to set the 3 different axis - if(calc->smd->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) proj_axis[0] = 1.0f; - if(calc->smd->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS) proj_axis[1] = 1.0f; - if(calc->smd->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Z_AXIS) proj_axis[2] = 1.0f; + if (calc->smd->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) proj_axis[0] = 1.0f; + if (calc->smd->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS) proj_axis[1] = 1.0f; + if (calc->smd->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Z_AXIS) proj_axis[2] = 1.0f; normalize_v3(proj_axis); //Invalid projection direction - if(dot_v3v3(proj_axis, proj_axis) < FLT_EPSILON) + if (dot_v3v3(proj_axis, proj_axis) < FLT_EPSILON) return; } - if(calc->smd->auxTarget) + if (calc->smd->auxTarget) { auxMesh = object_get_derived_final(calc->smd->auxTarget); - if(!auxMesh) + if (!auxMesh) return; space_transform_setup( &local2aux, calc->ob, calc->smd->auxTarget); } //After sucessufuly build the trees, start projection vertexs - if( bvhtree_from_mesh_faces(&treeData, calc->target, 0.0, 4, 6) + if ( bvhtree_from_mesh_faces(&treeData, calc->target, 0.0, 4, 6) && (auxMesh == NULL || bvhtree_from_mesh_faces(&auxData, auxMesh, 0.0, 4, 6))) { #ifndef __APPLE__ #pragma omp parallel for private(i,hit) schedule(static) #endif - for(i = 0; inumVerts; ++i) + for (i = 0; inumVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3], tmp_no[3]; float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup); - if(weight == 0.0f) continue; + if (weight == 0.0f) continue; - if(calc->vert) + if (calc->vert) { /* calc->vert contains verts from derivedMesh */ /* this coordinated are deformed by vertexCos only for normal projection (to get correct normals) */ /* for other cases calc->varts contains undeformed coordinates and vertexCos should be used */ - if(calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) { + if (calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) { copy_v3_v3(tmp_co, calc->vert[i].co); normal_short_to_float_v3(tmp_no, calc->vert[i].no); - } else { + } + else { copy_v3_v3(tmp_co, co); copy_v3_v3(tmp_no, proj_axis); } @@ -363,29 +364,29 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) hit.dist = 10000.0f; //TODO: we should use FLT_MAX here, but sweepsphere code isn't prepared for that //Project over positive direction of axis - if(use_normal & MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR) + if (use_normal & MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR) { - if(auxData.tree) + if (auxData.tree) normal_projection_project_vertex(0, tmp_co, tmp_no, &local2aux, auxData.tree, &hit, auxData.raycast_callback, &auxData); normal_projection_project_vertex(calc->smd->shrinkOpts, tmp_co, tmp_no, &calc->local2target, treeData.tree, &hit, treeData.raycast_callback, &treeData); } //Project over negative direction of axis - if(use_normal & MOD_SHRINKWRAP_PROJECT_ALLOW_NEG_DIR && hit.index == -1) + if (use_normal & MOD_SHRINKWRAP_PROJECT_ALLOW_NEG_DIR && hit.index == -1) { float inv_no[3]; negate_v3_v3(inv_no, tmp_no); - if(auxData.tree) + if (auxData.tree) normal_projection_project_vertex(0, tmp_co, inv_no, &local2aux, auxData.tree, &hit, auxData.raycast_callback, &auxData); normal_projection_project_vertex(calc->smd->shrinkOpts, tmp_co, inv_no, &calc->local2target, treeData.tree, &hit, treeData.raycast_callback, &treeData); } - if(hit.index != -1) + if (hit.index != -1) { madd_v3_v3v3fl(hit.co, hit.co, tmp_no, calc->keepDist); interp_v3_v3v3(co, co, hit.co, weight); @@ -413,7 +414,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) //Create a bvh-tree of the given target BENCH(bvhtree_from_mesh_faces( &treeData, calc->target, 0.0, 2, 6)); - if(treeData.tree == NULL) + if (treeData.tree == NULL) { OUT_OF_MEMORY(); return; @@ -428,15 +429,15 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) #ifndef __APPLE__ #pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(calc,treeData) schedule(static) #endif - for(i = 0; inumVerts; ++i) + for (i = 0; inumVerts; ++i) { float *co = calc->vertexCos[i]; float tmp_co[3]; float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup); - if(weight == 0.0f) continue; + if (weight == 0.0f) continue; //Convert the vertex to tree coordinates - if(calc->vert) { + if (calc->vert) { copy_v3_v3(tmp_co, calc->vert[i].co); } else { @@ -449,7 +450,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) //If we already had an hit before.. we assume this vertex is going to have a close hit to that other vertex //so we can initiate the "nearest.dist" with the expected value to that last hit. //This will lead in prunning of the search tree. - if(nearest.index != -1) + if (nearest.index != -1) nearest.dist = len_squared_v3v3(tmp_co, nearest.co); else nearest.dist = FLT_MAX; @@ -457,9 +458,9 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) BLI_bvhtree_find_nearest(treeData.tree, tmp_co, &nearest, treeData.nearest_callback, &treeData); //Found the nearest vertex - if(nearest.index != -1) + if (nearest.index != -1) { - if(calc->smd->shrinkOpts & MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE) + if (calc->smd->shrinkOpts & MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE) { //Make the vertex stay on the front side of the face madd_v3_v3v3fl(tmp_co, nearest.co, nearest.no, calc->keepDist); @@ -467,7 +468,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) else { //Adjusting the vertex weight, so that after interpolating it keeps a certain distance from the nearest position float dist = sasqrt( nearest.dist ); - if(dist > FLT_EPSILON) + if (dist > FLT_EPSILON) interp_v3_v3v3(tmp_co, tmp_co, nearest.co, (dist - calc->keepDist)/dist); //linear interpolation else copy_v3_v3( tmp_co, nearest.co ); @@ -490,8 +491,8 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM ShrinkwrapCalcData calc = NULL_ShrinkwrapCalcData; //remove loop dependencies on derived meshs (TODO should this be done elsewhere?) - if(smd->target == ob) smd->target = NULL; - if(smd->auxTarget == ob) smd->auxTarget = NULL; + if (smd->target == ob) smd->target = NULL; + if (smd->auxTarget == ob) smd->auxTarget = NULL; //Configure Shrinkwrap calc data @@ -502,7 +503,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM //DeformVertex calc.vgroup = defgroup_name_index(calc.ob, calc.smd->vgroup_name); - if(dm) { + if (dm) { calc.dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); } else if (calc.ob->type == OB_LATTICE) { @@ -510,7 +511,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM } - if(smd->target) + if (smd->target) { calc.target = object_get_derived_final(smd->target); @@ -527,14 +528,14 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM calc.vgroup = defgroup_name_index(calc.ob, smd->vgroup_name); - if(dm != NULL && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) + if (dm != NULL && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) { //Setup arrays to get vertexs positions, normals and deform weights calc.vert = dm->getVertDataArray(dm, CD_MVERT); calc.dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); //Using vertexs positions/normals as if a subsurface was applied - if(smd->subsurfLevels) + if (smd->subsurfLevels) { SubsurfModifierData ssmd= {{NULL}}; ssmd.subdivType = ME_CC_SUBSURF; //catmull clark @@ -542,10 +543,10 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM ss_mesh = subsurf_make_derived_from_derived(dm, &ssmd, FALSE, NULL, 0, 0, (ob->mode & OB_MODE_EDIT)); - if(ss_mesh) + if (ss_mesh) { calc.vert = ss_mesh->getVertDataArray(ss_mesh, CD_MVERT); - if(calc.vert) + if (calc.vert) { //TRICKY: this code assumes subsurface will have the transformed original vertices //in their original order at the end of the vert array. @@ -578,7 +579,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM } //free memory - if(ss_mesh) + if (ss_mesh) ss_mesh->release(ss_mesh); } -- cgit v1.2.3