[Bf-blender-cvs] [eccdced972f] master: Cleanup: Moving `mesh_evaluate` and `mesh_normals` to C++

Jagannadhan Ravi noreply at git.blender.org
Wed Jul 7 05:59:38 CEST 2021


Commit: eccdced972f42a451d0c73dfb7ce19a43c120d7f
Author: Jagannadhan Ravi
Date:   Wed Jul 7 13:57:09 2021 +1000
Branches: master
https://developer.blender.org/rBeccdced972f42a451d0c73dfb7ce19a43c120d7f

Cleanup: Moving `mesh_evaluate` and `mesh_normals` to C++

No functional changes.

Reviewed By: HooglyBoogly

Ref D11744

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

M	source/blender/blenkernel/CMakeLists.txt
R095	source/blender/blenkernel/intern/mesh_evaluate.c	source/blender/blenkernel/intern/mesh_evaluate.cc
R090	source/blender/blenkernel/intern/mesh_normals.c	source/blender/blenkernel/intern/mesh_normals.cc

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 7a057d8fc1b..1db23002c1e 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -184,13 +184,13 @@ set(SRC
   intern/mesh.c
   intern/mesh_boolean_convert.cc
   intern/mesh_convert.c
-  intern/mesh_evaluate.c
+  intern/mesh_evaluate.cc
   intern/mesh_fair.cc
   intern/mesh_iterators.c
   intern/mesh_mapping.c
   intern/mesh_merge.c
   intern/mesh_mirror.c
-  intern/mesh_normals.c
+  intern/mesh_normals.cc
   intern/mesh_remap.c
   intern/mesh_remesh_voxel.c
   intern/mesh_runtime.c
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.cc
similarity index 95%
rename from source/blender/blenkernel/intern/mesh_evaluate.c
rename to source/blender/blenkernel/intern/mesh_evaluate.cc
index 7290679bc07..369e3de2c67 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.cc
@@ -23,7 +23,7 @@
  * Functions to evaluate mesh data.
  */
 
-#include <limits.h>
+#include <climits>
 
 #include "MEM_guardedalloc.h"
 
@@ -200,7 +200,7 @@ float BKE_mesh_calc_poly_area(const MPoly *mpoly, const MLoop *loopstart, const
   }
 
   const MLoop *l_iter = loopstart;
-  float(*vertexcos)[3] = BLI_array_alloca(vertexcos, (size_t)mpoly->totloop);
+  float(*vertexcos)[3] = (float(*)[3])BLI_array_alloca(vertexcos, (size_t)mpoly->totloop);
 
   /* pack vertex cos into an array for area_poly_v3 */
   for (int i = 0; i < mpoly->totloop; i++, l_iter++) {
@@ -236,7 +236,7 @@ float BKE_mesh_calc_poly_uv_area(const MPoly *mpoly, const MLoopUV *uv_array)
 
   int i, l_iter = mpoly->loopstart;
   float area;
-  float(*vertexcos)[2] = BLI_array_alloca(vertexcos, (size_t)mpoly->totloop);
+  float(*vertexcos)[2] = (float(*)[2])BLI_array_alloca(vertexcos, (size_t)mpoly->totloop);
 
   /* pack vertex cos into an array for area_poly_v2 */
   for (i = 0; i < mpoly->totloop; i++, l_iter++) {
@@ -404,7 +404,7 @@ void BKE_mesh_poly_edgehash_insert(EdgeHash *ehash, const MPoly *mp, const MLoop
   ml = &ml_next[i - 1]; /* last loop */
 
   while (i-- != 0) {
-    BLI_edgehash_reinsert(ehash, ml->v, ml_next->v, NULL);
+    BLI_edgehash_reinsert(ehash, ml->v, ml_next->v, nullptr);
 
     ml = ml_next;
     ml_next++;
@@ -692,9 +692,9 @@ static void bm_corners_to_loops_ex(ID *id,
   MFace *mf = mface + findex;
 
   for (int i = 0; i < numTex; i++) {
-    MTFace *texface = CustomData_get_n(fdata, CD_MTFACE, findex, i);
+    MTFace *texface = (MTFace *)CustomData_get_n(fdata, CD_MTFACE, findex, i);
 
-    MLoopUV *mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, loopstart, i);
+    MLoopUV *mloopuv = (MLoopUV *)CustomData_get_n(ldata, CD_MLOOPUV, loopstart, i);
     copy_v2_v2(mloopuv->uv, texface->uv[0]);
     mloopuv++;
     copy_v2_v2(mloopuv->uv, texface->uv[1]);
@@ -709,8 +709,8 @@ static void bm_corners_to_loops_ex(ID *id,
   }
 
   for (int i = 0; i < numCol; i++) {
-    MLoopCol *mloopcol = CustomData_get_n(ldata, CD_MLOOPCOL, loopstart, i);
-    MCol *mcol = CustomData_get_n(fdata, CD_MCOL, findex, i);
+    MLoopCol *mloopcol = (MLoopCol *)CustomData_get_n(ldata, CD_MLOOPCOL, loopstart, i);
+    MCol *mcol = (MCol *)CustomData_get_n(fdata, CD_MCOL, findex, i);
 
     MESH_MLOOPCOL_FROM_MCOL(mloopcol, &mcol[0]);
     mloopcol++;
@@ -725,8 +725,8 @@ static void bm_corners_to_loops_ex(ID *id,
   }
 
   if (CustomData_has_layer(fdata, CD_TESSLOOPNORMAL)) {
-    float(*lnors)[3] = CustomData_get(ldata, loopstart, CD_NORMAL);
-    short(*tlnors)[3] = CustomData_get(fdata, findex, CD_TESSLOOPNORMAL);
+    float(*lnors)[3] = (float(*)[3])CustomData_get(ldata, loopstart, CD_NORMAL);
+    short(*tlnors)[3] = (short(*)[3])CustomData_get(fdata, findex, CD_TESSLOOPNORMAL);
     const int max = mf->v4 ? 4 : 3;
 
     for (int i = 0; i < max; i++, lnors++, tlnors++) {
@@ -735,8 +735,8 @@ static void bm_corners_to_loops_ex(ID *id,
   }
 
   if (CustomData_has_layer(fdata, CD_MDISPS)) {
-    MDisps *ld = CustomData_get(ldata, loopstart, CD_MDISPS);
-    MDisps *fd = CustomData_get(fdata, findex, CD_MDISPS);
+    MDisps *ld = (MDisps *)CustomData_get(ldata, loopstart, CD_MDISPS);
+    MDisps *fd = (MDisps *)CustomData_get(fdata, findex, CD_MDISPS);
     float(*disps)[3] = fd->disps;
     int tot = mf->v4 ? 4 : 3;
     int corners;
@@ -767,7 +767,8 @@ static void bm_corners_to_loops_ex(ID *id,
           MEM_freeN(ld->disps);
         }
 
-        ld->disps = MEM_malloc_arrayN((size_t)side_sq, sizeof(float[3]), "converted loop mdisps");
+        ld->disps = (float(*)[3])MEM_malloc_arrayN(
+            (size_t)side_sq, sizeof(float[3]), "converted loop mdisps");
         if (fd->disps) {
           memcpy(ld->disps, disps, (size_t)side_sq * sizeof(float[3]));
         }
@@ -864,7 +865,7 @@ void BKE_mesh_convert_mfaces_to_mpolys_ex(ID *id,
   CustomData_free(pdata, totpoly_i);
 
   totpoly = totface_i;
-  mpoly = MEM_calloc_arrayN((size_t)totpoly, sizeof(MPoly), "mpoly converted");
+  mpoly = (MPoly *)MEM_calloc_arrayN((size_t)totpoly, sizeof(MPoly), "mpoly converted");
   CustomData_add_layer(pdata, CD_MPOLY, CD_ASSIGN, mpoly, totpoly);
 
   numTex = CustomData_number_of_layers(fdata, CD_MTFACE);
@@ -876,7 +877,7 @@ void BKE_mesh_convert_mfaces_to_mpolys_ex(ID *id,
     totloop += mf->v4 ? 4 : 3;
   }
 
-  mloop = MEM_calloc_arrayN((size_t)totloop, sizeof(MLoop), "mloop converted");
+  mloop = (MLoop *)MEM_calloc_arrayN((size_t)totloop, sizeof(MLoop), "mloop converted");
 
   CustomData_add_layer(ldata, CD_MLOOP, CD_ASSIGN, mloop, totloop);
 
@@ -900,7 +901,7 @@ void BKE_mesh_convert_mfaces_to_mpolys_ex(ID *id,
     me->flag &= ~ME_FGON;
   }
 
-  polyindex = CustomData_get_layer(fdata, CD_ORIGINDEX);
+  polyindex = (int *)CustomData_get_layer(fdata, CD_ORIGINDEX);
 
   j = 0; /* current loop index */
   ml = mloop;
@@ -946,7 +947,7 @@ void BKE_mesh_convert_mfaces_to_mpolys_ex(ID *id,
   /* NOTE: we don't convert NGons at all, these are not even real ngons,
    * they have their own UV's, colors etc - its more an editing feature. */
 
-  BLI_edgehash_free(eh, NULL);
+  BLI_edgehash_free(eh, nullptr);
 
   *r_totpoly = totpoly;
   *r_totloop = totloop;
@@ -1050,8 +1051,8 @@ void BKE_mesh_polygon_flip_ex(MPoly *mpoly,
 
 void BKE_mesh_polygon_flip(MPoly *mpoly, MLoop *mloop, CustomData *ldata)
 {
-  MDisps *mdisp = CustomData_get_layer(ldata, CD_MDISPS);
-  BKE_mesh_polygon_flip_ex(mpoly, mloop, ldata, NULL, mdisp, true);
+  MDisps *mdisp = (MDisps *)CustomData_get_layer(ldata, CD_MDISPS);
+  BKE_mesh_polygon_flip_ex(mpoly, mloop, ldata, nullptr, mdisp, true);
 }
 
 /**
@@ -1061,12 +1062,12 @@ void BKE_mesh_polygon_flip(MPoly *mpoly, MLoop *mloop, CustomData *ldata)
  */
 void BKE_mesh_polygons_flip(MPoly *mpoly, MLoop *mloop, CustomData *ldata, int totpoly)
 {
-  MDisps *mdisp = CustomData_get_layer(ldata, CD_MDISPS);
+  MDisps *mdisp = (MDisps *)CustomData_get_layer(ldata, CD_MDISPS);
   MPoly *mp;
   int i;
 
   for (mp = mpoly, i = 0; i < totpoly; mp++, i++) {
-    BKE_mesh_polygon_flip_ex(mp, mloop, ldata, NULL, mdisp, true);
+    BKE_mesh_polygon_flip_ex(mp, mloop, ldata, nullptr, mdisp, true);
   }
 }
 
@@ -1277,7 +1278,7 @@ void BKE_mesh_calc_relative_deform(const MPoly *mpoly,
   const MPoly *mp;
   int i;
 
-  int *vert_accum = MEM_calloc_arrayN((size_t)totvert, sizeof(*vert_accum), __func__);
+  int *vert_accum = (int *)MEM_calloc_arrayN((size_t)totvert, sizeof(*vert_accum), __func__);
 
   memset(vert_cos_new, '\0', sizeof(*vert_cos_new) * (size_t)totvert);
 
diff --git a/source/blender/blenkernel/intern/mesh_normals.c b/source/blender/blenkernel/intern/mesh_normals.cc
similarity index 90%
rename from source/blender/blenkernel/intern/mesh_normals.c
rename to source/blender/blenkernel/intern/mesh_normals.cc
index 89fd7f92d94..2fe132fc684 100644
--- a/source/blender/blenkernel/intern/mesh_normals.c
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@ -25,7 +25,7 @@
  * \see bmesh_mesh_normals.c for the equivalent #BMesh functionality.
  */
 
-#include <limits.h>
+#include <climits>
 
 #include "CLG_log.h"
 
@@ -90,15 +90,15 @@ void BKE_mesh_calc_normals_mapping_simple(struct Mesh *mesh)
                                    mesh->mpoly,
                                    mesh->totloop,
                                    mesh->totpoly,
-                                   NULL,
+                                   nullptr,
                                    mesh->mface,
                                    mesh->totface,
-                                   NULL,
-                                   NULL,
+                                   nullptr,
+                                   nullptr,
                                    only_face_normals);
 }
 
-/* Calculate vertex and face normals, face normals are returned in *r_faceNors if non-NULL
+/* Calculate vertex and face normals, face normals are returned in *r_faceNors if non-nullptr
  * and vertex normals are stored in actual mverts.
  */
 void BKE_mesh_calc_normals_mapping(MVert *mverts,
@@ -150,13 +150,13 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts,
   }
 
   /* if we are not calculating verts and no verts were passes then we have nothing to do */
-  if ((only_face_normals == true) && (r_polyNors == NULL) && (r_faceNors == NULL)) {
+  if ((only_face_normals == true) && (r_polyNors == nullptr) && (r_faceNors == nullptr)) {
     CLOG_WARN(&LOG, "called with nothing to do");
     return;
   }
 
   if (!pnors) {
-    pnors = MEM_calloc_arrayN((size_t)numPolys, sizeof(float[3]), __func__);
+    pnors = (float(*)[3])MEM_calloc_arrayN((size_t)numPolys, sizeof(float[3]), __func__);
   }
   /* NO NEED TO ALLOC YET */
   /* if (!fnors) fnors = MEM_calloc_arrayN(numFaces, sizeof(float[3]), "face nors mesh.c"); */
@@ -165,7 +165,7 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts,
     /* vertex normals are optional, they require some extra calculations,
      * so make them optional */
     BKE_mesh_calc_normals_poly(
-        mverts, NULL, numVerts, mloop, mpolys, numLoops, numPolys, pnors, false);
+        mverts, nullptr, numVerts, mloop, mpolys, numLoops, numPolys, pnors, false)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list