Start migrating away from pat_min and pat_max for markers
authorKeir Mierle <mierle@gmail.com>
Mon, 14 May 2012 10:47:25 +0000 (10:47 +0000)
committerKeir Mierle <mierle@gmail.com>
Mon, 14 May 2012 10:47:25 +0000 (10:47 +0000)
This starts converting markers in the movie clip editor / 2D
tracker from using pat_min and pat_max notation to using the
a more general, 4-corner representation. There is still
considerable porting work to do; in particular:

- The preview widget does not respect the new
  representation
- The corners cannot yet be edited individually.
- The clamping does not do the right thing for general
  corners; e.g. detecting a convex quad.
- The tracking code in Blender does not actually invoke the
  corner tracking version of libmv's tracking API.

Next steps:

- Convert libmv's legacy ESM tracker and brute tracker to
  work under the new TrackRegion() API.
- Make Blender use the new TrackRegion() API; this will
  allow real planar tracking tests.
- Everything else (UI, etc).

This patch is mostly the work of Sergey Sharybin.

source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/tracking.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/space_clip/clip_buttons.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/editors/transform/transform_conversions.c
source/blender/makesdna/DNA_tracking_types.h

index 817cb477abad0173b57ea272e8c79350d66237b4..84beca4fd9696fea9964d5be5f109e213e010f1d 100644 (file)
@@ -57,6 +57,7 @@ struct MovieTrackingMarker *BKE_tracking_insert_marker(struct MovieTrackingTrack
                                                        struct MovieTrackingMarker *marker);
 void BKE_tracking_delete_marker(struct MovieTrackingTrack *track, int framenr);
 
+void BKE_tracking_marker_pattern_minmax(struct MovieTrackingMarker *marker, float min[2], float max[2]);
 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);
index f07de7f0127ef2e93033e90bca497df5b30df98e..952e87077dc52e85157166f7484cb012e333cea1 100644 (file)
@@ -1076,10 +1076,18 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip
                        }
 
                        if ((track->flag & TRACK_LOCKED) == 0) {
+                               float pat_min[2], pat_max[2];
+
                                scopes->marker = marker;
                                scopes->track = track;
-                               scopes->slide_scale[0] = track->pat_max[0] - track->pat_min[0];
-                               scopes->slide_scale[1] = track->pat_max[1] - track->pat_min[1];
+
+                               /* XXX: would work fine with non-transformed patterns, but would likely fail
+                                *      with transformed patterns, but that would be easier to debug when
+                                *      we'll have real pattern sampling (at least to test) */
+                               BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+
+                               scopes->slide_scale[0] = pat_max[0] - pat_min[0];
+                               scopes->slide_scale[1] = pat_max[1] - pat_min[1];
                        }
                }
        }
