diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-08-06 17:53:38 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-08-06 17:53:38 +0400 |
commit | b282b5275c919b95e9947801b21678341ec21bba (patch) | |
tree | 3f17c2e028c5d5305f30e74e29575f56c3b87602 /source/blender/blenkernel/intern/mask.c | |
parent | 2b8ac9bc616d9a9cd8f303228efc30fdc9dd38a1 (diff) |
Mask feather self-intersection check
Enable self-intersection check for preview. In own tests average
time for this operation on mango files was ~0.0015sec, and it was
like 20 splines max which still gives pretty smooth performance
on my core quad machine.
Would think let's check how it works for now, if it'll give some
issues here, would just avoid tessellation on every redraw by
storing tessellation in some cache (probably in mask user).
Another change is related on a way which loop to collapse.
Changed length check with AABB size check. A bit slower but
should be a bit more predictable.
Diffstat (limited to 'source/blender/blenkernel/intern/mask.c')
-rw-r--r-- | source/blender/blenkernel/intern/mask.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index 779c1e1b2ec..3208862cef6 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -481,14 +481,29 @@ static void feather_bucket_check_intersect(float (*feather_points)[2], int tot_f continue; if (isect_seg_seg_v2(v1, v2, v3, v4)) { - int k, len; + int k; float p[2]; + float min_a[2], max_a[2]; + float min_b[2], max_b[2]; isect_seg_seg_v2_point(v1, v2, v3, v4, p); - /* TODO: for now simply choose the shortest loop, could be made smarter in some way */ - len = cur_a - check_b; - if (len < tot_feather_point - len) { + INIT_MINMAX2(min_a, max_a); + INIT_MINMAX2(min_b, max_b); + + /* collapse loop with smaller AABB */ + for (k = 0; k < tot_feather_point; k++) { + if (k >= check_b && k <= cur_a) { + DO_MINMAX2(feather_points[k], min_a, max_a); + } + else { + DO_MINMAX2(feather_points[k], min_b, max_b); + } + } + + 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]) + { for (k = check_b; k <= cur_a; k++) { copy_v2_v2(feather_points[k], p); } @@ -702,8 +717,7 @@ static void spline_feather_collapse_inner_loops(MaskSpline *spline, float (*feat */ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpline *spline, int *tot_feather_point, - const unsigned int resol, - const int do_collapse + const unsigned int resol ))[2] { MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); @@ -765,10 +779,7 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpl *tot_feather_point = tot; - /* this is slow! - don't do on draw */ - if (do_collapse) { - spline_feather_collapse_inner_loops(spline, feather, tot); - } + spline_feather_collapse_inner_loops(spline, feather, tot); return feather; } @@ -778,7 +789,7 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline { unsigned int resol = BKE_mask_spline_feather_resolution(spline, width, height); - return BKE_mask_spline_feather_differentiated_points_with_resolution_ex(spline, tot_feather_point, resol, FALSE); + return BKE_mask_spline_feather_differentiated_points_with_resolution_ex(spline, tot_feather_point, resol); } float (*BKE_mask_spline_feather_differentiated_points(MaskSpline *spline, int *tot_feather_point))[2] |