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

Code cleanup and minor refactor. Moved some functions from movieclip.c
to tracking.c due to they're operating on tracking data only.

source/blender/blenkernel/BKE_movieclip.h
source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/tracking.c
source/blender/editors/object/object_constraint.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/editors/space_view3d/view3d_select.c

index 827134bcbee29751538d40c90cd0313f1e0e1416..4d16df8afa39a897b27ee6e3a41a648872137c0c 100644 (file)
@@ -55,7 +55,6 @@ int BKE_movieclip_has_frame(struct MovieClip *clip, struct MovieClipUser *user);
 void BKE_movieclip_user_set_frame(struct MovieClipUser *user, int framenr);
 
 void BKE_movieclip_select_track(struct MovieClip *clip, struct MovieTrackingTrack *track, int area, int extend);
-void BKE_movieclip_deselect_track(struct MovieClip *clip, struct MovieTrackingTrack *track, int area);
 
 void BKE_movieclip_update_scopes(struct MovieClip *clip, struct MovieClipUser *user, struct MovieClipScopes *scopes);
 
index 068fef1795c6dfb991eb2e7c2641bb055d8480d1..a8fb2c836def10877c8063a6d5ad2f0b0ff24584 100644 (file)
@@ -46,10 +46,12 @@ struct Scene;
 
 void BKE_tracking_clamp_track(struct MovieTrackingTrack *track, int event);
 void BKE_tracking_track_flag(struct MovieTrackingTrack *track, int area, int flag, int clear);
+
 struct MovieTrackingTrack *BKE_tracking_add_track(struct MovieTracking *tracking, float x, float y,
                        int framenr, int width, int height);
 void BKE_tracking_insert_marker(struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker);
 void BKE_tracking_delete_marker(struct MovieTrackingTrack *track, int framenr);
+
 struct MovieTrackingMarker *BKE_tracking_get_marker(struct MovieTrackingTrack *track, int framenr);
 struct MovieTrackingMarker *BKE_tracking_ensure_marker(struct MovieTrackingTrack *track, int framenr);
 struct MovieTrackingMarker *BKE_tracking_exact_marker(struct MovieTrackingTrack *track, int framenr);
@@ -57,7 +59,9 @@ int BKE_tracking_has_marker(struct MovieTrackingTrack *track, int framenr);
 
 void BKE_tracking_free_track(struct MovieTrackingTrack *track);
 struct MovieTrackingTrack *BKE_tracking_copy_track(struct MovieTrackingTrack *track);
+
 void BKE_tracking_clear_path(struct MovieTrackingTrack *track, int ref_frame, int action);
+
 int BKE_tracking_test_join_tracks(struct MovieTrackingTrack *dst_track, struct MovieTrackingTrack *src_track);
 void BKE_tracking_join_tracks(struct MovieTrackingTrack *dst_track, struct MovieTrackingTrack *src_track);
 void BKE_tracking_free(struct MovieTracking *tracking);
@@ -67,6 +71,18 @@ struct ImBuf *BKE_tracking_get_pattern_imbuf(struct ImBuf *ibuf, struct MovieTra
 struct ImBuf *BKE_tracking_get_search_imbuf(struct ImBuf *ibuf, struct MovieTrackingTrack *track,
                        struct MovieTrackingMarker *marker, int margin, int anchored, float pos[2], int origin[2]);
 
+void BKE_track_unique_name(struct MovieTracking *tracking, struct MovieTrackingTrack *track);
+
+struct MovieTrackingTrack *BKE_tracking_named_track(struct MovieTracking *tracking, const char *name);
+struct MovieTrackingTrack *BKE_tracking_indexed_track(struct MovieTracking *tracking, int tracknr);
+
+void BKE_tracking_camera_shift(struct MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty);
+void BKE_tracking_camera_to_blender(struct MovieTracking *tracking, struct Scene *scene, struct Camera *camera, int width, int height);
+
+void BKE_get_tracking_mat(struct Scene *scene, struct Object *ob, float mat[4][4]);
+void BKE_tracking_projection_matrix(struct MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4]);
+
+/* 2D tracking */
 struct MovieTrackingContext *BKE_tracking_context_new(struct MovieClip *clip, struct MovieClipUser *user,
                        short backwards, short disable_failed);
 void BKE_tracking_context_free(struct MovieTrackingContext *context);
