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