From 881334c499c839679b4b40e0ce1ca6bda3c03a39 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 15 Oct 2018 13:38:10 +1100 Subject: Cleanup: remove DerivedMesh bvhtree_from_mesh_get --- source/blender/blenkernel/intern/bvhutils.c | 222 +--------------------------- 1 file changed, 1 insertion(+), 221 deletions(-) (limited to 'source/blender/blenkernel/intern/bvhutils.c') diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index bb3d468fd7b..15c7ba54732 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -42,7 +42,7 @@ #include "BLI_math.h" #include "BLI_threads.h" -#include "BKE_DerivedMesh.h" +#include "BKE_bvhutils.h" #include "BKE_editmesh.h" #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" @@ -1086,226 +1086,6 @@ static BLI_bitmap *loose_edges_map_get( return loose_edges_mask; } -/** - * Builds or queries a bvhcache for the cache bvhtree of the request type. - */ -BVHTree *bvhtree_from_mesh_get( - struct BVHTreeFromMesh *data, struct DerivedMesh *dm, - const int type, const int tree_type) -{ - BVHTree *tree = NULL; - - BVHTree_NearestPointCallback nearest_callback = NULL; - BVHTree_RayCastCallback raycast_callback = NULL; - - MVert *mvert = NULL; - MEdge *medge = NULL; - MFace *mface = NULL; - MLoop *mloop = NULL; - const MLoopTri *looptri = NULL; - bool vert_allocated = false; - bool edge_allocated = false; - bool face_allocated = false; - bool loop_allocated = false; - bool looptri_allocated = false; - - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ); - bool in_cache = bvhcache_find(dm->bvhCache, type, &tree); - BLI_rw_mutex_unlock(&cache_rwlock); - - if (in_cache && tree == NULL) { - memset(data, 0, sizeof(*data)); - return tree; - } - - switch (type) { - case BVHTREE_FROM_VERTS: - case BVHTREE_FROM_LOOSEVERTS: - raycast_callback = mesh_verts_spherecast; - - mvert = DM_get_vert_array(dm, &vert_allocated); - - if (in_cache == false) { - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); - in_cache = bvhcache_find(dm->bvhCache, type, &tree); - if (in_cache == false) { - BLI_bitmap *loose_verts_mask = NULL; - int loose_vert_num = -1; - int verts_num = dm->getNumVerts(dm); - - if (type == BVHTREE_FROM_LOOSEVERTS) { - medge = DM_get_edge_array(dm, &edge_allocated); - - loose_verts_mask = loose_verts_map_get( - medge, dm->getNumEdges(dm), mvert, - verts_num, &loose_vert_num); - - if (edge_allocated) { - MEM_freeN(medge); - edge_allocated = false; - } - medge = NULL; - } - - tree = bvhtree_from_mesh_verts_create_tree( - 0.0, tree_type, 6, mvert, verts_num, - loose_verts_mask, loose_vert_num); - - if (loose_verts_mask != NULL) { - MEM_freeN(loose_verts_mask); - } - - - /* Save on cache for later use */ - /* printf("BVHTree built and saved on cache\n"); */ - bvhcache_insert(&dm->bvhCache, tree, type); - - } - - BLI_rw_mutex_unlock(&cache_rwlock); - } - break; - - case BVHTREE_FROM_EDGES: - case BVHTREE_FROM_LOOSEEDGES: - nearest_callback = mesh_edges_nearest_point; - raycast_callback = mesh_edges_spherecast; - - mvert = DM_get_vert_array(dm, &vert_allocated); - medge = DM_get_edge_array(dm, &edge_allocated); - - if (in_cache == false) { - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); - in_cache = bvhcache_find(dm->bvhCache, type, &tree); - if (in_cache == false) { - BLI_bitmap *loose_edges_mask = NULL; - int loose_edges_num = -1; - int edges_num = dm->getNumEdges(dm); - - if (type == BVHTREE_FROM_LOOSEEDGES) { - loose_edges_mask = loose_edges_map_get( - medge, edges_num, &loose_edges_num); - } - - tree = bvhtree_from_mesh_edges_create_tree( - mvert, medge, edges_num, - loose_edges_mask, loose_edges_num, 0.0, tree_type, 6); - - if (loose_edges_mask != NULL) { - MEM_freeN(loose_edges_mask); - } - - /* Save on cache for later use */ - /* printf("BVHTree built and saved on cache\n"); */ - bvhcache_insert(&dm->bvhCache, tree, type); - } - BLI_rw_mutex_unlock(&cache_rwlock); - } - break; - - case BVHTREE_FROM_FACES: - nearest_callback = mesh_faces_nearest_point; - raycast_callback = mesh_faces_spherecast; - - mvert = DM_get_vert_array(dm, &vert_allocated); - mface = DM_get_tessface_array(dm, &face_allocated); - - if (in_cache == false) { - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); - in_cache = bvhcache_find(dm->bvhCache, BVHTREE_FROM_FACES, &tree); - if (in_cache == false) { - int numFaces = dm->getNumTessFaces(dm); - BLI_assert(!(numFaces == 0 && dm->getNumPolys(dm) != 0)); - - tree = bvhtree_from_mesh_faces_create_tree( - 0.0, tree_type, 6, mvert, mface, numFaces, NULL, -1); - - /* Save on cache for later use */ - /* printf("BVHTree built and saved on cache\n"); */ - bvhcache_insert(&dm->bvhCache, tree, BVHTREE_FROM_FACES); - } - BLI_rw_mutex_unlock(&cache_rwlock); - } - break; - - case BVHTREE_FROM_LOOPTRI: - nearest_callback = mesh_looptri_nearest_point; - raycast_callback = mesh_looptri_spherecast; - - mvert = DM_get_vert_array(dm, &vert_allocated); - mloop = DM_get_loop_array(dm, &loop_allocated); - looptri = dm->getLoopTriArray(dm); - - if (in_cache == false) { - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); - in_cache = bvhcache_find(dm->bvhCache, BVHTREE_FROM_LOOPTRI, &tree); - if (in_cache == false) { - int looptri_num = dm->getNumLoopTri(dm); - - /* this assert checks we have looptris, - * if not caller should use DM_ensure_looptri() */ - BLI_assert(!(looptri_num == 0 && dm->getNumPolys(dm) != 0)); - - tree = bvhtree_from_mesh_looptri_create_tree( - 0.0, tree_type, 6, - mvert, mloop, looptri, looptri_num, NULL, -1); - - /* Save on cache for later use */ - /* printf("BVHTree built and saved on cache\n"); */ - bvhcache_insert(&dm->bvhCache, tree, BVHTREE_FROM_LOOPTRI); - } - BLI_rw_mutex_unlock(&cache_rwlock); - } - break; - } - - if (tree != 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 - data->tree = tree; - - data->nearest_callback = nearest_callback; - data->raycast_callback = raycast_callback; - - data->vert = mvert; - data->edge = medge; - data->face = mface; - data->loop = mloop; - data->looptri = looptri; - data->vert_allocated = vert_allocated; - data->edge_allocated = edge_allocated; - data->face_allocated = face_allocated; - data->loop_allocated = loop_allocated; - data->looptri_allocated = looptri_allocated; - - data->cached = true; - } - else { - if (vert_allocated) { - MEM_freeN(mvert); - } - if (edge_allocated) { - MEM_freeN(medge); - } - if (face_allocated) { - MEM_freeN(mface); - } - if (loop_allocated) { - MEM_freeN(mloop); - } - if (looptri_allocated) { - MEM_freeN((void *)looptri); - } - - memset(data, 0, sizeof(*data)); - } - - return tree; -} - /** * Builds or queries a bvhcache for the cache bvhtree of the request type. */ -- cgit v1.2.3