[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58244] branches/soc-2013-sketch_mesh/ source/blender: The code was organized and optimized.

Alexander Pinzon apinzonf at gmail.com
Sun Jul 14 23:54:15 CEST 2013


Revision: 58244
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58244
Author:   apinzonf
Date:     2013-07-14 21:54:15 +0000 (Sun, 14 Jul 2013)
Log Message:
-----------
The code was organized and optimized.
The system has problems with the handling of events.
The deformation system is activated with the special menu key W "Laplacian Deform" in vertex editing mode.
The system works with keys Pkey, Hkey, Skey
You must mark the static vertices with Skey, then the handlers with hkey, and then you can move the handles and calculate the deformation with Pkey.

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

Modified: branches/soc-2013-sketch_mesh/source/blender/bmesh/operators/bmo_deform_laplacian.c
===================================================================
--- branches/soc-2013-sketch_mesh/source/blender/bmesh/operators/bmo_deform_laplacian.c	2013-07-14 20:38:55 UTC (rev 58243)
+++ branches/soc-2013-sketch_mesh/source/blender/bmesh/operators/bmo_deform_laplacian.c	2013-07-14 21:54:15 UTC (rev 58244)
@@ -485,7 +485,7 @@
 			BLI_array_empty(vin);
 			vin = NULL;
 		}
-		if (num_fni>0) mul_v3_fl(fni, 1.0f/num_fni);
+		if (num_fni>0) mul_v3_fl(ni, 1.0f/num_fni);
 		sub_v3_v3v3(uij, pj, pi);
 		mul_v3_v3fl(dun, ni, dot_v3v3(uij, ni));
 		sub_v3_v3(uij, dun);

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-14 20:38:55 UTC (rev 58243)
+++ branches/soc-2013-sketch_mesh/source/blender/editors/mesh/editmesh_deform_laplacian.c	2013-07-14 21:54:15 UTC (rev 58244)
@@ -20,8 +20,8 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file blender/bmesh/operators/bmo_deform_laplacian.c
- *  \ingroup bmesh
+/** \file blender/editors/mesh/editmesh_deform_laplacian.c
+ *  \ingroup mesh
  *
  * Deform Laplacian.
  */
@@ -54,21 +54,31 @@
 #include "ED_view3d.h"
 #include "ED_mesh.h"
 
+struct BStaticAnchors {
+	int numStatics;				/* Number of static anchors*/
+	int numVerts;				/* Number of verts*/
+	int * list_index;			/* Static vertex index list*/
+	float (*co)[3];				/* Original vertex coordinates*/
+	float (*no)[3];				/* Original vertex normal*/
+};
+typedef struct BStaticAnchors StaticAnchors;
+
+struct BHandlerAnchors {
+	int numHandlers;			/* Number of handler anchors*/
+	int * list_handlers;		/* Static vertex index list*/
+};
+typedef struct BHandlerAnchors HandlerAnchors;
+
 struct BLaplacianSystem {
 	float *vweights;			/* Total sum of weights per vertice*/
 	float (*delta)[3];			/* Differential Coordinates*/
-	float (*cos)[3];			/* Original Vertices Positions*/
-	float (*nos)[3];			/* Original Vertices Normals*/
-	BMVert **handlers;			/* Handlers Vertices Positions*/
-	int *handlers_index;		/* Handlers Vertices index*/
-	int *statics_index;			/* Static Vertices index*/
-	BMVert **uverts;			/* Unit vectors of projected edges onto the plane orthogonal to  n*/
-	int numVerts;				/* Number of verts*/
-	int numStatics;				/* Number of static amchor verts*/
-	int numHandlers;			/* Number of handler anchor verts*/
+	int *list_uverts;			/* Unit vectors of projected edges onto the plane orthogonal to  n*/
+	BMVert ** list_verts;		/* Vertex order by index*/
 	/* Pointers to data*/
+	int numVerts;
+	int numHandlers;
+	int numStatics;
 	BMesh *bm;
-	BMOperator *op;
 	NLContext *context;			/* System for solve general implicit rotations*/
 	NLContext *contextrot;		/* System for solve general Laplacian with rotated differential coordinates*/
 	vptrSpMatrixD spLapMatrix;  /* Sparse Laplacian Matrix*/
@@ -78,27 +88,55 @@
 };
 typedef struct BLaplacianSystem LaplacianSystem;
 
-static void compute_mesh_laplacian();
-static void delete_laplacian_system(LaplacianSystem *sys);
-static void delete_void_pointer(void *data);
-static void compute_implict_rotations(LaplacianSystem * sys);
+enum {
+	LAP_STATE_INIT = 1,
+	LAP_STATE_HAS_STATIC,
+	LAP_STATE_HAS_HANDLER,
+	LAP_STATE_HAS_STATIC_AND_HANDLER,
+	LAP_STATE_HAS_L_COMPUTE,
+	LAP_STATE_UPDATE_REQUIRED
+};
 
