[Bf-blender-cvs] [5fe146e505d] master: Cleanup: Move mesh_remap.c to C++
Hans Goudey
noreply at git.blender.org
Mon Nov 14 03:28:10 CET 2022
Commit: 5fe146e505d4a52287e4960aefaf801e5dae3029
Author: Hans Goudey
Date: Sun Nov 13 20:26:00 2022 -0600
Branches: master
https://developer.blender.org/rB5fe146e505d4a52287e4960aefaf801e5dae3029
Cleanup: Move mesh_remap.c to C++
To facilitate further mesh data structure refactoring.
===================================================================
M source/blender/blenkernel/CMakeLists.txt
R093 source/blender/blenkernel/intern/mesh_remap.c source/blender/blenkernel/intern/mesh_remap.cc
===================================================================
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index d85c7791df6..6b8160aaeda 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -209,7 +209,7 @@ set(SRC
intern/mesh_merge_customdata.cc
intern/mesh_mirror.c
intern/mesh_normals.cc
- intern/mesh_remap.c
+ intern/mesh_remap.cc
intern/mesh_remesh_voxel.cc
intern/mesh_runtime.cc
intern/mesh_sample.cc
diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.cc
similarity index 93%
rename from source/blender/blenkernel/intern/mesh_remap.c
rename to source/blender/blenkernel/intern/mesh_remap.cc
index d96cd54e198..e9f032a40f8 100644
--- a/source/blender/blenkernel/intern/mesh_remap.c
+++ b/source/blender/blenkernel/intern/mesh_remap.cc
@@ -6,7 +6,7 @@
* Functions for mapping data between meshes.
*/
-#include <limits.h>
+#include <climits>
#include "CLG_log.h"
@@ -15,7 +15,7 @@
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "BLI_alloca.h"
+#include "BLI_array.hh"
#include "BLI_astar.h"
#include "BLI_bitmap.h"
#include "BLI_math.h"
@@ -143,7 +143,7 @@ float BKE_mesh_remap_calc_difference_from_mesh(const SpaceTransform *space_trans
}
}
- result = ((float)numverts_dst / result) - 1.0f;
+ result = (float(numverts_dst) / result) - 1.0f;
#if 0
printf("%s: Computed difference between meshes (the lower the better): %f\n", __func__, result);
@@ -180,7 +180,7 @@ static void mesh_calc_eigen_matrix(const MVert *verts,
const MVert *mv;
float(*co)[3];
- cos = MEM_mallocN(sizeof(*cos) * (size_t)numverts, __func__);
+ cos = static_cast<float(*)[3]>(MEM_mallocN(sizeof(*cos) * (size_t)numverts, __func__));
for (i = 0, co = cos, mv = verts; i < numverts; i++, co++, mv++) {
copy_v3_v3(*co, mv->co);
}
@@ -188,7 +188,7 @@ static void mesh_calc_eigen_matrix(const MVert *verts,
* doesn't handle casting correct we use workaround to avoid explicit
* cast here.
*/
- vcos = (void *)cos;
+ vcos = static_cast<const float(*)[3]>((void *)cos);
}
unit_m4(r_mat);
@@ -304,10 +304,10 @@ void BKE_mesh_remap_find_best_match_from_mesh(const MVert *verts_dst,
/** \name Mesh to Mesh Mapping
* \{ */
-void BKE_mesh_remap_calc_source_cddata_masks_from_map_modes(const int UNUSED(vert_mode),
- const int UNUSED(edge_mode),
+void BKE_mesh_remap_calc_source_cddata_masks_from_map_modes(const int /*vert_mode*/,
+ const int /*edge_mode*/,
const int loop_mode,
- const int UNUSED(poly_mode),
+ const int /*poly_mode*/,
CustomData_MeshMasks *r_cddata_mask)
{
/* vert, edge and poly mapping modes never need extra cddata from source object. */
@@ -324,7 +324,8 @@ void BKE_mesh_remap_init(MeshPairRemap *map, const int items_num)
BKE_mesh_remap_free(map);
- map->items = BLI_memarena_alloc(mem, sizeof(*map->items) * (size_t)items_num);
+ map->items = static_cast<MeshPairRemapItem *>(
+ BLI_memarena_alloc(mem, sizeof(*map->items) * (size_t)items_num));
map->items_num = items_num;
map->mem = mem;
@@ -343,7 +344,7 @@ void BKE_mesh_remap_free(MeshPairRemap *map)
static void mesh_remap_item_define(MeshPairRemap *map,
const int index,
- const float UNUSED(hit_dist),
+ const float /*hit_dist*/,
const int island,
const int sources_num,
const int *indices_src,
@@ -354,11 +355,11 @@ static void mesh_remap_item_define(MeshPairRemap *map,
if (sources_num) {
mapit->sources_num = sources_num;
- mapit->indices_src = BLI_memarena_alloc(mem,
- sizeof(*mapit->indices_src) * (size_t)sources_num);
+ mapit->indices_src = static_cast<int *>(
+ BLI_memarena_alloc(mem, sizeof(*mapit->indices_src) * (size_t)sources_num));
memcpy(mapit->indices_src, indices_src, sizeof(*mapit->indices_src) * (size_t)sources_num);
- mapit->weights_src = BLI_memarena_alloc(mem,
- sizeof(*mapit->weights_src) * (size_t)sources_num);
+ mapit->weights_src = static_cast<float *>(
+ BLI_memarena_alloc(mem, sizeof(*mapit->weights_src) * (size_t)sources_num));
memcpy(mapit->weights_src, weights_src, sizeof(*mapit->weights_src) * (size_t)sources_num);
}
else {
@@ -366,7 +367,6 @@ static void mesh_remap_item_define(MeshPairRemap *map,
mapit->indices_src = NULL;
mapit->weights_src = NULL;
}
- /* UNUSED */
// mapit->hit_dist = hit_dist;
mapit->island = island;
}
@@ -397,16 +397,16 @@ static int mesh_remap_interp_poly_data_get(const MPoly *mp,
if ((size_t)sources_num > *buff_size) {
*buff_size = (size_t)sources_num;
- *vcos = MEM_reallocN(*vcos, sizeof(**vcos) * *buff_size);
- *indices = MEM_reallocN(*indices, sizeof(**indices) * *buff_size);
+ *vcos = static_cast<float(*)[3]>(MEM_reallocN(*vcos, sizeof(**vcos) * *buff_size));
+ *indices = static_cast<int *>(MEM_reallocN(*indices, sizeof(**indices) * *buff_size));
if (do_weights) {
- *weights = MEM_reallocN(*weights, sizeof(**weights) * *buff_size);
+ *weights = static_cast<float *>(MEM_reallocN(*weights, sizeof(**weights) * *buff_size));
}
}
for (i = 0, ml = &mloops[mp->loopstart], vco = *vcos, index = *indices; i < sources_num;
i++, ml++, vco++, index++) {
- *index = use_loops ? (int)mp->loopstart + i : (int)ml->v;
+ *index = use_loops ? int(mp->loopstart) + i : int(ml->v);
copy_v3_v3(*vco, vcos_src[ml->v]);
if (r_closest_index) {
/* Find closest vert/loop in this case. */
@@ -426,7 +426,7 @@ static int mesh_remap_interp_poly_data_get(const MPoly *mp,
}
/** Little helper when dealing with source islands */
-typedef struct IslandResult {
+struct IslandResult {
/** A factor, based on which best island for a given set of elements will be selected. */
float factor;
/** Index of the source. */
@@ -435,7 +435,7 @@ typedef struct IslandResult {
float hit_dist;
/** The hit point, if relevant. */
float hit_point[3];
-} IslandResult;
+};
/**
* \note About all BVH/ray-casting stuff below:
@@ -471,7 +471,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
const float ray_radius,
const MVert *verts_dst,
const int numverts_dst,
- const bool UNUSED(dirty_nors_dst),
+ const bool /*dirty_nors_dst*/,
Mesh *me_src,
Mesh *me_dst,
MeshPairRemap *r_map)
@@ -543,15 +543,15 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
if (mode == MREMAP_MODE_VERT_EDGE_NEAREST) {
const float dist_v1 = len_squared_v3v3(tmp_co, v1cos);
const float dist_v2 = len_squared_v3v3(tmp_co, v2cos);
- const int index = (int)((dist_v1 > dist_v2) ? me->v2 : me->v1);
+ const int index = int((dist_v1 > dist_v2) ? me->v2 : me->v1);
mesh_remap_item_define(r_map, i, hit_dist, 0, 1, &index, &full_weight);
}
else if (mode == MREMAP_MODE_VERT_EDGEINTERP_NEAREST) {
int indices[2];
float weights[2];
- indices[0] = (int)me->v1;
- indices[1] = (int)me->v2;
+ indices[0] = int(me->v1);
+ indices[1] = int(me->v2);
/* Weight is inverse of point factor here... */
weights[0] = line_point_factor_v3(tmp_co, v2cos, v1cos);
@@ -579,9 +579,11 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
const float(*vert_normals_dst)[3] = BKE_mesh_vertex_normals_ensure(me_dst);
size_t tmp_buff_size = MREMAP_DEFAULT_BUFSIZE;
- float(*vcos)[3] = MEM_mallocN(sizeof(*vcos) * tmp_buff_size, __func__);
- int *indices = MEM_mallocN(sizeof(*indices) * tmp_buff_size, __func__);
- float *weights = MEM_mallocN(sizeof(*weights) * tmp_buff_size, __func__);
+ float(*vcos)[3] = static_cast<float(*)[3]>(
+ MEM_mallocN(sizeof(*vcos) * tmp_buff_size, __func__));
+ int *indices = static_cast<int *>(MEM_mallocN(sizeof(*indices) * tmp_buff_size, __func__));
+ float *weights = static_cast<float *>(
+ MEM_mallocN(sizeof(*weights) * tmp_buff_size, __func__));
BKE_bvhtree_from_mesh_get(&treedata, me_src, BVHTREE_FROM_LOOPTRI, 2);
@@ -697,7 +699,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
const int numverts_dst,
const MEdge *edges_dst,
const int numedges_dst,
- const bool UNUSED(dirty_nors_dst),
+ const bool /*dirty_nors_dst*/,
Mesh *me_src,
Mesh *me_dst,
MeshPairRemap *r_map)
@@ -732,11 +734,12 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
MeshElemMap *vert_to_edge_src_map;
int *vert_to_edge_src_map_mem;
- struct {
+ struct HitData {
float hit_dist;
int index;
- } *v_dst_to_src_map = MEM_mallocN(sizeof(*v_dst_to_src_map) * (size_t)numverts_dst,
- __func__);
+ };
+ HitData *v_dst_to_src_map = static_cast<HitData *>(
+ MEM_mallocN(sizeof(*v_dst_to_src_ma
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list