diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-11-07 16:55:18 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-11-07 16:55:18 +0400 |
commit | 27d42c63d9b507b1771ed5a7923c389c719b877b (patch) | |
tree | 8dd4ca61e197a7053633f62b4a5d8091957724c4 /source/blender/editors/interface | |
parent | e122dc0748f6a4d77b236e26beba93e2a9a36bf0 (diff) |
Camera tracking integration
===========================
Commiting camera tracking integration gsoc project into trunk.
This commit includes:
- Bundled version of libmv library (with some changes against official repo,
re-sync with libmv repo a bit later)
- New datatype ID called MovieClip which is optimized to work with movie
clips (both of movie files and image sequences) and doing camera/motion
tracking operations.
- New editor called Clip Editor which is currently used for motion/tracking
stuff only, but which can be easily extended to work with masks too.
This editor supports:
* Loading movie files/image sequences
* Build proxies with different size for loaded movie clip, also supports
building undistorted proxies to increase speed of playback in
undistorted mode.
* Manual lens distortion mode calibration using grid and grease pencil
* Supervised 2D tracking using two different algorithms KLT and SAD.
* Basic algorithm for feature detection
* Camera motion solving. scene orientation
- New constraints to "link" scene objects with solved motions from clip:
* Follow Track (make object follow 2D motion of track with given name
or parent object to reconstructed 3D position of track)
* Camera Solver to make camera moving in the same way as reconstructed camera
This commit NOT includes changes from tomato branch:
- New nodes (they'll be commited as separated patch)
- Automatic image offset guessing for image input node and image editor
(need to do more tests and gather more feedback)
- Code cleanup in libmv-capi. It's not so critical cleanup, just increasing
readability and understanadability of code. Better to make this chaneg when
Keir will finish his current patch.
More details about this project can be found on this page:
http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011
Further development of small features would be done in trunk, bigger/experimental
features would first be implemented in tomato branch.
Diffstat (limited to 'source/blender/editors/interface')
6 files changed, 293 insertions, 2 deletions
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 3d08e761090..4bc0963aad4 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -34,6 +34,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" @@ -1501,6 +1502,114 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect 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 --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index c34c10bf1a7..c871c87983c 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -56,6 +56,7 @@ #include "BKE_idprop.h" #include "BKE_report.h" #include "BKE_texture.h" +#include "BKE_tracking.h" #include "BKE_unit.h" #include "ED_screen.h" @@ -259,7 +260,7 @@ static uiBut *ui_but_last(uiBlock *block) static int ui_is_a_warp_but(uiBut *but) { if(U.uiflag & USER_CONTINUOUS_MOUSE) - if(ELEM3(but->type, NUM, NUMABS, HSVCIRCLE)) + if(ELEM4(but->type, NUM, NUMABS, HSVCIRCLE, TRACKPREVIEW)) return TRUE; return FALSE; @@ -922,6 +923,13 @@ static void ui_apply_but_WAVEFORM(bContext *C, uiBut *but, uiHandleButtonData *d data->applied= 1; } +static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data) +{ + ui_apply_but_func(C, but); + data->retval= but->retval; + data->applied= 1; +} + static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, int interactive) { @@ -1051,6 +1059,9 @@ static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleBut case WAVEFORM: ui_apply_but_WAVEFORM(C, but, data); break; + case TRACKPREVIEW: + ui_apply_but_TRACKPREVIEW(C, but, data); + break; default: break; } @@ -4254,6 +4265,88 @@ static int ui_do_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data, wmE return WM_UI_HANDLER_CONTINUE; } +static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data, int mx, int my, int shift) +{ + MovieClipScopes *scopes = (MovieClipScopes *)but->poin; + int changed= 1; + float dx, dy; + + dx = mx - data->draglastx; + dy = my - data->draglasty; + + if(shift) { + dx /= 5.0f; + dy /= 5.0f; + } + + if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) { + /* resize preview widget itself */ + scopes->track_preview_height = (but->y2 - but->y1) + (data->dragstarty - my); + } else { + if(scopes->marker) { + if(scopes->marker->framenr!=scopes->framenr) + scopes->marker= BKE_tracking_ensure_marker(scopes->track, scopes->framenr); + + scopes->marker->flag&= ~(MARKER_DISABLED|MARKER_TRACKED); + scopes->marker->pos[0]+= -dx*scopes->slide_scale[0] / (but->block->maxx-but->block->minx); + scopes->marker->pos[1]+= -dy*scopes->slide_scale[1] / (but->block->maxy-but->block->miny); + + WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL); + } + + scopes->ok= 0; + } + + data->draglastx= mx; + data->draglasty= my; + + return changed; +} + +static int ui_do_but_TRACKPREVIEW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, wmEvent *event) +{ + int mx, my; + + mx= event->x; + my= event->y; + ui_window_to_block(data->region, block, &mx, &my); + + if(data->state == BUTTON_STATE_HIGHLIGHT) { + if(event->type==LEFTMOUSE && event->val==KM_PRESS) { + data->dragstartx= mx; + data->dragstarty= my; + data->draglastx= mx; + data->draglasty= my; + button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); + + /* also do drag the first time */ + if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift)) + ui_numedit_apply(C, block, but, data); + + return WM_UI_HANDLER_BREAK; + } + } + else if(data->state == BUTTON_STATE_NUM_EDITING) { + if(event->type == ESCKEY) { + data->cancel= 1; + data->escapecancel= 1; + button_activate_state(C, but, BUTTON_STATE_EXIT); + } + else if(event->type == MOUSEMOVE) { + if(mx!=data->draglastx || my!=data->draglasty) { + if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift)) + ui_numedit_apply(C, block, but, data); + } + } + else if(event->type==LEFTMOUSE && event->val!=KM_PRESS) { + button_activate_state(C, but, BUTTON_STATE_EXIT); + } + return WM_UI_HANDLER_BREAK; + } + + return WM_UI_HANDLER_CONTINUE; +} + static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event)) { uiBut *but = (uiBut *)arg1; @@ -4791,6 +4884,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) case INLINK: retval= ui_do_but_LINK(C, but, data, event); break; + case TRACKPREVIEW: + retval= ui_do_but_TRACKPREVIEW(C, block, but, data, event); + break; } return retval; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 9c5fafaf167..29447d492c5 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -454,6 +454,7 @@ void ui_draw_but_COLORBAND(uiBut *but, struct uiWidgetColors *wcol, rcti *rect); void ui_draw_but_NORMAL(uiBut *but, struct uiWidgetColors *wcol, rcti *rect); void ui_draw_but_CURVE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect); void ui_draw_but_IMAGE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect); +void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rcti *rect); /* interface_handlers.c */ extern void ui_button_activate_do(struct bContext *C, struct ARegion *ar, uiBut *but); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 19d22a432dc..7c745c3cfef 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2455,6 +2455,7 @@ void uiTemplateOperatorSearch(uiLayout *layout) #define B_STOPANIM 3 #define B_STOPCOMPO 4 #define B_STOPSEQ 5 +#define B_STOPCLIP 6 static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) { @@ -2474,6 +2475,9 @@ static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) case B_STOPSEQ: WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL); break; + case B_STOPCLIP: + WM_jobs_stop(CTX_wm_manager(C), CTX_wm_area(C), NULL); + break; } } @@ -2499,6 +2503,10 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C) if(WM_jobs_test(wm, sa)) owner = sa; handle_event = B_STOPSEQ; + } else if(sa->spacetype==SPACE_CLIP) { + if(WM_jobs_test(wm, sa)) + owner = sa; + handle_event= B_STOPCLIP; } else { Scene *scene; /* another scene can be rendering too, for example via compositor */ diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 878d1bc36a4..8ab48ac8ffa 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -3078,6 +3078,10 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct wt= widget_type(UI_WTYPE_SCROLL); break; + case TRACKPREVIEW: + ui_draw_but_TRACKPREVIEW(ar, but, &tui->wcol_regular, rect); + break; + default: wt= widget_type(UI_WTYPE_REGULAR); } diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 921a1879bb7..5f392daeec6 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -153,6 +153,9 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo case SPACE_LOGIC: ts= &btheme->tlogic; break; + case SPACE_CLIP: + ts= &btheme->tclip; + break; default: ts= &btheme->tv3d; break; @@ -409,6 +412,27 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo case TH_PREVIEW_BACK: cp= ts->preview_back; break; + + case TH_MARKER_OUTLINE: + cp= ts->marker_outline; break; + case TH_MARKER: + cp= ts->marker; break; + case TH_ACT_MARKER: + cp= ts->act_marker; break; + case TH_SEL_MARKER: + cp= ts->sel_marker; break; + case TH_BUNDLE_SOLID: + cp= ts->bundle_solid; break; + case TH_DIS_MARKER: + cp= ts->dis_marker; break; + case TH_PATH_BEFORE: + cp= ts->path_before; break; + case TH_PATH_AFTER: + cp= ts->path_after; break; + case TH_CAMERA_PATH: + cp= ts->camera_path; break; + case TH_LOCK_MARKER: + cp= ts->lock_marker; break; } } } @@ -533,6 +557,7 @@ static void ui_theme_init_new(bTheme *btheme) ui_theme_init_new_do(&btheme->tlogic); ui_theme_init_new_do(&btheme->tuserpref); ui_theme_init_new_do(&btheme->tconsole); + ui_theme_init_new_do(&btheme->tclip); } @@ -639,7 +664,9 @@ void ui_theme_init_default(void) SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255); SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80); // alpha 80 is not meant editable, used for wire+action draw - + + SETCOL(btheme->tv3d.bundle_solid, 200, 200, 200, 255); + SETCOL(btheme->tv3d.camera_path, 0x00, 0x00, 0x00, 255); /* space buttons */ /* to have something initialized */ @@ -777,6 +804,23 @@ void ui_theme_init_default(void) /* space logic */ btheme->tlogic= btheme->tv3d; SETCOL(btheme->tlogic.back, 100, 100, 100, 255); + + /* space clip */ + btheme->tclip= btheme->tv3d; + + SETCOL(btheme->tclip.marker_outline, 0x00, 0x00, 0x00, 255); + SETCOL(btheme->tclip.marker, 0x7f, 0x7f, 0x00, 255); + SETCOL(btheme->tclip.act_marker, 0xff, 0xff, 0xff, 255); + SETCOL(btheme->tclip.sel_marker, 0xff, 0xff, 0x00, 255); + SETCOL(btheme->tclip.dis_marker, 0x7f, 0x00, 0x00, 255); + SETCOL(btheme->tclip.lock_marker, 0x7f, 0x7f, 0x7f, 255); + SETCOL(btheme->tclip.path_before, 0xff, 0x00, 0x00, 255); + SETCOL(btheme->tclip.path_after, 0x00, 0x00, 0xff, 255); + SETCOL(btheme->tclip.grid, 0x5e, 0x5e, 0x5e, 255); + SETCOL(btheme->tclip.cframe, 0x60, 0xc0, 0x40, 255); + SETCOL(btheme->tclip.handle_vertex, 0x00, 0x00, 0x00, 0xff); + SETCOL(btheme->tclip.handle_vertex_select, 0xff, 0xff, 0, 0xff); + btheme->tclip.handle_vertex_size= 4; } @@ -1590,6 +1634,35 @@ void init_userdef_do_versions(void) } } + { + bTheme *btheme; + for(btheme= U.themes.first; btheme; btheme= btheme->next) { + if(btheme->tv3d.bundle_solid[3] == 0) + SETCOL(btheme->tv3d.bundle_solid, 200, 200, 200, 255); + + if(btheme->tv3d.camera_path[3] == 0) + SETCOL(btheme->tv3d.camera_path, 0x00, 0x00, 0x00, 255); + + if((btheme->tclip.back[3]) == 0) { + btheme->tclip= btheme->tv3d; + + SETCOL(btheme->tclip.marker_outline, 0x00, 0x00, 0x00, 255); + SETCOL(btheme->tclip.marker, 0x7f, 0x7f, 0x00, 255); + SETCOL(btheme->tclip.act_marker, 0xff, 0xff, 0xff, 255); + SETCOL(btheme->tclip.sel_marker, 0xff, 0xff, 0x00, 255); + SETCOL(btheme->tclip.dis_marker, 0x7f, 0x00, 0x00, 255); + SETCOL(btheme->tclip.lock_marker, 0x7f, 0x7f, 0x7f, 255); + SETCOL(btheme->tclip.path_before, 0xff, 0x00, 0x00, 255); + SETCOL(btheme->tclip.path_after, 0x00, 0x00, 0xff, 255); + SETCOL(btheme->tclip.grid, 0x5e, 0x5e, 0x5e, 255); + SETCOL(btheme->tclip.cframe, 0x60, 0xc0, 0x40, 255); + SETCOL(btheme->tclip.handle_vertex, 0x00, 0x00, 0x00, 0xff); + SETCOL(btheme->tclip.handle_vertex_select, 0xff, 0xff, 0, 0xff); + btheme->tclip.handle_vertex_size= 4; + } + } + } + /* GL Texture Garbage Collection (variable abused above!) */ if (U.textimeout == 0) { U.texcollectrate = 60; |