Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2019-11-28 13:14:32 +0300
committerSergey Sharybin <sergey@blender.org>2021-01-18 18:38:40 +0300
commitf17b26bbed3d78fdd98e5262af66719f6a5ec121 (patch)
treed7ec6737175ea2226c8a69c6976601b9fc0d7487 /source/blender/editors/space_clip
parent0ac8fec3be4af8d2c079142bb9638d5f1e3097ed (diff)
Tracking: Implement tracks average operator
Average selected tracks into the new one. This can be used to improve stability of tracking on blurry or non-very-sharp feature shapes. Averaging happens for all position, pattern corners and search area. Disabled markers do not take effect on averaging. Keyframed flag is copied from source. Gaps in the source tracks will be linearly interpolated, to reduce result track jump. Note that this only applies to gaps "inbetween". This means that if an input track doesn't have markers in the beginning/end of it, there is nothing to interpolate with and the result track will jump. Available from the Track panel, under the Merge category. Differential Revision: https://developer.blender.org/D6323
Diffstat (limited to 'source/blender/editors/space_clip')
-rw-r--r--source/blender/editors/space_clip/clip_intern.h1
-rw-r--r--source/blender/editors/space_clip/space_clip.c1
-rw-r--r--source/blender/editors/space_clip/tracking_ops.c91
3 files changed, 93 insertions, 0 deletions
diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h
index 4848ec72f79..81df8cc8ecd 100644
--- a/source/blender/editors/space_clip/clip_intern.h
+++ b/source/blender/editors/space_clip/clip_intern.h
@@ -191,6 +191,7 @@ void CLIP_OT_clear_solution(struct wmOperatorType *ot);
void CLIP_OT_clear_track_path(struct wmOperatorType *ot);
void CLIP_OT_join_tracks(struct wmOperatorType *ot);
+void CLIP_OT_average_tracks(struct wmOperatorType *ot);
void CLIP_OT_disable_markers(struct wmOperatorType *ot);
void CLIP_OT_hide_tracks(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 33c4bf7c255..085dbccabb2 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -514,6 +514,7 @@ static void clip_operatortypes(void)
/* clean-up */
WM_operatortype_append(CLIP_OT_clear_track_path);
WM_operatortype_append(CLIP_OT_join_tracks);
+ WM_operatortype_append(CLIP_OT_average_tracks);
WM_operatortype_append(CLIP_OT_track_copy_color);
WM_operatortype_append(CLIP_OT_clean_tracks);
diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c
index 49313005c43..10574063ebd 100644
--- a/source/blender/editors/space_clip/tracking_ops.c
+++ b/source/blender/editors/space_clip/tracking_ops.c
@@ -1490,6 +1490,97 @@ void CLIP_OT_join_tracks(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+/********************** Average tracks operator *********************/
+
+static int average_tracks_exec(bContext *C, wmOperator *op)
+{
+ SpaceClip *space_clip = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(space_clip);
+ MovieTracking *tracking = &clip->tracking;
+
+ /* Collect source tracks. */
+ int num_source_tracks;
+ MovieTrackingTrack **source_tracks = BKE_tracking_selected_tracks_in_active_object(
+ tracking, &num_source_tracks);
+ if (num_source_tracks == 0) {
+ return OPERATOR_CANCELLED;
+ }
+
+ /* Create new empty track, which will be the averaged result.
+ * Makes it simple to average all selection to it. */
+ ListBase *tracks_list = BKE_tracking_get_active_tracks(tracking);
+ MovieTrackingTrack *result_track = BKE_tracking_track_add_empty(tracking, tracks_list);
+
+ /* Perform averaging. */
+ BKE_tracking_tracks_average(result_track, source_tracks, num_source_tracks);
+
+ const bool keep_original = RNA_boolean_get(op->ptr, "keep_original");
+ if (!keep_original) {
+ for (int i = 0; i < num_source_tracks; i++) {
+ clip_delete_track(C, clip, source_tracks[i]);
+ }
+ }
+
+ /* Update selection, making the result track active and selected. */
+ /* TODO(sergey): Should become some sort of utility function available for all operators. */
+
+ BKE_tracking_track_select(tracks_list, result_track, TRACK_AREA_ALL, 0);
+ ListBase *plane_tracks_list = BKE_tracking_get_active_plane_tracks(tracking);
+ BKE_tracking_plane_tracks_deselect_all(plane_tracks_list);
+
+ clip->tracking.act_track = result_track;
+ clip->tracking.act_plane_track = NULL;
+
+ /* Inform the dependency graph and interface about changes. */
+ DEG_id_tag_update(&clip->id, 0);
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
+
+ /* Free memory. */
+ MEM_freeN(source_tracks);
+
+ return OPERATOR_FINISHED;
+}
+
+static int average_tracks_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ PropertyRNA *prop_keep_original = RNA_struct_find_property(op->ptr, "keep_original");
+ if (!RNA_property_is_set(op->ptr, prop_keep_original)) {
+ SpaceClip *space_clip = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip_get_clip(space_clip);
+ MovieTracking *tracking = &clip->tracking;
+
+ const int num_selected_tracks = BKE_tracking_count_selected_tracks_in_active_object(tracking);
+
+ if (num_selected_tracks == 1) {
+ RNA_property_boolean_set(op->ptr, prop_keep_original, false);
+ }
+ }
+
+ return average_tracks_exec(C, op);
+}
+
+void CLIP_OT_average_tracks(wmOperatorType *ot)
+{
+ /* Identifiers. */
+ ot->name = "Average Tracks";
+ ot->description = "Average selected tracks into active";
+ ot->idname = "CLIP_OT_average_tracks";
+
+ /* API callbacks. */
+ ot->exec = average_tracks_exec;
+ ot->invoke = average_tracks_invoke;
+ ot->poll = ED_space_clip_tracking_poll;
+
+ /* Flags. */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* Properties. */
+ PropertyRNA *prop;
+
+ prop = RNA_def_boolean(ot->srna, "keep_original", 1, "Keep Original", "Keep original tracks");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+}
+
/********************** lock tracks operator *********************/
enum {