Blender V5.3
tracking_ops_stabilize.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "BLI_listbase.hh"
12
13#include "DNA_screen_types.h"
14#include "DNA_space_types.h"
15
16#include "BKE_context.hh"
17#include "BKE_tracking.hh"
18
19#include "DEG_depsgraph.hh"
20
21#include "WM_api.hh"
22#include "WM_types.hh"
23
24#include "ED_clip.hh"
25
26#include "clip_intern.hh"
27
28namespace blender {
29
30/********************* add 2d stabilization tracks operator ********************/
31
33{
38 return (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0;
39 }
40 return false;
41}
42
44{
47 MovieTracking *tracking = &clip->tracking;
48 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
49 MovieTrackingStabilization *stabilization = &tracking->stabilization;
50
51 bool update = false;
52 for (MovieTrackingTrack &track : tracking_object->tracks) {
53 if (TRACK_VIEW_SELECTED(sc, &track) && (track.flag & TRACK_USE_2D_STAB) == 0) {
54 track.flag |= TRACK_USE_2D_STAB;
55 stabilization->tot_track++;
56 update = true;
57 }
58 }
59
60 if (update) {
61 DEG_id_tag_update(&clip->id, 0);
63 }
64
65 return OPERATOR_FINISHED;
66}
67
69{
70 /* identifiers */
71 ot->name = "Add Stabilization Tracks";
72 ot->description = "Add selected tracks to 2D translation stabilization";
73 ot->idname = "CLIP_OT_stabilize_2d_add";
74
75 /* API callbacks. */
78
79 /* flags */
81}
82
83/******************* remove 2d stabilization tracks operator ******************/
84
86{
89 MovieTracking *tracking = &clip->tracking;
90 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
91 MovieTrackingStabilization *stabilization = &tracking->stabilization;
92 int a = 0;
93 bool update = false;
94
95 for (MovieTrackingTrack &track : tracking_object->tracks) {
96 if (track.flag & TRACK_USE_2D_STAB) {
97 if (a == stabilization->act_track) {
98 track.flag &= ~TRACK_USE_2D_STAB;
99 stabilization->act_track--;
100 stabilization->tot_track--;
101 stabilization->act_track = std::max(stabilization->act_track, 0);
102 update = true;
103 break;
104 }
105 a++;
106 }
107 }
108
109 if (update) {
110 DEG_id_tag_update(&clip->id, 0);
112 }
113
114 return OPERATOR_FINISHED;
115}
116
118{
119 /* identifiers */
120 ot->name = "Remove Stabilization Track";
121 ot->description = "Remove selected track from translation stabilization";
122 ot->idname = "CLIP_OT_stabilize_2d_remove";
123
124 /* API callbacks. */
127
128 /* flags */
130}
131
132/******************* select 2d stabilization tracks operator ******************/
133
135{
138 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
139 bool update = false;
140
141 for (MovieTrackingTrack &track : tracking_object->tracks) {
142 if (track.flag & TRACK_USE_2D_STAB) {
144 update = true;
145 }
146 }
147
148 if (update) {
150 }
151
152 return OPERATOR_FINISHED;
153}
154
156{
157 /* identifiers */
158 ot->name = "Select Stabilization Tracks";
159 ot->description = "Select tracks which are used for translation stabilization";
160 ot->idname = "CLIP_OT_stabilize_2d_select";
161
162 /* API callbacks. */
165
166 /* flags */
168}
169
170/********************** add 2d stabilization tracks for rotation operator ****************/
171
173{
176 MovieTracking *tracking = &clip->tracking;
177 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
178 MovieTrackingStabilization *stabilization = &tracking->stabilization;
179
180 bool update = false;
181 for (MovieTrackingTrack &track : tracking_object->tracks) {
182 if (TRACK_VIEW_SELECTED(sc, &track) && (track.flag & TRACK_USE_2D_STAB_ROT) == 0) {
184 stabilization->tot_rot_track++;
185 update = true;
186 }
187 }
188
189 if (update) {
190 DEG_id_tag_update(&clip->id, 0);
192 }
193
194 return OPERATOR_FINISHED;
195}
196
198{
199 /* identifiers */
200 ot->name = "Add Stabilization Rotation Tracks";
201 ot->description = "Add selected tracks to 2D rotation stabilization";
202 ot->idname = "CLIP_OT_stabilize_2d_rotation_add";
203
204 /* API callbacks. */
207
208 /* flags */
210}
211
212/********************** remove 2d stabilization tracks for rotation operator *************/
213
215{
218 MovieTracking *tracking = &clip->tracking;
219 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking);
220 MovieTrackingStabilization *stabilization = &tracking->stabilization;
221 int a = 0;
222 bool update = false;
223
224 for (MovieTrackingTrack &track : tracking_object->tracks) {
225 if (track.flag & TRACK_USE_2D_STAB_ROT) {
226 if (a == stabilization->act_rot_track) {
228 stabilization->act_rot_track--;
229 stabilization->tot_rot_track--;
230 stabilization->act_rot_track = std::max(stabilization->act_rot_track, 0);
231 update = true;
232 break;
233 }
234 a++;
235 }
236 }
237
238 if (update) {
239 DEG_id_tag_update(&clip->id, 0);
241 }
242
243 return OPERATOR_FINISHED;
244}
245
247{
248 /* identifiers */
249 ot->name = "Remove Stabilization Rotation Track";
250 ot->description = "Remove selected track from rotation stabilization";
251 ot->idname = "CLIP_OT_stabilize_2d_rotation_remove";
252
253 /* API callbacks. */
256
257 /* flags */
259}
260
261/********************** select 2d stabilization rotation tracks operator *****************/
262
264{
267 const MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(&clip->tracking);
268 bool update = false;
269
270 for (MovieTrackingTrack &track : tracking_object->tracks) {
271 if (track.flag & TRACK_USE_2D_STAB_ROT) {
273 update = true;
274 }
275 }
276
277 if (update) {
279 }
280
281 return OPERATOR_FINISHED;
282}
283
285{
286 /* identifiers */
287 ot->name = "Select Stabilization Rotation Tracks";
288 ot->description = "Select tracks which are used for rotation stabilization";
289 ot->idname = "CLIP_OT_stabilize_2d_rotation_select";
290
291 /* API callbacks. */
294
295 /* flags */
297}
298
299} // namespace blender
#define TRACK_VIEW_SELECTED(sc, track)
#define C
Definition RandGen.cpp:29
#define ND_DISPLAY
Definition WM_types.hh:534
#define NC_MOVIECLIP
Definition WM_types.hh:410
#define ND_SELECT
Definition WM_types.hh:551
BMesh Iterators.
static wmOperatorStatus stabilize_2d_rotation_remove_exec(bContext *C, wmOperator *)
void CLIP_OT_stabilize_2d_add(wmOperatorType *ot)
static bool stabilize_2d_poll(bContext *C)
void CLIP_OT_stabilize_2d_rotation_add(wmOperatorType *ot)
MovieTrackingObject * BKE_tracking_object_get_active(const MovieTracking *tracking)
Definition tracking.cc:1982
SpaceClip * CTX_wm_space_clip(const bContext *C)
void CLIP_OT_stabilize_2d_select(wmOperatorType *ot)
static wmOperatorStatus stabilize_2d_remove_exec(bContext *C, wmOperator *)
void DEG_id_tag_update(ID *id, unsigned int flags)
void CLIP_OT_stabilize_2d_rotation_remove(wmOperatorType *ot)
static wmOperatorStatus stabilize_2d_rotation_add_exec(bContext *C, wmOperator *)
static wmOperatorStatus stabilize_2d_rotation_select_exec(bContext *C, wmOperator *)
void CLIP_OT_stabilize_2d_rotation_select(wmOperatorType *ot)
static wmOperatorStatus stabilize_2d_select_exec(bContext *C, wmOperator *)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void CLIP_OT_stabilize_2d_remove(wmOperatorType *ot)
MovieClip * ED_space_clip_get_clip(const SpaceClip *sc)
bool ED_space_clip_tracking_poll(bContext *C)
void BKE_tracking_track_flag_set(MovieTrackingTrack *track, eTrackArea area, TrackingTrackFlag flag)
Definition tracking.cc:677
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
static wmOperatorStatus stabilize_2d_add_exec(bContext *C, wmOperator *)
struct MovieTracking tracking
ListBaseT< MovieTrackingTrack > tracks
MovieTrackingStabilization stabilization
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165