[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47978] branches/soc-2012-sushi: I implemented Laplacian smoothing as a modifier.

Alexander Pinzon apinzonf at gmail.com
Fri Jun 15 23:48:10 CEST 2012


Revision: 47978
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47978
Author:   apinzonf
Date:     2012-06-15 21:48:08 +0000 (Fri, 15 Jun 2012)
Log Message:
-----------
I implemented Laplacian smoothing as a modifier.

Modified Paths:
--------------
    branches/soc-2012-sushi/release/scripts/startup/bl_ui/properties_data_modifier.py
    branches/soc-2012-sushi/source/blender/bmesh/SConscript
    branches/soc-2012-sushi/source/blender/makesdna/DNA_modifier_types.h
    branches/soc-2012-sushi/source/blender/makesrna/intern/rna_modifier.c
    branches/soc-2012-sushi/source/blender/modifiers/CMakeLists.txt
    branches/soc-2012-sushi/source/blender/modifiers/SConscript
    branches/soc-2012-sushi/source/blender/modifiers/intern/MOD_laplaciansmooth.c

Modified: branches/soc-2012-sushi/release/scripts/startup/bl_ui/properties_data_modifier.py
===================================================================
--- branches/soc-2012-sushi/release/scripts/startup/bl_ui/properties_data_modifier.py	2012-06-15 21:19:05 UTC (rev 47977)
+++ branches/soc-2012-sushi/release/scripts/startup/bl_ui/properties_data_modifier.py	2012-06-15 21:48:08 UTC (rev 47978)
@@ -317,8 +317,10 @@
         col.prop(md, "use_z")
 
         col = split.column()
-        col.prop(md, "factor")
         col.prop(md, "iterations")
+        col.prop(md, "lamb")
+        col.prop(md, "lambdaborder")
+        col.prop(md, "minarea")
         col.label(text="Vertex Group:")
         col.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
 

Modified: branches/soc-2012-sushi/source/blender/bmesh/SConscript
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/SConscript	2012-06-15 21:19:05 UTC (rev 47977)
+++ branches/soc-2012-sushi/source/blender/bmesh/SConscript	2012-06-15 21:48:08 UTC (rev 47978)
@@ -13,6 +13,7 @@
 	'../makesdna',
 	'../blenkernel',
 	'#/intern/guardedalloc',
+	'#/intern/opennl/extern',
 	]
 
 defs = []

Modified: branches/soc-2012-sushi/source/blender/makesdna/DNA_modifier_types.h
===================================================================
--- branches/soc-2012-sushi/source/blender/makesdna/DNA_modifier_types.h	2012-06-15 21:19:05 UTC (rev 47977)
+++ branches/soc-2012-sushi/source/blender/makesdna/DNA_modifier_types.h	2012-06-15 21:48:08 UTC (rev 47978)
@@ -1073,7 +1073,7 @@
 
 typedef struct LaplacianSmoothModifierData {
 	ModifierData modifier;
-	float fac;
+	float lambda, lambda_border, min_area;
 	char defgrp_name[64];	/* MAX_VGROUP_NAME */
 	short flag, repeat;
 

Modified: branches/soc-2012-sushi/source/blender/makesrna/intern/rna_modifier.c
===================================================================
--- branches/soc-2012-sushi/source/blender/makesrna/intern/rna_modifier.c	2012-06-15 21:19:05 UTC (rev 47977)
+++ branches/soc-2012-sushi/source/blender/makesrna/intern/rna_modifier.c	2012-06-15 21:48:08 UTC (rev 47978)
@@ -1761,16 +1761,30 @@
 	RNA_def_property_ui_text(prop, "Z", "Smooth object along Z axis");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
-	prop = RNA_def_property(srna, "factor", PROP_FLOAT, PROP_NONE);
-	RNA_def_property_float_sdna(prop, NULL, "fac");
+	prop = RNA_def_property(srna, "lamb", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "lambda");
 	RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
-	RNA_def_property_ui_range(prop, -10, 10, 1, 3);
-	RNA_def_property_ui_text(prop, "Factor", "Strength of modifier effect");
+	RNA_def_property_ui_range(prop, 0.0000001, 100.0, 0.0000001, 8);
+	RNA_def_property_ui_text(prop, "Lambda Factor", "Smooth factor effect");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "lambdaborder", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "lambda_border");
+	RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0000001, 100.0, 0.0000001, 8);
+	RNA_def_property_ui_text(prop, "Lambda border", "Lambda factor in border");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "minarea", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "min_area");
+	RNA_def_property_range(prop, 0.0000000000000001, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0000000000000001, 100.0, 0.0000001, 18);
+	RNA_def_property_ui_text(prop, "Minimum area", "Minimum area permitted");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	prop = RNA_def_property(srna, "iterations", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "repeat");
-	RNA_def_property_ui_range(prop, 0, 30, 1, 0);
+	RNA_def_property_ui_range(prop, 0, 50, 1, 0);
 	RNA_def_property_ui_text(prop, "Repeat", "");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 	

