Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Sat, 5 Nov 2011 11:53:10 +0000 (11:53 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sat, 5 Nov 2011 11:53:10 +0000 (11:53 +0000)
===========================

- Fix in rna description for pyramid level
- Unlock clip editor when deselecting all markers, deleting all marker
  or hiding them.
- Keep disabled marker when clearing upto/after so there'll be no
  estimated markers in this case which doesn't have much sense here.

source/blender/blenkernel/intern/tracking.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/makesrna/intern/rna_tracking.c

index c79a237fb9e4144df304e996a4d465b767fbc4b6..9a2f6053fa1775f4c13c189fdc9feeddce634cde 100644 (file)
@@ -370,6 +370,21 @@ MovieTrackingTrack *BKE_tracking_copy_track(MovieTrackingTrack *track)
        return new_track;
 }
 
+static void put_disabled_marker(MovieTrackingTrack *track, MovieTrackingMarker *ref_marker, int before, int overwrite)
+{
+       MovieTrackingMarker marker_new;
+
+       marker_new= *ref_marker;
+       marker_new.flag&= ~MARKER_TRACKED;
+       marker_new.flag|= MARKER_DISABLED;
+
+       if(before) marker_new.framenr--;
+       else marker_new.framenr++;
+
+       if(!BKE_tracking_has_marker(track, marker_new.framenr) || overwrite)
+               BKE_tracking_insert_marker(track, &marker_new);
+}
+
 void BKE_tracking_clear_path(MovieTrackingTrack *track, int ref_frame, int action)
 {
        int a;
@@ -386,6 +401,9 @@ void BKE_tracking_clear_path(MovieTrackingTrack *track, int ref_frame, int actio
 
                        a++;
                }
+
+               if(track->markersnr)
+                       put_disabled_marker(track, &track->markers[track->markersnr-1], 0, 1);
        } else if(action==TRACK_CLEAR_UPTO) {
                a= track->markersnr-1;
                while(a>=0) {
@@ -400,19 +418,23 @@ void BKE_tracking_clear_path(MovieTrackingTrack *track, int ref_frame, int actio
 
                        a--;
                }
+
+               if(track->markersnr)
+                       put_disabled_marker(track, &track->markers[0], 1, 1);
        } else if(action==TRACK_CLEAR_ALL) {
                MovieTrackingMarker *marker, marker_new;
 
                marker= BKE_tracking_get_marker(track, ref_frame);
-               if(marker)
-                       marker_new= *marker;
+               marker_new= *marker;
 
                MEM_freeN(track->markers);
                track->markers= NULL;
                track->markersnr= 0;
 
-               if(marker)
-                       BKE_tracking_insert_marker(track, &marker_new);
+               BKE_tracking_insert_marker(track, &marker_new);
+
+               put_disabled_marker(track, &marker_new, 1, 1);
+               put_disabled_marker(track, &marker_new, 0, 1);
        }
 }
 
@@ -1153,24 +1175,11 @@ int BKE_tracking_next(MovieTrackingContext *context)
                        coords_correct= !isnan(x2) && !isnan(y2) && finite(x2) && finite(y2);
                        if(coords_correct && (tracked || !context->disable_failed)) {
                                if(context->first_time) {
-                                       int prevframe;
-
-                                       if(context->backwards) prevframe= curfra+1;
-                                       else prevframe= curfra-1;
-
-                                       /* check if there's no keyframe/tracked markers before tracking marker.
-                                           if so -- create disabled marker before currently tracking "segment" */
-                                       if(!BKE_tracking_has_marker(track, prevframe)) {
-                                               marker_new= *marker;
-                                               marker_new.framenr= prevframe;
-
-                                               marker_new.flag&= ~MARKER_GRAPH_SEL;
-                                               marker_new.flag|= MARKER_DISABLED;
-
-                                               #pragma omp critical
-                                               {
-                                                       BKE_tracking_insert_marker(track, &marker_new);
-                                               }
+                                       #pragma omp critical
+                                       {
+                                               /* check if there's no keyframe/tracked markers before tracking marker.
+                                                   if so -- create disabled marker before currently tracking "segment" */
+                                               put_disabled_marker(track, marker, 1, 0);
                                        }
                                }
 
@@ -1191,19 +1200,10 @@ int BKE_tracking_next(MovieTrackingContext *context)
                                        BKE_tracking_insert_marker(track, &marker_new);
                                }
 
-                               if(context->backwards) nextfra--;
-                               else nextfra++;
-
                                /* make currently tracked segment be finished with disabled marker */
-                               if(!BKE_tracking_has_marker(track, nextfra)) {
-                                       marker_new.framenr= nextfra;
-                                       marker_new.flag|= MARKER_DISABLED;
-                                       marker_new.flag&= ~MARKER_TRACKED;
-
-                                       #pragma omp critical
-                                       {
-                                               BKE_tracking_insert_marker(track, &marker_new);
-                                       }
+                               #pragma omp critical
+                               {
+                                       put_disabled_marker(track, &marker_new, 0, 0);
                                }
                        } else {
                                marker_new= *marker;
index 35b54b8c3e38057fe57df47bbee3d8bd98642109..17e07cd82247f8c155f0f21b5a220b76776e2ca6 100644 (file)
@@ -201,6 +201,9 @@ static int delete_track_exec(bContext *C, wmOperator *UNUSED(op))
                track= next;
        }
 
+       /* nothing selected now, unlock view so it can be scrolled nice again */
+       sc->flag&= ~SC_LOCK_SELECTION;
+
        return OPERATOR_FINISHED;
 }
 
