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