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

This commit is contained in:
Campbell Barton
2014-03-24 13:21:58 +11:00
parent 551d1a1ed5
commit 3214d4fd5a
3 changed files with 34 additions and 25 deletions

View File

@@ -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. */

View File

@@ -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;

View File

@@ -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;