Cleanup: Remove #ifdef blocks for Dyntopo edge code

At this point, it is unlikely that we will revert the changes made over
a decade ago to the Dyntopo edge splitting code. The old code will still
exist in the git history, but to improve readability, this commit
flattens out the blocks and removes the `#define` statements.

Pull Request: https://projects.blender.org/blender/blender/pulls/135410
This commit is contained in:
Sean Kim
2025-03-04 17:30:16 +01:00
committed by Sean Kim
parent 5a29367325
commit d6f885c408

View File

@@ -17,6 +17,7 @@
#include "BLI_time.h"
#include "BLI_utildefines.h"
#include "BKE_global.hh"
#include "BKE_paint_bvh.hh"
#include "bmesh.hh"
@@ -26,24 +27,13 @@
static CLG_LogRef LOG = {"pbvh.bmesh"};
/* Avoid skinny faces */
#define USE_EDGEQUEUE_EVEN_SUBDIV
#ifdef USE_EDGEQUEUE_EVEN_SUBDIV
# include "BKE_global.hh"
#endif
namespace blender::bke::pbvh {
/* Support for only operating on front-faces. */
#define USE_EDGEQUEUE_FRONTFACE
/* Don't add edges into the queue multiple times. */
#define USE_EDGEQUEUE_TAG
/**
* Ensure we don't have dirty tags for the edge queue, and that they are left cleared.
* (slow, even for debug mode, so leave disabled for now).
*/
#if defined(USE_EDGEQUEUE_TAG) && 0
#if 0
# if !defined(NDEBUG)
# define USE_EDGEQUEUE_TAG_VERIFY
# endif
@@ -679,16 +669,12 @@ struct EdgeQueue {
float center_proj[3]; /* For when we use projected coords. */
float radius_squared;
float limit_len_squared;
#ifdef USE_EDGEQUEUE_EVEN_SUBDIV
float limit_len;
#endif
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
};
struct EdgeQueueContext {
@@ -701,13 +687,10 @@ struct EdgeQueueContext {
};
/* Only tagged edges are in the queue. */
#ifdef USE_EDGEQUEUE_TAG
# define EDGE_QUEUE_TEST(e) BM_elem_flag_test((CHECK_TYPE_INLINE(e, BMEdge *), e), BM_ELEM_TAG)
# define EDGE_QUEUE_ENABLE(e) \
BM_elem_flag_enable((CHECK_TYPE_INLINE(e, BMEdge *), e), BM_ELEM_TAG)
# define EDGE_QUEUE_DISABLE(e) \
BM_elem_flag_disable((CHECK_TYPE_INLINE(e, BMEdge *), e), BM_ELEM_TAG)
#endif
#define EDGE_QUEUE_TEST(e) BM_elem_flag_test((CHECK_TYPE_INLINE(e, BMEdge *), e), BM_ELEM_TAG)
#define EDGE_QUEUE_ENABLE(e) BM_elem_flag_enable((CHECK_TYPE_INLINE(e, BMEdge *), e), BM_ELEM_TAG)
#define EDGE_QUEUE_DISABLE(e) \
BM_elem_flag_disable((CHECK_TYPE_INLINE(e, BMEdge *), e), BM_ELEM_TAG)
#ifdef USE_EDGEQUEUE_TAG_VERIFY
/* simply check no edges are tagged
@@ -795,10 +778,8 @@ static void edge_queue_insert(EdgeQueueContext *eq_ctx, BMEdge *e, float priorit
pair[0] = e->v1;
pair[1] = e->v2;
BLI_heapsimple_insert(eq_ctx->q->heap, priority, pair);
#ifdef USE_EDGEQUEUE_TAG
BLI_assert(EDGE_QUEUE_TEST(e) == false);
EDGE_QUEUE_ENABLE(e);
#endif
}
}
@@ -884,10 +865,7 @@ static float short_edge_queue_priority(const BMEdge &edge)
static void long_edge_queue_edge_add(EdgeQueueContext *eq_ctx, BMEdge *e)
{
#ifdef USE_EDGEQUEUE_TAG
if (EDGE_QUEUE_TEST(e) == false)
#endif
{
if (!EDGE_QUEUE_TEST(e)) {
const float len_sq = BM_edge_calc_length_squared(e);
if (len_sq > eq_ctx->q->limit_len_squared) {
edge_queue_insert(eq_ctx, e, long_edge_queue_priority(*e));
@@ -895,24 +873,18 @@ static void long_edge_queue_edge_add(EdgeQueueContext *eq_ctx, BMEdge *e)
}
}
#ifdef USE_EDGEQUEUE_EVEN_SUBDIV
static void long_edge_queue_edge_add_recursive(
EdgeQueueContext *eq_ctx, BMLoop *l_edge, BMLoop *l_end, const float len_sq, float limit_len)
{
BLI_assert(len_sq > square_f(limit_len));
# ifdef USE_EDGEQUEUE_FRONTFACE
if (eq_ctx->q->use_view_normal) {
if (dot_v3v3(l_edge->f->no, eq_ctx->q->view_normal) < 0.0f) {
return;
}
}
# endif
# ifdef USE_EDGEQUEUE_TAG
if (EDGE_QUEUE_TEST(l_edge->e) == false)
# endif
{
if (!EDGE_QUEUE_TEST(l_edge->e)) {
edge_queue_insert(eq_ctx, l_edge->e, long_edge_queue_priority(*l_edge->e));
}
@@ -924,14 +896,14 @@ static void long_edge_queue_edge_add_recursive(
if (l_edge->radial_next != l_edge) {
/* How much longer we need to be to consider for subdividing
* (avoids subdividing faces which are only *slightly* skinny). */
# define EVEN_EDGELEN_THRESHOLD 1.2f
static constexpr float even_edgelen_threshold = 1.2f;
/* How much the limit increases per recursion
* (avoids performing subdivisions too far away). */
# define EVEN_GENERATION_SCALE 1.6f
static constexpr float even_generation_scale = 1.6f;
const float len_sq_cmp = len_sq * EVEN_EDGELEN_THRESHOLD;
const float len_sq_cmp = len_sq * even_edgelen_threshold;
limit_len *= EVEN_GENERATION_SCALE;
limit_len *= even_generation_scale;
const float limit_len_sq = square_f(limit_len);
BMLoop *l_iter = l_edge;
@@ -946,19 +918,12 @@ static void long_edge_queue_edge_add_recursive(
}
}
} while ((l_iter = l_iter->radial_next) != l_end);
# undef EVEN_EDGELEN_THRESHOLD
# undef EVEN_GENERATION_SCALE
}
}
#endif /* USE_EDGEQUEUE_EVEN_SUBDIV */
static void short_edge_queue_edge_add(EdgeQueueContext *eq_ctx, BMEdge *e)
{
#ifdef USE_EDGEQUEUE_TAG
if (EDGE_QUEUE_TEST(e) == false)
#endif
{
if (!EDGE_QUEUE_TEST(e)) {
const float len_sq = BM_edge_calc_length_squared(e);
if (len_sq < eq_ctx->q->limit_len_squared) {
edge_queue_insert(eq_ctx, e, short_edge_queue_priority(*e));
@@ -968,41 +933,33 @@ static void short_edge_queue_edge_add(EdgeQueueContext *eq_ctx, BMEdge *e)
static void long_edge_queue_face_add(EdgeQueueContext *eq_ctx, BMFace *f)
{
#ifdef USE_EDGEQUEUE_FRONTFACE
if (eq_ctx->q->use_view_normal) {
if (dot_v3v3(f->no, eq_ctx->q->view_normal) < 0.0f) {
return;
}
}
#endif
if (eq_ctx->q->edge_queue_tri_in_range(eq_ctx->q, f)) {
/* Check each edge of the face. */
BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
BMLoop *l_iter = l_first;
do {
#ifdef USE_EDGEQUEUE_EVEN_SUBDIV
const float len_sq = BM_edge_calc_length_squared(l_iter->e);
if (len_sq > eq_ctx->q->limit_len_squared) {
long_edge_queue_edge_add_recursive(
eq_ctx, l_iter->radial_next, l_iter, len_sq, eq_ctx->q->limit_len);
}
#else
long_edge_queue_edge_add(eq_ctx, l_iter->e);
#endif
} while ((l_iter = l_iter->next) != l_first);
}
}
static void short_edge_queue_face_add(EdgeQueueContext *eq_ctx, BMFace *f)
{
#ifdef USE_EDGEQUEUE_FRONTFACE
if (eq_ctx->q->use_view_normal) {
if (dot_v3v3(f->no, eq_ctx->q->view_normal) < 0.0f) {
return;
}
}
#endif
if (eq_ctx->q->edge_queue_tri_in_range(eq_ctx->q, f)) {
BMLoop *l_iter;
@@ -1039,17 +996,11 @@ static void long_edge_queue_create(EdgeQueueContext *eq_ctx,
eq_ctx->q->center = center;
eq_ctx->q->radius_squared = radius * radius;
eq_ctx->q->limit_len_squared = max_edge_len * max_edge_len;
#ifdef USE_EDGEQUEUE_EVEN_SUBDIV
eq_ctx->q->limit_len = max_edge_len;
#endif
eq_ctx->q->view_normal = view_normal;
#ifdef USE_EDGEQUEUE_FRONTFACE
eq_ctx->q->use_view_normal = use_frontface;
#else
UNUSED_VARS(use_frontface);
#endif
if (use_projected) {
eq_ctx->q->edge_queue_tri_in_range = edge_queue_tri_in_circle;
@@ -1098,17 +1049,11 @@ static void short_edge_queue_create(EdgeQueueContext *eq_ctx,
eq_ctx->q->center = center;
eq_ctx->q->radius_squared = radius * radius;
eq_ctx->q->limit_len_squared = min_edge_len * min_edge_len;
#ifdef USE_EDGEQUEUE_EVEN_SUBDIV
eq_ctx->q->limit_len = min_edge_len;
#endif
eq_ctx->q->view_normal = view_normal;
#ifdef USE_EDGEQUEUE_FRONTFACE
eq_ctx->q->use_view_normal = use_frontface;
#else
UNUSED_VARS(use_frontface);
#endif
if (use_projected) {
eq_ctx->q->edge_queue_tri_in_range = edge_queue_tri_in_circle;
@@ -1303,9 +1248,7 @@ static bool pbvh_bmesh_subdivide_long_edges(EdgeQueueContext *eq_ctx,
if (!(e = BM_edge_exists(v1, v2))) {
continue;
}
#ifdef USE_EDGEQUEUE_TAG
EDGE_QUEUE_DISABLE(e);
#endif
BLI_assert(len_squared_v3v3(v1->co, v2->co) > eq_ctx->q->limit_len_squared);
@@ -1808,9 +1751,7 @@ static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
if (!(e = BM_edge_exists(v1, v2))) {
continue;
}
#ifdef USE_EDGEQUEUE_TAG
EDGE_QUEUE_DISABLE(e);
#endif
if (len_squared_v3v3(v1->co, v2->co) >= min_len_squared) {
continue;