-static float cotan_weight(float *v1, float *v2, float *v3)
-{
-	float a[3], b[3], c[3], clen;
+struct BSystemCustomData {
+	LaplacianSystem * sys;
+	StaticAnchors  * sa;
+	HandlerAnchors * shs;
+	int stateSystem;
+};
 
-	sub_v3_v3v3(a, v2, v1);
-	sub_v3_v3v3(b, v3, v1);
-	cross_v3_v3v3(c, a, b);
+typedef struct BSystemCustomData SystemCustomData;
 
-	clen = len_v3(c);
-	
-	if (clen < FLT_EPSILON)
-		return 0.0f;
 
-	return dot_v3v3(a, b) / clen;
-}
+enum {
+	LAP_MODAL_CANCEL = 1,
+	LAP_MODAL_CONFIRM,
+	LAP_MODAL_PREVIEW,
+	LAP_MODAL_MARK_STATIC,
+	LAP_MODAL_MARK_HANDLER
+};
 
+wmKeyMap * laplacian_deform_modal_keymap(wmKeyConfig *keyconf);
+void MESH_OT_vertices_laplacian_deform(wmOperatorType *ot);
+static StaticAnchors * init_static_anchors(int numv, int nums);
+static HandlerAnchors * init_handler_anchors(int numh);
+static LaplacianSystem * init_laplacian_system(int numv, int nums, int numh);
+static float cotan_weight(float *v1, float *v2, float *v3);
+static int laplacian_deform_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *evt);
+static int laplacian_deform_modal(bContext *C, wmOperator *op, const wmEvent *event);
+static int laplacian_deform_cancel(bContext *C, wmOperator *op);
+static void compute_implict_rotations(SystemCustomData * data);
+static void delete_void_pointer(void *data);
+static void delete_static_anchors(StaticAnchors * sa);
+static void delete_handler_anchors(HandlerAnchors * sh);
+static void delete_laplacian_system(LaplacianSystem *sys);
+static void init_laplacian_matrix( SystemCustomData * data);
+static void laplacian_deform_mark_static(bContext *C, wmOperator *op);
+static void laplacian_deform_mark_handlers(bContext *C, wmOperator *op);
+static void laplacian_deform_preview(bContext *C, wmOperator *op);
+static void laplacian_deform_init(struct bContext *C, LaplacianSystem * sys);
+static void rotate_differential_coordinates(SystemCustomData * data);
+static void update_system_state(SystemCustomData * data, int state);
+
 static void delete_void_pointer(void *data)
 {
 	if (data) {
@@ -106,127 +144,258 @@
 	}
 }
 
