Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 14 Jul 2011 12:05:40 +0000 (12:05 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 14 Jul 2011 12:05:40 +0000 (12:05 +0000)
===========================

Small fixes and features:
- Fixed broken toolshelf for empty space clip.
- Added option to hide disabled tracks.
- Do not send disabled markers to tracking job.
- Fixed bug with disabling marker when tracking backwards.
- Fixed bug with unset principal point by default.
- Hide bundle projection for disabled markers.
- Flip orientation when hitting "Set Axis" when bundle is
  already defines axis.

release/scripts/startup/bl_ui/space_clip.py
source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/tracking.c
source/blender/editors/space_clip/clip_draw.c
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesrna/intern/rna_space.c

index e4b15d2b2b30b4489887e489dd4b6bd20d3aaf78..8b3efeb6bf40cd22e215ff773716b5bb8fb7d055 100644 (file)
@@ -121,9 +121,10 @@ class CLIP_PT_tools(bpy.types.Panel):
     def draw(self, context):
         layout = self.layout
         clip = context.space_data.clip
-        settings = clip.tracking.settings
 
         if clip:
+            settings = clip.tracking.settings
+
             col = layout.column(align=True)
             col.label(text="Transform:")
             col.operator("transform.translate")
@@ -296,8 +297,11 @@ class CLIP_PT_display(bpy.types.Panel):
         row.active = sc.show_track_path
         row.prop(sc, "path_length", text="Length")
 
+        row = layout.row()
+        row.prop(sc, "show_disabled", text="Disabled")
+        row.prop(sc, "show_bundles", text="Bundles")
+
         layout.prop(sc, "show_tiny_markers", text="Tiny Markers")
-        layout.prop(sc, "show_bundles", text="Bundles")
 
         layout.prop(sc, "lock_selection")
         layout.prop(sc, "use_mute_footage")
index 1bd0111a513fef7325934a8a23ed0a0ec13fd99a..9816e5a65bc74d996b20008e3829f635f68b57bc 100644 (file)
@@ -78,9 +78,11 @@ void BKE_get_tracking_mat(struct Scene *scene, float mat[4][4]);
 void BKE_tracking_projection_matrix(struct MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4]);
 void BKE_tracking_apply_intrinsics(struct MovieTracking *tracking, float co[2], float width, float height, float nco[2]);
 
-#define TRACK_SELECTED(track) ((track)->flag&SELECT || (track)->pat_flag&SELECT || (track)->search_flag&SELECT)
-#define TRACK_AREA_SELECTED(track, area) ((area)==TRACK_AREA_POINT?(track)->flag&SELECT : ((area)==TRACK_AREA_PAT?(track)->pat_flag&SELECT:(track)->search_flag&SELECT))
-#define TRACK_VIEW_SELECTED(track) ((track->flag&TRACK_HIDDEN)==0 && TRACK_SELECTED(track))
+#define TRACK_SELECTED(track)                          ((track)->flag&SELECT || (track)->pat_flag&SELECT || (track)->search_flag&SELECT)
+#define TRACK_AREA_SELECTED(track, area)       ((area)==TRACK_AREA_POINT?(track)->flag&SELECT : ((area)==TRACK_AREA_PAT?(track)->pat_flag&SELECT:(track)->search_flag&SELECT))
+#define TRACK_VIEW_SELECTED(track)                     ((track->flag&TRACK_HIDDEN)==0 && TRACK_SELECTED(track))
+#define TRACK_VISIBLE(track)                           (((track)->flag&TRACK_HIDDEN)==0)
+#define MARKER_VISIBLE(sc, marker)                     (((marker)->flag&MARKER_DISABLED)==0 || ((sc)->flag&SC_HIDE_DISABLED)==0)
 
 #define CLAMP_PAT_DIM          1
 #define CLAMP_PAT_POS          2
