[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47126] branches/soc-2012-sushi: I added several lines and file for do laplacian smooth.

Alexander Pinzon apinzonf at gmail.com
Mon May 28 19:15:57 CEST 2012


Revision: 47126
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47126
Author:   apinzonf
Date:     2012-05-28 17:15:57 +0000 (Mon, 28 May 2012)
Log Message:
-----------
I added several lines and file for do laplacian smooth.
At this moment the laplacian smooth is then same that smooth vertex, i did this for test functionality from operators to user interface.

Modified Paths:
--------------
    branches/soc-2012-sushi/release/scripts/startup/bl_ui/space_view3d.py
    branches/soc-2012-sushi/source/blender/bmesh/CMakeLists.txt
    branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c
    branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_operators_private.h
    branches/soc-2012-sushi/source/blender/editors/mesh/editmesh_tools.c
    branches/soc-2012-sushi/source/blender/editors/mesh/mesh_intern.h
    branches/soc-2012-sushi/source/blender/editors/mesh/mesh_ops.c

Added Paths:
-----------
    branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_smooth_laplacian.c

Modified: branches/soc-2012-sushi/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- branches/soc-2012-sushi/release/scripts/startup/bl_ui/space_view3d.py	2012-05-28 17:03:13 UTC (rev 47125)
+++ branches/soc-2012-sushi/release/scripts/startup/bl_ui/space_view3d.py	2012-05-28 17:15:57 UTC (rev 47126)
@@ -1686,6 +1686,7 @@
         layout.operator("mesh.select_all", text="Select Inverse").action = 'INVERT'
         layout.operator("mesh.flip_normals")
         layout.operator("mesh.vertices_smooth", text="Smooth")
+        layout.operator("mesh.vertices_smooth_laplacian", text="Laplacian Smooth")
         layout.operator("mesh.inset")
         layout.operator("mesh.bevel", text="Bevel")
         layout.operator("mesh.bridge_edge_loops")

Modified: branches/soc-2012-sushi/source/blender/bmesh/CMakeLists.txt
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/CMakeLists.txt	2012-05-28 17:03:13 UTC (rev 47125)
+++ branches/soc-2012-sushi/source/blender/bmesh/CMakeLists.txt	2012-05-28 17:15:57 UTC (rev 47126)
@@ -48,6 +48,7 @@
 	operators/bmo_mirror.c
 	operators/bmo_primitive.c
 	operators/bmo_removedoubles.c
+	operators/bmo_smooth_laplacian.c
 	operators/bmo_subdivide.c
 	operators/bmo_subdivide.h
 	operators/bmo_triangulate.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-28 17:03:13 UTC (rev 47125)
