Tracking: Add utility function to find tracking object from a given track
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 19 Dec 2017 11:10:42 +0000 (12:10 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 19 Dec 2017 11:13:57 +0000 (12:13 +0100)
source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/tracking.c

index d05ed1800fb5e0ea595de6b6a9025ebc64c60585..169059b121f4f001d53f76f36bae312c8c0fc62f 100644 (file)
@@ -288,6 +288,13 @@ void BKE_tracking_stabilization_data_to_mat4(int width, int height, float aspect
 void BKE_tracking_dopesheet_tag_update(struct MovieTracking *tracking);
 void BKE_tracking_dopesheet_update(struct MovieTracking *tracking);
 
+/* **** Query/search **** */
+
+struct MovieTrackingObject *BKE_tracking_find_object_for_track(const struct MovieTracking *tracking,
+                                                               const struct MovieTrackingTrack *track);
+
+/* **** Utility macros **** */
+
 #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 : \
index b4ef381534f18e67837c7c2d4c65e0df48839120..0c464058ebaeba07c512fdc49a830d4b71a00033 100644 (file)
@@ -2904,3 +2904,21 @@ void BKE_tracking_dopesheet_update(MovieTracking *tracking)
 
        dopesheet->ok = true;
 }
+
+/* NOTE: Returns NULL if the track comes from camera object, */
+MovieTrackingObject *BKE_tracking_find_object_for_track(const MovieTracking *tracking,
+                                                        const MovieTrackingTrack *track)
+{
+       const ListBase *tracksbase = &tracking->tracks;
+       if (BLI_findindex(tracksbase, track) != -1) {
+               return NULL;
+       }
+       MovieTrackingObject *object = tracking->objects.first;
+       while (object) {
+               if (BLI_findindex(&object->tracks, track) != -1) {
+                       return object;
+               }
+               object = object->next;
+       }
+       return NULL;
+}