[Bf-blender-cvs] [0b793514fab] master: Cleanup: Use bitmaps insteand of bool and char arrays

Pablo Dobarro noreply at git.blender.org
Wed May 27 18:36:35 CEST 2020


Commit: 0b793514fabec9e29b6c72b6ebe3aeebd42416d4
Author: Pablo Dobarro
Date:   Wed May 27 17:42:06 2020 +0200
Branches: master
https://developer.blender.org/rB0b793514fabec9e29b6c72b6ebe3aeebd42416d4

Cleanup: Use bitmaps insteand of bool and char arrays

This was propsed in D7059, so I applied it to the rest of the code

Reviewed By: campbellbarton, sergey

Differential Revision: https://developer.blender.org/D7480

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

M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_face_set.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_pose.c

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

diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 9826cc9571c..4ad6bcc5d0f 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -858,7 +858,7 @@ void SCULPT_floodfill_init(SculptSession *ss, SculptFloodFill *flood)
   SCULPT_vertex_random_access_init(ss);
 
   flood->queue = BLI_gsqueue_new(sizeof(int));
-  flood->visited_vertices = MEM_callocN(vertex_count * sizeof(char), "visited vertices");
+  flood->visited_vertices = BLI_BITMAP_NEW(vertex_count, "visited vertices");
 }
 
 void SCULPT_floodfill_add_initial(SculptFloodFill *flood, int index)