Modified: branches/soc-2012-sushi/source/blender/modifiers/CMakeLists.txt
===================================================================
--- branches/soc-2012-sushi/source/blender/modifiers/CMakeLists.txt	2012-06-15 21:19:05 UTC (rev 47977)
+++ branches/soc-2012-sushi/source/blender/modifiers/CMakeLists.txt	2012-06-15 21:48:08 UTC (rev 47978)
@@ -38,6 +38,7 @@
 	../render/extern/include
 	../../../intern/elbeem/extern
 	../../../intern/guardedalloc
+	../../../intern/opennl/extern
 )
 
 set(INC_SYS

Modified: branches/soc-2012-sushi/source/blender/modifiers/SConscript
===================================================================
--- branches/soc-2012-sushi/source/blender/modifiers/SConscript	2012-06-15 21:19:05 UTC (rev 47977)
+++ branches/soc-2012-sushi/source/blender/modifiers/SConscript	2012-06-15 21:48:08 UTC (rev 47978)
@@ -4,7 +4,7 @@
 sources = env.Glob('intern/*.c')
 
 incs = '. ./intern'
-incs += ' #/intern/guardedalloc #/intern/decimation/extern #/intern/bsp/extern #/intern/elbeem/extern #/extern/glew/include'
+incs += ' #/intern/guardedalloc #/intern/decimation/extern #/intern/bsp/extern #/intern/elbeem/extern #/extern/glew/include #/intern/opennl/extern'
 incs += ' ../render/extern/include ../blenloader ../bmesh'
 incs += ' ../include ../blenlib ../blenfont ../makesdna ../makesrna ../blenkernel ../blenkernel/intern'
 incs += ' ../gpu'

Modified: branches/soc-2012-sushi/source/blender/modifiers/intern/MOD_laplaciansmooth.c
===================================================================
--- branches/soc-2012-sushi/source/blender/modifiers/intern/MOD_laplaciansmooth.c	2012-06-15 21:19:05 UTC (rev 47977)
+++ branches/soc-2012-sushi/source/blender/modifiers/intern/MOD_laplaciansmooth.c	2012-06-15 21:48:08 UTC (rev 47978)
@@ -35,6 +35,7 @@
 
 
 #include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
@@ -43,18 +44,148 @@
 #include "MEM_guardedalloc.h"
 
 #include "BKE_cdderivedmesh.h"
+#include "BKE_deform.h"
+#include "BKE_displist.h"
+#include "BKE_mesh.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
 #include "BKE_particle.h"
-#include "BKE_deform.h"
+#include "BKE_tessmesh.h"
 
 #include "MOD_modifiertypes.h"
 #include "MOD_util.h"
 
+#include "ONL_opennl.h"
 
+struct BModLaplacianSystem {
+	float *eweights;		/* Length weights per Edge */
+	float (*fweights)[3];   /* Cotangent weights per face */
+	float *ring_areas;		/* Total area per ring*/
+	float *vlengths;		/* Total sum of lengths(edges) per vertice*/
+	float *vweights;		/* Total sum of weights per vertice*/
+	int numEdges;			/* Number of edges*/
+	int numFaces;			/* Number of faces*/
+	int numVerts;			/* Number of verts*/
+	short *numNeFa;			/* Number of neighboors faces around vertice*/
+	short *numNeEd;			/* Number of neighboors Edges around vertice*/
+	short *zerola;			/* Is zero area or length*/
+	
+	NLContext *context;
+};
+typedef struct BModLaplacianSystem ModLaplacianSystem;
+
+static float compute_volume(float (*vertexCos)[3], MFace *mfaces, int numFaces);
+static float cotan_weight(float *v1, float *v2, float *v3);
+static int isDisabled(ModifierData *md, int UNUSED(useRenderParams));
+static void copyData(ModifierData *md, ModifierData *target);
+static void delete_ModLaplacianSystem(ModLaplacianSystem * sys);
+static void delete_void_MLS(void * data);
+static void initData(ModifierData *md);
+static void memset_ModLaplacianSystem(ModLaplacianSystem *sys, int val);
+static void volume_preservation(float (*vertexCos)[3], int numVerts, float vini, float vend, short flag);
+static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md);
+static ModLaplacianSystem * init_ModLaplacianSystem( int a_numEdges, int a_numFaces, int a_numVerts);
+
+static void delete_void_MLS(void * data)
+{
+	if (data) {
+		MEM_freeN(data);
+		data = NULL;
+	}
+}
+
+static void delete_ModLaplacianSystem(ModLaplacianSystem * sys) 
+{
+	delete_void_MLS(sys->eweights);
+	delete_void_MLS(sys->fweights);
+	delete_void_MLS(sys->numNeEd);
+	delete_void_MLS(sys->numNeFa);
+	delete_void_MLS(sys->ring_areas);
+	delete_void_MLS(sys->vlengths);
+	delete_void_MLS(sys->vweights);
+	delete_void_MLS(sys->zerola);
+	if (sys->context) {
+		nlDeleteContext(sys->context);
+	}
+	MEM_freeN(sys);
+}
+
+static void memset_ModLaplacianSystem(ModLaplacianSystem *sys, int val)
+{
+	memset(sys->eweights	, val, sizeof(float) * sys->numEdges);
+	memset(sys->fweights	, val, sizeof(float) * sys->numFaces * 3);
+	memset(sys->numNeEd		, val, sizeof(short) * sys->numVerts);
+	memset(sys->numNeFa		, val, sizeof(short) * sys->numVerts);
+	memset(sys->ring_areas	, val, sizeof(float) * sys->numVerts);
+	memset(sys->vlengths	, val, sizeof(float) * sys->numVerts);
+	memset(sys->vweights	, val, sizeof(float) * sys->numVerts);
+	memset(sys->zerola		, val, sizeof(short) * sys->numVerts);
+}
+
+static ModLaplacianSystem * init_ModLaplacianSystem( int a_numEdges, int a_numFaces, int a_numVerts) {
+	ModLaplacianSystem * sys; 
+	sys = MEM_callocN(sizeof(ModLaplacianSystem), "ModLaplSmoothSystem");
+	sys->numEdges = a_numEdges;
+	sys->numFaces = a_numFaces;
+	sys->numVerts = a_numVerts;
+
+	sys->eweights =  MEM_callocN(sizeof(float) * sys->numEdges, "ModLaplSmoothEWeight");
+	if (!sys->eweights) {
+		delete_ModLaplacianSystem(sys);
+		return NULL;
+	}
+	
+	sys->fweights =  MEM_callocN(sizeof(float) * 3 * sys->numFaces, "ModLaplSmoothFWeight");
+	if (!sys->fweights) {
+		delete_ModLaplacianSystem(sys);
+		return NULL;
+	}
+
+	sys->numNeEd =  MEM_callocN(sizeof(short) * sys->numVerts, "ModLaplSmoothNumNeEd");
+	if (!sys->numNeEd) {
+		delete_ModLaplacianSystem(sys);
+		return NULL;
+	}
+	
+	sys->numNeFa =  MEM_callocN(sizeof(short) * sys->numVerts, "ModLaplSmoothNumNeFa");
+	if (!sys->numNeFa) {
+		delete_ModLaplacianSystem(sys);
+		return NULL;
+	}
+	
+	sys->ring_areas =  MEM_callocN(sizeof(float) * sys->numVerts, "ModLaplSmoothRingAreas");
+	if (!sys->ring_areas) {
+		delete_ModLaplacianSystem(sys);
+		return NULL;
+	}
+	
+	sys->vlengths =  MEM_callocN(sizeof(float) * sys->numVerts, "ModLaplSmoothVlengths");
+	if (!sys->vlengths) {
+		delete_ModLaplacianSystem(sys);
+		return NULL;
+	}
+
+	sys->vweights =  MEM_callocN(sizeof(float) * sys->numVerts, "ModLaplSmoothVweights");
+	if (!sys->vweights) {
+		delete_ModLaplacianSystem(sys);
+		return NULL;
+	}
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list