[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38477] branches/soc-2011-tomato: Camera tracking integration

Sergey Sharybin g.ulairi at gmail.com
Mon Jul 18 16:54:32 CEST 2011


Revision: 38477
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38477
Author:   nazgul
Date:     2011-07-18 14:54:32 +0000 (Mon, 18 Jul 2011)
Log Message:
-----------
Camera tracking integration
===========================

- Track preview widget is now resizeable.
- Marker position could now be adjusted from track
  preview widget.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
    branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-tomato/source/blender/editors/include/UI_interface.h
    branches/soc-2011-tomato/source/blender/editors/interface/interface_draw.c
    branches/soc-2011-tomato/source/blender/editors/interface/interface_handlers.c
    branches/soc-2011-tomato/source/blender/editors/interface/interface_intern.h
    branches/soc-2011-tomato/source/blender/editors/interface/interface_widgets.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_buttons.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h
    branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_movieclip_types.h
    branches/soc-2011-tomato/source/blender/makesdna/DNA_space_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_movieclip.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_ui_api.c
    branches/soc-2011-tomato/source/blenderplayer/bad_level_call_stubs/stubs.c

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-07-18 14:49:05 UTC (rev 38476)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-07-18 14:54:32 UTC (rev 38477)
@@ -213,8 +213,7 @@
 
         layout.prop(act_track, "name")
 
-        layout.template_track(clip.tracking, "active_track", \
-            sc.clip_user, clip)
+        layout.template_track(sc, "scopes")
 
         if act_track:
             row = layout.row()

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h	2011-07-18 14:49:05 UTC (rev 38476)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h	2011-07-18 14:54:32 UTC (rev 38477)
@@ -37,6 +37,7 @@
 struct ImBuf;
 struct Main;
 struct MovieClip;
+struct MovieClipScopes;
 struct MovieClipUser;
 struct MovieTrackingTrack;
 
@@ -56,6 +57,8 @@
 void BKE_movieclip_set_selection(struct MovieClip *clip, int type, void *sel);
 void BKE_movieclip_last_selection(struct MovieClip *clip, int *type, void **sel);
 
+void BKE_movieclip_update_scopes(struct MovieClip *clip, struct MovieClipUser *user, struct MovieClipScopes *scopes);
+
 void BKE_movieclip_get_cache_segments(struct MovieClip *clip, int *totseg_r, int **points_r);
 
 #define TRACK_CLEAR_UPTO		0

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-07-18 14:49:05 UTC (rev 38476)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-07-18 14:54:32 UTC (rev 38477)
@@ -441,6 +441,61 @@
 	else *sel= clip->last_sel;
 }
 
+void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClipScopes *scopes)
+{
+	void *sel;
+	int sel_type;
+
+	if(scopes->ok) return;
+
+	if(scopes->track_preview) {
+		IMB_freeImBuf(scopes->track_preview);
+		scopes->track_preview= NULL;
+	}
+
+	scopes->marker_pos= NULL;
+
+	if(clip) {
+		BKE_movieclip_last_selection(clip, &sel_type, &sel);
+
+		if(sel_type==MCLIP_SEL_TRACK) {
+			MovieTrackingTrack *track= (MovieTrackingTrack*)sel;
+			MovieTrackingMarker *marker= BKE_tracking_get_marker(track, user->framenr);
+
+			if(marker->flag&MARKER_DISABLED) {
+				scopes->track_disabled= 1;
+			} else {
+				ImBuf *ibuf= BKE_movieclip_acquire_ibuf(clip, user);
+
+				scopes->track_disabled= 0;
+
+				if(ibuf && ibuf->rect) {
+					ImBuf *tmpibuf;
+
+					tmpibuf= BKE_tracking_acquire_pattern_imbuf(ibuf, track, marker, 1, &scopes->track_pos, NULL);
+
+					if(tmpibuf->rect_float)
+						IMB_rect_from_float(tmpibuf);
+
+					if(tmpibuf->rect)
+						scopes->track_preview= tmpibuf;
+					else
+						IMB_freeImBuf(tmpibuf);
+
+					scopes->marker_pos= marker->pos;
+					scopes->slide_scale[0]= track->pat_max[0]-track->pat_min[0];
+					scopes->slide_scale[1]= track->pat_max[1]-track->pat_min[1];
+				}
+
+				IMB_freeImBuf(ibuf);
+			}
+		}
+	}
+
+
+	scopes->ok= 1;
+}
+
 void free_movieclip(MovieClip *clip)
 {
 	free_buffers(clip);

Modified: branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2011-07-18 14:49:05 UTC (rev 38476)
+++ branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2011-07-18 14:54:32 UTC (rev 38477)
@@ -5012,6 +5012,9 @@
 						SpaceClip *sclip= (SpaceClip *)sl;
 
 						sclip->clip= newlibadr_us(fd, sc->id.lib, sclip->clip);
+
+						sclip->scopes.track_preview = NULL;
+						sclip->scopes.ok = 0;
 					}
 				}
 				sa= sa->next;
