[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12477] trunk/blender:
Brecht Van Lommel
brechtvanlommel at pandora.be
Sun Nov 4 23:00:25 CET 2007
Revision: 12477
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12477
Author: blendix
Date: 2007-11-04 23:00:24 +0100 (Sun, 04 Nov 2007)
Log Message:
-----------
Mesh Deform Modifier
====================
The MeshDeform modifier can deform a mesh with another 'cage' mesh.
It is similar to a lattice modifier, but instead of being restricted
to the regular grid layout of a lattice, the cage mesh can be modeled
to fit the mesh better.
http://www.blender.org/development/current-projects/changes-since-244/modifiers/
Implementation Notes:
- OpenNL has been refactored a bit to allow least squares matrices to
be built without passing the matrix row by row, but instead with
random access. MDef doesn't need this actually, but it's using this
version of OpenNL so I'm just committing it now.
- Mean value weights for polygons have been added to arithb.c, a type
of barycentric coordinates for polygons with >= 3 vertices. This
might be useful for other parts of blender too.
Modified Paths:
--------------
trunk/blender/intern/opennl/extern/ONL_opennl.h
trunk/blender/intern/opennl/intern/opennl.c
trunk/blender/source/blender/blenkernel/BKE_bad_level_calls.h
trunk/blender/source/blender/blenkernel/BKE_mesh.h
trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c
trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
trunk/blender/source/blender/blenkernel/intern/mesh.c
trunk/blender/source/blender/blenkernel/intern/modifier.c
trunk/blender/source/blender/blenlib/BLI_arithb.h
trunk/blender/source/blender/blenlib/intern/arithb.c
trunk/blender/source/blender/blenloader/intern/readfile.c
trunk/blender/source/blender/blenloader/intern/writefile.c
trunk/blender/source/blender/include/BIF_meshlaplacian.h
trunk/blender/source/blender/makesdna/DNA_modifier_types.h
trunk/blender/source/blender/src/buttons_editing.c
trunk/blender/source/blender/src/meshlaplacian.c
trunk/blender/source/blender/src/parametrizer.c
Modified: trunk/blender/intern/opennl/extern/ONL_opennl.h
===================================================================
--- trunk/blender/intern/opennl/extern/ONL_opennl.h 2007-11-04 21:02:37 UTC (rev 12476)
+++ trunk/blender/intern/opennl/extern/ONL_opennl.h 2007-11-04 22:00:24 UTC (rev 12477)
@@ -79,21 +79,17 @@
#define NL_SYSTEM 0x0
#define NL_MATRIX 0x1
-#define NL_ROW 0x2
/* Solver Parameters */
-#define NL_SOLVER 0x100
-#define NL_NB_VARIABLES 0x101
-#define NL_LEAST_SQUARES 0x102
-#define NL_SYMMETRIC 0x106
-#define NL_ERROR 0x108
+#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 */
-/* Row parameters */
-
-#define NL_RIGHT_HAND_SIDE 0x500
-#define NL_ROW_SCALING 0x501
-
/* Contexts */
NLContext nlNewContext(void);
@@ -106,9 +102,6 @@
void nlSolverParameterf(NLenum pname, NLfloat param);
void nlSolverParameteri(NLenum pname, NLint param);
-void nlRowParameterf(NLenum pname, NLfloat param);
-void nlRowParameteri(NLenum pname, NLint param);
-
void nlGetBooleanv(NLenum pname, NLboolean* params);
void nlGetFloatv(NLenum pname, NLfloat* params);
void nlGetIntergerv(NLenum pname, NLint* params);
@@ -119,8 +112,8 @@
/* Variables */
-void nlSetVariable(NLuint index, NLfloat value);
-NLfloat nlGetVariable(NLuint index);
+void nlSetVariable(NLuint rhsindex, NLuint index, NLfloat value);
+NLfloat nlGetVariable(NLuint rhsindex, NLuint index);
void nlLockVariable(NLuint index);
void nlUnlockVariable(NLuint index);
NLboolean nlVariableIsLocked(NLuint index);
@@ -129,15 +122,17 @@
void nlBegin(NLenum primitive);
void nlEnd(NLenum primitive);
-void nlCoefficient(NLuint index, NLfloat value);
-/* Setting random elements matrix/vector - not supported for
- least squares! */
+/* Setting elements in matrix/vector */
void nlMatrixAdd(NLuint row, NLuint col, NLfloat value);
-void nlRightHandSideAdd(NLuint index, NLfloat value);
-void nlRightHandSideSet(NLuint index, NLfloat value);
+void nlRightHandSideAdd(NLuint rhsindex, NLuint index, NLfloat value);
+void nlRightHandSideSet(NLuint rhsindex, NLuint index, NLfloat value);
+/* Multiply */
+
+void nlMatrixMultiply(NLfloat *x, NLfloat *y);
+
/* Solve */
void nlPrintMatrix(void);
Modified: trunk/blender/intern/opennl/intern/opennl.c
===================================================================
--- trunk/blender/intern/opennl/intern/opennl.c 2007-11-04 21:02:37 UTC (rev 12476)
+++ trunk/blender/intern/opennl/intern/opennl.c 2007-11-04 22:00:24 UTC (rev 12477)
@@ -207,10 +207,6 @@
c->size++;
}
-static void __nlRowColumnZero(__NLRowColumn* c) {
- c->size = 0;
-}
-
static void __nlRowColumnClear(__NLRowColumn* c) {
c->size = 0;
c->capacity = 0;
@@ -432,13 +428,62 @@
}
}
+/* ****************** Routines for least squares ******************* */
+
+static void __nlSparseMatrix_square(
+ __NLSparseMatrix* AtA, __NLSparseMatrix *A
+) {
+ NLuint m = A->m;
+ NLuint n = A->n;
+ NLuint i, j0, j1;
+ __NLRowColumn *Ri = NULL;
+ __NLCoeff *c0 = NULL, *c1 = NULL;
+ float value;
+
+ __nlSparseMatrixConstruct(AtA, n, n, A->storage);
+
+ for(i=0; i<m; i++) {
+ Ri = &(A->row[i]);
+
+ for(j0=0; j0<Ri->size; j0++) {
+ c0 = &(Ri->coeff[j0]);
+ for(j1=0; j1<Ri->size; j1++) {
+ c1 = &(Ri->coeff[j1]);
+
+ value = c0->value*c1->value;
+ __nlSparseMatrixAdd(AtA, c0->index, c1->index, value);
+ }
+ }
+ }
+}
+
+static void __nlSparseMatrix_transpose_mult_rows(
+ __NLSparseMatrix* A, NLfloat* x, NLfloat* y
+) {
+ NLuint m = A->m;
+ NLuint n = A->n;
+ NLuint i,ij;
+ __NLRowColumn* Ri = NULL;
+ __NLCoeff* c = NULL;
+
+ __NL_CLEAR_ARRAY(NLfloat, y, n);
+
+ for(i=0; i<m; i++) {
+ Ri = &(A->row[i]);
+ for(ij=0; ij<Ri->size; ij++) {
+ c = &(Ri->coeff[ij]);
+ y[c->index] += c->value * x[i];
+ }
+ }
+}
+
/************************************************************************************/
/* NLContext data structure */
typedef void(*__NLMatrixFunc)(float* x, float* y);
typedef struct {
- NLfloat value;
+ NLfloat value[4];
NLboolean locked;
NLuint index;
__NLRowColumn *a;
@@ -447,32 +492,32 @@
#define __NL_STATE_INITIAL 0
#define __NL_STATE_SYSTEM 1
#define __NL_STATE_MATRIX 2
-#define __NL_STATE_ROW 3
-#define __NL_STATE_MATRIX_CONSTRUCTED 4
-#define __NL_STATE_SYSTEM_CONSTRUCTED 5
-#define __NL_STATE_SYSTEM_SOLVED 7
+#define __NL_STATE_MATRIX_CONSTRUCTED 3
+#define __NL_STATE_SYSTEM_CONSTRUCTED 4
+#define __NL_STATE_SYSTEM_SOLVED 5
typedef struct {
- NLenum state;
- NLuint n;
+ NLenum state;
+ NLuint n;
+ NLuint m;
__NLVariable* variable;
NLfloat* b;
+ NLfloat* Mtb;
__NLSparseMatrix M;
- __NLRowColumn af;
- __NLRowColumn al;
+ __NLSparseMatrix MtM;
NLfloat* x;
- NLfloat right_hand_side;
- NLuint nb_variables;
- NLuint current_row;
+ NLuint nb_variables;
+ NLuint nb_rows;
NLboolean least_squares;
NLboolean symmetric;
+ NLuint nb_rhs;
NLboolean solve_again;
NLboolean alloc_M;
- NLboolean alloc_af;
- NLboolean alloc_al;
+ NLboolean alloc_MtM;
NLboolean alloc_variable;
NLboolean alloc_x;
NLboolean alloc_b;
+ NLboolean alloc_Mtb;
NLfloat error;
__NLMatrixFunc matrix_vector_prod;
@@ -494,8 +539,8 @@
NLContext nlNewContext(void) {
__NLContext* result = __NL_NEW(__NLContext);
result->state = __NL_STATE_INITIAL;
- result->right_hand_side = 0.0;
result->matrix_vector_prod = __nlMatrixVectorProd_default;
+ result->nb_rhs = 1;
nlMakeCurrent(result);
return result;
}
@@ -512,12 +557,9 @@
if(context->alloc_M) {
__nlSparseMatrixDestroy(&context->M);
}
- if(context->alloc_af) {
- __nlRowColumnDestroy(&context->af);
+ if(context->alloc_MtM) {
+ __nlSparseMatrixDestroy(&context->MtM);
}
- if(context->alloc_al) {
- __nlRowColumnDestroy(&context->al);
- }
if(context->alloc_variable) {
for(i=0; i<context->nb_variables; i++) {
if(context->variable[i].a) {
@@ -529,6 +571,9 @@
if(context->alloc_b) {
__NL_DELETE_ARRAY(context->b);
}
+ if(context->alloc_Mtb) {
+ __NL_DELETE_ARRAY(context->Mtb);
+ }
if(context->alloc_x) {
__NL_DELETE_ARRAY(context->x);
}
@@ -569,12 +614,19 @@
__nl_assert(param > 0);
__nlCurrentContext->nb_variables = (NLuint)param;
} break;
+ case NL_NB_ROWS: {
+ __nl_assert(param > 0);
+ __nlCurrentContext->nb_rows = (NLuint)param;
+ } break;
case NL_LEAST_SQUARES: {
__nlCurrentContext->least_squares = (NLboolean)param;
} break;
case NL_SYMMETRIC: {
__nlCurrentContext->symmetric = (NLboolean)param;
- }
+ } break;
+ case NL_NB_RIGHT_HAND_SIDES: {
+ __nlCurrentContext->nb_rhs = (NLuint)param;
+ } break;
default: {
__nl_assert_not_reached;
} break;
@@ -588,36 +640,25 @@
__nl_assert(param > 0);
__nlCurrentContext->nb_variables = (NLuint)param;
} break;
+ case NL_NB_ROWS: {
+ __nl_assert(param > 0);
+ __nlCurrentContext->nb_rows = (NLuint)param;
+ } break;
case NL_LEAST_SQUARES: {
__nlCurrentContext->least_squares = (NLboolean)param;
} break;
case NL_SYMMETRIC: {
__nlCurrentContext->symmetric = (NLboolean)param;
- }
+ } break;
+ case NL_NB_RIGHT_HAND_SIDES: {
+ __nlCurrentContext->nb_rhs = (NLuint)param;
+ } break;
default: {
__nl_assert_not_reached;
} break;
}
}
-void nlRowParameterf(NLenum pname, NLfloat param) {
- __nlCheckState(__NL_STATE_MATRIX);
- switch(pname) {
- case NL_RIGHT_HAND_SIDE: {
- __nlCurrentContext->right_hand_side = param;
- } break;
- }
-}
-
-void nlRowParameteri(NLenum pname, NLint param) {
- __nlCheckState(__NL_STATE_MATRIX);
- switch(pname) {
- case NL_RIGHT_HAND_SIDE: {
- __nlCurrentContext->right_hand_side = (NLfloat)param;
- } break;
- }
-}
-
void nlGetBooleanv(NLenum pname, NLboolean* params) {
switch(pname) {
case NL_LEAST_SQUARES: {
@@ -637,6 +678,9 @@
case NL_NB_VARIABLES: {
*params = (NLfloat)(__nlCurrentContext->nb_variables);
} break;
+ case NL_NB_ROWS: {
+ *params = (NLfloat)(__nlCurrentContext->nb_rows);
+ } break;
case NL_LEAST_SQUARES: {
*params = (NLfloat)(__nlCurrentContext->least_squares);
} break;
@@ -657,6 +701,9 @@
case NL_NB_VARIABLES: {
*params = (NLint)(__nlCurrentContext->nb_variables);
} break;
+ case NL_NB_ROWS: {
+ *params = (NLint)(__nlCurrentContext->nb_rows);
+ } break;
case NL_LEAST_SQUARES: {
*params = (NLint)(__nlCurrentContext->least_squares);
} break;
@@ -700,16 +747,16 @@
/************************************************************************************/
/* Get/Set Lock/Unlock variables */
-void nlSetVariable(NLuint index, NLfloat value) {
+void nlSetVariable(NLuint rhsindex, NLuint index, NLfloat value) {
__nlCheckState(__NL_STATE_SYSTEM);
__nl_parano_range_assert(index, 0, __nlCurrentContext->nb_variables - 1);
- __nlCurrentContext->variable[index].value = value;
+ __nlCurrentContext->variable[index].value[rhsindex] = value;
}
-NLfloat nlGetVariable(NLuint index) {
+NLfloat nlGetVariable(NLuint rhsindex, NLuint index) {
__nl_assert(__nlCurrentContext->state != __NL_STATE_INITIAL);
__nl_parano_range_assert(index, 0, __nlCurrentContext->nb_variables - 1);
- return __nlCurrentContext->variable[index].value;
+ return __nlCurrentContext->variable[index].value[rhsindex];
}
void nlLockVariable(NLuint index) {
@@ -734,31 +781,41 @@
/* System construction */
static void __nlVariablesToVector() {
- NLuint i;
+ __NLContext *context = __nlCurrentContext;
+ NLuint i, j, nb_rhs;
- __nl_assert(__nlCurrentContext->alloc_x);
- __nl_assert(__nlCurrentContext->alloc_variable);
+ __nl_assert(context->alloc_x);
+ __nl_assert(context->alloc_variable);
- for(i=0; i<__nlCurrentContext->nb_variables; i++) {
- __NLVariable* v = &(__nlCurrentContext->variable[i]);
+ nb_rhs= context->nb_rhs;
+
+ for(i=0; i<context->nb_variables; i++) {
+ __NLVariable* v = &(context->variable[i]);
if(!v->locked) {
- __nl_assert(v->index < __nlCurrentContext->n);
- __nlCurrentContext->x[v->index] = v->value;
+ __nl_assert(v->index < context->n);
+
+ for(j=0; j<nb_rhs; j++)
+ context->x[context->n*j + v->index] = v->value[j];
}
}
}
static void __nlVectorToVariables() {
- NLuint i;
+ __NLContext *context = __nlCurrentContext;
+ NLuint i, j, nb_rhs;
- __nl_assert(__nlCurrentContext->alloc_x);
- __nl_assert(__nlCurrentContext->alloc_variable);
+ __nl_assert(context->alloc_x);
+ __nl_assert(context->alloc_variable);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list