[Bf-blender-cvs] [308b016] soc-2014-remesh: Initial version, to create a Scalar Field U. The tool is implement as a Modifier. The features points are define with vertex groups.

Alexander Pinzon Fernandez noreply at git.blender.org
Fri Jun 6 21:04:13 CEST 2014


Commit: 308b016251304c0f290da6f1e9e0dd7b9ff3b9da
Author: Alexander Pinzon Fernandez
Date:   Fri Jun 6 14:02:24 2014 -0500
https://developer.blender.org/rB308b016251304c0f290da6f1e9e0dd7b9ff3b9da

Initial version, to create a Scalar Field U.
The tool is implement as a Modifier.
The features points are define with vertex groups.

===================================================================

M	source/blender/modifiers/intern/MOD_quadremesh.c

===================================================================

diff --git a/source/blender/modifiers/intern/MOD_quadremesh.c b/source/blender/modifiers/intern/MOD_quadremesh.c
index 6db50d2..edbb4b4 100644
--- a/source/blender/modifiers/intern/MOD_quadremesh.c
+++ b/source/blender/modifiers/intern/MOD_quadremesh.c
@@ -52,12 +52,12 @@ typedef struct LaplacianSystem {
 	int total_faces;
 	int total_features;
 	char features_grp_name[64];	/* Vertex Group name */
-	int *index_features;		/* Static vertex index list */
-	int *ringf_indices;			/* Indices of faces per vertex */
-	int *ringv_indices;			/* Indices of neighbors(vertex) per vertex */
+	float(*co)[3];				/* Original vertex coordinates */
+	int *constraints;			/* Feature points constraints*/
+	float *weights;				/* Feature points weights*/
+	float *U_field;				/* Initial scalar field*/
+	unsigned int(*faces)[4];	/* Copy of MFace (tessface) v1-v4 */
 	NLContext *context;			/* System for solve general implicit rotations */
-	MeshElemMap *ringf_map;		/* Map of faces per vertex */
-	MeshElemMap *ringv_map;		/* Map of vertex per vertex */
 } LaplacianSystem;
 
 static LaplacianSystem *newLaplacianSystem(void)
@@ -88,301 +88,311 @@ static LaplacianSystem *initLaplacianSystem(int totalVerts, int totalEdges, int
 	sys->total_faces = totalFaces;
 	sys->total_features = totalFeatures;
 	BLI_strncpy(sys->features_grp_name, defgrpName, sizeof(sys->features_grp_name));
-	sys->index_features = MEM_mallocN(sizeof(int)* (totalFeatures), "QuadRemeshFeatures");
+	sys->faces = MEM_mallocN(sizeof(int[4]) * totalFaces, "QuadRemeshFaces");
+	sys->co = MEM_mallocN(sizeof(float[3]) * totalVerts, "QuadRemeshCoordinates");
+	sys->constraints = MEM_mallocN(sizeof(int) * totalVerts, "QuadRemeshConstraints");
+	sys->weights = MEM_mallocN(sizeof(float)* (totalVerts), "QuadRemeshWeights");
+	sys->U_field = MEM_mallocN(sizeof(float)* (totalVerts), "QuadRemeshUField");
 	return sys;
 }
 
 static void deleteLaplacianSystem(LaplacianSystem *sys)
 {
-	MEM_SAFE_FREE(sys->index_features);
-	MEM_SAFE_FREE(sys->ringf_indices);
-	MEM_SAFE_FREE(sys->ringv_indices);
-	MEM_SAFE_FREE(sys->ringf_map);
-	MEM_SAFE_FREE(sys->ringv_map);
-
+	MEM_SAFE_FREE(sys->faces);
+	MEM_SAFE_FREE(sys->co);
+	MEM_SAFE_FREE(sys->constraints);
+	MEM_SAFE_FREE(sys->weights);
+	MEM_SAFE_FREE(sys->U_field);
 	if (sys->context) {
 		nlDeleteContext(sys->context);
 	}
 	MEM_SAFE_FREE(sys);
 }
 
