36 float max_segment = 0.01f;
39 if (width != 0 && height != 0) {
49 bezt_curr = &point->
bezt;
52 if (bezt_next ==
nullptr) {
61 cur_resol =
len / max_segment;
63 resol = std::max(resol, cur_resol);
75 const float max_segment = 0.005;
77 float max_jump = 0.0f;
84 for (
int i = 0; i < spline->
tot_point; i++) {
90 for (
int j = 0; j < point->
tot_uw; j++) {
91 const float w_diff = (point->
uw[j].
w - prev_w);
92 const float u_diff = (point->
uw[j].
u - prev_u);
102 prev_u = point->
uw[j].
u;
103 prev_w = point->
uw[j].
w;
107 resol += max_jump / max_segment;
118 return ((spline->
tot_point - 1) * resol) + 1;
123 uint *r_tot_diff_point))[2]
128 float (*diff_points)[2], (*fp)[2];
132 if (spline->tot_point <= 1) {
134 *r_tot_diff_point = 0;
139 *r_tot_diff_point = tot;
142 a = spline->tot_point - 1;
147 point_prev = points_array;
148 point_curr = point_prev + 1;
156 point_curr = points_array;
159 bezt_prev = &point_prev->
bezt;
160 bezt_curr = &point_curr->
bezt;
162 for (j = 0; j < 2; j++) {
164 bezt_prev->
vec[2][j],
165 bezt_curr->
vec[0][j],
166 bezt_curr->
vec[1][j],
178 point_prev = point_curr;
186 MaskSpline *spline,
int width,
int height,
uint *r_tot_diff_point))[2]
203 const int alloc_delta = 256;
224 int tot_feather_point,
229 const float *v1 =
static_cast<float *
>(feather_points[cur_a]);
230 const float *
v2 =
static_cast<float *
>(feather_points[cur_b]);
233 int check_a = bucket->
segments[i][0];
234 int check_b = bucket->
segments[i][1];
236 const float *v3 =
static_cast<float *
>(feather_points[check_a]);
237 const float *v4 =
static_cast<float *
>(feather_points[check_b]);
239 if (check_a >= cur_a - 1 || cur_b == check_a) {
246 float min_a[2], max_a[2];
247 float min_b[2], max_b[2];
255 for (k = 0; k < tot_feather_point; k++) {
256 if (k >= check_b && k <= cur_a) {
264 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]) {
265 for (k = check_b; k <= cur_a; k++) {
270 for (k = 0; k <= check_a; k++) {
275 for (k = cur_b; k < tot_feather_point; k++) {
286 const float bucket_scale[2],
287 const int buckets_per_side)
289 int x = int((co[0] -
min[0]) * bucket_scale[0]);
290 int y = int((co[1] -
min[1]) * bucket_scale[1]);
292 if (
x == buckets_per_side) {
296 if (
y == buckets_per_side) {
300 return y * buckets_per_side +
x;
304 int start_bucket_index,
305 int end_bucket_index,
306 int buckets_per_side,
310 int start_bucket_x = start_bucket_index % buckets_per_side;
311 int start_bucket_y = start_bucket_index / buckets_per_side;
313 int end_bucket_x = end_bucket_index % buckets_per_side;
314 int end_bucket_y = end_bucket_index / buckets_per_side;
316 int diagonal_bucket_a_index = start_bucket_y * buckets_per_side + end_bucket_x;
317 int diagonal_bucket_b_index = end_bucket_y * buckets_per_side + start_bucket_x;
319 *r_diagonal_bucket_a = &buckets[diagonal_bucket_a_index];
320 *r_diagonal_bucket_b = &buckets[diagonal_bucket_b_index];
324 float (*feather_points)[2],
325 const uint tot_feather_point)
327#define BUCKET_INDEX(co) feather_bucket_index_from_coord(co, min, bucket_scale, buckets_per_side)
329 int buckets_per_side, tot_bucket;
330 float bucket_size, bucket_scale[2];
335 float max_delta_x = -1.0f, max_delta_y = -1.0f, max_delta;
337 if (tot_feather_point < 4) {
348 for (
uint i = 0; i < tot_feather_point; i++) {
354 if (next == tot_feather_point) {
363 delta =
fabsf(feather_points[i][0] - feather_points[next][0]);
364 max_delta_x = std::max(delta, max_delta_x);
366 delta =
fabsf(feather_points[i][1] - feather_points[next][1]);
367 max_delta_y = std::max(delta, max_delta_y);
386 max_delta_x /=
max[0] -
min[0];
387 max_delta_y /=
max[1] -
min[1];
389 max_delta = std::max(max_delta_x, max_delta_y);
391 buckets_per_side =
min_ii(512, 0.9f / max_delta);
393 if (buckets_per_side == 0) {
396 buckets_per_side = 1;
399 tot_bucket = buckets_per_side * buckets_per_side;
400 bucket_size = 1.0f / buckets_per_side;
403 bucket_scale[0] = 1.0f / ((
max[0] -
min[0]) * bucket_size);
404 bucket_scale[1] = 1.0f / ((
max[1] -
min[1]) * bucket_size);
409 for (
int i = 0; i < tot_feather_point; i++) {
410 int start = i, end = i + 1;
411 int start_bucket_index, end_bucket_index;
413 if (end == tot_feather_point) {
422 start_bucket_index =
BUCKET_INDEX(feather_points[start]);
427 if (start_bucket_index != end_bucket_index) {
445 for (
int i = 0; i < tot_feather_point; i++) {
446 int cur_a = i, cur_b = i + 1;
447 int start_bucket_index, end_bucket_index;
451 if (cur_b == tot_feather_point) {
455 start_bucket_index =
BUCKET_INDEX(feather_points[cur_a]);
458 start_bucket = &buckets[start_bucket_index];
462 if (start_bucket_index != end_bucket_index) {
475 feather_points, tot_feather_point, diagonal_bucket_a, cur_a, cur_b);
477 feather_points, tot_feather_point, diagonal_bucket_b, cur_a, cur_b);
482 for (
int i = 0; i < tot_bucket; i++) {
483 if (buckets[i].segments) {
484 MEM_delete(buckets[i].segments);
497 const bool do_feather_isect,
498 uint *r_tot_feather_point))[2]
502 float (*feather)[2], (*fp)[2];
515 point_prev = points_array;
516 point_curr = point_prev + 1;
524 point_curr = points_array;
530 for (j = 0; j < resol; j++, fp++) {
531 float u =
float(j) / resol, weight;
544 float u = 1.0f, weight;
554 point_prev = point_curr;
558 *r_tot_feather_point = tot;
571 const bool do_feather_isect,
572 uint *r_tot_feather_point))[2]
577 float (*feather)[2], (*fp)[2];
583 *r_tot_feather_point = 0;
588 *r_tot_feather_point = tot;
596 point_prev = points_array;
597 point_curr = point_prev + 1;
602 float point_prev_n[2], point_curr_n[2], tvec[2];
603 float weight_prev, weight_curr;
604 float len_base, len_feather, len_scalar;
611 point_curr = points_array;
614 bezt_prev = &point_prev->
bezt;
615 bezt_curr = &point_curr->
bezt;
618 local_prevbezt = *bezt_prev;
619 local_bezt = *bezt_curr;
621 bezt_prev = &local_prevbezt;
622 bezt_curr = &local_bezt;
627 point_prev_n[0] = -tvec[1];
628 point_prev_n[1] = tvec[0];
632 point_curr_n[0] = -tvec[1];
633 point_curr_n[1] = tvec[0];
635 weight_prev = bezt_prev->
weight;
636 weight_curr = bezt_curr->
weight;
655 len_scalar = len_feather / len_base;
663 for (j = 0; j < 2; j++) {
665 bezt_prev->
vec[2][j],
666 bezt_curr->
vec[0][j],
667 bezt_curr->
vec[1][j],
675 for (j = 0; j < resol; j++, fp++) {
676 float u =
float(j) / resol;
677 float weight_uw, weight_scalar;
698 point_prev = point_curr;
712 const bool do_feather_isect,
713 uint *r_tot_feather_point))[2]
718 spline, resol, do_feather_isect, r_tot_feather_point);
722 spline, resol, do_feather_isect, r_tot_feather_point);
731 float (*feather)[2], (*fp)[2];
734 for (i = 0; i < spline->
tot_point; i++) {
743 for (i = 0; i < spline->
tot_point; i++) {
755 for (j = 0; j < point->
tot_uw; j++) {
756 float u = point->
uw[j].
u;
768 *r_tot_feather_point = tot;
781 for (
uint i = 0; i < resol; i++, fp += 2) {
782 float u =
float(i % resol) / resol, weight;
789 fp[0] = co[0] + n[0] * weight;
790 fp[1] = co[1] + n[1] * weight;
793 *r_tot_feather_point = resol;
804 float *diff_points, *fp;
815 *r_tot_diff_point = resol + 1;
818 for (j = 0; j < 2; j++) {
821 bezt_next->
vec[0][j],
822 bezt_next->
vec[1][j],
835 float parent_matrix[3][3];
848 masklay, ctime, &masklay_shape_a, &masklay_shape_b);
852 printf(
"%s: exact %d %d (%d)\n",
856 masklay_shape_a->
frame);
860 else if (found == 2) {
861 float w = masklay_shape_b->
frame - masklay_shape_a->
frame;
863 printf(
"%s: tween %d %d (%d %d)\n",
867 masklay_shape_a->
frame,
868 masklay_shape_b->
frame);
871 masklay, masklay_shape_a, masklay_shape_b, (ctime - masklay_shape_a->
frame) /
w);
884 bool need_handle_recalc =
false;
886 for (
int i = 0; i < spline.
tot_point; i++) {
890 *point_deform = *point;
891 point_deform->
uw = point->
uw ? MEM_dupalloc(point->
uw) :
nullptr;
894 need_handle_recalc =
true;
900 if (need_handle_recalc) {
901 for (
int i = 0; i < spline.
tot_point; i++) {
931 if (is_depsgraph_active) {
934 *masklay_eval =
mask->masklayers.first();
935 masklay_orig !=
nullptr;
936 masklay_orig = masklay_orig->next, masklay_eval = masklay_eval->next)
938 for (
MaskSpline *spline_orig = masklay_orig->splines.first(),
939 *spline_eval = masklay_eval->splines.first();
940 spline_orig !=
nullptr;
941 spline_orig = spline_orig->
next, spline_eval = spline_eval->
next)
943 for (
int i = 0; i < spline_eval->tot_point; i++) {
946 point_orig->
bezt = point_eval->
bezt;
Read Blender memory allocation and freeing.
#define INIT_MINMAX2(min, max)
#define MEM_realloc_uninitialized(vmemh, len)
void jump(const btVector3 &v=btVector3(0, 0, 0))
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void feather_bucket_add_edge(FeatherEdgesBucket *bucket, int start, int end)
bool DEG_is_active(const Depsgraph *depsgraph)
void BKE_mask_layer_evaluate_deform(MaskLayer *masklay, float ctime)
MINLINE void mul_v2_fl(float r[2], float f)
uint64_t DEG_get_update_count(const Depsgraph *depsgraph)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MaskSplinePoint * BKE_mask_spline_point_array_from_point(MaskSpline *spline, const MaskSplinePoint *point_ref)
void BKE_mask_eval_update(Depsgraph *depsgraph, Mask *mask)
void DEG_debug_print_eval(Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
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])
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]
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
void BKE_mask_point_parent_matrix_get(MaskSplinePoint *point, float ctime, float parent_matrix[3][3])
MINLINE float normalize_v2(float n[2])
MINLINE int max_ii(int a, int b)
void mul_m3_v2(const float m[3][3], float r[2])
void BKE_mask_layer_shape_to_mask(MaskLayer *masklay, MaskLayerShape *masklay_shape)
int BKE_mask_layer_shape_find_frame_range(MaskLayer *masklay, float frame, MaskLayerShape **r_masklay_shape_a, MaskLayerShape **r_masklay_shape_b)
MINLINE void add_v2_v2(float r[2], const float a[2])
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
BezTriple * BKE_mask_spline_point_next_bezt(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point)
int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
float BKE_mask_point_weight_scalar(MaskSpline *spline, MaskSplinePoint *point, float u)
float(* BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline *spline, unsigned int resol, bool do_feather_isect, unsigned int *r_tot_feather_point))[2]
void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, float(*feather_points)[2], unsigned int tot_feather_point)
void BKE_mask_spline_ensure_deform(MaskSpline *spline)
float(* BKE_mask_spline_feather_points(MaskSpline *spline, int *tot_feather_point))[2]
void BKE_mask_layer_calc_handles(MaskLayer *masklay)
@ MASK_SPLINE_NOINTERSECT
void BKE_mask_point_normal(MaskSpline *spline, MaskSplinePoint *point, float u, float n[2])
float * BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, int width, int height, unsigned int *r_tot_feather_point)
int BKE_mask_spline_differentiate_calc_total(const MaskSpline *spline, unsigned int resol)
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]
void dist_ensure_v2_v2fl(float v1[2], const float v2[2], float dist)
bool isect_seg_seg_v2_simple(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
void BKE_mask_layer_evaluate_animation(MaskLayer *masklay, float ctime)
static void feather_bucket_check_intersect(float(*feather_points)[2], int tot_feather_point, FeatherEdgesBucket *bucket, int cur_a, int cur_b)
float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, float u)
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)
T * DEG_get_original(T *id)
static void mask_evaluate_apply_point_parent(MaskSplinePoint *point, float ctime)
void BKE_mask_calc_handle_point(MaskSpline *spline, MaskSplinePoint *point)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
unsigned int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height)
MINLINE float max_ff(float a, float b)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
static constexpr int MASK_RESOL_MAX
void BKE_mask_point_free(MaskSplinePoint *point)
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)
void BKE_mask_eval_animation(Depsgraph *depsgraph, Mask *mask)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
MaskSplinePoint * BKE_mask_spline_point_array(MaskSpline *spline)
void BKE_mask_layer_shape_to_mask_interp(MaskLayer *masklay, MaskLayerShape *masklay_shape_a, MaskLayerShape *masklay_shape_b, float fac)
MINLINE int min_ii(int a, int b)
float DEG_get_ctime(const Depsgraph *graph)
void BKE_mask_point_segment_co(MaskSpline *spline, MaskSplinePoint *point, float u, float co[2])
@ MASK_SPLINE_OFFSET_EVEN
@ MASK_SPLINE_OFFSET_SMOOTH
float * BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, int width, int height, unsigned int *r_tot_diff_point)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
float(* BKE_mask_spline_differentiate(MaskSpline *spline, int width, int height, unsigned int *r_tot_diff_point))[2]
float(* BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline, unsigned int resol, unsigned int *r_tot_diff_point))[2]
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< MaskLayerShape > splines_shapes
ListBaseT< MaskSpline > splines
MaskSplineRuntime * runtime
MaskSplineOffset offset_mode
ListBaseT< struct MaskLayer > masklayers
Array< MaskSplinePoint > points_deform