[Bf-blender-cvs] [556590f] master: Dyntopo:

Antony Riakiotakis noreply at git.blender.org
Wed Apr 16 04:31:09 CEST 2014


Commit: 556590fa3a9757f5ee21d923ce38471c343495b7
Author: Antony Riakiotakis
Date:   Wed Apr 16 05:31:02 2014 +0300
https://developer.blender.org/rB556590fa3a9757f5ee21d923ce38471c343495b7

Dyntopo:

Store PBVH node ID in CustomData. This avoids a number of hash deletions
and checks/insertions on big hashes.

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

M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/bmesh/bmesh_class.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/makesdna/DNA_customdata_types.h

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

diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 6126195..0309e7d 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1037,6 +1037,17 @@ static void layerDefault_mvert_skin(void *data, int count)
 	}
 }
 
+static void layerDefault_dyntopo_node(void *data, int count)
+{
+	int *indices = data;
+	int i;
+
+	for (i = 0; i < count; i++) {
+		indices[i] = DYNTOPO_NODE_NONE;
+	}
+}
+
+
 static void layerInterp_mvert_skin(void **sources, const float *weights,
                                    const float *UNUSED(sub_weights),
                                    int count, void *dest)
@@ -1172,6 +1183,8 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
 	{sizeof(float[4]), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
 	/* 40: CD_TESSLOOPNORMAL */
 	{sizeof(short[4][3]), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
+    /* 41: CD_DYNTOPO_NODE */
+	{sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, layerDefault_dyntopo_node},
 };
 
 /* note, numbers are from trunk and need updating for bmesh */
@@ -1188,6 +1201,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
 	/* 30-34 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol", "CDBMElemPyPtr", "CDPaintMask",
 	/* 35-36 */ "CDGridPaintMask", "CDMVertSkin",
 	/* 37-40 */ "CDFreestyleEdge", "CDFreestyleFace", "CDMLoopTangent", "CDTessLoopNormal",
+    /* 41 */ "CDDyntopoNode"
 };
 
 
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index d568d61..a0007fe 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -618,11 +618,6 @@ void BKE_pbvh_free(PBVH *bvh)
 	if (bvh->prim_indices)
 		MEM_freeN(bvh->prim_indices);
 
-	if (bvh->bm_vert_to_node)
-		BLI_ghash_free(bvh->bm_vert_to_node, NULL, NULL);
-	if (bvh->bm_face_to_node)
-		BLI_ghash_free(bvh->bm_face_to_node, NULL, NULL);
-
 	MEM_freeN(bvh);
 }
 
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 80d92f7..cca2468 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -46,7 +46,7 @@
 /****************************** Building ******************************/
 
 /* Update node data after splitting */
-static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index)
+static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index, const int cd_vert_node_offset, const int cd_face_node_offset)
 {
 	GSetIterator gs_iter;
 	PBVHNode *n = &bvh->nodes[node_index];
@@ -62,22 +62,21 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index)
 		BMLoop *l_iter;
 		BMLoop *l_first;
 		BMVert *v;
-		void *node_val = SET_INT_IN_POINTER(node_index);
 
 		/* Update ownership of faces */
-		BLI_ghash_insert(bvh->bm_face_to_node, f, node_val);
+		BM_ELEM_CD_SET_INT(f, cd_face_node_offset, node_index);
 
-		/* Update vertices */
+		        /* Update vertices */
 		l_iter = l_first = BM_FACE_FIRST_LOOP(f);
 		do {
 			v = l_iter->v;
 			if (!BLI_gset_haskey(n->bm_unique_verts, v)) {
-				if (BLI_ghash_haskey(bvh->bm_vert_to_node, v)) {
+				if (BM_ELEM_CD_GET_INT(v, cd_vert_node_offset) != DYNTOPO_NODE_NONE) {
 					BLI_gset_reinsert(n->bm_other_verts, v, NULL);
 				}
 				else {
 					BLI_gset_insert(n->bm_unique_verts, v);
-					BLI_ghash_insert(bvh->bm_vert_to_node, v, node_val);
+					BM_ELEM_CD_SET_INT(v, cd_vert_node_offset, node_index);
 				}
 			}
 			/* Update node bounding box */
@@ -97,7 +96,8 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index)
 }
 
 /* Recursively split the node if it exceeds the leaf_limit */
