OpenNL: significantly simplify code using Eigen / STL.

This commit is contained in:
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. * the Software into proprietary programs.
*/ */
/*
#define NL_DEBUG
#define NL_PARANOID
*/
#ifndef nlOPENNL_H #ifndef nlOPENNL_H
#define nlOPENNL_H #define nlOPENNL_H
@@ -49,8 +44,6 @@
extern "C" { extern "C" {
#endif #endif
#define NL_VERSION_0_0 1
/* Datatypes */ /* Datatypes */
typedef unsigned int NLenum; typedef unsigned int NLenum;
@@ -59,7 +52,7 @@ typedef int NLint; /* 4-byte signed */
typedef unsigned int NLuint; /* 4-byte unsigned */ typedef unsigned int NLuint; /* 4-byte unsigned */
typedef double NLdouble; /* double precision float */ typedef double NLdouble; /* double precision float */
typedef void* NLContext; typedef struct NLContext NLContext;
/* Constants */ /* Constants */
@@ -76,17 +69,16 @@ typedef void* NLContext;
#define NL_SOLVER 0x100 #define NL_SOLVER 0x100
#define NL_NB_VARIABLES 0x101 #define NL_NB_VARIABLES 0x101
#define NL_LEAST_SQUARES 0x102 #define NL_LEAST_SQUARES 0x102
#define NL_SYMMETRIC 0x106
#define NL_ERROR 0x108 #define NL_ERROR 0x108
#define NL_NB_ROWS 0x110 #define NL_NB_ROWS 0x110
#define NL_NB_RIGHT_HAND_SIDES 0x112 /* 4 max */ #define NL_NB_RIGHT_HAND_SIDES 0x112 /* 4 max */
/* Contexts */ /* Contexts */
NLContext nlNewContext(void); NLContext *nlNewContext(void);
void nlDeleteContext(NLContext context); void nlDeleteContext(NLContext *context);
void nlMakeCurrent(NLContext context); void nlMakeCurrent(NLContext *context);
NLContext nlGetCurrent(void); NLContext *nlGetCurrent(void);
/* State get/set */ /* State get/set */
@@ -113,8 +105,7 @@ void nlRightHandSideSet(NLuint rhsindex, NLuint index, NLdouble value);
/* Solve */ /* Solve */
void nlPrintMatrix(void); void nlPrintMatrix(void);
NLboolean nlSolve(void); NLboolean nlSolve(NLboolean solveAgain);
NLboolean nlSolveAdvanced(NLint *permutation, NLboolean solveAgain);
#ifdef __cplusplus #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_MATRIX);
nlEnd(NL_SYSTEM); nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_TRUE) ) { if (nlSolve(NL_TRUE) ) {
validate_solution(sys, usex, usey, usez, preserve_volume); 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 *****************************/ /************************** Laplacian System *****************************/
struct LaplacianSystem { struct LaplacianSystem {
NLContext context; /* opennl context */ NLContext *context; /* opennl context */
int totvert, totface; int totvert, totface;
@@ -341,7 +341,7 @@ int laplacian_system_solve(LaplacianSystem *sys)
//nlPrintMatrix(); //nlPrintMatrix();
return nlSolveAdvanced(NULL, NL_TRUE); return nlSolve(NL_TRUE);
} }
float laplacian_system_get_solution(int v) float laplacian_system_get_solution(int v)
@@ -1438,7 +1438,7 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind
nlEnd(NL_MATRIX); nlEnd(NL_MATRIX);
nlEnd(NL_SYSTEM); nlEnd(NL_SYSTEM);
if (nlSolveAdvanced(NULL, NL_TRUE)) { if (nlSolve(NL_TRUE)) {
for (z = 0; z < mdb->size; z++) for (z = 0; z < mdb->size; z++)
for (y = 0; y < mdb->size; y++) for (y = 0; y < mdb->size; y++)
for (x = 0; x < mdb->size; x++) for (x = 0; x < mdb->size; x++)

View File

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

View File

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

View File

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

View File

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