OpenNL: significantly simplify code using Eigen / STL.

This commit is contained in:
Brecht Van Lommel 2015-11-22 05:25:32 +01:00
parent e6c58df74e
commit 47ce2d7bef
8 changed files with 231 additions and 795 deletions

View File

@ -37,11 +37,6 @@
* the Software into proprietary programs.
*/
/*
#define NL_DEBUG
#define NL_PARANOID
*/
#ifndef nlOPENNL_H
#define nlOPENNL_H
@ -49,8 +44,6 @@
extern "C" {
#endif
#define NL_VERSION_0_0 1
/* Datatypes */
typedef unsigned int NLenum;
@ -59,7 +52,7 @@ typedef int NLint; /* 4-byte signed */
typedef unsigned int NLuint; /* 4-byte unsigned */
typedef double NLdouble; /* double precision float */
typedef void* NLContext;
typedef struct NLContext NLContext;
/* Constants */
@ -76,17 +69,16 @@ typedef void* NLContext;
#define NL_SOLVER 0x100
#define NL_NB_VARIABLES 0x101
#define NL_LEAST_SQUARES 0x102
#define NL_SYMMETRIC 0x106
#define NL_ERROR 0x108
#define NL_NB_ROWS 0x110
#define NL_NB_RIGHT_HAND_SIDES 0x112 /* 4 max */
/* Contexts */
NLContext nlNewContext(void);
void nlDeleteContext(NLContext context);
void nlMakeCurrent(NLContext context);
NLContext nlGetCurrent(void);
NLContext *nlNewContext(void);
void nlDeleteContext(NLContext *context);
void nlMakeCurrent(NLContext *context);
NLContext *nlGetCurrent(void);
/* State get/set */
@ -113,8 +105,7 @@ void nlRightHandSideSet(NLuint rhsindex, NLuint index, NLdouble value);
/* Solve */
void nlPrintMatrix(void);
NLboolean nlSolve(void);
NLboolean nlSolveAdvanced(NLint *permutation, NLboolean solveAgain);
NLboolean nlSolve(NLboolean solveAgain);
#ifdef __cplusplus
}

File diff suppressed because it is too large Load Diff

View File

@ -551,7 +551,7 @@ void bmo_smooth_laplacian_vert_exec(BMesh *bm, BMOperator *op)
nlEnd(NL_MATRIX);
nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_TRUE) ) {
if (nlSolve(NL_TRUE) ) {
validate_solution(sys, usex, usey, usez, preserve_volume);
}

View File

@ -64,7 +64,7 @@ static void error(const char *str) { printf("error: %s\n", str); }
/************************** Laplacian System *****************************/
struct LaplacianSystem {
NLContext context; /* opennl context */
NLContext *context; /* opennl context */
int totvert, totface;
@ -341,7 +341,7 @@ int laplacian_system_solve(LaplacianSystem *sys)
//nlPrintMatrix();
return nlSolveAdvanced(NULL, NL_TRUE);
return nlSolve(NL_TRUE);
}
float laplacian_system_get_solution(int v)
@ -1438,7 +1438,7 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind
nlEnd(NL_MATRIX);
nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_TRUE)) {
if (nlSolve(NL_TRUE)) {
for (z = 0; z < mdb->size; z++)
for (y = 0; y < mdb->size; y++)
for (x = 0; x < mdb->size; x++)

View File

@ -2628,7 +2628,7 @@ int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges)
nlEnd(NL_SYSTEM);
success = nlSolveAdvanced(NULL, NL_TRUE);
success = nlSolve(NL_TRUE);
if (success) {
rval = 1;

View File

@ -193,7 +193,7 @@ typedef struct PChart {
union PChartUnion {
struct PChartLscm {
NLContext context;
NLContext *context;
float *abf_alpha;
PVert *pin1, *pin2;
} lscm;
@ -2613,7 +2613,7 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart)
nlEnd(NL_SYSTEM);
success = nlSolve();
success = nlSolve(NL_FALSE);
if (success) {
for (f = chart->faces; f; f = f->nextlink) {
@ -3223,7 +3223,7 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart)
nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_TRUE)) {
if (nlSolve(NL_TRUE)) {
p_chart_lscm_load_solution(chart);
return P_TRUE;
}

View File

@ -399,7 +399,6 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
sys->context = nlGetCurrent();
nlSolverParameteri(NL_NB_VARIABLES, n);
nlSolverParameteri(NL_SYMMETRIC, NL_FALSE);
nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE);
nlSolverParameteri(NL_NB_ROWS, n + na);
nlSolverParameteri(NL_NB_RIGHT_HAND_SIDES, 3);
@ -434,7 +433,7 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
}
nlEnd(NL_MATRIX);
nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_TRUE)) {
if (nlSolve(NL_TRUE)) {
sys->has_solution = true;
for (j = 1; j <= sys->repeat; j++) {
@ -451,7 +450,7 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
nlEnd(NL_MATRIX);
nlEnd(NL_SYSTEM);
if (!nlSolveAdvanced(NULL, NL_FALSE)) {
if (!nlSolve(NL_FALSE)) {
sys->has_solution = false;
break;
}
@ -495,7 +494,7 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
nlEnd(NL_MATRIX);
nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_FALSE)) {
if (nlSolve(NL_FALSE)) {
sys->has_solution = true;
for (j = 1; j <= sys->repeat; j++) {
nlBegin(NL_SYSTEM);
@ -510,7 +509,7 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
}
nlEnd(NL_MATRIX);
nlEnd(NL_SYSTEM);
if (!nlSolveAdvanced(NULL, NL_FALSE)) {
if (!nlSolve(NL_FALSE)) {
sys->has_solution = false;
break;
}

View File

@ -468,7 +468,7 @@ static void laplaciansmoothModifier_do(
nlEnd(NL_MATRIX);
nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_TRUE)) {
if (nlSolve(NL_TRUE)) {
validate_solution(sys, smd->flag, smd->lambda, smd->lambda_border);
}
}