+++ branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c	2012-05-28 17:15:57 UTC (rev 47126)
@@ -111,6 +111,24 @@
 };
 
 /*
+ * Vertext Smooth Laplacian 
+ * Smooths vertices by using Laplacian smoothing propose by.
+ * Desbrun, et al. Implicit Fairing of Irregular Meshes using Diffusion and Curvature Flow
+*/
+static BMOpDefine bmo_vertexsmoothlaplacian_def = {
+	"vertexsmoothlaplacian",
+	{{BMO_OP_SLOT_ELEMENT_BUF, "verts"}, //input vertices
+	 {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
+	 {BMO_OP_SLOT_FLT, "clipdist"}, //clipping threshod for the above three slots
+	{0} /* null-terminating sentinel */,
+	},
+	bmo_vertexsmoothlaplacian_exec,
+	0
+};
+
+/*
  * Right-Hand Faces
  *
  * Computes an "outside" normal for the specified input faces.
@@ -1208,6 +1226,7 @@
 	&bmo_regionextend_def,
 	&bmo_righthandfaces_def,
 	&bmo_vertexsmooth_def,
+	&bmo_vertexsmoothlaplacian_def,
 	&bmo_extrude_edge_only_def,
 	&bmo_extrude_indivface_def,
 	&bmo_collapse_uvs_def,

Modified: branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_operators_private.h	2012-05-28 17:03:13 UTC (rev 47125)
+++ branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_operators_private.h	2012-05-28 17:15:57 UTC (rev 47126)
@@ -66,6 +66,7 @@
 void bmo_regionextend_exec(BMesh *bm, BMOperator *op);
 void bmo_righthandfaces_exec(BMesh *bm, BMOperator *op);
 void bmo_vertexsmooth_exec(BMesh *bm, BMOperator *op);
+void bmo_vertexsmoothlaplacian_exec(BMesh *bm, BMOperator *op);
 void bmo_extrude_edge_only_exec(BMesh *bm, BMOperator *op);
 void bmo_extrude_face_indiv_exec(BMesh *bm, BMOperator *op);
 void bmo_collapse_uvs_exec(BMesh *bm, BMOperator *op);

Added: branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_smooth_laplacian.c
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_smooth_laplacian.c	                        (rev 0)
+++ branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_smooth_laplacian.c	2012-05-28 17:15:57 UTC (rev 47126)
@@ -0,0 +1,95 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Joseph Eagar.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/bmesh/operators/bmo_smooth_laplacian.c
+ *  \ingroup bmesh
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_meshdata_types.h"
+
+#include "BLI_array.h"
+#include "BLI_heap.h"
+#include "BLI_math.h"
+#include "BLI_smallhash.h"
+
+#include "BKE_customdata.h"
+
+#include "bmesh.h"
+
+#include "intern/bmesh_operators_private.h" /* own include */
+
+void bmo_vertexsmoothlaplacian_exec(BMesh *bm, BMOperator *op)
+{
+	BMOIter siter;
+	BMIter iter;
+	BMVert *v;
+	BMEdge *e;
+	BLI_array_declare(cos);
+	float (*cos)[3] = NULL;
+	float *co, *co2, clipdist = BMO_slot_float_get(op, "clipdist");
+	int i, j, clipx, clipy, clipz;
+	
+	clipx = BMO_slot_bool_get(op, "mirror_clip_x");
+	clipy = BMO_slot_bool_get(op, "mirror_clip_y");
+	clipz = BMO_slot_bool_get(op, "mirror_clip_z");
+
+	i = 0;
+	BMO_ITER (v, &siter, bm, op, "verts", BM_VERT) {
+		BLI_array_grow_one(cos);
+		co = cos[i];
+		
+		j  = 0;
+		BM_ITER_ELEM (e, &iter, v, BM_EDGES_OF_VERT) {
+			co2 = BM_edge_other_vert(e, v)->co;
+			add_v3_v3v3(co, co, co2);
+			j += 1;
+		}
+		
+		if (!j) {
+			copy_v3_v3(co, v->co);
+			i++;
+			continue;
+		}
+
+		mul_v3_fl(co, 1.0f / (float)j);
+		mid_v3_v3v3(co, co, v->co);
+
+		if (clipx && fabsf(v->co[0]) <= clipdist)
+			co[0] = 0.0f;
+		if (clipy && fabsf(v->co[1]) <= clipdist)
+			co[1] = 0.0f;
+		if (clipz && fabsf(v->co[2]) <= clipdist)
+			co[2] = 0.0f;
+
+		i++;
+	}
+
+	i = 0;
+	BMO_ITER (v, &siter, bm, op, "verts", BM_VERT) {
+		copy_v3_v3(v->co, cos[i]);
+		i++;
+	}
+
+	BLI_array_free(cos);
+}

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-28 17:03:13 UTC (rev 47125)
+++ branches/soc-2012-sushi/source/blender/editors/mesh/editmesh_tools.c	2012-05-28 17:15:57 UTC (rev 47126)
@@ -1595,6 +1595,82 @@
 	RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Number of times to smooth the mesh", "", 1, INT_MAX);
 }
 
