diff options
author | Alexander Pinzon <apinzonf@gmail.com> | 2013-01-21 23:33:58 +0400 |
---|---|---|
committer | Alexander Pinzon <apinzonf@gmail.com> | 2013-01-21 23:33:58 +0400 |
commit | 044e3398b959ae80096bf4f436fd5cca9e3a6203 (patch) | |
tree | 3985109c3e401640a35a5da6795d5f108b8d1c01 | |
parent | d760a86927a45d31244603e7642ca87a5e23991f (diff) |
Improved performance for multiple iterations, keeping the same laplacian matrix.
-rw-r--r-- | source/blender/modifiers/intern/MOD_laplaciansmooth.c | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c index 7084fb498f0..a18d0e22c5c 100644 --- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c +++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c @@ -576,17 +576,17 @@ static void laplaciansmoothModifier_do( sys->vert_centroid[0] = 0.0f; sys->vert_centroid[1] = 0.0f; sys->vert_centroid[2] = 0.0f; - for (iter = 0; iter < smd->repeat; iter++) { - memset_laplacian_system(sys, 0); - nlNewContext(); - sys->context = nlGetCurrent(); - nlSolverParameteri(NL_NB_VARIABLES, numVerts); - nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE); - nlSolverParameteri(NL_NB_ROWS, numVerts); - nlSolverParameteri(NL_NB_RIGHT_HAND_SIDES, 3); + memset_laplacian_system(sys, 0); + nlNewContext(); + sys->context = nlGetCurrent(); + nlSolverParameteri(NL_NB_VARIABLES, numVerts); + nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE); + nlSolverParameteri(NL_NB_ROWS, numVerts); + nlSolverParameteri(NL_NB_RIGHT_HAND_SIDES, 3); - init_laplacian_matrix(sys); + init_laplacian_matrix(sys); + for (iter = 0; iter < smd->repeat; iter++) { nlBegin(NL_SYSTEM); for (i = 0; i < numVerts; i++) { nlSetVariable(0, i, vertexCos[i][0]); @@ -603,50 +603,54 @@ static void laplaciansmoothModifier_do( nlBegin(NL_MATRIX); dv = dvert; for (i = 0; i < numVerts; i++) { - nlRightHandSideAdd(0, i, vertexCos[i][0]); - nlRightHandSideAdd(1, i, vertexCos[i][1]); - nlRightHandSideAdd(2, i, vertexCos[i][2]); - if (dv) { - wpaint = defvert_find_weight(dv, defgrp_index); - dv++; - } - else { - wpaint = 1.0f; - } - - if (sys->zerola[i] == 0) { - if (smd->flag & MOD_LAPLACIANSMOOTH_NORMALIZED) { - w = sys->vweights[i]; - sys->vweights[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda) * wpaint / w; - w = sys->vlengths[i]; - sys->vlengths[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda_border) * wpaint * 2.0f / w; - if (sys->numNeEd[i] == sys->numNeFa[i]) { - nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda) * wpaint); - } - else { - nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda_border) * wpaint * 2.0f); - } + nlRightHandSideSet(0, i, vertexCos[i][0]); + nlRightHandSideSet(1, i, vertexCos[i][1]); + nlRightHandSideSet(2, i, vertexCos[i][2]); + if (iter == 0) { + if (dv) { + wpaint = defvert_find_weight(dv, defgrp_index); + dv++; } else { - w = sys->vweights[i] * sys->ring_areas[i]; - sys->vweights[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda) * wpaint / (4.0f * w); - w = sys->vlengths[i]; - sys->vlengths[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda_border) * wpaint * 2.0f / w; + wpaint = 1.0f; + } - if (sys->numNeEd[i] == sys->numNeFa[i]) { - nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda) * wpaint / (4.0f * sys->ring_areas[i])); + if (sys->zerola[i] == 0) { + if (smd->flag & MOD_LAPLACIANSMOOTH_NORMALIZED) { + w = sys->vweights[i]; + sys->vweights[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda) * wpaint / w; + w = sys->vlengths[i]; + sys->vlengths[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda_border) * wpaint * 2.0f / w; + if (sys->numNeEd[i] == sys->numNeFa[i]) { + nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda) * wpaint); + } + else { + nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda_border) * wpaint * 2.0f); + } } else { - nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda_border) * wpaint * 2.0f); + w = sys->vweights[i] * sys->ring_areas[i]; + sys->vweights[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda) * wpaint / (4.0f * w); + w = sys->vlengths[i]; + sys->vlengths[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda_border) * wpaint * 2.0f / w; + + if (sys->numNeEd[i] == sys->numNeFa[i]) { + nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda) * wpaint / (4.0f * sys->ring_areas[i])); + } + else { + nlMatrixAdd(i, i, 1.0f + fabsf(smd->lambda_border) * wpaint * 2.0f); + } } } - } - else { - nlMatrixAdd(i, i, 1.0f); + else { + nlMatrixAdd(i, i, 1.0f); + } } } - fill_laplacian_matrix(sys); + if (iter == 0){ + fill_laplacian_matrix(sys); + } nlEnd(NL_MATRIX); nlEnd(NL_SYSTEM); @@ -654,9 +658,9 @@ static void laplaciansmoothModifier_do( if (nlSolveAdvanced(NULL, NL_TRUE)) { validate_solution(sys, smd->flag, smd->lambda, smd->lambda_border); } - nlDeleteContext(sys->context); - sys->context = NULL; } + nlDeleteContext(sys->context); + sys->context = NULL; delete_laplacian_system(sys); } |