@@ -74,33 +90,26 @@ void BKE_tracking_sync(struct MovieTrackingContext *context);
 void BKE_tracking_sync_user(struct MovieClipUser *user, struct MovieTrackingContext *context);
 int BKE_tracking_next(struct MovieTrackingContext *context);
 
+/* Camera solving */
 float BKE_tracking_solve_reconstruction(struct MovieTracking *tracking, int width, int height);
 
-void BKE_track_unique_name(struct MovieTracking *tracking, struct MovieTrackingTrack *track);
-struct MovieTrackingTrack *BKE_find_track_by_name(struct MovieTracking *tracking, const char *name);
-
 struct MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(struct MovieTracking *tracking, int framenr);
 void BKE_tracking_get_interpolated_camera(struct MovieTracking *tracking, int framenr, float mat[4][4]);
 
-void BKE_tracking_camera_shift(struct MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty);
-void BKE_tracking_camera_to_blender(struct MovieTracking *tracking, struct Scene *scene, struct Camera *camera, int width, int height);
-
-void BKE_get_tracking_mat(struct Scene *scene, struct Object *ob, 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 nco[2]);
-void BKE_tracking_invert_intrinsics(struct MovieTracking *tracking, float co[2], float nco[2]);
-
+/* Feature detection */
 void BKE_tracking_detect_fast(struct MovieTracking *tracking, struct ImBuf *imbuf,
                        int framenr, int margin, int min_trackness, int min_distance, struct bGPDlayer *layer,
                        int place_outside_layer);
 
-struct MovieTrackingTrack *BKE_tracking_indexed_bundle(struct MovieTracking *tracking, int bundlenr);
-
+/* 2D stabilization */
 void BKE_tracking_stabilization_data(struct MovieTracking *tracking, int framenr, int width, int height, float loc[2], float *scale, float *angle);
 struct ImBuf *BKE_tracking_stabilize(struct MovieTracking *tracking, int framenr, struct ImBuf *ibuf, float loc[2], float *scale, float *angle);
 void BKE_tracking_stabdata_to_mat4(int width, int height, float loc[2], float scale, float angle, float mat[4][4]);
 
 /* Distortion/Undistortion */
+void BKE_tracking_apply_intrinsics(struct MovieTracking *tracking, float co[2], float nco[2]);
+void BKE_tracking_invert_intrinsics(struct MovieTracking *tracking, float co[2], float nco[2]);
+
 struct MovieDistortion *BKE_tracking_distortion_create(void);
 struct MovieDistortion *BKE_tracking_distortion_copy(struct MovieDistortion *distortion);
 struct ImBuf *BKE_tracking_distortion_exec(struct MovieDistortion *distortion, struct MovieTracking *tracking,
@@ -110,6 +119,10 @@ void BKE_tracking_distortion_destroy(struct MovieDistortion *distortion);
 struct ImBuf *BKE_tracking_undistort(struct MovieTracking *tracking, struct ImBuf *ibuf, int width, int height, float overscan);
 struct ImBuf *BKE_tracking_distort(struct MovieTracking *tracking, struct ImBuf *ibuf, int width, int height, float overscan);
 
+/* Select */
+void BKE_tracking_select_track(struct MovieTracking *tracking, struct MovieTrackingTrack *track, int area, int extend);
+void BKE_tracking_deselect_track(struct MovieTrackingTrack *track, int area);
+
 #define TRACK_SELECTED(track)                          ((((track)->flag&TRACK_HIDDEN)==0) && ((track)->flag&SELECT || (track)->pat_flag&SELECT || (track)->search_flag&SELECT))
 #define TRACK_AREA_SELECTED(track, area)       ((((track)->flag&TRACK_HIDDEN)==0) && ((area)==TRACK_AREA_POINT?(track)->flag&SELECT : ((area)==TRACK_AREA_PAT?(track)->pat_flag&SELECT:(track)->search_flag&SELECT)))
 #define TRACK_VIEW_SELECTED(sc, track)         ((TRACK_AREA_SELECTED(track, TRACK_AREA_POINT) || (((sc)->flag&SC_SHOW_MARKER_PATTERN && TRACK_AREA_SELECTED(track, TRACK_AREA_PAT))) || (((sc)->flag&SC_SHOW_MARKER_SEARCH && TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH)))))
index c7a86d996b13d813e5e6a18cc8d359eec42e9715..17b9821c431dfd139badf4dba7d32c93c62962ee 100644 (file)
@@ -3962,7 +3962,7 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
        if(!clip || !data->track[0])
                return;
 
-       track= BKE_find_track_by_name(&clip->tracking, data->track);
+       track= BKE_tracking_named_track(&clip->tracking, data->track);
 
        if(!track)
                return;
index ab2744ced439234bcd095c525771a2226f5cb5b6..f3d81915709d2f5ec59a8c1f8023f1c852569c8c 100644 (file)
@@ -835,33 +835,6 @@ void BKE_movieclip_reload(MovieClip *clip)
        else clip->source= MCLIP_SRC_SEQUENCE;
 }
 