-static void pbvh_bmesh_node_split(PBVH *bvh, GHash *prim_bbc, int node_index)
+static void pbvh_bmesh_node_split(PBVH *bvh, GHash *prim_bbc, int node_index,
+                                  const int cd_vert_node_offset, const int cd_face_node_offset)
 {
 	GSet *empty, *other;
 	GSetIterator gs_iter;
@@ -110,7 +110,7 @@ static void pbvh_bmesh_node_split(PBVH *bvh, GHash *prim_bbc, int node_index)
 
 	if (BLI_gset_size(n->bm_faces) <= bvh->leaf_limit) {
 		/* Node limit not exceeded */
-		pbvh_bmesh_node_finalize(bvh, node_index);
+		pbvh_bmesh_node_finalize(bvh, node_index, cd_vert_node_offset, cd_face_node_offset);
 		return;
 	}
 
@@ -179,7 +179,7 @@ static void pbvh_bmesh_node_split(PBVH *bvh, GHash *prim_bbc, int node_index)
 	if (n->bm_unique_verts) {
 		GSET_ITER (gs_iter, n->bm_unique_verts) {
 			BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
-			BLI_ghash_remove(bvh->bm_vert_to_node, v, NULL, NULL);
+			BM_ELEM_CD_SET_INT(v, cd_vert_node_offset, DYNTOPO_NODE_NONE);
 		}
 		BLI_gset_free(n->bm_unique_verts, NULL);
 	}
@@ -187,7 +187,7 @@ static void pbvh_bmesh_node_split(PBVH *bvh, GHash *prim_bbc, int node_index)
 	/* Unclaim faces */
 	GSET_ITER (gs_iter, n->bm_faces) {
 		BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
-		BLI_ghash_remove(bvh->bm_face_to_node, f, NULL, NULL);
+		BM_ELEM_CD_SET_INT(f, cd_face_node_offset, DYNTOPO_NODE_NONE);
 	}
 	BLI_gset_free(n->bm_faces, NULL);
 
@@ -210,8 +210,8 @@ static void pbvh_bmesh_node_split(PBVH *bvh, GHash *prim_bbc, int node_index)
 	
 	/* Recurse */
 	c1 = c2 = NULL;
-	pbvh_bmesh_node_split(bvh, prim_bbc, children);
-	pbvh_bmesh_node_split(bvh, prim_bbc, children + 1);
+	pbvh_bmesh_node_split(bvh, prim_bbc, children, cd_vert_node_offset, cd_face_node_offset);
+	pbvh_bmesh_node_split(bvh, prim_bbc, children + 1, cd_vert_node_offset, cd_face_node_offset);
 
 	/* Array maybe reallocated, update current node pointer */
 	n = &bvh->nodes[node_index];
@@ -224,7 +224,7 @@ static void pbvh_bmesh_node_split(PBVH *bvh, GHash *prim_bbc, int node_index)
 }
 
 /* Recursively split the node if it exceeds the leaf_limit */
-static bool pbvh_bmesh_node_limit_ensure(PBVH *bvh, int node_index)
+static bool pbvh_bmesh_node_limit_ensure(PBVH *bvh, int node_index, const int cd_vert_node_offset, const int cd_face_node_offset)
 {
 	GHash *prim_bbc;
 	GSet *bm_faces;
@@ -260,7 +260,7 @@ static bool pbvh_bmesh_node_limit_ensure(PBVH *bvh, int node_index)
 		BLI_ghash_insert(prim_bbc, f, bbc);
 	}
 
-	pbvh_bmesh_node_split(bvh, prim_bbc, node_index);
+	pbvh_bmesh_node_split(bvh, prim_bbc, node_index, cd_vert_node_offset, cd_face_node_offset);
 
 	BLI_ghash_free(prim_bbc, NULL, NULL);
 	MEM_freeN(bbc_array);
@@ -270,13 +270,12 @@ static bool pbvh_bmesh_node_limit_ensure(PBVH *bvh, int node_index)
 
 /**********************************************************************/
 
