[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43499] trunk/blender/source/blender: Curve points of tracking curves now can be grabbed to smooth spikes

Sergey Sharybin sergey.vfx at gmail.com
Wed Jan 18 17:45:09 CET 2012


Revision: 43499
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43499
Author:   nazgul
Date:     2012-01-18 16:45:02 +0000 (Wed, 18 Jan 2012)
Log Message:
-----------
Curve points of tracking curves now can be grabbed to smooth spikes

Curve points of tracks curves now can be selected for X and Y channels
separately and can be moved along Y axis of curve viewer, points currently
can't change frame they belong to. This allows to smooth spikes caused by
unwanted marker jump.

Also fixed some mistakes in cancel transform in cases when locked tracks
were being trying to be moved; fixed incorrect calculation of marker speed
for curve drawing.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_clip/clip_graph_draw.c
    trunk/blender/source/blender/editors/space_clip/clip_graph_ops.c
    trunk/blender/source/blender/editors/space_clip/clip_utils.c
    trunk/blender/source/blender/editors/space_clip/space_clip.c
    trunk/blender/source/blender/editors/transform/transform_conversions.c
    trunk/blender/source/blender/editors/transform/transform_generics.c
    trunk/blender/source/blender/makesdna/DNA_tracking_types.h

Modified: trunk/blender/source/blender/editors/space_clip/clip_graph_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_graph_draw.c	2012-01-18 15:47:56 UTC (rev 43498)
+++ trunk/blender/source/blender/editors/space_clip/clip_graph_draw.c	2012-01-18 16:45:02 UTC (rev 43499)
@@ -155,15 +155,16 @@
 }
 
 static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track,
-			MovieTrackingMarker *marker, int UNUSED(coord), float val)
+			MovieTrackingMarker *marker, int coord, float val)
 {
 	struct { MovieTrackingTrack *act_track; int sel; float xscale, yscale, hsize; } *data = userdata;
-	int sel= 0;
+	int sel= 0, sel_flag;
 
 	if(track!=data->act_track)
 		return;
 
-	sel= (marker->flag&MARKER_GRAPH_SEL) ? 1 : 0;
+	sel_flag= coord == 0 ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y;
+	sel= (marker->flag & sel_flag) ? 1 : 0;
 
 	if(sel == data->sel) {
 		if(sel) UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);

Modified: trunk/blender/source/blender/editors/space_clip/clip_graph_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_graph_ops.c	2012-01-18 15:47:56 UTC (rev 43498)
+++ trunk/blender/source/blender/editors/space_clip/clip_graph_ops.c	2012-01-18 16:45:02 UTC (rev 43499)
@@ -68,13 +68,13 @@
 
 	switch(data->action) {
 		case SEL_SELECT:
-			marker->flag|= MARKER_GRAPH_SEL;
+			marker->flag|= (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y);
 			break;
 		case SEL_DESELECT:
-			marker->flag&= ~MARKER_GRAPH_SEL;
+			marker->flag&= ~(MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y);
 			break;
 		case SEL_INVERT:
-			marker->flag^= MARKER_GRAPH_SEL;
+			marker->flag^= (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y);
 			break;
 	}
 }
@@ -177,7 +177,10 @@
 					clip_graph_tracking_iterate(sc, &selectdata, toggle_selection_cb);
 				}
 
-				userdata.marker->flag|= MARKER_GRAPH_SEL;
+				if(userdata.coord==0)
+					userdata.marker->flag|= MARKER_GRAPH_SEL_X;
+				else
+					userdata.marker->flag|= MARKER_GRAPH_SEL_Y;
 
 				return 1;
 			}
@@ -335,7 +338,7 @@
 		while(a<act_track->markersnr) {
 			MovieTrackingMarker *marker= &act_track->markers[a];
 
-			if(marker->flag&MARKER_GRAPH_SEL)
+			if(marker->flag & (MARKER_GRAPH_SEL_X|MARKER_GRAPH_SEL_Y))
 				clip_delete_marker(C, clip, tracksbase, act_track, marker);
 			else
 				a++;

Modified: trunk/blender/source/blender/editors/space_clip/clip_utils.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_utils.c	2012-01-18 15:47:56 UTC (rev 43498)
+++ trunk/blender/source/blender/editors/space_clip/clip_utils.c	2012-01-18 16:45:02 UTC (rev 43499)
@@ -95,7 +95,7 @@
 			}
 
 			/* value is a pixels per frame speed */