@@ -5244,6 +5247,9 @@
 					SpaceClip *sclip= (SpaceClip *)sl;
 
 					sclip->clip= restore_pointer_by_name(newmain, (ID *)sclip->clip, 1);
+
+					sclip->scopes.track_preview = NULL;
+					sclip->scopes.ok = 0;
 				}
 			}
 			sa= sa->next;
@@ -11811,6 +11817,7 @@
 
 	{
 		bScreen *sc;
+		Camera *cam;
 
 		for (sc= main->screen.first; sc; sc= sc->id.next) {
 			ScrArea *sa;
@@ -11824,17 +11831,19 @@
 							v3d->flag2 |= V3D_SHOW_RECONSTRUCTION;
 						}
 					}
+					else if(sl->spacetype==SPACE_CLIP) {
+						SpaceClip *sc= (SpaceClip *)sl;
+						if(sc->scopes.track_preview_height==0)
+							sc->scopes.track_preview_height= 120;
+					}
 				}
 			}
 		}
-	}
-	
-	{
-		Camera *cam;
-			for(cam= main->camera.first; cam; cam= cam->id.next) {
-				if (cam->sensor_x < 0.01) {
-					cam->sensor_x = 32.f;
-					cam->sensor_y = 18.f;
+
+		for(cam= main->camera.first; cam; cam= cam->id.next) {
+			if (cam->sensor_x < 0.01) {
+				cam->sensor_x = 32.f;
+				cam->sensor_y = 18.f;
 			}
 		}
 	}

Modified: branches/soc-2011-tomato/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/include/UI_interface.h	2011-07-18 14:49:05 UTC (rev 38476)
+++ branches/soc-2011-tomato/source/blender/editors/include/UI_interface.h	2011-07-18 14:54:32 UTC (rev 38477)
@@ -232,6 +232,7 @@
 #define WAVEFORM	(48<<9)
 #define VECTORSCOPE	(49<<9)
 #define PROGRESSBAR	(50<<9)
+#define TRACKPREVIEW	(51<<9)
 
 #define BUTTYPE		(63<<9)
 
@@ -726,7 +727,7 @@
 void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *activeptr, const char *activeprop, int rows, int maxrows, int type);
 
 void uiTemplateMovieClip(struct uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *userptr, int compact);
-void uiTemplateTrack(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *userptr, struct PointerRNA *clipptr);
+void uiTemplateTrack(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname);
 
 /* items */
 void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname);

Modified: branches/soc-2011-tomato/source/blender/editors/interface/interface_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/interface/interface_draw.c	2011-07-18 14:49:05 UTC (rev 38476)
+++ branches/soc-2011-tomato/source/blender/editors/interface/interface_draw.c	2011-07-18 14:54:32 UTC (rev 38477)
@@ -36,6 +36,7 @@
 #include "DNA_color_types.h"
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
+#include "DNA_movieclip_types.h"
 
 #include "BLI_math.h"
 #include "BLI_rect.h"
@@ -725,7 +726,7 @@
 	/* outline */
 	glColor4f(0.f, 0.f, 0.f, 0.5f);
 	uiSetRoundBox(15);
-	uiDrawBox(GL_LINE_LOOP, rect->xmin-1, rect->ymin, rect->xmax+1, rect->ymax+1, 3.0f);
+	uiDrawBox(GL_LINE_LOOP, rect->xmin-1, rect->ymin-1, rect->xmax+1, rect->ymax+1, 3.0f);
 }
 
 static void histogram_draw_one(float r, float g, float b, float alpha, float x, float y, float w, float h, float *data, int res)
@@ -1530,7 +1531,115 @@
 	fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
 }
 
