[Bf-blender-cvs] [feba1fe9748] master: Cleanup: Move gpencil_geom.c to C++

Hans Goudey noreply at git.blender.org
Fri Jul 16 19:01:02 CEST 2021


Commit: feba1fe974870f4d5f77aded3c71ec0983145572
Author: Hans Goudey
Date:   Fri Jul 16 13:00:33 2021 -0400
Branches: master
https://developer.blender.org/rBfeba1fe974870f4d5f77aded3c71ec0983145572

Cleanup: Move gpencil_geom.c to C++

This will help enable development on optimizations to the perimeter
calculation here. Using C++ data structures like Array can make the
code easier to read as well.

Longer term, this can help improve integration with attributes
and possibly the new curve code (since strokes and curves are
quite similar in theory).

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

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

M	source/blender/blenkernel/CMakeLists.txt
R090	source/blender/blenkernel/intern/gpencil_geom.c	source/blender/blenkernel/intern/gpencil_geom.cc

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 2c25b940578..527996ee46d 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -143,7 +143,7 @@ set(SRC
   intern/geometry_set_instances.cc
   intern/gpencil.c
   intern/gpencil_curve.c
-  intern/gpencil_geom.c
+  intern/gpencil_geom.cc
   intern/gpencil_modifier.c
   intern/hair.c
   intern/icons.cc
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.cc
similarity index 90%
rename from source/blender/blenkernel/intern/gpencil_geom.c
rename to source/blender/blenkernel/intern/gpencil_geom.cc
index 4dcd94fdeec..0ed0cbb600e 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.cc
@@ -21,11 +21,11 @@
  * \ingroup bke
  */
 
-#include <math.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstddef>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 
 #include "CLG_log.h"
 
@@ -79,7 +79,7 @@ bool BKE_gpencil_stroke_minmax(const bGPDstroke *gps,
   int i;
   bool changed = false;
 
-  if (ELEM(NULL, gps, r_min, r_max)) {
+  if (ELEM(nullptr, gps, r_min, r_max)) {
     return false;
   }
 
@@ -105,14 +105,14 @@ bool BKE_gpencil_data_minmax(const bGPdata *gpd, float r_min[3], float r_max[3])
 
   INIT_MINMAX(r_min, r_max);
 
-  if (gpd == NULL) {
+  if (gpd == nullptr) {
     return changed;
   }
 
   LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
     bGPDframe *gpf = gpl->actframe;
 
-    if (gpf != NULL) {
+    if (gpf != nullptr) {
       LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
         changed |= BKE_gpencil_stroke_minmax(gps, false, r_min, r_max);
       }
@@ -157,12 +157,12 @@ static void boundbox_gpencil(Object *ob)
   bGPdata *gpd;
   float min[3], max[3];
 
-  if (ob->runtime.bb == NULL) {
-    ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "GPencil boundbox");
+  if (ob->runtime.bb == nullptr) {
+    ob->runtime.bb = (BoundBox *)MEM_callocN(sizeof(BoundBox), "GPencil boundbox");
   }
 
   bb = ob->runtime.bb;
-  gpd = ob->data;
+  gpd = (bGPdata *)ob->data;
 
   if (!BKE_gpencil_data_minmax(gpd, min, max)) {
     min[0] = min[1] = min[2] = -1.0f;
@@ -181,8 +181,8 @@ static void boundbox_gpencil(Object *ob)
  */
 BoundBox *BKE_gpencil_boundbox_get(Object *ob)
 {
-  if (ELEM(NULL, ob, ob->data)) {
-    return NULL;
+  if (ELEM(nullptr, ob, ob->data)) {
+    return nullptr;
   }
 
   bGPdata *gpd = (bGPdata *)ob->data;
@@ -196,9 +196,9 @@ BoundBox *BKE_gpencil_boundbox_get(Object *ob)
   /* Update orig object's boundbox with re-computed evaluated values. This function can be
    * called with the evaluated object and need update the original object bound box data
    * to keep both values synchronized. */
-  if (!ELEM(ob_orig, NULL, ob)) {
-    if (ob_orig->runtime.bb == NULL) {
-      ob_orig->runtime.bb = MEM_callocN(sizeof(BoundBox), "GPencil boundbox");
+  if (!ELEM(ob_orig, nullptr, ob)) {
+    if (ob_orig->runtime.bb == nullptr) {
+      ob_orig->runtime.bb = (BoundBox *)MEM_callocN(sizeof(BoundBox), "GPencil boundbox");
     }
     for (int i = 0; i < 8; i++) {
       copy_v3_v3(ob_orig->runtime.bb->vec[i], ob->runtime.bb->vec[i]);
@@ -227,7 +227,7 @@ static int stroke_march_next_point(const bGPDstroke *gps,
   float step_start[3];
   float point[3];
   int next_point_index = index_next_pt;
-  bGPDspoint *pt = NULL;
+  bGPDspoint *pt = nullptr;
 
   if (!(next_point_index < gps->totpoints)) {
     return -1;
@@ -295,7 +295,7 @@ static int stroke_march_next_point_no_interp(const bGPDstroke *gps,
   float step_start[3];
   float point[3];
   int next_point_index = index_next_pt;
-  bGPDspoint *pt = NULL;
+  bGPDspoint *pt = nullptr;
 
   if (!(next_point_index < gps->totpoints)) {
     return -1;
@@ -336,7 +336,7 @@ static int stroke_march_count(const bGPDstroke *gps, const float dist)
   int point_count = 0;
   float point[3];
   int next_point_index = 1;
-  bGPDspoint *pt = NULL;
+  bGPDspoint *pt = nullptr;
 
   pt = &gps->points[0];
   copy_v3_v3(point, &pt->x);
@@ -369,14 +369,14 @@ static void stroke_defvert_create_nr_list(MDeformVert *dv_list,
     for (j = 0; j < dv->totweight; j++) {
       bool found = false;
       dw = &dv->dw[j];
-      for (ld = result->first; ld; ld = ld->next) {
+      for (ld = (LinkData *)result->first; ld; ld = ld->next) {
         if (ld->data == POINTER_FROM_INT(dw->def_nr)) {
           found = true;
           break;
         }
       }
       if (!found) {
-        ld = MEM_callocN(sizeof(LinkData), "def_nr_item");
+        ld = (LinkData *)MEM_callocN(sizeof(LinkData), "def_nr_item");
         ld->data = POINTER_FROM_INT(dw->def_nr);
         BLI_addtail(result, ld);
         tw++;
@@ -391,14 +391,15 @@ static MDeformVert *stroke_defvert_new_count(int count, int totweight, ListBase
 {
   int i, j;
   LinkData *ld;
-  MDeformVert *dst = MEM_mallocN(count * sizeof(MDeformVert), "new_deformVert");
+  MDeformVert *dst = (MDeformVert *)MEM_mallocN(count * sizeof(MDeformVert), "new_deformVert");
 
   for (i = 0; i < count; i++) {
-    dst[i].dw = MEM_mallocN(sizeof(MDeformWeight) * totweight, "new_deformWeight");
+    dst[i].dw = (MDeformWeight *)MEM_mallocN(sizeof(MDeformWeight) * totweight,
+                                             "new_deformWeight");
     dst[i].totweight = totweight;
     j = 0;
     /* re-assign deform groups */
-    for (ld = def_nr_list->first; ld; ld = ld->next) {
+    for (ld = (LinkData *)def_nr_list->first; ld; ld = ld->next) {
       dst[i].dw[j].def_nr = POINTER_AS_INT(ld->data);
       j++;
     }
@@ -429,10 +430,10 @@ static void stroke_interpolate_deform_weights(
 bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist, const bool select)
 {
   bGPDspoint *pt = gps->points;
-  bGPDspoint *pt1 = NULL;
-  bGPDspoint *pt2 = NULL;
+  bGPDspoint *pt1 = nullptr;
+  bGPDspoint *pt2 = nullptr;
   LinkData *ld;
-  ListBase def_nr_list = {0};
+  ListBase def_nr_list = {nullptr};
 
   if (gps->totpoints < 2 || dist < FLT_EPSILON) {
     return false;
@@ -440,12 +441,13 @@ bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist,
   /* TODO: Implement feature point preservation. */
   int count = stroke_march_count(gps, dist);
 
-  bGPDspoint *new_pt = MEM_callocN(sizeof(bGPDspoint) * count, "gp_stroke_points_sampled");
-  MDeformVert *new_dv = NULL;
+  bGPDspoint *new_pt = (bGPDspoint *)MEM_callocN(sizeof(bGPDspoint) * count,
+                                                 "gp_stroke_points_sampled");
+  MDeformVert *new_dv = nullptr;
 
   int result_totweight;
 
-  if (gps->dvert != NULL) {
+  if (gps->dvert != nullptr) {
     stroke_defvert_create_nr_list(gps->dvert, gps->totpoints, &def_nr_list, &result_totweight);
     new_dv = stroke_defvert_new_count(count, result_totweight, &def_nr_list);
   }
@@ -513,7 +515,7 @@ bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist,
     /* Free original weight data. */
     BKE_gpencil_free_stroke_weights(gps);
     MEM_freeN(gps->dvert);
-    while ((ld = BLI_pophead(&def_nr_list))) {
+    while ((ld = (LinkData *)BLI_pophead(&def_nr_list))) {
       MEM_freeN(ld);
     }
 
@@ -610,26 +612,27 @@ bool BKE_gpencil_stroke_trim_points(bGPDstroke *gps, const int index_from, const
   if (new_count == 1) {
     BKE_gpencil_free_stroke_weights(gps);
     MEM_freeN(gps->points);
-    gps->points = NULL;
-    gps->dvert = NULL;
+    gps->points = nullptr;
+    gps->dvert = nullptr;
     gps->totpoints = 0;
     return false;
   }
 
-  new_pt = MEM_callocN(sizeof(bGPDspoint) * new_count, "gp_stroke_points_trimmed");
+  new_pt = (bGPDspoint *)MEM_callocN(sizeof(bGPDspoint) * new_count, "gp_stroke_points_trimmed");
 
   for (int i = 0; i < new_count; i++) {
     memcpy(&new_pt[i], &pt[i + index_from], sizeof(bGPDspoint));
   }
 
   if (gps->dvert) {
-    new_dv = MEM_callocN(sizeof(MDeformVert) * new_count, "gp_stroke_dverts_trimmed");
+    new_dv = (MDeformVert *)MEM_callocN(sizeof(MDeformVert) * new_count,
+                                        "gp_stroke_dverts_trimmed");
     for (int i = 0; i < new_count; i++) {
       dv = &gps->dvert[i + index_from];
       new_dv[i].flag = dv->flag;
       new_dv[i].totweight = dv->totweight;
-      new_dv[i].dw = MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
-                                 "gp_stroke_dverts_dw_trimmed");
+      new_dv[i].dw = (MDeformWeight *)MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
+                                                  "gp_stroke_dverts_dw_trimmed");
       for (int j = 0; j < dv->totweight; j++) {
         new_dv[i].dw[j].weight = dv->dw[j].weight;
         new_dv[i].dw[j].def_nr = dv->dw[j].def_nr;
@@ -685,14 +688,14 @@ bool BKE_gpencil_stroke_split(bGPdata *gpd,
   }
 
   if (gps->dvert) {
-    new_dv = MEM_callocN(sizeof(MDeformVert) * new_count,
-                         "gp_stroke_dverts_remaining(MDeformVert)");
+    new_dv = (MDeformVert *)MEM_callocN(sizeof(MDeformVert) * new_count,
+                                        "gp_stroke_dverts_remaining(MDeformVert)");
     for (int i = 0; i < new_count; i++) {
       dv = &gps->dvert[i + before_index];
       new_dv[i].flag = dv->flag;
       new_dv[i].totweight = dv->totweight;
-      new_dv[i].dw = MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
-                                 "gp_stroke_dverts_dw_remaining(MDeformWeight)");
+      new_dv[i].dw = (MDeformWeight *)MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
+                                                  "gp_stroke_dverts_dw_remaining(MDeformWeight)");
       for (int j = 0; j < dv->totweight; j++) {
         new_dv[i].dw[j].weight = dv->dw[j].weight;
         new_dv[i].dw[j].def_nr = dv->dw[j].def_nr;
@@ -1301,11 +1304,12 @@ void BKE_gpencil_stroke_fill_triangulate(bGPDstroke *gps)
 
   /* allocate memory for temporary areas */
   gps->tot_triangles = gps->totpoints - 2;
-  uint(*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->tot_triangles,
-                                        "GP Stroke 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list