-/* area - which part of marker should be selected. see TRACK_AREA_* constants */
-void BKE_movieclip_select_track(MovieClip *clip, MovieTrackingTrack *track, int area, int extend)
-{
-       if(extend) {
-               BKE_tracking_track_flag(track, area, SELECT, 0);
-       } else {
-               MovieTrackingTrack *cur= clip->tracking.tracks.first;
-
-               while(cur) {
-                       if(cur==track) {
-                               BKE_tracking_track_flag(cur, TRACK_AREA_ALL, SELECT, 1);
-                               BKE_tracking_track_flag(cur, area, SELECT, 0);
-                       }
-                       else {
-                               BKE_tracking_track_flag(cur, TRACK_AREA_ALL, SELECT, 1);
-                       }
-
-                       cur= cur->next;
-               }
-       }
-}
-
-void BKE_movieclip_deselect_track(MovieClip *UNUSED(clip), MovieTrackingTrack *track, int area)
-{
-       BKE_tracking_track_flag(track, area, SELECT, 1);
-}
-
 void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClipScopes *scopes)
 {
        if(scopes->ok) return;
index fb866a62d263d40c85a7f712bc64d1271944aac7..06a985e7d722a8701bb30767fffb50bfd6d6c702 100644 (file)
@@ -1387,7 +1387,7 @@ void BKE_track_unique_name(MovieTracking *tracking, MovieTrackingTrack *track)
        BLI_uniquename(&tracking->tracks, track, "Track", '.', offsetof(MovieTrackingTrack, name), sizeof(track->name));
 }
 
