32 float max_segment = 0.01f;
35 if (width != 0 && height != 0) {
45 bezt_curr = &point->
bezt;
48 if (bezt_next ==
nullptr) {
57 cur_resol =
len / max_segment;
59 resol = std::max(resol, cur_resol);
71 const float max_segment = 0.005;
73 float max_jump = 0.0f;
86 for (
int j = 0; j < point->
tot_uw; j++) {
87 const float w_diff = (point->
uw[j].
w - prev_w);
88 const float u_diff = (point->
uw[j].
u - prev_u);
92 if (u_diff > FLT_EPSILON) {
98 prev_u = point->
uw[j].
u;
99 prev_w = point->
uw[j].
w;
103 resol += max_jump / max_segment;
114 return ((spline->
tot_point - 1) * resol) + 1;
119 uint *r_tot_diff_point))[2]
124 float (*diff_points)[2], (*fp)[2];
128 if (spline->tot_point <= 1) {
130 *r_tot_diff_point = 0;
135 *r_tot_diff_point = tot;
138 a = spline->tot_point - 1;
143 point_prev = points_array;
144 point_curr = point_prev + 1;
152 point_curr = points_array;
155 bezt_prev = &point_prev->
bezt;
156 bezt_curr = &point_curr->
bezt;
158 for (j = 0; j < 2; j++) {
160 bezt_prev->
vec[2][j],
161 bezt_curr->
vec[0][j],
162 bezt_curr->
vec[1][j],
174 point_prev = point_curr;
182 MaskSpline *spline,
int width,
int height,
uint *r_tot_diff_point))[2]
199 const int alloc_delta = 256;
220 int tot_feather_point,
225 const float *v1 = (
float *)feather_points[cur_a];
226 const float *
v2 = (
float *)feather_points[cur_b];
232 const float *v3 = (
float *)feather_points[check_a];
233 const float *v4 = (
float *)feather_points[check_b];
235 if (check_a >= cur_a - 1 || cur_b == check_a) {
242 float min_a[2], max_a[2];
243 float min_b[2], max_b[2];
251 for (k = 0; k < tot_feather_point; k++) {
252 if (k >= check_b && k <= cur_a) {
260 if (max_a[0] - min_a[0] < max_b[0] - min_b[0] || max_a[1] - min_a[1] < max_b[1] - min_b[1]) {
261 for (k = check_b; k <= cur_a; k++) {
266 for (k = 0; k <= check_a; k++) {
271 for (k = cur_b; k < tot_feather_point; k++) {
282 const float bucket_scale[2],
283 const int buckets_per_side)
285 int x = int((co[0] -
min[0]) * bucket_scale[0]);
286 int y = int((co[1] -
min[1]) * bucket_scale[1]);
288 if (
x == buckets_per_side) {
292 if (
y == buckets_per_side) {
296 return y * buckets_per_side +
x;
300 int start_bucket_index,
301 int end_bucket_index,
302 int buckets_per_side,
306 int start_bucket_x = start_bucket_index % buckets_per_side;
307 int start_bucket_y = start_bucket_index / buckets_per_side;
309 int end_bucket_x = end_bucket_index % buckets_per_side;
310 int end_bucket_y = end_bucket_index / buckets_per_side;
312 int diagonal_bucket_a_index = start_bucket_y * buckets_per_side + end_bucket_x;
313 int diagonal_bucket_b_index = end_bucket_y * buckets_per_side + start_bucket_x;
315 *r_diagonal_bucket_a = &buckets[diagonal_bucket_a_index];
316 *r_diagonal_bucket_b = &buckets[diagonal_bucket_b_index];
320 float (*feather_points)[2],
321 const uint tot_feather_point)
323#define BUCKET_INDEX(co) feather_bucket_index_from_coord(co, min, bucket_scale, buckets_per_side)
325 int buckets_per_side, tot_bucket;
326 float bucket_size, bucket_scale[2];
331 float max_delta_x = -1.0f, max_delta_y = -1.0f, max_delta;
333 if (tot_feather_point < 4) {
344 for (
uint i = 0;
i < tot_feather_point;
i++) {
350 if (
next == tot_feather_point) {
359 delta =
fabsf(feather_points[
i][0] - feather_points[
next][0]);
360 max_delta_x = std::max(delta, max_delta_x);
362 delta =
fabsf(feather_points[
i][1] - feather_points[
next][1]);
363 max_delta_y = std::max(delta, max_delta_y);
367 if (
max[0] -
min[0] < FLT_EPSILON) {
372 if (
max[1] -
min[1] < FLT_EPSILON) {
382 max_delta_x /=
max[0] -
min[0];
383 max_delta_y /=
max[1] -
min[1];
385 max_delta = std::max(max_delta_x, max_delta_y);
387 buckets_per_side =
min_ii(512, 0.9f / max_delta);
389 if (buckets_per_side == 0) {
392 buckets_per_side = 1;
395 tot_bucket = buckets_per_side * buckets_per_side;
396 bucket_size = 1.0f / buckets_per_side;
399 bucket_scale[0] = 1.0f / ((
max[0] -
min[0]) * bucket_size);
400 bucket_scale[1] = 1.0f / ((
max[1] -
min[1]) * bucket_size);
405 for (
int i = 0;
i < tot_feather_point;
i++) {
406 int start =
i, end =
i + 1;
407 int start_bucket_index, end_bucket_index;
409 if (end == tot_feather_point) {
418 start_bucket_index =
BUCKET_INDEX(feather_points[start]);
423 if (start_bucket_index != end_bucket_index) {
441 for (
int i = 0;
i < tot_feather_point;
i++) {
442 int cur_a =
i, cur_b =
i + 1;
443 int start_bucket_index, end_bucket_index;
447 if (cur_b == tot_feather_point) {
451 start_bucket_index =
BUCKET_INDEX(feather_points[cur_a]);
454 start_bucket = &buckets[start_bucket_index];
458 if (start_bucket_index != end_bucket_index) {
471 feather_points, tot_feather_point, diagonal_bucket_a, cur_a, cur_b);
473 feather_points, tot_feather_point, diagonal_bucket_b, cur_a, cur_b);
478 for (
int i = 0;
i < tot_bucket;
i++) {
479 if (buckets[
i].segments) {
493 const bool do_feather_isect,
494 uint *r_tot_feather_point))[2]
498 float (*feather)[2], (*fp)[2];
511 point_prev = points_array;
512 point_curr = point_prev + 1;
520 point_curr = points_array;
526 for (j = 0; j < resol; j++, fp++) {
527 float u =
float(j) / resol, weight;
540 float u = 1.0f, weight;
550 point_prev = point_curr;
554 *r_tot_feather_point = tot;
567 const bool do_feather_isect,
568 uint *r_tot_feather_point))[2]
573 float (*feather)[2], (*fp)[2];
579 *r_tot_feather_point = 0;
584 *r_tot_feather_point = tot;
592 point_prev = points_array;
593 point_curr = point_prev + 1;
598 float point_prev_n[2], point_curr_n[2], tvec[2];
599 float weight_prev, weight_curr;
600 float len_base, len_feather, len_scalar;
607 point_curr = points_array;
610 bezt_prev = &point_prev->
bezt;
611 bezt_curr = &point_curr->
bezt;
614 local_prevbezt = *bezt_prev;
615 local_bezt = *bezt_curr;
617 bezt_prev = &local_prevbezt;
618 bezt_curr = &local_bezt;
623 point_prev_n[0] = -tvec[1];
624 point_prev_n[1] = tvec[0];
628 point_curr_n[0] = -tvec[1];
629 point_curr_n[1] = tvec[0];
631 weight_prev = bezt_prev->
weight;
632 weight_curr = bezt_curr->
weight;
651 len_scalar = len_feather / len_base;
659 for (j = 0; j < 2; j++) {
661 bezt_prev->
vec[2][j],
662 bezt_curr->
vec[0][j],
663 bezt_curr->
vec[1][j],
671 for (j = 0; j < resol; j++, fp++) {
672 float u =
float(j) / resol;
673 float weight_uw, weight_scalar;
694 point_prev = point_curr;
708 const bool do_feather_isect,
709 uint *r_tot_feather_point))[2]
714 spline, resol, do_feather_isect, r_tot_feather_point);
718 spline, resol, do_feather_isect, r_tot_feather_point);
727 float (*feather)[2], (*fp)[2];
751 for (j = 0; j < point->
tot_uw; j++) {
752 float u = point->
uw[j].
u;
764 *r_tot_feather_point = tot;
777 for (
uint i = 0;
i < resol;
i++, fp += 2) {
778 float u =
float(
i % resol) / resol, weight;
785 fp[0] = co[0] + n[0] * weight;
786 fp[1] = co[1] + n[1] * weight;
789 *r_tot_feather_point = resol;
800 float *diff_points, *fp;
811 *r_tot_diff_point = resol + 1;
814 for (j = 0; j < 2; j++) {
817 bezt_next->
vec[0][j],
818 bezt_next->
vec[1][j],
831 float parent_matrix[3][3];
844 masklay, ctime, &masklay_shape_a, &masklay_shape_b);
848 printf(
"%s: exact %d %d (%d)\n",
852 masklay_shape_a->
frame);
856 else if (found == 2) {
857 float w = masklay_shape_b->
frame - masklay_shape_a->
frame;
859 printf(
"%s: tween %d %d (%d %d)\n",
863 masklay_shape_a->
frame,
864 masklay_shape_b->
frame);
867 masklay, masklay_shape_a, masklay_shape_b, (ctime - masklay_shape_a->
frame) /
w);
880 bool need_handle_recalc =
false;
886 *point_deform = *point;
891 need_handle_recalc =
true;
897 if (need_handle_recalc) {
928 if (is_depsgraph_active) {
931 *masklay_eval =
static_cast<MaskLayer *
>(
mask->masklayers.first);
932 masklay_orig !=
nullptr;
933 masklay_orig = masklay_orig->
next, masklay_eval = masklay_eval->
next)
936 *spline_eval =
static_cast<MaskSpline *
>(masklay_eval->splines.first);
937 spline_orig !=
nullptr;
938 spline_orig = spline_orig->
next, spline_eval = spline_eval->
next)
940 for (
int i = 0;
i < spline_eval->tot_point;
i++) {
943 point_orig->
bezt = point_eval->
bezt;
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
void BKE_mask_layer_shape_to_mask(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape)
struct MaskSplinePoint * BKE_mask_spline_point_array_from_point(struct MaskSpline *spline, const struct MaskSplinePoint *point_ref)
void BKE_mask_layer_shape_to_mask_interp(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape_a, struct MaskLayerShape *masklay_shape_b, float fac)
void BKE_mask_calc_handle_point(struct MaskSpline *spline, struct MaskSplinePoint *point)
void BKE_mask_point_free(struct MaskSplinePoint *point)
int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay, float frame, struct MaskLayerShape **r_masklay_shape_a, struct MaskLayerShape **r_masklay_shape_b)
struct BezTriple * BKE_mask_spline_point_next_bezt(struct MaskSpline *spline, struct MaskSplinePoint *points_array, struct MaskSplinePoint *point)
void BKE_mask_spline_ensure_deform(struct MaskSpline *spline)
float BKE_mask_point_weight(struct MaskSpline *spline, struct MaskSplinePoint *point, float u)
float BKE_mask_point_weight_scalar(struct MaskSpline *spline, struct MaskSplinePoint *point, float u)
void BKE_mask_layer_calc_handles(struct MaskLayer *masklay)
void BKE_mask_point_parent_matrix_get(struct MaskSplinePoint *point, float ctime, float parent_matrix[3][3])
void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float n[2])
void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2])
struct MaskSplinePoint * BKE_mask_spline_point_array(struct MaskSpline *spline)
#define LISTBASE_FOREACH(type, var, list)
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float max_ff(float a, float b)
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
bool isect_seg_seg_v2_simple(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2])
void mul_m3_v2(const float m[3][3], float r[2])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
void dist_ensure_v2_v2fl(float v1[2], const float v2[2], float dist)
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
MINLINE void add_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])
#define INIT_MINMAX2(min, max)
uint64_t DEG_get_update_count(const Depsgraph *depsgraph)
bool DEG_is_active(const Depsgraph *depsgraph)
void DEG_debug_print_eval(Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
float DEG_get_ctime(const Depsgraph *graph)
T * DEG_get_original(T *id)
@ MASK_SPLINE_NOINTERSECT
@ MASK_SPLINE_OFFSET_SMOOTH
@ MASK_SPLINE_OFFSET_EVEN
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
BPy_StructRNA * depsgraph
void jump(const btVector3 &v=btVector3(0, 0, 0))
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_dupallocN(const void *vmemh)
void MEM_freeN(void *vmemh)
static void feather_bucket_get_diagonal(FeatherEdgesBucket *buckets, int start_bucket_index, int end_bucket_index, int buckets_per_side, FeatherEdgesBucket **r_diagonal_bucket_a, FeatherEdgesBucket **r_diagonal_bucket_b)
float(* BKE_mask_spline_feather_points(MaskSpline *spline, int *r_tot_feather_point))[2]
int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
void BKE_mask_layer_evaluate_animation(MaskLayer *masklay, const float ctime)
static float(* mask_spline_feather_differentiated_points_with_resolution__even(MaskSpline *spline, const uint resol, const bool do_feather_isect, uint *r_tot_feather_point))[2]
static void mask_evaluate_apply_point_parent(MaskSplinePoint *point, float ctime)
int BKE_mask_spline_differentiate_calc_total(const MaskSpline *spline, const uint resol)
void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, float(*feather_points)[2], const uint tot_feather_point)
void BKE_mask_eval_animation(Depsgraph *depsgraph, Mask *mask)
float(* BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline *spline, const uint resol, const bool do_feather_isect, uint *r_tot_feather_point))[2]
float(* BKE_mask_spline_differentiate(MaskSpline *spline, int width, int height, uint *r_tot_diff_point))[2]
static void feather_bucket_check_intersect(float(*feather_points)[2], int tot_feather_point, FeatherEdgesBucket *bucket, int cur_a, int cur_b)
void BKE_mask_layer_evaluate_deform(MaskLayer *masklay, const float ctime)
float(* BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline, const uint resol, uint *r_tot_diff_point))[2]
static float(* mask_spline_feather_differentiated_points_with_resolution__double(MaskSpline *spline, const uint resol, const bool do_feather_isect, uint *r_tot_feather_point))[2]
uint BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height)
void BKE_mask_eval_update(Depsgraph *depsgraph, Mask *mask)
static void feather_bucket_add_edge(FeatherEdgesBucket *bucket, int start, int end)
static int feather_bucket_index_from_coord(const float co[2], const float min[2], const float bucket_scale[2], const int buckets_per_side)
float * BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, int width, int height, uint *r_tot_diff_point)
float * BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, int width, int height, uint *r_tot_feather_point)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
MaskSplinePoint * points_deform