[Bf-blender-cvs] [3214d4f] master: Code Cleanup: PBVH, avoid sqrt and use bool for raycast functions

Campbell Barton noreply at git.blender.org
Mon Mar 24 03:31:50 CET 2014


Commit: 3214d4fd5aa803237637da2eee5d1b9e0006ae26
Author: Campbell Barton
Date:   Mon Mar 24 13:21:58 2014 +1100
https://developer.blender.org/rB3214d4fd5aa803237637da2eee5d1b9e0006ae26

Code Cleanup: PBVH, avoid sqrt and use bool for raycast functions

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 3601ff1..7517a93 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -94,12 +94,14 @@ void BKE_pbvh_raycast(PBVH *bvh, BKE_pbvh_HitOccludedCallback cb, void *data,
                       const float ray_start[3], const float ray_normal[3],
                       int original);
 
-int BKE_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], int use_origco,
+bool BKE_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], int use_origco,
                           const float ray_start[3], const float ray_normal[3],
                           float *dist);
 
-int BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, const float ray_start[3],
-							const float ray_normal[3], float *detail, float *dist);
+bool BKE_pbvh_bmesh_node_raycast_detail(
+        PBVHNode *node,
+        const float ray_start[3], const float ray_normal[3],
+        float *detail, float *dist);
 
 /* for orthographic cameras, project the far away ray segment points to the root node so
  * we can have better precision. */
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 426a1e1..5a81bbf 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1453,14 +1453,16 @@ static bool pbvh_faces_node_raycast(PBVH *bvh, const PBVHNode *node,
 	return hit;
 }
 
-static int pbvh_grids_node_raycast(PBVH *bvh, PBVHNode *node,
-                                   float (*origco)[3],
-                                   const float ray_start[3],
-                                   const float ray_normal[3], float *dist)
+static bool pbvh_grids_node_raycast(
+        PBVH *bvh, PBVHNode *node,
+        float (*origco)[3],
+        const float ray_start[3], const float ray_normal[3],
+        float *dist)
 {
 	int totgrid = node->totprim;
 	int gridsize = bvh->gridkey.grid_size;
-	int i, x, y, hit = 0;
+	int i, x, y;
+	bool hit = false;
 
 	for (i = 0; i < totgrid; ++i) {
 		CCGElem *grid = bvh->grids[node->prim_indices[i]];
@@ -1505,9 +1507,10 @@ static int pbvh_grids_node_raycast(PBVH *bvh, PBVHNode *node,
 	return hit;
 }
 
-int BKE_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], int use_origco,
-                          const float ray_start[3], const float ray_normal[3],
-                          float *dist)
+bool BKE_pbvh_node_raycast(
+        PBVH *bvh, PBVHNode *node, float (*origco)[3], int use_origco,
+        const float ray_start[3], const float ray_normal[3],
+        float *dist)
 {
 	bool hit = false;
 
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 4fedf76..0ea554c 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1035,11 +1035,13 @@ int pbvh_bmesh_node_raycast(PBVHNode *node, const float ray_start[3],
 	return hit;
 }
 
-int BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, const float ray_start[3],
-							const float ray_normal[3], float *detail, float *dist)
+bool BKE_pbvh_bmesh_node_raycast_detail(
+        PBVHNode *node,
+        const float ray_start[3], const float ray_normal[3],
+        float *detail, float *dist)
 {
 	GHashIterator gh_iter;
-	int hit = 0;
+	bool hit = false;
 	BMFace *f_hit = NULL;
 
 	if (node->flag & PBVH_FullyHidden)
@@ -1051,17 +1053,19 @@ int BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, const float ray_start[3],
 		BLI_assert(f->len == 3);
 		if (f->len == 3 && !paint_is_bmesh_face_hidden(f)) {
 			BMVert *v_tri[3];
-			int hit_local;
+			bool hit_local;
 			BM_face_as_array_vert_tri(f, v_tri);
-			hit_local = ray_face_intersection(ray_start, ray_normal,
-										 v_tri[0]->co,
-										 v_tri[1]->co,
-										 v_tri[2]->co,
-										 NULL, dist);
+			hit_local = ray_face_intersection(
+			        ray_start, ray_normal,
+			        v_tri[0]->co,
+			        v_tri[1]->co,
+			        v_tri[2]->co,
+			        NULL, dist);
+
 			if (hit_local) {
 				f_hit = f;
+				hit = true;
 			}
-			hit |= hit_local;
 		}
 	}
 
@@ -1069,12 +1073,12 @@ int BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, const float ray_start[3],
 		float len1, len2, len3;
 		BMVert *v_tri[3];
 		BM_face_as_array_vert_tri(f_hit, v_tri);
-		len1 = len_v3v3(v_tri[0]->co, v_tri[1]->co);
-		len2 = len_v3v3(v_tri[1]->co, v_tri[2]->co);
-		len3 = len_v3v3(v_tri[2]->co, v_tri[0]->co);
+		len1 = len_squared_v3v3(v_tri[0]->co, v_tri[1]->co);
+		len2 = len_squared_v3v3(v_tri[1]->co, v_tri[2]->co);
+		len3 = len_squared_v3v3(v_tri[2]->co, v_tri[0]->co);
 
 		/* detail returned will be set to the maximum allowed size, so take max here */
-		*detail = max_fff(len1, len2, len3);
+		*detail = sqrtf(max_fff(len1, len2, len3));
 	}
 
 	return hit;




More information about the Bf-blender-cvs mailing list