index 4e2b4be474bf69544076758f379ce630e37fc923..e8168da45fb43f367dbedbf20015bccc716d3acb 100644 (file)
@@ -102,59 +102,67 @@ void BKE_tracking_init_settings(MovieTracking *tracking)
 void BKE_tracking_clamp_track(MovieTrackingTrack *track, int event)
 {
        int a;
-       float pat_min[2];
-       float pat_max[2];
+       float pat_min[2], pat_max[2];
+       float eff_pat_min[2], eff_pat_max[2];
        float max_pyramid_level_factor = 1.0;
 
        if (track->tracker == TRACKER_KLT) {
                max_pyramid_level_factor = 1 << (track->pyramid_levels - 1);
        }
 
-       /* sort */
-       for (a = 0; a < 2; a++) {
-               if (track->pat_min[a] > track->pat_max[a])
-                       SWAP(float, track->pat_min[a], track->pat_max[a]);
+       /* XXX: currently search area is global, pattern size is per-marker, so we'll need to
+        *      find maximal size of pattern to clamp search size nicely */
+       INIT_MINMAX2(pat_min, pat_max);
+
+       for (a = 0; a < track->markersnr; a++) {
+               float cur_pat_min[2], cur_pat_max[2];
 
-               if (track->search_min[a] > track->search_max[a])
-                       SWAP(float, track->search_min[a], track->search_max[a]);
+               BKE_tracking_marker_pattern_minmax(&track->markers[a], cur_pat_min, cur_pat_max);
+
+               DO_MINMAX2(cur_pat_min, pat_min, pat_max);
+               DO_MINMAX2(cur_pat_max, pat_min, pat_max);
        }
 
        /* compute the effective pattern size, which differs from the fine resolution
         * pattern size for the pyramid KLT tracker */
        for (a = 0; a < 2; a++) {
-               pat_min[a] = max_pyramid_level_factor * track->pat_min[a];
-               pat_max[a] = max_pyramid_level_factor * track->pat_max[a];
+               eff_pat_min[a] = max_pyramid_level_factor * pat_min[a];
+               eff_pat_max[a] = max_pyramid_level_factor * pat_max[a];
        }
 
        if (event == CLAMP_PAT_DIM) {
                for (a = 0; a < 2; a++) {
                        /* search shouldn't be resized smaller than pattern */
-                       track->search_min[a] = MIN2(pat_min[a], track->search_min[a]);
-                       track->search_max[a] = MAX2(pat_max[a], track->search_max[a]);
+                       track->search_min[a] = MIN2(eff_pat_min[a], track->search_min[a]);
+                       track->search_max[a] = MAX2(eff_pat_max[a], track->search_max[a]);
                }
        }
        else if (event == CLAMP_PAT_POS) {
                float dim[2];
 
-               sub_v2_v2v2(dim, track->pat_max, track->pat_min);
+               sub_v2_v2v2(dim, pat_max, pat_min);
 
+#if 0
+               /* XXX: needs porting, but we need to know marker here, will be ported after a bit
+                *      more global refactoring */
                for (a = 0; a < 2; a++) {
                        /* pattern shouldn't be moved outside of search */
-                       if (pat_min[a] < track->search_min[a]) {
-                               track->pat_min[a] = track->search_min[a] - (pat_min[a] - track->pat_min[a]);
+                       if (eff_pat_min[a] < track->search_min[a]) {
+                               track->pat_min[a] = track->search_min[a] - (eff_pat_min[a] - pat_min[a]);
                                track->pat_max[a] = track->pat_min[a] + dim[a];
                        }
-                       if (track->pat_max[a] > track->search_max[a]) {
-                               track->pat_max[a] = track->search_max[a] - (pat_max[a] - track->pat_max[a]);
+                       if (eff_pat_max[a] > track->search_max[a]) {
+                               track->pat_max[a] = track->search_max[a] - (eff_pat_max[a] - pat_max[a]);
                                track->pat_min[a] = track->pat_max[a] - dim[a];
                        }
                }
+#endif
        }
        else if (event == CLAMP_SEARCH_DIM) {
                for (a = 0; a < 2; a++) {
                        /* search shouldn't be resized smaller than pattern */
-                       track->search_min[a] = MIN2(pat_min[a], track->search_min[a]);
-                       track->search_max[a] = MAX2(pat_max[a], track->search_max[a]);
+                       track->search_min[a] = MIN2(eff_pat_min[a], track->search_min[a]);
+                       track->search_max[a] = MAX2(eff_pat_max[a], track->search_max[a]);
                }
        }
        else if (event == CLAMP_SEARCH_POS) {
@@ -164,42 +172,30 @@ void BKE_tracking_clamp_track(MovieTrackingTrack *track, int event)
 
                for (a = 0; a < 2; a++) {
                        /* search shouldn't be moved inside pattern */
-                       if (track->search_min[a] > pat_min[a]) {
-                               track->search_min[a] = pat_min[a];
+                       if (track->search_min[a] > eff_pat_min[a]) {
+                               track->search_min[a] = eff_pat_min[a];
                                track->search_max[a] = track->search_min[a] + dim[a];
                        }
-                       if (track->search_max[a] < pat_max[a]) {
-                               track->search_max[a] = pat_max[a];
+                       if (track->search_max[a] < eff_pat_max[a]) {
+                               track->search_max[a] = eff_pat_max[a];
                                track->search_min[a] = track->search_max[a] - dim[a];
                        }
                }
        }
        else if (event == CLAMP_PYRAMID_LEVELS || (event == CLAMP_SEARCH_DIM && track->tracker == TRACKER_KLT)) {
                float dim[2];
-               sub_v2_v2v2(dim, track->pat_max, track->pat_min);
+               sub_v2_v2v2(dim, pat_max, pat_min);
                {
                        float search_ratio = 2.3f * max_pyramid_level_factor;
 
                        /* resize the search area to something sensible based
                         * on the number of pyramid levels */
                        for (a = 0; a < 2; a++) {
-                               track->search_min[a] = search_ratio * track->pat_min[a];
-                               track->search_max[a] = search_ratio * track->pat_max[a];
+                               track->search_min[a] = search_ratio * pat_min[a];
+                               track->search_max[a] = search_ratio * pat_max[a];
                        }
                }
        }
-
-       /* marker's center should be in center of pattern */
-       if (event == CLAMP_PAT_DIM || event == CLAMP_PAT_POS) {
-               float dim[2];
-
-               sub_v2_v2v2(dim, track->pat_max, track->pat_min);
-
-               for (a = 0; a < 2; a++) {
-                       track->pat_min[a] = -dim[a] / 2.0f;
-                       track->pat_max[a] = dim[a] / 2.0f;
-               }
-       }
 }
 
 void BKE_tracking_track_flag(MovieTrackingTrack *track, int area, int flag, int clear)
@@ -258,8 +254,14 @@ MovieTrackingTrack *BKE_tracking_add_track(MovieTracking *tracking, ListBase *tr
        marker.pos[1] = y;
        marker.framenr = framenr;
 
-       copy_v2_v2(track->pat_max, pat);
-       negate_v2_v2(track->pat_min, pat);
+       marker.pattern_corners[0][0] = -pat[0];
+       marker.pattern_corners[0][1] = -pat[1];
+
+       marker.pattern_corners[1][0] = pat[0];
+       marker.pattern_corners[1][1] = -pat[1];
+
+       negate_v2_v2(marker.pattern_corners[2], marker.pattern_corners[0]);
+       negate_v2_v2(marker.pattern_corners[3], marker.pattern_corners[1]);
 
        copy_v2_v2(track->search_max, search);
        negate_v2_v2(track->search_min, search);
@@ -337,6 +339,16 @@ void BKE_tracking_delete_marker(MovieTrackingTrack *track, int framenr)
        }
 }
 
+void BKE_tracking_marker_pattern_minmax(MovieTrackingMarker *marker, float min[2], float max[2])
+{
+       INIT_MINMAX2(min, max);
+
+       DO_MINMAX2(marker->pattern_corners[0], min, max);
+       DO_MINMAX2(marker->pattern_corners[1], min, max);
+       DO_MINMAX2(marker->pattern_corners[2], min, max);
+       DO_MINMAX2(marker->pattern_corners[3], min, max);
+}
+
 MovieTrackingMarker *BKE_tracking_get_marker(MovieTrackingTrack *track, int framenr)
 {
        int a = track->markersnr - 1;
@@ -1002,28 +1014,38 @@ MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *u
 
 #ifdef WITH_LIBMV
                                        {
-                                               float patx = (int)((track->pat_max[0] - track->pat_min[0]) * width),
-                                                     paty = (int)((track->pat_max[1] - track->pat_min[1]) * height);
-
-                                               float search_size_x = (track->search_max[0] - track->search_min[0]) * width;
-                                               float search_size_y = (track->search_max[1] - track->search_min[1]) * height;
-                                               float pattern_size_x = (track->pat_max[0] - track->pat_min[0]) * width;
-                                               float pattern_size_y = (track->pat_max[1] - track->pat_min[1]) * height;
-                                               int wndx = (int)patx / 2, wndy = (int)paty / 2;
-                                               int half_wnd = MAX2(wndx, wndy);
-
-                                                       /* compute the maximum pyramid size */
-                                               float search_to_pattern_ratio = MIN2(search_size_x,  search_size_y)
-                                                       / MAX2(pattern_size_x, pattern_size_y);
-                                               float log2_search_to_pattern_ratio = log(floor(search_to_pattern_ratio)) / M_LN2;
-                                               int max_pyramid_levels = floor(log2_search_to_pattern_ratio + 1);
+                                               float search_size_x, search_size_y;
+                                               float pattern_size_x, pattern_size_y;
+                                               float pat_min[2], pat_max[2], patx, paty;
+                                               float search_to_pattern_ratio, log2_search_to_pattern_ratio;
+                                               int wndx, wndy, half_wnd, max_pyramid_levels, level;
+
+                                               struct libmv_RegionTracker *region_tracker;
+
+                                               /* XXX: use boundbox of marker's pattern for now
+                                                *      no idea how it should behave with non-affine tracking */
+                                               BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+
+                                               patx = (int)((pat_max[0] - pat_min[0]) * width);
+                                               paty = (int)((pat_max[1] - pat_min[1]) * height);
+                                               wndx = (int)patx / 2;
+                                               wndy = (int)paty / 2;
+                                               half_wnd = MAX2(wndx, wndy);
+
+                                               search_size_x = (track->search_max[0] - track->search_min[0]) * width;
+                                               search_size_y = (track->search_max[1] - track->search_min[1]) * height;
+                                               pattern_size_x = (pat_max[0] - pat_min[0]) * width;
+                                               pattern_size_y = (pat_max[1] - pat_min[1]) * height;
+
+                                               /* compute the maximum pyramid size */
+                                               search_to_pattern_ratio = MIN2(search_size_x,  search_size_y) / MAX2(pattern_size_x, pattern_size_y);
+                                               log2_search_to_pattern_ratio = log(floor(search_to_pattern_ratio)) / M_LN2;
+                                               max_pyramid_levels = floor(log2_search_to_pattern_ratio + 1);
 
                                                /* try to accommodate the user's choice of pyramid level in a way
                                                 * that doesn't cause the coarsest pyramid pattern to be larger
                                                 * than the search size */
-                                               int level = MIN2(track->pyramid_levels, max_pyramid_levels);
-
-                                               struct libmv_RegionTracker *region_tracker;
+                                               level = MIN2(track->pyramid_levels, max_pyramid_levels);
 
                                                if (track->tracker == TRACKER_KLT) {
                                                        region_tracker = libmv_pyramidRegionTrackerNew(100, level, half_wnd,
@@ -1226,7 +1248,13 @@ static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTracki
 ImBuf *BKE_tracking_get_pattern_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker,
                                       int margin, int anchored, float pos[2], int origin[2])
 {
-       return get_area_imbuf(ibuf, track, marker, track->pat_min, track->pat_max, margin, anchored, pos, origin);
+       float pat_min[2], pat_max[2];
+
+       /* XXX: need to do real quad sampling here, but currently just assume
+        *      corners represents quad pattern */
+       BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+
+       return get_area_imbuf(ibuf, track, marker, pat_min, pat_max, margin, anchored, pos, origin);
 }
 
 ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker,
@@ -1430,7 +1458,7 @@ int BKE_tracking_next(MovieTrackingContext *context)
                if (marker && (marker->flag & MARKER_DISABLED) == 0) {
 #ifdef WITH_LIBMV
                        int width, height, origin[2], tracked = 0, need_readjust = 0;
-                       float pos[2], margin[2], dim[2];
+                       float pos[2], margin[2], dim[2], pat_min[2], pat_max[2];
                        double x1, y1, x2, y2;
                        ImBuf *ibuf = NULL;
                        MovieTrackingMarker marker_new, *marker_keyed;
@@ -1447,7 +1475,8 @@ int BKE_tracking_next(MovieTrackingContext *context)
                                nextfra = curfra + 1;
 
                        /* margin from frame boundaries */
-                       sub_v2_v2v2(dim, track->pat_max, track->pat_min);
+                       BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+                       sub_v2_v2v2(dim, pat_max, pat_min);
                        margin[0] = margin[1] = MAX2(dim[0], dim[1]) / 2.0f;
 
                        margin[0] = MAX2(margin[0], (float)track->margin / ibuf_new->x);
@@ -1509,6 +1538,10 @@ int BKE_tracking_next(MovieTrackingContext *context)
                                        copy_v2_v2(marker_new.pos, marker->pos);
                                }
 
+                               /* XXX: currently trackers does not change corners of a track, so
+                                *      just copy them from previous position */
+                               memcpy(marker_new.pattern_corners, marker->pattern_corners, sizeof(marker_new.pattern_corners));
+
                                marker_new.flag |= MARKER_TRACKED;
                                marker_new.framenr = nextfra;
 
index 1e61aa937d6a2f72a0f1e24c1bc54e356d6f3126..79a09ab6c230851516dca13bce6cd355b23598f7 100644 (file)
@@ -7612,6 +7612,41 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
+       {
+               MovieClip *clip;
+
+               for (clip = main->movieclip.first; clip; clip = clip->id.next) {
+                       MovieTrackingTrack *track;
+
+                       track = clip->tracking.tracks.first;
+                       while (track) {
+                               int i;
+
+                               for (i = 0; i < track->markersnr; i++) {
+                                       MovieTrackingMarker *marker = &track->markers[i];
+
+                                       if (is_zero_v2(marker->pattern_corners[0]) && is_zero_v2(marker->pattern_corners[1]) &&
+                                           is_zero_v2(marker->pattern_corners[3]) && is_zero_v2(marker->pattern_corners[3]))
+                                       {
+                                               marker->pattern_corners[0][0] = track->pat_min[0];
+                                               marker->pattern_corners[0][1] = track->pat_min[1];
+
+                                               marker->pattern_corners[1][0] = track->pat_max[0];
+                                               marker->pattern_corners[1][1] = track->pat_min[1];
+
+                                               marker->pattern_corners[2][0] = track->pat_max[0];
+                                               marker->pattern_corners[2][1] = track->pat_max[1];
+
+                                               marker->pattern_corners[3][0] = track->pat_min[0];
+                                               marker->pattern_corners[3][1] = track->pat_max[1];
+                                       }
+                               }
+
+                               track = track->next;
+                       }
+               }
+       }
+
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
 
index 18f191a46a6ed5b4606cf1ba5f5c4399fd162e0d..1f5e838f0735a1ab2c98e2c1e8e6f96368a13ee2 100644 (file)
@@ -186,6 +186,7 @@ typedef struct {
        MovieClip *clip;
        MovieClipUser *user;                                            /* user of clip */
        MovieTrackingTrack *track;
+       MovieTrackingMarker *marker;
 
        int framenr;                                                            /* current frame number */
        float marker_pos[2];                                            /* position of marker in pixel coords */
@@ -238,9 +239,11 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event)
                ok = TRUE;
        }
        else if (event == B_MARKER_PAT_DIM) {
-               float dim[2], pat_dim[2];
+               float dim[2], pat_dim[2], pat_min[2], pat_max[2];
+
+               BKE_tracking_marker_pattern_minmax(cb->marker, pat_min, pat_max);
 
-               sub_v2_v2v2(pat_dim, cb->track->pat_max, cb->track->pat_min);
+               sub_v2_v2v2(pat_dim, pat_max, pat_min);
 
                dim[0] = cb->track_pat[0] / width;
                dim[1] = cb->track_pat[1] / height;
@@ -248,11 +251,17 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event)
                sub_v2_v2(dim, pat_dim);
                mul_v2_fl(dim, 0.5f);
 
-               cb->track->pat_min[0] -= dim[0];
-               cb->track->pat_min[1] -= dim[1];
+               cb->marker->pattern_corners[0][0] -= dim[0];
+               cb->marker->pattern_corners[0][1] -= dim[1];
+
+               cb->marker->pattern_corners[1][0] += dim[0];
+               cb->marker->pattern_corners[1][1] -= dim[1];
 
-               cb->track->pat_max[0] += dim[0];
-               cb->track->pat_max[1] += dim[1];
+               cb->marker->pattern_corners[2][0] += dim[0];
+               cb->marker->pattern_corners[2][1] += dim[1];
+
+               cb->marker->pattern_corners[3][0] -= dim[0];
+               cb->marker->pattern_corners[3][1] += dim[1];
 
                BKE_tracking_clamp_track(cb->track, CLAMP_PAT_DIM);
 
@@ -337,6 +346,7 @@ void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, P
        MovieTrackingMarker *marker;
        MarkerUpdateCb *cb;
        const char *tip;
+       float pat_min[2], pat_max[2];
 
        if (!ptr->data)
                return;
@@ -366,6 +376,7 @@ void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, P
        cb->clip = clip;
        cb->user = user;
        cb->track = track;
+       cb->marker = marker;
        cb->marker_flag = marker->flag;
        cb->framenr = user->framenr;
 
@@ -383,7 +394,7 @@ void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, P
        }
        else {
                int width, height, step, digits;
-               float pat_dim[2], pat_pos[2], search_dim[2], search_pos[2];
+               float pat_dim[2], search_dim[2], search_pos[2];
                uiLayout *col;
 
                BKE_movieclip_get_size(clip, user, &width, &height);
@@ -399,15 +410,14 @@ void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, P
                step = 100;
                digits = 2;
 
-               sub_v2_v2v2(pat_dim, track->pat_max, track->pat_min);
+               BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+
+               sub_v2_v2v2(pat_dim, pat_max, pat_min);
                sub_v2_v2v2(search_dim, track->search_max, track->search_min);
 
                add_v2_v2v2(search_pos, track->search_max, track->search_min);
                mul_v2_fl(search_pos, 0.5);
 
-               add_v2_v2v2(pat_pos, track->pat_max, track->pat_min);
-               mul_v2_fl(pat_pos, 0.5);
-
                to_pixel_space(cb->marker_pos, marker->pos, width, height);
                to_pixel_space(cb->track_pat, pat_dim, width, height);
                to_pixel_space(cb->track_search, search_dim, width, height);
index f92f639586d64e5f224f732937db8df18d3f8f67..8a9d9313a6cbbace5d3d14e15b09210c688cb262 100644 (file)
@@ -428,14 +428,17 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT
 
        if ((marker->flag & MARKER_DISABLED) == 0) {
                float pos[2];
-               rctf r;
+               float p[2];
 
-               BLI_init_rctf(&r, track->pat_min[0], track->pat_max[0], track->pat_min[1], track->pat_max[1]);
                add_v2_v2v2(pos, marker->pos, track->offset);
 
                ED_clip_point_undistorted_pos(sc, pos, pos);
 
-               if (BLI_in_rctf(&r, pos[0] - marker_pos[0], pos[1] - marker_pos[1])) {
+               sub_v2_v2v2(p, pos, marker_pos);
+
+               if (isect_point_quad_v2(p, marker->pattern_corners[0], marker->pattern_corners[1],
+                                       marker->pattern_corners[2], marker->pattern_corners[3]))
+               {
                        if (tiny) glPointSize(3.0f);
                        else glPointSize(4.0f);
                        glBegin(GL_POINTS);
@@ -471,10 +474,10 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT
 
        if (sc->flag & SC_SHOW_MARKER_PATTERN) {
                glBegin(GL_LINE_LOOP);
-                       glVertex2f(track->pat_min[0], track->pat_min[1]);
-                       glVertex2f(track->pat_max[0], track->pat_min[1]);
-                       glVertex2f(track->pat_max[0], track->pat_max[1]);
-                       glVertex2f(track->pat_min[0], track->pat_max[1]);
+                       glVertex2fv(marker->pattern_corners[0]);
+                       glVertex2fv(marker->pattern_corners[1]);
+                       glVertex2fv(marker->pattern_corners[2]);
+                       glVertex2fv(marker->pattern_corners[3]);
                glEnd();
        }
 
@@ -528,8 +531,7 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
 
        /* marker position and offset position */
        if ((track->flag & SELECT) == sel && (marker->flag & MARKER_DISABLED) == 0) {
-               float pos[2];
-               rctf r;
+               float pos[2], p[2];
 
                if (track->flag & TRACK_LOCKED) {
                        if (act)
@@ -546,11 +548,14 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
                                glColor3fv(col);
                }
 
-               BLI_init_rctf(&r, track->pat_min[0], track->pat_max[0], track->pat_min[1], track->pat_max[1]);
                add_v2_v2v2(pos, marker->pos, track->offset);
                ED_clip_point_undistorted_pos(sc, pos, pos);
 
-               if (BLI_in_rctf(&r, pos[0] - marker_pos[0], pos[1] - marker_pos[1])) {
+               sub_v2_v2v2(p, pos, marker_pos);
+
+               if (isect_point_quad_v2(p, marker->pattern_corners[0], marker->pattern_corners[1],
+                                       marker->pattern_corners[2], marker->pattern_corners[3]))
+               {
                        if (!tiny)
                                glPointSize(2.0f);
 
@@ -623,10 +628,10 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
                }
 
                glBegin(GL_LINE_LOOP);
-                       glVertex2f(track->pat_min[0], track->pat_min[1]);
-                       glVertex2f(track->pat_max[0], track->pat_min[1]);
-                       glVertex2f(track->pat_max[0], track->pat_max[1]);
-                       glVertex2f(track->pat_min[0], track->pat_max[1]);
+                       glVertex2fv(marker->pattern_corners[0]);
+                       glVertex2fv(marker->pattern_corners[1]);
+                       glVertex2fv(marker->pattern_corners[2]);
+                       glVertex2fv(marker->pattern_corners[3]);
                glEnd();
        }
 
@@ -698,10 +703,10 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
                        }
                        /* only draw a pattern for the coarsest level */
                        glBegin(GL_LINE_LOOP);
-                               glVertex2f(track->pat_min[0], track->pat_min[1]);
-                               glVertex2f(track->pat_max[0], track->pat_min[1]);
-                               glVertex2f(track->pat_max[0], track->pat_max[1]);
-                               glVertex2f(track->pat_min[0], track->pat_max[1]);
+                               glVertex2fv(marker->pattern_corners[0]);
+                               glVertex2fv(marker->pattern_corners[1]);
+                               glVertex2fv(marker->pattern_corners[2]);
+                               glVertex2fv(marker->pattern_corners[3]);
                        glEnd();
                        glDisable(GL_LINE_STIPPLE);
                        glPopMatrix();
@@ -717,6 +722,18 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
 static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
                                     float marker_pos[2], int outline, int sel, int act, int width, int height)
 {
+#if 1
+       /* XXX: not re-implemented yet */
+       (void) sc;
+       (void) track;
+       (void) marker;
+       (void) marker_pos;
+       (void) outline;
+       (void) sel;
+       (void) act;
+       (void) width;
+       (void) height;
+#else
        float x, y, dx, dy, patdx, patdy, searchdx, searchdy, tdx, tdy;
        int tiny = sc->flag & SC_SHOW_TINY_MARKER;
        float col[3], scol[3], px[2];
@@ -845,6 +862,7 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
 
        if (outline)
                glLineWidth(1.0f);
+#endif
 }
 
 static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
@@ -881,8 +899,11 @@ static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
                dy = track->search_min[1];
        }
        else if (sc->flag & SC_SHOW_MARKER_PATTERN) {
-               dx = track->pat_min[0];
-               dy = track->pat_min[1];
+               float pat_min[2], pat_max[2];
+
+               BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+               dx = pat_min[0];
+               dy = pat_min[1];
        }
 
        pos[0] = (marker_pos[0] + dx) * width;
index a85d2352fbb03888f1e6c033aa662c52cd808c82..d2bff340b971b264e7a90cdeb08380b1342dda94 100644 (file)
@@ -440,7 +440,8 @@ static void clip_operatortypes(void)
 
        /* markers */
        WM_operatortype_append(CLIP_OT_add_marker);
-       WM_operatortype_append(CLIP_OT_slide_marker);
+       /* XXX: need porting! */
+       //WM_operatortype_append(CLIP_OT_slide_marker);
        WM_operatortype_append(CLIP_OT_delete_track);
        WM_operatortype_append(CLIP_OT_delete_marker);
 
@@ -614,7 +615,8 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", DELKEY, KM_PRESS, KM_SHIFT, 0);
        WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", XKEY, KM_PRESS, KM_SHIFT, 0);
 
-       WM_keymap_add_item(keymap, "CLIP_OT_slide_marker", LEFTMOUSE, KM_PRESS, 0, 0);
+       /* XXX: need porting */
+       //WM_keymap_add_item(keymap, "CLIP_OT_slide_marker", LEFTMOUSE, KM_PRESS, 0, 0);
 
        kmi = WM_keymap_add_item(keymap, "CLIP_OT_disable_markers", DKEY, KM_PRESS, KM_SHIFT, 0);
        RNA_enum_set(kmi->ptr, "action", 2);    /* toggle */
index fc93bcc0409682abcba195cce0c5833f7c81a811..cf88a59f70560ea06d018a904da85a27cdf49d68 100644 (file)
@@ -78,6 +78,8 @@
 
 #include "clip_intern.h"       // own include
 
+static float dist_to_crns(float co[2], float pos[2], float crns[4][2]);
+
 /********************** add marker operator *********************/
 
 static void add_marker(SpaceClip *sc, float x, float y)
@@ -245,6 +247,8 @@ void CLIP_OT_delete_marker(wmOperatorType *ot)
 }
 
 /********************** slide marker operator *********************/
+/* XXX: need porting! */
+#if 0
 
 #define SLIDE_ACTION_POS       0
 #define SLIDE_ACTION_SIZE      1
@@ -646,6 +650,8 @@ void CLIP_OT_slide_marker(wmOperatorType *ot)
                "Offset", "Offset in floating point units, 1.0 is the width and height of the image", -FLT_MAX, FLT_MAX);
 }
 
+#endif
+
 /********************** mouse select operator *********************/
 
 static int mouse_on_side(float co[2], float x1, float y1, float x2, float y2, float epsx, float epsy)
@@ -668,18 +674,28 @@ static int mouse_on_rect(float co[2], float pos[2], float min[2], float max[2],
               mouse_on_side(co, pos[0] + max[0], pos[1] + min[1], pos[0] + max[0], pos[1] + max[1], epsx, epsy);
 }
 
+static int mouse_on_crns(float co[2], float pos[2], float crns[4][2], float epsx, float epsy)
+{
+       float dist = dist_to_crns(co, pos, crns);
+
+       return dist < MAX2(epsx, epsy);
+}
+
 static int track_mouse_area(SpaceClip *sc, float co[2], MovieTrackingTrack *track)
 {
        MovieTrackingMarker *marker = BKE_tracking_get_marker(track, sc->user.framenr);
+       float pat_min[2], pat_max[2];
        float epsx, epsy;
        int width, height;
 
        ED_space_clip_size(sc, &width, &height);
 
-       epsx = MIN4(track->pat_min[0] - track->search_min[0], track->search_max[0] - track->pat_max[0],
-                  fabsf(track->pat_min[0]), fabsf(track->pat_max[0])) / 2;
-       epsy = MIN4(track->pat_min[1] - track->search_min[1], track->search_max[1] - track->pat_max[1],
-                  fabsf(track->pat_min[1]), fabsf(track->pat_max[1])) / 2;
+       BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+
+       epsx = MIN4(pat_min[0] - track->search_min[0], track->search_max[0] - pat_max[0],
+                   fabsf(pat_min[0]), fabsf(pat_max[0])) / 2;
+       epsy = MIN4(pat_min[1] - track->search_min[1], track->search_max[1] - pat_max[1],
+                   fabsf(pat_min[1]), fabsf(pat_max[1])) / 2;
 
        epsx = MAX2(epsx, 2.0f / width);
        epsy = MAX2(epsy, 2.0f / height);
@@ -691,7 +707,7 @@ static int track_mouse_area(SpaceClip *sc, float co[2], MovieTrackingTrack *trac
 
        if ((marker->flag & MARKER_DISABLED) == 0) {
                if (sc->flag & SC_SHOW_MARKER_PATTERN)
-                       if (mouse_on_rect(co, marker->pos, track->pat_min, track->pat_max, epsx, epsy))
+                       if (mouse_on_crns(co, marker->pos, marker->pattern_corners, epsx, epsy))
                                return TRACK_AREA_PAT;
 
                epsx = 12.0f / width;
@@ -722,6 +738,21 @@ static float dist_to_rect(float co[2], float pos[2], float min[2], float max[2])
        return MIN4(d1, d2, d3, d4);
 }
 
+static float dist_to_crns(float co[2], float pos[2], float crns[4][2])
+{
+       float d1, d2, d3, d4;
+       float p[2] = {co[0] - pos[0], co[1] - pos[1]};
+       float *v1 = crns[0], *v2 = crns[1],
+             *v3 = crns[2], *v4 = crns[3];
+
+       d1 = dist_to_line_segment_v2(p, v1, v2);
+       d2 = dist_to_line_segment_v2(p, v2, v3);
+       d3 = dist_to_line_segment_v2(p, v3, v4);
+       d4 = dist_to_line_segment_v2(p, v4, v1);
+
+       return MIN4(d1, d2, d3, d4);
+}
+
 static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, ListBase *tracksbase, float co[2])
 {
        MovieTrackingTrack *track = NULL, *cur;
@@ -736,11 +767,11 @@ static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, ListBase *tracksbas
 
                        /* distance to marker point */
                        d1 = sqrtf((co[0] - marker->pos[0] - cur->offset[0]) * (co[0] - marker->pos[0] - cur->offset[0]) +
-                                         (co[1] - marker->pos[1] - cur->offset[1]) * (co[1] - marker->pos[1] - cur->offset[1]));
+                                          (co[1] - marker->pos[1] - cur->offset[1]) * (co[1] - marker->pos[1] - cur->offset[1]));
 
                        /* distance to pattern boundbox */
                        if (sc->flag & SC_SHOW_MARKER_PATTERN)
-                               d2 = dist_to_rect(co, marker->pos, cur->pat_min, cur->pat_max);
+                               d2 = dist_to_crns(co, marker->pos, marker->pattern_corners);
 
                        /* distance to search boundbox */
                        if (sc->flag & SC_SHOW_MARKER_SEARCH && TRACK_VIEW_SELECTED(sc, cur))
@@ -822,6 +853,8 @@ static int select_invoke(bContext *C, wmOperator *op, wmEvent *event)
        int extend = RNA_boolean_get(op->ptr, "extend");
 
        if (!extend) {
+#if 0
+               /* XXX: need porting */
                SlideMarkerData *slidedata = slide_marker_customdata(C, event);
 
                if (slidedata) {
@@ -836,6 +869,7 @@ static int select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
                        return OPERATOR_PASS_THROUGH;
                }
+#endif
        }
 
        ED_clip_mouse_pos(C, event, co);
index 661f6ba7842224458088a1eaa9674009c7435b2a..7949ecd5d1996d9d4964d9de3a7e5bd11ed472ed 100644 (file)
@@ -5420,8 +5420,10 @@ static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d,
                markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, marker->pos, NULL, NULL);
 
        if (track->pat_flag & SELECT) {
-               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, track->pat_min, marker->pos, NULL);
-               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, track->pat_max, marker->pos, NULL);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, marker->pattern_corners[0], marker->pos, NULL);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, marker->pattern_corners[1], marker->pos, NULL);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, marker->pattern_corners[2], marker->pos, NULL);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, marker->pattern_corners[3], marker->pos, NULL);
        }
 
        if (track->search_flag & SELECT) {
@@ -5468,7 +5470,7 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
                                t->total++;
 
                        if (track->pat_flag & SELECT)
-                               t->total+= 2;
+                               t->total+= 4;
 
                        if (track->search_flag & SELECT)
                                t->total+= 2;
@@ -5507,9 +5509,9 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
                                }
 
                                if (track->pat_flag & SELECT) {
-                                       td += 2;
-                                       td2d += 2;
-                                       tdt +=2;
+                                       td += 4;
+                                       td2d += 4;
+                                       tdt += 4;
                                }
                        }
 
