Cleanup: Move mesh_remap.c to C++
To facilitate further mesh data structure refactoring.
This commit is contained in:
parent
909f47e0e1
commit
5fe146e505
|
@ -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
|
||||
|
|
|
@ -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_map) * (size_t)numverts_dst, __func__));
|
||||
|
||||
for (i = 0; i < numverts_dst; i++) {
|
||||
v_dst_to_src_map[i].hit_dist = -1.0f;
|
||||
|
@ -800,7 +803,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
const MEdge *e_src = &edges_src[*eidx_src];
|
||||
const float *other_co_src = vcos_src[BKE_mesh_edge_other_vert(e_src, vidx_src)];
|
||||
const float *other_co_dst =
|
||||
verts_dst[BKE_mesh_edge_other_vert(e_dst, (int)vidx_dst)].co;
|
||||
verts_dst[BKE_mesh_edge_other_vert(e_dst, int(vidx_dst))].co;
|
||||
const float totdist = first_dist + len_v3v3(other_co_src, other_co_dst);
|
||||
|
||||
if (totdist < best_totdist) {
|
||||
|
@ -908,7 +911,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
dist_sq = len_squared_v3v3(tmp_co, co_src);
|
||||
if (dist_sq < best_dist_sq) {
|
||||
best_dist_sq = dist_sq;
|
||||
best_eidx_src = (int)ml_src->e;
|
||||
best_eidx_src = int(ml_src->e);
|
||||
}
|
||||
}
|
||||
if (best_eidx_src >= 0) {
|
||||
|
@ -928,10 +931,11 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
const int numedges_src = me_src->totedge;
|
||||
|
||||
/* Subtleness - this one we can allocate only max number of cast rays per edges! */
|
||||
int *indices = MEM_mallocN(sizeof(*indices) * (size_t)min_ii(numedges_src, num_rays_max),
|
||||
__func__);
|
||||
int *indices = static_cast<int *>(
|
||||
MEM_mallocN(sizeof(*indices) * (size_t)min_ii(numedges_src, num_rays_max), __func__));
|
||||
/* Here it's simpler to just allocate for all edges :/ */
|
||||
float *weights = MEM_mallocN(sizeof(*weights) * (size_t)numedges_src, __func__);
|
||||
float *weights = static_cast<float *>(
|
||||
MEM_mallocN(sizeof(*weights) * (size_t)numedges_src, __func__));
|
||||
|
||||
BKE_bvhtree_from_mesh_get(&treedata, me_src, BVHTREE_FROM_EDGES, 2);
|
||||
|
||||
|
@ -967,21 +971,21 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
BLI_space_transform_apply_normal(space_transform, v2_no);
|
||||
}
|
||||
|
||||
copy_vn_fl(weights, (int)numedges_src, 0.0f);
|
||||
copy_vn_fl(weights, int(numedges_src), 0.0f);
|
||||
|
||||
/* We adjust our ray-casting grid to ray_radius (the smaller, the more rays are cast),
|
||||
* with lower/upper bounds. */
|
||||
edge_dst_len = len_v3v3(v1_co, v2_co);
|
||||
|
||||
grid_size = (int)((edge_dst_len / ray_radius) + 0.5f);
|
||||
grid_size = int((edge_dst_len / ray_radius) + 0.5f);
|
||||
CLAMP(grid_size, num_rays_min, num_rays_max); /* min 5 rays/edge, max 100. */
|
||||
|
||||
grid_step = 1.0f /
|
||||
(float)grid_size; /* Not actual distance here, rather an interp fac... */
|
||||
float(grid_size); /* Not actual distance here, rather an interp fac... */
|
||||
|
||||
/* And now we can cast all our rays, and see what we get! */
|
||||
for (j = 0; j < grid_size; j++) {
|
||||
const float fac = grid_step * (float)j;
|
||||
const float fac = grid_step * float(j);
|
||||
|
||||
int n = (ray_radius > 0.0f) ? MREMAP_RAYCAST_APPROXIMATE_NR : 1;
|
||||
float w = 1.0f;
|
||||
|
@ -1003,8 +1007,8 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
}
|
||||
/* A sampling is valid (as in, its result can be considered as valid sources)
|
||||
* only if at least half of the rays found a source! */
|
||||
if (totweights > ((float)grid_size / 2.0f)) {
|
||||
for (j = 0; j < (int)numedges_src; j++) {
|
||||
if (totweights > (float(grid_size) / 2.0f)) {
|
||||
for (j = 0; j < int(numedges_src); j++) {
|
||||
if (!weights[j]) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1052,8 +1056,7 @@ static void mesh_island_to_astar_graph_edge_process(MeshIslandStore *islands,
|
|||
float (*poly_centers)[3],
|
||||
uchar *poly_status)
|
||||
{
|
||||
int *poly_island_indices = BLI_array_alloca(poly_island_indices,
|
||||
(size_t)edge_to_poly_map[edge_idx].count);
|
||||
blender::Array<int, 16> poly_island_indices(edge_to_poly_map[edge_idx].count);
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < edge_to_poly_map[edge_idx].count; i++) {
|
||||
|
@ -1114,7 +1117,8 @@ static void mesh_island_to_astar_graph(MeshIslandStore *islands,
|
|||
BLI_bitmap *done_edges = BLI_BITMAP_NEW(numedges, __func__);
|
||||
|
||||
const int node_num = islands ? island_poly_map->count : numpolys;
|
||||
uchar *poly_status = MEM_callocN(sizeof(*poly_status) * (size_t)node_num, __func__);
|
||||
uchar *poly_status = static_cast<uchar *>(
|
||||
MEM_callocN(sizeof(*poly_status) * (size_t)node_num, __func__));
|
||||
float(*poly_centers)[3];
|
||||
|
||||
int pidx_isld;
|
||||
|
@ -1122,12 +1126,13 @@ static void mesh_island_to_astar_graph(MeshIslandStore *islands,
|
|||
|
||||
BLI_astar_graph_init(r_as_graph, node_num, NULL);
|
||||
/* poly_centers is owned by graph memarena. */
|
||||
poly_centers = BLI_memarena_calloc(r_as_graph->mem, sizeof(*poly_centers) * (size_t)node_num);
|
||||
poly_centers = static_cast<float(*)[3]>(
|
||||
BLI_memarena_calloc(r_as_graph->mem, sizeof(*poly_centers) * (size_t)node_num));
|
||||
|
||||
if (islands) {
|
||||
/* poly_island_index_map is owned by graph memarena. */
|
||||
poly_island_index_map = BLI_memarena_calloc(r_as_graph->mem,
|
||||
sizeof(*poly_island_index_map) * (size_t)numpolys);
|
||||
poly_island_index_map = static_cast<int *>(
|
||||
BLI_memarena_calloc(r_as_graph->mem, sizeof(*poly_island_index_map) * (size_t)numpolys));
|
||||
for (i = island_poly_map->count; i--;) {
|
||||
poly_island_index_map[island_poly_map->indices[i]] = i;
|
||||
}
|
||||
|
@ -1173,7 +1178,7 @@ static void mesh_island_to_astar_graph(MeshIslandStore *islands,
|
|||
verts,
|
||||
polys,
|
||||
loops,
|
||||
(int)ml->e,
|
||||
int(ml->e),
|
||||
done_edges,
|
||||
edge_to_poly_map,
|
||||
false,
|
||||
|
@ -1279,7 +1284,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
BLI_AStarGraph *as_graphdata = NULL;
|
||||
BLI_AStarSolution as_solution = {0};
|
||||
const int isld_steps_src = (islands_precision_src ?
|
||||
max_ii((int)(ASTAR_STEPS_MAX * islands_precision_src + 0.499f),
|
||||
max_ii(int(ASTAR_STEPS_MAX * islands_precision_src + 0.499f),
|
||||
1) :
|
||||
0);
|
||||
|
||||
|
@ -1331,9 +1336,12 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
if (!use_from_vert) {
|
||||
vcos_src = BKE_mesh_vert_coords_alloc(me_src, NULL);
|
||||
|
||||
vcos_interp = MEM_mallocN(sizeof(*vcos_interp) * buff_size_interp, __func__);
|
||||
indices_interp = MEM_mallocN(sizeof(*indices_interp) * buff_size_interp, __func__);
|
||||
weights_interp = MEM_mallocN(sizeof(*weights_interp) * buff_size_interp, __func__);
|
||||
vcos_interp = static_cast<float(*)[3]>(
|
||||
MEM_mallocN(sizeof(*vcos_interp) * buff_size_interp, __func__));
|
||||
indices_interp = static_cast<int *>(
|
||||
MEM_mallocN(sizeof(*indices_interp) * buff_size_interp, __func__));
|
||||
weights_interp = static_cast<float *>(
|
||||
MEM_mallocN(sizeof(*weights_interp) * buff_size_interp, __func__));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1347,14 +1355,15 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
poly_nors_dst = BKE_mesh_poly_normals_ensure(mesh_dst);
|
||||
}
|
||||
if (need_lnors_dst) {
|
||||
short(*custom_nors_dst)[2] = CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL);
|
||||
short(*custom_nors_dst)[2] = static_cast<short(*)[2]>(
|
||||
CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL));
|
||||
|
||||
/* Cache loop normals into a temporary custom data layer. */
|
||||
loop_nors_dst = CustomData_get_layer(ldata_dst, CD_NORMAL);
|
||||
loop_nors_dst = static_cast<float(*)[3]>(CustomData_get_layer(ldata_dst, CD_NORMAL));
|
||||
const bool do_loop_nors_dst = (loop_nors_dst == NULL);
|
||||
if (!loop_nors_dst) {
|
||||
loop_nors_dst = CustomData_add_layer(
|
||||
ldata_dst, CD_NORMAL, CD_SET_DEFAULT, NULL, numloops_dst);
|
||||
loop_nors_dst = static_cast<float(*)[3]>(
|
||||
CustomData_add_layer(ldata_dst, CD_NORMAL, CD_SET_DEFAULT, NULL, numloops_dst));
|
||||
CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
|
||||
}
|
||||
if (dirty_nors_dst || do_loop_nors_dst) {
|
||||
|
@ -1381,7 +1390,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
poly_nors_src = BKE_mesh_poly_normals_ensure(me_src);
|
||||
}
|
||||
if (need_lnors_src) {
|
||||
loop_nors_src = CustomData_get_layer(&me_src->ldata, CD_NORMAL);
|
||||
loop_nors_src = static_cast<const float(*)[3]>(
|
||||
CustomData_get_layer(&me_src->ldata, CD_NORMAL));
|
||||
BLI_assert(loop_nors_src != NULL);
|
||||
}
|
||||
}
|
||||
|
@ -1416,9 +1426,10 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
loops_src,
|
||||
num_loops_src);
|
||||
if (use_from_vert) {
|
||||
loop_to_poly_map_src = MEM_mallocN(sizeof(*loop_to_poly_map_src) * (size_t)num_loops_src,
|
||||
__func__);
|
||||
poly_cents_src = MEM_mallocN(sizeof(*poly_cents_src) * (size_t)num_polys_src, __func__);
|
||||
loop_to_poly_map_src = static_cast<int *>(
|
||||
MEM_mallocN(sizeof(*loop_to_poly_map_src) * (size_t)num_loops_src, __func__));
|
||||
poly_cents_src = static_cast<float(*)[3]>(
|
||||
MEM_mallocN(sizeof(*poly_cents_src) * (size_t)num_polys_src, __func__));
|
||||
for (pidx_src = 0, mp_src = polys_src; pidx_src < num_polys_src; pidx_src++, mp_src++) {
|
||||
ml_src = &loops_src[mp_src->loopstart];
|
||||
for (plidx_src = 0, lidx_src = mp_src->loopstart; plidx_src < mp_src->totloop;
|
||||
|
@ -1449,9 +1460,11 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
&island_store);
|
||||
|
||||
num_trees = use_islands ? island_store.islands_num : 1;
|
||||
treedata = MEM_callocN(sizeof(*treedata) * (size_t)num_trees, __func__);
|
||||
treedata = static_cast<BVHTreeFromMesh *>(
|
||||
MEM_callocN(sizeof(*treedata) * (size_t)num_trees, __func__));
|
||||
if (isld_steps_src) {
|
||||
as_graphdata = MEM_callocN(sizeof(*as_graphdata) * (size_t)num_trees, __func__);
|
||||
as_graphdata = static_cast<BLI_AStarGraph *>(
|
||||
MEM_callocN(sizeof(*as_graphdata) * (size_t)num_trees, __func__));
|
||||
}
|
||||
|
||||
if (use_islands) {
|
||||
|
@ -1465,9 +1478,9 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
}
|
||||
else {
|
||||
num_trees = 1;
|
||||
treedata = MEM_callocN(sizeof(*treedata), __func__);
|
||||
treedata = static_cast<BVHTreeFromMesh *>(MEM_callocN(sizeof(*treedata), __func__));
|
||||
if (isld_steps_src) {
|
||||
as_graphdata = MEM_callocN(sizeof(*as_graphdata), __func__);
|
||||
as_graphdata = static_cast<BLI_AStarGraph *>(MEM_callocN(sizeof(*as_graphdata), __func__));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1563,9 +1576,11 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
}
|
||||
|
||||
/* And check each dest poly! */
|
||||
islands_res = MEM_mallocN(sizeof(*islands_res) * (size_t)num_trees, __func__);
|
||||
islands_res = static_cast<IslandResult **>(
|
||||
MEM_mallocN(sizeof(*islands_res) * (size_t)num_trees, __func__));
|
||||
for (tindex = 0; tindex < num_trees; tindex++) {
|
||||
islands_res[tindex] = MEM_mallocN(sizeof(**islands_res) * islands_res_buff_size, __func__);
|
||||
islands_res[tindex] = static_cast<IslandResult *>(
|
||||
MEM_mallocN(sizeof(**islands_res) * islands_res_buff_size, __func__));
|
||||
}
|
||||
|
||||
for (pidx_dst = 0, mp_dst = polys_dst; pidx_dst < numpolys_dst; pidx_dst++, mp_dst++) {
|
||||
|
@ -1586,8 +1601,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
if ((size_t)mp_dst->totloop > islands_res_buff_size) {
|
||||
islands_res_buff_size = (size_t)mp_dst->totloop + MREMAP_DEFAULT_BUFSIZE;
|
||||
for (tindex = 0; tindex < num_trees; tindex++) {
|
||||
islands_res[tindex] = MEM_reallocN(islands_res[tindex],
|
||||
sizeof(**islands_res) * islands_res_buff_size);
|
||||
islands_res[tindex] = static_cast<IslandResult *>(
|
||||
MEM_reallocN(islands_res[tindex], sizeof(**islands_res) * islands_res_buff_size));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1686,7 +1701,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
mp_src = &polys_src[best_index_src];
|
||||
ml_src = &loops_src[mp_src->loopstart];
|
||||
for (plidx_src = 0; plidx_src < mp_src->totloop; plidx_src++, ml_src++) {
|
||||
if ((int)ml_src->v == nearest.index) {
|
||||
if (int(ml_src->v) == nearest.index) {
|
||||
best_index_src = plidx_src + mp_src->loopstart;
|
||||
break;
|
||||
}
|
||||
|
@ -1722,7 +1737,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
tdata, &rayhit, tmp_co, tmp_no, ray_radius / w, max_dist, &hit_dist)) {
|
||||
islands_res[tindex][plidx_dst].factor = (hit_dist ? (1.0f / hit_dist) : 1e18f) * w;
|
||||
islands_res[tindex][plidx_dst].hit_dist = hit_dist;
|
||||
islands_res[tindex][plidx_dst].index_src = (int)tdata->looptri[rayhit.index].poly;
|
||||
islands_res[tindex][plidx_dst].index_src = int(tdata->looptri[rayhit.index].poly);
|
||||
copy_v3_v3(islands_res[tindex][plidx_dst].hit_point, rayhit.co);
|
||||
break;
|
||||
}
|
||||
|
@ -1751,7 +1766,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
if (mesh_remap_bvhtree_query_nearest(
|
||||
tdata, &nearest, tmp_co, max_dist_sq, &hit_dist)) {
|
||||
islands_res[tindex][plidx_dst].hit_dist = hit_dist;
|
||||
islands_res[tindex][plidx_dst].index_src = (int)tdata->looptri[nearest.index].poly;
|
||||
islands_res[tindex][plidx_dst].index_src = int(tdata->looptri[nearest.index].poly);
|
||||
copy_v3_v3(islands_res[tindex][plidx_dst].hit_point, nearest.co);
|
||||
}
|
||||
else {
|
||||
|
@ -1774,7 +1789,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
tdata, &nearest, tmp_co, max_dist_sq, &hit_dist)) {
|
||||
islands_res[tindex][plidx_dst].factor = hit_dist ? (1.0f / hit_dist) : 1e18f;
|
||||
islands_res[tindex][plidx_dst].hit_dist = hit_dist;
|
||||
islands_res[tindex][plidx_dst].index_src = (int)tdata->looptri[nearest.index].poly;
|
||||
islands_res[tindex][plidx_dst].index_src = int(tdata->looptri[nearest.index].poly);
|
||||
copy_v3_v3(islands_res[tindex][plidx_dst].hit_point, nearest.co);
|
||||
}
|
||||
else {
|
||||
|
@ -1814,7 +1829,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
for (plidx_dst = 0; plidx_dst < mp_dst->totloop; plidx_dst++) {
|
||||
island_fac += islands_res[tindex][plidx_dst].factor;
|
||||
}
|
||||
island_fac /= (float)mp_dst->totloop;
|
||||
island_fac /= float(mp_dst->totloop);
|
||||
|
||||
if (island_fac > best_island_fac) {
|
||||
best_island_fac = island_fac;
|
||||
|
@ -2202,7 +2217,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
|
|||
if (mesh_remap_bvhtree_query_nearest(
|
||||
&treedata, &nearest, tmp_co, max_dist_sq, &hit_dist)) {
|
||||
const MLoopTri *lt = &treedata.looptri[nearest.index];
|
||||
const int poly_index = (int)lt->poly;
|
||||
const int poly_index = int(lt->poly);
|
||||
mesh_remap_item_define(r_map, i, hit_dist, 0, 1, &poly_index, &full_weight);
|
||||
}
|
||||
else {
|
||||
|
@ -2229,7 +2244,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
|
|||
if (mesh_remap_bvhtree_query_raycast(
|
||||
&treedata, &rayhit, tmp_co, tmp_no, ray_radius, max_dist, &hit_dist)) {
|
||||
const MLoopTri *lt = &treedata.looptri[rayhit.index];
|
||||
const int poly_index = (int)lt->poly;
|
||||
const int poly_index = int(lt->poly);
|
||||
|
||||
mesh_remap_item_define(r_map, i, hit_dist, 0, 1, &poly_index, &full_weight);
|
||||
}
|
||||
|
@ -2249,13 +2264,16 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
|
|||
const size_t numpolys_src = (size_t)me_src->totpoly;
|
||||
|
||||
/* Here it's simpler to just allocate for all polys :/ */
|
||||
int *indices = MEM_mallocN(sizeof(*indices) * numpolys_src, __func__);
|
||||
float *weights = MEM_mallocN(sizeof(*weights) * numpolys_src, __func__);
|
||||
int *indices = static_cast<int *>(MEM_mallocN(sizeof(*indices) * numpolys_src, __func__));
|
||||
float *weights = static_cast<float *>(
|
||||
MEM_mallocN(sizeof(*weights) * numpolys_src, __func__));
|
||||
|
||||
size_t tmp_poly_size = MREMAP_DEFAULT_BUFSIZE;
|
||||
float(*poly_vcos_2d)[2] = MEM_mallocN(sizeof(*poly_vcos_2d) * tmp_poly_size, __func__);
|
||||
float(*poly_vcos_2d)[2] = static_cast<float(*)[2]>(
|
||||
MEM_mallocN(sizeof(*poly_vcos_2d) * tmp_poly_size, __func__));
|
||||
/* Tessellated 2D poly, always (num_loops - 2) triangles. */
|
||||
int(*tri_vidx_2d)[3] = MEM_mallocN(sizeof(*tri_vidx_2d) * (tmp_poly_size - 2), __func__);
|
||||
int(*tri_vidx_2d)[3] = static_cast<int(*)[3]>(
|
||||
MEM_mallocN(sizeof(*tri_vidx_2d) * (tmp_poly_size - 2), __func__));
|
||||
|
||||
for (i = 0; i < numpolys_dst; i++) {
|
||||
/* For each dst poly, we sample some rays from it (2D grid in pnor space)
|
||||
|
@ -2286,12 +2304,14 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
|
|||
BLI_space_transform_apply_normal(space_transform, tmp_no);
|
||||
}
|
||||
|
||||
copy_vn_fl(weights, (int)numpolys_src, 0.0f);
|
||||
copy_vn_fl(weights, int(numpolys_src), 0.0f);
|
||||
|
||||
if (UNLIKELY((size_t)mp->totloop > tmp_poly_size)) {
|
||||
tmp_poly_size = (size_t)mp->totloop;
|
||||
poly_vcos_2d = MEM_reallocN(poly_vcos_2d, sizeof(*poly_vcos_2d) * tmp_poly_size);
|
||||
tri_vidx_2d = MEM_reallocN(tri_vidx_2d, sizeof(*tri_vidx_2d) * (tmp_poly_size - 2));
|
||||
poly_vcos_2d = static_cast<float(*)[2]>(
|
||||
MEM_reallocN(poly_vcos_2d, sizeof(*poly_vcos_2d) * tmp_poly_size));
|
||||
tri_vidx_2d = static_cast<int(*)[3]>(
|
||||
MEM_reallocN(tri_vidx_2d, sizeof(*tri_vidx_2d) * (tmp_poly_size - 2)));
|
||||
}
|
||||
|
||||
axis_dominant_v3_to_m3(to_pnor_2d_mat, tmp_no);
|
||||
|
@ -2318,7 +2338,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
|
|||
sub_v2_v2v2(poly_dst_2d_size, poly_dst_2d_max, poly_dst_2d_min);
|
||||
|
||||
if (ray_radius) {
|
||||
tot_rays = (int)((max_ff(poly_dst_2d_size[0], poly_dst_2d_size[1]) / ray_radius) + 0.5f);
|
||||
tot_rays = int((max_ff(poly_dst_2d_size[0], poly_dst_2d_size[1]) / ray_radius) + 0.5f);
|
||||
CLAMP(tot_rays, MREMAP_RAYCAST_TRI_SAMPLES_MIN, MREMAP_RAYCAST_TRI_SAMPLES_MAX);
|
||||
}
|
||||
else {
|
||||
|
@ -2358,8 +2378,8 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
|
|||
/* All this allows us to get 'absolute' number of rays for each tri,
|
||||
* avoiding accumulating errors over iterations, and helping better even distribution. */
|
||||
done_area += area_tri_v2(v1, v2, v3);
|
||||
rays_num = max_ii(
|
||||
(int)((float)tot_rays * done_area * poly_area_2d_inv + 0.5f) - done_rays, 0);
|
||||
rays_num = max_ii(int(float(tot_rays) * done_area * poly_area_2d_inv + 0.5f) - done_rays,
|
||||
0);
|
||||
done_rays += rays_num;
|
||||
|
||||
while (rays_num--) {
|
||||
|
@ -2389,7 +2409,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
|
|||
}
|
||||
|
||||
if (totweights > 0.0f) {
|
||||
for (j = 0; j < (int)numpolys_src; j++) {
|
||||
for (j = 0; j < int(numpolys_src); j++) {
|
||||
if (!weights[j]) {
|
||||
continue;
|
||||
}
|
Loading…
Reference in New Issue