@@ -926,8 +926,8 @@ void SCULPT_floodfill_execute(
     SculptVertexNeighborIter ni;
     SCULPT_VERTEX_DUPLICATES_AND_NEIGHBORS_ITER_BEGIN (ss, from_v, ni) {
       const int to_v = ni.index;
-      if (flood->visited_vertices[to_v] == 0 && SCULPT_vertex_visible_get(ss, to_v)) {
-        flood->visited_vertices[to_v] = 1;
+      if (!BLI_BITMAP_TEST(flood->visited_vertices, to_v) && SCULPT_vertex_visible_get(ss, to_v)) {
+        BLI_BITMAP_ENABLE(flood->visited_vertices, to_v);
 
         if (func(ss, from_v, to_v, ni.is_duplicate, userdata)) {
           BLI_gsqueue_push(flood->queue, &to_v);
@@ -7835,8 +7835,7 @@ void SCULPT_geometry_preview_lines_update(bContext *C, SculptSession *ss, float
   float brush_co[3];
   copy_v3_v3(brush_co, SCULPT_active_vertex_co_get(ss));
 
-  char *visited_vertices = MEM_callocN(SCULPT_vertex_count_get(ss) * sizeof(char),
-                                       "visited vertices");
+  BLI_bitmap *visited_vertices = BLI_BITMAP_NEW(SCULPT_vertex_count_get(ss), "visited_vertices");
 
   /* Assuming an average of 6 edges per vertex in a triangulated mesh. */
   const int max_preview_vertices = SCULPT_vertex_count_get(ss) * 3 * 2;
@@ -7860,8 +7859,8 @@ void SCULPT_geometry_preview_lines_update(bContext *C, SculptSession *ss, float
         totpoints++;
         ss->preview_vert_index_list[totpoints] = to_v;
         totpoints++;
-        if (visited_vertices[to_v] == 0) {
-          visited_vertices[to_v] = 1;
+        if (!BLI_BITMAP_TEST(visited_vertices, to_v)) {
+          BLI_BITMAP_ENABLE(visited_vertices, to_v);
           const float *co = SCULPT_vertex_co_get(ss, to_v);
           if (len_squared_v3v3(brush_co, co) < radius * radius) {
             BLI_gsqueue_push(not_visited_vertices, &to_v);
diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.c b/source/blender/editors/sculpt_paint/sculpt_face_set.c
index 72180ce23d1..cbdbab14690 100644
--- a/source/blender/editors/sculpt_paint/sculpt_face_set.c
+++ b/source/blender/editors/sculpt_paint/sculpt_face_set.c
@@ -523,7 +523,7 @@ static void sculpt_face_sets_init_flood_fill(Object *ob,
                          .calc_face_normal = true,
                      }));
 
-  bool *visited_faces = MEM_callocN(sizeof(bool) * mesh->totpoly, "visited faces");
+  BLI_bitmap *visited_faces = BLI_BITMAP_NEW(mesh->totpoly, "visited faces");
   const int totfaces = mesh->totpoly;
 
   int *face_sets = ss->face_sets;
@@ -534,12 +534,12 @@ static void sculpt_face_sets_init_flood_fill(Object *ob,
   int next_face_set = 1;
 
   for (int i = 0; i < totfaces; i++) {
-    if (!visited_faces[i]) {
+    if (!BLI_BITMAP_TEST(visited_faces, i)) {
       GSQueue *queue;
       queue = BLI_gsqueue_new(sizeof(int));
 
       face_sets[i] = next_face_set;
-      visited_faces[i] = true;
+      BLI_BITMAP_ENABLE(visited_faces, i);
       BLI_gsqueue_push(queue, &i);
 
       while (!BLI_gsqueue_is_empty(queue)) {
@@ -556,10 +556,10 @@ static void sculpt_face_sets_init_flood_fill(Object *ob,
           BM_ITER_ELEM (f_neighbor, &iter_b, ed, BM_FACES_OF_EDGE) {
             if (f_neighbor != f) {
               int neighbor_face_index = BM_elem_index_get(f_neighbor);
-              if (!visited_faces[neighbor_face_index]) {
+              if (!BLI_BITMAP_TEST(visited_faces, neighbor_face_index)) {
                 if (test(bm, f, ed, f_neighbor, threshold)) {
                   face_sets[neighbor_face_index] = next_face_set;
-                  visited_faces[neighbor_face_index] = true;
+                  BLI_BITMAP_ENABLE(visited_faces, neighbor_face_index);
                   BLI_gsqueue_push(queue, &neighbor_face_index);
                 }
               }
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index e00555d93bd..6c217f66940 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -233,7 +233,7 @@ void SCULPT_flip_quat_by_symm_area(float quat[3],
 /* Flood Fill. */
 typedef struct {
   GSQueue *queue;
-  char *visited_vertices;
+  BLI_bitmap *visited_vertices;
 } SculptFloodFill;
 
 void SCULPT_floodfill_init(struct SculptSession *ss, SculptFloodFill *flood);
diff --git a/source/blender/editors/sculpt_paint/sculpt_pose.c b/source/blender/editors/sculpt_paint/sculpt_pose.c
index f01800b2895..35f4870fa12 100644
--- a/source/blender/editors/sculpt_paint/sculpt_pose.c
+++ b/source/blender/editors/sculpt_paint/sculpt_pose.c
@@ -389,7 +389,7 @@ typedef struct PoseFloodFillData {
   GSet *visited_face_sets;
 
   /* In face sets origin mode, each vertex can only be assigned to one face set. */
-  bool *is_weighted;
+  BLI_bitmap *is_weighted;
 
   bool is_first_iteration;
 
@@ -450,7 +450,7 @@ static bool pose_face_sets_floodfill_cb(
   if (data->current_face_set == SCULPT_FACE_SET_NONE) {
 
     data->pose_factor[index] = 1.0f;
-    data->is_weighted[index] = true;
+    BLI_BITMAP_ENABLE(data->is_weighted, index);
 
     if (sculpt_pose_brush_is_vertex_inside_brush_radius(
             co, data->pose_initial_co, data->radius, data->symm)) {
@@ -481,9 +481,9 @@ static bool pose_face_sets_floodfill_cb(
 
   if (is_vertex_valid) {
 
-    if (!data->is_weighted[index]) {
+    if (!BLI_BITMAP_TEST(data->is_weighted, index)) {
       data->pose_factor[index] = 1.0f;
-      data->is_weighted[index] = true;
+      BLI_BITMAP_ENABLE(data->is_weighted, index);
       visit_next = true;
     }
 
@@ -746,7 +746,7 @@ static SculptPoseIKChain *pose_ik_chain_init_face_sets(
 
   GSet *visited_face_sets = BLI_gset_int_new_ex("visited_face_sets", ik_chain->tot_segments);
 
-  bool *is_weighted = MEM_callocN(sizeof(bool) * totvert, "weighted");
+  BLI_bitmap *is_weighted = BLI_BITMAP_NEW(totvert, "weighted");
 
   int current_face_set = SCULPT_FACE_SET_NONE;
   int prev_face_set = SCULPT_FACE_SET_NONE;



More information about the Bf-blender-cvs mailing list