-static void createFaceRingMap(
-        const int mvert_tot, const MFace *mface, const int mface_tot,
-        MeshElemMap **r_map, int **r_indices)
+
+
+static void initLaplacianMatrix(LaplacianSystem *sys)
 {
-	int i, j, totalr = 0;
-	int *indices, *index_iter;
-	MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * mvert_tot, "DeformRingMap");
-	const MFace *mf;
+	float v1[3], v2[3], v3[3], v4[3], no[3];
+	float w2, w3, w4;
+	int i, j, fi;
+	bool has_4_vert;
+	unsigned int idv1, idv2, idv3, idv4;
+
+	printf("initLaplacianMatrix 0 \n");
+
+	for (fi = 0; fi < sys->total_faces; fi++) {
+		const unsigned int *vidf = sys->faces[fi];
+
+		idv1 = vidf[0];
+		idv2 = vidf[1];
+		idv3 = vidf[2];
+		idv4 = vidf[3];
+
+		has_4_vert = vidf[3] ? 1 : 0;
+		i = has_4_vert ? 4 : 3;
+		for (j = 0; j < i; j++) {
+
+			idv1 = vidf[j];
+			idv2 = vidf[(j + 1) % i];
+			idv3 = vidf[(j + 2) % i];
+			idv4 = has_4_vert ? vidf[(j + 3) % i] : 0;
+
+			copy_v3_v3(v1, sys->co[idv1]);
+			copy_v3_v3(v2, sys->co[idv2]);
+			copy_v3_v3(v3, sys->co[idv3]);
+			if (has_4_vert) {
+				copy_v3_v3(v4, sys->co[idv4]);
+			}
 
-	for (i = 0, mf = mface; i < mface_tot; i++, mf++) {
-		bool has_4_vert;
+			if (has_4_vert) {
 
-		has_4_vert = mf->v4 ? 1 : 0;
+				w2 = (cotangent_tri_weight_v3(v4, v1, v2) + cotangent_tri_weight_v3(v3, v1, v2)) / 2.0f;
+				w3 = (cotangent_tri_weight_v3(v2, v3, v1) + cotangent_tri_weight_v3(v4, v1, v3)) / 2.0f;
+				w4 = (cotangent_tri_weight_v3(v2, v4, v1) + cotangent_tri_weight_v3(v3, v4, v1)) / 2.0f;
 
-		for (j = 0; j < (has_4_vert ? 4 : 3); j++) {
-			const unsigned int v_index = (*(&mf->v1 + j));
-			map[v_index].count++;
-			totalr++;
-		}
-	}
-	indices = MEM_callocN(sizeof(int) * totalr, "DeformRingIndex");
-	index_iter = indices;
-	for (i = 0; i < mvert_tot; i++) {
-		map[i].indices = index_iter;
-		index_iter += map[i].count;
-		map[i].count = 0;
-	}
-	for (i = 0, mf = mface; i < mface_tot; i++, mf++) {
-		bool has_4_vert;
+				if (sys->constraints[idv1] == 0) {
+					nlMatrixAdd(idv1, idv4, -w4);
+				}
+			}
+			else {
+				w2 = cotangent_tri_weight_v3(v3, v1, v2);
+				w3 = cotangent_tri_weight_v3(v2, v3, v1);
+				w4 = 0.0f;
+			}
 
-		has_4_vert = mf->v4 ? 1 : 0;
+			if (sys->constraints[idv1] == 1) {
+				nlMatrixAdd(idv1, idv1, w2 + w3 + w4);
+			}
+			else  {
+				nlMatrixAdd(idv1, idv2, -w2);
+				nlMatrixAdd(idv1, idv3, -w3);
+				nlMatrixAdd(idv1, idv1, w2 + w3 + w4);
+			}
 
-		for (j = 0; j < (has_4_vert ? 4 : 3); j++) {
-			const unsigned int v_index = (*(&mf->v1 + j));
-			map[v_index].indices[map[v_index].count] = i;
-			map[v_index].count++;
 		}
 	}
-	*r_map = map;
-	*r_indices = indices;
+	printf("initLaplacianMatrix 1 \n");
+	
 }
 
-static void createVertRingMap(
-        const int mvert_tot, const MEdge *medge, const int medge_tot,
-        MeshElemMap **r_map, int **r_indices)
+static void laplacianDeformPreview(LaplacianSystem *sys)
 {
-	MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * mvert_tot, "DeformNeighborsMap");
-	int i, vid[2], totalr = 0;
-	int *indices, *index_iter;
-	const MEdge *me;
-
-	for (i = 0, me = medge; i < medge_tot; i++, me++) {
-		vid[0] = me->v1;
-		vid[1] = me->v2;
-		map[vid[0]].count++;
-		map[vid[1]].count++;
-		totalr += 2;
+	int vid, i, j, n, na;
+	if (sys) {
+		printf("laplacianDeformPreview NOT NULL\n");
+	} 
+	else {
+		printf("laplacianDeformPreview NULL \n");
 	}
-	indices = MEM_callocN(sizeof(int) * totalr, "DeformNeighborsIndex");
-	index_iter = indices;
-	for (i = 0; i < mvert_tot; i++) {
-		map[i].indices = index_iter;
-		index_iter += map[i].count;
-		map[i].count = 0;
+	printf("laplacianDeformPreview -4\n");
+	printf("sys->total_verts test\n");
+	if (sys->total_verts) {
+		printf("sys->total_verts NOT NULL\n");
 	}
-	for (i = 0, me = medge; i < medge_tot; i++, me++) {
-		vid[0] = me->v1;
-		vid[1] = me->v2;
-		map[vid[0]].indices[map[vid[0]].count] = vid[1];
-		map[vid[0]].count++;
-		map[vid[1]].indices[map[vid[1]].count] = vid[0];
-		map[vid[1]].count++;
+	else {
+		printf("sys->total_verts NULL\n");
 	}
-	*r_map = map;
-	*r_indices = indices;
-}
 
-static void initLaplacianMatrix(LaplacianSystem *sys)
-{
+
+	printf("%f,  %f", sys->total_verts, sys->total_features);
 	
-}
 
-static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
-{
-	int vid, i, j, n, na;
+
 	n = sys->total_verts;
 	na = sys->total_features;
 
+	printf("laplacianDeformPreview -3\n");
+
 #ifdef OPENNL_THREADING_HACK
+	printf("laplacianDeformPreview -2\n");
 	modifier_opennl_lock();
+	printf("laplacianDeformPreview -1\n");
 #endif
 
-	/*if (!sys->is_matrix_computed) {
+	printf("laplacianDeformPreview 0\n");
+	if (!sys->is_matrix_computed) {
+		printf("laplacianDeformPreview 1\n");
 		nlNewContext();
 		sys->context = nlGetCurrent();
 
 		nlSolverParameteri(NL_NB_VARIABLES, n);
 		nlSolverParameteri(NL_SYMMETRIC, NL_FALSE);
 		nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE);
-		nlSolverParameteri(NL_NB_ROWS, n + na);
-		nlSolverParameteri(NL_NB_RIGHT_HAND_SIDES, 3);
+		nlSolverParameteri(NL_NB_ROWS, n);
+		nlSolverParameteri(NL_NB_RIGHT_HAND_SIDES, 1);
 		nlBegin(NL_SYSTEM);
+		printf("laplacianDeformPreview 2\n");
 		for (i = 0; i < n; i++) {
-			nlSetVariable(0, i, sys->co[i][0]);
-			nlSetVariable(1, i, sys->co[i][1]);
-			nlSetVariable(2, i, sys->co[i][2]);
-		}
-		for (i = 0; i < na; i++) {
-			vid = sys->index_anchors[i];
-			nlSetVariable(0, vid, vertexCos[vid][0]);
-			nlSetVariable(1, vid, vertexCos[vid][1]);
-			nlSetVariable(2, vid, vertexCos[vid][2]);
+			nlSetVariable(0, i, 0);
 		}
+		
+		printf("laplacianDeformPreview 3\n");
 		nlBegin(NL_MATRIX);
 
 		initLaplacianMatrix(sys);
-		computeImplictRotations(sys);
+		printf("laplacianDeformPreview 4\n");
 
 		for (i = 0; i < n; i++) {
-			nlRightHandSideSet(0, i, sys->delta[i][0]);
-			nlRightHandSideSet(1, i, sys->delta[i][1]);
-			nlRightHandSideSet(2, i, sys->delta[i][2]);
-		}
-		for (i = 0; i < na; i++) {
-			vid = sys->index_anchors[i];
-			nlRightHandSideSet(0, n + i, vertexCos[vid][0]);
-			nlRightHandSideSet(1, n + i, vertexCos[vid][1]);
-			nlRightHandSideSet(2, n + i, vertexCos[vid][2]);
-			nlMatrixAdd(n + i, vid, 1.0f);
-		}
-		nlEnd(NL_MATRIX);
-		nlEnd(NL_SYSTEM);
-		if (nlSolveAdvanced(NULL, NL_TRUE)) {
-			sys->has_solution = true;
-
-			for (j = 1; j <= sys->repeat; j++) {
-				nlBegin(NL_SYSTEM);
-				nlBegin(NL_MATRIX);
-				rotateDifferentialCoordinates(sys);
-
-				for (i = 0; i < na; i++) {
-					vid = sys->index_anchors[i];
-					nlRightHandSideSet(0, n + i, vertexCos[vid][0]);
-					nlRightHandSideSet(1, n + i, vertexCos[vid][1]);
-					nlRightHandSideSet(2, n + i, vertexCos[vid][2]);
-				}
-
-				nlEnd(NL_MATRIX);
-				nlEnd(NL_SYSTEM);
-				if (!nlSolveAdvanced(NULL, NL_FALSE)) {
-					sys->has_solution = false;
-					break;
-				}
-			}
-			if (sys->has_solution) {
-				for (vid = 0; vid < sys->total_verts; vid++) {
-					vertexCos[vid][0] = nlGetVariable(0, vid);
-					vertexCos[vid][1] = nlGetVariable(1, vid);
-					vertexCos[vid][2] = nlGetVariable(2, vid);
-				}
+			if (sys->constraints[i] == 1) {
+				//printf("i: %d, w:%f \n", i, sys->weights[i]);
+				nlRightHandSideSet(0, i, sys->weights[i]);
 			}
 			else {
-				sys->has_solution = false;
+				nlRightHandSideSet(0, i, 0);
 			}
-
-		}
-		else {
-			sys->has_solution = false;
-		}
-		sys->is_matrix_computed = true;
-
-	}
-	else if (sys->has_solution) {
-		nlMakeCurrent(sys->context);
-
-		nlBegin(NL_SYSTEM);
-		nlBegin(NL_MATRIX);
-
-		for (i = 0; i < n; i++) {
-			nlRightHandSideSet(0, i, sys->delta[i][0]);
-			nlRightHandSideSet(1, i, sys->delta[i][1]);
-			nlRightHandSideSet(2, i, sys->delta[i][2]);
 		}
-		for (i = 0; i < na; i++) {
-			vid = sys->index_anchors[i];
-			nlRightHandSideSet(0, n + i, vertexCos[vid][0]);
-			nlRightHandSideSet(1, n + i, vertexCos[vid][1]);
-			nlRightHandSideSet(2, n + i, vertexCos[vid][2]);
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list