@@ -228,6 +231,7 @@ static int delete_marker_exec(bContext *C, wmOperator *UNUSED(op))
        MovieClip *clip= ED_space_clip(sc);
        MovieTrackingTrack *track= clip->tracking.tracks.first, *next;
        int framenr= sc->user.framenr;
+       int has_selection= 0;
 
        while(track) {
                next= track->next;
@@ -235,13 +239,21 @@ static int delete_marker_exec(bContext *C, wmOperator *UNUSED(op))
                if(TRACK_VIEW_SELECTED(sc, track)) {
                        MovieTrackingMarker *marker= BKE_tracking_exact_marker(track, framenr);
 
-                       if(marker)
+                       if(marker) {
+                               has_selection|= track->markersnr>1;
+
                                clip_delete_marker(C, clip, track, marker);
+                       }
                }
 
                track= next;
        }
 
+       if(!has_selection) {
+               /* nothing selected now, unlock view so it can be scrolled nice again */
+               sc->flag&= ~SC_LOCK_SELECTION;
+       }
+
        return OPERATOR_FINISHED;
 }
 
@@ -1009,6 +1021,7 @@ static int select_all_exec(bContext *C, wmOperator *op)
        MovieTrackingTrack *track= NULL;        /* selected track */
        int action= RNA_enum_get(op->ptr, "action");
        int framenr= sc->user.framenr;
+       int has_selection= 0;
 
        if(action == SEL_TOGGLE){
                action= SEL_SELECT;
@@ -1049,9 +1062,15 @@ static int select_all_exec(bContext *C, wmOperator *op)
                        }
                }
 
+               if(TRACK_VIEW_SELECTED(sc, track))
+                       has_selection= 1;
+
                track= track->next;
        }
 
+       if(!has_selection)
+               sc->flag&= ~SC_LOCK_SELECTION;
+
        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, NULL);
 
        return OPERATOR_FINISHED;
@@ -2160,6 +2179,11 @@ static int hide_tracks_exec(bContext *C, wmOperator *op)
        if(clip->tracking.act_track && clip->tracking.act_track->flag&TRACK_HIDDEN)
                clip->tracking.act_track= NULL;
 
+       if(unselected==0) {
+               /* no selection on screen now, unlock view so it can be scrolled nice again */
+               sc->flag&= ~SC_LOCK_SELECTION;
+       }
+
        WM_event_add_notifier(C, NC_MOVIECLIP|ND_DISPLAY, NULL);
 
        return OPERATOR_FINISHED;
index 71552c6e9f052581c009c7ef9555569c3460c02f..34307f972c587444f3559de74c767fbba24e4e73 100644 (file)
@@ -484,7 +484,7 @@ static void rna_def_trackingTrack(BlenderRNA *brna)
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
        RNA_def_property_int_sdna(prop, NULL, "pyramid_levels");
        RNA_def_property_range(prop, 1, 16);
-       RNA_def_property_ui_text(prop, "Pyramid levels", "Number of pyramid levels for KLT tracking.");
+       RNA_def_property_ui_text(prop, "Pyramid levels", "Number of pyramid levels for KLT tracking");
        RNA_def_property_update(prop, NC_MOVIECLIP|NA_EDITED, "rna_tracking_trackerPyramid_update");
 
        /* minmal correlation - only used for SAD tracker */