Cleanup: Move PBVH files to C++

For continued refactoring of the Mesh data structure. See T103343.
This commit is contained in:
Hans Goudey
2023-02-05 16:56:37 -05:00
parent 3420c47900
commit 501352ef05
7 changed files with 347 additions and 337 deletions

View File

@@ -167,6 +167,7 @@ typedef enum {
PBVH_TopologyUpdated = 1 << 17, /* Used internally by pbvh_bmesh.c */
} PBVHNodeFlags;
ENUM_OPERATORS(PBVHNodeFlags, PBVH_TopologyUpdated);
typedef struct PBVHFrustumPlanes {
float (*planes)[4];

View File

@@ -248,9 +248,9 @@ set(SRC
intern/particle_child.c
intern/particle_distribute.c
intern/particle_system.c
intern/pbvh.c
intern/pbvh.cc
intern/pbvh_colors.cc
intern/pbvh_bmesh.c
intern/pbvh_bmesh.cc
intern/pbvh_pixels.cc
intern/pbvh_uv_islands.cc
intern/pointcache.c
@@ -505,7 +505,7 @@ set(SRC
intern/multires_reshape.hh
intern/multires_unsubdivide.h
intern/ocean_intern.h
intern/pbvh_intern.h
intern/pbvh_intern.hh
intern/pbvh_uv_islands.hh
intern/subdiv_converter.h
intern/subdiv_inline.h

View File

@@ -6,13 +6,14 @@
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
#include <climits>
#include "BLI_bitmap.h"
#include "BLI_ghash.h"
#include "BLI_math.h"
#include "BLI_rand.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -33,9 +34,7 @@
#include "atomic_ops.h"
#include "pbvh_intern.h"
#include <limits.h>
#include "pbvh_intern.hh"
#define LEAF_LIMIT 10000
@@ -50,12 +49,12 @@
//#define PERFCNTRS
#define STACK_FIXED_DEPTH 100
typedef struct PBVHStack {
struct PBVHStack {
PBVHNode *node;
bool revisiting;
} PBVHStack;
};
typedef struct PBVHIter {
struct PBVHIter {
PBVH *pbvh;
BKE_pbvh_SearchCallback scb;
void *search_data;
@@ -65,7 +64,7 @@ typedef struct PBVHIter {
PBVHStack stackfixed[STACK_FIXED_DEPTH];
int stackspace;
} PBVHIter;
};
void BB_reset(BB *bb)
{
@@ -273,7 +272,8 @@ void pbvh_grow_nodes(PBVH *pbvh, int totnode)
if (pbvh->node_mem_count < totnode) {
pbvh->node_mem_count = totnode;
}
pbvh->nodes = MEM_recallocN(pbvh->nodes, sizeof(PBVHNode) * pbvh->node_mem_count);
pbvh->nodes = static_cast<PBVHNode *>(
MEM_recallocN(pbvh->nodes, sizeof(PBVHNode) * pbvh->node_mem_count));
}
pbvh->totnode = totnode;
@@ -315,7 +315,8 @@ static void build_mesh_leaf_node(PBVH *pbvh, PBVHNode *node)
/* reserve size is rough guess */
GHash *map = BLI_ghash_int_new_ex("build_mesh_leaf_node gh", 2 * totface);
int(*face_vert_indices)[3] = MEM_mallocN(sizeof(int[3]) * totface, "bvh node face vert indices");
int(*face_vert_indices)[3] = static_cast<int(*)[3]>(
MEM_mallocN(sizeof(int[3]) * totface, __func__));
node->face_vert_indices = (const int(*)[3])face_vert_indices;
@@ -337,8 +338,8 @@ static void build_mesh_leaf_node(PBVH *pbvh, PBVHNode *node)
}
}
int *vert_indices = MEM_callocN(sizeof(int) * (node->uniq_verts + node->face_verts),
"bvh node vert indices");
int *vert_indices = static_cast<int *>(
MEM_callocN(sizeof(int) * (node->uniq_verts + node->face_verts), __func__));
node->vert_indices = vert_indices;
/* Build the vertex list, unique verts first */
@@ -368,7 +369,7 @@ static void build_mesh_leaf_node(PBVH *pbvh, PBVHNode *node)
BKE_pbvh_node_fully_hidden_set(node, !has_visible);
BLI_ghash_free(map, NULL, NULL);
BLI_ghash_free(map, nullptr, nullptr);
}
static void update_vb(PBVH *pbvh, PBVHNode *node, BBC *prim_bbc, int offset, int count)
@@ -392,8 +393,8 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
/* grid hidden layer is present, so have to check each grid for
* visibility */
int depth1 = (int)(log2((double)gridsize - 1.0) + DBL_EPSILON);
int depth2 = (int)(log2((double)display_gridsize - 1.0) + DBL_EPSILON);
int depth1 = int(log2((double)gridsize - 1.0) + DBL_EPSILON);
int depth2 = int(log2((double)display_gridsize - 1.0) + DBL_EPSILON);
int skip = depth2 < depth1 ? 1 << (depth1 - depth2 - 1) : 1;
@@ -550,7 +551,7 @@ static void build_sub(PBVH *pbvh,
BB cb_backing;
if (!prim_scratch) {
prim_scratch = MEM_malloc_arrayN(pbvh->totprim, sizeof(int), __func__);
prim_scratch = static_cast<int *>(MEM_malloc_arrayN(pbvh->totprim, sizeof(int), __func__));
}
/* Decide whether this is a leaf or not */
@@ -615,7 +616,7 @@ static void build_sub(PBVH *pbvh,
/* Build children */
build_sub(pbvh,
pbvh->nodes[node_index].children_offset,
NULL,
nullptr,
prim_bbc,
offset,
end - offset,
@@ -623,7 +624,7 @@ static void build_sub(PBVH *pbvh,
depth + 1);
build_sub(pbvh,
pbvh->nodes[node_index].children_offset + 1,
NULL,
nullptr,
prim_bbc,
end,
offset + count - end,
@@ -645,19 +646,20 @@ static void pbvh_build(PBVH *pbvh, BB *cb, BBC *prim_bbc, int totprim)
if (pbvh->prim_indices) {
MEM_freeN(pbvh->prim_indices);
}
pbvh->prim_indices = MEM_mallocN(sizeof(int) * totprim, "bvh prim indices");
pbvh->prim_indices = static_cast<int *>(MEM_mallocN(sizeof(int) * totprim, __func__));
for (int i = 0; i < totprim; i++) {
pbvh->prim_indices[i] = i;
}
pbvh->totnode = 0;
if (pbvh->node_mem_count < 100) {
pbvh->node_mem_count = 100;
pbvh->nodes = MEM_callocN(sizeof(PBVHNode) * pbvh->node_mem_count, "bvh initial nodes");
pbvh->nodes = static_cast<PBVHNode *>(
MEM_callocN(sizeof(PBVHNode) * pbvh->node_mem_count, __func__));
}
}
pbvh->totnode = 1;
build_sub(pbvh, 0, cb, prim_bbc, 0, totprim, NULL, 0);
build_sub(pbvh, 0, cb, prim_bbc, 0, totprim, nullptr, 0);
}
static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
@@ -669,7 +671,7 @@ static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
args->mesh_grids_num = pbvh->totgrid;
args->node = node;
BKE_pbvh_node_num_verts(pbvh, node, NULL, &args->node_verts_num);
BKE_pbvh_node_num_verts(pbvh, node, nullptr, &args->node_verts_num);
args->grid_hidden = pbvh->grid_hidden;
args->face_sets_color_default = pbvh->face_sets_color_default;
@@ -680,9 +682,9 @@ static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
args->mlooptri = pbvh->looptri;
if (ELEM(pbvh->header.type, PBVH_FACES, PBVH_GRIDS)) {
args->hide_poly = pbvh->pdata ?
CustomData_get_layer_named(pbvh->pdata, CD_PROP_BOOL, ".hide_poly") :
NULL;
args->hide_poly = pbvh->pdata ? static_cast<const bool *>(CustomData_get_layer_named(
pbvh->pdata, CD_PROP_BOOL, ".hide_poly")) :
nullptr;
}
switch (pbvh->header.type) {
@@ -813,30 +815,31 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
const MLoop *mloop,
float (*vert_positions)[3],
int totvert,
struct CustomData *vdata,
struct CustomData *ldata,
struct CustomData *pdata,
CustomData *vdata,
CustomData *ldata,
CustomData *pdata,
const MLoopTri *looptri,
int looptri_num)
{
BBC *prim_bbc = NULL;
BBC *prim_bbc = nullptr;
BB cb;
pbvh->mesh = mesh;
pbvh->header.type = PBVH_FACES;
pbvh->mpoly = mpoly;
pbvh->hide_poly = (bool *)CustomData_get_layer_named_for_write(
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly);
pbvh->material_indices = (const int *)CustomData_get_layer_named(
&mesh->pdata, CD_PROP_INT32, "material_index");
pbvh->hide_poly = static_cast<bool *>(CustomData_get_layer_named_for_write(
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly));
pbvh->material_indices = static_cast<const int *>(
CustomData_get_layer_named(&mesh->pdata, CD_PROP_INT32, "material_index"));
pbvh->mloop = mloop;
pbvh->looptri = looptri;
pbvh->vert_positions = vert_positions;
BKE_mesh_vertex_normals_ensure(mesh);
pbvh->vert_normals = BKE_mesh_vertex_normals_for_write(mesh);
pbvh->hide_vert = (bool *)CustomData_get_layer_named_for_write(
&mesh->vdata, CD_PROP_BOOL, ".hide_vert", mesh->totvert);
pbvh->vert_bitmap = MEM_calloc_arrayN(totvert, sizeof(bool), "bvh->vert_bitmap");
pbvh->hide_vert = static_cast<bool *>(CustomData_get_layer_named_for_write(
&mesh->vdata, CD_PROP_BOOL, ".hide_vert", mesh->totvert));
pbvh->vert_bitmap = static_cast<bool *>(
MEM_calloc_arrayN(totvert, sizeof(bool), "bvh->vert_bitmap"));
pbvh->totvert = totvert;
#ifdef TEST_PBVH_FACE_SPLIT
@@ -859,7 +862,7 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
BB_reset(&cb);
/* For each face, store the AABB and the AABB centroid */
prim_bbc = MEM_mallocN(sizeof(BBC) * looptri_num, "prim_bbc");
prim_bbc = static_cast<BBC *>(MEM_mallocN(sizeof(BBC) * looptri_num, __func__));
for (int i = 0; i < looptri_num; i++) {
const MLoopTri *lt = &looptri[i];
@@ -948,7 +951,7 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
BB_reset(&cb);
/* For each grid, store the AABB and the AABB centroid */
BBC *prim_bbc = MEM_mallocN(sizeof(BBC) * totgrid, "prim_bbc");
BBC *prim_bbc = static_cast<BBC *>(MEM_mallocN(sizeof(BBC) * totgrid, __func__));
for (int i = 0; i < totgrid; i++) {
CCGElem *grid = grids[i];
@@ -981,7 +984,7 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
PBVH *BKE_pbvh_new(PBVHType type)
{
PBVH *pbvh = MEM_callocN(sizeof(PBVH), "pbvh");
PBVH *pbvh = MEM_cnew<PBVH>(__func__);
pbvh->respect_hide = true;
pbvh->draw_cache_invalid = true;
pbvh->header.type = type;
@@ -1012,13 +1015,13 @@ void BKE_pbvh_free(PBVH *pbvh)
MEM_freeN((void *)node->face_vert_indices);
}
if (node->bm_faces) {
BLI_gset_free(node->bm_faces, NULL);
BLI_gset_free(node->bm_faces, nullptr);
}
if (node->bm_unique_verts) {
BLI_gset_free(node->bm_unique_verts, NULL);
BLI_gset_free(node->bm_unique_verts, nullptr);
}
if (node->bm_other_verts) {
BLI_gset_free(node->bm_other_verts, NULL);
BLI_gset_free(node->bm_other_verts, nullptr);
}
}
@@ -1083,10 +1086,12 @@ static void pbvh_stack_push(PBVHIter *iter, PBVHNode *node, bool revisiting)
if (UNLIKELY(iter->stacksize == iter->stackspace)) {
iter->stackspace *= 2;
if (iter->stackspace != (STACK_FIXED_DEPTH * 2)) {
iter->stack = MEM_reallocN(iter->stack, sizeof(PBVHStack) * iter->stackspace);
iter->stack = static_cast<PBVHStack *>(
MEM_reallocN(iter->stack, sizeof(PBVHStack) * iter->stackspace));
}
else {
iter->stack = MEM_mallocN(sizeof(PBVHStack) * iter->stackspace, "PBVHStack");
iter->stack = static_cast<PBVHStack *>(
MEM_mallocN(sizeof(PBVHStack) * iter->stackspace, "PBVHStack"));
memcpy(iter->stack, iter->stackfixed, sizeof(PBVHStack) * iter->stacksize);
}
}
@@ -1108,8 +1113,8 @@ static PBVHNode *pbvh_iter_next(PBVHIter *iter, PBVHNodeFlags leaf_flag)
/* on a mesh with no faces this can happen
* can remove this check if we know meshes have at least 1 face */
if (node == NULL) {
return NULL;
if (node == nullptr) {
return nullptr;
}
bool revisiting = iter->stack[iter->stacksize].revisiting;
@@ -1136,7 +1141,7 @@ static PBVHNode *pbvh_iter_next(PBVHIter *iter, PBVHNodeFlags leaf_flag)
pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset, false);
}
return NULL;
return nullptr;
}
static PBVHNode *pbvh_iter_next_occluded(PBVHIter *iter)
@@ -1148,8 +1153,8 @@ static PBVHNode *pbvh_iter_next_occluded(PBVHIter *iter)
/* on a mesh with no faces this can happen
* can remove this check if we know meshes have at least 1 face */
if (node == NULL) {
return NULL;
if (node == nullptr) {
return nullptr;
}
if (iter->scb && !iter->scb(node, iter->search_data)) {
@@ -1165,7 +1170,7 @@ static PBVHNode *pbvh_iter_next_occluded(PBVHIter *iter)
pbvh_stack_push(iter, iter->pbvh->nodes + node->children_offset, false);
}
return NULL;
return nullptr;
}
void BKE_pbvh_search_gather_ex(PBVH *pbvh,
@@ -1176,7 +1181,7 @@ void BKE_pbvh_search_gather_ex(PBVH *pbvh,
PBVHNodeFlags leaf_flag)
{
PBVHIter iter;
PBVHNode **array = NULL, *node;
PBVHNode **array = nullptr, *node;
int tot = 0, space = 0;
pbvh_iter_begin(&iter, pbvh, scb, search_data);
@@ -1186,7 +1191,8 @@ void BKE_pbvh_search_gather_ex(PBVH *pbvh,
if (UNLIKELY(tot == space)) {
/* resize array if needed */
space = (tot == 0) ? 32 : space * 2;
array = MEM_recallocN_id(array, sizeof(PBVHNode *) * space, __func__);
array = static_cast<PBVHNode **>(
MEM_recallocN_id(array, sizeof(PBVHNode *) * space, __func__));
}
array[tot] = node;
@@ -1198,7 +1204,7 @@ void BKE_pbvh_search_gather_ex(PBVH *pbvh,
if (tot == 0 && array) {
MEM_freeN(array);
array = NULL;
array = nullptr;
}
*r_array = array;
@@ -1231,12 +1237,12 @@ void BKE_pbvh_search_callback(PBVH *pbvh,
pbvh_iter_end(&iter);
}
typedef struct node_tree {
struct node_tree {
PBVHNode *data;
struct node_tree *left;
struct node_tree *right;
} node_tree;
node_tree *left;
node_tree *right;
};
static void node_tree_insert(node_tree *tree, node_tree *new_node)
{
@@ -1278,12 +1284,12 @@ static void free_tree(node_tree *tree)
{
if (tree->left) {
free_tree(tree->left);
tree->left = NULL;
tree->left = nullptr;
}
if (tree->right) {
free_tree(tree->right);
tree->right = NULL;
tree->right = nullptr;
}
free(tree);
@@ -1302,18 +1308,18 @@ static void BKE_pbvh_search_callback_occluded(PBVH *pbvh,
{
PBVHIter iter;
PBVHNode *node;
node_tree *tree = NULL;
node_tree *tree = nullptr;
pbvh_iter_begin(&iter, pbvh, scb, search_data);
while ((node = pbvh_iter_next_occluded(&iter))) {
if (node->flag & PBVH_Leaf) {
node_tree *new_node = malloc(sizeof(node_tree));
node_tree *new_node = static_cast<node_tree *>(malloc(sizeof(node_tree)));
new_node->data = node;
new_node->left = NULL;
new_node->right = NULL;
new_node->left = nullptr;
new_node->right = nullptr;
if (tree) {
node_tree_insert(tree, new_node);
@@ -1344,7 +1350,7 @@ static bool update_search_cb(PBVHNode *node, void *data_v)
return true;
}
typedef struct PBVHUpdateData {
struct PBVHUpdateData {
PBVH *pbvh;
PBVHNode **nodes;
int totnode;
@@ -1354,13 +1360,13 @@ typedef struct PBVHUpdateData {
bool show_sculpt_face_sets;
PBVHAttrReq *attrs;
int attrs_num;
} PBVHUpdateData;
};
static void pbvh_update_normals_clear_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
PBVHUpdateData *data = userdata;
PBVHUpdateData *data = static_cast<PBVHUpdateData *>(userdata);
PBVH *pbvh = data->pbvh;
PBVHNode *node = data->nodes[n];
float(*vert_normals)[3] = data->vert_normals;
@@ -1379,9 +1385,9 @@ static void pbvh_update_normals_clear_task_cb(void *__restrict userdata,
static void pbvh_update_normals_accum_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
PBVHUpdateData *data = userdata;
PBVHUpdateData *data = static_cast<PBVHUpdateData *>(userdata);
PBVH *pbvh = data->pbvh;
PBVHNode *node = data->nodes[n];
@@ -1429,9 +1435,9 @@ static void pbvh_update_normals_accum_task_cb(void *__restrict userdata,
static void pbvh_update_normals_store_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
PBVHUpdateData *data = userdata;
PBVHUpdateData *data = static_cast<PBVHUpdateData *>(userdata);
PBVH *pbvh = data->pbvh;
PBVHNode *node = data->nodes[n];
float(*vert_normals)[3] = data->vert_normals;
@@ -1467,11 +1473,10 @@ static void pbvh_faces_update_normals(PBVH *pbvh, PBVHNode **nodes, int totnode)
* can only update vertices marked in the `vert_bitmap`.
*/
PBVHUpdateData data = {
.pbvh = pbvh,
.nodes = nodes,
.vert_normals = pbvh->vert_normals,
};
PBVHUpdateData data{};
data.pbvh = pbvh;
data.nodes = nodes;
data.vert_normals = pbvh->vert_normals;
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -1484,10 +1489,10 @@ static void pbvh_faces_update_normals(PBVH *pbvh, PBVHNode **nodes, int totnode)
static void pbvh_update_mask_redraw_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
PBVHUpdateData *data = userdata;
PBVHUpdateData *data = static_cast<PBVHUpdateData *>(userdata);
PBVH *pbvh = data->pbvh;
PBVHNode *node = data->nodes[n];
if (node->flag & PBVH_UpdateMask) {
@@ -1520,11 +1525,10 @@ static void pbvh_update_mask_redraw_task_cb(void *__restrict userdata,
static void pbvh_update_mask_redraw(PBVH *pbvh, PBVHNode **nodes, int totnode, int flag)
{
PBVHUpdateData data = {
.pbvh = pbvh,
.nodes = nodes,
.flag = flag,
};
PBVHUpdateData data{};
data.pbvh = pbvh;
data.nodes = nodes;
data.flag = flag;
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -1533,10 +1537,10 @@ static void pbvh_update_mask_redraw(PBVH *pbvh, PBVHNode **nodes, int totnode, i
static void pbvh_update_visibility_redraw_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
PBVHUpdateData *data = userdata;
PBVHUpdateData *data = static_cast<PBVHUpdateData *>(userdata);
PBVH *pbvh = data->pbvh;
PBVHNode *node = data->nodes[n];
if (node->flag & PBVH_UpdateVisibility) {
@@ -1557,11 +1561,10 @@ static void pbvh_update_visibility_redraw_task_cb(void *__restrict userdata,
static void pbvh_update_visibility_redraw(PBVH *pbvh, PBVHNode **nodes, int totnode, int flag)
{
PBVHUpdateData data = {
.pbvh = pbvh,
.nodes = nodes,
.flag = flag,
};
PBVHUpdateData data{};
data.pbvh = pbvh;
data.nodes = nodes;
data.flag = flag;
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -1570,9 +1573,9 @@ static void pbvh_update_visibility_redraw(PBVH *pbvh, PBVHNode **nodes, int totn
static void pbvh_update_BB_redraw_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
PBVHUpdateData *data = userdata;
PBVHUpdateData *data = static_cast<PBVHUpdateData *>(userdata);
PBVH *pbvh = data->pbvh;
PBVHNode *node = data->nodes[n];
const int flag = data->flag;
@@ -1595,11 +1598,10 @@ static void pbvh_update_BB_redraw_task_cb(void *__restrict userdata,
void pbvh_update_BB_redraw(PBVH *pbvh, PBVHNode **nodes, int totnode, int flag)
{
/* update BB, redraw flag */
PBVHUpdateData data = {
.pbvh = pbvh,
.nodes = nodes,
.flag = flag,
};
PBVHUpdateData data{};
data.pbvh = pbvh;
data.nodes = nodes;
data.flag = flag;
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -1611,7 +1613,7 @@ bool BKE_pbvh_get_color_layer(const Mesh *me, CustomDataLayer **r_layer, eAttrDo
CustomDataLayer *layer = BKE_id_attributes_color_find(&me->id, me->active_color_attribute);
if (!layer || !ELEM(layer->type, CD_PROP_COLOR, CD_PROP_BYTE_COLOR)) {
*r_layer = NULL;
*r_layer = nullptr;
*r_attr = ATTR_DOMAIN_POINT;
return false;
}
@@ -1619,7 +1621,7 @@ bool BKE_pbvh_get_color_layer(const Mesh *me, CustomDataLayer **r_layer, eAttrDo
eAttrDomain domain = BKE_id_attribute_domain(&me->id, layer);
if (!ELEM(domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CORNER)) {
*r_layer = NULL;
*r_layer = nullptr;
*r_attr = ATTR_DOMAIN_POINT;
return false;
}
@@ -1632,12 +1634,12 @@ bool BKE_pbvh_get_color_layer(const Mesh *me, CustomDataLayer **r_layer, eAttrDo
static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
/* Create and update draw buffers. The functions called here must not
* do any OpenGL calls. Flags are not cleared immediately, that happens
* after GPU_pbvh_buffer_flush() which does the final OpenGL calls. */
PBVHUpdateData *data = userdata;
PBVHUpdateData *data = static_cast<PBVHUpdateData *>(userdata);
PBVH *pbvh = data->pbvh;
PBVHNode *node = data->nodes[n];
@@ -1660,11 +1662,11 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
}
}
void pbvh_free_draw_buffers(PBVH *UNUSED(pbvh), PBVHNode *node)
void pbvh_free_draw_buffers(PBVH * /*pbvh*/, PBVHNode *node)
{
if (node->draw_batches) {
DRW_pbvh_node_free(node->draw_batches);
node->draw_batches = NULL;
node->draw_batches = nullptr;
}
}
@@ -1685,7 +1687,7 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
vdata = pbvh->vdata;
break;
case PBVH_GRIDS:
vdata = NULL;
vdata = nullptr;
break;
}
UNUSED_VARS(vdata);
@@ -1707,10 +1709,9 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
}
/* Parallel creation and update of draw buffers. */
PBVHUpdateData data = {
.pbvh = pbvh,
.nodes = nodes,
};
PBVHUpdateData data{};
data.pbvh = pbvh;
data.nodes = nodes;
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -1818,10 +1819,10 @@ void BKE_pbvh_update_vertex_data(PBVH *pbvh, int flag)
static void pbvh_faces_node_visibility_update(PBVH *pbvh, PBVHNode *node)
{
int totvert, i;
BKE_pbvh_node_num_verts(pbvh, node, NULL, &totvert);
BKE_pbvh_node_num_verts(pbvh, node, nullptr, &totvert);
const int *vert_indices = BKE_pbvh_node_get_vert_indices(node);
if (pbvh->hide_vert == NULL) {
if (pbvh->hide_vert == nullptr) {
BKE_pbvh_node_fully_hidden_set(node, false);
return;
}
@@ -1841,7 +1842,7 @@ static void pbvh_grids_node_visibility_update(PBVH *pbvh, PBVHNode *node)
BLI_bitmap **grid_hidden;
int *grid_indices, totgrid, i;
BKE_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid, NULL, NULL, &grids);
BKE_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid, nullptr, nullptr, &grids);
grid_hidden = BKE_pbvh_grid_hidden(pbvh);
CCGKey key = *BKE_pbvh_get_grid_key(pbvh);
@@ -1876,7 +1877,7 @@ static void pbvh_bmesh_node_visibility_update(PBVHNode *node)
GSetIterator gs_iter;
GSET_ITER (gs_iter, unique) {
BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
BMVert *v = static_cast<BMVert *>(BLI_gsetIterator_getKey(&gs_iter));
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
BKE_pbvh_node_fully_hidden_set(node, false);
return;
@@ -1884,7 +1885,7 @@ static void pbvh_bmesh_node_visibility_update(PBVHNode *node)
}
GSET_ITER (gs_iter, other) {
BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
BMVert *v = static_cast<BMVert *>(BLI_gsetIterator_getKey(&gs_iter));
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
BKE_pbvh_node_fully_hidden_set(node, false);
return;
@@ -1896,10 +1897,10 @@ static void pbvh_bmesh_node_visibility_update(PBVHNode *node)
static void pbvh_update_visibility_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
PBVHUpdateData *data = userdata;
PBVHUpdateData *data = static_cast<PBVHUpdateData *>(userdata);
PBVH *pbvh = data->pbvh;
PBVHNode *node = data->nodes[n];
if (node->flag & PBVH_UpdateVisibility) {
@@ -1920,10 +1921,9 @@ static void pbvh_update_visibility_task_cb(void *__restrict userdata,
static void pbvh_update_visibility(PBVH *pbvh, PBVHNode **nodes, int totnode)
{
PBVHUpdateData data = {
.pbvh = pbvh,
.nodes = nodes,
};
PBVHUpdateData data{};
data.pbvh = pbvh;
data.nodes = nodes;
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
@@ -1956,7 +1956,7 @@ void BKE_pbvh_redraw_BB(PBVH *pbvh, float bb_min[3], float bb_max[3])
BB_reset(&bb);
pbvh_iter_begin(&iter, pbvh, NULL, NULL);
pbvh_iter_begin(&iter, pbvh, nullptr, nullptr);
while ((node = pbvh_iter_next(&iter, PBVH_Leaf))) {
if (node->flag & PBVH_UpdateRedraw) {
@@ -1976,7 +1976,7 @@ void BKE_pbvh_get_grid_updates(PBVH *pbvh, bool clear, void ***r_gridfaces, int
PBVHNode *node;
PBVHIter iter;
pbvh_iter_begin(&iter, pbvh, NULL, NULL);
pbvh_iter_begin(&iter, pbvh, nullptr, nullptr);
while ((node = pbvh_iter_next(&iter, PBVH_Leaf))) {
if (node->flag & PBVH_UpdateNormals) {
@@ -1996,12 +1996,12 @@ void BKE_pbvh_get_grid_updates(PBVH *pbvh, bool clear, void ***r_gridfaces, int
const int tot = BLI_gset_len(face_set);
if (tot == 0) {
*r_totface = 0;
*r_gridfaces = NULL;
BLI_gset_free(face_set, NULL);
*r_gridfaces = nullptr;
BLI_gset_free(face_set, nullptr);
return;
}
void **faces = MEM_mallocN(sizeof(*faces) * tot, "PBVH Grid Faces");
void **faces = static_cast<void **>(MEM_mallocN(sizeof(*faces) * tot, __func__));
GSetIterator gs_iter;
int i;
@@ -2009,7 +2009,7 @@ void BKE_pbvh_get_grid_updates(PBVH *pbvh, bool clear, void ***r_gridfaces, int
faces[i] = BLI_gsetIterator_getKey(&gs_iter);
}
BLI_gset_free(face_set, NULL);
BLI_gset_free(face_set, nullptr);
*r_totface = tot;
*r_gridfaces = faces;
@@ -2051,7 +2051,7 @@ const CCGKey *BKE_pbvh_get_grid_key(const PBVH *pbvh)
return &pbvh->gridkey;
}
struct CCGElem **BKE_pbvh_get_grids(const PBVH *pbvh)
CCGElem **BKE_pbvh_get_grids(const PBVH *pbvh)
{
BLI_assert(pbvh->header.type == PBVH_GRIDS);
return pbvh->grids;
@@ -2285,7 +2285,7 @@ void BKE_pbvh_node_get_grids(PBVH *pbvh,
case PBVH_FACES:
case PBVH_BMESH:
if (r_grid_indices) {
*r_grid_indices = NULL;
*r_grid_indices = nullptr;
}
if (r_totgrid) {
*r_totgrid = 0;
@@ -2297,7 +2297,7 @@ void BKE_pbvh_node_get_grids(PBVH *pbvh,
*r_gridsize = 0;
}
if (r_griddata) {
*r_griddata = NULL;
*r_griddata = nullptr;
}
break;
}
@@ -2327,7 +2327,7 @@ void BKE_pbvh_node_get_proxies(PBVHNode *node, PBVHProxyNode **proxies, int *pro
}
else {
if (proxies) {
*proxies = NULL;
*proxies = nullptr;
}
if (proxy_count) {
*proxy_count = 0;
@@ -2369,14 +2369,14 @@ bool BKE_pbvh_node_has_vert_with_normal_update_tag(PBVH *pbvh, PBVHNode *node)
/********************************* Ray-cast ***********************************/
typedef struct {
struct IsectRayAABB_Precalc ray;
struct RaycastData {
IsectRayAABB_Precalc ray;
bool original;
} RaycastData;
};
static bool ray_aabb_intersect(PBVHNode *node, void *data_v)
{
RaycastData *rcd = data_v;
RaycastData *rcd = static_cast<RaycastData *>(data_v);
const float *bb_min, *bb_max;
if (rcd->original) {
@@ -2409,7 +2409,7 @@ void BKE_pbvh_raycast(PBVH *pbvh,
}
bool ray_face_intersection_quad(const float ray_start[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
const float t0[3],
const float t1[3],
const float t2[3],
@@ -2418,9 +2418,9 @@ bool ray_face_intersection_quad(const float ray_start[3],
{
float depth_test;
if ((isect_ray_tri_watertight_v3(ray_start, isect_precalc, t0, t1, t2, &depth_test, NULL) &&
if ((isect_ray_tri_watertight_v3(ray_start, isect_precalc, t0, t1, t2, &depth_test, nullptr) &&
(depth_test < *depth)) ||
(isect_ray_tri_watertight_v3(ray_start, isect_precalc, t0, t2, t3, &depth_test, NULL) &&
(isect_ray_tri_watertight_v3(ray_start, isect_precalc, t0, t2, t3, &depth_test, nullptr) &&
(depth_test < *depth))) {
*depth = depth_test;
return true;
@@ -2430,14 +2430,14 @@ bool ray_face_intersection_quad(const float ray_start[3],
}
bool ray_face_intersection_tri(const float ray_start[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
const float t0[3],
const float t1[3],
const float t2[3],
float *depth)
{
float depth_test;
if (isect_ray_tri_watertight_v3(ray_start, isect_precalc, t0, t1, t2, &depth_test, NULL) &&
if (isect_ray_tri_watertight_v3(ray_start, isect_precalc, t0, t1, t2, &depth_test, nullptr) &&
(depth_test < *depth)) {
*depth = depth_test;
return true;
@@ -2524,7 +2524,7 @@ static bool pbvh_faces_node_raycast(PBVH *pbvh,
float (*origco)[3],
const float ray_start[3],
const float ray_normal[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
float *depth,
PBVHVertRef *r_active_vertex,
int *r_active_face_index,
@@ -2592,7 +2592,7 @@ static bool pbvh_grids_node_raycast(PBVH *pbvh,
float (*origco)[3],
const float ray_start[3],
const float ray_normal[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
float *depth,
PBVHVertRef *r_active_vertex,
int *r_active_grid_index,
@@ -2687,7 +2687,7 @@ bool BKE_pbvh_node_raycast(PBVH *pbvh,
bool use_origco,
const float ray_start[3],
const float ray_normal[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
float *depth,
PBVHVertRef *active_vertex,
int *active_face_grid_index,
@@ -2746,7 +2746,7 @@ void BKE_pbvh_raycast_project_ray_root(
if (pbvh->nodes) {
float rootmin_start, rootmin_end;
float bb_min_root[3], bb_max_root[3], bb_center[3], bb_diff[3];
struct IsectRayAABB_Precalc ray;
IsectRayAABB_Precalc ray;
float ray_normal_inv[3];
float offset = 1.0f + 1e-3f;
const float offset_vec[3] = {1e-3f, 1e-3f, 1e-3f};
@@ -2789,14 +2789,14 @@ void BKE_pbvh_raycast_project_ray_root(
/* -------------------------------------------------------------------- */
typedef struct {
struct DistRayAABB_Precalc dist_ray_to_aabb_precalc;
struct FindNearestRayData {
DistRayAABB_Precalc dist_ray_to_aabb_precalc;
bool original;
} FindNearestRayData;
};
static bool nearest_to_ray_aabb_dist_sq(PBVHNode *node, void *data_v)
{
FindNearestRayData *rcd = data_v;
FindNearestRayData *rcd = static_cast<FindNearestRayData *>(data_v);
const float *bb_min, *bb_max;
if (rcd->original) {
@@ -2974,11 +2974,11 @@ bool BKE_pbvh_node_find_nearest_to_ray(PBVH *pbvh,
return hit;
}
typedef enum {
enum PlaneAABBIsect {
ISECT_INSIDE,
ISECT_OUTSIDE,
ISECT_INTERSECT,
} PlaneAABBIsect;
};
/* Adapted from:
* http://www.gamedev.net/community/forums/topic.asp?topic_id=512123
@@ -3024,7 +3024,8 @@ bool BKE_pbvh_node_frustum_contain_AABB(PBVHNode *node, void *data)
bb_min = node->vb.bmin;
bb_max = node->vb.bmax;
return test_frustum_aabb(bb_min, bb_max, data) != ISECT_OUTSIDE;
return test_frustum_aabb(bb_min, bb_max, static_cast<PBVHFrustumPlanes *>(data)) !=
ISECT_OUTSIDE;
}
bool BKE_pbvh_node_frustum_exclude_AABB(PBVHNode *node, void *data)
@@ -3034,10 +3035,10 @@ bool BKE_pbvh_node_frustum_exclude_AABB(PBVHNode *node, void *data)
bb_min = node->vb.bmin;
bb_max = node->vb.bmax;
return test_frustum_aabb(bb_min, bb_max, data) != ISECT_INSIDE;
return test_frustum_aabb(bb_min, bb_max, static_cast<PBVHFrustumPlanes *>(data)) != ISECT_INSIDE;
}
void BKE_pbvh_update_normals(PBVH *pbvh, struct SubdivCCG *subdiv_ccg)
void BKE_pbvh_update_normals(PBVH *pbvh, SubdivCCG *subdiv_ccg)
{
/* Update normals */
PBVHNode **nodes;
@@ -3054,7 +3055,7 @@ void BKE_pbvh_update_normals(PBVH *pbvh, struct SubdivCCG *subdiv_ccg)
pbvh_faces_update_normals(pbvh, nodes, totnode);
}
else if (pbvh->header.type == PBVH_GRIDS) {
struct CCGFace **faces;
CCGFace **faces;
int num_faces;
BKE_pbvh_get_grid_updates(pbvh, true, (void ***)&faces, &num_faces);
if (num_faces > 0) {
@@ -3077,16 +3078,16 @@ void BKE_pbvh_face_sets_color_set(PBVH *pbvh, int seed, int color_default)
* PBVH drawing, updating draw buffers as needed and culling any nodes outside
* the specified frustum.
*/
typedef struct PBVHDrawSearchData {
struct PBVHDrawSearchData {
PBVHFrustumPlanes *frustum;
int accum_update_flag;
PBVHAttrReq *attrs;
int attrs_num;
} PBVHDrawSearchData;
};
static bool pbvh_draw_search_cb(PBVHNode *node, void *data_v)
{
PBVHDrawSearchData *data = data_v;
PBVHDrawSearchData *data = static_cast<PBVHDrawSearchData *>(data_v);
if (data->frustum && !BKE_pbvh_node_frustum_contain_AABB(node, data->frustum)) {
return false;
}
@@ -3101,7 +3102,7 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
PBVHFrustumPlanes *draw_frustum,
void (*draw_fn)(void *user_data, PBVHBatches *batches, PBVH_GPU_Args *args),
void *user_data,
bool UNUSED(full_render),
bool /*full_render*/,
PBVHAttrReq *attrs,
int attrs_num)
{
@@ -3114,8 +3115,11 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
/* Search for nodes that need updates. */
if (update_only_visible) {
/* Get visible nodes with draw updates. */
PBVHDrawSearchData data = {
.frustum = update_frustum, .accum_update_flag = 0, attrs, attrs_num};
PBVHDrawSearchData data{};
data.frustum = update_frustum;
data.accum_update_flag = 0;
data.attrs = attrs;
data.attrs_num = attrs_num;
BKE_pbvh_search_gather(pbvh, pbvh_draw_search_cb, &data, &nodes, &totnode);
update_flag = data.accum_update_flag;
}
@@ -3134,7 +3138,9 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
MEM_SAFE_FREE(nodes);
/* Draw visible nodes. */
PBVHDrawSearchData draw_data = {.frustum = draw_frustum, .accum_update_flag = 0};
PBVHDrawSearchData draw_data{};
draw_data.frustum = draw_frustum;
draw_data.accum_update_flag = 0;
BKE_pbvh_search_gather(pbvh, pbvh_draw_search_cb, &draw_data, &nodes, &totnode);
PBVH_GPU_Args args;
@@ -3204,10 +3210,11 @@ void BKE_pbvh_grids_update(PBVH *pbvh,
float (*BKE_pbvh_vert_coords_alloc(PBVH *pbvh))[3]
{
float(*vertCos)[3] = NULL;
float(*vertCos)[3] = nullptr;
if (pbvh->vert_positions) {
vertCos = MEM_malloc_arrayN(pbvh->totvert, sizeof(float[3]), __func__);
vertCos = static_cast<float(*)[3]>(
MEM_malloc_arrayN(pbvh->totvert, sizeof(float[3]), __func__));
memcpy(vertCos, pbvh->vert_positions, sizeof(float[3]) * pbvh->totvert);
}
@@ -3227,7 +3234,7 @@ void BKE_pbvh_vert_coords_apply(PBVH *pbvh, const float (*vertCos)[3], const int
/* original data and applying new coords to this arrays would lead to */
/* unneeded deformation -- duplicate verts/faces to avoid this */
pbvh->vert_positions = MEM_dupallocN(pbvh->vert_positions);
pbvh->vert_positions = static_cast<float(*)[3]>(MEM_dupallocN(pbvh->vert_positions));
/* No need to dupalloc pbvh->looptri, this one is 'totally owned' by pbvh,
* it's never some mesh data. */
@@ -3269,14 +3276,16 @@ PBVHProxyNode *BKE_pbvh_node_add_proxy(PBVH *pbvh, PBVHNode *node)
node->proxy_count++;
if (node->proxies) {
node->proxies = MEM_reallocN(node->proxies, node->proxy_count * sizeof(PBVHProxyNode));
node->proxies = static_cast<PBVHProxyNode *>(
MEM_reallocN(node->proxies, node->proxy_count * sizeof(PBVHProxyNode)));
}
else {
node->proxies = MEM_mallocN(sizeof(PBVHProxyNode), "PBVHNodeProxy");
node->proxies = static_cast<PBVHProxyNode *>(MEM_mallocN(sizeof(PBVHProxyNode), __func__));
}
BKE_pbvh_node_num_verts(pbvh, node, &totverts, NULL);
node->proxies[index].co = MEM_callocN(sizeof(float[3]) * totverts, "PBVHNodeProxy.co");
BKE_pbvh_node_num_verts(pbvh, node, &totverts, nullptr);
node->proxies[index].co = static_cast<float(*)[3]>(
MEM_callocN(sizeof(float[3]) * totverts, __func__));
return node->proxies + index;
}
@@ -3285,18 +3294,18 @@ void BKE_pbvh_node_free_proxies(PBVHNode *node)
{
for (int p = 0; p < node->proxy_count; p++) {
MEM_freeN(node->proxies[p].co);
node->proxies[p].co = NULL;
node->proxies[p].co = nullptr;
}
MEM_freeN(node->proxies);
node->proxies = NULL;
node->proxies = nullptr;
node->proxy_count = 0;
}
void BKE_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot)
{
PBVHNode **array = NULL;
PBVHNode **array = nullptr;
int tot = 0, space = 0;
for (int n = 0; n < pbvh->totnode; n++) {
@@ -3306,7 +3315,8 @@ void BKE_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot)
if (tot == space) {
/* resize array if needed */
space = (tot == 0) ? 32 : space * 2;
array = MEM_recallocN_id(array, sizeof(PBVHNode *) * space, __func__);
array = static_cast<PBVHNode **>(
MEM_recallocN_id(array, sizeof(PBVHNode *) * space, __func__));
}
array[tot] = node;
@@ -3316,7 +3326,7 @@ void BKE_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot)
if (tot == 0 && array) {
MEM_freeN(array);
array = NULL;
array = nullptr;
}
*r_array = array;
@@ -3327,7 +3337,8 @@ PBVHColorBufferNode *BKE_pbvh_node_color_buffer_get(PBVHNode *node)
{
if (!node->color_buffer.color) {
node->color_buffer.color = MEM_callocN(sizeof(float[4]) * node->uniq_verts, "Color buffer");
node->color_buffer.color = static_cast<float(*)[4]>(
MEM_callocN(sizeof(float[4]) * node->uniq_verts, "Color buffer"));
}
return &node->color_buffer;
}
@@ -3336,7 +3347,7 @@ void BKE_pbvh_node_color_buffer_free(PBVH *pbvh)
{
PBVHNode **nodes;
int totnode;
BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode);
BKE_pbvh_search_gather(pbvh, nullptr, nullptr, &nodes, &totnode);
for (int i = 0; i < totnode; i++) {
MEM_SAFE_FREE(nodes[i]->color_buffer.color);
}
@@ -3345,14 +3356,14 @@ void BKE_pbvh_node_color_buffer_free(PBVH *pbvh)
void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int mode)
{
struct CCGElem **grids;
CCGElem **grids;
int *grid_indices;
int totgrid, gridsize, uniq_verts, totvert;
vi->grid = NULL;
vi->no = NULL;
vi->fno = NULL;
vi->vert_positions = NULL;
vi->grid = nullptr;
vi->no = nullptr;
vi->fno = nullptr;
vi->vert_positions = nullptr;
vi->vertex.i = 0LL;
vi->respect_hide = pbvh->respect_hide;
@@ -3361,7 +3372,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
vi->visible = true;
}
BKE_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid, NULL, &gridsize, &grids);
BKE_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid, nullptr, &gridsize, &grids);
BKE_pbvh_node_num_verts(pbvh, node, &uniq_verts, &totvert);
const int *vert_indices = BKE_pbvh_node_get_vert_indices(node);
vi->key = pbvh->gridkey;
@@ -3379,7 +3390,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
}
vi->vert_indices = vert_indices;
vi->vert_positions = pbvh->vert_positions;
vi->is_mesh = pbvh->vert_positions != NULL;
vi->is_mesh = pbvh->vert_positions != nullptr;
if (pbvh->header.type == PBVH_BMESH) {
BLI_gsetIterator_init(&vi->bm_unique_verts, node->bm_unique_verts);
@@ -3388,17 +3399,18 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
vi->cd_vert_mask_offset = CustomData_get_offset(vi->bm_vdata, CD_PAINT_MASK);
}
vi->gh = NULL;
vi->gh = nullptr;
if (vi->grids && mode == PBVH_ITER_UNIQUE) {
vi->grid_hidden = pbvh->grid_hidden;
}
vi->mask = NULL;
vi->mask = nullptr;
if (pbvh->header.type == PBVH_FACES) {
vi->vert_normals = pbvh->vert_normals;
vi->hide_vert = pbvh->hide_vert;
vi->vmask = CustomData_get_layer_for_write(pbvh->vdata, CD_PAINT_MASK, pbvh->mesh->totvert);
vi->vmask = static_cast<float *>(
CustomData_get_layer_for_write(pbvh->vdata, CD_PAINT_MASK, pbvh->mesh->totvert));
}
}
@@ -3423,7 +3435,7 @@ bool pbvh_has_face_sets(PBVH *pbvh)
case PBVH_GRIDS:
case PBVH_FACES:
return pbvh->pdata &&
CustomData_get_layer_named(pbvh->pdata, CD_PROP_INT32, ".sculpt_face_set") != NULL;
CustomData_get_layer_named(pbvh->pdata, CD_PROP_INT32, ".sculpt_face_set") != nullptr;
case PBVH_BMESH:
return false;
}
@@ -3485,13 +3497,17 @@ bool *BKE_pbvh_get_vert_hide_for_write(PBVH *pbvh)
if (pbvh->hide_vert) {
return pbvh->hide_vert;
}
pbvh->hide_vert = CustomData_get_layer_named_for_write(
&pbvh->mesh->vdata, CD_PROP_BOOL, ".hide_vert", pbvh->mesh->totvert);
pbvh->hide_vert = static_cast<bool *>(CustomData_get_layer_named_for_write(
&pbvh->mesh->vdata, CD_PROP_BOOL, ".hide_vert", pbvh->mesh->totvert));
if (pbvh->hide_vert) {
return pbvh->hide_vert;
}
pbvh->hide_vert = (bool *)CustomData_add_layer_named(
&pbvh->mesh->vdata, CD_PROP_BOOL, CD_SET_DEFAULT, NULL, pbvh->mesh->totvert, ".hide_vert");
pbvh->hide_vert = static_cast<bool *>(CustomData_add_layer_named(&pbvh->mesh->vdata,
CD_PROP_BOOL,
CD_SET_DEFAULT,
nullptr,
pbvh->mesh->totvert,
".hide_vert"));
return pbvh->hide_vert;
}
@@ -3508,10 +3524,10 @@ void BKE_pbvh_face_sets_set(PBVH *pbvh, int *face_sets)
void BKE_pbvh_update_hide_attributes_from_mesh(PBVH *pbvh)
{
if (pbvh->header.type == PBVH_FACES) {
pbvh->hide_vert = CustomData_get_layer_named_for_write(
&pbvh->mesh->vdata, CD_PROP_BOOL, ".hide_vert", pbvh->mesh->totvert);
pbvh->hide_poly = CustomData_get_layer_named_for_write(
&pbvh->mesh->pdata, CD_PROP_BOOL, ".hide_poly", pbvh->mesh->totpoly);
pbvh->hide_vert = static_cast<bool *>(CustomData_get_layer_named_for_write(
&pbvh->mesh->vdata, CD_PROP_BOOL, ".hide_vert", pbvh->mesh->totvert));
pbvh->hide_poly = static_cast<bool *>(CustomData_get_layer_named_for_write(
&pbvh->mesh->pdata, CD_PROP_BOOL, ".hide_poly", pbvh->mesh->totpoly));
}
}
@@ -3586,7 +3602,8 @@ void BKE_pbvh_ensure_node_loops(PBVH *pbvh)
continue;
}
node->loop_indices = MEM_malloc_arrayN(node->totprim * 3, sizeof(int), __func__);
node->loop_indices = static_cast<int *>(
MEM_malloc_arrayN(node->totprim * 3, sizeof(int), __func__));
node->loop_indices_num = 0;
for (int j = 0; j < node->totprim; j++) {
@@ -3618,7 +3635,8 @@ static void pbvh_face_iter_verts_reserve(PBVHFaceIter *fd, int verts_num)
MEM_SAFE_FREE(fd->verts);
}
fd->verts = MEM_malloc_arrayN(fd->verts_size_, sizeof(void *), __func__);
fd->verts = static_cast<PBVHVertRef *>(
MEM_malloc_arrayN(fd->verts_size_, sizeof(void *), __func__));
}
fd->verts_num = verts_num;
@@ -3831,8 +3849,8 @@ void BKE_pbvh_sync_visibility_from_verts(PBVH *pbvh, Mesh *mesh)
const MPoly *mp = BKE_mesh_polys(mesh);
CCGKey key = pbvh->gridkey;
bool *hide_poly = (bool *)CustomData_get_layer_named_for_write(
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly);
bool *hide_poly = static_cast<bool *>(CustomData_get_layer_named_for_write(
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly));
bool delete_hide_poly = true;
for (int face_index = 0; face_index < mesh->totpoly; face_index++, mp++) {
@@ -3850,15 +3868,12 @@ void BKE_pbvh_sync_visibility_from_verts(PBVH *pbvh, Mesh *mesh)
}
if (hidden && !hide_poly) {
hide_poly = (bool *)CustomData_get_layer_named_for_write(
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly);
hide_poly = static_cast<bool *>(CustomData_get_layer_named_for_write(
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly));
if (!hide_poly) {
CustomData_add_layer_named(
&mesh->pdata, CD_PROP_BOOL, CD_CONSTRUCT, NULL, mesh->totpoly, ".hide_poly");
hide_poly = (bool *)CustomData_get_layer_named_for_write(
&mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly);
hide_poly = static_cast<bool *>(CustomData_add_layer_named(
&mesh->pdata, CD_PROP_BOOL, CD_CONSTRUCT, nullptr, mesh->totpoly, ".hide_poly"));
}
}

View File

@@ -20,7 +20,7 @@
#include "DRW_pbvh.h"
#include "bmesh.h"
#include "pbvh_intern.h"
#include "pbvh_intern.hh"
/* Avoid skinny faces */
#define USE_EDGEQUEUE_EVEN_SUBDIV
@@ -106,9 +106,9 @@ static void pbvh_bmesh_verify(PBVH *pbvh);
static void bm_edges_from_tri(BMesh *bm, BMVert *v_tri[3], BMEdge *e_tri[3])
{
e_tri[0] = BM_edge_create(bm, v_tri[0], v_tri[1], NULL, BM_CREATE_NO_DOUBLE);
e_tri[1] = BM_edge_create(bm, v_tri[1], v_tri[2], NULL, BM_CREATE_NO_DOUBLE);
e_tri[2] = BM_edge_create(bm, v_tri[2], v_tri[0], NULL, BM_CREATE_NO_DOUBLE);
e_tri[0] = BM_edge_create(bm, v_tri[0], v_tri[1], nullptr, BM_CREATE_NO_DOUBLE);
e_tri[1] = BM_edge_create(bm, v_tri[1], v_tri[2], nullptr, BM_CREATE_NO_DOUBLE);
e_tri[2] = BM_edge_create(bm, v_tri[2], v_tri[0], nullptr, BM_CREATE_NO_DOUBLE);
}
BLI_INLINE void bm_face_as_array_index_tri(BMFace *f, int r_index[3])
@@ -154,7 +154,7 @@ static BMFace *bm_face_exists_tri_from_loop_vert(BMLoop *l_radial_first, BMVert
}
} while ((l_radial_iter = l_radial_iter->radial_next) != l_radial_first);
}
return NULL;
return nullptr;
}
/**
@@ -165,13 +165,13 @@ static BMVert *bm_vert_hash_lookup_chain(GHash *deleted_verts, BMVert *v)
{
while (true) {
BMVert **v_next_p = (BMVert **)BLI_ghash_lookup_p(deleted_verts, v);
if (v_next_p == NULL) {
if (v_next_p == nullptr) {
/* Not remapped. */
return v;
}
if (*v_next_p == NULL) {
if (*v_next_p == nullptr) {
/* removed and not remapped */
return NULL;
return nullptr;
}
/* remapped */
@@ -200,7 +200,7 @@ static void pbvh_bmesh_node_finalize(PBVH *pbvh,
BB_reset(&n->vb);
GSET_ITER (gs_iter, n->bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
/* Update ownership of faces */
BM_ELEM_CD_SET_INT(f, cd_face_node_offset, node_index);
@@ -259,7 +259,7 @@ static void pbvh_bmesh_node_split(PBVH *pbvh, const BBC *bbc_array, int node_ind
BB_reset(&cb);
GSetIterator gs_iter;
GSET_ITER (gs_iter, n->bm_faces) {
const BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
const BMFace *f = static_cast<const BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
const BBC *bbc = &bbc_array[BM_elem_index_get(f)];
BB_expand(&cb, bbc->bcentroid);
@@ -286,7 +286,7 @@ static void pbvh_bmesh_node_split(PBVH *pbvh, const BBC *bbc_array, int node_ind
/* Partition the parent node's faces between the two children */
GSET_ITER (gs_iter, n->bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
const BBC *bbc = &bbc_array[BM_elem_index_get(f)];
if (bbc->bcentroid[axis] < mid) {
@@ -298,7 +298,7 @@ static void pbvh_bmesh_node_split(PBVH *pbvh, const BBC *bbc_array, int node_ind
}
/* Enforce at least one primitive in each node */
GSet *empty = NULL, *other;
GSet *empty = nullptr, *other;
if (BLI_gset_len(c1->bm_faces) == 0) {
empty = c1->bm_faces;
other = c2->bm_faces;
@@ -311,7 +311,7 @@ static void pbvh_bmesh_node_split(PBVH *pbvh, const BBC *bbc_array, int node_ind
GSET_ITER (gs_iter, other) {
void *key = BLI_gsetIterator_getKey(&gs_iter);
BLI_gset_insert(empty, key);
BLI_gset_remove(other, key, NULL);
BLI_gset_remove(other, key, nullptr);
break;
}
}
@@ -321,31 +321,31 @@ static void pbvh_bmesh_node_split(PBVH *pbvh, const BBC *bbc_array, int node_ind
/* Mark this node's unique verts as unclaimed */
if (n->bm_unique_verts) {
GSET_ITER (gs_iter, n->bm_unique_verts) {
BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
BMVert *v = static_cast<BMVert *>(BLI_gsetIterator_getKey(&gs_iter));
BM_ELEM_CD_SET_INT(v, cd_vert_node_offset, DYNTOPO_NODE_NONE);
}
BLI_gset_free(n->bm_unique_verts, NULL);
BLI_gset_free(n->bm_unique_verts, nullptr);
}
/* Unclaim faces */
GSET_ITER (gs_iter, n->bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
BM_ELEM_CD_SET_INT(f, cd_face_node_offset, DYNTOPO_NODE_NONE);
}
BLI_gset_free(n->bm_faces, NULL);
BLI_gset_free(n->bm_faces, nullptr);
if (n->bm_other_verts) {
BLI_gset_free(n->bm_other_verts, NULL);
BLI_gset_free(n->bm_other_verts, nullptr);
}
if (n->layer_disp) {
MEM_freeN(n->layer_disp);
}
n->bm_faces = NULL;
n->bm_unique_verts = NULL;
n->bm_other_verts = NULL;
n->layer_disp = NULL;
n->bm_faces = nullptr;
n->bm_unique_verts = nullptr;
n->bm_other_verts = nullptr;
n->layer_disp = nullptr;
if (n->draw_batches) {
DRW_pbvh_node_free(n->draw_batches);
@@ -380,12 +380,12 @@ static bool pbvh_bmesh_node_limit_ensure(PBVH *pbvh, int node_index)
pbvh->draw_cache_invalid = true;
/* For each BMFace, store the AABB and AABB centroid */
BBC *bbc_array = MEM_mallocN(sizeof(BBC) * bm_faces_size, "BBC");
BBC *bbc_array = static_cast<BBC *>(MEM_mallocN(sizeof(BBC) * bm_faces_size, "BBC"));
GSetIterator gs_iter;
int i;
GSET_ITER_INDEX (gs_iter, bm_faces, i) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
BBC *bbc = &bbc_array[i];
BB_reset((BB *)bbc);
@@ -484,7 +484,7 @@ static BMVert *pbvh_bmesh_vert_create(PBVH *pbvh,
BLI_assert((pbvh->totnode == 1 || node_index) && node_index <= pbvh->totnode);
/* avoid initializing customdata because its quite involved */
BMVert *v = BM_vert_create(pbvh->header.bm, co, NULL, BM_CREATE_SKIP_CD);
BMVert *v = BM_vert_create(pbvh->header.bm, co, nullptr, BM_CREATE_SKIP_CD);
CustomData_bmesh_set_default(&pbvh->header.bm->vdata, &v->head.data);
/* This value is logged below */
@@ -587,7 +587,7 @@ static PBVHNode *pbvh_bmesh_vert_other_node_find(PBVH *pbvh, BMVert *v)
}
BM_FACES_OF_VERT_ITER_END;
return NULL;
return nullptr;
}
static void pbvh_bmesh_vert_ownership_transfer(PBVH *pbvh, PBVHNode *new_owner, BMVert *v)
@@ -599,12 +599,12 @@ static void pbvh_bmesh_vert_ownership_transfer(PBVH *pbvh, PBVHNode *new_owner,
BLI_assert(current_owner != new_owner);
/* Remove current ownership */
BLI_gset_remove(current_owner->bm_unique_verts, v, NULL);
BLI_gset_remove(current_owner->bm_unique_verts, v, nullptr);
/* Set new ownership */
BM_ELEM_CD_SET_INT(v, pbvh->cd_vert_node_offset, new_owner - pbvh->nodes);
BLI_gset_insert(new_owner->bm_unique_verts, v);
BLI_gset_remove(new_owner->bm_other_verts, v, NULL);
BLI_gset_remove(new_owner->bm_other_verts, v, nullptr);
BLI_assert(!BLI_gset_haskey(new_owner->bm_other_verts, v));
/* mark node for update */
@@ -617,7 +617,7 @@ static void pbvh_bmesh_vert_remove(PBVH *pbvh, BMVert *v)
int f_node_index_prev = DYNTOPO_NODE_NONE;
PBVHNode *v_node = pbvh_bmesh_node_from_vert(pbvh, v);
BLI_gset_remove(v_node->bm_unique_verts, v, NULL);
BLI_gset_remove(v_node->bm_unique_verts, v, nullptr);
BM_ELEM_CD_SET_INT(v, pbvh->cd_vert_node_offset, DYNTOPO_NODE_NONE);
/* Have to check each neighboring face's node */
@@ -634,7 +634,7 @@ static void pbvh_bmesh_vert_remove(PBVH *pbvh, BMVert *v)
f_node->flag |= PBVH_UpdateDrawBuffers | PBVH_UpdateBB | PBVH_TopologyUpdated;
/* Remove current ownership */
BLI_gset_remove(f_node->bm_other_verts, v, NULL);
BLI_gset_remove(f_node->bm_other_verts, v, nullptr);
BLI_assert(!BLI_gset_haskey(f_node->bm_unique_verts, v));
BLI_assert(!BLI_gset_haskey(f_node->bm_other_verts, v));
@@ -667,13 +667,13 @@ static void pbvh_bmesh_face_remove(PBVH *pbvh, BMFace *f)
}
else {
/* Remove from other verts */
BLI_gset_remove(f_node->bm_other_verts, v, NULL);
BLI_gset_remove(f_node->bm_other_verts, v, nullptr);
}
}
} while ((l_iter = l_iter->next) != l_first);
/* Remove face from node and top level */
BLI_gset_remove(f_node->bm_faces, f, NULL);
BLI_gset_remove(f_node->bm_faces, f, nullptr);
BM_ELEM_CD_SET_INT(f, pbvh->cd_face_node_offset, DYNTOPO_NODE_NONE);
/* Log removed face */
@@ -688,14 +688,14 @@ static void pbvh_bmesh_edge_loops(BLI_Buffer *buf, BMEdge *e)
/* fast-path for most common case where an edge has 2 faces,
* no need to iterate twice.
* This assumes that the buffer */
BMLoop **data = buf->data;
BMLoop **data = static_cast<BMLoop **>(buf->data);
BLI_assert(buf->alloc_count >= 2);
if (LIKELY(BM_edge_loop_pair(e, &data[0], &data[1]))) {
buf->count = 2;
}
else {
BLI_buffer_reinit(buf, BM_edge_face_count(e));
BM_iter_as_array(NULL, BM_LOOPS_OF_EDGE, e, buf->data, buf->count);
BM_iter_as_array(nullptr, BM_LOOPS_OF_EDGE, e, static_cast<void **>(buf->data), buf->count);
}
}
@@ -709,9 +709,7 @@ static void pbvh_bmesh_node_drop_orig(PBVHNode *node)
/****************************** EdgeQueue *****************************/
struct EdgeQueue;
typedef struct EdgeQueue {
struct EdgeQueue {
HeapSimple *heap;
const float *center;
float center_proj[3]; /* for when we use projected coords. */
@@ -721,22 +719,22 @@ typedef struct EdgeQueue {
float limit_len;
#endif
bool (*edge_queue_tri_in_range)(const struct EdgeQueue *q, BMFace *f);
bool (*edge_queue_tri_in_range)(const EdgeQueue *q, BMFace *f);
const float *view_normal;
#ifdef USE_EDGEQUEUE_FRONTFACE
uint use_view_normal : 1;
#endif
} EdgeQueue;
};
typedef struct {
struct EdgeQueueContext {
EdgeQueue *q;
BLI_mempool *pool;
BMesh *bm;
int cd_vert_mask_offset;
int cd_vert_node_offset;
int cd_face_node_offset;
} EdgeQueueContext;
};
/* only tag'd edges are in the queue */
#ifdef USE_EDGEQUEUE_TAG
@@ -828,7 +826,7 @@ static void edge_queue_insert(EdgeQueueContext *eq_ctx, BMEdge *e, float priorit
(check_mask(eq_ctx, e->v1) || check_mask(eq_ctx, e->v2))) &&
!(BM_elem_flag_test_bool(e->v1, BM_ELEM_HIDDEN) ||
BM_elem_flag_test_bool(e->v2, BM_ELEM_HIDDEN))) {
BMVert **pair = BLI_mempool_alloc(eq_ctx->pool);
BMVert **pair = static_cast<BMVert **>(BLI_mempool_alloc(eq_ctx->pool));
pair[0] = e->v1;
pair[1] = e->v2;
BLI_heapsimple_insert(eq_ctx->q->heap, priority, pair);
@@ -1028,7 +1026,7 @@ static void long_edge_queue_create(EdgeQueueContext *eq_ctx,
/* Check each face */
GSET_ITER (gs_iter, node->bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
long_edge_queue_face_add(eq_ctx, f);
}
@@ -1087,7 +1085,7 @@ static void short_edge_queue_create(EdgeQueueContext *eq_ctx,
/* Check each face */
GSET_ITER (gs_iter, node->bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
short_edge_queue_face_add(eq_ctx, f);
}
@@ -1187,9 +1185,9 @@ static void pbvh_bmesh_split_edge(EdgeQueueContext *eq_ctx,
v_tri[0] = v_new;
v_tri[1] = v2;
/* v_tri[2] = v_opp; */ /* unchanged */
e_tri[0] = BM_edge_create(pbvh->header.bm, v_tri[0], v_tri[1], NULL, BM_CREATE_NO_DOUBLE);
e_tri[0] = BM_edge_create(pbvh->header.bm, v_tri[0], v_tri[1], nullptr, BM_CREATE_NO_DOUBLE);
e_tri[2] = e_tri[1]; /* switched */
e_tri[1] = BM_edge_create(pbvh->header.bm, v_tri[1], v_tri[2], NULL, BM_CREATE_NO_DOUBLE);
e_tri[1] = BM_edge_create(pbvh->header.bm, v_tri[1], v_tri[2], nullptr, BM_CREATE_NO_DOUBLE);
f_new = pbvh_bmesh_face_create(pbvh, ni, v_tri, e_tri, f_adj);
long_edge_queue_face_add(eq_ctx, f_new);
@@ -1222,12 +1220,12 @@ static bool pbvh_bmesh_subdivide_long_edges(EdgeQueueContext *eq_ctx,
bool any_subdivided = false;
while (!BLI_heapsimple_is_empty(eq_ctx->q->heap)) {
BMVert **pair = BLI_heapsimple_pop_min(eq_ctx->q->heap);
BMVert **pair = static_cast<BMVert **>(BLI_heapsimple_pop_min(eq_ctx->q->heap));
BMVert *v1 = pair[0], *v2 = pair[1];
BMEdge *e;
BLI_mempool_free(eq_ctx->pool, pair);
pair = NULL;
pair = nullptr;
/* Check that the edge still exists */
if (!(e = BM_edge_exists(v1, v2))) {
@@ -1318,7 +1316,7 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
BMFace *existing_face;
/* Get vertices, replace use of v_del with v_conn */
// BM_iter_as_array(NULL, BM_VERTS_OF_FACE, f, (void **)v_tri, 3);
// BM_iter_as_array(nullptr, BM_VERTS_OF_FACE, f, (void **)v_tri, 3);
BMFace *f = l->f;
#if 0
BMVert *v_tri[3];
@@ -1396,15 +1394,15 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
/* Check if any of the face's vertices are now unused, if so
* remove them from the PBVH */
for (int j = 0; j < 3; j++) {
if ((v_tri[j] != v_del) && (v_tri[j]->e == NULL)) {
if ((v_tri[j] != v_del) && (v_tri[j]->e == nullptr)) {
pbvh_bmesh_vert_remove(pbvh, v_tri[j]);
BM_log_vert_removed(pbvh->bm_log, v_tri[j], eq_ctx->cd_vert_mask_offset);
if (v_tri[j] == v_conn) {
v_conn = NULL;
v_conn = nullptr;
}
BLI_ghash_insert(deleted_verts, v_tri[j], NULL);
BLI_ghash_insert(deleted_verts, v_tri[j], nullptr);
BM_vert_kill(pbvh->header.bm, v_tri[j]);
}
}
@@ -1412,7 +1410,7 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
/* Move v_conn to the midpoint of v_conn and v_del (if v_conn still exists, it
* may have been deleted above) */
if (v_conn != NULL) {
if (v_conn != nullptr) {
BM_log_vert_before_modified(pbvh->bm_log, v_conn, eq_ctx->cd_vert_mask_offset);
mid_v3_v3v3(v_conn->co, v_conn->co, v_del->co);
add_v3_v3(v_conn->no, v_del->no);
@@ -1430,7 +1428,7 @@ static void pbvh_bmesh_collapse_edge(PBVH *pbvh,
/* Delete v_del */
BLI_assert(!BM_vert_face_check(v_del));
BM_log_vert_removed(pbvh->bm_log, v_del, eq_ctx->cd_vert_mask_offset);
/* v_conn == NULL is OK */
/* v_conn == nullptr is OK */
BLI_ghash_insert(deleted_verts, v_del, v_conn);
BM_vert_kill(pbvh->header.bm, v_del);
}
@@ -1441,14 +1439,14 @@ static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
{
const float min_len_squared = pbvh->bm_min_edge_len * pbvh->bm_min_edge_len;
bool any_collapsed = false;
/* deleted verts point to vertices they were merged into, or NULL when removed. */
/* deleted verts point to vertices they were merged into, or nullptr when removed. */
GHash *deleted_verts = BLI_ghash_ptr_new("deleted_verts");
while (!BLI_heapsimple_is_empty(eq_ctx->q->heap)) {
BMVert **pair = BLI_heapsimple_pop_min(eq_ctx->q->heap);
BMVert **pair = static_cast<BMVert **>(BLI_heapsimple_pop_min(eq_ctx->q->heap));
BMVert *v1 = pair[0], *v2 = pair[1];
BLI_mempool_free(eq_ctx->pool, pair);
pair = NULL;
pair = nullptr;
/* Check the verts still exist */
if (!(v1 = bm_vert_hash_lookup_chain(deleted_verts, v1)) ||
@@ -1483,17 +1481,17 @@ static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
pbvh_bmesh_collapse_edge(pbvh, e, v1, v2, deleted_verts, deleted_faces, eq_ctx);
}
BLI_ghash_free(deleted_verts, NULL, NULL);
BLI_ghash_free(deleted_verts, nullptr, nullptr);
return any_collapsed;
}
/************************* Called from pbvh.c *************************/
/************************* Called from pbvh.cc *************************/
bool pbvh_bmesh_node_raycast(PBVHNode *node,
const float ray_start[3],
const float ray_normal[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
float *depth,
bool use_original,
PBVHVertRef *r_active_vertex,
@@ -1539,7 +1537,7 @@ bool pbvh_bmesh_node_raycast(PBVHNode *node,
}
else {
GSET_ITER (gs_iter, node->bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
BLI_assert(f->len == 3);
@@ -1576,7 +1574,7 @@ bool pbvh_bmesh_node_raycast(PBVHNode *node,
bool BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node,
const float ray_start[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
float *depth,
float *r_edge_length)
{
@@ -1586,10 +1584,10 @@ bool BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node,
GSetIterator gs_iter;
bool hit = false;
BMFace *f_hit = NULL;
BMFace *f_hit = nullptr;
GSET_ITER (gs_iter, node->bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
BLI_assert(f->len == 3);
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
@@ -1645,7 +1643,7 @@ bool pbvh_bmesh_node_nearest_to_ray(PBVHNode *node,
GSetIterator gs_iter;
GSET_ITER (gs_iter, node->bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
BLI_assert(f->len == 3);
if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
@@ -1670,14 +1668,14 @@ void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode)
GSetIterator gs_iter;
GSET_ITER (gs_iter, node->bm_faces) {
BM_face_normal_update(BLI_gsetIterator_getKey(&gs_iter));
BM_face_normal_update(static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter)));
}
GSET_ITER (gs_iter, node->bm_unique_verts) {
BM_vert_normal_update(BLI_gsetIterator_getKey(&gs_iter));
BM_vert_normal_update(static_cast<BMVert *>(BLI_gsetIterator_getKey(&gs_iter)));
}
/* This should be unneeded normally */
GSET_ITER (gs_iter, node->bm_other_verts) {
BM_vert_normal_update(BLI_gsetIterator_getKey(&gs_iter));
BM_vert_normal_update(static_cast<BMVert *>(BLI_gsetIterator_getKey(&gs_iter)));
}
node->flag &= ~PBVH_UpdateNormals;
}
@@ -1687,8 +1685,8 @@ void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode)
struct FastNodeBuildInfo {
int totface; /* number of faces */
int start; /* start of faces in array */
struct FastNodeBuildInfo *child1;
struct FastNodeBuildInfo *child2;
FastNodeBuildInfo *child1;
FastNodeBuildInfo *child2;
};
/**
@@ -1697,9 +1695,9 @@ struct FastNodeBuildInfo {
* to a sub part of the arrays.
*/
static void pbvh_bmesh_node_limit_ensure_fast(
PBVH *pbvh, BMFace **nodeinfo, BBC *bbc_array, struct FastNodeBuildInfo *node, MemArena *arena)
PBVH *pbvh, BMFace **nodeinfo, BBC *bbc_array, FastNodeBuildInfo *node, MemArena *arena)
{
struct FastNodeBuildInfo *child1, *child2;
FastNodeBuildInfo *child1, *child2;
if (node->totface <= pbvh->leaf_limit) {
return;
@@ -1778,21 +1776,23 @@ static void pbvh_bmesh_node_limit_ensure_fast(
* each sequential part belonging to one node only */
BLI_assert((num_child1 + num_child2) == node->totface);
node->child1 = child1 = BLI_memarena_alloc(arena, sizeof(struct FastNodeBuildInfo));
node->child2 = child2 = BLI_memarena_alloc(arena, sizeof(struct FastNodeBuildInfo));
node->child1 = child1 = static_cast<FastNodeBuildInfo *>(
BLI_memarena_alloc(arena, sizeof(FastNodeBuildInfo)));
node->child2 = child2 = static_cast<FastNodeBuildInfo *>(
BLI_memarena_alloc(arena, sizeof(FastNodeBuildInfo)));
child1->totface = num_child1;
child1->start = node->start;
child2->totface = num_child2;
child2->start = node->start + num_child1;
child1->child1 = child1->child2 = child2->child1 = child2->child2 = NULL;
child1->child1 = child1->child2 = child2->child1 = child2->child2 = nullptr;
pbvh_bmesh_node_limit_ensure_fast(pbvh, nodeinfo, bbc_array, child1, arena);
pbvh_bmesh_node_limit_ensure_fast(pbvh, nodeinfo, bbc_array, child2, arena);
}
static void pbvh_bmesh_create_nodes_fast_recursive(
PBVH *pbvh, BMFace **nodeinfo, BBC *bbc_array, struct FastNodeBuildInfo *node, int node_index)
PBVH *pbvh, BMFace **nodeinfo, BBC *bbc_array, FastNodeBuildInfo *node, int node_index)
{
PBVHNode *n = pbvh->nodes + node_index;
/* two cases, node does not have children or does have children */
@@ -1910,8 +1910,9 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
}
/* bounding box array of all faces, no need to recalculate every time */
BBC *bbc_array = MEM_mallocN(sizeof(BBC) * bm->totface, "BBC");
BMFace **nodeinfo = MEM_mallocN(sizeof(*nodeinfo) * bm->totface, "nodeinfo");
BBC *bbc_array = static_cast<BBC *>(MEM_mallocN(sizeof(BBC) * bm->totface, "BBC"));
BMFace **nodeinfo = static_cast<BMFace **>(
MEM_mallocN(sizeof(*nodeinfo) * bm->totface, "nodeinfo"));
MemArena *arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "fast PBVH node storage");
BMIter iter;
@@ -1942,7 +1943,7 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
}
/* setup root node */
struct FastNodeBuildInfo rootnode = {0};
FastNodeBuildInfo rootnode = {0};
rootnode.totface = bm->totface;
/* start recursion, assign faces to nodes accordingly */
@@ -1952,7 +1953,7 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
* next we need to assign those to the gsets of the nodes. */
/* Start with all faces in the root node */
pbvh->nodes = MEM_callocN(sizeof(PBVHNode), "PBVHNode");
pbvh->nodes = MEM_cnew<PBVHNode>(__func__);
pbvh->totnode = 1;
/* take root node and visit and populate children recursively */
@@ -1999,7 +2000,7 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
short_edge_queue_create(
&eq_ctx, pbvh, center, view_normal, radius, use_frontface, use_projected);
modified |= pbvh_bmesh_collapse_short_edges(&eq_ctx, pbvh, &deleted_faces);
BLI_heapsimple_free(q.heap, NULL);
BLI_heapsimple_free(q.heap, nullptr);
BLI_mempool_destroy(queue_pool);
}
@@ -2018,7 +2019,7 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
long_edge_queue_create(
&eq_ctx, pbvh, center, view_normal, radius, use_frontface, use_projected);
modified |= pbvh_bmesh_subdivide_long_edges(&eq_ctx, pbvh, &edge_loops);
BLI_heapsimple_free(q.heap, NULL);
BLI_heapsimple_free(q.heap, nullptr);
BLI_mempool_destroy(queue_pool);
}
@@ -2066,15 +2067,17 @@ void BKE_pbvh_bmesh_node_save_orig(BMesh *bm, BMLog *log, PBVHNode *node, bool u
const int tottri = BLI_gset_len(node->bm_faces);
node->bm_orco = MEM_mallocN(sizeof(*node->bm_orco) * totvert, __func__);
node->bm_ortri = MEM_mallocN(sizeof(*node->bm_ortri) * tottri, __func__);
node->bm_orvert = MEM_mallocN(sizeof(*node->bm_orvert) * totvert, __func__);
node->bm_orco = static_cast<float(*)[3]>(
MEM_mallocN(sizeof(*node->bm_orco) * totvert, __func__));
node->bm_ortri = static_cast<int(*)[3]>(MEM_mallocN(sizeof(*node->bm_ortri) * tottri, __func__));
node->bm_orvert = static_cast<BMVert **>(
MEM_mallocN(sizeof(*node->bm_orvert) * totvert, __func__));
/* Copy out the vertices and assign a temporary index */
int i = 0;
GSetIterator gs_iter;
GSET_ITER (gs_iter, node->bm_unique_verts) {
BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
BMVert *v = static_cast<BMVert *>(BLI_gsetIterator_getKey(&gs_iter));
const float *origco = BM_log_original_vert_co(log, v);
if (use_original && origco) {
@@ -2089,7 +2092,7 @@ void BKE_pbvh_bmesh_node_save_orig(BMesh *bm, BMLog *log, PBVHNode *node, bool u
i++;
}
GSET_ITER (gs_iter, node->bm_other_verts) {
BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
BMVert *v = static_cast<BMVert *>(BLI_gsetIterator_getKey(&gs_iter));
const float *origco = BM_log_original_vert_co(log, v);
if (use_original && origco) {
@@ -2109,7 +2112,7 @@ void BKE_pbvh_bmesh_node_save_orig(BMesh *bm, BMLog *log, PBVHNode *node, bool u
/* Copy the triangles */
i = 0;
GSET_ITER (gs_iter, node->bm_faces) {
BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
BMFace *f = static_cast<BMFace *>(BLI_gsetIterator_getKey(&gs_iter));
if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
continue;
@@ -2167,7 +2170,7 @@ GSet *BKE_pbvh_bmesh_node_other_verts(PBVHNode *node)
return node->bm_other_verts;
}
struct GSet *BKE_pbvh_bmesh_node_faces(PBVHNode *node)
GSet *BKE_pbvh_bmesh_node_faces(PBVHNode *node)
{
return node->bm_faces;
}
@@ -2318,14 +2321,14 @@ static void pbvh_bmesh_verify(PBVH *pbvh)
* adjacent faces */
bool found = false;
BMIter bm_iter;
BMFace *f = NULL;
BMFace *f = nullptr;
BM_ITER_ELEM (f, &bm_iter, v, BM_FACES_OF_VERT) {
if (pbvh_bmesh_node_lookup(pbvh, f) == n) {
found = true;
break;
}
}
BLI_assert(found || f == NULL);
BLI_assert(found || f == nullptr);
# if 1
/* total freak stuff, check if node exists somewhere else */
@@ -2347,7 +2350,7 @@ static void pbvh_bmesh_verify(PBVH *pbvh)
bool has_unique = false;
for (int i = 0; i < pbvh->totnode; i++) {
PBVHNode *n = &pbvh->nodes[i];
if ((n->bm_unique_verts != NULL) && BLI_gset_haskey(n->bm_unique_verts, vi)) {
if ((n->bm_unique_verts != nullptr) && BLI_gset_haskey(n->bm_unique_verts, vi)) {
has_unique = true;
}
}
@@ -2389,8 +2392,8 @@ static void pbvh_bmesh_verify(PBVH *pbvh)
}
}
BLI_gset_free(faces_all, NULL);
BLI_gset_free(verts_all, NULL);
BLI_gset_free(faces_all, nullptr);
BLI_gset_free(verts_all, nullptr);
}
#endif

View File

@@ -33,7 +33,7 @@
#include "atomic_ops.h"
#include "pbvh_intern.h"
#include "pbvh_intern.hh"
#include <climits>

View File

@@ -2,37 +2,31 @@
#pragma once
struct PBVHGPUFormat;
/** \file
* \ingroup bke
*/
#ifdef __cplusplus
extern "C" {
#endif
struct PBVHGPUFormat;
struct MLoop;
struct MLoopTri;
struct MPoly;
struct MeshElemMap;
/* Axis-aligned bounding box */
typedef struct {
struct BB {
float bmin[3], bmax[3];
} BB;
};
/* Axis-aligned bounding box with centroid */
typedef struct {
struct BBC {
float bmin[3], bmax[3], bcentroid[3];
} BBC;
struct MeshElemMap;
};
/* NOTE: this structure is getting large, might want to split it into
* union'd structs */
struct PBVHNode {
/* Opaque handle for drawing code */
struct PBVHBatches *draw_batches;
PBVHBatches *draw_batches;
/* Voxel bounds */
BB vb;
@@ -95,7 +89,7 @@ struct PBVHNode {
/* Indicates whether this node is a leaf or not; also used for
* marking various updates that need to be applied. */
PBVHNodeFlags flag : 32;
PBVHNodeFlags flag;
/* Used for ray-casting: how close the bounding-box is to the ray point. */
float tmin;
@@ -132,12 +126,15 @@ struct PBVHNode {
int debug_draw_gen;
};
typedef enum { PBVH_DYNTOPO_SMOOTH_SHADING = 1 } PBVHFlags;
enum PBVHFlags {
PBVH_DYNTOPO_SMOOTH_SHADING = 1,
};
ENUM_OPERATORS(PBVHFlags, PBVH_DYNTOPO_SMOOTH_SHADING);
typedef struct PBVHBMeshLog PBVHBMeshLog;
struct PBVH {
struct PBVHPublic header;
PBVHPublic header;
PBVHFlags flags;
PBVHNode *nodes;
@@ -154,18 +151,18 @@ struct PBVH {
int depth_limit;
/* Mesh data */
struct Mesh *mesh;
Mesh *mesh;
/* NOTE: Normals are not `const` because they can be updated for drawing by sculpt code. */
float (*vert_normals)[3];
bool *hide_vert;
float (*vert_positions)[3];
const struct MPoly *mpoly;
const MPoly *mpoly;
bool *hide_poly;
/** Material indices. Only valid for polygon meshes. */
const int *material_indices;
const struct MLoop *mloop;
const struct MLoopTri *looptri;
const MLoop *mloop;
const MLoopTri *looptri;
CustomData *vdata;
CustomData *ldata;
CustomData *pdata;
@@ -203,10 +200,10 @@ struct PBVH {
float planes[6][4];
int num_planes;
struct BMLog *bm_log;
struct SubdivCCG *subdiv_ccg;
BMLog *bm_log;
SubdivCCG *subdiv_ccg;
const struct MeshElemMap *pmap;
const MeshElemMap *pmap;
CustomDataLayer *color_layer;
eAttrDomain color_domain;
@@ -216,12 +213,12 @@ struct PBVH {
/* Used by DynTopo to invalidate the draw cache. */
bool draw_cache_invalid;
struct PBVHGPUFormat *vbo_id;
PBVHGPUFormat *vbo_id;
PBVHPixels pixels;
};
/* pbvh.c */
/* pbvh.cc */
void BB_reset(BB *bb);
/**
@@ -239,14 +236,14 @@ void BBC_update_centroid(BBC *bbc);
int BB_widest_axis(const BB *bb);
void pbvh_grow_nodes(PBVH *bvh, int totnode);
bool ray_face_intersection_quad(const float ray_start[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
const float t0[3],
const float t1[3],
const float t2[3],
const float t3[3],
float *depth);
bool ray_face_intersection_tri(const float ray_start[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
const float t0[3],
const float t1[3],
const float t2[3],
@@ -270,12 +267,12 @@ bool ray_face_nearest_tri(const float ray_start[3],
void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag);
/* pbvh_bmesh.c */
/* pbvh_bmesh.cc */
bool pbvh_bmesh_node_raycast(PBVHNode *node,
const float ray_start[3],
const float ray_normal[3],
struct IsectRayPrecalc *isect_precalc,
IsectRayPrecalc *isect_precalc,
float *dist,
bool use_original,
PBVHVertRef *r_active_vertex,
@@ -295,7 +292,3 @@ void pbvh_node_pixels_free(PBVHNode *node);
void pbvh_pixels_free(PBVH *pbvh);
void pbvh_pixels_free_brush_test(PBVHNode *node);
void pbvh_free_draw_buffers(PBVH *pbvh, PBVHNode *node);
#ifdef __cplusplus
}
#endif

View File

@@ -22,7 +22,7 @@
#include "bmesh.h"
#include "pbvh_intern.h"
#include "pbvh_intern.hh"
#include "pbvh_uv_islands.hh"
namespace blender::bke::pbvh::pixels {
@@ -800,7 +800,6 @@ void BKE_pbvh_pixels_mark_image_dirty(PBVHNode &node, Image &image, ImageUser &i
}
} // namespace blender::bke::pbvh::pixels
extern "C" {
using namespace blender::bke::pbvh::pixels;
void BKE_pbvh_build_pixels(PBVH *pbvh, Mesh *mesh, Image *image, ImageUser *image_user)
@@ -828,4 +827,3 @@ void pbvh_pixels_free(PBVH *pbvh)
MEM_delete(pbvh_data);
pbvh->pixels.data = nullptr;
}
}