-			val= (marker->pos[coord] - prevval) * ((i==0) ? (width) : (height));
+			val= (marker->pos[coord] - prevval) * ((coord==0) ? (width) : (height));
 			val/= marker->framenr-prevfra;
 
 			if(func)

Modified: trunk/blender/source/blender/editors/space_clip/space_clip.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/space_clip.c	2012-01-18 15:47:56 UTC (rev 43498)
+++ trunk/blender/source/blender/editors/space_clip/space_clip.c	2012-01-18 16:45:02 UTC (rev 43499)
@@ -545,6 +545,8 @@
 
 	WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", DELKEY, KM_PRESS, KM_SHIFT, 0);
 	WM_keymap_add_item(keymap, "CLIP_OT_graph_delete_knot", XKEY, KM_PRESS, KM_SHIFT, 0);
+
+	transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
 }
 
 const char *clip_context_dir[]= {"edit_movieclip", NULL};

Modified: trunk/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_conversions.c	2012-01-18 15:47:56 UTC (rev 43498)
+++ trunk/blender/source/blender/editors/transform/transform_conversions.c	2012-01-18 16:45:02 UTC (rev 43499)
@@ -5330,7 +5330,15 @@
 
 /* *** CLIP EDITOR *** */
 
+enum {
+	transDataTracking_ModeTracks = 0,
+	transDataTracking_ModeCurves = 1,
+} transDataTracking_Mode;
+
 typedef struct TransDataTracking {
+	int mode, flag;
+
+	/* tracks transformation from main window */
 	int area;
 	float *relative, *loc;
 	float soffset[2], srelative[2];
@@ -5339,6 +5347,10 @@
 	float (*smarkers)[2];
 	int markersnr;
 	MovieTrackingMarker *markers;
+
+	/* marker transformation from curves editor */
+	float *prev_pos, scale;
+	short coord;
 } TransDataTracking;
 
 static void markerToTransDataInit(TransData *td, TransData2D *td2d,
@@ -5346,6 +5358,8 @@
 {
 	int anchor = area==TRACK_AREA_POINT && off;
 
+	tdt->mode = transDataTracking_ModeTracks;
+
 	if(anchor) {
 		td2d->loc[0] = rel[0]; /* hold original location */
 		td2d->loc[1] = rel[1];
@@ -5400,8 +5414,7 @@
 {
 	MovieTrackingMarker *marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
 
-	track->transflag= marker->flag;
-
+	tdt->flag= marker->flag;
 	marker->flag&= ~(MARKER_DISABLED|MARKER_TRACKED);
 
 	markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, track->offset, marker->pos, track->offset);
@@ -5430,7 +5443,7 @@
 	}
 }
 
-static void createTransTrackingData(bContext *C, TransInfo *t)
+static void createTransTrackingTracksData(bContext *C, TransInfo *t)
 {
 	TransData *td;
 	TransData2D *td2d;
@@ -5442,11 +5455,6 @@
 	TransDataTracking *tdt;
 	int framenr = sc->user.framenr;
 
-	if(!clip || !BKE_movieclip_has_frame(clip, &sc->user)) {
-		t->total = 0;
-		return;
-	}
-
 	/* count */
 	t->total = 0;
 
@@ -5455,13 +5463,11 @@
 		if(TRACK_VIEW_SELECTED(sc, track) && (track->flag&TRACK_LOCKED)==0) {
 			marker= BKE_tracking_get_marker(track, framenr);
 
-			if(marker) {
-				t->total++;	/* offset */
+			t->total++;	/* offset */
 
-				if(track->flag&SELECT) t->total++;
-				if(track->pat_flag&SELECT) t->total+= 2;
-				if(track->search_flag&SELECT) t->total+= 2;
-			}
+			if(track->flag&SELECT) t->total++;
+			if(track->pat_flag&SELECT) t->total+= 2;
+			if(track->search_flag&SELECT) t->total+= 2;
 		}
 
 		track = track->next;
@@ -5511,6 +5517,194 @@
 	}
 }
 
