Blender  V2.93
tracking_ops_stabilize.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) 2016 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "DNA_screen_types.h"
25 #include "DNA_space_types.h"
26 
27 #include "BLI_utildefines.h"
28 
29 #include "BKE_context.h"
30 #include "BKE_tracking.h"
31 
32 #include "DEG_depsgraph.h"
33 
34 #include "WM_api.h"
35 #include "WM_types.h"
36 
37 #include "ED_clip.h"
38 
39 #include "clip_intern.h"
40 
41 /********************* add 2d stabilization tracks operator ********************/
42 
44 {
49  return (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0;
50  }
51  return 0;
52 }
53 
55 {
58  MovieTracking *tracking = &clip->tracking;
59  ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
60  MovieTrackingStabilization *stab = &tracking->stabilization;
61 
62  bool update = false;
63  for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
64  if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_USE_2D_STAB) == 0) {
65  track->flag |= TRACK_USE_2D_STAB;
66  stab->tot_track++;
67  update = true;
68  }
69  }
70 
71  if (update) {
72  DEG_id_tag_update(&clip->id, 0);
74  }
75 
76  return OPERATOR_FINISHED;
77 }
78 
80 {
81  /* identifiers */
82  ot->name = "Add Stabilization Tracks";
83  ot->description = "Add selected tracks to 2D translation stabilization";
84  ot->idname = "CLIP_OT_stabilize_2d_add";
85 
86  /* api callbacks */
89 
90  /* flags */
92 }
93 
94 /******************* remove 2d stabilization tracks operator ******************/
95 
97 {
100  MovieTracking *tracking = &clip->tracking;
101  MovieTrackingStabilization *stab = &tracking->stabilization;
102  ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
103  int a = 0;
104  bool update = false;
105 
106  for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
107  if (track->flag & TRACK_USE_2D_STAB) {
108  if (a == stab->act_track) {
109  track->flag &= ~TRACK_USE_2D_STAB;
110  stab->act_track--;
111  stab->tot_track--;
112  if (stab->act_track < 0) {
113  stab->act_track = 0;
114  }
115  update = true;
116  break;
117  }
118  a++;
119  }
120  }
121 
122  if (update) {
123  DEG_id_tag_update(&clip->id, 0);
125  }
126 
127  return OPERATOR_FINISHED;
128 }
129 
131 {
132  /* identifiers */
133  ot->name = "Remove Stabilization Track";
134  ot->description = "Remove selected track from translation stabilization";
135  ot->idname = "CLIP_OT_stabilize_2d_remove";
136 
137  /* api callbacks */
140 
141  /* flags */
143 }
144 
145 /******************* select 2d stabilization tracks operator ******************/
146 
148 {
150  MovieClip *clip = ED_space_clip_get_clip(sc);
151  MovieTracking *tracking = &clip->tracking;
152  ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
153  bool update = false;
154 
155  for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
156  if (track->flag & TRACK_USE_2D_STAB) {
158  update = true;
159  }
160  }
161 
162  if (update) {
164  }
165 
166  return OPERATOR_FINISHED;
167 }
168 
170 {
171  /* identifiers */
172  ot->name = "Select Stabilization Tracks";
173  ot->description = "Select tracks which are used for translation stabilization";
174  ot->idname = "CLIP_OT_stabilize_2d_select";
175 
176  /* api callbacks */
179 
180  /* flags */
182 }
183 
184 /********************** add 2d stabilization tracks for rotation operator ****************/
185 
187 {
189  MovieClip *clip = ED_space_clip_get_clip(sc);
190  MovieTracking *tracking = &clip->tracking;
191  ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
192  MovieTrackingStabilization *stab = &tracking->stabilization;
193 
194  bool update = false;
195  for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
196  if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_USE_2D_STAB_ROT) == 0) {
197  track->flag |= TRACK_USE_2D_STAB_ROT;
198  stab->tot_rot_track++;
199  update = true;
200  }
201  }
202 
203  if (update) {
204  DEG_id_tag_update(&clip->id, 0);
206  }
207 
208  return OPERATOR_FINISHED;
209 }
210 
212 {
213  /* identifiers */
214  ot->name = "Add Stabilization Rotation Tracks";
215  ot->description = "Add selected tracks to 2D rotation stabilization";
216  ot->idname = "CLIP_OT_stabilize_2d_rotation_add";
217 
218  /* api callbacks */
221 
222  /* flags */
224 }
225 
226 /********************** remove 2d stabilization tracks for rotation operator *************/
227 
229 {
231  MovieClip *clip = ED_space_clip_get_clip(sc);
232  MovieTracking *tracking = &clip->tracking;
233  MovieTrackingStabilization *stab = &tracking->stabilization;
234  ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
235  int a = 0;
236  bool update = false;
237 
238  for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
239  if (track->flag & TRACK_USE_2D_STAB_ROT) {
240  if (a == stab->act_rot_track) {
241  track->flag &= ~TRACK_USE_2D_STAB_ROT;
242  stab->act_rot_track--;
243  stab->tot_rot_track--;
244  if (stab->act_rot_track < 0) {
245  stab->act_rot_track = 0;
246  }
247  update = true;
248  break;
249  }
250  a++;
251  }
252  }
253 
254  if (update) {
255  DEG_id_tag_update(&clip->id, 0);
257  }
258 
259  return OPERATOR_FINISHED;
260 }
261 
263 {
264  /* identifiers */
265  ot->name = "Remove Stabilization Rotation Track";
266  ot->description = "Remove selected track from rotation stabilization";
267  ot->idname = "CLIP_OT_stabilize_2d_rotation_remove";
268 
269  /* api callbacks */
272 
273  /* flags */
275 }
276 
277 /********************** select 2d stabilization rotation tracks operator *****************/
278 
280 {
282  MovieClip *clip = ED_space_clip_get_clip(sc);
283  MovieTracking *tracking = &clip->tracking;
284  ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
285  bool update = false;
286 
287  for (MovieTrackingTrack *track = tracksbase->first; track != NULL; track = track->next) {
288  if (track->flag & TRACK_USE_2D_STAB_ROT) {
290  update = true;
291  }
292  }
293 
294  if (update) {
296  }
297 
298  return OPERATOR_FINISHED;
299 }
300 
302 {
303  /* identifiers */
304  ot->name = "Select Stabilization Rotation Tracks";
305  ot->description = "Select tracks which are used for rotation stabilization";
306  ot->idname = "CLIP_OT_stabilize_2d_rotation_select";
307 
308  /* api callbacks */
311 
312  /* flags */
314 }
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:899
#define TRACK_AREA_ALL
Definition: BKE_tracking.h:524
struct ListBase * BKE_tracking_get_active_tracks(struct MovieTracking *tracking)
Definition: tracking.c:365
void BKE_tracking_track_flag_set(struct MovieTrackingTrack *track, int area, int flag)
Definition: tracking.c:753
#define TRACK_VIEW_SELECTED(sc, track)
Definition: BKE_tracking.h:497
struct MovieTrackingObject * BKE_tracking_object_get_active(struct MovieTracking *tracking)
Definition: tracking.c:2198
#define UNUSED(x)
void DEG_id_tag_update(struct ID *id, int flag)
@ TRACK_USE_2D_STAB
@ TRACK_USE_2D_STAB_ROT
@ TRACKING_OBJECT_CAMERA
@ OPERATOR_FINISHED
bool ED_space_clip_tracking_poll(struct bContext *C)
Definition: clip_editor.c:98
struct MovieClip * ED_space_clip_get_clip(struct SpaceClip *sc)
Definition: clip_editor.c:572
#define C
Definition: RandGen.cpp:39
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define ND_DISPLAY
Definition: WM_types.h:391
#define NC_MOVIECLIP
Definition: WM_types.h:298
#define ND_SELECT
Definition: WM_types.h:407
#define SELECT
static unsigned a[3]
Definition: RandGen.cpp:92
static void update(bNodeTree *ntree)
void * first
Definition: DNA_listBase.h:47
struct MovieTracking tracking
MovieTrackingStabilization stabilization
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
static int stabilize_2d_remove_exec(bContext *C, wmOperator *UNUSED(op))
void CLIP_OT_stabilize_2d_rotation_add(wmOperatorType *ot)
void CLIP_OT_stabilize_2d_remove(wmOperatorType *ot)
static int stabilize_2d_rotation_select_exec(bContext *C, wmOperator *UNUSED(op))
void CLIP_OT_stabilize_2d_rotation_remove(wmOperatorType *ot)
void CLIP_OT_stabilize_2d_select(wmOperatorType *ot)
void CLIP_OT_stabilize_2d_add(wmOperatorType *ot)
static int stabilize_2d_rotation_add_exec(bContext *C, wmOperator *UNUSED(op))
static int stabilize_2d_add_exec(bContext *C, wmOperator *UNUSED(op))
void CLIP_OT_stabilize_2d_rotation_select(wmOperatorType *ot)
static int stabilize_2d_rotation_remove_exec(bContext *C, wmOperator *UNUSED(op))
static int stabilize_2d_select_exec(bContext *C, wmOperator *UNUSED(op))
static bool stabilize_2d_poll(bContext *C)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156