+static StaticAnchors * init_static_anchors(int numv, int nums)
+{
+	StaticAnchors * sa;
+	sa = (StaticAnchors *)MEM_callocN(sizeof(StaticAnchors), "LapStaticAnchors");
+	sa->numVerts = numv;
+	sa->numStatics = nums;
+	sa->list_index = (int *)MEM_callocN(sizeof(int)*(sa->numStatics), "LapListStatics");
+	sa->co = (float (*)[3])MEM_callocN(sizeof(float)*(sa->numVerts*3), "LapCoordinates");
+	sa->no = (float (*)[3])MEM_callocN(sizeof(float)*(sa->numVerts*3), "LapNormals");
+	return sa;
+}
+
+static HandlerAnchors * init_handler_anchors(int numh)
+{
+	HandlerAnchors * sh;
+	sh = (HandlerAnchors *)MEM_callocN(sizeof(HandlerAnchors), "LapHandlerAnchors");
+	sh->numHandlers = numh;
+	sh->list_handlers = (int *)MEM_callocN(sizeof(int)*(sh->numHandlers), "LapListHandlers");
+	return sh;
+}
+
+static LaplacianSystem * init_laplacian_system(int numv, int nums, int numh)
+{
+	LaplacianSystem *sys;
+	int rows, cols;
+	sys = (LaplacianSystem *)MEM_callocN(sizeof(LaplacianSystem), "LapSystem");
+	if (!sys) {
+		return NULL;
+	}
+	sys->numVerts = numv;
+	sys->numStatics = nums;
+	sys->numHandlers = numh;
+	rows = (sys->numVerts + sys->numStatics + sys->numHandlers) * 3;
+	cols = sys->numVerts * 3;
+	sys->spLapMatrix = new_spmatrix(rows, cols);
+	sys->VectorB = new_vectord(rows);
+	sys->VectorX = new_vectord(cols);
+	sys->tripletList = new_triplet(sys->numVerts*18);
+	sys->vweights = (float *)MEM_callocN(sizeof(float) * sys->numVerts, "LapVweights");
+	sys->list_uverts = (int *)MEM_callocN(sizeof(BMVert *) * sys->numVerts, "LapUverts");
+	sys->delta = (float (*)[3])MEM_callocN(sizeof(float) * sys->numVerts * 3, "LapDelta");
+	sys->list_verts = (BMVert**)MEM_callocN(sizeof(BMVert*) * sys->numVerts, "LapVerts");
+	memset(sys->vweights, 0.0 , sizeof(float) * sys->numVerts);
+	memset(sys->delta, 0.0, sizeof(float) * sys->numVerts * 3);
+	return sys;
+}
+
+static void delete_static_anchors(StaticAnchors * sa)
+{
+	if (!sa) return;
+	delete_void_pointer(sa->co);
+	delete_void_pointer(sa->list_index);
+	delete_void_pointer(sa->no);
+	delete_void_pointer(sa);
+	sa = NULL;
+}
+
+static void delete_handler_anchors(HandlerAnchors * sh)
+{
+	if (!sh) return;
+	delete_void_pointer(sh->list_handlers);
+	delete_void_pointer(sh);
+	sh = NULL;
+}
+
 static void delete_laplacian_system(LaplacianSystem *sys)
 {
-	if(!sys) return;
+	if (!sys) return;
 	delete_void_pointer(sys->vweights);
 	delete_void_pointer(sys->delta);
-	delete_void_pointer(sys->uverts);
-	if (sys->context) {
-		nlDeleteContext(sys->context);
-	}
-	if (sys->contextrot) {
-		nlDeleteContext(sys->contextrot);
-	}
-	if (sys->spLapMatrix) {
-		delete_spmatrix(sys->spLapMatrix);
-	}
-	if (sys->VectorB) {
-		delete_vectord(sys->VectorB);
-	}
-	if (sys->VectorX) {
-		delete_vectord(sys->VectorX);
-	}
-	if (sys->tripletList) {
-		delete_triplet(sys->tripletList);
-	}
+	delete_void_pointer(sys->list_uverts);
+	delete_void_pointer(sys->list_verts);
 	sys->bm = NULL;
-	sys->op = NULL;
-	MEM_freeN(sys);
+	if (sys->context) nlDeleteContext(sys->context);
+	if (sys->contextrot) nlDeleteContext(sys->contextrot);
+	delete_spmatrix(sys->spLapMatrix);
+	delete_vectord(sys->VectorB);
+	delete_vectord(sys->VectorX);
+	delete_triplet(sys->tripletList);
+	delete_void_pointer(sys);
+	sys = NULL;
 }
 
-static void memset_laplacian_system(LaplacianSystem *sys, int val)
+void MESH_OT_vertices_laplacian_deform(wmOperatorType *ot)
 {
-	memset(sys->vweights,     val, sizeof(float) * sys->numVerts);
-	memset(sys->delta,     val, sizeof(float) * sys->numVerts);
+	ot->name = "Laplacian Deform Edit Mesh tool";
+	ot->description = "Laplacian Deform Mesh tool";
+	ot->idname = "MESH_OT_vertices_laplacian_deform";
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
+	ot->invoke = laplacian_deform_invoke;
+	ot->modal = laplacian_deform_modal;
+	ot->cancel = laplacian_deform_cancel;
+	ot->poll = ED_operator_editmesh_view3d;
 }
 
-static void init_laplacian_system(LaplacianSystem * sys, int a_numVerts, int rows, int cols)
+static void update_system_state(SystemCustomData * data, int state)
 {
-	//LaplacianSystem *sys;
-	/*sys = (LaplacianSystem *)MEM_callocN(sizeof(LaplacianSystem), "bmoLaplDeformSystem");
+	if (!data) return;
+	switch(data->stateSystem) {
+		case LAP_STATE_INIT:
+			if (state == LAP_STATE_HAS_STATIC || state == LAP_STATE_HAS_HANDLER) {
+				data->stateSystem = state;
+			}
+			break;
+		case LAP_STATE_HAS_STATIC:
+			if (state == LAP_STATE_HAS_HANDLER) {
+				data->stateSystem = LAP_STATE_HAS_STATIC_AND_HANDLER;
+			}
+			break;
+		case LAP_STATE_HAS_HANDLER:
+			if (state == LAP_STATE_HAS_STATIC)  {
+				data->stateSystem = LAP_STATE_HAS_STATIC_AND_HANDLER;
+			}
+			break;
+		case LAP_STATE_HAS_STATIC_AND_HANDLER:
+			if (state == LAP_STATE_HAS_L_COMPUTE) {
+				data->stateSystem = LAP_STATE_HAS_L_COMPUTE;
+			} 
+			break;
+		case LAP_STATE_HAS_L_COMPUTE:

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list