[Bf-blender-cvs] [7c3bbe93aaa] master: Cleanup/Refactor: Simplify/deduplicate bvhutils code
mano-wii
noreply at git.blender.org
Thu Aug 22 19:08:00 CEST 2019
Commit: 7c3bbe93aaa293a27d9b88a0d4104e0b2661ef1a
Author: mano-wii
Date: Thu Aug 22 14:07:40 2019 -0300
Branches: master
https://developer.blender.org/rB7c3bbe93aaa293a27d9b88a0d4104e0b2661ef1a
Cleanup/Refactor: Simplify/deduplicate bvhutils code
This is a step that allow using `bvh_cache` for `EditMeshe`s.
===================================================================
M source/blender/blenkernel/BKE_bvhutils.h
M source/blender/blenkernel/intern/bvhutils.c
M source/blender/blenkernel/intern/mesh_remap.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index c88a64097bb..d010f5dd836 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -115,7 +115,9 @@ BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data,
int verts_num_active,
float epsilon,
int tree_type,
- int axis);
+ int axis,
+ const int bvh_cache_type,
+ BVHCache **bvh_cache);
BVHTree *bvhtree_from_editmesh_edges(BVHTreeFromEditMesh *data,
struct BMEditMesh *em,
@@ -141,7 +143,9 @@ BVHTree *bvhtree_from_mesh_edges_ex(struct BVHTreeFromMesh *data,
int edges_num_active,
float epsilon,
int tree_type,
- int axis);
+ int axis,
+ const int bvh_cache_type,
+ BVHCache **bvh_cache);
BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data,
const struct MVert *vert,
@@ -153,7 +157,9 @@ BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data,
int numFaces_active,
float epsilon,
int tree_type,
- int axis);
+ int axis,
+ const int bvh_cache_type,
+ BVHCache **bvh_cache);
BVHTree *bvhtree_from_editmesh_looptri(BVHTreeFromEditMesh *data,
struct BMEditMesh *em,
@@ -182,7 +188,9 @@ BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data,
int looptri_num_active,
float epsilon,
int tree_type,
- int axis);
+ int axis,
+ const int bvh_cache_type,
+ BVHCache **bvh_cache);
BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
struct Mesh *mesh,
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index 8c125d1609b..1210e6f18ce 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -580,13 +580,40 @@ BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
int verts_num_active,
float epsilon,
int tree_type,
- int axis)
+ int axis,
+ const int bvh_cache_type,
+ BVHCache **bvh_cache)
{
- BVHTree *tree = bvhtree_from_mesh_verts_create_tree(
- epsilon, tree_type, axis, vert, verts_num, verts_mask, verts_num_active);
+ bool in_cache = false;
+ BVHTree *tree = NULL;
+ if (bvh_cache) {
+ BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ);
+ in_cache = bvhcache_find(*bvh_cache, bvh_cache_type, &tree);
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ if (in_cache == false) {
+ BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE);
+ in_cache = bvhcache_find(*bvh_cache, bvh_cache_type, &tree);
+ if (in_cache) {
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ }
+ }
+ }
+
+ if (in_cache == false) {
+ tree = bvhtree_from_mesh_verts_create_tree(
+ epsilon, tree_type, axis, vert, verts_num, verts_mask, verts_num_active);
+
+ if (bvh_cache) {
+ /* Save on cache for later use */
+ /* printf("BVHTree built and saved on cache\n"); */
+ bvhcache_insert(bvh_cache, tree, bvh_cache_type);
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ in_cache = true;
+ }
+ }
/* Setup BVHTreeFromMesh */
- bvhtree_from_mesh_verts_setup_data(data, tree, false, vert, vert_allocated);
+ bvhtree_from_mesh_verts_setup_data(data, tree, in_cache, vert, vert_allocated);
return tree;
}
@@ -774,14 +801,41 @@ BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
int edges_num_active,
float epsilon,
int tree_type,
- int axis)
+ int axis,
+ const int bvh_cache_type,
+ BVHCache **bvh_cache)
{
- BVHTree *tree = bvhtree_from_mesh_edges_create_tree(
- vert, edge, edges_num, edges_mask, edges_num_active, epsilon, tree_type, axis);
+ bool in_cache = false;
+ BVHTree *tree = NULL;
+ if (bvh_cache) {
+ BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ);
+ in_cache = bvhcache_find(*bvh_cache, bvh_cache_type, &tree);
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ if (in_cache == false) {
+ BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE);
+ in_cache = bvhcache_find(*bvh_cache, bvh_cache_type, &tree);
+ if (in_cache) {
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ }
+ }
+ }
+
+ if (in_cache == false) {
+ tree = bvhtree_from_mesh_edges_create_tree(
+ vert, edge, edges_num, edges_mask, edges_num_active, epsilon, tree_type, axis);
+
+ if (bvh_cache) {
+ /* Save on cache for later use */
+ /* printf("BVHTree built and saved on cache\n"); */
+ bvhcache_insert(bvh_cache, tree, bvh_cache_type);
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ in_cache = true;
+ }
+ }
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_edges_setup_data(
- data, tree, false, vert, vert_allocated, edge, edge_allocated);
+ data, tree, in_cache, vert, vert_allocated, edge, edge_allocated);
return tree;
}
@@ -882,14 +936,41 @@ BVHTree *bvhtree_from_mesh_faces_ex(BVHTreeFromMesh *data,
int faces_num_active,
float epsilon,
int tree_type,
- int axis)
+ int axis,
+ const int bvh_cache_type,
+ BVHCache **bvh_cache)
{
- BVHTree *tree = bvhtree_from_mesh_faces_create_tree(
- epsilon, tree_type, axis, vert, face, numFaces, faces_mask, faces_num_active);
+ bool in_cache = false;
+ BVHTree *tree = NULL;
+ if (bvh_cache) {
+ BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ);
+ in_cache = bvhcache_find(*bvh_cache, bvh_cache_type, &tree);
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ if (in_cache == false) {
+ BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE);
+ in_cache = bvhcache_find(*bvh_cache, bvh_cache_type, &tree);
+ if (in_cache) {
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ }
+ }
+ }
+
+ if (in_cache == false) {
+ tree = bvhtree_from_mesh_faces_create_tree(
+ epsilon, tree_type, axis, vert, face, numFaces, faces_mask, faces_num_active);
+
+ if (bvh_cache) {
+ /* Save on cache for later use */
+ /* printf("BVHTree built and saved on cache\n"); */
+ bvhcache_insert(bvh_cache, tree, bvh_cache_type);
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ in_cache = true;
+ }
+ }
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_faces_setup_data(
- data, tree, false, vert, vert_allocated, face, face_allocated);
+ data, tree, in_cache, vert, vert_allocated, face, face_allocated);
return tree;
}
@@ -1101,21 +1182,54 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
int looptri_num_active,
float epsilon,
int tree_type,
- int axis)
+ int axis,
+ const int bvh_cache_type,
+ BVHCache **bvh_cache)
{
- BVHTree *tree = bvhtree_from_mesh_looptri_create_tree(epsilon,
- tree_type,
- axis,
- vert,
- mloop,
- looptri,
- looptri_num,
- looptri_mask,
- looptri_num_active);
+ bool in_cache = false;
+ BVHTree *tree = NULL;
+ if (bvh_cache) {
+ BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ);
+ in_cache = bvhcache_find(*bvh_cache, bvh_cache_type, &tree);
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ if (in_cache == false) {
+ BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE);
+ in_cache = bvhcache_find(*bvh_cache, bvh_cache_type, &tree);
+ if (in_cache) {
+ BLI_rw_mutex_unlock(&cache_rwlock);
+ }
+ }
+ }
+
+ if (in_cache == false) {
+ /* Setup BVHTreeFromMesh */
+ tree = bvhtree_from_mesh_looptri_create_tree(epsilon,
+ tree_type,
+ axis,
+ vert,
+ mloop,
+ looptri,
+ looptri_num,
+ looptri_mask,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list