+static int edbm_do_smooth_laplacian_vertex_exec(bContext *C, wmOperator *op)
+{
+	Object *obedit = CTX_data_edit_object(C);
+	BMEditMesh *em = BMEdit_FromObject(obedit);
+	ModifierData *md;
+	int mirrx = FALSE, mirry = FALSE, mirrz = FALSE;
+	int i, repeat;
+	float clipdist = 0.0f;
+
+	/* mirror before smooth */
+	if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) {
+		EDBM_verts_mirror_cache_begin(em, TRUE);
+	}
+
+	/* if there is a mirror modifier with clipping, flag the verts that
+	 * are within tolerance of the plane(s) of reflection 
+	 */
+	for (md = obedit->modifiers.first; md; md = md->next) {
+		if (md->type == eModifierType_Mirror && (md->mode & eModifierMode_Realtime)) {
+			MirrorModifierData *mmd = (MirrorModifierData *)md;
+		
+			if (mmd->flag & MOD_MIR_CLIPPING) {
+				if (mmd->flag & MOD_MIR_AXIS_X)
+					mirrx = TRUE;
+				if (mmd->flag & MOD_MIR_AXIS_Y)
+					mirry = TRUE;
+				if (mmd->flag & MOD_MIR_AXIS_Z)
+					mirrz = TRUE;
+
+				clipdist = mmd->tolerance;
+			}
+		}
+	}
+
+	repeat = RNA_int_get(op->ptr, "repeat");
+	if (!repeat)
+		repeat = 1;
+	
+	for (i = 0; i < repeat; i++) {
+		if (!EDBM_op_callf(em, op,
+		                   "vertexsmoothlaplacian verts=%hv mirror_clip_x=%b mirror_clip_y=%b mirror_clip_z=%b clipdist=%f",
+		                   BM_ELEM_SELECT, mirrx, mirry, mirrz, clipdist))
+		{
+			return OPERATOR_CANCELLED;
+		}
+	}
+
+	/* apply mirror */
+	if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) {
+		EDBM_verts_mirror_apply(em, BM_ELEM_SELECT, 0);
+		EDBM_verts_mirror_cache_end(em);
+	}
+
+	EDBM_update_generic(C, em, TRUE);
+
+	return OPERATOR_FINISHED;
+}
+
+void MESH_OT_vertices_smooth_laplacian(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Laplacian Smooth Vertex";
+	ot->description = "Laplacian smooth of selected vertices";
+	ot->idname = "MESH_OT_vertices_smooth_laplacian";
+	
+	/* api callbacks */
+	ot->exec = edbm_do_smooth_laplacian_vertex_exec;
+	ot->poll = ED_operator_editmesh;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Number of iterations to smooth the mesh", "", 1, INT_MAX);
+
+}
+
 /********************** Smooth/Solid Operators *************************/
 
 static void mesh_set_smooth_faces(BMEditMesh *em, short smooth)

Modified: branches/soc-2012-sushi/source/blender/editors/mesh/mesh_intern.h
===================================================================
--- branches/soc-2012-sushi/source/blender/editors/mesh/mesh_intern.h	2012-05-28 17:03:13 UTC (rev 47125)
+++ branches/soc-2012-sushi/source/blender/editors/mesh/mesh_intern.h	2012-05-28 17:15:57 UTC (rev 47126)
@@ -136,6 +136,7 @@
 void MESH_OT_mark_seam(struct wmOperatorType *ot);
 void MESH_OT_mark_sharp(struct wmOperatorType *ot);
 void MESH_OT_vertices_smooth(struct wmOperatorType *ot);
+void MESH_OT_vertices_smooth_laplacian(struct wmOperatorType *ot);
 void MESH_OT_noise(struct wmOperatorType *ot);
 void MESH_OT_flip_normals(struct wmOperatorType *ot);
 void MESH_OT_solidify(struct wmOperatorType *ot);

Modified: branches/soc-2012-sushi/source/blender/editors/mesh/mesh_ops.c
===================================================================
--- branches/soc-2012-sushi/source/blender/editors/mesh/mesh_ops.c	2012-05-28 17:03:13 UTC (rev 47125)
+++ branches/soc-2012-sushi/source/blender/editors/mesh/mesh_ops.c	2012-05-28 17:15:57 UTC (rev 47126)
@@ -132,6 +132,7 @@
 	WM_operatortype_append(MESH_OT_mark_seam);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list