+static void markerToTransCurveDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt,
+									   MovieTrackingMarker *marker, MovieTrackingMarker *prev_marker,
+                                       short coord, float size)
+{
+	float frames_delta = (marker->framenr - prev_marker->framenr);
+
+	tdt->flag = marker->flag;
+	marker->flag &= ~MARKER_TRACKED;
+
+	tdt->mode = transDataTracking_ModeCurves;
+	tdt->coord = coord;
+	tdt->scale = 1.0f / size * frames_delta;
+	tdt->prev_pos = prev_marker->pos;
+
+	/* calculate values depending on marker's speed */
+	td2d->loc[0] = marker->framenr;
+	td2d->loc[1] = (marker->pos[coord] - prev_marker->pos[coord]) * size / frames_delta;
+	td2d->loc[2] = 0.0f;
+
+	td2d->loc2d = marker->pos; /* current location */
+
+	td->flag = 0;
+	td->loc = td2d->loc;
+	VECCOPY(td->center, td->loc);
+	VECCOPY(td->iloc, td->loc);
+
+	memset(td->axismtx, 0, sizeof(td->axismtx));
+	td->axismtx[2][2] = 1.0f;
+
+	td->ext= NULL; td->val= NULL;
+
+	td->flag |= TD_SELECTED;
+	td->dist= 0.0;
+
+	unit_m3(td->mtx);
+	unit_m3(td->smtx);
+}
+
+static void createTransTrackingCurvesData(bContext *C, TransInfo *t)
+{
+	TransData *td;
+	TransData2D *td2d;
+	SpaceClip *sc = CTX_wm_space_clip(C);
+	MovieClip *clip = ED_space_clip(sc);
+	ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
+	MovieTrackingTrack *track;
+	MovieTrackingMarker *marker, *prev_marker;
+	TransDataTracking *tdt;
+	int i, width, height;
+
+	BKE_movieclip_get_size(clip, &sc->user, &width, &height);
+
+	/* count */
+	t->total = 0;
+
+	track = tracksbase->first;
+	while(track) {
+		if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+			for(i = 1; i < track->markersnr; i++) {
+				marker = &track->markers[i];
+				prev_marker = &track->markers[i-1];
+
+				if((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED))
+					continue;
+
+				if(marker->flag & MARKER_GRAPH_SEL_X)
+					t->total += 1;
+
+				if(marker->flag & MARKER_GRAPH_SEL_Y)
+					t->total += 1;
+			}
+		}
+
+		track = track->next;
+	}
+
+	if(t->total==0)
+		return;
+
+	td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransTracking TransData");
+	td2d = t->data2d = MEM_callocN(t->total*sizeof(TransData2D), "TransTracking TransData2D");
+	tdt = t->customData = MEM_callocN(t->total*sizeof(TransDataTracking), "TransTracking TransDataTracking");
+
+	t->customFree = transDataTrackingFree;
+
+	/* create actual data */
+	track = tracksbase->first;
+	while(track) {
+		if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+			for(i = 1; i < track->markersnr; i++) {
+				marker = &track->markers[i];
+				prev_marker = &track->markers[i-1];
+
+				if((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED))
+					continue;
+
+				if(marker->flag & MARKER_GRAPH_SEL_X) {
+					markerToTransCurveDataInit(td, td2d, tdt, marker, &track->markers[i-1], 0, width);
+					td += 1;
+					td2d += 1;
+					tdt += 1;
+				}
+
+				if(marker->flag & MARKER_GRAPH_SEL_Y) {
+					markerToTransCurveDataInit(td, td2d, tdt, marker, &track->markers[i-1], 1, height);
+
+					td += 1;
+					td2d += 1;
+					tdt += 1;
+				}
+			}
+		}
+
+		track = track->next;
+	}
+}
+
+static void createTransTrackingData(bContext *C, TransInfo *t)
+{
+	ARegion *ar = CTX_wm_region(C);
+	SpaceClip *sc = CTX_wm_space_clip(C);
+	MovieClip *clip = ED_space_clip(sc);
+
+	if(!clip || !BKE_movieclip_has_frame(clip, &sc->user)) {
+		t->total = 0;
+		return;
+	}
+
+	if(ar->regiontype == RGN_TYPE_PREVIEW) {
+		/* transformation was called from graph editor */
+		createTransTrackingCurvesData(C, t);
+	}
+	else {
+		createTransTrackingTracksData(C, t);
+	}
+}
+
+static void cancelTransTracking(TransInfo *t)
+{
+	TransDataTracking *tdt = t->customData;
+	SpaceClip *sc= t->sa->spacedata.first;
+	MovieClip *clip= ED_space_clip(sc);
+	ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
+	MovieTrackingTrack *track;
+	MovieTrackingMarker *marker;
+	int a, framenr = sc->user.framenr;
+
+	if(tdt->mode == transDataTracking_ModeTracks) {
+		track = tracksbase->first;
+		while(track) {
+			if(TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED)==0) {
+				marker = BKE_tracking_get_marker(track, framenr);
+				marker->flag = tdt->flag;
+
+				tdt++;
+
+				if(track->flag&SELECT) tdt++;

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list