[Bf-blender-cvs] [c8b9ede4b1c] master: Sculpt: Move sculpt_face_set.c to C++

Hans Goudey noreply at git.blender.org
Fri Sep 16 15:20:55 CEST 2022


Commit: c8b9ede4b1c2aef234553e1a455afbc31e96ebd4
Author: Hans Goudey
Date:   Fri Sep 16 07:32:27 2022 -0500
Branches: master
https://developer.blender.org/rBc8b9ede4b1c2aef234553e1a455afbc31e96ebd4

Sculpt: Move sculpt_face_set.c to C++

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

M	source/blender/editors/sculpt_paint/CMakeLists.txt
R092	source/blender/editors/sculpt_paint/sculpt_face_set.c	source/blender/editors/sculpt_paint/sculpt_face_set.cc

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

diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index f4d3002219d..2709ac3fd91 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -68,7 +68,7 @@ set(SRC
   sculpt_detail.c
   sculpt_dyntopo.c
   sculpt_expand.c
-  sculpt_face_set.c
+  sculpt_face_set.cc
   sculpt_filter_color.c
   sculpt_filter_mask.c
   sculpt_filter_mesh.c
diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.c b/source/blender/editors/sculpt_paint/sculpt_face_set.cc
similarity index 92%
rename from source/blender/editors/sculpt_paint/sculpt_face_set.c
rename to source/blender/editors/sculpt_paint/sculpt_face_set.cc
index 091d9fbffe8..447972d74c2 100644
--- a/source/blender/editors/sculpt_paint/sculpt_face_set.c
+++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc
@@ -5,6 +5,9 @@
  * \ingroup edsculpt
  */
 
+#include <cmath>
+#include <cstdlib>
+
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
@@ -53,14 +56,12 @@
 
 #include "bmesh.h"
 
-#include <math.h>
-#include <stdlib.h>
-
 /* Utils. */
 
 int ED_sculpt_face_sets_find_next_available_id(struct Mesh *mesh)
 {
-  const int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
+  const int *face_sets = static_cast<const int *>(
+      CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS));
   if (!face_sets) {
     return SCULPT_FACE_SET_NONE;
   }
@@ -76,7 +77,7 @@ int ED_sculpt_face_sets_find_next_available_id(struct Mesh *mesh)
 
 void ED_sculpt_face_sets_initialize_none_to_id(struct Mesh *mesh, const int new_id)
 {
-  int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
+  int *face_sets = static_cast<int *>(CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS));
   if (!face_sets) {
     return;
   }
@@ -109,7 +110,7 @@ static void do_draw_face_sets_brush_task_cb_ex(void *__restrict userdata,
                                                const int n,
                                                const TaskParallelTLS *__restrict tls)
 {
-  SculptThreadedTaskData *data = userdata;
+  SculptThreadedTaskData *data = static_cast<SculptThreadedTaskData *>(userdata);
   SculptSession *ss = data->ob->sculpt;
   const Brush *brush = data->brush;
   const float bstrength = ss->cache->bstrength;
@@ -180,7 +181,7 @@ static void do_relax_face_sets_brush_task_cb_ex(void *__restrict userdata,
                                                 const int n,
                                                 const TaskParallelTLS *__restrict tls)
 {
-  SculptThreadedTaskData *data = userdata;
+  SculptThreadedTaskData *data = static_cast<SculptThreadedTaskData *>(userdata);
   SculptSession *ss = data->ob->sculpt;
   const Brush *brush = data->brush;
   float bstrength = ss->cache->bstrength;
@@ -233,12 +234,11 @@ void SCULPT_do_draw_face_sets_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, in
   BKE_curvemapping_init(brush->curve);
 
   /* Threaded loop over nodes. */
-  SculptThreadedTaskData data = {
-      .sd = sd,
-      .ob = ob,
-      .brush = brush,
-      .nodes = nodes,
-  };
+  SculptThreadedTaskData data{};
+  data.sd = sd;
+  data.ob = ob;
+  data.brush = brush;
+  data.nodes = nodes;
 
   TaskParallelSettings settings;
   BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -291,7 +291,7 @@ static EnumPropertyItem prop_sculpt_face_set_create_types[] = {
         "Face Set from Edit Mode Selection",
         "Create an Face Set corresponding to the Edit Mode face selection",
     },
-    {0, NULL, 0, NULL, NULL},
+    {0, nullptr, 0, nullptr, nullptr},
 };
 
 static int sculpt_face_set_create_exec(bContext *C, wmOperator *op)
@@ -307,7 +307,7 @@ static int sculpt_face_set_create_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
-  Mesh *mesh = ob->data;
+  Mesh *mesh = static_cast<Mesh *>(ob->data);
   ss->face_sets = BKE_sculpt_face_sets_ensure(mesh);
 
   BKE_sculpt_update_object_for_edit(depsgraph, ob, true, mode == SCULPT_FACE_SET_MASKED, false);
@@ -318,7 +318,7 @@ static int sculpt_face_set_create_exec(bContext *C, wmOperator *op)
   PBVH *pbvh = ob->sculpt->pbvh;
   PBVHNode **nodes;
   int totnode;
-  BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode);
+  BKE_pbvh_search_gather(pbvh, nullptr, nullptr, &nodes, &totnode);
 
   if (!nodes) {
     return OPERATOR_CANCELLED;
@@ -381,17 +381,14 @@ static int sculpt_face_set_create_exec(bContext *C, wmOperator *op)
   if (mode == SCULPT_FACE_SET_SELECTION) {
     BMesh *bm;
     const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(mesh);
-    bm = BM_mesh_create(&allocsize,
-                        &((struct BMeshCreateParams){
-                            .use_toolflags = true,
-                        }));
-
-    BM_mesh_bm_from_me(bm,
-                       mesh,
-                       (&(struct BMeshFromMeshParams){
-                           .calc_face_normal = true,
-                           .calc_vert_normal = true,
-                       }));
+    BMeshCreateParams create_params{};
+    create_params.use_toolflags = true;
+    bm = BM_mesh_create(&allocsize, &create_params);
+
+    BMeshFromMeshParams convert_params{};
+    convert_params.calc_vert_normal = true;
+    convert_params.calc_face_normal = true;
+    BM_mesh_bm_from_me(bm, mesh, &convert_params);
 
     BMIter iter;
     BMFace *f;
@@ -510,7 +507,7 @@ static EnumPropertyItem prop_sculpt_face_sets_init_types[] = {
         "Create a Face Set per isolated Face Set",
     },
 
-    {0, NULL, 0, NULL, NULL},
+    {0, nullptr, 0, nullptr, nullptr},
 };
 
 typedef bool (*face_sets_flood_fill_test)(
@@ -574,20 +571,17 @@ static void sculpt_face_sets_init_flood_fill(Object *ob,
                                              const float threshold)
 {
   SculptSession *ss = ob->sculpt;
-  Mesh *mesh = ob->data;
+  Mesh *mesh = static_cast<Mesh *>(ob->data);
   BMesh *bm;
   const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(mesh);
-  bm = BM_mesh_create(&allocsize,
-                      &((struct BMeshCreateParams){
-                          .use_toolflags = true,
-                      }));
-
-  BM_mesh_bm_from_me(bm,
-                     mesh,
-                     (&(struct BMeshFromMeshParams){
-                         .calc_face_normal = true,
-                         .calc_vert_normal = true,
-                     }));
+  BMeshCreateParams create_params{};
+  create_params.use_toolflags = true;
+  bm = BM_mesh_create(&allocsize, &create_params);
+
+  BMeshFromMeshParams convert_params{};
+  convert_params.calc_vert_normal = true;
+  convert_params.calc_face_normal = true;
+  BM_mesh_bm_from_me(bm, mesh, &convert_params);
 
   BLI_bitmap *visited_faces = BLI_BITMAP_NEW(mesh->totpoly, "visited faces");
   const int totfaces = mesh->totpoly;
@@ -652,21 +646,19 @@ static void sculpt_face_sets_init_flood_fill(Object *ob,
 
 static void sculpt_face_sets_init_loop(Object *ob, const int mode)
 {
-  Mesh *mesh = ob->data;
+  Mesh *mesh = static_cast<Mesh *>(ob->data);
   SculptSession *ss = ob->sculpt;
   BMesh *bm;
   const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(mesh);
-  bm = BM_mesh_create(&allocsize,
-                      &((struct BMeshCreateParams){
-                          .use_toolflags = true,
-                      }));
-
-  BM_mesh_bm_from_me(bm,
-                     mesh,
-                     (&(struct BMeshFromMeshParams){
-                         .calc_face_normal = true,
-                         .calc_vert_normal = true,
-                     }));
+  BMeshCreateParams create_params{};
+  create_params.use_toolflags = true;
+  bm = BM_mesh_create(&allocsize, &create_params);
+
+  BMeshFromMeshParams convert_params{};
+  convert_params.calc_vert_normal = true;
+  convert_params.calc_face_normal = true;
+  BM_mesh_bm_from_me(bm, mesh, &convert_params);
+
   BMIter iter;
   BMFace *f;
 
@@ -706,7 +698,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op)
   PBVH *pbvh = ob->sculpt->pbvh;
   PBVHNode **nodes;
   int totnode;
-  BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode);
+  BKE_pbvh_search_gather(pbvh, nullptr, nullptr, &nodes, &totnode);
 
   if (!nodes) {
     return OPERATOR_CANCELLED;
@@ -717,7 +709,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op)
 
   const float threshold = RNA_float_get(op->ptr, "threshold");
 
-  Mesh *mesh = ob->data;
+  Mesh *mesh = static_cast<Mesh *>(ob->data);
   ss->face_sets = BKE_sculpt_face_sets_ensure(mesh);
 
   switch (mode) {
@@ -765,7 +757,7 @@ static int sculpt_face_set_init_exec(bContext *C, wmOperator *op)
   MEM_SAFE_FREE(nodes);
 
   if (BKE_pbvh_type(pbvh) == PBVH_FACES) {
-    BKE_mesh_flush_hidden_from_verts(ob->data);
+    BKE_mesh_flush_hidden_from_verts(mesh);
   }
 
   SCULPT_tag_update_overlays(C);
@@ -844,7 +836,7 @@ static EnumPropertyItem prop_sculpt_face_sets_change_visibility_types[] = {
         "Show All Face Sets",
         "Show All Face Sets",
     },
-    {0, NULL, 0, NULL, NULL},
+    {0, nullptr, 0, nullptr, nullptr},
 };
 
 static int sculpt_face_sets_change_visibility_exec(bContext *C, wmOperator *op)
@@ -876,7 +868,7 @@ static int sculpt_face_sets_change_visibility_exec(bContext *C, wmOperator *op)
   PBVHNode **nodes;
   int totnode;
 
-  BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode);
+  BKE_pbvh_search_gather(pbvh, nullptr, nullptr, &nodes, &totnode);
 
   if (totnode == 0) {
     MEM_SAFE_FREE(nodes);
@@ -926,7 +918,7 @@ static int sculpt_face_sets_change_visibility_exec(bContext *C, wmOperator *op)
      * reduced memory usage without manually clearing it later, and allows sculpt operations to
      * avoid checking element's hide status. */
     CustomData_free_layer_named(&mesh->pdata, ".hide_poly", mesh->totpoly);
-    ss->hide_poly = NULL;
+    ss->hide_poly = nullptr;
     BKE_pbvh_update_hide_attributes_from_mesh(pbvh);
   }
 
@@ -986,7 +978,7 @@ static int sculpt_face_sets_change_visibility_invoke(bContext *C,
   /* Update the active vertex and Face Set using the cursor position to avoid relying on the paint
    * cursor updates. */
   SculptCursorGeometryInfo sgi;


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list