This will allow greater control of the bvhtrees that are obtained, and helps identify problems.
It is also an additional step to unify the functions.
const BLI_bitmap *mask, int looptri_num_active,
float epsilon, int tree_type, int axis);
-BVHTree *bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, int type);
+BVHTree *bvhtree_from_mesh_get(
+ struct BVHTreeFromMesh *data, struct DerivedMesh *mesh,
+ const int type, const int tree_type);
/**
* Frees data allocated by a call to bvhtree_from_mesh_*.
* Builds or queries a bvhcache for the cache bvhtree of the request type.
*/
BVHTree *bvhtree_from_mesh_get(
- struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, int type)
+ struct BVHTreeFromMesh *data, struct DerivedMesh *mesh,
+ const int type, const int tree_type)
{
+ BVHTree *tree = NULL;
switch (type) {
case BVHTREE_FROM_VERTS:
- return bvhtree_from_mesh_verts(data, mesh, 0.0f, 2, 6);
+ tree = bvhtree_from_mesh_verts(data, mesh, 0.0f, tree_type, 6);
+ break;
case BVHTREE_FROM_EDGES:
- return bvhtree_from_mesh_edges(data, mesh, 0.0f, 2, 6);
+ tree = bvhtree_from_mesh_edges(data, mesh, 0.0f, tree_type, 6);
+ break;
case BVHTREE_FROM_FACES:
- return bvhtree_from_mesh_faces(data, mesh, 0.0f, 2, 6);
+ tree = bvhtree_from_mesh_faces(data, mesh, 0.0f, tree_type, 6);
+ break;
case BVHTREE_FROM_LOOPTRI:
- return bvhtree_from_mesh_looptri(data, mesh, 0.0f, 2, 6);
+ tree = bvhtree_from_mesh_looptri(data, mesh, 0.0f, tree_type, 6);
+ break;
}
- return NULL;
+#ifdef DEBUG
+ if (BLI_bvhtree_get_tree_type(tree) != tree_type) {
+ printf("tree_type %d obtained instead of %d\n", BLI_bvhtree_get_tree_type(tree), tree_type);
+ }
+#endif
+ return tree;
}
/** \} */
nearest.dist_sq = FLT_MAX;
if (scon->shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX)
- bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_VERTS);
+ bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_VERTS, 2);
else
- bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_LOOPTRI);
+ bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_LOOPTRI, 2);
if (treeData.tree == NULL) {
fail = true;
sub_v3_v3v3(ray_nor, ray_end, ray_start);
normalize_v3(ray_nor);
- bvhtree_from_mesh_looptri(&treeData, target, 0.0f, 4, 6);
+ bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_LOOPTRI, 4);
hit.dist = BVH_RAYCAST_DIST_MAX;
hit.index = -1;
float result = 0.0f;
int i;
- bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS);
+ bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS, 2);
nearest.index = -1;
for (i = 0; i < numverts_dst; i++) {
float tmp_co[3], tmp_no[3];
if (mode == MREMAP_MODE_VERT_NEAREST) {
- bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS);
+ bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS, 2);
nearest.index = -1;
for (i = 0; i < numverts_dst; i++) {
float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__);
dm_src->getVertCos(dm_src, vcos_src);
- bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES);
+ bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES, 2);
nearest.index = -1;
for (i = 0; i < numverts_dst; i++) {
&treedata, dm_src, ray_radius, 2, 6);
}
else {
- bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI);
+ bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI, 2);
}
if (mode == MREMAP_MODE_VERT_POLYINTERP_VNORPROJ) {
dm_src->getVertCos(dm_src, vcos_src);
- bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS);
+ bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS, 2);
nearest.index = -1;
for (i = 0; i < numedges_dst; i++) {
MEM_freeN(vert_to_edge_src_map_mem);
}
else if (mode == MREMAP_MODE_EDGE_NEAREST) {
- bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES);
+ bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES, 2);
nearest.index = -1;
for (i = 0; i < numedges_dst; i++) {
float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__);
dm_src->getVertCos(dm_src, vcos_src);
- bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI);
+ bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI, 2);
for (i = 0; i < numedges_dst; i++) {
interp_v3_v3v3(tmp_co, verts_dst[edges_dst[i].v1].co, verts_dst[edges_dst[i].v2].co, 0.5f);
}
else {
BLI_assert(num_trees == 1);
- bvhtree_from_mesh_get(&treedata[0], dm_src, BVHTREE_FROM_VERTS);
+ bvhtree_from_mesh_get(&treedata[0], dm_src, BVHTREE_FROM_VERTS, 2);
}
}
else { /* We use polygons. */
&treedata, dm_src, MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON(ray_radius), 2, 6);
}
else {
- bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI);
+ bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI, 2);
}
if (mode == MREMAP_MODE_POLY_NEAREST) {
return;
}
- TIMEIT_BENCH(bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_VERTS), bvhtree_verts);
+ TIMEIT_BENCH(bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_VERTS, 2), bvhtree_verts);
if (treeData.tree == NULL) {
OUT_OF_MEMORY();
return;
}
}
else {
- if ((targ_tree = bvhtree_from_mesh_looptri(
- &treedata_stack.dmtreedata, calc->target, 0.0, 4, 6)))
+ if (targ_tree = bvhtree_from_mesh_get(
+ &treedata_stack.dmtreedata, calc->target, BVHTREE_FROM_LOOPTRI, 4))
{
targ_callback = treedata_stack.dmtreedata.raycast_callback;
treeData = &treedata_stack.dmtreedata;
}
}
else {
- if ((aux_tree = bvhtree_from_mesh_looptri(&auxdata_stack.dmtreedata, auxMesh, 0.0, 4, 6)) != NULL) {
+ if ((aux_tree = bvhtree_from_mesh_get(
+ &auxdata_stack.dmtreedata, auxMesh, BVHTREE_FROM_LOOPTRI, 4)) != NULL)
+ {
aux_callback = auxdata_stack.dmtreedata.raycast_callback;
auxData = &auxdata_stack.dmtreedata;
}
}
/* Create a bvh-tree of the given target */
- bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_LOOPTRI);
+ bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_LOOPTRI, 2);
if (treeData.tree == NULL) {
OUT_OF_MEMORY();
return;
BVHTree_OverlapCallback callback, void *userdata);
int BLI_bvhtree_get_len(const BVHTree *tree);
-
+int BLI_bvhtree_get_tree_type(const BVHTree *tree);
float BLI_bvhtree_get_epsilon(const BVHTree *tree);
/* find nearest node to the given coordinates
return tree->totleaf;
}
+/**
+ * Maximum number of children that a node can have.
+ */
+int BLI_bvhtree_get_tree_type(const BVHTree *tree)
+{
+ return tree->tree_type;
+}
+
float BLI_bvhtree_get_epsilon(const BVHTree *tree)
{
return tree->epsilon;
if (dm->getNumTessFaces(dm) != 0) {
mface = dm->getTessFaceArray(dm);
- bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_FACES);
+ bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_FACES, 2);
}
else if (dm->getNumEdges(dm) != 0) {
medge = dm->getEdgeArray(dm);
- bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_EDGES);
+ bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_EDGES, 2);
}
else {
dm->release(dm);
}
if (treedata->tree == NULL) {
- bvhtree_from_mesh_looptri(treedata, dm, 0.0f, 4, 6);
+ bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_LOOPTRI, 4);
if (treedata->tree == NULL) {
return retval;
if (treedata->tree == NULL) {
switch (snapdata->snap_to) {
case SCE_SNAP_MODE_EDGE:
- bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_EDGES);
+ bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_EDGES, 2);
break;
case SCE_SNAP_MODE_VERTEX:
- bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_VERTS);
+ bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_VERTS, 2);
break;
}
}
surmd->bvhtree = MEM_callocN(sizeof(BVHTreeFromMesh), "BVHTreeFromMesh");
if (surmd->dm->getNumPolys(surmd->dm))
- bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_LOOPTRI);
+ bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_LOOPTRI, 2);
else
- bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_EDGES);
+ bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_EDGES, 2);
}
}
return false;
}
- bvhtree_from_mesh_get(&treeData, tdm, BVHTREE_FROM_LOOPTRI);
+ bvhtree_from_mesh_get(&treeData, tdm, BVHTREE_FROM_LOOPTRI, 2);
if (treeData.tree == NULL) {
modifier_setError((ModifierData *)smd, "Out of memory");
freeAdjacencyMap(vert_edges, adj_array, edge_polys);
if (dist_v) {
/* Create a bvh-tree of the given target's verts. */
- bvhtree_from_mesh_get(&treeData_v, target, BVHTREE_FROM_VERTS);
+ bvhtree_from_mesh_get(&treeData_v, target, BVHTREE_FROM_VERTS, 2);
if (treeData_v.tree == NULL) {
OUT_OF_MEMORY();
return;
}
if (dist_e) {
/* Create a bvh-tree of the given target's edges. */
- bvhtree_from_mesh_get(&treeData_e, target, BVHTREE_FROM_EDGES);
+ bvhtree_from_mesh_get(&treeData_e, target, BVHTREE_FROM_EDGES, 2);
if (treeData_e.tree == NULL) {
OUT_OF_MEMORY();
return;
}
if (dist_f) {
/* Create a bvh-tree of the given target's faces. */
- bvhtree_from_mesh_get(&treeData_f, target, BVHTREE_FROM_LOOPTRI);
+ bvhtree_from_mesh_get(&treeData_f, target, BVHTREE_FROM_LOOPTRI, 2);
if (treeData_f.tree == NULL) {
OUT_OF_MEMORY();
return;
if (dm_highpoly[i]->getNumTessFaces(dm_highpoly[i]) != 0) {
/* Create a bvh-tree for each highpoly object */
- bvhtree_from_mesh_get(&treeData[i], dm_highpoly[i], BVHTREE_FROM_FACES);
+ bvhtree_from_mesh_get(&treeData[i], dm_highpoly[i], BVHTREE_FROM_FACES, 2);
if (treeData[i].tree == NULL) {
printf("Baking: out of memory while creating BHVTree for object \"%s\"\n", highpoly[i].ob->id.name + 2);