[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58188] branches/soc-2013-sketch_mesh: Mesh Sketch based on Laplacian Deform implemented as EditMesh tool.
Alexander Pinzon
apinzonf at gmail.com
Fri Jul 12 04:37:58 CEST 2013
Revision: 58188
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58188
Author: apinzonf
Date: 2013-07-12 02:37:55 +0000 (Fri, 12 Jul 2013)
Log Message:
-----------
Mesh Sketch based on Laplacian Deform implemented as EditMesh tool.
Modified Paths:
--------------
branches/soc-2013-sketch_mesh/release/scripts/startup/bl_ui/space_view3d.py
branches/soc-2013-sketch_mesh/source/blender/editors/mesh/CMakeLists.txt
branches/soc-2013-sketch_mesh/source/blender/editors/mesh/mesh_intern.h
branches/soc-2013-sketch_mesh/source/blender/editors/mesh/mesh_ops.c
Added Paths:
-----------
branches/soc-2013-sketch_mesh/source/blender/editors/mesh/editmesh_deform_laplacian.c
branches/soc-2013-sketch_mesh/source/blender/editors/mesh/editmesh_deform_utils.cpp
branches/soc-2013-sketch_mesh/source/blender/editors/mesh/editmesh_deform_utils.h
Modified: branches/soc-2013-sketch_mesh/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- branches/soc-2013-sketch_mesh/release/scripts/startup/bl_ui/space_view3d.py 2013-07-12 01:33:42 UTC (rev 58187)
+++ branches/soc-2013-sketch_mesh/release/scripts/startup/bl_ui/space_view3d.py 2013-07-12 02:37:55 UTC (rev 58188)
@@ -1858,7 +1858,8 @@
layout.operator("mesh.flip_normals")
layout.operator("mesh.vertices_smooth", text="Smooth")
layout.operator("mesh.vertices_smooth_laplacian", text="Laplacian Smooth")
- layout.operator("mesh.vertices_deform_laplacian", text="Laplacian Deform")
+ layout.operator("mesh.vertices_deform_laplacian", text="Old Laplacian Deform")
+ layout.operator("mesh.vertices_laplacian_deform", text="Laplacian Deform")
layout.separator()
Modified: branches/soc-2013-sketch_mesh/source/blender/editors/mesh/CMakeLists.txt
===================================================================
--- branches/soc-2013-sketch_mesh/source/blender/editors/mesh/CMakeLists.txt 2013-07-12 01:33:42 UTC (rev 58187)
+++ branches/soc-2013-sketch_mesh/source/blender/editors/mesh/CMakeLists.txt 2013-07-12 02:37:55 UTC (rev 58188)
@@ -32,6 +32,8 @@
../../render/extern/include
../../windowmanager
../../../../intern/guardedalloc
+ ../../../../extern/Eigen3
+ ../../../../intern/opennl/extern
)
set(INC_SYS
@@ -42,6 +44,9 @@
editface.c
editmesh_add.c
editmesh_bevel.c
+ editmesh_deform_laplacian.c
+ editmesh_deform_utils.cpp
+ editmesh_deform_utils.h
editmesh_extrude.c
editmesh_inset.c
editmesh_knife.c
Added: 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 (rev 0)
+++ branches/soc-2013-sketch_mesh/source/blender/editors/mesh/editmesh_deform_laplacian.c 2013-07-12 02:37:55 UTC (rev 58188)
@@ -0,0 +1,1025 @@
+/*
+ * ***** 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): Alexander Pinzon
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/bmesh/operators/bmo_deform_laplacian.c
+ * \ingroup bmesh
+ *
+ * Deform Laplacian.
+ */
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "DNA_object_types.h"
+#include "UI_resources.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "mesh_intern.h" /* own include */
+
+#include "BKE_DerivedMesh.h"
+#include "BKE_context.h"
+#include "BKE_editmesh.h"
+#include "BKE_editmesh_bvh.h"
+
+#include "MEM_guardedalloc.h"
+#include "BLI_math.h"
+#include "BLI_array.h"
+#include "ONL_opennl.h"
+
+#include "editmesh_deform_utils.h"
+
+#include "ED_screen.h"
+#include "ED_space_api.h"
+#include "ED_view3d.h"
+#include "ED_mesh.h"
+
+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*/
+ /* Pointers to data*/
+ 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*/
+ vptrVectorD VectorB; /* Array to store vertex positions of handlers*/
+ vptrVectorD VectorX; /* Array to store solution */
+ vptrTripletD tripletList; /* List of triplets in Laplacian Matrix*/
+};
+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);
+
+static float cotan_weight(float *v1, float *v2, float *v3)
+{
+ float a[3], b[3], c[3], clen;
+
+ sub_v3_v3v3(a, v2, v1);
+ sub_v3_v3v3(b, v3, v1);
+ cross_v3_v3v3(c, a, b);
+
+ clen = len_v3(c);
+
+ if (clen < FLT_EPSILON)
+ return 0.0f;
+
+ return dot_v3v3(a, b) / clen;
+}
+
+static void delete_void_pointer(void *data)
+{
+ if (data) {
+ MEM_freeN(data);
+ }
+}
+
+static void delete_laplacian_system(LaplacianSystem *sys)
+{
+ 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);
+ }
+ sys->bm = NULL;
+ sys->op = NULL;
+ MEM_freeN(sys);
+}
+
+static void memset_laplacian_system(LaplacianSystem *sys, int val)
+{
+ memset(sys->vweights, val, sizeof(float) * sys->numVerts);
+ memset(sys->delta, val, sizeof(float) * sys->numVerts);
+}
+
+static void init_laplacian_system(LaplacianSystem * sys, int a_numVerts, int rows, int cols)
+{
+ //LaplacianSystem *sys;
+ /*sys = (LaplacianSystem *)MEM_callocN(sizeof(LaplacianSystem), "bmoLaplDeformSystem");
+ if (!sys) {
+ return NULL;
+ }*/
+ sys->numVerts = a_numVerts;
+
+ sys->spLapMatrix = new_spmatrix(rows, cols);
+ if (!sys->spLapMatrix) {
+ delete_laplacian_system(sys);
+ return ;
+ }
+
+ sys->VectorB = new_vectord(rows);
+ if (!sys->VectorB) {
+ delete_laplacian_system(sys);
+ return ;
+ }
+
+ sys->VectorX = new_vectord(cols);
+ if (!sys->VectorX) {
+ delete_laplacian_system(sys);
+ return ;
+ }
+
+ sys->tripletList = new_triplet(a_numVerts*18);
+ if (!sys->tripletList) {
+ delete_laplacian_system(sys);
+ return ;
+ }
+
+ sys->vweights = (float *)MEM_callocN(sizeof(float) * sys->numVerts, "bmoLaplDeformVweights");
+ if (!sys->vweights) {
+ delete_laplacian_system(sys);
+ return ;
+ }
+
+ sys->uverts = (BMVert **)MEM_callocN(sizeof(BMVert *) * sys->numVerts, "bmoLaplDeformuverts");
+ if (!sys->uverts) {
+ delete_laplacian_system(sys);
+ return ;
+ }
+
+ sys->delta = (float (*)[3])MEM_callocN(sizeof(float) * sys->numVerts * 3, "bmoLaplDeformDelta");
+ if (!sys->delta) {
+ delete_laplacian_system(sys);
+ return ;
+ }
+
+ //return sys;
+}
+
+static void init_laplacian_matrix(LaplacianSystem *sys)
+{
+ float *v1, *v2, *v3, *v4;
+ float w2, w3, w4;
+ int i, j;
+ bool has_4_vert;
+ unsigned int idv1, idv2, idv3, idv4, idv[4];
+ BMFace *f;
+ BMIter fiter;
+ BMIter vi;
+ BMVert *vn;
+ BMVert *vf[4];
+ float vfcos[4][3];
+
+ BM_ITER_MESH (f, &fiter, sys->bm, BM_FACES_OF_MESH) {
+
+
+ BM_ITER_ELEM_INDEX (vn, &vi, f, BM_VERTS_OF_FACE, i) {
+ vf[i] = vn;
+ copy_v3_v3(vfcos[i], vn->co);
+ }
+ has_4_vert = (i == 4) ? 1 : 0;
+ idv1 = BM_elem_index_get(vf[0]);
+ idv2 = BM_elem_index_get(vf[1]);
+ idv3 = BM_elem_index_get(vf[2]);
+ idv4 = has_4_vert ? BM_elem_index_get(vf[3]) : 0;
+
+ v1 = vfcos[0];// vf[0]->co;
+ v2 = vfcos[1];//vf[1]->co;
+ v3 = vfcos[2];//vf[2]->co;
+ v4 = has_4_vert ? vfcos[3] : 0;
+
+ idv[0] = idv1;
+ idv[1] = idv2;
+ idv[2] = idv3;
+ idv[3] = idv4;
+
+ nlMakeCurrent(sys->context);
+ nlRightHandSideAdd(0, idv1 , 0.0f);
+ nlRightHandSideAdd(0, sys->numVerts + idv1 , 0.0f);
+ nlRightHandSideAdd(0, 2*sys->numVerts + idv1 , 0.0f);
+
+ for (j = 0; j < i; j++) {
+ idv1 = idv[j];
+ idv2 = idv[(j + 1) % i];
+ idv3 = idv[(j + 2) % i];
+ idv4 = idv[(j + 3) % i];
+
+ v1 = vfcos[j];
+ v2 = vfcos[(j + 1) % i];
+ v3 = vfcos[(j + 2) % i];
+ v4 = has_4_vert ? vfcos[(j + 3) % i] : 0;
+
+ if (has_4_vert) {
+
+ w2 = (cotan_weight(v4, v1, v2) + cotan_weight(v3, v1, v2)) ;
+ w3 = (cotan_weight(v2, v3, v1) + cotan_weight(v4, v1, v3)) ;
+ w4 = (cotan_weight(v2, v4, v1) + cotan_weight(v3, v4, v1)) ;
+
+ sys->delta[idv1][0] -= v4[0] * w4;
+ sys->delta[idv1][1] -= v4[1] * w4;
+ sys->delta[idv1][2] -= v4[2] * w4;
+
+ nlMakeCurrent(sys->context);
+ nlMatrixAdd(idv1 , idv4 , -w4 );
+ nlMatrixAdd(sys->numVerts + idv1 , sys->numVerts + idv4 , -w4 );
+ nlMatrixAdd(sys->numVerts*2 + idv1 , sys->numVerts*2 + idv4 , -w4 );
+
+ nlMakeCurrent(sys->contextrot);
+ nlMatrixAdd(idv1 , idv4 , -w4 );
+
+ push_back_triplet(sys->tripletList, idv1 , idv4 , -w4 );
+ push_back_triplet(sys->tripletList, sys->numVerts + idv1 , sys->numVerts + idv4 , -w4 );
+ push_back_triplet(sys->tripletList, sys->numVerts*2 + idv1 , sys->numVerts*2 + idv4 , -w4 );
+
+
+ }
+ else {
+ w2 = cotan_weight(v3, v1, v2);
+ w3 = cotan_weight(v2, v3, v1);
+ w4 = 0.0f;
+ }
+
+ sys->vweights[idv1] += w2 + w3 + w4;
+
+ sys->delta[idv1][0] += v1[0] * (w2 + w3 + w4);
+ sys->delta[idv1][1] += v1[1] * (w2 + w3 + w4);
+ sys->delta[idv1][2] += v1[2] * (w2 + w3 + w4);
+
+ sys->delta[idv1][0] -= v2[0] * w2;
+ sys->delta[idv1][1] -= v2[1] * w2;
+ sys->delta[idv1][2] -= v2[2] * w2;
+
+ sys->delta[idv1][0] -= v3[0] * w3;
+ sys->delta[idv1][1] -= v3[1] * w3;
+ sys->delta[idv1][2] -= v3[2] * w3;
+
+ nlMakeCurrent(sys->context);
+ nlMatrixAdd(idv1 , idv2 , -w2);
+ nlMatrixAdd(sys->numVerts + idv1 , sys->numVerts + idv2 , -w2);
+ nlMatrixAdd(sys->numVerts*2 + idv1 , sys->numVerts*2 + idv2 , -w2);
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list