+static ImBuf *scale_trackpreview_ibuf(ImBuf *ibuf, float zoomx, float zoomy)
+{
+	ImBuf *scaleibuf;
+	int x, y, w= ibuf->x*zoomx, h= ibuf->y*zoomy;
+	scaleibuf= IMB_allocImBuf(w, h, 32, IB_rect);
 
+	for(y= 0; y<scaleibuf->y; y++) {
+		for (x= 0; x<scaleibuf->x; x++) {
+			int pixel= scaleibuf->x*y + x;
+			int orig_pixel= ibuf->x*(int)(((float)y)/zoomy) + (int)(((float)x)/zoomx);
+			char *rrgb= (char*)scaleibuf->rect + pixel*4;
+			char *orig_rrgb= (char*)ibuf->rect + orig_pixel*4;
+			rrgb[0]= orig_rrgb[0];
+			rrgb[1]= orig_rrgb[1];
+			rrgb[2]= orig_rrgb[2];
+			rrgb[3]= orig_rrgb[3];
+		}
+	}
+
+	return scaleibuf;
+}
+
+void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
+{
+	rctf rect;
+	int ok= 0;
+	GLint scissor[4];
+	MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
+
+	rect.xmin = (float)recti->xmin+1;
+	rect.xmax = (float)recti->xmax-1;
+	rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
+	rect.ymax = (float)recti->ymax-1;
+
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+
+	/* need scissor test, preview image can draw outside of boundary */
+	glGetIntegerv(GL_VIEWPORT, scissor);
+	glScissor(ar->winrct.xmin + (rect.xmin-1), ar->winrct.ymin+(rect.ymin-1), (rect.xmax+1)-(rect.xmin-1), (rect.ymax+1)-(rect.ymin-1));
+
+	if(scopes->track_disabled) {
+		glColor4f(0.7f, 0.3f, 0.3f, 0.3f);
+		uiSetRoundBox(15);
+		uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
+
+		ok= 1;
+	}
+	else if(scopes->track_preview) {
+		int a, off_x, off_y;
+		float zoomx, zoomy;
+		ImBuf *drawibuf;
+
+		glPushMatrix();
+
+		/* draw content of pattern area */
+		glScissor(ar->winrct.xmin+rect.xmin, ar->winrct.ymin+rect.ymin, scissor[2], scissor[3]);
+
+		zoomx= (rect.xmax-rect.xmin) / (scopes->track_preview->x-2.f);
+		zoomy= (rect.ymax-rect.ymin) / (scopes->track_preview->y-2.f);
+
+		off_x= ((int)scopes->track_pos[0]-scopes->track_pos[0]-0.5)*zoomx;
+		off_y= ((int)scopes->track_pos[1]-scopes->track_pos[1]-0.5)*zoomy;
+
+		drawibuf= scale_trackpreview_ibuf(scopes->track_preview, zoomx, zoomy);
+		glaDrawPixelsSafe(off_x+rect.xmin, off_y+rect.ymin, rect.xmax-rect.xmin+1.f-off_x, rect.ymax-rect.ymin+1.f-off_y, drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect);
+
+		IMB_freeImBuf(drawibuf);
+
+		/* draw cross for pizel position */
+		glTranslatef(off_x+rect.xmin+scopes->track_pos[0]*zoomx, off_y+rect.ymin+scopes->track_pos[1]*zoomy, 0.f);
+		glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin+rect.ymin, rect.xmax-rect.xmin, rect.ymax-rect.ymin);
+
+		for(a= 0; a< 2; a++) {
+			if(a==1) {
+				glLineStipple(3, 0xaaaa);
+				glEnable(GL_LINE_STIPPLE);
+				UI_ThemeColor(TH_SEL_MARKER);
+			}
+			else {
+				UI_ThemeColor(TH_MARKER_OUTLINE);
+			}
+
+			glBegin(GL_LINES);
+				glVertex2f(-10.0f, 0.0f);
+				glVertex2f(10.0f, 0.0f);
+				glVertex2f(0.0f, -10.0f);
+				glVertex2f(0.0f, 10.0f);
+			glEnd();
+		}
+
+		glDisable(GL_LINE_STIPPLE);
+		glPopMatrix();
+
+		ok= 1;
+	}
+
+	if(!ok) {
+		glColor4f(0.f, 0.f, 0.f, 0.3f);
+		uiSetRoundBox(15);
+		uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
+	}
+
+	/* outline, scale gripper */
+	draw_scope_end(&rect, scissor);
+
+	glDisable(GL_BLEND);
+}
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list