Blender V5.3
mask_query.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "BKE_context.hh"
12#include "BKE_mask.hh"
13
14#include "BLI_listbase.hh"
15#include "BLI_math_geom_c.hh"
16#include "BLI_math_vector_c.hh"
17
19
20#include "DNA_mask_types.h"
21#include "DNA_screen_types.h"
22
23#include "ED_clip.hh"
24#include "ED_image.hh"
25#include "ED_mask.hh" /* own include */
26
27#include "UI_view2d.hh"
28
29#include "mask_intern.hh" /* own include */
30
31namespace blender {
32
33/* -------------------------------------------------------------------- */
36
38 Mask *mask_orig,
39 const float normal_co[2],
40 int threshold,
41 bool feather,
42 float tangent[2],
43 const bool use_deform,
44 const bool use_project,
45 MaskLayer **r_mask_layer,
46 MaskSpline **r_spline,
47 MaskSplinePoint **r_point,
48 float *r_u,
49 float *r_score)
50{
51 const float threshold_sq = threshold * threshold;
52
53 ScrArea *area = CTX_wm_area(C);
54 ARegion *region = CTX_wm_region(C);
55
56 MaskLayer *point_mask_layer;
57 MaskSpline *point_spline;
58 MaskSplinePoint *point = nullptr;
59 float dist_best_sq = FLT_MAX, co[2];
60 int width, height;
61 float u = 0.0f;
62 float scalex, scaley;
63
64 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
65 Mask *mask_eval = DEG_get_evaluated(depsgraph, mask_orig);
66
67 ED_mask_get_size(area, &width, &height);
68 ED_mask_pixelspace_factor(area, region, &scalex, &scaley);
69
70 co[0] = normal_co[0] * scalex;
71 co[1] = normal_co[1] * scaley;
72
73 for (MaskLayer *mask_layer_orig = mask_orig->masklayers.first(),
74 *mask_layer_eval = mask_eval->masklayers.first();
75 mask_layer_orig != nullptr;
76 mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next)
77 {
78 if (mask_layer_orig->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
79 continue;
80 }
81
82 for (MaskSpline *spline_orig = mask_layer_orig->splines.first(),
83 *spline_eval = mask_layer_eval->splines.first();
84 spline_orig != nullptr;
85 spline_orig = spline_orig->next, spline_eval = spline_eval->next)
86 {
87 int i;
88 MaskSplinePoint *cur_point_eval;
89
90 for (i = 0,
91 cur_point_eval = use_deform ? spline_eval->runtime->points_deform.data() :
92 spline_eval->points;
93 i < spline_eval->tot_point;
94 i++, cur_point_eval++)
95 {
96 uint tot_diff_point;
97 float *diff_points = BKE_mask_point_segment_diff(
98 spline_eval, cur_point_eval, width, height, &tot_diff_point);
99
100 if (diff_points) {
101 int j, tot_point;
102 uint tot_feather_point;
103 float *feather_points = nullptr, *points;
104
105 if (feather) {
107 spline_eval, cur_point_eval, width, height, &tot_feather_point);
108
109 points = feather_points;
110 tot_point = tot_feather_point;
111 }
112 else {
113 points = diff_points;
114 tot_point = tot_diff_point;
115 }
116
117 for (j = 0; j < tot_point - 1; j++) {
118 float dist_sq, a[2], b[2];
119
120 a[0] = points[2 * j] * scalex;
121 a[1] = points[2 * j + 1] * scaley;
122
123 b[0] = points[2 * j + 2] * scalex;
124 b[1] = points[2 * j + 3] * scaley;
125
126 dist_sq = dist_squared_to_line_segment_v2(co, a, b);
127
128 if (dist_sq < dist_best_sq) {
129 if (tangent) {
130 sub_v2_v2v2(tangent, &diff_points[2 * j + 2], &diff_points[2 * j]);
131 }
132
133 point_mask_layer = mask_layer_orig;
134 point_spline = spline_orig;
135 point = use_deform ?
136 &spline_orig->points[(cur_point_eval -
137 spline_eval->runtime->points_deform.data())] :
138 &spline_orig->points[(cur_point_eval - spline_eval->points)];
139 dist_best_sq = dist_sq;
140 u = float(j) / tot_point;
141 }
142 }
143
144 if (feather_points != nullptr) {
145 MEM_delete(feather_points);
146 }
147 MEM_delete(diff_points);
148 }
149 }
150 }
151 }
152
153 if (point && dist_best_sq < threshold_sq) {
154 if (r_mask_layer) {
155 *r_mask_layer = point_mask_layer;
156 }
157
158 if (r_spline) {
159 *r_spline = point_spline;
160 }
161
162 if (r_point) {
163 *r_point = point;
164 }
165
166 if (r_u) {
167 /* TODO(sergey): Projection fails in some weirdo cases. */
168 if (use_project) {
169 u = BKE_mask_spline_project_co(point_spline, point, u, normal_co, MASK_PROJ_ANY);
170 }
171
172 *r_u = u;
173 }
174
175 if (r_score) {
176 *r_score = dist_best_sq;
177 }
178
179 return true;
180 }
181
182 if (r_mask_layer) {
183 *r_mask_layer = nullptr;
184 }
185
186 if (r_spline) {
187 *r_spline = nullptr;
188 }
189
190 if (r_point) {
191 *r_point = nullptr;
192 }
193
194 return false;
195}
196
198 const eMaskWhichHandle which_handle,
199 const float scalex,
200 const float scaley,
201 float handle[2])
202{
203 BKE_mask_point_handle(point, which_handle, handle);
204 handle[0] *= scalex;
205 handle[1] *= scaley;
206}
207
209 Mask *mask_orig,
210 const float normal_co[2],
211 const float threshold,
212 MaskLayer **r_mask_layer,
213 MaskSpline **r_spline,
214 eMaskWhichHandle *r_which_handle,
215 float *r_score)
216{
217 ScrArea *area = CTX_wm_area(C);
218 ARegion *region = CTX_wm_region(C);
219
220 MaskLayer *point_mask_layer = nullptr;
221 MaskSpline *point_spline = nullptr;
222 MaskSplinePoint *point = nullptr;
223 float co[2];
224 const float threshold_sq = threshold * threshold;
225 float len_sq = FLT_MAX, scalex, scaley;
227 int width, height;
228
229 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
230 Mask *mask_eval = DEG_get_evaluated(depsgraph, mask_orig);
231
232 ED_mask_get_size(area, &width, &height);
233 ED_mask_pixelspace_factor(area, region, &scalex, &scaley);
234
235 co[0] = normal_co[0] * scalex;
236 co[1] = normal_co[1] * scaley;
237
238 for (MaskLayer *mask_layer_orig = mask_orig->masklayers.first(),
239 *mask_layer_eval = mask_eval->masklayers.first();
240 mask_layer_orig != nullptr;
241 mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next)
242 {
243
244 if (mask_layer_orig->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
245 continue;
246 }
247
248 for (MaskSpline *spline_orig = mask_layer_orig->splines.first(),
249 *spline_eval = mask_layer_eval->splines.first();
250 spline_orig != nullptr;
251 spline_orig = spline_orig->next, spline_eval = spline_eval->next)
252 {
253 MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline_eval);
254
255 for (int i = 0; i < spline_orig->tot_point; i++) {
256 MaskSplinePoint *cur_point_orig = &spline_orig->points[i];
257 const MaskSplinePoint *cur_point_deform_eval = &points_array[i];
258 eMaskWhichHandle cur_which_handle = MASK_WHICH_HANDLE_NONE;
259 const BezTriple *bezt = &cur_point_deform_eval->bezt;
260 float cur_len_sq, vec[2];
261
262 vec[0] = bezt->vec[1][0] * scalex;
263 vec[1] = bezt->vec[1][1] * scaley;
264
265 cur_len_sq = len_squared_v2v2(co, vec);
266
267 if (cur_len_sq < len_sq) {
268 point_spline = spline_orig;
269 point_mask_layer = mask_layer_orig;
270 point = cur_point_orig;
271 len_sq = cur_len_sq;
272 which_handle = MASK_WHICH_HANDLE_NONE;
273 }
274
275 if (BKE_mask_point_handles_mode_get(cur_point_deform_eval) == MASK_HANDLE_MODE_STICK) {
276 float handle[2];
278 cur_point_deform_eval, MASK_WHICH_HANDLE_STICK, scalex, scaley, handle);
279 cur_len_sq = len_squared_v2v2(co, handle);
280 cur_which_handle = MASK_WHICH_HANDLE_STICK;
281 }
282 else {
283 float handle_left[2], handle_right[2];
284 float len_left_sq, len_right_sq;
286 cur_point_deform_eval, MASK_WHICH_HANDLE_LEFT, scalex, scaley, handle_left);
288 cur_point_deform_eval, MASK_WHICH_HANDLE_RIGHT, scalex, scaley, handle_right);
289
290 len_left_sq = len_squared_v2v2(co, handle_left);
291 len_right_sq = len_squared_v2v2(co, handle_right);
292 if (i == 0) {
293 if (len_left_sq <= len_right_sq) {
294 if (bezt->h1 != HD_VECT) {
295 cur_which_handle = MASK_WHICH_HANDLE_LEFT;
296 cur_len_sq = len_left_sq;
297 }
298 }
299 else if (bezt->h2 != HD_VECT) {
300 cur_which_handle = MASK_WHICH_HANDLE_RIGHT;
301 cur_len_sq = len_right_sq;
302 }
303 }
304 else {
305 if (len_right_sq <= len_left_sq) {
306 if (bezt->h2 != HD_VECT) {
307 cur_which_handle = MASK_WHICH_HANDLE_RIGHT;
308 cur_len_sq = len_right_sq;
309 }
310 }
311 else if (bezt->h1 != HD_VECT) {
312 cur_which_handle = MASK_WHICH_HANDLE_LEFT;
313 cur_len_sq = len_left_sq;
314 }
315 }
316 }
317
318 if (cur_len_sq <= len_sq && cur_which_handle != MASK_WHICH_HANDLE_NONE) {
319 point_mask_layer = mask_layer_orig;
320 point_spline = spline_orig;
321 point = cur_point_orig;
322 len_sq = cur_len_sq;
323 which_handle = cur_which_handle;
324 }
325 }
326 }
327 }
328
329 if (len_sq < threshold_sq) {
330 if (r_mask_layer) {
331 *r_mask_layer = point_mask_layer;
332 }
333
334 if (r_spline) {
335 *r_spline = point_spline;
336 }
337
338 if (r_which_handle) {
339 *r_which_handle = which_handle;
340 }
341
342 if (r_score) {
343 *r_score = sqrtf(len_sq);
344 }
345
346 return point;
347 }
348
349 if (r_mask_layer) {
350 *r_mask_layer = nullptr;
351 }
352
353 if (r_spline) {
354 *r_spline = nullptr;
355 }
356
357 if (r_which_handle) {
358 *r_which_handle = MASK_WHICH_HANDLE_NONE;
359 }
360
361 return nullptr;
362}
363
365 Mask *mask_orig,
366 const float normal_co[2],
367 const float threshold,
368 MaskLayer **r_mask_layer,
369 MaskSpline **r_spline,
370 MaskSplinePoint **r_point,
371 MaskSplinePointUW **r_uw,
372 float *r_score)
373{
374 ScrArea *area = CTX_wm_area(C);
375 ARegion *region = CTX_wm_region(C);
376
377 MaskLayer *point_mask_layer = nullptr;
378 MaskSpline *point_spline = nullptr;
379 MaskSplinePoint *point = nullptr;
380 MaskSplinePointUW *uw = nullptr;
381 const float threshold_sq = threshold * threshold;
382 float len = FLT_MAX, co[2];
383 float scalex, scaley;
384 int width, height;
385
386 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
387 Mask *mask_eval = DEG_get_evaluated(depsgraph, mask_orig);
388
389 ED_mask_get_size(area, &width, &height);
390 ED_mask_pixelspace_factor(area, region, &scalex, &scaley);
391
392 co[0] = normal_co[0] * scalex;
393 co[1] = normal_co[1] * scaley;
394
395 for (MaskLayer *mask_layer_orig = mask_orig->masklayers.first(),
396 *mask_layer_eval = mask_eval->masklayers.first();
397 mask_layer_orig != nullptr;
398 mask_layer_orig = mask_layer_orig->next, mask_layer_eval = mask_layer_eval->next)
399 {
400
401 for (MaskSpline *spline_orig = mask_layer_orig->splines.first(),
402 *spline_eval = mask_layer_eval->splines.first();
403 spline_orig != nullptr;
404 spline_orig = spline_orig->next, spline_eval = spline_eval->next)
405 {
406 // MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
407
408 int i, tot_feather_point;
409 float (*feather_points)[2], (*fp)[2];
410
411 if (mask_layer_orig->visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
412 continue;
413 }
414
415 feather_points = fp = BKE_mask_spline_feather_points(spline_eval, &tot_feather_point);
416
417 for (i = 0; i < spline_orig->tot_point; i++) {
418 int j;
419 MaskSplinePoint *cur_point_orig = &spline_orig->points[i];
420 MaskSplinePoint *cur_point_eval = &spline_eval->points[i];
421
422 for (j = 0; j <= cur_point_eval->tot_uw; j++) {
423 float cur_len_sq, vec[2];
424
425 vec[0] = (*fp)[0] * scalex;
426 vec[1] = (*fp)[1] * scaley;
427
428 cur_len_sq = len_squared_v2v2(vec, co);
429
430 if (point == nullptr || cur_len_sq < len) {
431 if (j == 0) {
432 uw = nullptr;
433 }
434 else {
435 uw = &cur_point_orig->uw[j - 1];
436 }
437
438 point_mask_layer = mask_layer_orig;
439 point_spline = spline_orig;
440 point = cur_point_orig;
441 len = cur_len_sq;
442 }
443
444 fp++;
445 }
446 }
447
448 MEM_delete(feather_points);
449 }
450 }
451
452 if (len < threshold_sq) {
453 if (r_mask_layer) {
454 *r_mask_layer = point_mask_layer;
455 }
456
457 if (r_spline) {
458 *r_spline = point_spline;
459 }
460
461 if (r_point) {
462 *r_point = point;
463 }
464
465 if (r_uw) {
466 *r_uw = uw;
467 }
468
469 if (r_score) {
470 *r_score = sqrtf(len);
471 }
472
473 return true;
474 }
475
476 if (r_mask_layer) {
477 *r_mask_layer = nullptr;
478 }
479
480 if (r_spline) {
481 *r_spline = nullptr;
482 }
483
484 if (r_point) {
485 *r_point = nullptr;
486 }
487
488 return false;
489}
490
491void ED_mask_mouse_pos(ScrArea *area, ARegion *region, const int mval[2], float r_co[2])
492{
493 if (area) {
494 switch (area->spacetype) {
495 case SPACE_CLIP: {
496 SpaceClip *sc = area->spacedata.first_as<SpaceClip>();
497 ED_clip_mouse_pos(sc, region, mval, r_co);
498 BKE_mask_coord_from_movieclip(sc->clip, &sc->user, r_co, r_co);
499 break;
500 }
501 case SPACE_SEQ: {
502 ui::view2d_region_to_view(&region->v2d, mval[0], mval[1], &r_co[0], &r_co[1]);
503 break;
504 }
505 case SPACE_IMAGE: {
506 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
507 ED_image_mouse_pos(sima, region, mval, r_co);
508 BKE_mask_coord_from_image(sima->image, &sima->iuser, r_co, r_co);
509 break;
510 }
511 default:
512 /* possible other spaces from which mask editing is available */
513 BLI_assert(0);
514 zero_v2(r_co);
515 break;
516 }
517 }
518 else {
519 BLI_assert(0);
520 zero_v2(r_co);
521 }
522}
523
524void ED_mask_point_pos(ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
525{
526 float co[2];
527
528 if (area) {
529 switch (area->spacetype) {
530 case SPACE_CLIP: {
531 SpaceClip *sc = area->spacedata.first_as<SpaceClip>();
532 ED_clip_point_stable_pos(sc, region, x, y, &co[0], &co[1]);
533 BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
534 break;
535 }
536 case SPACE_SEQ:
537 zero_v2(co); /* MASKTODO */
538 break;
539 case SPACE_IMAGE: {
540 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
541 ED_image_point_pos(sima, region, x, y, &co[0], &co[1]);
542 BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co);
543 break;
544 }
545 default:
546 /* possible other spaces from which mask editing is available */
547 BLI_assert(0);
548 zero_v2(co);
549 break;
550 }
551 }
552 else {
553 BLI_assert(0);
554 zero_v2(co);
555 }
556
557 *r_x = co[0];
558 *r_y = co[1];
559}
560
562 ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
563{
564 float co[2];
565
566 if (area) {
567 switch (area->spacetype) {
568 case SPACE_CLIP: {
569 SpaceClip *sc = area->spacedata.first_as<SpaceClip>();
570 co[0] = x;
571 co[1] = y;
572 BKE_mask_coord_to_movieclip(sc->clip, &sc->user, co, co);
573 ED_clip_point_stable_pos__reverse(sc, region, co, co);
574 break;
575 }
576 case SPACE_SEQ:
577 zero_v2(co); /* MASKTODO */
578 break;
579 case SPACE_IMAGE: {
580 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
581 co[0] = x;
582 co[1] = y;
583 BKE_mask_coord_to_image(sima->image, &sima->iuser, co, co);
584 ED_image_point_pos__reverse(sima, region, co, co);
585 break;
586 }
587 default:
588 /* possible other spaces from which mask editing is available */
589 BLI_assert(0);
590 zero_v2(co);
591 break;
592 }
593 }
594 else {
595 BLI_assert(0);
596 zero_v2(co);
597 }
598
599 *r_x = co[0];
600 *r_y = co[1];
601}
602
604 eMaskWhichHandle which_handle,
605 bool handles_as_knot,
606 float r_handle[2])
607{
608 if (handles_as_knot) {
609 copy_v2_v2(r_handle, point->bezt.vec[1]);
610 return;
611 }
612 BKE_mask_point_handle(point, which_handle, r_handle);
613}
614
616 float min[2],
617 float max[2],
618 const bool handles_as_knot,
619 const bool handles_as_knot_selected_only)
620{
621 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
623
624 bool ok = false;
625
626 if (mask == nullptr) {
627 return ok;
628 }
629
630 /* Use evaluated mask to take animation into account.
631 * The animation of splines is not "flushed" back to original, so need to explicitly
632 * use evaluated data-block here. */
633 Mask *mask_eval = DEG_get_evaluated(depsgraph, mask);
634
636 for (MaskLayer &mask_layer : mask_eval->masklayers) {
637 if (mask_layer.visibility_flag & (MASK_HIDE_VIEW | MASK_HIDE_SELECT)) {
638 continue;
639 }
640 for (MaskSpline &spline : mask_layer.splines) {
641 MaskSplinePoint *points_array = BKE_mask_spline_point_array(&spline);
642 for (int i = 0; i < spline.tot_point; i++) {
643 const MaskSplinePoint *point = &spline.points[i];
644 const MaskSplinePoint *deform_point = &points_array[i];
645 const BezTriple *bezt = &point->bezt;
646 float handle[2];
647 if (!BKE_mask_point_selected(point)) {
648 continue;
649 }
650 if (bezt->f2 & SELECT || handles_as_knot_selected_only) {
651 minmax_v2v2_v2(min, max, deform_point->bezt.vec[1]);
652 ok = true;
653 continue;
654 }
655
658 deform_point, MASK_WHICH_HANDLE_STICK, handles_as_knot, handle);
659 minmax_v2v2_v2(min, max, handle);
660 ok = true;
661 }
662 else {
663 if ((bezt->f1 & SELECT) && (bezt->h1 != HD_VECT)) {
665 deform_point, MASK_WHICH_HANDLE_LEFT, handles_as_knot, handle);
666 minmax_v2v2_v2(min, max, handle);
667 ok = true;
668 }
669 if ((bezt->f3 & SELECT) && (bezt->h2 != HD_VECT)) {
671 deform_point, MASK_WHICH_HANDLE_RIGHT, handles_as_knot, handle);
672 minmax_v2v2_v2(min, max, handle);
673 ok = true;
674 }
675 }
676 }
677 }
678 }
679 return ok;
680}
681
683 ScrArea *area,
684 const char mode,
685 const bool handles_as_knot_selected_only,
686 float r_center[2],
687 bool *r_has_select)
688{
689 float min[2], max[2];
690 const bool mask_selected = ED_mask_selected_minmax(
691 C, min, max, false, handles_as_knot_selected_only);
692
693 switch (mode) {
695 ED_mask_cursor_location_get(area, r_center);
696 break;
697 default:
698 mid_v2_v2v2(r_center, min, max);
699 break;
700 }
701 if (r_has_select != nullptr) {
702 *r_has_select = mask_selected;
703 }
704}
705
707
708/* -------------------------------------------------------------------- */
711
712void ED_mask_get_size(ScrArea *area, int *r_width, int *r_height)
713{
714 if (area && area->spacedata.first_) {
715 switch (area->spacetype) {
716 case SPACE_CLIP: {
717 SpaceClip *sc = area->spacedata.first_as<SpaceClip>();
718 ED_space_clip_get_size(sc, r_width, r_height);
719 break;
720 }
721 case SPACE_SEQ: {
722 // Scene *scene = CTX_data_scene(C);
723 // BKE_render_resolution(&scene->r, false, r_width, r_height);
724 break;
725 }
726 case SPACE_IMAGE: {
727 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
728 ED_space_image_get_size(sima, r_width, r_height);
729 break;
730 }
731 default:
732 /* possible other spaces from which mask editing is available */
733 BLI_assert(0);
734 *r_width = 0;
735 *r_height = 0;
736 break;
737 }
738 }
739 else {
740 BLI_assert(0);
741 *r_width = 0;
742 *r_height = 0;
743 }
744}
745
746void ED_mask_zoom(ScrArea *area, ARegion *region, float *r_zoomx, float *r_zoomy)
747{
748 if (area && area->spacedata.first_) {
749 switch (area->spacetype) {
750 case SPACE_CLIP: {
751 SpaceClip *sc = area->spacedata.first_as<SpaceClip>();
752 ED_space_clip_get_zoom(sc, region, r_zoomx, r_zoomy);
753 break;
754 }
755 case SPACE_SEQ: {
756 *r_zoomx = *r_zoomy = 1.0f;
757 break;
758 }
759 case SPACE_IMAGE: {
760 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
761 ED_space_image_get_zoom(sima, region, r_zoomx, r_zoomy);
762 break;
763 }
764 default:
765 /* possible other spaces from which mask editing is available */
766 BLI_assert(0);
767 *r_zoomx = *r_zoomy = 1.0f;
768 break;
769 }
770 }
771 else {
772 BLI_assert(0);
773 *r_zoomx = *r_zoomy = 1.0f;
774 }
775}
776
777void ED_mask_get_aspect(ScrArea *area, ARegion * /*region*/, float *r_aspx, float *r_aspy)
778{
779 if (area && area->spacedata.first_) {
780 switch (area->spacetype) {
781 case SPACE_CLIP: {
782 SpaceClip *sc = area->spacedata.first_as<SpaceClip>();
783 ED_space_clip_get_aspect(sc, r_aspx, r_aspy);
784 break;
785 }
786 case SPACE_SEQ: {
787 *r_aspx = *r_aspy = 1.0f; /* MASKTODO - render aspect? */
788 break;
789 }
790 case SPACE_IMAGE: {
791 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
792 ED_space_image_get_aspect(sima, r_aspx, r_aspy);
793 break;
794 }
795 default:
796 /* possible other spaces from which mask editing is available */
797 BLI_assert(0);
798 *r_aspx = *r_aspy = 1.0f;
799 break;
800 }
801 }
802 else {
803 BLI_assert(0);
804 *r_aspx = *r_aspy = 1.0f;
805 }
806}
807
808void ED_mask_pixelspace_factor(ScrArea *area, ARegion *region, float *r_scalex, float *r_scaley)
809{
810 if (area && area->spacedata.first_) {
811 switch (area->spacetype) {
812 case SPACE_CLIP: {
813 SpaceClip *sc = area->spacedata.first_as<SpaceClip>();
814 float aspx, aspy;
815
816 ui::view2d_scale_get(&region->v2d, r_scalex, r_scaley);
817 ED_space_clip_get_aspect(sc, &aspx, &aspy);
818
819 *r_scalex *= aspx;
820 *r_scaley *= aspy;
821 break;
822 }
823 case SPACE_SEQ: {
824 *r_scalex = *r_scaley = 1.0f; /* MASKTODO? */
825 break;
826 }
827 case SPACE_IMAGE: {
828 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
829 float aspx, aspy;
830
831 ui::view2d_scale_get(&region->v2d, r_scalex, r_scaley);
832 ED_space_image_get_aspect(sima, &aspx, &aspy);
833
834 *r_scalex *= aspx;
835 *r_scaley *= aspy;
836 break;
837 }
838 default:
839 /* possible other spaces from which mask editing is available */
840 BLI_assert(0);
841 *r_scalex = *r_scaley = 1.0f;
842 break;
843 }
844 }
845 else {
846 BLI_assert(0);
847 *r_scalex = *r_scaley = 1.0f;
848 }
849}
850
851void ED_mask_cursor_location_get(ScrArea *area, float cursor[2])
852{
853 if (area) {
854 switch (area->spacetype) {
855 case SPACE_CLIP: {
856 SpaceClip *space_clip = area->spacedata.first_as<SpaceClip>();
857 copy_v2_v2(cursor, space_clip->cursor);
858 break;
859 }
860 case SPACE_SEQ: {
861 zero_v2(cursor);
862 break;
863 }
864 case SPACE_IMAGE: {
865 SpaceImage *space_image = area->spacedata.first_as<SpaceImage>();
866 copy_v2_v2(cursor, space_image->cursor);
867 break;
868 }
869 default:
870 /* possible other spaces from which mask editing is available */
871 BLI_assert(0);
872 zero_v2(cursor);
873 break;
874 }
875 }
876 else {
877 BLI_assert(0);
878 zero_v2(cursor);
879 }
880}
881
883
884} // namespace blender
#define SELECT
Definition BKE_mask.hh:19
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define INIT_MINMAX2(min, max)
btScalar max
#define FLT_MAX
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
void view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1893
BMesh Iterators.
eMaskWhichHandle
Definition BKE_mask.hh:44
@ MASK_WHICH_HANDLE_LEFT
Definition BKE_mask.hh:47
@ MASK_WHICH_HANDLE_RIGHT
Definition BKE_mask.hh:48
@ MASK_WHICH_HANDLE_STICK
Definition BKE_mask.hh:46
@ MASK_WHICH_HANDLE_NONE
Definition BKE_mask.hh:45
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void ED_space_clip_get_size(const SpaceClip *sc, int *r_width, int *r_height)
ScrArea * CTX_wm_area(const bContext *C)
unsigned int uint
Definition BKE_text.h:55
void ED_space_image_get_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
void BKE_mask_point_handle(const MaskSplinePoint *point, eMaskWhichHandle which_handle, float r_handle[2])
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
MINLINE void copy_v2_v2(float r[2], const float a[2])
@ MASK_PROJ_ANY
Definition BKE_mask.hh:120
void ED_space_image_get_size(SpaceImage *sima, int *r_width, int *r_height)
void ED_clip_point_stable_pos__reverse(const SpaceClip *sc, const ARegion *region, const float co[2], float r_co[2])
the reverse of ED_clip_point_stable_pos(), gets the marker region coords. better name here?...
MaskSplinePoint * ED_mask_point_find_nearest(const bContext *C, Mask *mask_orig, const float normal_co[2], float threshold, MaskLayer **r_mask_layer, MaskSpline **r_spline, eMaskWhichHandle *r_which_handle, float *r_score)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
void ED_clip_point_stable_pos(const SpaceClip *sc, const ARegion *region, float x, float y, float *xr, float *yr)
void ED_mask_zoom(ScrArea *area, ARegion *region, float *r_zoomx, float *r_zoomy)
void ED_mask_cursor_location_get(ScrArea *area, float cursor[2])
void ED_mask_point_pos__reverse(ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
void ED_space_clip_get_aspect(const SpaceClip *sc, float *r_aspx, float *r_aspy)
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:307
static void mask_point_scaled_handle(const MaskSplinePoint *point, const eMaskWhichHandle which_handle, const float scalex, const float scaley, float handle[2])
void ED_image_point_pos(SpaceImage *sima, const ARegion *region, float x, float y, float *r_x, float *r_y)
void ED_mask_pixelspace_factor(ScrArea *area, ARegion *region, float *r_scalex, float *r_scaley)
void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
void BKE_mask_coord_from_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2])
bool BKE_mask_point_selected(const MaskSplinePoint *p)
Definition BKE_mask.hh:155
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
void ED_image_mouse_pos(SpaceImage *sima, const ARegion *region, const int mval[2], float co[2])
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void BKE_mask_coord_from_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2])
float(* BKE_mask_spline_feather_points(MaskSpline *spline, int *tot_feather_point))[2]
void ED_mask_get_size(ScrArea *area, int *r_width, int *r_height)
Mask * CTX_data_edit_mask(const bContext *C)
float * BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, int width, int height, unsigned int *r_tot_feather_point)
void ED_mask_center_from_pivot_ex(const bContext *C, ScrArea *area, char mode, bool handles_as_knot_selected_only, float r_center[2], bool *r_has_select)
void ED_clip_mouse_pos(const SpaceClip *sc, const ARegion *region, const int mval[2], float r_co[2])
static void handle_position_for_minmax(const MaskSplinePoint *point, eMaskWhichHandle which_handle, bool handles_as_knot, float r_handle[2])
void ED_mask_point_pos(ScrArea *area, ARegion *region, float x, float y, float *r_x, float *r_y)
void ED_mask_get_aspect(ScrArea *area, ARegion *region, float *r_aspx, float *r_aspy)
void mid_v2_v2v2(float r[2], const float a[2], const float b[2])
void ED_space_image_get_zoom(SpaceImage *sima, const ARegion *region, float *r_zoomx, float *r_zoomy)
void BKE_mask_coord_to_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2])
bool ED_mask_selected_minmax(const bContext *C, float min[2], float max[2], bool handles_as_knot, bool handles_as_knot_selected_only)
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void ED_mask_mouse_pos(ScrArea *area, ARegion *region, const int mval[2], float r_co[2])
void ED_image_point_pos__reverse(SpaceImage *sima, const ARegion *region, const float co[2], float r_co[2])
MaskSplinePoint * BKE_mask_spline_point_array(MaskSpline *spline)
eMaskhandleMode BKE_mask_point_handles_mode_get(const MaskSplinePoint *point)
MINLINE void zero_v2(float r[2])
ARegion * CTX_wm_region(const bContext *C)
void ED_space_clip_get_zoom(const SpaceClip *sc, const ARegion *region, float *r_zoomx, float *r_zoomy)
float * BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, int width, int height, unsigned int *r_tot_diff_point)
@ MASK_HANDLE_MODE_STICK
Definition BKE_mask.hh:53
float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, float start_u, const float co[2], eMaskSign sign)
bool ED_mask_find_nearest_diff_point(const bContext *C, Mask *mask_orig, const float normal_co[2], int threshold, bool feather, float tangent[2], bool use_deform, bool use_project, MaskLayer **r_mask_layer, MaskSpline **r_spline, MaskSplinePoint **r_point, float *r_u, float *r_score)
Definition mask_query.cc:37
bool ED_mask_feather_find_nearest(const bContext *C, Mask *mask_orig, const float normal_co[2], float threshold, MaskLayer **r_mask_layer, MaskSpline **r_spline, MaskSplinePoint **r_point, MaskSplinePointUW **r_uw, float *r_score)
#define sqrtf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
eBezTriple_Flag f2
eBezTriple_Handle h2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Handle h1
MaskLayerVisibility visibility_flag
ListBaseT< MaskSpline > splines
MaskSplinePointUW * uw
MaskSplinePoint * points
struct MaskSpline * next
ListBaseT< struct MaskLayer > masklayers
ListBaseT< SpaceLink > spacedata
struct MovieClip * clip
struct MovieClipUser user
struct ImageUser iuser