28#define BARYCENTRIC_INTERP
30#ifdef BARYCENTRIC_INTERP
55 const float co_a_next[3],
56 const float co_b_next[3],
58 const float co_a_prev[3],
59 const float co_b_prev[3],
100 l_pair[1] =
e->l->next;
103 l_pair[0] =
e->l->next;
121 if (l_pair_a[0] && l_pair_b[0] ==
nullptr) {
122 l_pair_b[0] = l_pair_a[1];
123 l_pair_b[1] = l_pair_a[0];
125 else if (l_pair_b[0] && l_pair_a[0] ==
nullptr) {
126 l_pair_a[0] = l_pair_b[1];
127 l_pair_a[1] = l_pair_b[0];
141 const void *l_cdata[4] = {
154 const float w[2] = {1.0f - t, t};
166 float (*weight_table)[4])
168 float x_step = 1.0f /
float(xtot - 1);
169 float y_step = 1.0f /
float(ytot - 1);
174 for (y = 0; y < ytot; y++) {
175 xy_fl[1] = y_step *
float(y);
176 for (x = 0; x < xtot; x++) {
177 xy_fl[0] = x_step *
float(x);
179 const float cos[4][2] = {
180 {xy_fl[0], 0.0f}, {0.0f, xy_fl[1]}, {xy_fl[0], 1.0f}, {1.0f, xy_fl[1]}};
197 const bool use_smooth,
199 const bool use_interp_simple)
206 BMLoop *(*larr_x_a)[2], *(*larr_x_b)[2], *(*larr_y_a)[2], *(*larr_y_b)[2];
208 float(*weight_table)[4];
210#define XY(_x, _y) ((_x) + ((_y) * (xtot)))
212#ifdef BARYCENTRIC_INTERP
218 v_grid[
XY(0, 0)]->co,
219 v_grid[
XY(xtot - 1, 0)]->co,
220 v_grid[
XY(0, 1)]->co,
221 v_grid[
XY(xtot - 1, 1)]->co,
227 v_grid[
XY(0, (ytot - 1))]->co,
228 v_grid[
XY(xtot - 1, (ytot - 1))]->co,
229 v_grid[
XY(0, (ytot - 2))]->co,
230 v_grid[
XY(xtot - 1, (ytot - 2))]->co,
236 if (use_interp_simple || use_vert_interp || use_loop_interp) {
237 weight_table =
static_cast<float(*)[4]
>(
238 MEM_mallocN(
sizeof(*weight_table) *
size_t(xtot * ytot), __func__));
242 weight_table =
nullptr;
246 if (use_loop_interp) {
248 larr_x_a =
static_cast<BMLoop *(*)[2]
>(
MEM_mallocN(
sizeof(*larr_x_a) * (xtot - 1), __func__));
249 larr_x_b =
static_cast<BMLoop *(*)[2]
>(
MEM_mallocN(
sizeof(*larr_x_b) * (xtot - 1), __func__));
251 larr_y_a =
static_cast<BMLoop *(*)[2]
>(
MEM_mallocN(
sizeof(*larr_y_a) * (ytot - 1), __func__));
252 larr_y_b =
static_cast<BMLoop *(*)[2]
>(
MEM_mallocN(
sizeof(*larr_y_b) * (ytot - 1), __func__));
255 for (x = 0; x < xtot - 1; x++) {
261 for (y = 0; y < ytot - 1; y++) {
269 for (y = 1; y < ytot - 1; y++) {
270#ifdef BARYCENTRIC_INTERP
272 v_grid[
XY(0, y + 0)]->co,
273 v_grid[
XY(xtot - 1, y + 0)]->co,
274 v_grid[
XY(0, y + 1)]->co,
275 v_grid[
XY(xtot - 1, y + 1)]->co,
276 v_grid[
XY(0, y - 1)]->co,
277 v_grid[
XY(xtot - 1, y - 1)]->co,
280 for (x = 1; x < xtot - 1; x++) {
284 BLI_assert(v_grid[(y * xtot) + x] ==
nullptr);
287#ifdef BARYCENTRIC_INTERP
288 if (use_interp_simple ==
false) {
289 float co_a[3], co_b[3];
292 co_a, v_grid[x]->co, tri_t[0], tri_t[1], tri_t[2], tri_a[0], tri_a[1], tri_a[2]);
294 v_grid[(xtot * ytot) + (x - xtot)]->co,
307 const float *
w = weight_table[
XY(x, y)];
317 v_grid[(y * xtot) + x] =
v;
321 if (use_vert_interp) {
322 const float *
w = weight_table[
XY(x, y)];
324 const void *v_cdata[4] = {
337 for (x = 0; x < xtot - 1; x++) {
338 for (y = 0; y < ytot - 1; y++) {
343 v_grid[
XY(x, y + 0)],
344 v_grid[
XY(x, y + 1)],
345 v_grid[
XY(x + 1, y + 1)],
346 v_grid[
XY(x + 1, y + 0)],
352 v_grid[
XY(x + 1, y + 0)],
353 v_grid[
XY(x + 1, y + 1)],
354 v_grid[
XY(x, y + 1)],
355 v_grid[
XY(x, y + 0)],
360 if (use_loop_interp && (larr_x_a[x][0] || larr_y_a[y][0])) {
365 uint x_side, y_side, i;
368 if (larr_x_a[x][0] && larr_y_a[y][0]) {
370 l_tmp = larr_x_a[
x][0];
372 else if (larr_x_a[x][0]) {
374 l_tmp = larr_x_a[
x][0];
378 l_tmp = larr_y_a[
y][0];
408 for (x_side = 0; x_side < 2; x_side++) {
409 for (y_side = 0; y_side < 2; y_side++) {
410 if (interp_from ==
'B') {
411 const float *
w = weight_table[
XY(x + x_side, y + y_side)];
412 l_bound[0] = larr_x_a[
x][x_side];
413 l_bound[1] = larr_y_a[
y][y_side];
414 l_bound[2] = larr_x_b[
x][x_side];
415 l_bound[3] = larr_y_b[
y][y_side];
419 else if (interp_from ==
'X') {
420 const float t =
float(y + y_side) /
float(ytot - 1);
421 l_bound[0] = larr_x_a[
x][x_side];
422 l_bound[1] = larr_x_b[
x][x_side];
426 else if (interp_from ==
'Y') {
427 const float t =
float(x + x_side) /
float(xtot - 1);
428 l_bound[0] = larr_y_a[
y][y_side];
429 l_bound[1] = larr_y_b[
y][y_side];
449 if (use_loop_interp) {
469 const bool use_smooth,
470 const bool use_interp_simple)
472#define USE_FLIP_DETECT
482 bool use_flip =
false;
518 v_grid[(ytot * xtot) + (i - xtot)] =
static_cast<BMVert *
>(el->
data);
520 for (el =
static_cast<LinkData *
>(lb_rail_a->
first), i = 0; el; el = el->
next, i++) {
521 v_grid[xtot * i] =
static_cast<BMVert *
>(el->
data);
523 for (el =
static_cast<LinkData *
>(lb_rail_b->
first), i = 0; el; el = el->
next, i++) {
524 v_grid[(xtot * i) + (xtot - 1)] =
static_cast<BMVert *
>(el->
data);
527 for (x = 1; x < xtot - 1; x++) {
528 for (y = 1; y < ytot - 1; y++) {
529 BLI_assert(v_grid[(y * xtot) + x] ==
nullptr);
534#ifdef USE_FLIP_DETECT
536 ListBase *lb_iter[4] = {lb_a, lb_b, lb_rail_a, lb_rail_b};
537 const int lb_iter_dir[4] = {-1, 1, 1, -1};
538 int winding_votes = 0;
540 for (i = 0; i < 4; i++) {
542 for (el =
static_cast<LinkData *
>(lb_iter[i]->first); el && (el_next = el->
next);
548 winding_votes += (
e->l->v == el->data) ? lb_iter_dir[i] : -lb_iter_dir[i];
552 use_flip = (winding_votes < 0);
559#undef USE_FLIP_DETECT
594 ListBase eloops = {
nullptr,
nullptr};
595 ListBase eloops_rail = {
nullptr,
nullptr};
598 BMVert *v_a_first, *v_a_last;
599 BMVert *v_b_first, *v_b_last;
603 GSet *split_edges =
nullptr;
606 bool changed =
false;
618 "Select two edge loops "
619 "or a single closed edge loop from which two edge loops can be calculated");
686 {estore_a, estore_b},
687 {estore_rail_a, estore_rail_b},
691 for (i = 0; i < 2; i++) {
694 if (len_a != len_b) {
695 if (split_edges ==
nullptr) {
711 bm, estore_a, estore_b, estore_rail_a, estore_rail_b, mat_nr, use_smooth, use_interp_simple);
CustomData interface, see also DNA_customdata_types.h.
bool CustomData_has_interp(const CustomData *data)
void CustomData_bmesh_interp(CustomData *data, const void **src_blocks, const float *weights, const float *sub_weights, int count, void *dst_block)
GSet * BLI_gset_ptr_new(const char *info)
BLI_INLINE void * BLI_gsetIterator_getKey(GSetIterator *gsi)
#define GSET_ITER(gs_iter_, gset_)
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
void transform_point_by_tri_v3(float pt_tar[3], float const pt_src[3], const float tri_tar_p1[3], const float tri_tar_p2[3], const float tri_tar_p3[3], const float tri_src_p1[3], const float tri_src_p2[3], const float tri_src_p3[3])
void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const float v3[2], const float v4[2], const float co[2], float w[4])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void negate_v3(float r[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void zero_v3(float r[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3(float n[3])
Read Guarded memory(de)allocation.
#define BM_FACE_FIRST_LOOP(p)
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
BMFace * BM_face_create_quad_tri(BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4, const BMFace *f_example, const eBMCreateFlag create_flag)
Make Quad/Triangle.
BMVert * BM_vert_create(BMesh *bm, const float co[3], const BMVert *v_example, const eBMCreateFlag create_flag)
Main function for creating a new vertex.
void BM_edgeloop_expand(BMesh *bm, BMEdgeLoopStore *el_store, int el_store_len, bool split, GSet *split_edges)
void BM_mesh_edgeloops_free(ListBase *eloops)
bool BM_edgeloop_overlap_check(BMEdgeLoopStore *el_store_a, BMEdgeLoopStore *el_store_b)
void BM_edgeloop_flip(BMesh *, BMEdgeLoopStore *el_store)
int BM_mesh_edgeloops_find(BMesh *bm, ListBase *r_eloops, bool(*test_fn)(BMEdge *, void *user_data), void *user_data)
bool BM_mesh_edgeloops_find_path(BMesh *bm, ListBase *r_eloops, bool(*test_fn)(BMEdge *, void *user_data), void *user_data, BMVert *v_src, BMVert *v_dst)
int BM_edgeloop_length_get(BMEdgeLoopStore *el_store)
bool BM_edgeloop_is_closed(BMEdgeLoopStore *el_store)
ListBase * BM_edgeloop_verts_get(BMEdgeLoopStore *el_store)
void BMO_error_raise(BMesh *bm, BMOperator *owner, eBMOpErrorLevel level, const char *msg) ATTR_NONNULL(1
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
ATTR_WARN_UNUSED_RESULT BMesh * bm
BMVert * BM_edge_collapse(BMesh *bm, BMEdge *e_kill, BMVert *v_kill, const bool do_del, const bool kill_degenerate_faces)
#define BMO_edge_flag_test_bool(bm, e, oflag)
void BMO_slot_buffer_flag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
BMO_FLAG_BUFFER.
void BMO_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
#define BMO_face_flag_enable(bm, e, oflag)
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
void BM_face_as_array_loop_quad(BMFace *f, BMLoop *r_loops[4])
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
static void bm_loop_interp_from_grid_boundary_2(BMesh *bm, BMLoop *l, BMLoop *l_bound[2], const float t)
static void bm_loop_interp_from_grid_boundary_4(BMesh *bm, BMLoop *l, BMLoop *l_bound[4], const float w[4])
static void bm_edgeloop_flag_set(BMEdgeLoopStore *estore, char hflag, bool set)
static void barycentric_weights_v2_grid_cache(const uint xtot, const uint ytot, float(*weight_table)[4])
static void bm_grid_fill_array(BMesh *bm, BMVert **v_grid, const uint xtot, const uint ytot, const short mat_nr, const bool use_smooth, const bool use_flip, const bool use_interp_simple)
static void bm_loop_pair_from_verts(BMVert *v_a, BMVert *v_b, BMLoop *l_pair[2])
static void bm_grid_fill(BMesh *bm, BMEdgeLoopStore *estore_a, BMEdgeLoopStore *estore_b, BMEdgeLoopStore *estore_rail_a, BMEdgeLoopStore *estore_rail_b, const short mat_nr, const bool use_smooth, const bool use_interp_simple)
static void quad_verts_to_barycentric_tri(float tri[3][3], const float co_a[3], const float co_b[3], const float co_a_next[3], const float co_b_next[3], const float co_a_prev[3], const float co_b_prev[3], const bool is_flip)
static void bm_loop_pair_test_copy(BMLoop *l_pair_a[2], BMLoop *l_pair_b[2])
static bool bm_edge_test_cb(BMEdge *e, void *bm_v)
void bmo_grid_fill_exec(BMesh *bm, BMOperator *op)
static bool bm_edge_test_rail_cb(BMEdge *e, void *)
static void quad_edges_to_normal(float no[3], const float co_a1[3], const float co_a2[3], const float co_b1[3], const float co_b2[3])
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
draw_view in_light_buf[] float
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
ccl_device_inline float3 cos(float3 v)
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]