[Bf-blender-cvs] [718d545ff88] master: Cleanup: minor improvement to boundary check

Campbell Barton noreply at git.blender.org
Thu Sep 15 08:58:54 CEST 2022


Commit: 718d545ff88f3092f4bd6baef3e3d5642109da0c
Author: Campbell Barton
Date:   Thu Sep 15 16:42:37 2022 +1000
Branches: master
https://developer.blender.org/rB718d545ff88f3092f4bd6baef3e3d5642109da0c

Cleanup: minor improvement to boundary check

Use a byte flag instead of counting polys using edges
(technically a fix for edges with USHRT_MAX+2 users).

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

M	source/blender/modifiers/intern/MOD_correctivesmooth.c

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

diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c
index 4fdbe44281b..5e46e98263c 100644
--- a/source/blender/modifiers/intern/MOD_correctivesmooth.c
+++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c
@@ -130,25 +130,24 @@ static void mesh_get_boundaries(Mesh *mesh, float *smooth_weights)
   const MEdge *medge = BKE_mesh_edges(mesh);
   const MPoly *mpoly = BKE_mesh_polys(mesh);
   const MLoop *mloop = BKE_mesh_loops(mesh);
-  uint mpoly_num, medge_num, i;
-  ushort *boundaries;
 
-  mpoly_num = (uint)mesh->totpoly;
-  medge_num = (uint)mesh->totedge;
+  const uint mpoly_num = (uint)mesh->totpoly;
+  const uint medge_num = (uint)mesh->totedge;
 
-  boundaries = MEM_calloc_arrayN(medge_num, sizeof(*boundaries), __func__);
+  /* Flag boundary edges so only boundaries are set to 1. */
+  uint8_t *boundaries = MEM_calloc_arrayN(medge_num, sizeof(*boundaries), __func__);
 
-  /* count the number of adjacent faces */
-  for (i = 0; i < mpoly_num; i++) {
+  for (uint i = 0; i < mpoly_num; i++) {
     const MPoly *p = &mpoly[i];
     const int totloop = p->totloop;
     int j;
     for (j = 0; j < totloop; j++) {
-      boundaries[mloop[p->loopstart + j].e]++;
+      uint8_t *e_value = &boundaries[mloop[p->loopstart + j].e];
+      *e_value |= (*e_value) + 1;
     }
   }
 
-  for (i = 0; i < medge_num; i++) {
+  for (uint i = 0; i < medge_num; i++) {
     if (boundaries[i] == 1) {
       smooth_weights[medge[i].v1] = 0.0f;
       smooth_weights[medge[i].v2] = 0.0f;



More information about the Bf-blender-cvs mailing list