[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56121] trunk/blender/source/blender/ blenkernel/intern/editmesh_bvh.c: bmbvh was allocating an array for vert coords but not using it, removed.

Campbell Barton ideasman42 at gmail.com
Thu Apr 18 02:24:44 CEST 2013


Revision: 56121
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56121
Author:   campbellbarton
Date:     2013-04-18 00:24:44 +0000 (Thu, 18 Apr 2013)
Log Message:
-----------
bmbvh was allocating an array for vert coords but not using it, removed.
also use generic name for callback data.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/editmesh_bvh.c

Modified: trunk/blender/source/blender/blenkernel/intern/editmesh_bvh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/editmesh_bvh.c	2013-04-18 00:19:57 UTC (rev 56120)
+++ trunk/blender/source/blender/blenkernel/intern/editmesh_bvh.c	2013-04-18 00:24:44 UTC (rev 56121)
@@ -48,7 +48,7 @@
 	BMEditMesh *em;
 	BMesh *bm;
 
-	float (*cos_cage)[3], (*cos)[3];
+	float (*cos_cage)[3];
 	int flag;
 };
 
@@ -115,18 +115,8 @@
 	
 	if (flag & BMBVH_USE_CAGE) {
 		BLI_bitmap vert_bitmap;
-		BMIter iter;
-		BMVert *v;
 		struct CageUserData data;
 
-		bmtree->cos = MEM_callocN(sizeof(*bmtree->cos) * em->bm->totvert, "bmbvh cos");
-		BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, i) {
-			BM_elem_index_set(v, i); /* set_inline */
-			copy_v3_v3(bmtree->cos[i], v->co);
-		}
-		em->bm->elem_index_dirty &= ~BM_VERT;
-
-
 		cage = editbmesh_get_derived_cage_and_final(scene, em->ob, em, &final, CD_MASK_DERIVEDMESH);
 		cos_cage = MEM_callocN(sizeof(float) * 3 * em->bm->totvert, "bmbvh cos_cage");
 		
@@ -185,8 +175,6 @@
 	
 	if (bmtree->cos_cage)
 		MEM_freeN(bmtree->cos_cage);
-	if (bmtree->cos)
-		MEM_freeN(bmtree->cos);
 	
 	MEM_freeN(bmtree);
 }
@@ -236,12 +224,12 @@
 
 static void bmbvh_ray_cast_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
-	struct RayCastUserData *bmcast_data = userdata;
-	const BMLoop **ltri = bmcast_data->looptris[index];
+	struct RayCastUserData *bmcb_data = userdata;
+	const BMLoop **ltri = bmcb_data->looptris[index];
 	float dist, uv[2];
 	const float *tri_cos[3];
 
-	bmbvh_tri_from_face(tri_cos, ltri, bmcast_data->cos_cage);
+	bmbvh_tri_from_face(tri_cos, ltri, bmcb_data->cos_cage);
 
 	if (isect_ray_tri_v3(ray->origin, ray->direction, tri_cos[0], tri_cos[1], tri_cos[2], &dist, uv) &&
 	    (dist < hit->dist))
@@ -256,7 +244,7 @@
 		mul_v3_fl(hit->co, dist);
 		add_v3_v3(hit->co, ray->origin);
 		
-		copy_v2_v2(bmcast_data->uv, uv);
+		copy_v2_v2(bmcb_data->uv, uv);
 	}
 }
 
@@ -264,22 +252,22 @@
                            float *r_dist, float r_hitout[3], float r_cagehit[3])
 {
 	BVHTreeRayHit hit;
-	struct RayCastUserData bmcast_data;
+	struct RayCastUserData bmcb_data;
 	const float dist = r_dist ? *r_dist : FLT_MAX;
 
 	hit.dist = dist;
 	hit.index = -1;
 
 	/* ok to leave 'uv' uninitialized */
-	bmcast_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
-	bmcast_data.cos_cage = (const float (*)[3])bmtree->cos_cage;
+	bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
+	bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage;
 	
-	BLI_bvhtree_ray_cast(bmtree->tree, co, dir, 0.0f, &hit, bmbvh_ray_cast_cb, &bmcast_data);
+	BLI_bvhtree_ray_cast(bmtree->tree, co, dir, 0.0f, &hit, bmbvh_ray_cast_cb, &bmcb_data);
 	if (hit.index != -1 && hit.dist != dist) {
 		if (r_hitout) {
 			if (bmtree->flag & BMBVH_RETURN_ORIG) {
 				BMLoop **ltri = bmtree->em->looptris[hit.index];
-				interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, bmcast_data.uv);
+				interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, bmcb_data.uv);
 			}
 			else {
 				copy_v3_v3(r_hitout, hit.co);
@@ -316,20 +304,20 @@
 
 static void bmbvh_find_face_segment_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
-	struct SegmentUserData *bmseg_data = userdata;
-	const BMLoop **ltri = bmseg_data->looptris[index];
+	struct SegmentUserData *bmcb_data = userdata;
+	const BMLoop **ltri = bmcb_data->looptris[index];
 	float dist, uv[2];
 	const float *tri_cos[3];
 
-	bmbvh_tri_from_face(tri_cos, ltri, bmseg_data->cos_cage);
+	bmbvh_tri_from_face(tri_cos, ltri, bmcb_data->cos_cage);
 
-	if (equals_v3v3(bmseg_data->co_a, tri_cos[0]) ||
-	    equals_v3v3(bmseg_data->co_a, tri_cos[1]) ||
-	    equals_v3v3(bmseg_data->co_a, tri_cos[2]) ||
+	if (equals_v3v3(bmcb_data->co_a, tri_cos[0]) ||
+	    equals_v3v3(bmcb_data->co_a, tri_cos[1]) ||
+	    equals_v3v3(bmcb_data->co_a, tri_cos[2]) ||
 
-	    equals_v3v3(bmseg_data->co_b, tri_cos[0]) ||
-	    equals_v3v3(bmseg_data->co_b, tri_cos[1]) ||
-	    equals_v3v3(bmseg_data->co_b, tri_cos[2]))
+	    equals_v3v3(bmcb_data->co_b, tri_cos[0]) ||
+	    equals_v3v3(bmcb_data->co_b, tri_cos[1]) ||
+	    equals_v3v3(bmcb_data->co_b, tri_cos[2]))
 	{
 		return;
 	}
@@ -347,7 +335,7 @@
 		mul_v3_fl(hit->co, dist);
 		add_v3_v3(hit->co, ray->origin);
 
-		copy_v2_v2(bmseg_data->uv, uv);
+		copy_v2_v2(bmcb_data->uv, uv);
 	}
 }
 