index 529dbcbf08f6f1dde9b24e3bc2ec748c3b33ab49..7e2627f3c3018a05c7c88de4139eee43c4e5567e 100644 (file)
@@ -231,6 +231,7 @@ static MovieClip *movieclip_alloc(const char *name)
 MovieClip *BKE_add_movieclip_file(const char *name)
 {
        MovieClip *clip;
+       MovieClipUser user;
        int file, len, width, height;
        const char *libname;
        char str[FILE_MAX], strtest[FILE_MAX];
@@ -270,7 +271,8 @@ MovieClip *BKE_add_movieclip_file(const char *name)
        if(BLI_testextensie_array(name, imb_ext_movie)) clip->source= MCLIP_SRC_MOVIE;
        else clip->source= MCLIP_SRC_SEQUENCE;
 
-       BKE_movieclip_acquire_size(clip, NULL, &width, &height);
+       user.framenr= 1;
+       BKE_movieclip_acquire_size(clip, &user, &width, &height);
        if(width && height) {
                clip->tracking.camera.principal[0]= ((float)width)/2;
                clip->tracking.camera.principal[1]= ((float)height)/2;
index 11e847fd198aadec4a431bdd970b4cda72e88cdb..243632574c751a20b1030b1610f2976216e1c870 100644 (file)
@@ -386,11 +386,15 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u
 
        track= tracking->tracks.first;
        while(track) {
-               if(TRACK_VIEW_SELECTED(track)) {
-                       MovieTrackingTrack *new_track= BKE_tracking_copy_track(track);
+               if(TRACK_VIEW_SELECTED(track) && TRACK_VISIBLE(track)) {
+                       MovieTrackingMarker *marker= BKE_tracking_get_marker(track, user->framenr);
 
-                       BLI_addtail(&context->tracks, new_track);
-                       BLI_ghash_insert(context->hash, new_track, track);
+                       if((marker->flag&MARKER_DISABLED)==0) {
+                               MovieTrackingTrack *new_track= BKE_tracking_copy_track(track);
+
+                               BLI_addtail(&context->tracks, new_track);
+                               BLI_ghash_insert(context->hash, new_track, track);
+                       }
                }
 
                track= track->next;
@@ -661,7 +665,10 @@ int BKE_tracking_next(MovieTrackingContext *context)
 
                        } else {
                                marker_new= *marker;
-                               marker_new.framenr++;
+
+                               if(context->backwards) marker_new.framenr--;
+                               else marker_new.framenr++;;
+
                                marker_new.flag|= MARKER_DISABLED;
 
                                BKE_tracking_insert_marker(track, &marker_new);
index 2b4ee3e52f6baa526bc16664456f8b395a9720eb..dc70b0d3ba9e906961abfda334d81f3b18b24364 100644 (file)
@@ -524,7 +524,7 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
        if(sc->flag&SC_SHOW_TRACK_PATH) {
                track= tracking->tracks.first;
                while(track) {
-                       if((track->flag&TRACK_HIDDEN)==0)
+                       if(TRACK_VISIBLE(track))
                                draw_track_path(sc, clip, track);
 
                        track= track->next;
@@ -534,12 +534,14 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
        /* markers outline and non-selected areas */
        track= tracking->tracks.first;
        while(track) {
-               if((track->flag&TRACK_HIDDEN)==0) {
+               if(TRACK_VISIBLE(track)) {
                        marker= BKE_tracking_get_marker(track, framenr);
 
-                       draw_marker_outline(sc, track, marker);
-                       draw_marker_slide_zones(sc, track, marker, 1, 0, width, height);
-                       draw_marker_areas(sc, track, marker, 0, 0);
+                       if(MARKER_VISIBLE(sc, marker)) {
+                               draw_marker_outline(sc, track, marker);
+                               draw_marker_slide_zones(sc, track, marker, 1, 0, width, height);
+                               draw_marker_areas(sc, track, marker, 0, 0);
+                       }
                }
 
                track= track->next;
@@ -549,13 +551,16 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
           non-selected areas */
        track= tracking->tracks.first;
        while(track) {
-               if((track->flag&TRACK_HIDDEN)==0) {
+               if(TRACK_VISIBLE(track)) {
                        int act= sel_type==MCLIP_SEL_TRACK && sel==track;
 
                        if(!act) {
                                marker= BKE_tracking_get_marker(track, framenr);
-                               draw_marker_areas(sc, track, marker, 0, 1);
-                               draw_marker_slide_zones(sc, track, marker, 0, 0, width, height);
+
+                               if(MARKER_VISIBLE(sc, marker)) {
+                                       draw_marker_areas(sc, track, marker, 0, 1);
+                                       draw_marker_slide_zones(sc, track, marker, 0, 0, width, height);
+                               }
                        }
                }
 
@@ -564,10 +569,13 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
 
        /* active marker would be displayed on top of everything else */
        if(sel_type==MCLIP_SEL_TRACK) {
-               if((((MovieTrackingTrack *)sel)->flag&TRACK_HIDDEN)==0) {
+               if(TRACK_VISIBLE((MovieTrackingTrack *)sel)) {
                        marker= BKE_tracking_get_marker(sel, framenr);
-                       draw_marker_areas(sc, sel, marker, 1, 1);
-                       draw_marker_slide_zones(sc, sel, marker, 0, 1, width, height);
+
+                       if(MARKER_VISIBLE(sc, marker)) {
+                               draw_marker_areas(sc, sel, marker, 1, 1);
+                               draw_marker_slide_zones(sc, sel, marker, 0, 1, width, height);
+                       }
                }
        }
 
@@ -581,29 +589,31 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
 
                track= tracking->tracks.first;
                while(track) {
-                       if((track->flag&TRACK_HIDDEN)==0 && track->flag&TRACK_HAS_BUNDLE) {
+                       if(TRACK_VISIBLE(track) && track->flag&TRACK_HAS_BUNDLE) {
                                marker= BKE_tracking_get_marker(track, framenr);
 
-                               copy_v4_v4(vec, track->bundle_pos);
-                               vec[3]=1;
+                               if(MARKER_VISIBLE(sc, marker)) {
+                                       copy_v4_v4(vec, track->bundle_pos);
+                                       vec[3]=1;
 
-                               mul_v4_m4v4(pos, mat, vec);
+                                       mul_v4_m4v4(pos, mat, vec);
 
-                               pos[0]= (pos[0]/(pos[3]*2.0f)+0.5f)*width;
-                               pos[1]= (pos[1]/(pos[3]*2.0f)+0.5f)*height;
+                                       pos[0]= (pos[0]/(pos[3]*2.0f)+0.5f)*width;
+                                       pos[1]= (pos[1]/(pos[3]*2.0f)+0.5f)*height;
 
-                               BKE_tracking_apply_intrinsics(tracking, pos, width, height, pos);
+                                       BKE_tracking_apply_intrinsics(tracking, pos, width, height, pos);
 
-                               vec[0]= marker->pos[0]*width;
-                               vec[1]= marker->pos[1]*height;
-                               sub_v2_v2(vec, pos);
+                                       vec[0]= marker->pos[0]*width;
+                                       vec[1]= marker->pos[1]*height;
+                                       sub_v2_v2(vec, pos);
 
-                               if(len_v2(vec)<3) glColor3f(0.0f, 1.0f, 0.0f);
-                               else glColor3f(1.0f, 0.0f, 0.0f);
+                                       if(len_v2(vec)<3) glColor3f(0.0f, 1.0f, 0.0f);
+                                       else glColor3f(1.0f, 0.0f, 0.0f);
 
-                               glBegin(GL_POINTS);
-                                       glVertex3f(pos[0]/width, pos[1]/height, 0);
-                               glEnd();
+                                       glBegin(GL_POINTS);
+                                               glVertex3f(pos[0]/width, pos[1]/height, 0);
+                                       glEnd();
+                               }
                        }
 
                        track= track->next;
index b8e49ac094fcbd923f4009ee0262d46bb8bfdb7b..f9e820aad4d74d277b12ef1fac727e7400fdefe0 100644 (file)
@@ -301,6 +301,9 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
        RNA_boolean_set(kmi->ptr, "unselected", 1);
        WM_keymap_add_item(keymap, "CLIP_OT_hide_tracks_clear", HKEY, KM_PRESS, KM_ALT, 0);
 
+       kmi= WM_keymap_add_item(keymap, "CLIP_OT_disable_markers", DKEY, KM_PRESS, 0, 0);
+       RNA_enum_set(kmi->ptr, "action", 2);
+
        transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
 }
 
index c02da02ed1e84786e797ed3d6a1f78efc0f3dcf8..d32239fee1b427818e9e00d7bd4dac2c09ad12fe 100644 (file)
@@ -400,19 +400,22 @@ static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, MovieClip *clip, fl
        cur= clip->tracking.tracks.first;
        while(cur) {
                MovieTrackingMarker *marker= BKE_tracking_get_marker(cur, sc->user.framenr);
-               float dist, d1, d2, d3;
 
-               d1= sqrtf((co[0]-marker->pos[0])*(co[0]-marker->pos[0])+
-                                 (co[1]-marker->pos[1])*(co[1]-marker->pos[1])); /* distance to marker point */
-               d2= dist_to_rect(co, marker->pos, cur->pat_min, cur->pat_max); /* distance to search boundbox */
-               d3= dist_to_rect(co, marker->pos, cur->search_min, cur->search_max); /* distance to search boundbox */
+               if(TRACK_VISIBLE(cur) && MARKER_VISIBLE(sc, marker)) {
+                       float dist, d1, d2, d3;
 
-               /* choose minimal distance. useful for cases of overlapped markers. */
-               dist= MIN3(d1, d2, d3);
+                       d1= sqrtf((co[0]-marker->pos[0])*(co[0]-marker->pos[0])+
+                                         (co[1]-marker->pos[1])*(co[1]-marker->pos[1])); /* distance to marker point */
+                       d2= dist_to_rect(co, marker->pos, cur->pat_min, cur->pat_max); /* distance to search boundbox */
+                       d3= dist_to_rect(co, marker->pos, cur->search_min, cur->search_max); /* distance to search boundbox */
 
-               if(track==NULL || dist<mindist) {
-                       track= cur;
-                       mindist= dist;
+                       /* choose minimal distance. useful for cases of overlapped markers. */
+                       dist= MIN3(d1, d2, d3);
+
+                       if(track==NULL || dist<mindist) {
+                               track= cur;
+                               mindist= dist;
+                       }
                }
 
                cur= cur->next;
@@ -520,10 +523,10 @@ static int border_select_exec(bContext *C, wmOperator *op)
        /* do actual selection */
        track= clip->tracking.tracks.first;
        while(track) {
-               if((track->flag&TRACK_HIDDEN)==0) {
+               if(TRACK_VISIBLE(track)) {
                        MovieTrackingMarker *marker= BKE_tracking_get_marker(track, sc->user.framenr);
 
-                       if(BLI_in_rctf(&rectf, marker->pos[0], marker->pos[1])) {
+                       if(MARKER_VISIBLE(sc, marker) && BLI_in_rctf(&rectf, marker->pos[0], marker->pos[1])) {
                                BKE_tracking_track_flag(track, TRACK_AREA_ALL, SELECT, mode!=GESTURE_MODAL_SELECT);
 
                                change= 1;
@@ -605,10 +608,10 @@ static int circle_select_exec(bContext *C, wmOperator *op)
        /* do selection */
        track= clip->tracking.tracks.first;
        while(track) {
-               if((track->flag&TRACK_HIDDEN)==0) {
+               if(TRACK_VISIBLE(track)) {
                        MovieTrackingMarker *marker= BKE_tracking_get_marker(track, sc->user.framenr);
 
-                       if(marker_inside_ellipse(marker, offset, ellipse)) {
+                       if(MARKER_VISIBLE(sc, marker) && marker_inside_ellipse(marker, offset, ellipse)) {
                                BKE_tracking_track_flag(track, TRACK_AREA_ALL, SELECT, mode!=GESTURE_MODAL_SELECT);
 
                                change= 1;
@@ -680,23 +683,27 @@ static int select_all_exec(bContext *C, wmOperator *op)
 
        track= clip->tracking.tracks.first;
        while(track) {
-               if((track->flag&TRACK_HIDDEN)==0 && BKE_tracking_has_marker(track, framenr)) {
-                       switch (action) {
-                               case SEL_SELECT:
-                                       track->flag|= SELECT;
-                                       track->pat_flag|= SELECT;
-                                       track->search_flag|= SELECT;
-                                       break;
-                               case SEL_DESELECT:
-                                       track->flag&= ~SELECT;
-                                       track->pat_flag&= ~SELECT;
-                                       track->search_flag&= ~SELECT;
-                                       break;
-                               case SEL_INVERT:
-                                       track->flag^= SELECT;
-                                       track->pat_flag^= SELECT;
-                                       track->search_flag^= SELECT;
-                                       break;
+               if(TRACK_VISIBLE(track)) {
+                       MovieTrackingMarker *marker= BKE_tracking_get_marker(track, framenr);
+
+                       if(marker && MARKER_VISIBLE(sc, marker)) {
+                               switch (action) {
+                                       case SEL_SELECT:
+                                               track->flag|= SELECT;
+                                               track->pat_flag|= SELECT;
+                                               track->search_flag|= SELECT;
+                                               break;
+                                       case SEL_DESELECT:
+                                               track->flag&= ~SELECT;
+                                               track->pat_flag&= ~SELECT;
+                                               track->search_flag&= ~SELECT;
+                                               break;
+                                       case SEL_INVERT:
+                                               track->flag^= SELECT;
+                                               track->pat_flag^= SELECT;
+                                               track->search_flag^= SELECT;
+                                               break;
+                               }
                        }
                }
 
@@ -756,7 +763,7 @@ static void track_init_markers(SpaceClip *sc, MovieClip *clip)
 
        track= clip->tracking.tracks.first;
        while(track) {
-               if((track->flag&TRACK_HIDDEN)==0)
+               if(TRACK_VISIBLE(track))
                        BKE_tracking_ensure_marker(track, framenr);
 
                track= track->next;
@@ -1305,15 +1312,27 @@ static void set_axis(Scene *scene,  Object *ob, MovieTrackingTrack *track, char
        unit_m4(mat);
 
        if(axis=='X') {
-               copy_v3_v3(mat[0], vec);
-               mat[0][2]= 0.f;
-               mat[2][0]= 0.f; mat[2][1]= 0.f; mat[2][2]= 1.0f;
-               cross_v3_v3v3(mat[1], mat[2], mat[0]);
+               if(fabsf(vec[1])<1e-3) {
+                       mat[0][0]= -1.f; mat[0][1]= 0.f; mat[0][2]= 0.f;
+                       mat[1][0]= 0.f; mat[1][1]= -1.f; mat[1][2]= 0.f;
+                       mat[2][0]= 0.f; mat[2][1]= 0.f; mat[2][2]= 1.0f;
+               } else {
+                       copy_v3_v3(mat[0], vec);
+                       mat[0][2]= 0.f;
+                       mat[2][0]= 0.f; mat[2][1]= 0.f; mat[2][2]= 1.0f;
+                       cross_v3_v3v3(mat[1], mat[2], mat[0]);
+               }
        } else {
-               copy_v3_v3(mat[1], vec);
-               mat[1][2]= 0.f;
-               mat[2][0]= 0.f; mat[2][1]= 0.f; mat[2][2]= 1.0f;
-               cross_v3_v3v3(mat[0], mat[1], mat[2]);
+               if(fabsf(vec[0])<1e-3) {
+                       mat[0][0]= -1.f; mat[0][1]= 0.f; mat[0][2]= 0.f;
+                       mat[1][0]= 0.f; mat[1][1]= -1.f; mat[1][2]= 0.f;
+                       mat[2][0]= 0.f; mat[2][1]= 0.f; mat[2][2]= 1.0f;
+               } else {
+                       copy_v3_v3(mat[1], vec);
+                       mat[1][2]= 0.f;
+                       mat[2][0]= 0.f; mat[2][1]= 0.f; mat[2][2]= 1.0f;
+                       cross_v3_v3v3(mat[0], mat[1], mat[2]);
+               }
        }
 
        normalize_v3(mat[0]);
@@ -1759,7 +1778,7 @@ static int hide_tracks_exec(bContext *C, wmOperator *op)
        if(sel_type==MCLIP_SEL_TRACK) {
                track= (MovieTrackingTrack *)sel;
 
-               if(track->flag&TRACK_HIDDEN)
+               if(!TRACK_VISIBLE(track))
                        BKE_movieclip_set_selection(clip, MCLIP_SEL_NONE, NULL);
        }
 
index d005f7b8cc4b602851f2c3ce526fc9e2a05404a3..120733d94ecbf2594f8974520ec7152ae9e2bbc5 100644 (file)
@@ -967,6 +967,7 @@ enum {
 #define SC_SHOW_TRACK_PATH             (1<<4)
 #define SC_SHOW_BUNDLES                        (1<<5)
 #define SC_MUTE_FOOTAGE                        (1<<6)
+#define SC_HIDE_DISABLED               (1<<7)
 
 
 /* space types, moved from DNA_screen_types.h */
index 2828083649c58e3a8c598f138a9eb2b29a72e32c..b6966d0b9c7e6afb48f74f9cd8b889d3d53eed28 100644 (file)
@@ -2688,6 +2688,12 @@ static void rna_def_space_clip(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Mute Footage", "Mute footage and show black background instead");
        RNA_def_property_boolean_sdna(prop, NULL, "flag", SC_MUTE_FOOTAGE);
        RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CLIP, NULL);
+
+       /* hide disabled */
+       prop= RNA_def_property(srna, "show_disabled", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_ui_text(prop, "Show Disabled", "Show disabled tracks from the footage");
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SC_HIDE_DISABLED);
+       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CLIP, NULL);
 }
 
 void RNA_def_space(BlenderRNA *brna)