[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47303] branches/soc-2012-sushi/source/ blender: Area constraint added.

Alexander Pinzon apinzonf at gmail.com
Fri Jun 1 00:21:57 CEST 2012


Revision: 47303
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47303
Author:   apinzonf
Date:     2012-05-31 22:21:56 +0000 (Thu, 31 May 2012)
Log Message:
-----------
Area constraint added.

Modified Paths:
--------------
    branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c
    branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_smooth_laplacian.c
    branches/soc-2012-sushi/source/blender/editors/mesh/editmesh_tools.c

Modified: branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c	2012-05-31 21:56:41 UTC (rev 47302)
+++ branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c	2012-05-31 22:21:56 UTC (rev 47303)
@@ -119,6 +119,7 @@
 	"vertexsmoothlaplacian",
 	{{BMO_OP_SLOT_ELEMENT_BUF, "verts"}, //input vertices
 	 {BMO_OP_SLOT_FLT, "lambda"}, //lambda param
+	 {BMO_OP_SLOT_FLT, "min_area"}, //Minimun area permited
 	 {BMO_OP_SLOT_BOOL, "mirror_clip_x"}, //set vertices close to the x axis before the operation to 0
 	 {BMO_OP_SLOT_BOOL, "mirror_clip_y"}, //set vertices close to the y axis before the operation to 0
 	 {BMO_OP_SLOT_BOOL, "mirror_clip_z"}, //set vertices close to the z axis before the operation to 0

Modified: branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_smooth_laplacian.c
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_smooth_laplacian.c	2012-05-31 21:56:41 UTC (rev 47302)
+++ branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_smooth_laplacian.c	2012-05-31 22:21:56 UTC (rev 47303)
@@ -46,19 +46,20 @@
 #define SMOOTH_LAPLACIAN_AREA_FACTOR 4.0f
 
 static float cotan_weight(float *v1, float *v2, float *v3);
-void compute_weights_in_ring(BMVert *v, float lambda);
+void compute_weights_in_ring(BMVert *v, float lambda, float min_area);
 
 void bmo_vertexsmoothlaplacian_exec(BMesh *bm, BMOperator *op)
 {
 	int i;
 	int m_vertex_id;
-	float lambda;
+	float lambda, min_area;
 	BMOIter siter;
 	BMVert *v;
 	NLContext *context;
 
 	BM_mesh_elem_index_ensure(bm, BM_VERT);
 	lambda = BMO_slot_float_get(op, "lambda");
+	min_area = BMO_slot_float_get(op, "min_area");
 	nlNewContext();
 	context = nlGetCurrent();
 
@@ -85,7 +86,7 @@
 		nlRightHandSideAdd(0, m_vertex_id, v->co[0]);
 		nlRightHandSideAdd(1, m_vertex_id, v->co[1]);
 		nlRightHandSideAdd(2, m_vertex_id, v->co[2]);
-		compute_weights_in_ring(v, lambda);
+		compute_weights_in_ring(v, lambda, min_area);
 	}
 		
 	nlEnd(NL_MATRIX);
@@ -95,13 +96,13 @@
 		nlPrintMatrix();
 	}
 
-	nlSolveAdvanced(NULL, NL_TRUE);
-
-	BMO_ITER (v, &siter, bm, op, "verts", BM_VERT) {
-		m_vertex_id = BM_elem_index_get(v);
-		v->co[0] =  nlGetVariable(0, m_vertex_id);
-		v->co[1] =  nlGetVariable(1, m_vertex_id);
-		v->co[2] =  nlGetVariable(2, m_vertex_id);
+	if (nlSolveAdvanced(NULL, NL_TRUE) ) {
+		BMO_ITER (v, &siter, bm, op, "verts", BM_VERT) {
+			m_vertex_id = BM_elem_index_get(v);
+			v->co[0] =  nlGetVariable(0, m_vertex_id);
+			v->co[1] =  nlGetVariable(1, m_vertex_id);
+			v->co[2] =  nlGetVariable(2, m_vertex_id);
+		}
 	}
 		
 	nlDeleteContext(context);
@@ -134,9 +135,10 @@
  *          \ | /
  *            * v_neighbor
 */
-void compute_weights_in_ring(BMVert *v, float lambda)
+void compute_weights_in_ring(BMVert *v, float lambda, float min_area)
 {	
 	float area = 0.0f;
+	float at;
 	float factor;
 	float sumw = 0.0f;
 	float w1, w2;
@@ -145,6 +147,7 @@
 	int id1, id2, id3;
 	int i, j;
 	int * index = NULL;
+	int zeroa = 1;
 	BMIter fi;
 	BMIter vi;
 	BMFace *f;
@@ -173,35 +176,49 @@
 			i = i + 1;
 		}
 		if (i == 3 && ai > -1){
-			area = area + area_tri_v3(vf[0]->co, vf[1]->co, vf[2]->co);
+			at = area_tri_v3(vf[0]->co, vf[1]->co, vf[2]->co);
+			if (fabsf(at) < min_area) {
+				zeroa = 0;
+			}
+			area = area + at;
 			w1 = cotan_weight (vf[bi]->co, vf[ci]->co, vf[ai]->co); 
 			w2 = cotan_weight (vf[ci]->co, vf[ai]->co, vf[bi]->co);
 			id2 = BM_elem_index_get (vf[bi]);
 			id3 = BM_elem_index_get (vf[ci]);
-			BLI_array_grow_one (index);
-			BLI_array_grow_one (weight);
+			BLI_array_grow_one(index);
+			BLI_array_grow_one(weight);
 			index[j] = id3;
 			weight[j] = w1;
 			j = j + 1;
-			BLI_array_grow_one (index);
-			BLI_array_grow_one (weight);
+			BLI_array_grow_one(index);
+			BLI_array_grow_one(weight);
 			index[j] = id2;
 			weight[j] = w2;
 			sumw = sumw + w1 + w2;
 			j = j + 1;
 		}
 	}
