From c93978d445de1c33f49f2f49ccfd9dbe7d202abc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 24 Oct 2012 11:31:57 +0000 Subject: code cleanup: some edits for unused vars in recent smooth addition and some style edits. --- source/blender/blenkernel/intern/image.c | 12 ++- .../blender/bmesh/operators/bmo_smooth_laplacian.c | 33 +++--- source/blender/editors/mesh/editmesh_tools.c | 6 +- .../editors/transform/transform_conversions.c | 7 +- source/blender/makesrna/intern/makesrna.c | 4 +- .../blender/modifiers/intern/MOD_laplaciansmooth.c | 112 +++++++++++---------- .../blender/render/intern/source/convertblender.c | 4 +- 7 files changed, 97 insertions(+), 81 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 037f7331f3f..ef751ce3493 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -1832,9 +1832,11 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf) } if (imf->depth == R_IMF_CHAN_DEPTH_16) { ibuf->ftype |= CINEON_16BIT; - } else if (imf->depth == R_IMF_CHAN_DEPTH_12) { + } + else if (imf->depth == R_IMF_CHAN_DEPTH_12) { ibuf->ftype |= CINEON_12BIT; - } else if (imf->depth == R_IMF_CHAN_DEPTH_10) { + } + else if (imf->depth == R_IMF_CHAN_DEPTH_10) { ibuf->ftype |= CINEON_10BIT; } } @@ -1845,9 +1847,11 @@ int BKE_imbuf_write(ImBuf *ibuf, const char *name, ImageFormatData *imf) } if (imf->depth == R_IMF_CHAN_DEPTH_16) { ibuf->ftype |= CINEON_16BIT; - } else if (imf->depth == R_IMF_CHAN_DEPTH_12) { + } + else if (imf->depth == R_IMF_CHAN_DEPTH_12) { ibuf->ftype |= CINEON_12BIT; - } else if (imf->depth == R_IMF_CHAN_DEPTH_10) { + } + else if (imf->depth == R_IMF_CHAN_DEPTH_10) { ibuf->ftype |= CINEON_10BIT; } } diff --git a/source/blender/bmesh/operators/bmo_smooth_laplacian.c b/source/blender/bmesh/operators/bmo_smooth_laplacian.c index ccbc85a617c..0c367514a93 100644 --- a/source/blender/bmesh/operators/bmo_smooth_laplacian.c +++ b/source/blender/bmesh/operators/bmo_smooth_laplacian.c @@ -69,7 +69,7 @@ struct BLaplacianSystem { }; typedef struct BLaplacianSystem LaplacianSystem; -static float compute_volume(BMesh *bm, BMOperator *op); +static float compute_volume(BMesh *bm); static float cotan_weight(float *v1, float *v2, float *v3); static int vert_is_boundary(BMVert *v); static LaplacianSystem * init_laplacian_system( int a_numEdges, int a_numFaces, int a_numVerts); @@ -78,7 +78,7 @@ static void delete_laplacian_system(LaplacianSystem * sys); static void delete_void_pointer(void * data); static void fill_laplacian_matrix(LaplacianSystem * sys); static void memset_laplacian_system(LaplacianSystem *sys, int val); -static void validate_solution(LaplacianSystem * sys, int usex, int usey, int usez, float lambda, float lambda_border, int volumepreservation); +static void validate_solution(LaplacianSystem * sys, int usex, int usey, int usez, int volumepreservation); static void volume_preservation(BMesh *bm, BMOperator *op, float vini, float vend, int usex, int usey, int usez); static void delete_void_pointer(void * data) @@ -230,7 +230,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys) if (has_4_vert) { areaf = area_quad_v3(v1, v2, v3, v4); - } else { + } + else { areaf = area_tri_v3(v1, v2, v3); } @@ -270,7 +271,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys) sys->vweights[idv1] += (w2 + w3 + w4) / 4.0f; } - } else { + } + else { i = BM_elem_index_get(f); w1 = cotan_weight(v1, v2, v3); @@ -341,7 +343,8 @@ static void fill_laplacian_matrix(LaplacianSystem * sys) nlMatrixAdd(idv1, idv4, w4 * sys->vweights[idv1]); } } - } else { + } + else { idv1 = BM_elem_index_get(vf[0]); idv2 = BM_elem_index_get(vf[1]); idv3 = BM_elem_index_get(vf[2]); @@ -412,7 +415,7 @@ static int vert_is_boundary(BMVert *v) return 0; } -static float compute_volume(BMesh *bm, BMOperator *op) +static float compute_volume(BMesh *bm) { float vol = 0.0f; float x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4; @@ -474,7 +477,7 @@ static void volume_preservation(BMesh *bm, BMOperator *op, float vini, float ven } } -static void validate_solution(LaplacianSystem * sys, int usex, int usey, int usez, float lambda, float lambda_border, int volumepreservation) +static void validate_solution(LaplacianSystem * sys, int usex, int usey, int usez, int volumepreservation) { int m_vertex_id; float leni, lene; @@ -506,7 +509,7 @@ static void validate_solution(LaplacianSystem * sys, int usex, int usey, int use } if (volumepreservation) { - vini = compute_volume(sys->bm, sys->op); + vini = compute_volume(sys->bm); } BMO_ITER (v, &siter, sys->bm, sys->op, "verts", BM_VERT) { m_vertex_id = BM_elem_index_get(v); @@ -523,7 +526,7 @@ static void validate_solution(LaplacianSystem * sys, int usex, int usey, int use } } if (volumepreservation) { - vend = compute_volume(sys->bm, sys->op); + vend = compute_volume(sys->bm); volume_preservation(sys->bm, sys->op, vini, vend, usex, usey, usez); } @@ -587,16 +590,18 @@ void bmo_smooth_laplacian_vert_exec(BMesh *bm, BMOperator *op) i = m_vertex_id; if (sys->zerola[i] == 0) { w = sys->vweights[i] * sys->ring_areas[i]; - sys->vweights[i] = (w == 0.0f) ? 0.0f : - lambda / (4.0f * w); + sys->vweights[i] = (w == 0.0f) ? 0.0f : -lambda / (4.0f * w); w = sys->vlengths[i]; - sys->vlengths[i] = (w == 0.0f) ? 0.0f : - lambda_border * 2.0f / w; + sys->vlengths[i] = (w == 0.0f) ? 0.0f : -lambda_border * 2.0f / w; if (!vert_is_boundary(v)) { nlMatrixAdd(i, i, 1.0f + lambda / (4.0f * sys->ring_areas[i])); - } else { + } + else { nlMatrixAdd(i, i, 1.0f + lambda_border * 2.0f); } - } else { + } + else { nlMatrixAdd(i, i, 1.0f); } } @@ -606,7 +611,7 @@ void bmo_smooth_laplacian_vert_exec(BMesh *bm, BMOperator *op) nlEnd(NL_SYSTEM); if (nlSolveAdvanced(NULL, NL_TRUE) ) { - validate_solution(sys, usex, usey, usez, lambda, lambda_border, volumepreservation); + validate_solution(sys, usex, usey, usez, volumepreservation); } delete_laplacian_system(sys); diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 4e13833d85c..dd0cc08bf37 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -1672,15 +1672,15 @@ static int edbm_do_smooth_laplacian_vertex_exec(bContext *C, wmOperator *op) BMEditMesh *em = BMEdit_FromObject(obedit); int usex = TRUE, usey = TRUE, usez = TRUE, volume_preservation = TRUE; int i, repeat; - float lambda = 0.1f; - float lambda_border = 0.1f; + float lambda; + float lambda_border; BMIter fiter; BMFace *f; /* Check if select faces are triangles */ BM_ITER_MESH (f, &fiter, em->bm, BM_FACES_OF_MESH) { if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { - if(f->len > 4) { + if (f->len > 4) { BKE_report(op->reports, RPT_WARNING, "Selected faces must be triangles or quads"); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 54c38ba2d53..d77cf5cadd4 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -2378,11 +2378,12 @@ static void createTransUVs(bContext *C, TransInfo *t) if (!ED_space_image_show_uvedit(sima, t->obedit)) return; /* count */ - if(propconnected) { + if (propconnected) { /* create element map with island information */ if (ts->uv_flag & UV_SYNC_SELECTION) { elementmap = EDBM_uv_element_map_create (em, FALSE, TRUE); - } else { + } + else { elementmap = EDBM_uv_element_map_create (em, TRUE, TRUE); } island_enabled = MEM_callocN(sizeof(*island_enabled) * elementmap->totalIslands, "TransIslandData(UV Editing)"); @@ -2401,7 +2402,7 @@ static void createTransUVs(bContext *C, TransInfo *t) if (uvedit_uv_select_test(em, scene, l)) { countsel++; - if(propconnected) { + if (propconnected) { UvElement *element = ED_uv_element_get(elementmap, efa, l); island_enabled[element->island] = TRUE; } diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 6b6da122b3c..f049077aa3c 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -3384,13 +3384,13 @@ static const char *cpp_classes = "" " DynamicArray(const DynamicArray& other) { copy_from(other); }\n" " const DynamicArray& operator=(const DynamicArray& other) { copy_from(other); return *this; }\n" "\n" -" ~DynamicArray() { if(data) free(data); }\n" +" ~DynamicArray() { if (data) free(data); }\n" "\n" " operator T*() { return data; }\n" "\n" "protected:\n" " void copy_from(const DynamicArray& other) {\n" -" if(data) free(data);\n" +" if (data) free(data);\n" " data = (float*)malloc(sizeof(T) * other.length);\n" " memcpy(data, other.data, sizeof(T) * other.length);\n" " length = other.length;\n" diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c index 103d959dfc6..d20fd151534 100644 --- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c +++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c @@ -56,21 +56,21 @@ #define MOD_LAPLACIANSMOOTH_MIN_EDGE_PERCENTAGE 0.02 struct BLaplacianSystem { - float *eweights; /* Length weights per Edge */ + float *eweights; /* Length weights per Edge */ float (*fweights)[3]; /* Cotangent weights per face */ - float *ring_areas; /* Total area per ring*/ - float *vlengths; /* Total sum of lengths(edges) per vertice*/ - float *vweights; /* Total sum of weights per vertice*/ - int numEdges; /* Number of edges*/ - int numFaces; /* Number of faces*/ - int numVerts; /* Number of verts*/ - short *numNeFa; /* Number of neighboors faces around vertice*/ - short *numNeEd; /* Number of neighboors Edges around vertice*/ - short *zerola; /* Is zero area or length*/ + float *ring_areas; /* Total area per ring*/ + float *vlengths; /* Total sum of lengths(edges) per vertice*/ + float *vweights; /* Total sum of weights per vertice*/ + int numEdges; /* Number of edges*/ + int numFaces; /* Number of faces*/ + int numVerts; /* Number of verts*/ + short *numNeFa; /* Number of neighboors faces around vertice*/ + short *numNeEd; /* Number of neighboors Edges around vertice*/ + short *zerola; /* Is zero area or length*/ /* Pointers to data*/ float (*vertexCos)[3]; - MFace *mfaces; + MFace *mfaces; MEdge *medges; NLContext *context; @@ -86,14 +86,14 @@ static float compute_volume(float (*vertexCos)[3], MFace *mfaces, int numFaces); static float cotan_weight(float *v1, float *v2, float *v3); static LaplacianSystem * init_laplacian_system( int a_numEdges, int a_numFaces, int a_numVerts); static void copy_data(ModifierData *md, ModifierData *target); -static void delete_laplacian_system(LaplacianSystem * sys); +static void delete_laplacian_system(LaplacianSystem *sys); static void delete_void_pointer(void * data); -static void fill_laplacian_matrix(LaplacianSystem * sys); +static void fill_laplacian_matrix(LaplacianSystem *sys); static void init_data(ModifierData *md); -static void init_laplacian_matrix(LaplacianSystem * sys); +static void init_laplacian_matrix(LaplacianSystem *sys); static void memset_laplacian_system(LaplacianSystem *sys, int val); static void volume_preservation(LaplacianSystem *sys, float vini, float vend, short flag); -static void validate_solution(LaplacianSystem * sys, short flag, float lambda, float lambda_border); +static void validate_solution(LaplacianSystem *sys, short flag); static void delete_void_pointer(void * data) { @@ -103,7 +103,7 @@ static void delete_void_pointer(void * data) } } -static void delete_laplacian_system(LaplacianSystem * sys) +static void delete_laplacian_system(LaplacianSystem *sys) { delete_void_pointer(sys->eweights); delete_void_pointer(sys->fweights); @@ -117,26 +117,26 @@ static void delete_laplacian_system(LaplacianSystem * sys) nlDeleteContext(sys->context); } sys->vertexCos = NULL; - sys->mfaces = NULL; + sys->mfaces = NULL; sys->medges = NULL; MEM_freeN(sys); } static void memset_laplacian_system(LaplacianSystem *sys, int val) { - memset(sys->eweights , val, sizeof(float) * sys->numEdges); - memset(sys->fweights , val, sizeof(float) * sys->numFaces * 3); - memset(sys->numNeEd , val, sizeof(short) * sys->numVerts); - memset(sys->numNeFa , val, sizeof(short) * sys->numVerts); - memset(sys->ring_areas , val, sizeof(float) * sys->numVerts); - memset(sys->vlengths , val, sizeof(float) * sys->numVerts); - memset(sys->vweights , val, sizeof(float) * sys->numVerts); - memset(sys->zerola , val, sizeof(short) * sys->numVerts); + memset(sys->eweights, val, sizeof(float) * sys->numEdges); + memset(sys->fweights, val, sizeof(float) * sys->numFaces * 3); + memset(sys->numNeEd, val, sizeof(short) * sys->numVerts); + memset(sys->numNeFa, val, sizeof(short) * sys->numVerts); + memset(sys->ring_areas, val, sizeof(float) * sys->numVerts); + memset(sys->vlengths, val, sizeof(float) * sys->numVerts); + memset(sys->vweights, val, sizeof(float) * sys->numVerts); + memset(sys->zerola, val, sizeof(short) * sys->numVerts); } static LaplacianSystem * init_laplacian_system( int a_numEdges, int a_numFaces, int a_numVerts) { - LaplacianSystem * sys; + LaplacianSystem *sys; sys = MEM_callocN(sizeof(LaplacianSystem), "ModLaplSmoothSystem"); sys->numEdges = a_numEdges; sys->numFaces = a_numFaces; @@ -300,20 +300,20 @@ static void volume_preservation(LaplacianSystem *sys, float vini, float vend, sh beta = pow (vini / vend, 1.0f / 3.0f); for (i = 0; i < sys->numVerts; i++) { if (flag & MOD_LAPLACIANSMOOTH_X) { - sys->vertexCos[i][0] = (sys->vertexCos[i][0] - sys->vert_centroid[0])* beta + sys->vert_centroid[0]; + sys->vertexCos[i][0] = (sys->vertexCos[i][0] - sys->vert_centroid[0]) * beta + sys->vert_centroid[0]; } if (flag & MOD_LAPLACIANSMOOTH_Y) { - sys->vertexCos[i][1] = (sys->vertexCos[i][1] - sys->vert_centroid[1])* beta + sys->vert_centroid[1]; + sys->vertexCos[i][1] = (sys->vertexCos[i][1] - sys->vert_centroid[1]) * beta + sys->vert_centroid[1]; } if (flag & MOD_LAPLACIANSMOOTH_Z) { - sys->vertexCos[i][2] = (sys->vertexCos[i][2] - sys->vert_centroid[2])* beta + sys->vert_centroid[2]; + sys->vertexCos[i][2] = (sys->vertexCos[i][2] - sys->vert_centroid[2]) * beta + sys->vert_centroid[2]; } } } } -static void init_laplacian_matrix(LaplacianSystem * sys) +static void init_laplacian_matrix(LaplacianSystem *sys) { float *v1, *v2, *v3, *v4; float w1, w2, w3, w4; @@ -334,7 +334,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys) if (w1 < sys->min_area) { sys->zerola[idv1] = 1; sys->zerola[idv2] = 1; - } else { + } + else { w1 = 1.0f / w1; } @@ -360,7 +361,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys) if (has_4_vert) { areaf = area_quad_v3(v1, v2, v3, sys->vertexCos[sys->mfaces[i].v4]); - } else { + } + else { areaf = area_tri_v3(v1, v2, v3); } if (fabs(areaf) < sys->min_area) { @@ -399,7 +401,8 @@ static void init_laplacian_matrix(LaplacianSystem * sys) sys->vweights[idv1] += (w2 + w3 + w4) / 4.0f; } - } else { + } + else { w1 = cotan_weight(v1, v2, v3); w2 = cotan_weight(v2, v3, v1); w3 = cotan_weight(v3, v1, v2); @@ -425,7 +428,7 @@ static void init_laplacian_matrix(LaplacianSystem * sys) } -static void fill_laplacian_matrix(LaplacianSystem * sys) +static void fill_laplacian_matrix(LaplacianSystem *sys) { float *v1, *v2, *v3, *v4; float w2, w3, w4; @@ -469,7 +472,8 @@ static void fill_laplacian_matrix(LaplacianSystem * sys) nlMatrixAdd(idv1, idv4, w4 * sys->vweights[idv1]); } } - } else { + } + else { /* Is ring if number of faces == number of edges around vertice*/ if (sys->numNeEd[idv1] == sys->numNeFa[idv1] && sys->zerola[idv1] == 0) { nlMatrixAdd(idv1, idv2, sys->fweights[i][2] * sys->vweights[idv1]); @@ -501,7 +505,7 @@ static void fill_laplacian_matrix(LaplacianSystem * sys) } } -static void validate_solution(LaplacianSystem * sys, short flag, float lambda, float lambda_border) +static void validate_solution(LaplacianSystem *sys, short flag) { int i, idv1, idv2; float leni, lene; @@ -561,7 +565,9 @@ static void laplaciansmoothModifier_do( DM_ensure_tessface(dm); sys = init_laplacian_system(dm->getNumEdges(dm), dm->getNumTessFaces(dm), numVerts); - if(!sys) return; + if (!sys) { + return; + } sys->mfaces = dm->getTessFaceArray(dm); sys->medges = dm->getEdgeArray(dm); @@ -589,15 +595,11 @@ static void laplaciansmoothModifier_do( nlSetVariable(1, i, vertexCos[i][1]); nlSetVariable(2, i, vertexCos[i][2]); if (iter == 0) { - sys->vert_centroid[0] += vertexCos[i][0]; - sys->vert_centroid[1] += vertexCos[i][1]; - sys->vert_centroid[2] += vertexCos[i][2]; + add_v3_v3(sys->vert_centroid, vertexCos[i]); } } - if (iter == 0 && numVerts >0) { - sys->vert_centroid[0] = sys->vert_centroid[0] / numVerts; - sys->vert_centroid[1] = sys->vert_centroid[1] / numVerts; - sys->vert_centroid[2] = sys->vert_centroid[2] / numVerts; + if (iter == 0 && numVerts > 0) { + mul_v3_fl(sys->vert_centroid, 1.0f / (float)numVerts); } nlBegin(NL_MATRIX); @@ -609,21 +611,25 @@ static void laplaciansmoothModifier_do( if (dv) { wpaint = defvert_find_weight(dv, defgrp_index); dv++; - } else { + } + else { wpaint = 1.0f; } + if (sys->zerola[i] == 0) { w = sys->vweights[i] * sys->ring_areas[i]; - sys->vweights[i] = (w == 0.0f) ? 0.0f : - smd->lambda * wpaint / (4.0f * w); + sys->vweights[i] = (w == 0.0f) ? 0.0f : -smd->lambda * wpaint / (4.0f * w); w = sys->vlengths[i]; - sys->vlengths[i] = (w == 0.0f) ? 0.0f : - smd->lambda_border * wpaint * 2.0f / w; + sys->vlengths[i] = (w == 0.0f) ? 0.0f : -smd->lambda_border * wpaint * 2.0f / w; if (sys->numNeEd[i] == sys->numNeFa[i]) { nlMatrixAdd(i, i, 1.0f + smd->lambda * wpaint / (4.0f * sys->ring_areas[i])); - } else { + } + else { nlMatrixAdd(i, i, 1.0f + smd->lambda_border * wpaint * 2.0f); } - } else { + } + else { nlMatrixAdd(i, i, 1.0f); } } @@ -634,7 +640,7 @@ static void laplaciansmoothModifier_do( nlEnd(NL_SYSTEM); if (nlSolveAdvanced(NULL, NL_TRUE)) { - validate_solution(sys, smd->flag, smd->lambda, smd->lambda_border); + validate_solution(sys, smd->flag); } nlDeleteContext(sys->context); sys->context = NULL; @@ -684,10 +690,10 @@ ModifierTypeInfo modifierType_LaplacianSmooth = { /* deformMatricesEM */ NULL, /* applyModifier */ NULL, /* applyModifierEM */ NULL, - /* init_data */ init_data, - /* required_data_mask */ required_data_mask, + /* initData */ init_data, + /* requiredDataMask */ required_data_mask, /* freeData */ NULL, - /* is_disabled */ is_disabled, + /* isDisabled */ is_disabled, /* updateDepgraph */ NULL, /* dependsOnTime */ NULL, /* dependsOnNormals */ NULL, diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index f2682982f19..bcd5b27aa6f 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -557,8 +557,8 @@ static void GetNormal(const SMikkTSpaceContext * pContext, float fNorm[], const SRenderMeshToTangent * pMesh = (SRenderMeshToTangent *) pContext->m_pUserData; VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num); - if(vlr->flag & ME_SMOOTH) { - const float *n= (&vlr->v1)[vert_index]->n; + if (vlr->flag & ME_SMOOTH) { + const float *n = (&vlr->v1)[vert_index]->n; copy_v3_v3(fNorm, n); } else { -- cgit v1.2.3