[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58480] branches/soc-2013-sketch_mesh/ source/blender/editors/mesh/editmesh_deform_laplacian.c: Variables are initialized with the positions of the vertices so that the system does not take into account the trivial zero solution .

Alexander Pinzon apinzonf at gmail.com
Sun Jul 21 18:46:00 CEST 2013


Revision: 58480
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58480
Author:   apinzonf
Date:     2013-07-21 16:46:00 +0000 (Sun, 21 Jul 2013)
Log Message:
-----------
Variables are initialized with the positions of the vertices so that the system does not take into account the trivial zero solution.

Modified Paths:
--------------
    branches/soc-2013-sketch_mesh/source/blender/editors/mesh/editmesh_deform_laplacian.c

Modified: branches/soc-2013-sketch_mesh/source/blender/editors/mesh/editmesh_deform_laplacian.c
===================================================================
--- branches/soc-2013-sketch_mesh/source/blender/editors/mesh/editmesh_deform_laplacian.c	2013-07-21 16:45:38 UTC (rev 58479)
+++ branches/soc-2013-sketch_mesh/source/blender/editors/mesh/editmesh_deform_laplacian.c	2013-07-21 16:46:00 UTC (rev 58480)
@@ -358,7 +358,7 @@
 
 static void init_laplacian_matrix( SystemCustomData * data)
 {
-	float v1[3], v2[3], v3[3], v4[3], no[3];
+	float v1[3], v2[3], v3[3], v4[3], no[3], cf[3], nt[3];
 	float w2, w3, w4;
 	int i, j, vid, vidf[4];
 	bool has_4_vert;
@@ -383,16 +383,37 @@
 		idv4 = has_4_vert ? vidf[3] : 0;
 		if (has_4_vert) {
 			normal_quad_v3(no, sa->co[idv1], sa->co[idv2], sa->co[idv3], sa->co[idv4]); 
-			add_v3_v3(sa->no[idv1], no);
-			add_v3_v3(sa->no[idv2], no);
-			add_v3_v3(sa->no[idv3], no);
-			add_v3_v3(sa->no[idv4], no);
+			add_v3_v3v3(cf, sa->co[idv1], sa->co[idv2]);
+			add_v3_v3(cf, sa->co[idv3]);
+			add_v3_v3(cf, sa->co[idv4]);
+			mul_v3_fl(cf, 1.0f/4.0f);
+
+			mul_v3_v3fl(nt, no, len_v3v3(cf, sa->co[idv1]));
+			add_v3_v3(sa->no[idv1], nt);
+
+			mul_v3_v3fl(nt, no, len_v3v3(cf, sa->co[idv2]));
+			add_v3_v3(sa->no[idv2], nt);
+
+			mul_v3_v3fl(nt, no, len_v3v3(cf, sa->co[idv3]));
+			add_v3_v3(sa->no[idv3], nt);
+
+			mul_v3_v3fl(nt, no, len_v3v3(cf, sa->co[idv4]));
+			add_v3_v3(sa->no[idv4], nt);
 		} 
 		else {
 			normal_tri_v3(no, sa->co[idv1], sa->co[idv2], sa->co[idv3]); 
-			add_v3_v3(sa->no[idv1], no);
-			add_v3_v3(sa->no[idv2], no);
-			add_v3_v3(sa->no[idv3], no);
+			add_v3_v3v3(cf, sa->co[idv1], sa->co[idv2]);
+			add_v3_v3(cf, sa->co[idv3]);
+			mul_v3_fl(cf, 1.0f/3.0f);
+
+			mul_v3_v3fl(nt, no, len_v3v3(cf, sa->co[idv1]));
+			add_v3_v3(sa->no[idv1], nt);
+
+			mul_v3_v3fl(nt, no, len_v3v3(cf, sa->co[idv2]));
+			add_v3_v3(sa->no[idv2], nt);
+
+			mul_v3_v3fl(nt, no, len_v3v3(cf, sa->co[idv3]));
+			add_v3_v3(sa->no[idv3], nt);
 		}
 
 
@@ -526,7 +547,7 @@
 	BMIter fiter;
 	BMIter viter, viter2;
 	float alpha, beta, gamma,
-		pj[3], ni[3], di[3],
+		pj[3], ni[3], di[3], cf[3],
 		uij[3], dun[3], e2[3], pi[3], fni[3], vn[4][3];
 	int i, j, vin[4], lvin, num_fni, k;
 	LaplacianSystem * sys = data->sys;
@@ -572,9 +593,19 @@
 
 			if (lvin == 3) {
 				normal_tri_v3(fni, vn[0], vn[1], vn[2]);
+				add_v3_v3v3(cf, vn[0], vn[1]);
+				add_v3_v3(cf, vn[2]);
+				mul_v3_fl(cf, 1.0f/3.0f);
+				mul_v3_fl(fni, len_v3v3(cf, pi));
+				
 			} 
 			else if(lvin == 4) {
 				normal_quad_v3(fni, vn[0], vn[1], vn[2], vn[3]);
+				add_v3_v3v3(cf, vn[0], vn[1]);
+				add_v3_v3(cf, vn[2]);
+				add_v3_v3(cf, vn[3]);
+				mul_v3_fl(cf, 1.0f/4.0f);
+				mul_v3_fl(fni, len_v3v3(cf, pi));
 			} 
 
 			add_v3_v3(ni, fni);
@@ -587,11 +618,22 @@
 		sub_v3_v3(uij, dun);
 		normalize_v3(uij);
 		cross_v3_v3v3(e2, ni, uij);
+		fni[0] = alpha*ni[0] + beta*uij[0] + gamma*e2[0];
+		fni[1] = alpha*ni[1] + beta*uij[1] + gamma*e2[1];
+		fni[2] = alpha*ni[2] + beta*uij[2] + gamma*e2[2];
 
-		nlRightHandSideSet(0, i, alpha*ni[0] + beta*uij[0] + gamma*e2[0]);
-		nlRightHandSideSet(1, i, alpha*ni[1] + beta*uij[1] + gamma*e2[1]);
-		nlRightHandSideSet(2, i, alpha*ni[2] + beta*uij[2] + gamma*e2[2]);
+		if (len_v3(fni) > FLT_EPSILON) {
+			nlRightHandSideSet(0, i, fni[0]);
+			nlRightHandSideSet(1, i, fni[1]);
+			nlRightHandSideSet(2, i, fni[2]);
+		} 
+		else {
+			nlRightHandSideSet(0, i, sys->delta[i][0]);
+			nlRightHandSideSet(1, i, sys->delta[i][1]);
+			nlRightHandSideSet(2, i, sys->delta[i][2]);
+		}
 
+
 	}
 	
 }
@@ -778,6 +820,20 @@
 		nlSolverParameteri(NL_NB_RIGHT_HAND_SIDES, 3);
 
 		nlBegin(NL_SYSTEM);
+		for (i=0; i<n; i++) {
+			nlSetVariable(0, i, sa->co[i][0]);
+			nlSetVariable(1, i, sa->co[i][1]);
+			nlSetVariable(2, i, sa->co[i][2]);
+		}
+		for (i=0; i<nh; i++) {
+			vid = shs->list_handlers[i];
+			nlSetVariable(0, vid, sa->list_verts[vid]->co[0]);
+			nlSetVariable(1, vid, sa->list_verts[vid]->co[1]);
+			nlSetVariable(2, vid, sa->list_verts[vid]->co[2]);
+		}
+		for (i=0; i<ns; i++) {
+			nlLockVariable(sa->list_index[i]);
+		}
 		nlBegin(NL_MATRIX);
 
 		init_laplacian_matrix(data);




More information about the Bf-blender-cvs mailing list