-	for(i = 0; i < j; i = i + 2){
-		factor = lambda / (SMOOTH_LAPLACIAN_AREA_FACTOR * sumw * area);
-		w1 = -factor * weight[i];
-		w2 = -factor * weight[i+1];
-		id2 = index[i];
-		id3 = index[i+1];
-		nlMatrixAdd(id1, id2, w1);
-		nlMatrixAdd(id1, id3, w2);
+	for (i = 0; i < j; i = i + 2) {
+		if (zeroa == 1) {
+			factor = lambda / (SMOOTH_LAPLACIAN_AREA_FACTOR * sumw * area);
+			w1 = -factor * weight[i];
+			w2 = -factor * weight[i+1];
+			id2 = index[i];
+			id3 = index[i+1];
+			nlMatrixAdd(id1, id2, w1);
+			nlMatrixAdd(id1, id3, w2);
+		} else {
+			nlMatrixAdd(id1, id2, 0.0f);
+			nlMatrixAdd(id1, id3, 0.0f);
+		}
 	}
-	nlMatrixAdd(id1, id1, 1.0f + lambda / (SMOOTH_LAPLACIAN_AREA_FACTOR * area));
+	if (zeroa == 1) {
+		nlMatrixAdd(id1, id1, 1.0f + lambda / (SMOOTH_LAPLACIAN_AREA_FACTOR * area));
+	} else {
+		nlMatrixAdd(id1, id1, 1.0f);
 
+	}
+
 	BLI_array_free(index);
 	BLI_array_free(weight);
 	

Modified: branches/soc-2012-sushi/source/blender/editors/mesh/editmesh_tools.c
===================================================================
--- branches/soc-2012-sushi/source/blender/editors/mesh/editmesh_tools.c	2012-05-31 21:56:41 UTC (rev 47302)
+++ branches/soc-2012-sushi/source/blender/editors/mesh/editmesh_tools.c	2012-05-31 22:21:56 UTC (rev 47303)
@@ -1604,6 +1604,7 @@
 	int i, repeat;
 	float clipdist = 0.0f;
 	float lambda = 0.1f;
+	float min_area = 0.00001f;
 	BMIter fiter;
 	BMIter viter;
 	BMFace *f;
@@ -1649,13 +1650,14 @@
 
 	repeat = RNA_int_get(op->ptr, "repeat");
 	lambda = RNA_float_get(op->ptr, "lambda");
+	min_area = RNA_float_get(op->ptr, "min_area");
 	if (!repeat)
 		repeat = 1;
 	
 	for (i = 0; i < repeat; i++) {
 		if (!EDBM_op_callf(em, op,
-		                   "vertexsmoothlaplacian verts=%hv lambda=%f mirror_clip_x=%b mirror_clip_y=%b mirror_clip_z=%b clipdist=%f",
-		                   BM_ELEM_SELECT, lambda, mirrx, mirry, mirrz, clipdist))
+		                   "vertexsmoothlaplacian verts=%hv lambda=%f min_area=%f mirror_clip_x=%b mirror_clip_y=%b mirror_clip_z=%b clipdist=%f",
+		                   BM_ELEM_SELECT, lambda, min_area, mirrx, mirry, mirrz, clipdist))
 		{
 			return OPERATOR_CANCELLED;
 		}
@@ -1688,6 +1690,7 @@
 
 	RNA_def_int(ot->srna, "repeat", 1, 1, 50, "Number of iterations to smooth the mesh", "", 1, 50);
 	RNA_def_float(ot->srna, "lambda", 0.00005f, 0.0000001f, 100.0f, "Lambda factor", "", 0.0000001f, 100.0f);
+	RNA_def_float(ot->srna, "min_area", 0.00001f, 0.0000000000000001f, 100.0f, "Minimum area permitted", "", 0.0000000000000001f, 100.0f);
 
 }
 




More information about the Bf-blender-cvs mailing list