27#define COST_INIT_MAX FLT_MAX
39 const float v1[2],
const float v2[2],
const float v3[2],
bool skip_12,
bool skip_23)
48 const float cost = ((skip_12 ? 0.0f : cost_12) + (skip_23 ? 0.0f : cost_23));
76 const float uv_a[2] = {luv_a[0], luv_a[1] / params->
aspect_y};
91 const float uv_b[2] = {luv_b[0], luv_b[1] / params->
aspect_y};
95 const float cost_new = cost[l_a_index] + cost_cut;
97 if (cost[l_b_index] > cost_new) {
98 cost[l_b_index] = cost_new;
99 loops_prev[l_b_index] = l_a;
119 bool (*filter_fn)(
BMLoop *,
void *),
141 }
while ((l_iter = l_iter->
next) != l_first);
178 MEM_delete(loops_prev);
192 BMLoop *l_e_a,
BMLoop *l_e_b,
BMLoop *l_v,
const float aspect_y,
const int cd_loop_uv_offset)
194 BMLoop *l_v1 = (l_v->
v == l_e_a->
v) ? l_e_a->
next : l_e_a;
195 BMLoop *l_v2 = (l_v->
v == l_e_b->
v) ? l_e_b->
next : l_e_b;
201 float uv_v1[2] = {luv_v1[0], luv_v1[1] / aspect_y};
202 float uv_v2[2] = {luv_v2[0], luv_v2[1] / aspect_y};
203 float uv_v[2] = {luv_v[0], luv_v[1] / aspect_y};
209 BMLoop *l_e_a,
BMLoop *l_e_b,
BMFace *f,
const float aspect_v2[2],
const int cd_loop_uv_offset)
211 float l_e_a_cent[2], l_e_b_cent[2], f_cent[2];
238 for (
int i = 0; i <
ARRAY_SIZE(l_a_verts); i++) {
241 if (loops_prev[l_a_index]) {
242 BMLoop *l_prev = loops_prev[l_a_index];
243 if (l_a_verts[i]->
v != l_prev->
v) {
244 l_prev = (l_a_verts[i]->
v == l_prev->
next->
v) ? l_prev->
next :
nullptr;
254 if (e_b->
l ==
nullptr) {
258 l_first =
l_b = e_b->
l;
272 const float cost_new = cost[l_a_index] + cost_cut;
274 if (cost[l_b_index] > cost_new) {
275 cost[l_b_index] = cost_new;
276 loops_prev[l_b_index] = l_a;
286 const float aspect_v2[2] = {1.0f, 1.0f / params->
aspect_y};
288 l_iter = l_first = l_a;
295 BMLoop *l_cycle_iter, *l_cycle_end;
296 l_cycle_iter = l_iter->
next;
297 l_cycle_end = l_iter;
310 const float cost_new = cost[l_a_index] + cost_cut;
312 if (cost[l_b_index] > cost_new) {
313 cost[l_b_index] = cost_new;
314 loops_prev[l_b_index] = l_a;
318 }
while ((l_cycle_iter = l_cycle_iter->
next) != l_cycle_end);
319 }
while ((l_iter = l_iter->
radial_next) != l_first);
327 bool (*filter_fn)(
BMLoop *,
void *),
346 }
while ((l_iter = l_iter->
next) != l_first);
381 MEM_delete(loops_prev);
397 const void *
const f_endpoints[2],
398 const float aspect_v2[2],
399 const int cd_loop_uv_offset)
422 else if (factor > 1.0f) {
437 f_a_cent, e_cent, f_b_cent, (f_a == f_endpoints[0]), (f_b == f_endpoints[1]));
443 const void *
const f_endpoints[2],
444 const float aspect_v2[2],
445 const int cd_loop_uv_offset)
461 f_a_cent, v_cent, f_b_cent, (f_a == f_endpoints[0]), (f_b == f_endpoints[1]));
468 const void *
const f_endpoints[2],
469 const float aspect_v2[2],
492 const float cost_cut =
496 f_a, f_b, l_iter, f_endpoints, aspect_v2, cd_loop_uv_offset);
497 const float cost_new = cost[f_a_index] + cost_cut;
499 if (cost[f_b_index] > cost_new) {
500 cost[f_b_index] = cost_new;
501 faces_prev[f_b_index] = f_a;
506 }
while ((l_iter = l_iter->
radial_next) != l_first);
525 const float cost_cut =
529 f_a, f_b, l_a, f_endpoints, aspect_v2, cd_loop_uv_offset);
530 const float cost_new = cost[f_a_index] + cost_cut;
532 if (cost[f_b_index] > cost_new) {
533 cost[f_b_index] = cost_new;
534 faces_prev[f_b_index] = f_a;
549 bool (*filter_fn)(
BMFace *,
void *),
552 const float aspect_v2[2] = {1.0f, 1.0f / params->
aspect_y};
562 const void *
const f_endpoints[2] = {f_src, f_dst};
610 MEM_delete(faces_prev);
A min-heap / priority queue ADT.
Read Blender memory allocation and freeing.
#define BM_FACE_FIRST_LOOP(p)
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_elem_index_get(ele)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_index_set(ele, index)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
bool BM_loop_share_edge_check(BMLoop *l_a, BMLoop *l_b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void facetag_add_adjacent_uv(HeapSimple *heap, BMFace *f_a, BMFace **faces_prev, float *cost, const void *const f_endpoints[2], const float aspect_v2[2], const BMCalcPathUVParams *params)
static float facetag_cut_cost_edge_uv(BMFace *f_a, BMFace *f_b, BMLoop *l_edge, const void *const f_endpoints[2], const float aspect_v2[2], const int cd_loop_uv_offset)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
ATTR_WARN_UNUSED_RESULT const BMLoop * l
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float normalize_v2(float n[2])
ATTR_WARN_UNUSED_RESULT const BMVert * v
static float step_cost_3_v2_ex(const float v1[2], const float v2[2], const float v3[2], bool skip_12, bool skip_23)
bool BM_loop_uv_share_vert_check(const BMLoop *l_a, const BMLoop *l_b, const int cd_loop_uv_offset)
MINLINE void mul_v2_v2(float r[2], const float a[2])
void void BLI_linklist_prepend(LinkNode **listp, void *ptr) ATTR_NONNULL(1)
void * BLI_heapsimple_pop_min(HeapSimple *heap) ATTR_NONNULL(1)
static float step_cost_3_v2(const float v1[2], const float v2[2], const float v3[2])
float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2])
ATTR_WARN_UNUSED_RESULT const BMLoop * l_b
static float facetag_cut_cost_vert_uv(BMFace *f_a, BMFace *f_b, BMLoop *l_vert, const void *const f_endpoints[2], const float aspect_v2[2], const int cd_loop_uv_offset)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static void edgetag_add_adjacent_uv(HeapSimple *heap, BMLoop *l_a, BMLoop **loops_prev, float *cost, const BMCalcPathUVParams *params)
static void verttag_add_adjacent_uv(HeapSimple *heap, BMLoop *l_a, BMLoop **loops_prev, float *cost, const BMCalcPathUVParams *params)
void BLI_heapsimple_free(HeapSimple *heap, HeapSimpleFreeFP ptrfreefp) ATTR_NONNULL(1)
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
HeapSimple * BLI_heapsimple_new() ATTR_WARN_UNUSED_RESULT
LinkNode * BM_mesh_calc_path_uv_face(BMesh *bm, BMFace *f_src, BMFace *f_dst, const BMCalcPathUVParams *params, bool(*filter_fn)(BMFace *, void *), void *user_data)
void BLI_heapsimple_insert(HeapSimple *heap, float value, void *ptr) ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
LinkNode * BM_mesh_calc_path_uv_vert(BMesh *bm, BMLoop *l_src, BMLoop *l_dst, const BMCalcPathUVParams *params, bool(*filter_fn)(BMLoop *, void *), void *user_data)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
bool BLI_heapsimple_is_empty(const HeapSimple *heap) ATTR_NONNULL(1)
void mid_v2_v2v2(float r[2], const float a[2], const float b[2])
void BM_face_uv_calc_center_median_weighted(const BMFace *f, const float aspect[2], const int cd_loop_uv_offset, float r_cent[2])
bool BM_loop_uv_share_edge_check(const BMLoop *l_a, const BMLoop *l_b, const int cd_loop_uv_offset)
static float edgetag_cut_cost_vert_uv(BMLoop *l_e_a, BMLoop *l_e_b, BMLoop *l_v, const float aspect_y, const int cd_loop_uv_offset)
int isect_line_line_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2])
static float edgetag_cut_cost_face_uv(BMLoop *l_e_a, BMLoop *l_e_b, BMFace *f, const float aspect_v2[2], const int cd_loop_uv_offset)
LinkNode * BM_mesh_calc_path_uv_edge(BMesh *bm, BMLoop *l_src, BMLoop *l_dst, const BMCalcPathUVParams *params, bool(*filter_fn)(BMLoop *, void *), void *user_data)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
uint use_topology_distance
struct BMLoop * radial_next
struct BMLoop * radial_next