diff options
Diffstat (limited to 'source/blender/editors/armature')
-rw-r--r-- | source/blender/editors/armature/meshlaplacian.c | 93 | ||||
-rw-r--r-- | source/blender/editors/armature/meshlaplacian.h | 2 | ||||
-rw-r--r-- | source/blender/editors/armature/reeb.c | 49 |
3 files changed, 71 insertions, 73 deletions
diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 956cbe25c3b..3f27a58930d 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -182,18 +182,18 @@ static void laplacian_triangle_weights(LaplacianSystem *sys, int f, int i1, int t2 = cotangent_tri_weight_v3(v2, v3, v1) / laplacian_edge_count(sys->edgehash, i3, i1); t3 = cotangent_tri_weight_v3(v3, v1, v2) / laplacian_edge_count(sys->edgehash, i1, i2); - nlMatrixAdd(i1, i1, (t2 + t3) * varea[i1]); - nlMatrixAdd(i2, i2, (t1 + t3) * varea[i2]); - nlMatrixAdd(i3, i3, (t1 + t2) * varea[i3]); + nlMatrixAdd(sys->context, i1, i1, (t2 + t3) * varea[i1]); + nlMatrixAdd(sys->context, i2, i2, (t1 + t3) * varea[i2]); + nlMatrixAdd(sys->context, i3, i3, (t1 + t2) * varea[i3]); - nlMatrixAdd(i1, i2, -t3 * varea[i1]); - nlMatrixAdd(i2, i1, -t3 * varea[i2]); + nlMatrixAdd(sys->context, i1, i2, -t3 * varea[i1]); + nlMatrixAdd(sys->context, i2, i1, -t3 * varea[i2]); - nlMatrixAdd(i2, i3, -t1 * varea[i2]); - nlMatrixAdd(i3, i2, -t1 * varea[i3]); + nlMatrixAdd(sys->context, i2, i3, -t1 * varea[i2]); + nlMatrixAdd(sys->context, i3, i2, -t1 * varea[i3]); - nlMatrixAdd(i3, i1, -t2 * varea[i3]); - nlMatrixAdd(i1, i3, -t2 * varea[i1]); + nlMatrixAdd(sys->context, i3, i1, -t2 * varea[i3]); + nlMatrixAdd(sys->context, i1, i3, -t2 * varea[i1]); if (sys->storeweights) { sys->fweights[f][0] = t1 * varea[i1]; @@ -219,12 +219,10 @@ static LaplacianSystem *laplacian_system_construct_begin(int totvert, int totfac sys->storeweights = 0; /* create opennl context */ - nlNewContext(); - nlSolverParameteri(NL_NB_VARIABLES, totvert); + sys->context = nlNewContext(); + nlSolverParameteri(sys->context, NL_NB_VARIABLES, totvert); if (lsq) - nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE); - - sys->context = nlGetCurrent(); + nlSolverParameteri(sys->context, NL_LEAST_SQUARES, NL_TRUE); return sys; } @@ -274,7 +272,7 @@ static void laplacian_system_construct_end(LaplacianSystem *sys) /* for heat weighting */ if (sys->heat.H) - nlMatrixAdd(a, a, sys->heat.H[a]); + nlMatrixAdd(sys->context, a, a, sys->heat.H[a]); } if (sys->storeweights) @@ -312,41 +310,41 @@ void laplacian_begin_solve(LaplacianSystem *sys, int index) int a; if (!sys->nlbegun) { - nlBegin(NL_SYSTEM); + nlBegin(sys->context, NL_SYSTEM); if (index >= 0) { for (a = 0; a < sys->totvert; a++) { if (sys->vpinned[a]) { - nlSetVariable(0, a, sys->verts[a][index]); - nlLockVariable(a); + nlSetVariable(sys->context, 0, a, sys->verts[a][index]); + nlLockVariable(sys->context, a); } } } - nlBegin(NL_MATRIX); + nlBegin(sys->context, NL_MATRIX); sys->nlbegun = 1; } } -void laplacian_add_right_hand_side(LaplacianSystem *UNUSED(sys), int v, float value) +void laplacian_add_right_hand_side(LaplacianSystem *sys, int v, float value) { - nlRightHandSideAdd(0, v, value); + nlRightHandSideAdd(sys->context, 0, v, value); } int laplacian_system_solve(LaplacianSystem *sys) { - nlEnd(NL_MATRIX); - nlEnd(NL_SYSTEM); + nlEnd(sys->context, NL_MATRIX); + nlEnd(sys->context, NL_SYSTEM); sys->nlbegun = 0; - //nlPrintMatrix(); + //nlPrintMatrix(sys->context, ); - return nlSolve(NL_TRUE); + return nlSolve(sys->context, NL_TRUE); } -float laplacian_system_get_solution(int v) +float laplacian_system_get_solution(LaplacianSystem *sys, int v) { - return nlGetVariable(0, v); + return nlGetVariable(sys->context, 0, v); } /************************* Heat Bone Weighting ******************************/ @@ -723,7 +721,7 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, if (mask && !mask[a]) continue; - solution = laplacian_system_get_solution(a); + solution = laplacian_system_get_solution(sys, a); if (bbone) { if (solution > 0.0f) @@ -1286,7 +1284,7 @@ static float meshdeform_boundary_total_weight(MeshDeformBind *mdb, int x, int y, return totweight; } -static void meshdeform_matrix_add_cell(MeshDeformBind *mdb, int x, int y, int z) +static void meshdeform_matrix_add_cell(MeshDeformBind *mdb, NLContext *context, int x, int y, int z) { MDefBoundIsect *isect; float weight, totweight; @@ -1296,7 +1294,7 @@ static void meshdeform_matrix_add_cell(MeshDeformBind *mdb, int x, int y, int z) if (mdb->tag[acenter] == MESHDEFORM_TAG_EXTERIOR) return; - nlMatrixAdd(mdb->varidx[acenter], mdb->varidx[acenter], 1.0f); + nlMatrixAdd(context, mdb->varidx[acenter], mdb->varidx[acenter], 1.0f); totweight = meshdeform_boundary_total_weight(mdb, x, y, z); for (i = 1; i <= 6; i++) { @@ -1307,12 +1305,12 @@ static void meshdeform_matrix_add_cell(MeshDeformBind *mdb, int x, int y, int z) isect = mdb->boundisect[acenter][i - 1]; if (!isect) { weight = (1.0f / mdb->width[0]) / totweight; - nlMatrixAdd(mdb->varidx[acenter], mdb->varidx[a], -weight); + nlMatrixAdd(context, mdb->varidx[acenter], mdb->varidx[a], -weight); } } } -static void meshdeform_matrix_add_rhs(MeshDeformBind *mdb, int x, int y, int z, int cagevert) +static void meshdeform_matrix_add_rhs(MeshDeformBind *mdb, NLContext *context, int x, int y, int z, int cagevert) { MDefBoundIsect *isect; float rhs, weight, totweight; @@ -1333,7 +1331,7 @@ static void meshdeform_matrix_add_rhs(MeshDeformBind *mdb, int x, int y, int z, if (isect) { weight = (1.0f / isect->len) / totweight; rhs = weight * meshdeform_boundary_phi(mdb, isect, cagevert); - nlRightHandSideAdd(0, mdb->varidx[acenter], rhs); + nlRightHandSideAdd(context, 0, mdb->varidx[acenter], rhs); } } } @@ -1406,39 +1404,38 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind progress_bar(0, "Starting mesh deform solve"); /* setup opennl solver */ - nlNewContext(); - context = nlGetCurrent(); + context = nlNewContext(); - nlSolverParameteri(NL_NB_VARIABLES, totvar); - nlSolverParameteri(NL_NB_ROWS, totvar); - nlSolverParameteri(NL_NB_RIGHT_HAND_SIDES, 1); + nlSolverParameteri(context, NL_NB_VARIABLES, totvar); + nlSolverParameteri(context, NL_NB_ROWS, totvar); + nlSolverParameteri(context, NL_NB_RIGHT_HAND_SIDES, 1); - nlBegin(NL_SYSTEM); - nlBegin(NL_MATRIX); + nlBegin(context, NL_SYSTEM); + nlBegin(context, NL_MATRIX); /* build matrix */ for (z = 0; z < mdb->size; z++) for (y = 0; y < mdb->size; y++) for (x = 0; x < mdb->size; x++) - meshdeform_matrix_add_cell(mdb, x, y, z); + meshdeform_matrix_add_cell(mdb, context, x, y, z); /* solve for each cage vert */ for (a = 0; a < mdb->totcagevert; a++) { if (a != 0) { - nlBegin(NL_SYSTEM); - nlBegin(NL_MATRIX); + nlBegin(context, NL_SYSTEM); + nlBegin(context, NL_MATRIX); } /* fill in right hand side and solve */ for (z = 0; z < mdb->size; z++) for (y = 0; y < mdb->size; y++) for (x = 0; x < mdb->size; x++) - meshdeform_matrix_add_rhs(mdb, x, y, z, a); + meshdeform_matrix_add_rhs(mdb, context, x, y, z, a); - nlEnd(NL_MATRIX); - nlEnd(NL_SYSTEM); + nlEnd(context, NL_MATRIX); + nlEnd(context, NL_SYSTEM); - if (nlSolve(NL_TRUE)) { + if (nlSolve(context, NL_TRUE)) { for (z = 0; z < mdb->size; z++) for (y = 0; y < mdb->size; y++) for (x = 0; x < mdb->size; x++) @@ -1451,7 +1448,7 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind for (b = 0; b < mdb->size3; b++) { if (mdb->tag[b] != MESHDEFORM_TAG_EXTERIOR) - mdb->phi[b] = nlGetVariable(0, mdb->varidx[b]); + mdb->phi[b] = nlGetVariable(context, 0, mdb->varidx[b]); mdb->totalphi[b] += mdb->phi[b]; } diff --git a/source/blender/editors/armature/meshlaplacian.h b/source/blender/editors/armature/meshlaplacian.h index 1412136c1a8..bba8c739abf 100644 --- a/source/blender/editors/armature/meshlaplacian.h +++ b/source/blender/editors/armature/meshlaplacian.h @@ -48,7 +48,7 @@ void laplacian_add_triangle(LaplacianSystem *sys, int v1, int v2, int v3); void laplacian_begin_solve(LaplacianSystem *sys, int index); void laplacian_add_right_hand_side(LaplacianSystem *sys, int v, float value); int laplacian_system_solve(LaplacianSystem *sys); -float laplacian_system_get_solution(int v); +float laplacian_system_get_solution(LaplacianSystem *sys, int v); /* Heat Weighting */ diff --git a/source/blender/editors/armature/reeb.c b/source/blender/editors/armature/reeb.c index e10ae4bcf3f..d53e5b857a0 100644 --- a/source/blender/editors/armature/reeb.c +++ b/source/blender/editors/armature/reeb.c @@ -2497,7 +2497,7 @@ int weightFromLoc(EditMesh *em, int axis) return 1; } -static void addTriangle(EditVert *v1, EditVert *v2, EditVert *v3, int e1, int e2, int e3) +static void addTriangle(NLContext *context, EditVert *v1, EditVert *v2, EditVert *v3, int e1, int e2, int e3) { /* Angle opposite e1 */ float t1 = cotangent_tri_weight_v3(v1->co, v2->co, v3->co) / e2; @@ -2512,22 +2512,23 @@ static void addTriangle(EditVert *v1, EditVert *v2, EditVert *v3, int e1, int e2 int i2 = indexData(v2); int i3 = indexData(v3); - nlMatrixAdd(i1, i1, t2 + t3); - nlMatrixAdd(i2, i2, t1 + t3); - nlMatrixAdd(i3, i3, t1 + t2); + nlMatrixAdd(context, i1, i1, t2 + t3); + nlMatrixAdd(context, i2, i2, t1 + t3); + nlMatrixAdd(context, i3, i3, t1 + t2); - nlMatrixAdd(i1, i2, -t3); - nlMatrixAdd(i2, i1, -t3); + nlMatrixAdd(context, i1, i2, -t3); + nlMatrixAdd(context, i2, i1, -t3); - nlMatrixAdd(i2, i3, -t1); - nlMatrixAdd(i3, i2, -t1); + nlMatrixAdd(context, i2, i3, -t1); + nlMatrixAdd(context, i3, i2, -t1); - nlMatrixAdd(i3, i1, -t2); - nlMatrixAdd(i1, i3, -t2); + nlMatrixAdd(context, i3, i1, -t2); + nlMatrixAdd(context, i1, i3, -t2); } int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) { + NLContext *context; NLboolean success; EditVert *eve; EditEdge *eed; @@ -2543,11 +2544,11 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) /* Solve with openNL */ - nlNewContext(); + context = nlNewContext(); - nlSolverParameteri(NL_NB_VARIABLES, totvert); + nlSolverParameteri(context, NL_NB_VARIABLES, totvert); - nlBegin(NL_SYSTEM); + nlBegin(context, NL_SYSTEM); /* Find local extrema */ for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) { @@ -2582,8 +2583,8 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) if (maximum || minimum) { float w = weightData(eve); eve->f1 = 0; - nlSetVariable(0, index, w); - nlLockVariable(index); + nlSetVariable(context, 0, index, w); + nlLockVariable(context, index); } else { eve->f1 = 1; @@ -2591,7 +2592,7 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) } } - nlBegin(NL_MATRIX); + nlBegin(context, NL_MATRIX); /* Zero edge weight */ for (eed = em->edges.first; eed; eed = eed->next) { @@ -2615,32 +2616,32 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges) 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); + addTriangle(context, efa->v1, efa->v2, efa->v3, efa->e1->tmp.l, efa->e2->tmp.l, efa->e3->tmp.l); } 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); + addTriangle(context, efa->v1, efa->v2, efa->v3, efa->e1->tmp.l, efa->e2->tmp.l, 2); + addTriangle(context, efa->v3, efa->v4, efa->v1, efa->e3->tmp.l, efa->e4->tmp.l, 2); } } } - nlEnd(NL_MATRIX); + nlEnd(context, NL_MATRIX); - nlEnd(NL_SYSTEM); + nlEnd(context, NL_SYSTEM); - success = nlSolve(NL_TRUE); + success = nlSolve(context, NL_TRUE); if (success) { rval = 1; for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) { - weightSetData(eve, nlGetVariable(0, index)); + weightSetData(eve, nlGetVariable(context, 0, index)); } } else { rval = 0; } - nlDeleteContext(nlGetCurrent()); + nlDeleteContext(context); return rval; } |