-MovieTrackingTrack *BKE_find_track_by_name(MovieTracking *tracking, const char *name)
+MovieTrackingTrack *BKE_tracking_named_track(MovieTracking *tracking, const char *name)
 {
        MovieTrackingTrack *track= tracking->tracks.first;
 
@@ -1689,14 +1689,14 @@ void BKE_tracking_detect_fast(MovieTracking *tracking, ImBuf *ibuf,
 #endif
 }
 
-MovieTrackingTrack *BKE_tracking_indexed_bundle(MovieTracking *tracking, int bundlenr)
+MovieTrackingTrack *BKE_tracking_indexed_track(MovieTracking *tracking, int tracknr)
 {
        MovieTrackingTrack *track= tracking->tracks.first;
        int cur= 1;
 
        while(track) {
                if(track->flag&TRACK_HAS_BUNDLE) {
-                       if(cur==bundlenr)
+                       if(cur==tracknr)
                                return track;
 
                        cur++;
@@ -2139,3 +2139,30 @@ ImBuf *BKE_tracking_distort(MovieTracking *tracking, ImBuf *ibuf, int width, int
 
        return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, overscan, 0);
 }
+
+/* area - which part of marker should be selected. see TRACK_AREA_* constants */
+void BKE_tracking_select_track(MovieTracking *tracking, MovieTrackingTrack *track, int area, int extend)
+{
+       if(extend) {
+               BKE_tracking_track_flag(track, area, SELECT, 0);
+       } else {
+               MovieTrackingTrack *cur= tracking->tracks.first;
+
+               while(cur) {
+                       if(cur==track) {
+                               BKE_tracking_track_flag(cur, TRACK_AREA_ALL, SELECT, 1);
+                               BKE_tracking_track_flag(cur, area, SELECT, 0);
+                       }
+                       else {
+                               BKE_tracking_track_flag(cur, TRACK_AREA_ALL, SELECT, 1);
+                       }
+
+                       cur= cur->next;
+               }
+       }
+}
+
+void BKE_tracking_deselect_track(MovieTrackingTrack *track, int area)
+{
+       BKE_tracking_track_flag(track, area, SELECT, 1);
+}
index 0afe40ae037bd42e8051231066c82f7ce68df8de..b36416151a9ad4b9ff72cf1f97b3d4b4e4f6a9b8 100644 (file)
@@ -408,7 +408,7 @@ static void test_constraints (Object *owner, bPoseChannel *pchan)
 
                                if((data->flag&CAMERASOLVER_ACTIVECLIP)==0) {
                                        if(data->clip != NULL && data->track[0]) {
-                                               if (!BKE_find_track_by_name(&data->clip->tracking, data->track))
+                                               if (!BKE_tracking_named_track(&data->clip->tracking, data->track))
                                                        curcon->flag |= CONSTRAINT_DISABLE;
                                        }
                                        else curcon->flag |= CONSTRAINT_DISABLE;
index 5d7bd2f646264dac85ea3937f3607895e5f6e86a..3c90a009403ab625a4b29c3ebc1557840a388ebe 100644 (file)
@@ -123,7 +123,7 @@ static void add_marker(SpaceClip *sc, float x, float y)
 
        track= BKE_tracking_add_track(&clip->tracking, x, y, sc->user.framenr, width, height);
 
-       BKE_movieclip_select_track(clip, track, TRACK_AREA_ALL, 0);
+       BKE_tracking_select_track(&clip->tracking, track, TRACK_AREA_ALL, 0);
 
        clip->tracking.act_track= track;
 }
@@ -776,14 +776,14 @@ static int mouse_select(bContext *C, float co[2], int extend)
 
                if(extend && TRACK_AREA_SELECTED(track, area)) {
                        if(track==act_track)
-                               BKE_movieclip_deselect_track(clip, track, area);
+                               BKE_tracking_deselect_track(track, area);
                        else
                                clip->tracking.act_track= track;
                } else {
                        if(area==TRACK_AREA_POINT)
                                area= TRACK_AREA_ALL;
 
-                       BKE_movieclip_select_track(clip, track, area, extend);
+                       BKE_tracking_select_track(tracking, track, area, extend);
                        clip->tracking.act_track= track;
                }
        }
index fdc8a7d59ffd20d30653d4287c109fe344a86257..0163c29c9aa4d405261866e33d78a6f60cf9abe8 100644 (file)
@@ -1406,12 +1406,12 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short obce
                                                        if(buffer[4*i+3] & 0xFFFF0000) {
                                                                MovieClip *clip= object_get_movieclip(scene, basact->object, 0);
                                                                int selected;
-                                                               track= BKE_tracking_indexed_bundle(&clip->tracking, hitresult >> 16);
+                                                               track= BKE_tracking_indexed_track(&clip->tracking, hitresult >> 16);
 
                                                                selected= (track->flag&SELECT) || (track->pat_flag&SELECT) || (track->search_flag&SELECT);
 
-                                                               if(selected && extend) BKE_movieclip_deselect_track(clip, track, TRACK_AREA_ALL);
-                                                               else BKE_movieclip_select_track(clip, track, TRACK_AREA_ALL, extend);
+                                                               if(selected && extend)  BKE_tracking_deselect_track(track, TRACK_AREA_ALL);
+                                                               else BKE_tracking_select_track(&clip->tracking, track, TRACK_AREA_ALL, extend);
 
                                                                basact->flag|= SELECT;
                                                                basact->object->flag= basact->flag;