diff options
Diffstat (limited to 'source/blender/editors/space_clip')
-rw-r--r-- | source/blender/editors/space_clip/clip_graph_draw.c | 220 | ||||
-rw-r--r-- | source/blender/editors/space_clip/clip_graph_ops.c | 55 | ||||
-rw-r--r-- | source/blender/editors/space_clip/clip_intern.h | 57 | ||||
-rw-r--r-- | source/blender/editors/space_clip/clip_ops.c | 39 | ||||
-rw-r--r-- | source/blender/editors/space_clip/clip_utils.c | 178 | ||||
-rw-r--r-- | source/blender/editors/space_clip/space_clip.c | 12 | ||||
-rw-r--r-- | source/blender/editors/space_clip/tracking_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_clip/tracking_ops_orient.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_clip/tracking_ops_solve.c | 11 |
9 files changed, 330 insertions, 254 deletions
diff --git a/source/blender/editors/space_clip/clip_graph_draw.c b/source/blender/editors/space_clip/clip_graph_draw.c index ef5de1acee3..3f705aad89a 100644 --- a/source/blender/editors/space_clip/clip_graph_draw.c +++ b/source/blender/editors/space_clip/clip_graph_draw.c @@ -48,6 +48,7 @@ #include "clip_intern.h" // own include typedef struct TrackMotionCurveUserData { + SpaceClip *sc; MovieTrackingTrack *act_track; bool sel; float xscale, yscale, hsize; @@ -57,24 +58,43 @@ typedef struct TrackMotionCurveUserData { static void tracking_segment_point_cb(void *userdata, MovieTrackingTrack *UNUSED(track), MovieTrackingMarker *UNUSED(marker), - int UNUSED(coord), + eClipCurveValueSource value_source, int scene_framenr, float val) { TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata; + if (!clip_graph_value_visible(data->sc, value_source)) { + return; + } + immVertex2f(data->pos, scene_framenr, val); } static void tracking_segment_start_cb(void *userdata, MovieTrackingTrack *track, - int coord, + eClipCurveValueSource value_source, bool is_point) { TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata; + SpaceClip *sc = data->sc; float col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - col[coord] = 1.0f; + if (!clip_graph_value_visible(sc, value_source)) { + return; + } + + switch (value_source) { + case CLIP_VALUE_SOURCE_SPEED_X: + col[0] = 1.0f; + break; + case CLIP_VALUE_SOURCE_SPEED_Y: + col[1] = 1.0f; + break; + case CLIP_VALUE_SOURCE_REPROJECTION_ERROR: + col[2] = 1.0f; + break; + } if (track == data->act_track) { col[3] = 1.0f; @@ -96,15 +116,20 @@ static void tracking_segment_start_cb(void *userdata, } } -static void tracking_segment_end_cb(void *UNUSED(userdata), int UNUSED(coord)) +static void tracking_segment_end_cb(void *userdata, eClipCurveValueSource value_source) { + TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata; + SpaceClip *sc = data->sc; + if (!clip_graph_value_visible(sc, value_source)) { + return; + } immEnd(); } static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int coord, + eClipCurveValueSource value_source, int scene_framenr, float val) { @@ -114,8 +139,11 @@ static void tracking_segment_knot_cb(void *userdata, if (track != data->act_track) { return; } + if (!ELEM(value_source, CLIP_VALUE_SOURCE_SPEED_X, CLIP_VALUE_SOURCE_SPEED_Y)) { + return; + } - sel_flag = coord == 0 ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y; + sel_flag = value_source == CLIP_VALUE_SOURCE_SPEED_X ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y; sel = (marker->flag & sel_flag) ? 1 : 0; if (sel == data->sel) { @@ -131,34 +159,39 @@ static void tracking_segment_knot_cb(void *userdata, } } -static void draw_tracks_motion_curves(View2D *v2d, SpaceClip *sc, unsigned int pos) +static void draw_tracks_motion_and_error_curves(View2D *v2d, SpaceClip *sc, unsigned int pos) { MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking); - int width, height; - TrackMotionCurveUserData userdata; + const bool draw_knots = (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0; + int width, height; BKE_movieclip_get_size(clip, &sc->user, &width, &height); - if (!width || !height) { return; } - /* non-selected knot handles */ + TrackMotionCurveUserData userdata; + userdata.sc = sc; userdata.hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE); userdata.sel = false; userdata.act_track = act_track; userdata.pos = pos; - UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale); - clip_graph_tracking_values_iterate(sc, - (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, - (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, - &userdata, - tracking_segment_knot_cb, - NULL, - NULL); - /* draw graph lines */ + + /* Non-selected knot handles. */ + if (draw_knots) { + UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale); + clip_graph_tracking_values_iterate(sc, + (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, + (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, + &userdata, + tracking_segment_knot_cb, + NULL, + NULL); + } + + /* Draw graph lines. */ GPU_blend(true); clip_graph_tracking_values_iterate(sc, (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, @@ -169,138 +202,19 @@ static void draw_tracks_motion_curves(View2D *v2d, SpaceClip *sc, unsigned int p tracking_segment_end_cb); GPU_blend(false); - /* selected knot handles on top of curves */ - userdata.sel = true; - clip_graph_tracking_values_iterate(sc, - (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, - (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, - &userdata, - tracking_segment_knot_cb, - NULL, - NULL); -} - -typedef struct TrackErrorCurveUserData { - MovieClip *clip; - MovieTracking *tracking; - MovieTrackingObject *tracking_object; - MovieTrackingTrack *active_track; - bool matrix_initialized; - int matrix_frame; - float projection_matrix[4][4]; - int width, height; - float aspy; - unsigned int pos; -} TrackErrorCurveUserData; - -static void tracking_error_segment_point_cb(void *userdata, - MovieTrackingTrack *track, - MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float UNUSED(value)) -{ - if (coord == 1) { - TrackErrorCurveUserData *data = (TrackErrorCurveUserData *)userdata; - float reprojected_position[4], bundle_position[4], marker_position[2], delta[2]; - float reprojection_error; - float weight = BKE_tracking_track_get_weight_for_marker(data->clip, track, marker); - - if (!data->matrix_initialized || data->matrix_frame != scene_framenr) { - BKE_tracking_get_projection_matrix(data->tracking, - data->tracking_object, - scene_framenr, - data->width, - data->height, - data->projection_matrix); - } - - copy_v3_v3(bundle_position, track->bundle_pos); - bundle_position[3] = 1; - - mul_v4_m4v4(reprojected_position, data->projection_matrix, bundle_position); - reprojected_position[0] = (reprojected_position[0] / (reprojected_position[3] * 2.0f) + 0.5f) * - data->width; - reprojected_position[1] = (reprojected_position[1] / (reprojected_position[3] * 2.0f) + 0.5f) * - data->height * data->aspy; - - BKE_tracking_distort_v2(data->tracking, reprojected_position, reprojected_position); - - marker_position[0] = (marker->pos[0] + track->offset[0]) * data->width; - marker_position[1] = (marker->pos[1] + track->offset[1]) * data->height * data->aspy; - - sub_v2_v2v2(delta, reprojected_position, marker_position); - reprojection_error = len_v2(delta) * weight; - - immVertex2f(data->pos, scene_framenr, reprojection_error); - } -} - -static void tracking_error_segment_start_cb(void *userdata, - MovieTrackingTrack *track, - int coord, - bool is_point) -{ - if (coord == 1) { - TrackErrorCurveUserData *data = (TrackErrorCurveUserData *)userdata; - float col[4] = {0.0f, 0.0f, 1.0f, 1.0f}; - - if (track == data->active_track) { - col[3] = 1.0f; - GPU_line_width(2.0f); - } - else { - col[3] = 0.5f; - GPU_line_width(1.0f); - } - - immUniformColor4fv(col); - - if (is_point) { /* This probably never happens here, but just in case... */ - immBeginAtMost(GPU_PRIM_POINTS, 1); - } - else { - /* Graph can be composed of smaller segments, if any marker is disabled */ - immBeginAtMost(GPU_PRIM_LINE_STRIP, track->markersnr); - } - } -} - -static void tracking_error_segment_end_cb(void *UNUSED(userdata), int coord) -{ - if (coord == 1) { - immEnd(); + /* Selected knot handles on top of curves. */ + if (draw_knots) { + userdata.sel = true; + clip_graph_tracking_values_iterate(sc, + (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, + (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, + &userdata, + tracking_segment_knot_cb, + NULL, + NULL); } } -static void draw_tracks_error_curves(SpaceClip *sc, unsigned int pos) -{ - MovieClip *clip = ED_space_clip_get_clip(sc); - MovieTracking *tracking = &clip->tracking; - TrackErrorCurveUserData data; - - data.clip = clip; - data.tracking = tracking; - data.tracking_object = BKE_tracking_object_get_active(tracking); - data.active_track = BKE_tracking_track_get_active(tracking); - data.matrix_initialized = false; - data.pos = pos; - BKE_movieclip_get_size(clip, &sc->user, &data.width, &data.height); - data.aspy = 1.0f / tracking->camera.pixel_aspect; - - if (!data.width || !data.height) { - return; - } - - clip_graph_tracking_values_iterate(sc, - (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, - (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, - &data, - tracking_error_segment_point_cb, - tracking_error_segment_start_cb, - tracking_error_segment_end_cb); -} - static void draw_frame_curves(SpaceClip *sc, unsigned int pos) { MovieClip *clip = ED_space_clip_get_clip(sc); @@ -350,12 +264,8 @@ void clip_draw_graph(SpaceClip *sc, ARegion *ar, Scene *scene) GPU_point_size(3.0f); - if (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) { - draw_tracks_motion_curves(v2d, sc, pos); - } - - if (sc->flag & SC_SHOW_GRAPH_TRACKS_ERROR) { - draw_tracks_error_curves(sc, pos); + if (sc->flag & (SC_SHOW_GRAPH_TRACKS_MOTION | SC_SHOW_GRAPH_TRACKS_ERROR)) { + draw_tracks_motion_and_error_curves(v2d, sc, pos); } if (sc->flag & SC_SHOW_GRAPH_FRAMES) { diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c index a3722433e33..58a00d2e6b9 100644 --- a/source/blender/editors/space_clip/clip_graph_ops.c +++ b/source/blender/editors/space_clip/clip_graph_ops.c @@ -64,7 +64,7 @@ static bool clip_graph_knots_poll(bContext *C) if (ED_space_clip_graph_poll(C)) { SpaceClip *sc = CTX_wm_space_clip(C); - return (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0; + return (sc->flag & (SC_SHOW_GRAPH_TRACKS_MOTION | SC_SHOW_GRAPH_TRACKS_ERROR)) != 0; } return false; } @@ -93,13 +93,14 @@ static void toggle_selection_cb(void *userdata, MovieTrackingMarker *marker) /******************** mouse select operator ********************/ typedef struct { - int coord; /* coordinate index of found entuty (0 = X-axis, 1 = Y-axis) */ + SpaceClip *sc; + eClipCurveValueSource value_source; bool has_prev; /* if there's valid coordinate of previous point of curve segment */ - float min_dist_sq, /* minimal distance between mouse and currently found entity */ - mouse_co[2], /* mouse coordinate */ - prev_co[2], /* coordinate of previeous point of segment */ - min_co[2]; /* coordinate of entity with minimal distance */ + float min_dist_sq; /* minimal distance between mouse and currently found entity */ + float mouse_co[2]; /* mouse coordinate */ + float prev_co[2]; /* coordinate of previous point of segment */ + float min_co[2]; /* coordinate of entity with minimal distance */ MovieTrackingTrack *track; /* nearest found track */ MovieTrackingMarker *marker; /* nearest found marker */ @@ -108,20 +109,24 @@ typedef struct { static void find_nearest_tracking_segment_cb(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *UNUSED(marker), - int coord, + eClipCurveValueSource value_source, int scene_framenr, float val) { MouseSelectUserData *data = userdata; float co[2] = {scene_framenr, val}; + if (!clip_graph_value_visible(data->sc, value_source)) { + return; + } + if (data->has_prev) { float dist_sq = dist_squared_to_line_segment_v2(data->mouse_co, data->prev_co, co); if (data->track == NULL || dist_sq < data->min_dist_sq) { data->track = track; data->min_dist_sq = dist_sq; - data->coord = coord; + data->value_source = value_source; copy_v2_v2(data->min_co, co); } } @@ -130,7 +135,8 @@ static void find_nearest_tracking_segment_cb(void *userdata, copy_v2_v2(data->prev_co, co); } -static void find_nearest_tracking_segment_end_cb(void *userdata, int UNUSED(coord)) +static void find_nearest_tracking_segment_end_cb(void *userdata, + eClipCurveValueSource UNUSED(source_value)) { MouseSelectUserData *data = userdata; @@ -140,7 +146,7 @@ static void find_nearest_tracking_segment_end_cb(void *userdata, int UNUSED(coor static void find_nearest_tracking_knot_cb(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int coord, + eClipCurveValueSource value_source, int scene_framenr, float val) { @@ -148,20 +154,26 @@ static void find_nearest_tracking_knot_cb(void *userdata, float mdiff[2] = {scene_framenr - data->mouse_co[0], val - data->mouse_co[1]}; float dist_sq = len_squared_v2(mdiff); + if (!clip_graph_value_visible(data->sc, value_source)) { + return; + } + if (data->marker == NULL || dist_sq < data->min_dist_sq) { float co[2] = {scene_framenr, val}; data->track = track; data->marker = marker; data->min_dist_sq = dist_sq; - data->coord = coord; + data->value_source = value_source; copy_v2_v2(data->min_co, co); } } -static void mouse_select_init_data(MouseSelectUserData *userdata, const float co[2]) +static void mouse_select_init_data(bContext *C, MouseSelectUserData *userdata, const float co[2]) { + SpaceClip *sc = CTX_wm_space_clip(C); memset(userdata, 0, sizeof(MouseSelectUserData)); + userdata->sc = sc; userdata->min_dist_sq = FLT_MAX; copy_v2_v2(userdata->mouse_co, co); } @@ -179,7 +191,7 @@ static bool mouse_select_knot(bContext *C, float co[2], bool extend) if (act_track) { MouseSelectUserData userdata; - mouse_select_init_data(&userdata, co); + mouse_select_init_data(C, &userdata, co); clip_graph_tracking_values_iterate_track( sc, act_track, &userdata, find_nearest_tracking_knot_cb, NULL, NULL); @@ -199,7 +211,7 @@ static bool mouse_select_knot(bContext *C, float co[2], bool extend) toggle_selection_cb); } - if (userdata.coord == 0) { + if (userdata.value_source == CLIP_VALUE_SOURCE_SPEED_X) { if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_X) != 0) { userdata.marker->flag &= ~MARKER_GRAPH_SEL_X; } @@ -207,7 +219,7 @@ static bool mouse_select_knot(bContext *C, float co[2], bool extend) userdata.marker->flag |= MARKER_GRAPH_SEL_X; } } - else { + else if (userdata.value_source == CLIP_VALUE_SOURCE_SPEED_Y) { if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_Y) != 0) { userdata.marker->flag &= ~MARKER_GRAPH_SEL_Y; } @@ -232,7 +244,7 @@ static bool mouse_select_curve(bContext *C, float co[2], bool extend) MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking); MouseSelectUserData userdata; - mouse_select_init_data(&userdata, co); + mouse_select_init_data(C, &userdata, co); clip_graph_tracking_values_iterate(sc, (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, @@ -281,7 +293,7 @@ static int mouse_select(bContext *C, float co[2], bool extend) sel = mouse_select_knot(C, co, extend); if (!sel) { - /* if there's no close enough knot to mouse osition, select nearest curve */ + /* if there's no close enough knot to mouse position, select nearest curve */ sel = mouse_select_curve(C, co, extend); } @@ -356,16 +368,19 @@ typedef struct BoxSelectuserData { static void box_select_cb(void *userdata, MovieTrackingTrack *UNUSED(track), MovieTrackingMarker *marker, - int coord, + eClipCurveValueSource value_source, int scene_framenr, float val) { BoxSelectuserData *data = (BoxSelectuserData *)userdata; + if (!ELEM(value_source, CLIP_VALUE_SOURCE_SPEED_X, CLIP_VALUE_SOURCE_SPEED_Y)) { + return; + } if (BLI_rctf_isect_pt(&data->rect, scene_framenr, val)) { int flag = 0; - if (coord == 0) { + if (value_source == CLIP_VALUE_SOURCE_SPEED_X) { flag = MARKER_GRAPH_SEL_X; } else { @@ -591,7 +606,7 @@ typedef struct { static void view_all_cb(void *userdata, MovieTrackingTrack *UNUSED(track), MovieTrackingMarker *UNUSED(marker), - int UNUSED(coord), + eClipCurveValueSource UNUSED(value_source), int UNUSED(scene_framenr), float val) { diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index 7683823a79f..8599de9f16f 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -112,35 +112,44 @@ void CLIP_OT_cursor_set(struct wmOperatorType *ot); struct ARegion *ED_clip_has_properties_region(struct ScrArea *sa); /* clip_utils.c */ -void clip_graph_tracking_values_iterate_track( - struct SpaceClip *sc, - struct MovieTrackingTrack *track, - void *userdata, - void (*func)(void *userdata, - struct MovieTrackingTrack *track, - struct MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float val), - void (*segment_start)( - void *userdata, struct MovieTrackingTrack *track, int coord, bool is_point), - void (*segment_end)(void *userdata, int coord)); + +typedef enum { + CLIP_VALUE_SOURCE_SPEED_X, + CLIP_VALUE_SOURCE_SPEED_Y, + CLIP_VALUE_SOURCE_REPROJECTION_ERROR, +} eClipCurveValueSource; + +typedef void (*ClipTrackValueCallback)(void *userdata, + struct MovieTrackingTrack *track, + struct MovieTrackingMarker *marker, + eClipCurveValueSource value_source, + int scene_framenr, + float val); + +typedef void (*ClipTrackValueSegmentStartCallback)(void *userdata, + struct MovieTrackingTrack *track, + eClipCurveValueSource value_source, + bool is_point); + +typedef void (*ClipTrackValueSegmentEndCallback)(void *userdata, + eClipCurveValueSource value_source); + +bool clip_graph_value_visible(struct SpaceClip *sc, eClipCurveValueSource value_source); + +void clip_graph_tracking_values_iterate_track(struct SpaceClip *sc, + struct MovieTrackingTrack *track, + void *userdata, + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end); void clip_graph_tracking_values_iterate(struct SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata, - void (*func)(void *userdata, - struct MovieTrackingTrack *track, - struct MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float val), - void (*segment_start)(void *userdata, - struct MovieTrackingTrack *track, - int coord, - bool is_point), - void (*segment_end)(void *userdata, int coord)); + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end); void clip_graph_tracking_iterate(struct SpaceClip *sc, bool selected_only, diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 45479c4253d..5f04d0863a7 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -626,36 +626,35 @@ static void view_zoom_apply( bContext *C, ViewZoomData *vpd, wmOperator *op, const wmEvent *event, const bool zoom_to_pos) { float factor; + float delta; - if (U.viewzoom == USER_ZOOM_CONT) { - SpaceClip *sclip = CTX_wm_space_clip(C); - double time = PIL_check_seconds_timer(); - float time_step = (float)(time - vpd->timer_lastdraw); - float fac; - float zfac; - + if (U.viewzoom != USER_ZOOM_SCALE) { if (U.uiflag & USER_ZOOM_HORIZ) { - fac = (float)(event->x - vpd->x); + delta = (float)(event->x - vpd->x); } else { - fac = (float)(event->y - vpd->y); + delta = (float)(event->y - vpd->y); } + } + else { + delta = event->x - vpd->x + event->y - vpd->y; + } - if (U.uiflag & USER_ZOOM_INVERT) { - fac = -fac; - } + if (U.uiflag & USER_ZOOM_INVERT) { + delta = -delta; + } - zfac = 1.0f + ((fac / 20.0f) * time_step); + if (U.viewzoom == USER_ZOOM_CONT) { + SpaceClip *sclip = CTX_wm_space_clip(C); + double time = PIL_check_seconds_timer(); + float time_step = (float)(time - vpd->timer_lastdraw); + float zfac; + + zfac = 1.0f + ((delta / 20.0f) * time_step); vpd->timer_lastdraw = time; factor = (sclip->zoom * zfac) / vpd->zoom; } else { - float delta = event->x - vpd->x + event->y - vpd->y; - - if (U.uiflag & USER_ZOOM_INVERT) { - delta *= -1; - } - factor = 1.0f + delta / 300.0f; } @@ -1434,7 +1433,7 @@ static void proxy_endjob(void *pjv) if (pj->clip->source == MCLIP_SRC_MOVIE) { /* Timecode might have changed, so do a full reload to deal with this. */ - BKE_movieclip_reload(pj->main, pj->clip); + DEG_id_tag_update(&pj->clip->id, ID_RECALC_SOURCE); } else { /* For image sequences we'll preserve original cache. */ diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c index 3dfe529f8e8..48f788e2e3a 100644 --- a/source/blender/editors/space_clip/clip_utils.c +++ b/source/blender/editors/space_clip/clip_utils.c @@ -27,6 +27,7 @@ #include "BLI_utildefines.h" #include "BLI_listbase.h" +#include "BLI_math.h" #include "BKE_animsys.h" #include "BKE_context.h" @@ -52,18 +53,28 @@ #include "clip_intern.h" // own include -void clip_graph_tracking_values_iterate_track( +bool clip_graph_value_visible(SpaceClip *sc, eClipCurveValueSource value_source) +{ + if (ELEM(value_source, CLIP_VALUE_SOURCE_SPEED_X, CLIP_VALUE_SOURCE_SPEED_Y)) { + if ((sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) == 0) { + return false; + } + } + else if (value_source == CLIP_VALUE_SOURCE_REPROJECTION_ERROR) { + if ((sc->flag & SC_SHOW_GRAPH_TRACKS_ERROR) == 0) { + return false; + } + } + return true; +} + +static void clip_graph_tracking_values_iterate_track_speed_values( SpaceClip *sc, MovieTrackingTrack *track, void *userdata, - void (*func)(void *userdata, - MovieTrackingTrack *track, - MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float val), - void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point), - void (*segment_end)(void *userdata, int coord)) + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end) { MovieClip *clip = ED_space_clip_get_clip(sc); int width, height, coord; @@ -71,6 +82,8 @@ void clip_graph_tracking_values_iterate_track( BKE_movieclip_get_size(clip, &sc->user, &width, &height); for (coord = 0; coord < 2; coord++) { + eClipCurveValueSource value_source = (coord == 0) ? CLIP_VALUE_SOURCE_SPEED_X : + CLIP_VALUE_SOURCE_SPEED_Y; int i, prevfra = track->markers[0].framenr; bool open = false; float prevval = 0.0f; @@ -82,7 +95,7 @@ void clip_graph_tracking_values_iterate_track( if (marker->flag & MARKER_DISABLED) { if (open) { if (segment_end) { - segment_end(userdata, coord); + segment_end(userdata, value_source); } open = false; @@ -94,10 +107,11 @@ void clip_graph_tracking_values_iterate_track( if (!open) { if (segment_start) { if ((i + 1) == track->markersnr) { - segment_start(userdata, track, coord, true); + segment_start(userdata, track, value_source, true); } else { - segment_start(userdata, track, coord, (track->markers[i + 1].flag & MARKER_DISABLED)); + segment_start( + userdata, track, value_source, (track->markers[i + 1].flag & MARKER_DISABLED)); } } @@ -112,7 +126,7 @@ void clip_graph_tracking_values_iterate_track( if (func) { int scene_framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr); - func(userdata, track, marker, coord, scene_framenr, val); + func(userdata, track, marker, value_source, scene_framenr, val); } prevval = marker->pos[coord]; @@ -121,25 +135,139 @@ void clip_graph_tracking_values_iterate_track( if (open) { if (segment_end) { - segment_end(userdata, coord); + segment_end(userdata, value_source); } } } } -void clip_graph_tracking_values_iterate( +static float calculate_reprojection_error_at_marker(MovieClip *clip, + MovieTracking *tracking, + MovieTrackingObject *tracking_object, + MovieTrackingTrack *track, + MovieTrackingMarker *marker, + const int clip_width, + const int clip_height, + const int scene_framenr) +{ + float reprojected_position[4], bundle_position[4], marker_position[2], delta[2]; + float weight = BKE_tracking_track_get_weight_for_marker(clip, track, marker); + const float aspy = 1.0f / tracking->camera.pixel_aspect; + + float projection_matrix[4][4]; + BKE_tracking_get_projection_matrix( + tracking, tracking_object, scene_framenr, clip_width, clip_height, projection_matrix); + + copy_v3_v3(bundle_position, track->bundle_pos); + bundle_position[3] = 1; + + mul_v4_m4v4(reprojected_position, projection_matrix, bundle_position); + reprojected_position[0] = (reprojected_position[0] / (reprojected_position[3] * 2.0f) + 0.5f) * + clip_width; + reprojected_position[1] = (reprojected_position[1] / (reprojected_position[3] * 2.0f) + 0.5f) * + clip_height * aspy; + + BKE_tracking_distort_v2(tracking, reprojected_position, reprojected_position); + + marker_position[0] = (marker->pos[0] + track->offset[0]) * clip_width; + marker_position[1] = (marker->pos[1] + track->offset[1]) * clip_height * aspy; + + sub_v2_v2v2(delta, reprojected_position, marker_position); + return len_v2(delta) * weight; +} + +static void clip_graph_tracking_values_iterate_track_reprojection_error_values( SpaceClip *sc, - bool selected_only, - bool include_hidden, + MovieTrackingTrack *track, void *userdata, - void (*func)(void *userdata, - MovieTrackingTrack *track, - MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float val), - void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point), - void (*segment_end)(void *userdata, int coord)) + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end) +{ + /* Tracks without bundle can not have any reprojection error curve. */ + if ((track->flag & TRACK_HAS_BUNDLE) == 0) { + return; + } + + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking); + + int clip_width, clip_height; + BKE_movieclip_get_size(clip, &sc->user, &clip_width, &clip_height); + + /* Iterate over segments. */ + bool is_segment_open = false; + for (int marker_index = 0; marker_index < track->markersnr; marker_index++) { + MovieTrackingMarker *marker = &track->markers[marker_index]; + + /* End of tracked segment, no reprojection error can be calculated here since the ground truth + * 2D position is not known. */ + if (marker->flag & MARKER_DISABLED) { + if (is_segment_open) { + if (segment_end != NULL) { + segment_end(userdata, CLIP_VALUE_SOURCE_REPROJECTION_ERROR); + } + is_segment_open = false; + } + continue; + } + + /* Begin new segment if it is not open yet. */ + if (!is_segment_open) { + if (segment_start != NULL) { + if ((marker_index + 1) == track->markersnr) { + segment_start(userdata, track, CLIP_VALUE_SOURCE_REPROJECTION_ERROR, true); + } + else { + segment_start(userdata, + track, + CLIP_VALUE_SOURCE_REPROJECTION_ERROR, + (track->markers[marker_index + 1].flag & MARKER_DISABLED)); + } + } + is_segment_open = true; + } + + if (func != NULL) { + const int scene_framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr); + const float reprojection_error = calculate_reprojection_error_at_marker( + clip, tracking, tracking_object, track, marker, clip_width, clip_height, scene_framenr); + func(userdata, + track, + marker, + CLIP_VALUE_SOURCE_REPROJECTION_ERROR, + scene_framenr, + reprojection_error); + } + } + + if (is_segment_open && segment_end != NULL) { + segment_end(userdata, CLIP_VALUE_SOURCE_REPROJECTION_ERROR); + } +} + +void clip_graph_tracking_values_iterate_track(SpaceClip *sc, + MovieTrackingTrack *track, + void *userdata, + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end) +{ + clip_graph_tracking_values_iterate_track_speed_values( + sc, track, userdata, func, segment_start, segment_end); + + clip_graph_tracking_values_iterate_track_reprojection_error_values( + sc, track, userdata, func, segment_start, segment_end); +} + +void clip_graph_tracking_values_iterate(SpaceClip *sc, + bool selected_only, + bool include_hidden, + void *userdata, + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end) { MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index 7e19ac255f0..c1cb975447f 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -556,17 +556,17 @@ static void clip_operatortypes(void) static void clip_keymap(struct wmKeyConfig *keyconf) { - /* ******** Global hotkeys avalaible for all regions ******** */ + /* ******** Global hotkeys available for all regions ******** */ WM_keymap_ensure(keyconf, "Clip", SPACE_CLIP, 0); - /* ******** Hotkeys avalaible for main region only ******** */ + /* ******** Hotkeys available for main region only ******** */ WM_keymap_ensure(keyconf, "Clip Editor", SPACE_CLIP, 0); // keymap->poll = ED_space_clip_tracking_poll; - /* ******** Hotkeys avalaible for preview region only ******** */ + /* ******** Hotkeys available for preview region only ******** */ WM_keymap_ensure(keyconf, "Clip Graph Editor", SPACE_CLIP, 0); - /* ******** Hotkeys avalaible for channels region only ******** */ + /* ******** Hotkeys available for channels region only ******** */ WM_keymap_ensure(keyconf, "Clip Dopesheet Editor", SPACE_CLIP, 0); } @@ -947,7 +947,7 @@ static void clip_main_region_draw(const bContext *C, ARegion *ar) ScrArea *sa = CTX_wm_area(C); int mask_width, mask_height; ED_mask_get_size(sa, &mask_width, &mask_height); - ED_mask_draw_region(CTX_data_depsgraph(C), + ED_mask_draw_region(CTX_data_expect_evaluated_depsgraph(C), mask, ar, sc->mask_info.draw_flag, @@ -1224,7 +1224,7 @@ static void clip_header_region_listener(wmWindow *UNUSED(win), switch (wmn->data) { /* for proportional editmode only */ case ND_TOOLSETTINGS: - /* TODO - should do this when in mask mode only but no datas available */ + /* TODO - should do this when in mask mode only but no data available */ // if (sc->mode == SC_MODE_MASKEDIT) { ED_region_tag_redraw(ar); diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index d8d50ba72b5..1375b99bdaa 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -1894,6 +1894,7 @@ static int tracking_object_new_exec(bContext *C, wmOperator *UNUSED(op)) BKE_tracking_object_add(tracking, "Object"); + DEG_id_tag_update(&clip->id, ID_RECALC_COPY_ON_WRITE); WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); return OPERATOR_FINISHED; @@ -1932,6 +1933,7 @@ static int tracking_object_remove_exec(bContext *C, wmOperator *op) BKE_tracking_object_delete(tracking, object); + DEG_id_tag_update(&clip->id, ID_RECALC_COPY_ON_WRITE); WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_clip/tracking_ops_orient.c b/source/blender/editors/space_clip/tracking_ops_orient.c index 61991993b10..de0025a53d2 100644 --- a/source/blender/editors/space_clip/tracking_ops_orient.c +++ b/source/blender/editors/space_clip/tracking_ops_orient.c @@ -39,6 +39,7 @@ #include "BKE_report.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "WM_api.h" #include "WM_types.h" @@ -395,7 +396,6 @@ static int set_plane_exec(bContext *C, wmOperator *op) ListBase *tracksbase; Object *object; Object *camera = get_camera_with_movieclip(scene, clip); - Depsgraph *depsgraph = CTX_data_depsgraph(C); int tot = 0; float vec[3][3], mat[4][4], obmat[4][4], newmat[4][4], orig[3] = {0.0f, 0.0f, 0.0f}; int plane = RNA_enum_get(op->ptr, "plane"); @@ -484,7 +484,13 @@ static int set_plane_exec(bContext *C, wmOperator *op) BKE_object_apply_mat4(object, mat, 0, 0); } - BKE_object_where_is_calc(depsgraph, scene, object); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); + Object *object_eval = DEG_get_evaluated_object(depsgraph, object); + BKE_object_transform_copy(object_eval, object); + BKE_object_where_is_calc(depsgraph, scene_eval, object_eval); + BKE_object_transform_copy(object, object_eval); + set_axis(scene, object, clip, tracking_object, axis_track, 'X'); DEG_id_tag_update(&clip->id, 0); diff --git a/source/blender/editors/space_clip/tracking_ops_solve.c b/source/blender/editors/space_clip/tracking_ops_solve.c index 4490655393e..806df4dbaff 100644 --- a/source/blender/editors/space_clip/tracking_ops_solve.c +++ b/source/blender/editors/space_clip/tracking_ops_solve.c @@ -122,8 +122,14 @@ static void solve_camera_freejob(void *scv) solved = BKE_tracking_reconstruction_finish(scj->context, tracking); if (!solved) { - BKE_report( - scj->reports, RPT_WARNING, "Some data failed to reconstruct (see console for details)"); + const char *error_message = BKE_tracking_reconstruction_error_message_get(scj->context); + if (error_message[0]) { + BKE_report(scj->reports, RPT_ERROR, error_message); + } + else { + BKE_report( + scj->reports, RPT_WARNING, "Some data failed to reconstruct (see console for details)"); + } } else { BKE_reportf(scj->reports, @@ -146,6 +152,7 @@ static void solve_camera_freejob(void *scv) int width, height; BKE_movieclip_get_size(clip, &scj->user, &width, &height); BKE_tracking_camera_to_blender(tracking, scene, camera, width, height); + DEG_id_tag_update(&camera->id, ID_RECALC_COPY_ON_WRITE); WM_main_add_notifier(NC_OBJECT, camera); } |