From 35894dc700e035da914fb8457ef62706c5835391 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 30 Jul 2021 15:08:43 -0400 Subject: 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 --- intern/openvdb/intern/openvdb_level_set.cc | 19 ++++++++----------- intern/openvdb/intern/openvdb_level_set.h | 6 +++--- intern/openvdb/openvdb_capi.cc | 12 ++++++------ intern/openvdb/openvdb_capi.h | 22 +++++++++++----------- intern/quadriflow/quadriflow_capi.cpp | 10 ++++------ intern/quadriflow/quadriflow_capi.hpp | 4 ++-- 6 files changed, 34 insertions(+), 39 deletions(-) (limited to 'intern') 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 points(totvertices); std::vector triangles(totfaces); std::vector 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; -- cgit v1.2.3