Tracking: Cleanup, make autotrack context creation code more granular

This commit is contained in:
Sergey Sharybin 2017-12-15 12:35:41 +01:00
parent 4cc0f09881
commit e50442418a

@ -281,62 +281,23 @@ static bool tracking_check_marker_margin(libmv_Marker *libmv_marker,
return true;
}
AutoTrackContext *BKE_autotrack_context_new(MovieClip *clip,
MovieClipUser *user,
/* Provide Libmv side of auto track all information about given tracks. */
static void fill_autotrack_tracks(const int frame_width,
const int frame_height,
const ListBase *tracksbase,
const bool backwards,
const bool sequence)
struct libmv_AutoTrack *autotrack)
{
AutoTrackContext *context = MEM_callocN(sizeof(AutoTrackContext),
"autotrack context");
MovieTracking *tracking = &clip->tracking;
MovieTrackingTrack *track;
ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
int i, track_index, frame_width, frame_height;
BKE_movieclip_get_size(clip, user, &frame_width, &frame_height);
/* TODO(sergey): Currently using only a single clip. */
context->clips[0] = clip;
context->num_clips = 1;
context->user = *user;
context->user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL;
context->user.render_flag = 0;
context->frame_width = frame_width;
context->frame_height = frame_height;
context->backwards = backwards;
context->sequence = sequence;
context->first_frame = user->framenr;
context->sync_frame = user->framenr;
context->first_sync = true;
BLI_spin_init(&context->spin_lock);
int num_total_tracks = BLI_listbase_count(tracksbase);
context->tracks =
MEM_callocN(sizeof(MovieTrackingTrack *) * num_total_tracks,
"auto track pointers");
context->image_accessor =
tracking_image_accessor_new(context->clips, 1,
context->tracks, num_total_tracks,
user->framenr);
context->autotrack =
libmv_autoTrackNew(context->image_accessor->libmv_accessor);
/* Fill in Autotrack with all markers we know. */
track_index = 0;
for (track = tracksbase->first;
track;
int track_index = 0;
for (MovieTrackingTrack *track = tracksbase->first;
track != NULL;
track = track->next)
{
if (check_track_trackable(clip, track, user)) {
context->num_tracks++;
}
for (i = 0; i < track->markersnr; ++i) {
for (int i = 0; i < track->markersnr; ++i) {
MovieTrackingMarker *marker = track->markers + i;
if ((marker->flag & MARKER_DISABLED) == 0) {
if ((marker->flag & MARKER_DISABLED) != 0) {
continue;
}
libmv_Marker libmv_marker;
dna_marker_to_libmv_marker(track,
marker,
@ -346,23 +307,40 @@ AutoTrackContext *BKE_autotrack_context_new(MovieClip *clip,
frame_height,
backwards,
&libmv_marker);
libmv_autoTrackAddMarker(context->autotrack,
&libmv_marker);
}
libmv_autoTrackAddMarker(autotrack, &libmv_marker);
}
track_index++;
}
}
/* Create per-track tracking options. */
context->options =
MEM_callocN(sizeof(AutoTrackOptions) * context->num_tracks,
"auto track options");
i = track_index = 0;
for (track = tracksbase->first;
track;
static void create_per_track_tracking_options(const MovieClip *clip,
const MovieClipUser *user,
const ListBase *tracksbase,
AutoTrackContext *context)
{
/* Count number of trackable tracks. */
for (MovieTrackingTrack *track = tracksbase->first;
track != NULL;
track = track->next)
{
if (check_track_trackable(clip, track, user)) {
context->num_tracks++;
}
}
/* Allocate required memory. */
context->options =
MEM_callocN(sizeof(AutoTrackOptions) * context->num_tracks,
"auto track options");
/* Fill in all the settings. */
int i = 0, track_index = 0;
for (MovieTrackingTrack *track = tracksbase->first;
track != NULL;
track = track->next)
{
if (!check_track_trackable(clip, track, user)) {
++track_index;
continue;
}
AutoTrackOptions *options = &context->options[i++];
/* TODO(sergey): Single clip only for now. */
options->clip_index = 0;
@ -373,11 +351,57 @@ AutoTrackContext *BKE_autotrack_context_new(MovieClip *clip,
&options->track_region_options);
options->use_keyframe_match =
track->pattern_match == TRACK_MATCH_KEYFRAME;
}
context->tracks[track_index] = track;
++track_index;
}
}
AutoTrackContext *BKE_autotrack_context_new(MovieClip *clip,
MovieClipUser *user,
const bool backwards,
const bool sequence)
{
AutoTrackContext *context = MEM_callocN(sizeof(AutoTrackContext),
"autotrack context");
MovieTracking *tracking = &clip->tracking;
ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
int frame_width, frame_height;
/* get size of frame to convert normalized coordinates to a picture ones. */
BKE_movieclip_get_size(clip, user, &frame_width, &frame_height);
/* TODO(sergey): Currently using only a single clip. */
context->clips[0] = clip;
context->num_clips = 1;
context->user = *user;
context->user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL;
context->user.render_flag = 0;
context->frame_width = frame_width;
context->frame_height = frame_height;
context->backwards = backwards;
context->sequence = sequence;
context->first_frame = user->framenr;
context->sync_frame = user->framenr;
context->first_sync = true;
BLI_spin_init(&context->spin_lock);
const int num_total_tracks = BLI_listbase_count(tracksbase);
context->tracks =
MEM_callocN(sizeof(MovieTrackingTrack *) * num_total_tracks,
"auto track pointers");
/* Initialize image accessor. */
context->image_accessor =
tracking_image_accessor_new(context->clips, 1,
context->tracks, num_total_tracks,
user->framenr);
/* Initialize auto track context and provide all information about currently
* tracked markers.
*/
context->autotrack =
libmv_autoTrackNew(context->image_accessor->libmv_accessor);
fill_autotrack_tracks(frame_width, frame_height,
tracksbase,
backwards,
context->autotrack);
/* Create per-track tracking options. */
create_per_track_tracking_options(clip, user, tracksbase, context);
return context;
}