1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2016 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation,
* Sergey Sharybin
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/space_clip/tracking_ops_stabilize.c
* \ingroup spclip
*/
#include "MEM_guardedalloc.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "BKE_tracking.h"
#include "BKE_depsgraph.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_clip.h"
#include "clip_intern.h"
/********************* add 2d stabilization tracks operator ********************/
static int stabilize_2d_poll(bContext *C)
{
if (ED_space_clip_tracking_poll(C)) {
SpaceClip *sc = CTX_wm_space_clip(C);
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTrackingObject *tracking_object =
BKE_tracking_object_get_active(&clip->tracking);
return (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0;
}
return 0;
}
static int stabilize_2d_add_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceClip *sc = CTX_wm_space_clip(C);
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
MovieTrackingStabilization *stab = &tracking->stabilization;
bool update = false;
for (MovieTrackingTrack *track = tracksbase->first;
track != NULL;
track = track->next)
{
if (TRACK_VIEW_SELECTED(sc, track) &&
(track->flag & TRACK_USE_2D_STAB) == 0)
{
track->flag |= TRACK_USE_2D_STAB;
stab->tot_track++;
update = true;
}
}
if (update) {
stab->ok = 0;
DAG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
}
return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_add(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Add Stabilization Tracks";
ot->description = "Add selected tracks to 2D stabilization tool";
ot->idname = "CLIP_OT_stabilize_2d_add";
/* api callbacks */
ot->exec = stabilize_2d_add_exec;
ot->poll = stabilize_2d_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************* remove 2d stabilization tracks operator ******************/
static int stabilize_2d_remove_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceClip *sc = CTX_wm_space_clip(C);
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
MovieTrackingStabilization *stab = &tracking->stabilization;
ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
int a = 0;
bool update = false;
for (MovieTrackingTrack *track = tracksbase->first;
track != NULL;
track = track->next)
{
if (track->flag & TRACK_USE_2D_STAB) {
if (a == stab->act_track) {
track->flag &= ~TRACK_USE_2D_STAB;
stab->act_track--;
stab->tot_track--;
if (stab->act_track < 0) {
stab->act_track = 0;
}
update = true;
break;
}
a++;
}
}
if (update) {
stab->ok = 0;
DAG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
}
return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_remove(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Remove Stabilization Track";
ot->description = "Remove selected track from stabilization";
ot->idname = "CLIP_OT_stabilize_2d_remove";
/* api callbacks */
ot->exec = stabilize_2d_remove_exec;
ot->poll = stabilize_2d_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************* select 2d stabilization tracks operator ******************/
static int stabilize_2d_select_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceClip *sc = CTX_wm_space_clip(C);
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
bool update = false;
for (MovieTrackingTrack *track = tracksbase->first;
track != NULL;
track = track->next)
{
if (track->flag & TRACK_USE_2D_STAB) {
BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
update = true;
}
}
if (update) {
WM_event_add_notifier(C, NC_MOVIECLIP | ND_SELECT, clip);
}
return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_select(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select Stabilization Tracks";
ot->description = "Select tracks which are used for stabilization";
ot->idname = "CLIP_OT_stabilize_2d_select";
/* api callbacks */
ot->exec = stabilize_2d_select_exec;
ot->poll = stabilize_2d_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/***************** set 2d stabilization rotation track operator ****************/
static int stabilize_2d_set_rotation_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceClip *sc = CTX_wm_space_clip(C);
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
if (act_track != NULL) {
MovieTrackingStabilization *stab = &tracking->stabilization;
stab->rot_track = act_track;
stab->ok = 0;
DAG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
}
return OPERATOR_FINISHED;
}
void CLIP_OT_stabilize_2d_set_rotation(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Set Rotation Track";
ot->description = "Use active track to compensate rotation when "
"doing 2D stabilization";
ot->idname = "CLIP_OT_stabilize_2d_set_rotation";
/* api callbacks */
ot->exec = stabilize_2d_set_rotation_exec;
ot->poll = stabilize_2d_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
|