index 6bf059c7ecb7dad0f5b40290c12522cf64c82bf8..1e7552f918fc0555da683ce9e59b4fe66eee8431 100644 (file)
@@ -35,6 +35,7 @@
 #ifndef __DNA_TRACKING_TYPES_H__
 #define __DNA_TRACKING_TYPES_H__
 
+#include "DNA_defs.h"
 #include "DNA_listBase.h"
 
 /* match-moving data */
@@ -68,6 +69,20 @@ typedef struct MovieTrackingCamera {
 
 typedef struct MovieTrackingMarker {
        float pos[2];   /* 2d position of marker on frame (in unified 0..1 space) */
+
+       /* corners of pattern in the following order:
+        *
+        * Y
+        * ^
+        * | (3) --- (2)
+        * |  |       |
+        * |  |       |
+        * |  |       |
+        * | (0) --- (1)
+        * +-------------> X
+        */
+       float pattern_corners[4][2];
+
        int framenr;    /* number of frame marker is associated with */
        int flag;               /* Marker's flag (alive, ...) */
 } MovieTrackingMarker;
@@ -78,8 +93,13 @@ typedef struct MovieTrackingTrack {
        char name[64];  /* MAX_NAME */
 
        /* ** setings ** */
-       float pat_min[2], pat_max[2];           /* positions of left-bottom and right-top corners of pattern (in unified 0..1 space) */
-       float search_min[2], search_max[2];     /* positions of left-bottom and right-top corners of search area (in unified 0..1 space) */
+
+       /* positions of left-bottom and right-top corners of pattern (in unified 0..1 space) */
+       float pat_min[2], pat_max[2]            DNA_DEPRECATED;
+
+       /* positions of left-bottom and right-top corners of search area (in unified 0..1 space) */
+       float search_min[2], search_max[2];
+
        float offset[2];                                        /* offset to "parenting" point */
 
        /* ** track ** */