2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* The Original Code is Copyright (C) 2011 Blender Foundation.
19
* All rights reserved.
22
* Contributor(s): Blender Foundation,
25
* ***** END GPL LICENSE BLOCK *****
28
/** \file blender/editors/space_clip/clip_draw.c
32
#include "DNA_gpencil_types.h"
33
#include "DNA_movieclip_types.h"
34
#include "DNA_scene_types.h"
35
#include "DNA_object_types.h" /* SELECT */
37
#include "MEM_guardedalloc.h"
39
#include "BKE_context.h"
40
#include "BKE_movieclip.h"
41
#include "BKE_tracking.h"
43
#include "IMB_imbuf_types.h"
44
#include "IMB_imbuf.h"
46
#include "BLI_utildefines.h"
48
#include "BLI_string.h"
50
#include "BLI_math_base.h"
52
#include "ED_screen.h"
54
#include "ED_gpencil.h"
57
#include "BIF_glutil.h"
62
#include "UI_interface.h"
63
#include "UI_resources.h"
64
#include "UI_view2d.h"
66
#include "RNA_access.h"
70
#include "clip_intern.h" // own include
72
/*********************** main area drawing *************************/
74
void clip_draw_curfra_label(SpaceClip *sc, float x, float y)
76
uiStyle *style = UI_GetStyle();
77
int fontid = style->widget.uifont_id;
79
float font_dims[2] = {0.0f, 0.0f};
82
BLF_size(fontid, 11.0f, U.dpi);
83
BLI_snprintf(numstr, sizeof(numstr), "%d", sc->user.framenr);
85
BLF_width_and_height(fontid, numstr, &font_dims[0], &font_dims[1]);
87
glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
89
UI_ThemeColor(TH_TEXT);
90
BLF_position(fontid, x+2.0f, y+2.0f, 0.0f);
91
BLF_draw(fontid, numstr, sizeof(numstr));
94
static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Scene *scene)
97
int *points, totseg, i, a;
98
float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
99
MovieTrackingTrack *act_track = BKE_tracking_active_track(&clip->tracking);
100
MovieTrackingReconstruction *reconstruction = BKE_tracking_get_reconstruction(&clip->tracking);
104
/* cache background */
105
glColor4ub(128, 128, 255, 64);
106
glRecti(0, 0, ar->winx, 8);
108
/* cached segments -- could be usefu lto debug caching strategies */
109
BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points);
111
glColor4ub(128, 128, 255, 128);
113
for (a = 0; a < totseg; a++) {
116
x1 = (points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
117
x2 = (points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
119
glRecti(x1, 0, x2, 8);
125
MovieTrackingTrack *track = act_track;
127
for (i = sfra, a = 0; i <= efra; i++) {
129
MovieTrackingMarker *marker;
131
while (a<track->markersnr) {
132
if (track->markers[a].framenr >= i)
135
if (a < track->markersnr - 1 && track->markers[a + 1].framenr > i)
141
if (a < track->markersnr)
142
marker = &track->markers[a];
144
marker = &track->markers[track->markersnr - 1];
146
if ((marker->flag & MARKER_DISABLED) == 0) {
147
framenr = marker->framenr;
150
glColor4ub(128, 128, 0, 96);
151
else if ((marker->flag & MARKER_TRACKED) == 0)
152
glColor4ub(255, 255, 0, 196);
154
glColor4ub(255, 255, 0, 96);
156
glRecti((i - sfra) * framelen, 0, (i - sfra + 1)*framelen, 4);
162
if (reconstruction->flag & TRACKING_RECONSTRUCTED) {
163
int n = reconstruction->camnr;
164
MovieReconstructedCamera *cameras = reconstruction->cameras;
166
glColor4ub(255, 0, 0, 96);
168
for (i = sfra, a = 0; i <= efra; i++) {
172
if (cameras[a].framenr == i) {
176
else if (cameras[a].framenr > i) {
184
glRecti((i - sfra) * framelen, 0, (i - sfra + 1) * framelen, 8);
191
x = (sc->user.framenr - sfra) / (efra - sfra + 1) * ar->winx;
193
UI_ThemeColor(TH_CFRAME);
194
glRecti(x, 0, x+framelen, 8);
196
clip_draw_curfra_label(sc, x, 8.0f);
199
static void draw_movieclip_notes(SpaceClip *sc, ARegion *ar)
201
MovieClip *clip = ED_space_clip(sc);
202
MovieTracking *tracking = &clip->tracking;
206
if (tracking->stats) {
207
BLI_strncpy(str, tracking->stats->message, sizeof(str));
211
if (sc->flag & SC_LOCK_SELECTION)
212
strcpy(str, "Locked");
216
ED_region_info_draw(ar, str, block, 0.6f);
219
static void verify_buffer_float(ImBuf *ibuf)
221
if (ibuf->rect_float && (ibuf->rect == NULL || (ibuf->userflags & IB_RECT_INVALID))) {
222
IMB_rect_from_float(ibuf);
226
static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
227
int width, int height, float zoomx, float zoomy)
230
MovieClip *clip = ED_space_clip(sc);
233
glPixelZoom(zoomx*width/ibuf->x, zoomy*height/ibuf->y);
235
/* find window pixel coordinates of origin */
236
UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y);
238
if (sc->flag & SC_MUTE_FOOTAGE) {
239
glColor3f(0.0f, 0.0f, 0.0f);
240
glRectf(x, y, x + zoomx * width, y + zoomy * height);
243
verify_buffer_float(ibuf);
246
glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
249
/* draw boundary border for frame if stabilization is enabled */
250
if (sc->flag & SC_SHOW_STABLE && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
251
glColor3f(0.0f, 0.0f, 0.0f);
252
glLineStipple(3, 0xaaaa);
253
glEnable(GL_LINE_STIPPLE);
254
glEnable(GL_COLOR_LOGIC_OP);
258
glTranslatef(x, y, 0);
260
glScalef(zoomx, zoomy, 0);
261
glMultMatrixf(sc->stabmat);
263
glBegin(GL_LINE_LOOP);
264
glVertex2f(0.0f, 0.0f);
265
glVertex2f(width, 0.0f);
266
glVertex2f(width, height);
267
glVertex2f(0.0f, height);
272
glDisable(GL_COLOR_LOGIC_OP);
273
glDisable(GL_LINE_STIPPLE);
278
glPixelZoom(1.0f, 1.0f);
281
static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackingTrack *track)
283
int count = sc->path_length;
284
int i, a, b, curindex = -1;
286
int tiny = sc->flag&SC_SHOW_TINY_MARKER, framenr;
287
MovieTrackingMarker *marker;
292
marker = BKE_tracking_get_marker(track, sc->user.framenr);
293
if (marker->framenr != sc->user.framenr || marker->flag & MARKER_DISABLED)
296
framenr = marker->framenr;
300
while (i >= framenr - count) {
301
marker = BKE_tracking_get_marker(track, i);
303
if (!marker || marker->flag & MARKER_DISABLED)
306
if (marker->framenr == i) {
307
add_v2_v2v2(path[--a], marker->pos, track->offset);
308
ED_clip_point_undistorted_pos(sc, path[a], path[a]);
310
if (marker->framenr == sc->user.framenr)
322
while (i <= framenr+count) {
323
marker = BKE_tracking_get_marker(track, i);
325
if (!marker || marker->flag & MARKER_DISABLED)
328
if (marker->framenr == i) {
329
if (marker->framenr == sc->user.framenr)
332
add_v2_v2v2(path[b++], marker->pos, track->offset);
333
ED_clip_point_undistorted_pos(sc, path[b-1], path[b-1]);
342
UI_ThemeColor(TH_MARKER_OUTLINE);
344
if (TRACK_VIEW_SELECTED(sc, track)) {
347
for (i = a; i < b; i++) {
349
glVertex2f(path[i][0], path[i][1]);
355
glBegin(GL_LINE_STRIP);
356
for (i = a; i < b; i++)
357
glVertex2f(path[i][0], path[i][1]);
362
UI_ThemeColor(TH_PATH_BEFORE);
364
if (TRACK_VIEW_SELECTED(sc, track)) {
367
for (i = a; i < b; i++) {
369
UI_ThemeColor(TH_PATH_AFTER);
372
glVertex2f(path[i][0], path[i][1]);
377
UI_ThemeColor(TH_PATH_BEFORE);
379
glBegin(GL_LINE_STRIP);
380
for (i = a; i < b; i++) {
382
UI_ThemeColor(TH_PATH_AFTER);
384
glVertex2f(path[i][0], path[i][1]);
390
static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, float marker_pos[2], int width, int height)
392
int tiny = sc->flag&SC_SHOW_TINY_MARKER;
393
int show_search = FALSE;
396
UI_ThemeColor(TH_MARKER_OUTLINE);
398
px[0] = 1.0f / width / sc->zoom;
399
px[1] = 1.0f / height / sc->zoom;
401
if ((marker->flag & MARKER_DISABLED) == 0) {
405
BLI_init_rctf(&r, track->pat_min[0], track->pat_max[0], track->pat_min[1], track->pat_max[1]);
406
add_v2_v2v2(pos, marker->pos, track->offset);
408
ED_clip_point_undistorted_pos(sc, pos, pos);
410
if (BLI_in_rctf(&r, pos[0]-marker_pos[0], pos[1]-marker_pos[1])) {
411
if (tiny) glPointSize(3.0f);
412
else glPointSize(4.0f);
414
glVertex2f(pos[0], pos[1]);
419
if (!tiny) glLineWidth(3.0f);
421
glVertex2f(pos[0] + px[0]*2, pos[1]);
422
glVertex2f(pos[0] + px[0]*8, pos[1]);
424
glVertex2f(pos[0] - px[0]*2, pos[1]);
425
glVertex2f(pos[0] - px[0]*8, pos[1]);
427
glVertex2f(pos[0], pos[1] - px[1]*2);
428
glVertex2f(pos[0], pos[1] - px[1]*8);
430
glVertex2f(pos[0], pos[1] + px[1]*2);
431
glVertex2f(pos[0], pos[1] + px[1]*8);
433
if (!tiny) glLineWidth(1.0f);
437
/* pattern and search outline */
439
glTranslatef(marker_pos[0], marker_pos[1], 0);
444
if (sc->flag & SC_SHOW_MARKER_PATTERN) {
445
glBegin(GL_LINE_LOOP);
446
glVertex2f(track->pat_min[0], track->pat_min[1]);
447
glVertex2f(track->pat_max[0], track->pat_min[1]);
448
glVertex2f(track->pat_max[0], track->pat_max[1]);
449
glVertex2f(track->pat_min[0], track->pat_max[1]);
453
show_search = TRACK_VIEW_SELECTED(sc, track) &&
454
((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0);
455
if (sc->flag & SC_SHOW_MARKER_SEARCH && show_search) {
456
glBegin(GL_LINE_LOOP);
457
glVertex2f(track->search_min[0], track->search_min[1]);
458
glVertex2f(track->search_max[0], track->search_min[1]);
459
glVertex2f(track->search_max[0], track->search_max[1]);
460
glVertex2f(track->search_min[0], track->search_max[1]);
469
static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3])
471
if (track->flag & TRACK_CUSTOMCOLOR) {
473
UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
475
copy_v3_v3(scol, track->color);
477
mul_v3_v3fl(col, track->color, 0.5f);
480
UI_GetThemeColor3fv(TH_MARKER, col);
483
UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
485
UI_GetThemeColor3fv(TH_SEL_MARKER, scol);
489
static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, float marker_pos[2], int width, int height, int act, int sel)
491
int tiny= sc->flag&SC_SHOW_TINY_MARKER;
493
float col[3], scol[3], px[2];
495
track_colors(track, act, col, scol);
497
px[0]= 1.0f / width / sc->zoom;
498
px[1]= 1.0f / height / sc->zoom;
500
/* marker position and offset position */
501
if ((track->flag&SELECT) == sel && (marker->flag & MARKER_DISABLED) == 0) {
505
if (track->flag & TRACK_LOCKED) {
507
UI_ThemeColor(TH_ACT_MARKER);
508
else if (track->flag & SELECT)
509
UI_ThemeColorShade(TH_LOCK_MARKER, 64);
511
UI_ThemeColor(TH_LOCK_MARKER);
514
if (track->flag & SELECT)
520
BLI_init_rctf(&r, track->pat_min[0], track->pat_max[0], track->pat_min[1], track->pat_max[1]);
521
add_v2_v2v2(pos, marker->pos, track->offset);
522
ED_clip_point_undistorted_pos(sc, pos, pos);
524
if (BLI_in_rctf(&r, pos[0]-marker_pos[0], pos[1]-marker_pos[1])) {
529
glVertex2f(pos[0], pos[1]);
537
glVertex2f(pos[0] + px[0]*3, pos[1]);
538
glVertex2f(pos[0] + px[0]*7, pos[1]);
540
glVertex2f(pos[0] - px[0]*3, pos[1]);
541
glVertex2f(pos[0] - px[0]*7, pos[1]);
543
glVertex2f(pos[0], pos[1] - px[1]*3);
544
glVertex2f(pos[0], pos[1] - px[1]*7);
546
glVertex2f(pos[0], pos[1] + px[1]*3);
547
glVertex2f(pos[0], pos[1] + px[1]*7);
550
glColor3f(0.0f, 0.0f, 0.0f);
551
glLineStipple(3, 0xaaaa);
552
glEnable(GL_LINE_STIPPLE);
553
glEnable(GL_COLOR_LOGIC_OP);
558
glVertex2fv(marker_pos);
561
glDisable(GL_COLOR_LOGIC_OP);
562
glDisable(GL_LINE_STIPPLE);
568
glTranslatef(marker_pos[0], marker_pos[1], 0);
571
glLineStipple(3, 0xaaaa);
572
glEnable(GL_LINE_STIPPLE);
575
if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) {
576
if (track->flag & TRACK_LOCKED) {
578
UI_ThemeColor(TH_ACT_MARKER);
579
else if (track->pat_flag & SELECT)
580
UI_ThemeColorShade(TH_LOCK_MARKER, 64);
581
else UI_ThemeColor(TH_LOCK_MARKER);
583
else if (marker->flag & MARKER_DISABLED) {
585
UI_ThemeColor(TH_ACT_MARKER);
586
else if (track->pat_flag & SELECT)
587
UI_ThemeColorShade(TH_DIS_MARKER, 128);
588
else UI_ThemeColor(TH_DIS_MARKER);
591
if (track->pat_flag & SELECT)
593
else glColor3fv(col);
596
glBegin(GL_LINE_LOOP);
597
glVertex2f(track->pat_min[0], track->pat_min[1]);
598
glVertex2f(track->pat_max[0], track->pat_min[1]);
599
glVertex2f(track->pat_max[0], track->pat_max[1]);
600
glVertex2f(track->pat_min[0], track->pat_max[1]);
605
show_search = TRACK_VIEW_SELECTED(sc, track) &&
606
((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0);
607
if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) {
608
if (track->flag & TRACK_LOCKED) {
610
UI_ThemeColor(TH_ACT_MARKER);
611
else if (track->search_flag & SELECT)
612
UI_ThemeColorShade(TH_LOCK_MARKER, 64);
613
else UI_ThemeColor(TH_LOCK_MARKER);
615
else if (marker->flag & MARKER_DISABLED) {
617
UI_ThemeColor(TH_ACT_MARKER);
618
else if (track->search_flag & SELECT)
619
UI_ThemeColorShade(TH_DIS_MARKER, 128);
620
else UI_ThemeColor(TH_DIS_MARKER);
623
if (track->search_flag & SELECT)
629
glBegin(GL_LINE_LOOP);
630
glVertex2f(track->search_min[0], track->search_min[1]);
631
glVertex2f(track->search_max[0], track->search_min[1]);
632
glVertex2f(track->search_max[0], track->search_max[1]);
633
glVertex2f(track->search_min[0], track->search_max[1]);
638
if (sel && TRACK_VIEW_SELECTED(sc, track) &&
639
(track->tracker == TRACKER_KLT) &&
640
(marker->flag & MARKER_DISABLED) == 0)
642
if (track->flag & TRACK_LOCKED) {
644
UI_ThemeColor(TH_ACT_MARKER);
645
else if (track->pat_flag & SELECT)
646
UI_ThemeColorShade(TH_LOCK_MARKER, 64);
647
else UI_ThemeColor(TH_LOCK_MARKER);
649
else if (marker->flag & MARKER_DISABLED) {
651
UI_ThemeColor(TH_ACT_MARKER);
652
else if (track->pat_flag & SELECT)
653
UI_ThemeColorShade(TH_DIS_MARKER, 128);
654
else UI_ThemeColor(TH_DIS_MARKER);
657
if (track->pat_flag & SELECT)
666
glEnable(GL_LINE_STIPPLE);
667
for (i = 1; i < track->pyramid_levels; ++i) {
668
glScalef(2.0f, 2.0f, 1.0);
670
/* only draw a pattern for the coarsest level */
671
glBegin(GL_LINE_LOOP);
672
glVertex2f(track->pat_min[0], track->pat_min[1]);
673
glVertex2f(track->pat_max[0], track->pat_min[1]);
674
glVertex2f(track->pat_max[0], track->pat_max[1]);
675
glVertex2f(track->pat_min[0], track->pat_max[1]);
677
glDisable(GL_LINE_STIPPLE);
683
glDisable(GL_LINE_STIPPLE);
688
static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
689
float marker_pos[2], int outline, int sel, int act, int width, int height)
691
float x, y, dx, dy, patdx, patdy, searchdx, searchdy, tdx, tdy;
692
int tiny = sc->flag&SC_SHOW_TINY_MARKER;
693
float col[3], scol[3], px[2];
695
if ((tiny && outline) || (marker->flag & MARKER_DISABLED))
698
if (!TRACK_VIEW_SELECTED(sc, track) || track->flag & TRACK_LOCKED)
701
track_colors(track, act, col, scol);
705
UI_ThemeColor(TH_MARKER_OUTLINE);
709
glTranslatef(marker_pos[0], marker_pos[1], 0);
711
dx = 6.0f / width / sc->zoom;
712
dy = 6.0f / height / sc->zoom;
714
patdx = MIN2(dx * 2.0f / 3.0f, (track->pat_max[0] - track->pat_min[0]) / 6.0f);
715
patdy = MIN2(dy * 2.0f / 3.0f, (track->pat_max[1] - track->pat_min[1]) / 6.0f);
717
searchdx = MIN2(dx, (track->search_max[0] - track->search_min[0]) / 6.0f);
718
searchdy = MIN2(dy, (track->search_max[1] - track->search_min[1]) / 6.0f);
720
px[0] = 1.0f / sc->zoom / width / sc->scale;
721
px[1] = 1.0f / sc->zoom / height / sc->scale;
723
if ((sc->flag & SC_SHOW_MARKER_SEARCH) && ((track->search_flag & SELECT) == sel || outline)) {
725
if (track->search_flag & SELECT)
731
/* search offset square */
732
x = track->search_min[0];
733
y = track->search_max[1];
744
glVertex3f(x-tdx, y+tdy, 0);
745
glVertex3f(x+tdx, y+tdy, 0);
746
glVertex3f(x+tdx, y-tdy, 0);
747
glVertex3f(x-tdx, y-tdy, 0);
750
/* search re-sizing triangle */
751
x = track->search_max[0];
752
y = track->search_min[1];
762
glBegin(GL_TRIANGLES);
764
glVertex3f(x-tdx, y, 0);
765
glVertex3f(x, y+tdy, 0);
769
if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT)==sel || outline)) {
771
if (track->pat_flag & SELECT)
777
/* pattern offset square */
778
x = track->pat_min[0];
779
y = track->pat_max[1];
790
glVertex3f(x-tdx, y+tdy, 0);
791
glVertex3f(x+tdx, y+tdy, 0);
792
glVertex3f(x+tdx, y-tdy, 0);
793
glVertex3f(x-tdx, y-tdy, 0);
796
/* pattern re-sizing triangle */
797
x = track->pat_max[0];
798
y = track->pat_min[1];
808
glBegin(GL_TRIANGLES);
810
glVertex3f(x-tdx, y, 0);
811
glVertex3f(x, y+tdy, 0);
821
static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, float marker_pos[2], int act,
822
int width, int height, float zoomx, float zoomy)
824
char str[128] = {0}, state[64] = {0};
825
float dx= 0.0f, dy = 0.0f, fontsize, pos[3];
826
uiStyle *style = U.uistyles.first;
827
int fontid = style->widget.uifont_id;
829
if (!TRACK_VIEW_SELECTED(sc, track))
832
BLF_size(fontid, 11.0f, U.dpi);
833
fontsize = BLF_height_max(fontid);
835
if (marker->flag & MARKER_DISABLED) {
837
UI_ThemeColor(TH_ACT_MARKER);
839
UI_ThemeColorShade(TH_DIS_MARKER, 128);
843
UI_ThemeColor(TH_ACT_MARKER);
845
UI_ThemeColor(TH_SEL_MARKER);
848
if ((sc->flag & SC_SHOW_MARKER_SEARCH) &&
849
((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0))
851
dx = track->search_min[0];
852
dy = track->search_min[1];
854
else if (sc->flag & SC_SHOW_MARKER_PATTERN) {
855
dx = track->pat_min[0];
856
dy = track->pat_min[1];
859
pos[0] = (marker_pos[0] + dx) * width;
860
pos[1] = (marker_pos[1] + dy) * height;
863
mul_m4_v3(sc->stabmat, pos);
865
pos[0] = pos[0]*zoomx;
866
pos[1] = pos[1]*zoomy - fontsize;
868
if (marker->flag & MARKER_DISABLED)
869
strcpy(state, "disabled");
870
else if (marker->framenr != sc->user.framenr)
871
strcpy(state, "estimated");
872
else if (marker->flag & MARKER_TRACKED)
873
strcpy(state, "tracked");
875
strcpy(state, "keyframed");
878
BLI_snprintf(str, sizeof(str), "%s: %s", track->name, state);
880
BLI_snprintf(str, sizeof(str), "%s", track->name);
882
BLF_position(fontid, pos[0], pos[1], 0.0f);
883
BLF_draw(fontid, str, sizeof(str));
886
if (track->flag & TRACK_HAS_BUNDLE) {
887
BLI_snprintf(str, sizeof(str), "Average error: %.3f", track->error);
888
BLF_position(fontid, pos[0], pos[1], 0.0f);
889
BLF_draw(fontid, str, sizeof(str));
893
if (track->flag & TRACK_LOCKED) {
894
BLF_position(fontid, pos[0], pos[1], 0.0f);
895
BLF_draw(fontid, "locked", 6);
899
static void view2d_to_region_float(View2D *v2d, float x, float y, float *regionx, float *regiony)
901
/* express given coordinates as proportional values */
902
x = -v2d->cur.xmin / (v2d->cur.xmax - v2d->cur.xmin);
903
y = -v2d->cur.ymin / (v2d->cur.ymax - v2d->cur.ymin);
905
/* convert proportional distances to screen coordinates */
906
*regionx = v2d->mask.xmin + x*(v2d->mask.xmax - v2d->mask.xmin);
907
*regiony = v2d->mask.ymin + y*(v2d->mask.ymax - v2d->mask.ymin);
910
static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
911
int width, int height, float zoomx, float zoomy)
914
MovieTracking *tracking = &clip->tracking;
915
ListBase *tracksbase = BKE_tracking_get_tracks(tracking);
916
MovieTrackingTrack *track, *act_track;
917
MovieTrackingMarker *marker;
918
int framenr = sc->user.framenr;
919
int undistort = sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
920
float *marker_pos = NULL, *fp, *active_pos = NULL, cur_pos[2];
922
/* ** find window pixel coordinates of origin ** */
924
/* UI_view2d_to_region_no_clip return integer values, this could
925
* lead to 1px flickering when view is locked to selection during playbeck.
926
* to avoid this flickering, calculate base point in the same way as it happens
927
* in UI_view2d_to_region_no_clip, but do it in floats here */
929
view2d_to_region_float(&ar->v2d, 0.0f, 0.0f, &x, &y);
932
glTranslatef(x, y, 0);
935
glScalef(zoomx, zoomy, 0);
936
glMultMatrixf(sc->stabmat);
937
glScalef(width, height, 0);
939
act_track = BKE_tracking_active_track(tracking);
941
if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
945
track = tracksbase->first;
947
if ((track->flag & TRACK_HIDDEN)==0) {
948
marker = BKE_tracking_get_marker(track, framenr);
950
if (MARKER_VISIBLE(sc, marker))
959
marker_pos = MEM_callocN(2*sizeof(float)*count, "draw_tracking_tracks marker_pos");
961
track = tracksbase->first;
964
if ((track->flag & TRACK_HIDDEN)==0) {
965
marker = BKE_tracking_get_marker(track, framenr);
967
if (MARKER_VISIBLE(sc, marker)) {
968
ED_clip_point_undistorted_pos(sc, marker->pos, fp);
970
if (track == act_track)
982
if (sc->flag & SC_SHOW_TRACK_PATH) {
983
track = tracksbase->first;
985
if ((track->flag & TRACK_HIDDEN)==0)
986
draw_track_path(sc, clip, track);
992
/* markers outline and non-selected areas */
993
track = tracksbase->first;
996
if ((track->flag & TRACK_HIDDEN)==0) {
997
marker = BKE_tracking_get_marker(track, framenr);
999
if (MARKER_VISIBLE(sc, marker)) {
1000
copy_v2_v2(cur_pos, fp ? fp : marker->pos);
1002
draw_marker_outline(sc, track, marker, cur_pos, width, height);
1003
draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 0);
1004
draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height);
1005
draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height);
1012
track = track->next;
1015
/* selected areas only, so selection wouldn't be overlapped by
1016
* non-selected areas */
1017
track = tracksbase->first;
1020
if ((track->flag & TRACK_HIDDEN)==0) {
1021
int act = track == act_track;
1022
marker = BKE_tracking_get_marker(track, framenr);
1024
if (MARKER_VISIBLE(sc, marker)) {
1026
copy_v2_v2(cur_pos, fp ? fp : marker->pos);
1028
draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1);
1029
draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height);
1037
track = track->next;
1040
/* active marker would be displayed on top of everything else */
1042
if ((act_track->flag & TRACK_HIDDEN)==0) {
1043
marker = BKE_tracking_get_marker(act_track, framenr);
1045
if (MARKER_VISIBLE(sc, marker)) {
1046
copy_v2_v2(cur_pos, active_pos ? active_pos : marker->pos);
1048
draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1);
1049
draw_marker_slide_zones(sc, act_track, marker, cur_pos, 0, 1, 1, width, height);
1054
if (sc->flag & SC_SHOW_BUNDLES) {
1055
MovieTrackingObject *object = BKE_tracking_active_object(tracking);
1056
float pos[4], vec[4], mat[4][4], aspy;
1058
glEnable(GL_POINT_SMOOTH);
1061
aspy = 1.0f / clip->tracking.camera.pixel_aspect;
1062
BKE_tracking_projection_matrix(tracking, object, framenr, width, height, mat);
1064
track = tracksbase->first;
1066
if ((track->flag & TRACK_HIDDEN) == 0 && track->flag & TRACK_HAS_BUNDLE) {
1067
marker= BKE_tracking_get_marker(track, framenr);
1069
if (MARKER_VISIBLE(sc, marker)) {
1071
copy_v4_v4(vec, track->bundle_pos);
1074
mul_v4_m4v4(pos, mat, vec);
1076
pos[0] = (pos[0] / (pos[3] * 2.0f) + 0.5f) * width;
1077
pos[1] = (pos[1] / (pos[3] * 2.0f) + 0.5f) * height * aspy;
1079
BKE_tracking_apply_intrinsics(tracking, pos, npos);
1081
if (npos[0] >= 0.0f && npos[1] >= 0.0f && npos[0] <= width && npos[1] <= height * aspy) {
1082
vec[0] = (marker->pos[0] + track->offset[0]) * width;
1083
vec[1] = (marker->pos[1] + track->offset[1]) * height * aspy;
1085
sub_v2_v2(vec, npos);
1087
if (len_v2(vec)< 3.0f)
1088
glColor3f(0.0f, 1.0f, 0.0f);
1090
glColor3f(1.0f, 0.0f, 0.0f);
1094
glVertex3f(pos[0] / width, pos[1] / (height * aspy), 0);
1096
glVertex3f(npos[0] / width, npos[1] / (height * aspy), 0);
1102
track = track->next;
1106
glDisable(GL_POINT_SMOOTH);
1111
if (sc->flag & SC_SHOW_NAMES) {
1112
/* scaling should be cleared before drawing texts, otherwise font would also be scaled */
1113
track = tracksbase->first;
1116
if ((track->flag & TRACK_HIDDEN) == 0) {
1117
marker = BKE_tracking_get_marker(track, framenr);
1119
if (MARKER_VISIBLE(sc, marker)) {
1120
int act = track == act_track;
1122
copy_v2_v2(cur_pos, fp ? fp : marker->pos);
1124
draw_marker_texts(sc, track, marker, cur_pos, act, width, height, zoomx, zoomy);
1131
track = track->next;
1138
MEM_freeN(marker_pos);
1141
static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int width, int height, float zoomx, float zoomy)
1146
float pos[2], tpos[2], grid[11][11][2];
1147
MovieTracking *tracking = &clip->tracking;
1148
float aspy = 1.0f / tracking->camera.pixel_aspect;
1149
float dx = (float)width / n, dy = (float)height / n * aspy;
1151
if (sc->mode != SC_MODE_DISTORTION)
1154
if (!tracking->camera.focal)
1157
if ((sc->flag & SC_SHOW_GRID) == 0 && (sc->flag & SC_MANUAL_CALIBRATION) == 0)
1160
view2d_to_region_float(&ar->v2d, 0.0f, 0.0f, &x, &y);
1163
glTranslatef(x, y, 0);
1164
glScalef(zoomx, zoomy, 0);
1165
glMultMatrixf(sc->stabmat);
1166
glScalef(width, height, 0);
1169
if (sc->flag & SC_SHOW_GRID) {
1170
float val[4][2], idx[4][2];
1171
float min[2], max[2];
1173
for (a = 0; a < 4; a++) {
1175
val[a][a%2] = FLT_MAX;
1177
val[a][a%2] = -FLT_MAX;
1181
for (i = 0; i <= n; i++) {
1182
for (j = 0; j <= n; j++) {
1183
if (i == 0 || j == 0 || i == n || j == n) {
1184
BKE_tracking_apply_intrinsics(tracking, pos, tpos);
1186
for (a = 0; a < 4; a++) {
1190
ok = tpos[a%2] < val[a][a%2];
1192
ok= tpos[a%2] > val[a][a%2];
1195
copy_v2_v2(val[a], tpos);
1209
INIT_MINMAX2(min, max);
1211
for (a = 0; a < 4; a++) {
1212
pos[0] = idx[a][0] * dx;
1213
pos[1] = idx[a][1] * dy;
1215
BKE_tracking_invert_intrinsics(tracking, pos, tpos);
1217
DO_MINMAX2(tpos, min, max);
1220
copy_v2_v2(pos, min);
1221
dx = (max[0] - min[0]) / n;
1222
dy = (max[1] - min[1]) / n;
1224
for (i = 0; i <= n; i++) {
1225
for (j = 0; j <= n; j++) {
1226
BKE_tracking_apply_intrinsics(tracking, pos, grid[i][j]);
1228
grid[i][j][0] /= width;
1229
grid[i][j][1] /= height*aspy;
1238
glColor3f(1.0f, 0.0f, 0.0f);
1240
for (i = 0; i <= n; i++) {
1241
glBegin(GL_LINE_STRIP);
1242
for (j = 0; j <= n; j++) {
1243
glVertex2fv(grid[i][j]);
1248
for (j = 0; j <= n; j++) {
1249
glBegin(GL_LINE_STRIP);
1250
for (i = 0; i <= n; i++) {
1251
glVertex2fv(grid[i][j]);
1257
if (sc->flag & SC_MANUAL_CALIBRATION && clip->gpd) {
1258
bGPDlayer *layer= clip->gpd->layers.first;
1261
bGPDframe *frame = layer->frames.first;
1263
if (layer->flag & GP_LAYER_HIDE) {
1264
layer = layer->next;
1268
glColor4fv(layer->color);
1269
glLineWidth(layer->thickness);
1270
glPointSize((float)(layer->thickness + 2));
1273
bGPDstroke *stroke = frame->strokes.first;
1276
if (stroke->flag & GP_STROKE_2DSPACE) {
1277
if (stroke->totpoints > 1) {
1278
glBegin(GL_LINE_STRIP);
1279
for (i = 0; i < stroke->totpoints - 1; i++) {
1280
float npos[2], dpos[2], len;
1283
pos[0] = stroke->points[i].x * width;
1284
pos[1] = stroke->points[i].y * height * aspy;
1286
npos[0] = stroke->points[i+1].x * width;
1287
npos[1] = stroke->points[i+1].y * height * aspy;
1289
len = len_v2v2(pos, npos);
1290
steps= ceil(len/5.0f);
1292
/* we want to distort only long straight lines */
1293
if (stroke->totpoints == 2) {
1294
BKE_tracking_invert_intrinsics(tracking, pos, pos);
1295
BKE_tracking_invert_intrinsics(tracking, npos, npos);
1298
sub_v2_v2v2(dpos, npos, pos);
1299
mul_v2_fl(dpos, 1.0f/steps);
1301
for (j = 0; j <= steps; j++) {
1302
BKE_tracking_apply_intrinsics(tracking, pos, tpos);
1303
glVertex2f(tpos[0]/width, tpos[1]/(height*aspy));
1305
add_v2_v2(pos, dpos);
1310
else if (stroke->totpoints == 1) {
1312
glVertex2f(stroke->points[0].x, stroke->points[0].y);
1317
stroke = stroke->next;
1320
frame = frame->next;
1323
layer = layer->next;
1333
void clip_draw_main(SpaceClip *sc, ARegion *ar, Scene *scene)
1335
MovieClip *clip= ED_space_clip(sc);
1340
/* if no clip, nothing to do */
1344
ED_space_clip_size(sc, &width, &height);
1345
ED_space_clip_zoom(sc, ar, &zoomx, &zoomy);
1347
if (sc->flag & SC_SHOW_STABLE) {
1348
float smat[4][4], ismat[4][4];
1350
ibuf = ED_space_clip_get_stable_buffer(sc, sc->loc, &sc->scale, &sc->angle);
1354
float aspect = clip->tracking.camera.pixel_aspect;
1356
if (width != ibuf->x)
1357
mul_v2_v2fl(loc, sc->loc, (float)width / ibuf->x);
1359
copy_v2_v2(loc, sc->loc);
1361
BKE_tracking_stabdata_to_mat4(width, height, aspect, loc, sc->scale, sc->angle, sc->stabmat);
1364
smat[0][0] = 1.0f / width;
1365
smat[1][1] = 1.0f / height;
1366
invert_m4_m4(ismat, smat);
1368
mul_serie_m4(sc->unistabmat, smat, sc->stabmat, ismat, NULL, NULL, NULL, NULL, NULL);
1372
ibuf = ED_space_clip_get_buffer(sc);
1376
unit_m4(sc->stabmat);
1377
unit_m4(sc->unistabmat);
1381
draw_movieclip_buffer(sc, ar, ibuf, width, height, zoomx, zoomy);
1382
IMB_freeImBuf(ibuf);
1384
draw_tracking_tracks(sc, ar, clip, width, height, zoomx, zoomy);
1385
draw_distortion(sc, ar, clip, width, height, zoomx, zoomy);
1388
draw_movieclip_cache(sc, ar, clip, scene);
1389
draw_movieclip_notes(sc, ar);
1392
/* draw grease pencil */
1393
void clip_draw_grease_pencil(bContext *C, int onlyv2d)
1395
SpaceClip *sc = CTX_wm_space_clip(C);
1396
MovieClip *clip = ED_space_clip(sc);
1403
/* if manual calibration is used then grease pencil data is already
1404
* drawed in draw_distortion */
1405
if ((sc->flag & SC_MANUAL_CALIBRATION)==0 || sc->mode != SC_MODE_DISTORTION) {
1406
ibuf = ED_space_clip_get_buffer(sc);
1410
glMultMatrixf(sc->unistabmat);
1411
draw_gpencil_2dimage(C, ibuf);
1413
IMB_freeImBuf(ibuf);
1419
draw_gpencil_view2d(C, 0);