Changeset View
Changeset View
Standalone View
Standalone View
source/blender/bmesh/tools/bmesh_beautify.c
| Show All 26 Lines | |||||
| * | * | ||||
| * TODO | * TODO | ||||
| * - Take face normals into account. | * - Take face normals into account. | ||||
| */ | */ | ||||
| #include "BLI_heap.h" | #include "BLI_heap.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_polyfill_2d_beautify.h" | #include "BLI_polyfill_2d_beautify.h" | ||||
| #include <CLG_log.h> | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "bmesh.h" | #include "bmesh.h" | ||||
| #include "bmesh_beautify.h" /* own include */ | #include "bmesh_beautify.h" /* own include */ | ||||
| // #define DEBUG_TIME | // #define DEBUG_TIME | ||||
| #ifdef DEBUG_TIME | #ifdef DEBUG_TIME | ||||
| # include "PIL_time.h" | # include "PIL_time.h" | ||||
| # include "PIL_time_utildefines.h" | # include "PIL_time_utildefines.h" | ||||
| #endif | #endif | ||||
| static CLG_LogRef LOG = {"bmesh.bmesh_beautify"}; | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* GSet for edge rotation */ | /* GSet for edge rotation */ | ||||
| typedef struct EdRotState { | typedef struct EdRotState { | ||||
| int v1, v2; /* edge vert, small -> large */ | int v1, v2; /* edge vert, small -> large */ | ||||
| int f1, f2; /* face vert, small -> large */ | int f1, f2; /* face vert, small -> large */ | ||||
| } EdRotState; | } EdRotState; | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | /* first get the 2d values */ | ||||
| const float eps = 1e-5; | const float eps = 1e-5; | ||||
| float no_a[3], no_b[3]; | float no_a[3], no_b[3]; | ||||
| float no[3]; | float no[3]; | ||||
| float axis_mat[3][3]; | float axis_mat[3][3]; | ||||
| float no_scale; | float no_scale; | ||||
| cross_tri_v3(no_a, v2, v3, v4); | cross_tri_v3(no_a, v2, v3, v4); | ||||
| cross_tri_v3(no_b, v2, v4, v1); | cross_tri_v3(no_b, v2, v4, v1); | ||||
| // printf("%p %p %p %p - %p %p\n", v1, v2, v3, v4, e->l->f, e->l->radial_next->f); | CLOG_DEBUG(&LOG, 20, "%p %p %p %p", v1, v2, v3, v4); | ||||
| BLI_assert((ELEM(v1, v2, v3, v4) == false) && (ELEM(v2, v1, v3, v4) == false) && | BLI_assert((ELEM(v1, v2, v3, v4) == false) && (ELEM(v2, v1, v3, v4) == false) && | ||||
| (ELEM(v3, v1, v2, v4) == false) && (ELEM(v4, v1, v2, v3) == false)); | (ELEM(v3, v1, v2, v4) == false) && (ELEM(v4, v1, v2, v3) == false)); | ||||
| add_v3_v3v3(no, no_a, no_b); | add_v3_v3v3(no, no_a, no_b); | ||||
| if (UNLIKELY((no_scale = normalize_v3(no)) == 0.0f)) { | if (UNLIKELY((no_scale = normalize_v3(no)) == 0.0f)) { | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | do { | ||||
| if (flag & VERT_RESTRICT_TAG) { | if (flag & VERT_RESTRICT_TAG) { | ||||
| const BMVert *v_a = v1, *v_b = v3; | const BMVert *v_a = v1, *v_b = v3; | ||||
| if (BM_elem_flag_test(v_a, BM_ELEM_TAG) == BM_elem_flag_test(v_b, BM_ELEM_TAG)) { | if (BM_elem_flag_test(v_a, BM_ELEM_TAG) == BM_elem_flag_test(v_b, BM_ELEM_TAG)) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (UNLIKELY(v1 == v3)) { | if (UNLIKELY(v1 == v3)) { | ||||
| // printf("This should never happen, but does sometimes!\n"); | CLOG_ERROR(&LOG, "This should never happen, but does sometimes!"); | ||||
| break; | break; | ||||
| } | } | ||||
| switch (method) { | switch (method) { | ||||
| case 0: | case 0: | ||||
| return bm_edge_calc_rotate_beauty__area( | return bm_edge_calc_rotate_beauty__area( | ||||
| v1->co, v2->co, v3->co, v4->co, flag & EDGE_RESTRICT_DEGENERATE); | v1->co, v2->co, v3->co, v4->co, flag & EDGE_RESTRICT_DEGENERATE); | ||||
| default: | default: | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | if (edge_in_array(e, edge_array, edge_array_len)) { | ||||
| /* check if we can add it back */ | /* check if we can add it back */ | ||||
| BLI_assert(BM_edge_is_manifold(e) == true); | BLI_assert(BM_edge_is_manifold(e) == true); | ||||
| /* check we're not moving back into a state we have been in before */ | /* check we're not moving back into a state we have been in before */ | ||||
| if (e_state_set != NULL) { | if (e_state_set != NULL) { | ||||
| EdRotState e_state_alt; | EdRotState e_state_alt; | ||||
| erot_state_alternate(e, &e_state_alt); | erot_state_alternate(e, &e_state_alt); | ||||
| if (BLI_gset_haskey(e_state_set, (void *)&e_state_alt)) { | if (BLI_gset_haskey(e_state_set, (void *)&e_state_alt)) { | ||||
| // printf(" skipping, we already have this state\n"); | CLOG_VERBOSE(&LOG, 0, " skipping, we already have this state"); | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| { | { | ||||
| /* recalculate edge */ | /* recalculate edge */ | ||||
| const float cost = bm_edge_calc_rotate_beauty(e, flag, method); | const float cost = bm_edge_calc_rotate_beauty(e, flag, method); | ||||
| if (cost < 0.0f) { | if (cost < 0.0f) { | ||||
| ▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | if (LIKELY(e)) { | ||||
| EdRotState *e_state = BLI_mempool_alloc(edge_state_pool); | EdRotState *e_state = BLI_mempool_alloc(edge_state_pool); | ||||
| erot_state_current(e, e_state); | erot_state_current(e, e_state); | ||||
| if (UNLIKELY(e_state_set == NULL)) { | if (UNLIKELY(e_state_set == NULL)) { | ||||
| edge_state_arr[i] = e_state_set = erot_gset_new(); /* store previous state */ | edge_state_arr[i] = e_state_set = erot_gset_new(); /* store previous state */ | ||||
| } | } | ||||
| BLI_assert(BLI_gset_haskey(e_state_set, (void *)e_state) == false); | BLI_assert(BLI_gset_haskey(e_state_set, (void *)e_state) == false); | ||||
| BLI_gset_insert(e_state_set, e_state); | BLI_gset_insert(e_state_set, e_state); | ||||
| // printf(" %d -> %d, %d\n", i, BM_elem_index_get(e->v1), BM_elem_index_get(e->v2)); | CLOG_DEBUG(&LOG, 0, " %d -> %d, %d", i, BM_elem_index_get(e->v1), BM_elem_index_get(e->v2)); | ||||
| /* maintain the index array */ | /* maintain the index array */ | ||||
| edge_array[i] = e; | edge_array[i] = e; | ||||
| BM_elem_index_set(e, i); | BM_elem_index_set(e, i); | ||||
| /* recalculate faces connected on the heap */ | /* recalculate faces connected on the heap */ | ||||
| bm_edge_update_beauty_cost(e, | bm_edge_update_beauty_cost(e, | ||||
| eheap, | eheap, | ||||
| Show All 35 Lines | |||||