[Bf-blender-cvs] [501352ef05c] master: Cleanup: Move PBVH files to C++

Hans Goudey noreply at git.blender.org
Sun Feb 5 23:37:04 CET 2023


Commit: 501352ef05ca3ca262e0eaf3e1b0753376cf1d1a
Author: Hans Goudey
Date:   Sun Feb 5 16:56:37 2023 -0500
Branches: master
https://developer.blender.org/rB501352ef05ca3ca262e0eaf3e1b0753376cf1d1a

Cleanup: Move PBVH files to C++

For continued refactoring of the Mesh data structure. See T103343.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/CMakeLists.txt
R091	source/blender/blenkernel/intern/pbvh.c	source/blender/blenkernel/intern/pbvh.cc
R092	source/blender/blenkernel/intern/pbvh_bmesh.c	source/blender/blenkernel/intern/pbvh_bmesh.cc
M	source/blender/blenkernel/intern/pbvh_colors.cc
R091	source/blender/blenkernel/intern/pbvh_intern.h	source/blender/blenkernel/intern/pbvh_intern.hh
M	source/blender/blenkernel/intern/pbvh_pixels.cc

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 7153f05c0c3..367dc9a3035 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -167,6 +167,7 @@ typedef enum {
   PBVH_TopologyUpdated = 1 << 17, /* Used internally by pbvh_bmesh.c */
 
 } PBVHNodeFlags;
