diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-03-21 21:21:27 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-03-21 21:21:27 +0400 |
commit | af46a2902fff686a4abf59f0126c59b2e48bd4c4 (patch) | |
tree | c697b6b26babead25b68bbc2e34609f254d9069b /source/blender/blenkernel/intern/tracking.c | |
parent | e82cd12560c39e5fe94dcf2b05855774cb6f5607 (diff) |
Use linear interpolation for intersecting tracks when joining them together.
Diffstat (limited to 'source/blender/blenkernel/intern/tracking.c')
-rw-r--r-- | source/blender/blenkernel/intern/tracking.c | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 2b79f179fb7..e9f0fecbe18 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -497,12 +497,58 @@ void BKE_tracking_join_tracks(MovieTrackingTrack *dst_track, MovieTrackingTrack } else { if((src_track->markers[a].flag&MARKER_DISABLED)==0) { if((dst_track->markers[b].flag&MARKER_DISABLED)==0) { - /* both tracks are enabled on this frame, use their average position - * can be improved further if tracks will be storing tracking score */ + /* both tracks are enabled on this frame, so find the whole segment + * on which tracks are intersecting and blend tracks using linear + * interpolation to prevent jumps */ - markers[i]= dst_track->markers[b]; - add_v2_v2(markers[i].pos, src_track->markers[a].pos); - mul_v2_fl(markers[i].pos, 0.5f); + MovieTrackingMarker *marker_a, *marker_b; + int start_a = a, start_b = b, len = 0, frame = src_track->markers[a].framenr; + int j, inverse = 0; + + inverse = (b == 0) || + (dst_track->markers[b-1].flag & MARKER_DISABLED) || + (dst_track->markers[b-1].framenr != frame - 1); + + while (a < src_track->markersnr && b < dst_track->markersnr) { + marker_a = &src_track->markers[a]; + marker_b = &dst_track->markers[b]; + + if (marker_a->flag & MARKER_DISABLED || marker_b->flag & MARKER_DISABLED) + break; + + if (marker_a->framenr != frame || marker_b->framenr != frame) + break; + + frame++; + len++; + a++; + b++; + } + + a = start_a; + b = start_b; + + for (j = 0; j < len; j++) { + float fac = 0.5f; + + if (len > 1) + fac = 1.0f / (len - 1) * j; + + if (inverse) + fac = 1.0f - fac; + + marker_a = &src_track->markers[a]; + marker_b = &dst_track->markers[b]; + + markers[i]= dst_track->markers[b]; + interp_v2_v2v2(markers[i].pos, marker_b->pos, marker_a->pos, fac); + a++; + b++; + i++; + } + + /* this values will be incremented at the end of the loop cycle */ + a--; b--; i--; } else markers[i]= src_track->markers[a]; } |