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