[Bf-blender-cvs] [35894dc700e] master: Cleanup: Simplify logic, follow style guide for integer types

Hans Goudey noreply at git.blender.org
Fri Jul 30 21:09:03 CEST 2021


Commit: 35894dc700e035da914fb8457ef62706c5835391
Author: Hans Goudey
Date:   Fri Jul 30 15:08:43 2021 -0400
Branches: master
https://developer.blender.org/rB35894dc700e035da914fb8457ef62706c5835391

Cleanup: Simplify logic, follow style guide for integer types

- Use `int` instead of `unsigned int` for mesh indices
- Use C++ types (Array, float3, IndexRange)
- Use range based for loops

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

M	intern/openvdb/intern/openvdb_level_set.cc
M	intern/openvdb/intern/openvdb_level_set.h
M	intern/openvdb/openvdb_capi.cc
M	intern/openvdb/openvdb_capi.h
M	intern/quadriflow/quadriflow_capi.cpp
M	intern/quadriflow/quadriflow_capi.hpp
M	source/blender/blenkernel/intern/mesh_remesh_voxel.cc

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

diff --git a/intern/openvdb/intern/openvdb_level_set.cc b/intern/openvdb/intern/openvdb_level_set.cc
index ed0020a66ce..5b01c3b0cb7 100644
--- a/intern/openvdb/intern/openvdb_level_set.cc
+++ b/intern/openvdb/intern/openvdb_level_set.cc
@@ -33,20 +33,20 @@ OpenVDBLevelSet::~OpenVDBLevelSet()
 }
 
 void OpenVDBLevelSet::mesh_to_level_set(const float *vertices,
-                                        const unsigned int *faces,
-                                        const unsigned int totvertices,
-                                        const unsigned int totfaces,
+                                        const int *faces,
+                                        const int totvertices,
+                                        const int totfaces,
                                         const openvdb::math::Transform::Ptr &xform)
 {
   std::vector<openvdb::Vec3s> points(totvertices);
   std::vector<openvdb::Vec3I> triangles(totfaces);
   std::vector<openvdb::Vec4I> quads;
 
-  for (unsigned int i = 0; i < totvertices; i++) {
+  for (int i = 0; i < totvertices; i++) {
     points[i] = openvdb::Vec3s(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]);
   }
 
-  for (unsigned int i = 0; i < totfaces; i++) {
+  for (int i = 0; i < totfaces; i++) {
     triangles[i] = openvdb::Vec3I(faces[i * 3], faces[i * 3 + 1], faces[i * 3 + 2]);
   }
 
@@ -69,14 +69,11 @@ void OpenVDBLevelSet::volume_to_mesh(OpenVDBVolumeToMeshData *mesh,
                                                    isovalue,
                                                    adaptivity,
                                                    relax_disoriented_triangles);
-  mesh->vertices = (float *)MEM_malloc_arrayN(
-      out_points.size(), 3 * sizeof(float), "openvdb remesher out verts");
-  mesh->quads = (unsigned int *)MEM_malloc_arrayN(
-      out_quads.size(), 4 * sizeof(unsigned int), "openvdb remesh out quads");
+  mesh->vertices = (float *)MEM_malloc_arrayN(out_points.size(), sizeof(float[3]), __func__);
+  mesh->quads = (int *)MEM_malloc_arrayN(out_quads.size(), sizeof(int[4]), __func__);
   mesh->triangles = NULL;
   if (out_tris.size() > 0) {
-    mesh->triangles = (unsigned int *)MEM_malloc_arrayN(
-        out_tris.size(), 3 * sizeof(unsigned int), "openvdb remesh out tris");
+    mesh->triangles = (int *)MEM_malloc_arrayN(out_tris.size(), sizeof(int[3]), __func__);
   }
 
   mesh->totvertices = out_points.size();
diff --git a/intern/openvdb/intern/openvdb_level_set.h b/intern/openvdb/intern/openvdb_level_set.h
index 882958513fd..2c8f140c012 100644
--- a/intern/openvdb/intern/openvdb_level_set.h
+++ b/intern/openvdb/intern/openvdb_level_set.h
@@ -39,9 +39,9 @@ struct OpenVDBLevelSet {
   void set_grid(const openvdb::FloatGrid::Ptr &grid);
 
   void mesh_to_level_set(const float *vertices,
-                         const unsigned int *faces,
-                         const unsigned int totvertices,
-                         const unsigned int totfaces,
+                         const int *faces,
+                         const int totvertices,
+                         const int totfaces,
                          const openvdb::math::Transform::Ptr &transform);
 
   void volume_to_mesh(struct OpenVDBVolumeToMeshData *mesh,
diff --git a/intern/openvdb/openvdb_capi.cc b/intern/openvdb/openvdb_capi.cc
index e7a4bf335fc..674b394fa46 100644
--- a/intern/openvdb/openvdb_capi.cc
+++ b/intern/openvdb/openvdb_capi.cc
@@ -63,9 +63,9 @@ void OpenVDBLevelSet_free(OpenVDBLevelSet *level_set)
 
 void OpenVDBLevelSet_mesh_to_level_set(struct OpenVDBLevelSet *level_set,
                                        const float *vertices,
-                                       const unsigned int *faces,
-                                       const unsigned int totvertices,
-                                       const unsigned int totfaces,
+                                       const int *faces,
+                                       const int totvertices,
+                                       const int totfaces,
                                        OpenVDBTransform *xform)
 {
   level_set->mesh_to_level_set(vertices, faces, totvertices, totfaces, xform->get_transform());
@@ -73,9 +73,9 @@ void OpenVDBLevelSet_mesh_to_level_set(struct OpenVDBLevelSet *level_set,
 
 void OpenVDBLevelSet_mesh_to_level_set_transform(struct OpenVDBLevelSet *level_set,
                                                  const float *vertices,
-                                                 const unsigned int *faces,
-                                                 const unsigned int totvertices,
-                                                 const unsigned int totfaces,
+                                                 const int *faces,
+                                                 const int totvertices,
+                                                 const int totfaces,
                                                  OpenVDBTransform *transform)
 {
   level_set->mesh_to_level_set(vertices, faces, totvertices, totfaces, transform->get_transform());
diff --git a/intern/openvdb/openvdb_capi.h b/intern/openvdb/openvdb_capi.h
index 98d89c340bf..9333413c2fe 100644
--- a/intern/openvdb/openvdb_capi.h
+++ b/intern/openvdb/openvdb_capi.h
@@ -67,19 +67,19 @@ struct OpenVDBVolumeToMeshData {
   int totvertices;
 
   float *vertices;
-  unsigned int *quads;
-  unsigned int *triangles;
+  int *quads;
+  int *triangles;
 };
 
 struct OpenVDBRemeshData {
   float *verts;
-  unsigned int *faces;
+  int *faces;
   int totfaces;
   int totverts;
 
   float *out_verts;
-  unsigned int *out_faces;
-  unsigned int *out_tris;
+  int *out_faces;
+  int *out_tris;
   int out_totverts;
   int out_totfaces;
   int out_tottris;
@@ -112,15 +112,15 @@ struct OpenVDBLevelSet *OpenVDBLevelSet_create(bool initGrid, struct OpenVDBTran
 void OpenVDBLevelSet_free(struct OpenVDBLevelSet *level_set);
 void OpenVDBLevelSet_mesh_to_level_set(struct OpenVDBLevelSet *level_set,
                                        const float *vertices,
-                                       const unsigned int *faces,
-                                       const unsigned int totvertices,
-                                       const unsigned int totfaces,
+                                       const int *faces,
+                                       const int totvertices,
+                                       const int totfaces,
                                        struct OpenVDBTransform *xform);
 void OpenVDBLevelSet_mesh_to_level_set_transform(struct OpenVDBLevelSet *level_set,
                                                  const float *vertices,
-                                                 const unsigned int *faces,
-                                                 const unsigned int totvertices,
-                                                 const unsigned int totfaces,
+                                                 const int *faces,
+                                                 const int totvertices,
+                                                 const int totfaces,
                                                  struct OpenVDBTransform *transform);
 void OpenVDBLevelSet_volume_to_mesh(struct OpenVDBLevelSet *level_set,
                                     struct OpenVDBVolumeToMeshData *mesh,
diff --git a/intern/quadriflow/quadriflow_capi.cpp b/intern/quadriflow/quadriflow_capi.cpp
index 53237289874..086d5f7d296 100644
--- a/intern/quadriflow/quadriflow_capi.cpp
+++ b/intern/quadriflow/quadriflow_capi.cpp
@@ -20,12 +20,12 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "quadriflow_capi.hpp"
 #include "config.hpp"
 #include "field-math.hpp"
+#include "loader.hpp"
 #include "optimizer.hpp"
 #include "parametrizer.hpp"
-#include "loader.hpp"
+#include "quadriflow_capi.hpp"
 
 using namespace qflow;
 
@@ -217,10 +217,8 @@ void QFLOW_quadriflow_remesh(QuadriflowRemeshData *qrd,
   qrd->out_totverts = field.O_compact.size();
   qrd->out_totfaces = field.F_compact.size();
 
-  qrd->out_verts = (float *)MEM_malloc_arrayN(
-      qrd->out_totverts, 3 * sizeof(float), "quadriflow remesher out verts");
-  qrd->out_faces = (unsigned int *)MEM_malloc_arrayN(
-      qrd->out_totfaces, 4 * sizeof(unsigned int), "quadriflow remesh out quads");
+  qrd->out_verts = (float *)MEM_malloc_arrayN(qrd->out_totverts, sizeof(float[3]), __func__);
+  qrd->out_faces = (int *)MEM_malloc_arrayN(qrd->out_totfaces, sizeof(int[4]), __func__);
 
   for (int i = 0; i < qrd->out_totverts; i++) {
     auto t = field.O_compact[i] * field.normalize_scale + field.normalize_offset;
diff --git a/intern/quadriflow/quadriflow_capi.hpp b/intern/quadriflow/quadriflow_capi.hpp
index c31fd6eff95..59af2826e15 100644
--- a/intern/quadriflow/quadriflow_capi.hpp
+++ b/intern/quadriflow/quadriflow_capi.hpp
@@ -25,12 +25,12 @@ extern "C" {
 
 typedef struct QuadriflowRemeshData {
   float *verts;
-  unsigned int *faces;
+  int *faces;
   int totfaces;
   int totverts;
 
   float *out_verts;
-  unsigned int *out_faces;
+  int *out_faces;
   int out_totverts;
   int out_totfaces;
 
diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
index 5c5d86d3e34..059094090f2 100644
--- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
+++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
@@ -30,7 +30,10 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_array.hh"
 #include "BLI_blenlib.h"
+#include "BLI_float3.hh"
+#include "BLI_index_range.hh"
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
@@ -56,6 +59,10 @@
 #  include "quadriflow_capi.hpp"
 #endif
 
+using blender::Array;
+using blender::float3;
+using blender::IndexRange;
+
 #ifdef WITH_OPENVDB
 struct OpenVDBLevelSet *BKE_mesh_remesh_voxel_ovdb_mesh_to_level_set_create(
     Mesh *mesh, struct OpenVDBTransform *transform)
@@ -67,30 +74,26 @@ struct OpenVDBLevelSet *BKE_mesh_remesh_voxel_ovdb_mesh_to_level_set_create(
   BKE_mesh_runtime_verttri_from_looptri(
       verttri, mesh->mloop, looptri, BKE_mesh_runtime_looptri_len(mesh));
 
-  uint totfaces = BKE_mesh_runtime_looptri_len(mesh);
-  uint totverts = mesh->totvert;
-  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list