-static PBVHNode *pbvh_bmesh_node_lookup(PBVH *bvh, GHash *map, void *key)
+static PBVHNode *pbvh_bmesh_node_lookup(PBVH *bvh, void *key, const int cd_node_offset)
 {
-	int node_index;
+	int node_index = BM_ELEM_CD_GET_INT((BMElem *)key, cd_node_offset);
 
-	BLI_assert(BLI_ghash_haskey(map, key));
+	BLI_assert(node_index != DYNTOPO_NODE_NONE);
 
-	node_index = GET_INT_FROM_POINTER(BLI_ghash_lookup(map, key));
 	BLI_assert(node_index < bvh->totnode);
 
 	return &bvh->nodes[node_index];
@@ -285,16 +284,16 @@ static PBVHNode *pbvh_bmesh_node_lookup(PBVH *bvh, GHash *map, void *key)
 static BMVert *pbvh_bmesh_vert_create(PBVH *bvh, int node_index,
                                       const float co[3],
                                       const BMVert *example,
-                                      const int cd_vert_mask_offset)
+                                      const int cd_vert_mask_offset,
+                                      const int cd_vert_node_offset)
 {
 	BMVert *v = BM_vert_create(bvh->bm, co, example, BM_CREATE_NOP);
-	void *val = SET_INT_IN_POINTER(node_index);
 	PBVHNode *node = &bvh->nodes[node_index];
 
 	BLI_assert((bvh->totnode == 1 || node_index) && node_index <= bvh->totnode);
 
 	BLI_gset_insert(node->bm_unique_verts, v);
-	BLI_ghash_insert(bvh->bm_vert_to_node, v, val);
+	BM_ELEM_CD_SET_INT(v, cd_vert_node_offset, node_index);
 
 	node->flag |= PBVH_UpdateDrawBuffers | PBVH_UpdateBB;
 
@@ -306,10 +305,9 @@ static BMVert *pbvh_bmesh_vert_create(PBVH *bvh, int node_index,
 
 static BMFace *pbvh_bmesh_face_create(PBVH *bvh, int node_index,
                                       BMVert *v_tri[3], BMEdge *e_tri[3],
-                                      const BMFace *f_example)
+                                      const BMFace *f_example, const int cd_face_node_offset)
 {
 	BMFace *f;
-	void *val = SET_INT_IN_POINTER(node_index);
 	PBVHNode *node = &bvh->nodes[node_index];
 
 	/* ensure we never add existing face */
@@ -318,25 +316,21 @@ static BMFace *pbvh_bmesh_face_create(PBVH *bvh, int node_index,
 	f = BM_face_create(bvh->bm, v_tri, e_tri, 3, f_example, BM_CREATE_NOP);
 	f->head.hflag = f_example->head.hflag;
 
-	BLI_assert(!BLI_ghash_haskey(bvh->bm_face_to_node, f));
+	BLI_gset_insert(node->bm_faces, f);
+	BM_ELEM_CD_SET_INT(f, cd_face_node_offset, node_index);
 
-	{
-		BLI_gset_insert(node->bm_faces, f);
-		BLI_ghash_insert(bvh->bm_face_to_node, f, val);
-
-		/* mark node for update */
-		node->flag |= PBVH_UpdateDrawBuffers | PBVH_UpdateNormals;
-		node->flag &= ~PBVH_FullyHidden;
+	/* mark node for update */
+	node->flag |= PBVH_UpdateDrawBuffers | PBVH_UpdateNormals;
+	node->flag &= ~PBVH_FullyHidden;
 
-		/* Log the new face */
-		BM_log_face_added(bvh->bm_log, f);
-	}
+	/* Log the new face */
+	BM_log_face_added(bvh->bm_log, f);
 
 	return f;
 }
 
 /* Return the number of faces in 'node' that use vertex 'v' */
-static int pbvh_bmesh_node_vert_use_count(PBVH *bvh, PBVHNode *node, BMVert *v)
+static int pbvh_bmesh_node_vert_use_count(PBVH *bvh, PBVHNode *node, BMVert *v, const int cd_face_node_offset)
 {
 	BMIter bm_iter;
 	BMFace *f;
@@ -345,7 +339,7 @@ static int pbvh_bmesh_node_vert_use_count(PBVH *bvh, PBVHNode *node, BMVert *v)
 	BM_ITER_ELEM (f, &bm_iter, v, BM_FACES_OF_VERT) {
 		PBVHNode *f_node;
 
-		f_node = pbvh_bmesh_node_lookup(bvh, bvh->bm_face_to_node, f);
+		f_node = pbvh_bmesh_node_lookup(bvh, f, cd_face_node_offset);
 
 		if (f_node == node)
 			count++;
@@ -355,18 +349,20 @@ static int pbvh_bmesh_node_vert_use_count(PBVH *bvh, PBVHNode *node, BMVert *v)
 }
 
 /* Return a node that uses vertex 'v' other than its current owner */
-s

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list