@@ -355,7 +343,7 @@
                                     float *r_fac, float r_hitout[3], float r_cagehit[3])
 {
 	BVHTreeRayHit hit;
-	struct SegmentUserData bmseg_data;
+	struct SegmentUserData bmcb_data;
 	const float dist = len_v3v3(co_a, co_b);
 	float dir[3];
 
@@ -365,18 +353,18 @@
 	hit.index = -1;
 
 	/* ok to leave 'uv' uninitialized */
-	bmseg_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
-	bmseg_data.cos_cage = (const float (*)[3])bmtree->cos_cage;
-	bmseg_data.co_a = co_a;
-	bmseg_data.co_b = co_b;
+	bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
+	bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage;
+	bmcb_data.co_a = co_a;
+	bmcb_data.co_b = co_b;
 
-	BLI_bvhtree_ray_cast(bmtree->tree, co_a, dir, 0.0f, &hit, bmbvh_find_face_segment_cb, &bmseg_data);
+	BLI_bvhtree_ray_cast(bmtree->tree, co_a, dir, 0.0f, &hit, bmbvh_find_face_segment_cb, &bmcb_data);
 	if (hit.index != -1 && hit.dist != dist) {
 		/* duplicate of BKE_bmbvh_ray_cast() */
 		if (r_hitout) {
 			if (bmtree->flag & BMBVH_RETURN_ORIG) {
 				BMLoop **ltri = bmtree->em->looptris[hit.index];
-				interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, bmseg_data.uv);
+				interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, bmcb_data.uv);
 			}
 			else {
 				copy_v3_v3(r_hitout, hit.co);
@@ -405,6 +393,7 @@
 struct VertSearchUserData {
 	/* from the bmtree */
 	const BMLoop *(*looptris)[3];
+	const float (*cos_cage)[3];
 
 	/* from the hit */
 	float maxdist;
@@ -413,15 +402,15 @@
 
 static void bmbvh_find_vert_closest_cb(void *userdata, int index, const float *UNUSED(co), BVHTreeNearest *hit)
 {
-	struct VertSearchUserData *bmsearch_data = userdata;
-	const BMLoop **ltri = bmsearch_data->looptris[index];
-	const float maxdist = bmsearch_data->maxdist;
+	struct VertSearchUserData *bmcb_data = userdata;
+	const BMLoop **ltri = bmcb_data->looptris[index];
+	const float maxdist = bmcb_data->maxdist;
 	float dist;
 	int i;
 
 	const float *tri_cos[3];
 
-	bmbvh_tri_from_face(tri_cos, ltri, bmsearch_data->cos_cage);
+	bmbvh_tri_from_face(tri_cos, ltri, bmcb_data->cos_cage);
 
 	for (i = 0; i < 3; i++) {
 		dist = len_v3v3(hit->co, tri_cos[i]);
@@ -431,7 +420,7 @@
 			copy_v3_v3(hit->no, ltri[i]->v->no);
 			hit->dist = dist;
 			hit->index = index;
-			bmsearch_data->index_tri = i;
+			bmcb_data->index_tri = i;
 		}
 	}
 }
@@ -439,20 +428,21 @@
 BMVert *BKE_bmbvh_find_vert_closest(BMBVHTree *bmtree, const float co[3], const float maxdist)
 {
 	BVHTreeNearest hit;
-	struct VertSearchUserData bmsearch_data;
+	struct VertSearchUserData bmcb_data;
 
 	copy_v3_v3(hit.co, co);
 	/* XXX, why x5, scampbell */
 	hit.dist = maxdist * 5;
 	hit.index = -1;
 
-	bmsearch_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
-	bmsearch_data.maxdist = maxdist;
+	bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
+	bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage;
+	bmcb_data.maxdist = maxdist;
 
-	BLI_bvhtree_find_nearest(bmtree->tree, co, &hit, bmbvh_find_vert_closest_cb, &bmsearch_data);
+	BLI_bvhtree_find_nearest(bmtree->tree, co, &hit, bmbvh_find_vert_closest_cb, &bmcb_data);
 	if (hit.dist != FLT_MAX && hit.index != -1) {
 		BMLoop **ltri = bmtree->em->looptris[hit.index];
-		return ltri[bmsearch_data.index_tri]->v;
+		return ltri[bmcb_data.index_tri]->v;
 	}
 
 	return NULL;




More information about the Bf-blender-cvs mailing list