[Bf-blender-cvs] [fcb0425f64c] master: Sculpt: Remove old connected component API in favor of new island API

Joseph Eagar noreply at git.blender.org
Fri Jan 20 03:24:05 CET 2023


Commit: fcb0425f64c4b3652e513420fd7b1a59951e39a3
Author: Joseph Eagar
Date:   Thu Jan 19 18:22:59 2023 -0800
Branches: master
https://developer.blender.org/rBfcb0425f64c4b3652e513420fd7b1a59951e39a3

Sculpt: Remove old connected component API in favor of new island API

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/paint.cc
M	source/blender/editors/sculpt_paint/sculpt.cc
M	source/blender/editors/sculpt_paint/sculpt_expand.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_mask_init.c

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index aefb33357a2..1a380addfbb 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -392,9 +392,6 @@ typedef struct SculptPersistentBase {
 } SculptPersistentBase;
 
 typedef struct SculptVertexInfo {
-  /* Indexed by vertex, stores and ID of its topologically connected component. */
-  int *connected_component;
-
   /* Indexed by base mesh vertex index, stores if that vertex is a boundary. */
   BLI_bitmap *boundary;
 } SculptVertexInfo;
diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc
index 1d416eec1e8..0ee517311d2 100644
--- a/source/blender/blenkernel/intern/paint.cc
+++ b/source/blender/blenkernel/intern/paint.cc
@@ -1454,7 +1454,6 @@ static void sculptsession_free_pbvh(Object *object)
   MEM_SAFE_FREE(ss->preview_vert_list);
   ss->preview_vert_count = 0;
 
-  MEM_SAFE_FREE(ss->vertex_info.connected_component);
   MEM_SAFE_FREE(ss->vertex_info.boundary);
 
   MEM_SAFE_FREE(ss->fake_neighbors.fake_neighbor_index);
diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc
index a26cf16b78a..676f2de49ef 100644
--- a/source/blender/editors/sculpt_paint/sculpt.cc
+++ b/source/blender/editors/sculpt_paint/sculpt.cc
@@ -3351,7 +3351,6 @@ static void sculpt_topology_update(Sculpt *sd,
   /* Free index based vertex info as it will become invalid after modifying the topology during the
    * stroke. */
   MEM_SAFE_FREE(ss->vertex_info.boundary);
-  MEM_SAFE_FREE(ss->vertex_info.connected_component);
 
   PBVHTopologyUpdateMode mode = PBVHTopologyUpdateMode(0);
   float location[3];
@@ -5928,14 +5927,6 @@ enum {
   SCULPT_TOPOLOGY_ID_DEFAULT,
 };
 
-static int SCULPT_vertex_get_connected_component(SculptSession *ss, PBVHVertRef vertex)
-{
-  if (ss->vertex_info.connected_component) {
-    return ss->vertex_info.connected_component[vertex.i];
-  }
-  return SCULPT_TOPOLOGY_ID_DEFAULT;
-}
-
 static void SCULPT_fake_neighbor_init(SculptSession *ss, const float max_dist)
 {
   const int totvert = SCULPT_vertex_count_get(ss);
@@ -5981,7 +5972,7 @@ static void do_fake_neighbor_search_task_cb(void *__restrict userdata,
   PBVHVertexIter vd;
 
   BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
-    int vd_topology_id = SCULPT_vertex_get_connected_component(ss, vd.vertex);
+    int vd_topology_id = SCULPT_vertex_island_get(ss, vd.vertex);
     if (vd_topology_id != nvtd->current_topology_id &&
         ss->fake_neighbors.fake_neighbor_index[vd.index] == FAKE_NEIGHBOR_NONE) {
       float distance_squared = len_squared_v3v3(vd.co, data->nearest_vertex_search_co);
@@ -6044,7 +6035,7 @@ static PBVHVertRef SCULPT_fake_neighbor_search(Sculpt *sd,
   NearestVertexFakeNeighborTLSData nvtd;
   nvtd.nearest_vertex.i = -1;
   nvtd.nearest_vertex_distance_squared = FLT_MAX;
-  nvtd.current_topology_id = SCULPT_vertex_get_connected_component(ss, vertex);
+  nvtd.current_topology_id = SCULPT_vertex_island_get(ss, vertex);
 
   TaskParallelSettings settings;
   BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -6062,55 +6053,6 @@ struct SculptTopologyIDFloodFillData {
   int next_id;
 };
 
-static bool SCULPT_connected_components_floodfill_cb(
-    SculptSession *ss, PBVHVertRef from_v, PBVHVertRef to_v, bool /*is_duplicate*/, void *userdata)
-{
-  SculptTopologyIDFloodFillData *data = static_cast<SculptTopologyIDFloodFillData *>(userdata);
-
-  int from_v_i = BKE_pbvh_vertex_to_index(ss->pbvh, from_v);
-  int to_v_i = BKE_pbvh_vertex_to_index(ss->pbvh, to_v);
-
-  ss->vertex_info.connected_component[from_v_i] = data->next_id;
-  ss->vertex_info.connected_component[to_v_i] = data->next_id;
-  return true;
-}
-
-void SCULPT_connected_components_ensure(Object *ob)
-{
-  SculptSession *ss = ob->sculpt;
-
-  /* Topology IDs already initialized. They only need to be recalculated when the PBVH is
-   * rebuild.
-   */
-  if (ss->vertex_info.connected_component) {
-    return;
-  }
-
-  const int totvert = SCULPT_vertex_count_get(ss);
-  ss->vertex_info.connected_component = static_cast<int *>(
-      MEM_malloc_arrayN(totvert, sizeof(int), "topology ID"));
-
-  for (int i = 0; i < totvert; i++) {
-    ss->vertex_info.connected_component[i] = SCULPT_TOPOLOGY_ID_NONE;
-  }
-
-  int next_id = 0;
-  for (int i = 0; i < totvert; i++) {
-    PBVHVertRef vertex = BKE_pbvh_index_to_vertex(ss->pbvh, i);
-
-    if (ss->vertex_info.connected_component[i] == SCULPT_TOPOLOGY_ID_NONE) {
-      SculptFloodFill flood;
-      SCULPT_floodfill_init(ss, &flood);
-      SCULPT_floodfill_add_initial(&flood, vertex);
-      SculptTopologyIDFloodFillData data;
-      data.next_id = next_id;
-      SCULPT_floodfill_execute(ss, &flood, SCULPT_connected_components_floodfill_cb, &data);
-      SCULPT_floodfill_free(&flood);
-      next_id++;
-    }
-  }
-}
-
 void SCULPT_boundary_info_ensure(Object *object)
 {
   SculptSession *ss = object->sculpt;
@@ -6159,7 +6101,7 @@ void SCULPT_fake_neighbors_ensure(Sculpt *sd, Object *ob, const float max_dist)
     return;
   }
 
-  SCULPT_connected_components_ensure(ob);
+  SCULPT_topology_islands_ensure(ob);
   SCULPT_fake_neighbor_init(ss, max_dist);
 
   for (int i = 0; i < totvert; i++) {
diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c
index 683eeed5111..028ac847529 100644
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@ -133,10 +133,8 @@ static bool sculpt_expand_is_vert_in_active_component(SculptSession *ss,
                                                       ExpandCache *expand_cache,
                                                       const PBVHVertRef v)
 {
-  int v_i = BKE_pbvh_vertex_to_index(ss->pbvh, v);
-
   for (int i = 0; i < EXPAND_SYMM_AREAS; i++) {
-    if (ss->vertex_info.connected_component[v_i] == expand_cache->active_connected_components[i]) {
+    if (SCULPT_vertex_island_get(ss, v) == expand_cache->active_connected_islands[i]) {
       return true;
     }
   }
@@ -403,8 +401,6 @@ static void sculpt_expand_check_topology_islands(Object *ob)
 
   if (ss->expand_cache->check_islands) {
     SCULPT_topology_islands_ensure(ob);
-    ss->expand_cache->initial_island_key = SCULPT_vertex_island_get(
-        ss, ss->expand_cache->initial_active_vertex);
   }
 }
 
@@ -1269,7 +1265,7 @@ static void sculpt_expand_mask_update_task_cb(void *__restrict userdata,
     const bool enabled = sculpt_expand_state_get(ss, expand_cache, vd.vertex);
 
     if (expand_cache->check_islands &&
-        SCULPT_vertex_island_get(ss, vd.vertex) != expand_cache->initial_island_key) {
+        !sculpt_expand_is_vert_in_active_component(ss, expand_cache, vd.vertex)) {
       continue;
     }
 
@@ -1632,7 +1628,7 @@ static void sculpt_expand_find_active_connected_components_from_vert(
 {
   SculptSession *ss = ob->sculpt;
   for (int i = 0; i < EXPAND_SYMM_AREAS; i++) {
-    expand_cache->active_connected_components[i] = EXPAND_ACTIVE_COMPONENT_NONE;
+    expand_cache->active_connected_islands[i] = EXPAND_ACTIVE_COMPONENT_NONE;
   }
 
   const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
@@ -1644,10 +1640,8 @@ static void sculpt_expand_find_active_connected_components_from_vert(
     const PBVHVertRef symm_vertex = sculpt_expand_get_vertex_index_for_symmetry_pass(
         ob, symm_it, initial_vertex);
 
-    int symm_vertex_i = BKE_pbvh_vertex_to_index(ss->pbvh, symm_vertex);
-
-    expand_cache->active_connected_components[(int)symm_it] =
-        ss->vertex_info.connected_component[symm_vertex_i];
+    expand_cache->active_connected_islands[(int)symm_it] = SCULPT_vertex_island_get(
+        ss, symm_vertex);
   }
 }
 
@@ -1727,8 +1721,8 @@ static void sculpt_expand_move_propagation_origin(bContext *C,
 static void sculpt_expand_ensure_sculptsession_data(Object *ob)
 {
   SculptSession *ss = ob->sculpt;
+  SCULPT_topology_islands_ensure(ob);
   SCULPT_vertex_random_access_ensure(ss);
-  SCULPT_connected_components_ensure(ob);
   SCULPT_boundary_info_ensure(ob);
   if (!ss->tex_pool) {
     ss->tex_pool = BKE_image_pool_new();
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index b053b2764ca..ffd1554be89 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -744,11 +744,11 @@ typedef struct ExpandCache {
    * initial position of Expand. */
   float original_mouse_move[2];
 
-  /* Active components checks. */
-  /* Indexed by symmetry pass index, contains the connected component ID found in
-   * SculptSession->vertex_info.connected_component. Other connected components not found in this
+  /* Active island checks. */
+  /* Indexed by symmetry pass index, contains the connected island ID for that
+   * symmetry pass. Other connected island IDs not found in this
    * array will be ignored by Expand. */
-  int active_connected_components[EXPAND_SYMM_AREAS];
+  int active_connected_islands[EXPAND_SYMM_AREAS];
 
   /* Snapping. */
   /* GSet containing all Face Sets IDs that Expand will use to snap the new data. */
@@ -819,7 +819,6 @@ typedef struct ExpandCache {
   int *original_face_sets;
   float (*original_colors)[4];
 
-  int initial_island_key;
   bool check_islands;
 } ExpandCache;
 /** \} */
@@ -1028,8 +1027,6 @@ void SCULPT_boundary_info_ensure(Object *object);
 /* Boundary Info needs to be initialized in order to use this function. */
 bool SCULPT_vertex_is_boundary(const SculptSession *ss, PBVHVertRef vertex);
 
-void SCULPT_connected_components_ensure(Object *ob);
-
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/sculpt_paint/sculpt_mask_init.c b/source/blender/editors/sculpt_paint/sculpt_mask_init.c
index 99a7bb8a926..a4f29fd758a 100644
--- a/source/blender/editors/sculpt_paint/sculpt_mask_init.c
+++ b/source/blender/editors/sculpt_paint/sculpt_mask_init.c
@@ -95,7 +95,7 @@ static void mask_init_task_cb(void *__restrict userdata

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list