+ENUM_OPERATORS(PBVHNodeFlags, PBVH_TopologyUpdated);
 
 typedef struct PBVHFrustumPlanes {
   float (*planes)[4];
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index c5d3f6eb3ab..850c55de7e9 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -248,9 +248,9 @@ set(SRC
   intern/particle_child.c
   intern/particle_distribute.c
   intern/particle_system.c
-  intern/pbvh.c
+  intern/pbvh.cc
   intern/pbvh_colors.cc
-  intern/pbvh_bmesh.c
+  intern/pbvh_bmesh.cc
   intern/pbvh_pixels.cc
   intern/pbvh_uv_islands.cc
   intern/pointcache.c
@@ -505,7 +505,7 @@ set(SRC
   intern/multires_reshape.hh
   intern/multires_unsubdivide.h
   intern/ocean_intern.h
-  intern/pbvh_intern.h
+  intern/pbvh_intern.hh
   intern/pbvh_uv_islands.hh
   intern/subdiv_converter.h
   intern/subdiv_inline.h
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.cc
similarity index 91%
rename from source/blender/blenkernel/intern/pbvh.c
rename to source/blender/blenkernel/intern/pbvh.cc
index 6b21568ba38..1f3583a7f7e 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.cc
@@ -6,13 +6,14 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "BLI_utildefines.h"
+#include <climits>
 
 #include "BLI_bitmap.h"
 #include "BLI_ghash.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
 #include "BLI_task.h"
+#include "BLI_utildefines.h"
 
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
@@ -33,9 +34,7 @@
 
 #include "atomic_ops.h"
 
-#include "pbvh_intern.h"
-
-#include <limits.h>
+#include "pbvh_intern.hh"
 
 #define LEAF_LIMIT 10000
 
@@ -50,12 +49,12 @@
 //#define PERFCNTRS
 #define STACK_FIXED_DEPTH 100
 
-typedef struct PBVHStack {
+struct PBVHStack {
   PBVHNode *node;
   bool revisiting;
-} PBVHStack;
+};
 
-typedef struct PBVHIter {
+struct PBVHIter {
   PBVH *pbvh;
   BKE_pbvh_SearchCallback scb;
   void *search_data;
@@ -65,7 +64,7 @@ typedef struct PBVHIter {
 
   PBVHStack stackfixed[STACK_FIXED_DEPTH];
   int stackspace;
-} PBVHIter;
+};
 
 void BB_reset(BB *bb)
 {
@@ -273,7 +272,8 @@ void pbvh_grow_nodes(PBVH *pbvh, int totnode)
     if (pbvh->node_mem_count < totnode) {
       pbvh->node_mem_count = totnode;
     }
-    pbvh->nodes = MEM_recallocN(pbvh->nodes, sizeof(PBVHNode) * pbvh->node_mem_count);
+    pbvh->nodes = static_cast<PBVHNode *>(
+        MEM_recallocN(pbvh->nodes, sizeof(PBVHNode) * pbvh->node_mem_count));
   }
 
   pbvh->totnode = totnode;
@@ -315,7 +315,8 @@ static void build_mesh_leaf_node(PBVH *pbvh, PBVHNode *node)
   /* reserve size is rough guess */
   GHash *map = BLI_ghash_int_new_ex("build_mesh_leaf_node gh", 2 * totface);
 
-  int(*face_vert_indices)[3] = MEM_mallocN(sizeof(int[3]) * totface, "bvh node face vert indices");
+  int(*face_vert_indices)[3] = static_cast<int(*)[3]>(
+      MEM_mallocN(sizeof(int[3]) * totface, __func__));
 
   node->face_vert_indices = (const int(*)[3])face_vert_indices;
 
@@ -337,8 +338,8 @@ static void build_mesh_leaf_node(PBVH *pbvh, PBVHNode *node)
     }
   }
 
-  int *vert_indices = MEM_callocN(sizeof(int) * (node->uniq_verts + node->face_verts),
-                                  "bvh node vert indices");
+  int *vert_indices = static_cast<int *>(
+      MEM_callocN(sizeof(int) * (node->uniq_verts + node->face_verts), __func__));
   node->vert_indices = vert_indices;
 
   /* Build the vertex list, unique verts first */
@@ -368,7 +369,7 @@ static void build_mesh_leaf_node(PBVH *pbvh, PBVHNode *node)
 
   BKE_pbvh_node_fully_hidden_set(node, !has_visible);
 
-  BLI_ghash_free(map, NULL, NULL);
+  BLI_ghash_free(map, nullptr, nullptr);
 }
 
 static void update_vb(PBVH *pbvh, PBVHNode *node, BBC *prim_bbc, int offset, int count)
@@ -392,8 +393,8 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
   /* grid hidden layer is present, so have to check each grid for
    * visibility */
 
-  int depth1 = (int)(log2((double)gridsize - 1.0) + DBL_EPSILON);
-  int depth2 = (int)(log2((double)display_gridsize - 1.0) + DBL_EPSILON);
+  int depth1 = int(log2((double)gridsize - 1.0) + DBL_EPSILON);
+  int depth2 = int(log2((double)display_gridsize - 1.0) + DBL_EPSILON);
 
   int skip = depth2 < depth1 ? 1 << (depth1 - depth2 - 1) : 1;
 
@@ -550,7 +551,7 @@ static void build_sub(PBVH *pbvh,
   BB cb_backing;
 
   if (!prim_scratch) {
-    prim_scratch = MEM_malloc_arrayN(pbvh->totprim, sizeof(int), __func__);
+    prim_scratch = static_cast<int *>(MEM_malloc_arrayN(pbvh->totprim, sizeof(int), __func__));
   }
 
   /* Decide whether this is a leaf or not */
@@ -615,7 +616,7 @@ static void build_sub(PBVH *pbvh,
   /* Build children */
   build_sub(pbvh,
             pbvh->nodes[node_index].children_offset,
-            NULL,
+            nullptr,
             prim_bbc,
             offset,
             end - offset,
@@ -623,7 +624,7 @@ static void build_sub(PBVH *pbvh,
             depth + 1);
   build_sub(pbvh,
             pbvh->nodes[node_index].children_offset + 1,
-            NULL,
+            nullptr,
             prim_bbc,
             end,
             offset + count - end,
@@ -645,19 +646,20 @@ static void pbvh_build(PBVH *pbvh, BB *cb, BBC *prim_bbc, int totprim)
     if (pbvh->prim_indices) {
       MEM_freeN(pbvh->prim_indices);
     }
-    pbvh->prim_indices = MEM_mallocN(sizeof(int) * totprim, "bvh prim indices");
+    pbvh->prim_indices = static_cast<int *>(MEM_mallocN(sizeof(int) * totprim, __func__));
     for (int i = 0; i < totprim; i++) {
       pbvh->prim_indices[i] = i;
     }
     pbvh->totnode = 0;
     if (pbvh->node_mem_count < 100) {
       pbvh->node_mem_count = 100;
-      pbvh->nodes = MEM_callocN(sizeof(PBVHNode) * pbvh->node_mem_count, "bvh initial nodes");
+      pbvh->nodes = static_cast<PBVHNode *>(
+          MEM_callocN(sizeof(PBVHNode) * pbvh->node_mem_count, __func__));
     }
   }
 
   pbvh->totnode = 1;
-  build_sub(pbvh, 0, cb, prim_bbc, 0, totprim, NULL, 0);
+  build_sub(pbvh, 0, cb, prim_bbc, 0, totprim, nullptr, 0);
 }
 
 static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
@@ -669,7 +671,7 @@ static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
   args->mesh_grids_num = pbvh->totgrid;
   args->node = node;
 
-  BKE_pbvh_node_num_verts(pbvh, node, NULL, &args->node_verts_num);
+  BKE_pbvh_node_num_verts(pbvh, node, nullptr, &args->node_verts_num);
 
   args->grid_hidden = pbvh->grid_hidden;
   args->face_sets_color_default = pbvh->face_sets_color_default;
@@ -680,9 +682,9 @@ static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
   args->mlooptri = pbvh->looptri;
 
   if (ELEM(pbvh->header.type, PBVH_FACES, PBVH_GRIDS)) {
-    args->hide_poly = pbvh->pdata ?
-                          CustomData_get_layer_named(pbvh->pdata, CD_PROP_BOOL, ".hide_poly") :
-                          NULL;
+    args->hide_poly = pbvh->pdata ? static_cast<const bool *>(CustomData_get_layer_named(
+                                        pbvh->pdata, CD_PROP_BOOL, ".hide_poly")) :
+                                    nullptr;
   }
 
   switch (pbvh->header.type) {
@@ -813,30 +815,31 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
                          const MLoop *mloop,
                          float (*vert_positions)[3],
                          int totvert,
-                         struct CustomData *vdata,
-                         struct CustomData *ldata,
-                         struct CustomData *pdata,
+                         CustomData *vdata,
+                         CustomData *ldata,
+                         CustomData *pdata,
                          const MLoopTri *looptri,
                          int looptri_num)
 {
-  BBC *prim_bbc = NULL;
+  BBC *prim_bbc = nullptr;
   BB cb;
 
   pbvh->mesh = mesh;
   pbvh->header.type = PBVH_FACES;
   pbvh->mpoly = mpoly;
-  pbvh->hide_poly = (bool *)CustomData_get_layer_named_for_write(
-      &mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly);
-  pbvh->material_indices = (const int *)CustomData_get_layer_named(
-      &mesh->pdata, CD_PROP_INT32, "material_index");
+  pbvh->hide_poly = static_cast<bool *>(CustomData_get_layer_named_for_write(
+      &mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly));
+  pbvh->material_indices = static_cast<const int *>(
+      CustomData_get_layer_named(&mesh->pdata, CD_PROP_INT32, "material_index"));
   pbvh->mloop = mloop;
   pbvh->looptri = looptri;
   pbvh->vert_positions = vert_positions;
   BKE_mesh_vertex_normals_ensure(mesh);
   pbvh->vert_normals = BKE_mesh_vertex_normals_for_write(mesh);
-  pbvh->hide_vert = (bool *)CustomData_get_layer_named_for_write(
-      &mesh->vdata, CD_PROP_BOOL, ".hide_vert", mesh->totvert);
-  pbvh->vert_bitmap = MEM_calloc_arrayN(totvert, sizeof(bool), "bvh->vert_bitmap");
+  pbvh->hide_vert = static_cast<bool *>(CustomData_get_layer_named_for_write(
+      &mesh->vdata, CD_PROP_BOOL, ".hide_vert", mesh->totvert));
+  pbvh->vert_bitmap = static_cast<bool *>(
+      MEM_calloc_arrayN(totvert, sizeof(bool), "bvh->vert_bitmap"));
   pbvh->totvert = totvert;
 
 #ifdef TEST_PBVH_FACE_SPLIT
@@ -859,7 +862,7 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
   BB_reset(&cb);
 
   /* For each face, store the AABB and the AABB centroid */
-  prim_bbc = MEM_mallocN(sizeof(BBC) * looptri_num, "prim_bbc");
+  prim_bbc = static_cast<BBC *>(MEM_mallocN(sizeof(BBC) * looptri_num, __func__));
 
   for (int i = 0; i < looptri_num; i++) {
     const MLoopTri *lt = &looptri[i];
@@ -948,7 +951,7 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
   BB_reset(&cb);
 
   /* For each grid, store the AABB and the AABB centroid */
-  BBC *prim_bbc = MEM_mallocN(sizeof(BBC) * totgrid, "prim_bbc");
+  BBC *prim_bbc = static_cast<BBC *>(MEM_mallocN(sizeof(BBC) * totgrid, __func__));
 
   for (int 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list