Blender V2.61 - r43446

clip_draw.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2011 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  *
00022  * Contributor(s): Blender Foundation,
00023  *                 Sergey Sharybin
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #include "DNA_gpencil_types.h"
00033 #include "DNA_movieclip_types.h"
00034 #include "DNA_scene_types.h"
00035 #include "DNA_object_types.h"   /* SELECT */
00036 
00037 #include "MEM_guardedalloc.h"
00038 
00039 #include "BKE_context.h"
00040 #include "BKE_movieclip.h"
00041 #include "BKE_tracking.h"
00042 
00043 #include "IMB_imbuf_types.h"
00044 #include "IMB_imbuf.h"
00045 
00046 #include "BLI_utildefines.h"
00047 #include "BLI_math.h"
00048 #include "BLI_string.h"
00049 #include "BLI_rect.h"
00050 #include "BLI_math_base.h"
00051 
00052 #include "ED_screen.h"
00053 #include "ED_clip.h"
00054 #include "ED_gpencil.h"
00055 
00056 #include "BIF_gl.h"
00057 #include "BIF_glutil.h"
00058 
00059 #include "WM_api.h"
00060 #include "WM_types.h"
00061 
00062 #include "UI_interface.h"
00063 #include "UI_resources.h"
00064 #include "UI_view2d.h"
00065 
00066 #include "RNA_access.h"
00067 
00068 #include "BLF_api.h"
00069 
00070 #include "clip_intern.h"    // own include
00071 
00072 /*********************** main area drawing *************************/
00073 
00074 void clip_draw_curfra_label(SpaceClip *sc, float x, float y)
00075 {
00076     uiStyle *style= UI_GetStyle();
00077     int fontid= style->widget.uifont_id;
00078     char numstr[32];
00079     float font_dims[2] = {0.0f, 0.0f};
00080 
00081     /* frame number */
00082     BLF_size(fontid, 11.0f, U.dpi);
00083     BLI_snprintf(numstr, sizeof(numstr), "%d", sc->user.framenr);
00084 
00085     BLF_width_and_height(fontid, numstr, &font_dims[0], &font_dims[1]);
00086 
00087     glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
00088 
00089     UI_ThemeColor(TH_TEXT);
00090     BLF_position(fontid, x+2.0f, y+2.0f, 0.0f);
00091     BLF_draw(fontid, numstr, sizeof(numstr));
00092 }
00093 
00094 static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Scene *scene)
00095 {
00096     float x;
00097     int *points, totseg, i, a;
00098     float sfra= SFRA, efra= EFRA, framelen= ar->winx/(efra-sfra+1);
00099     MovieTrackingTrack *act_track= BKE_tracking_active_track(&clip->tracking);
00100     MovieTrackingReconstruction *reconstruction= BKE_tracking_get_reconstruction(&clip->tracking);
00101 
00102     glEnable(GL_BLEND);
00103 
00104     /* cache background */
00105     glColor4ub(128, 128, 255, 64);
00106     glRecti(0, 0, ar->winx, 8);
00107 
00108     /* cached segments -- could be usefu lto debug caching strategies */
00109     BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points);
00110     if(totseg) {
00111         glColor4ub(128, 128, 255, 128);
00112 
00113         for(a= 0; a<totseg; a++) {
00114             float x1, x2;
00115 
00116             x1= (points[a*2]-sfra)/(efra-sfra+1)*ar->winx;
00117             x2= (points[a*2+1]-sfra+1)/(efra-sfra+1)*ar->winx;
00118 
00119             glRecti(x1, 0, x2, 8);
00120         }
00121     }
00122 
00123     /* track */
00124     if(act_track) {
00125         MovieTrackingTrack *track= act_track;
00126 
00127         for(i= sfra, a= 0; i <= efra; i++) {
00128             int framenr;
00129             MovieTrackingMarker *marker;
00130 
00131             while(a<track->markersnr) {
00132                 if(track->markers[a].framenr>=i)
00133                     break;
00134 
00135                 if(a<track->markersnr-1 && track->markers[a+1].framenr>i)
00136                     break;
00137 
00138                 a++;
00139             }
00140 
00141             if(a<track->markersnr) marker= &track->markers[a];
00142             else marker= &track->markers[track->markersnr-1];
00143 
00144             if((marker->flag&MARKER_DISABLED)==0) {
00145                 framenr= marker->framenr;
00146 
00147                 if(framenr!=i) glColor4ub(128, 128, 0, 96);
00148                 else if((marker->flag&MARKER_TRACKED)==0) glColor4ub(255, 255, 0, 196);
00149                 else glColor4ub(255, 255, 0, 96);
00150 
00151                 glRecti((i-sfra)*framelen, 0, (i-sfra+1)*framelen, 4);
00152             }
00153         }
00154     }
00155 
00156     /* failed frames */
00157     if(reconstruction->flag&TRACKING_RECONSTRUCTED) {
00158         int n= reconstruction->camnr;
00159         MovieReconstructedCamera *cameras= reconstruction->cameras;
00160 
00161         glColor4ub(255, 0, 0, 96);
00162 
00163         for(i= sfra, a= 0; i <= efra; i++) {
00164             int ok= 0;
00165 
00166             while(a<n) {
00167                 if(cameras[a].framenr==i) {
00168                     ok= 1;
00169                     break;
00170                 }
00171                 else if(cameras[a].framenr>i) {
00172                     break;
00173                 }
00174 
00175                 a++;
00176             }
00177 
00178             if(!ok)
00179                 glRecti((i-sfra)*framelen, 0, (i-sfra+1)*framelen, 8);
00180         }
00181     }
00182 
00183     glDisable(GL_BLEND);
00184 
00185     /* current frame */
00186     x= (sc->user.framenr-sfra)/(efra-sfra+1)*ar->winx;
00187 
00188     UI_ThemeColor(TH_CFRAME);
00189     glRecti(x, 0, x+framelen, 8);
00190 
00191     clip_draw_curfra_label(sc, x, 8.0f);
00192 }
00193 
00194 static void draw_movieclip_notes(SpaceClip *sc, ARegion *ar)
00195 {
00196     MovieClip *clip= ED_space_clip(sc);
00197     MovieTracking *tracking= &clip->tracking;
00198     char str[256]= {0};
00199     int block= 0;
00200 
00201     if(tracking->stats) {
00202         BLI_strncpy(str, tracking->stats->message, sizeof(str));
00203         block= 1;
00204     } else {
00205         if(sc->flag&SC_LOCK_SELECTION)
00206             strcpy(str, "Locked");
00207     }
00208 
00209     if(str[0])
00210         ED_region_info_draw(ar, str, block, 0.6f);
00211 }
00212 
00213 static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
00214             int width, int height, float zoomx, float zoomy)
00215 {
00216     int x, y;
00217     MovieClip *clip= ED_space_clip(sc);
00218 
00219     /* set zoom */
00220     glPixelZoom(zoomx*width/ibuf->x, zoomy*height/ibuf->y);
00221 
00222     /* find window pixel coordinates of origin */
00223     UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y);
00224 
00225     if(sc->flag&SC_MUTE_FOOTAGE) {
00226         glColor3f(0.0f, 0.0f, 0.0f);
00227         glRectf(x, y, x+zoomx*width, y+zoomy*height);
00228     } else {
00229         if(ibuf->rect_float && !ibuf->rect) {
00230             IMB_rect_from_float(ibuf);
00231         }
00232 
00233         if(ibuf->rect)
00234             glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
00235     }
00236 
00237     /* draw boundary border for frame if stabilization is enabled */
00238     if(sc->flag&SC_SHOW_STABLE && clip->tracking.stabilization.flag&TRACKING_2D_STABILIZATION) {
00239         glColor3f(0.0f, 0.0f, 0.0f);
00240         glLineStipple(3, 0xaaaa);
00241         glEnable(GL_LINE_STIPPLE);
00242         glEnable(GL_COLOR_LOGIC_OP);
00243         glLogicOp(GL_NOR);
00244 
00245         glPushMatrix();
00246         glTranslatef(x, y, 0);
00247 
00248         glScalef(zoomx, zoomy, 0);
00249         glMultMatrixf(sc->stabmat);
00250 
00251         glBegin(GL_LINE_LOOP);
00252             glVertex2f(0.0f, 0.0f);
00253             glVertex2f(width, 0.0f);
00254             glVertex2f(width, height);
00255             glVertex2f(0.0f, height);
00256         glEnd();
00257 
00258         glPopMatrix();
00259 
00260         glDisable(GL_COLOR_LOGIC_OP);
00261         glDisable(GL_LINE_STIPPLE);
00262     }
00263 
00264 
00265     /* reset zoom */
00266     glPixelZoom(1.0f, 1.0f);
00267 }
00268 
00269 static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackingTrack *track)
00270 {
00271     int count= sc->path_length;
00272     int i, a, b, curindex= -1;
00273     float path[102][2];
00274     int tiny= sc->flag&SC_SHOW_TINY_MARKER, framenr;
00275     MovieTrackingMarker *marker;
00276 
00277     if(count==0)
00278         return;
00279 
00280     marker= BKE_tracking_get_marker(track, sc->user.framenr);
00281     if(marker->framenr!=sc->user.framenr || marker->flag&MARKER_DISABLED)
00282         return;
00283 
00284     framenr= marker->framenr;
00285 
00286     a= count;
00287     i= framenr-1;
00288     while(i>=framenr-count) {
00289         marker= BKE_tracking_get_marker(track, i);
00290 
00291         if(!marker || marker->flag&MARKER_DISABLED)
00292             break;
00293 
00294         if(marker->framenr==i) {
00295             add_v2_v2v2(path[--a], marker->pos, track->offset);
00296             ED_clip_point_undistorted_pos(sc, path[a], path[a]);
00297 
00298             if(marker->framenr==sc->user.framenr)
00299                 curindex= a;
00300         } else
00301             break;
00302 
00303         i--;
00304     }
00305 
00306     b= count;
00307     i= framenr;
00308     while(i<=framenr+count) {
00309         marker= BKE_tracking_get_marker(track, i);
00310 
00311         if(!marker || marker->flag&MARKER_DISABLED)
00312             break;
00313 
00314         if(marker->framenr==i) {
00315             if(marker->framenr==sc->user.framenr)
00316                 curindex= b;
00317 
00318             add_v2_v2v2(path[b++], marker->pos, track->offset);
00319             ED_clip_point_undistorted_pos(sc, path[b-1], path[b-1]);
00320         } else
00321             break;
00322 
00323         i++;
00324     }
00325 
00326     if(!tiny) {
00327         UI_ThemeColor(TH_MARKER_OUTLINE);
00328 
00329         if(TRACK_VIEW_SELECTED(sc, track)) {
00330             glPointSize(5.0f);
00331             glBegin(GL_POINTS);
00332                 for(i= a; i<b; i++) {
00333                     if(i!=curindex)
00334                         glVertex2f(path[i][0], path[i][1]);
00335                 }
00336             glEnd();
00337         }
00338 
00339         glLineWidth(3.0f);
00340         glBegin(GL_LINE_STRIP);
00341             for(i= a; i<b; i++)
00342                 glVertex2f(path[i][0], path[i][1]);
00343         glEnd();
00344         glLineWidth(1.0f);
00345     }
00346 
00347     UI_ThemeColor(TH_PATH_BEFORE);
00348 
00349     if(TRACK_VIEW_SELECTED(sc, track)) {
00350         glPointSize(3.0f);
00351         glBegin(GL_POINTS);
00352             for(i= a; i<b; i++) {
00353                 if(i==count+1)
00354                     UI_ThemeColor(TH_PATH_AFTER);
00355 
00356                 if(i!=curindex)
00357                     glVertex2f(path[i][0], path[i][1]);
00358             }
00359         glEnd();
00360     }
00361 
00362     UI_ThemeColor(TH_PATH_BEFORE);
00363 
00364     glBegin(GL_LINE_STRIP);
00365         for(i= a; i<b; i++) {
00366             if(i==count+1)
00367                 UI_ThemeColor(TH_PATH_AFTER);
00368 
00369             glVertex2f(path[i][0], path[i][1]);
00370         }
00371     glEnd();
00372     glPointSize(1.0f);
00373 }
00374 
00375 static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, float marker_pos[2], int width, int height)
00376 {
00377     int tiny= sc->flag&SC_SHOW_TINY_MARKER;
00378     int show_search= 0;
00379     float px[2];
00380 
00381     UI_ThemeColor(TH_MARKER_OUTLINE);
00382 
00383     px[0]= 1.0f/width/sc->zoom;
00384     px[1]= 1.0f/height/sc->zoom;
00385 
00386     if((marker->flag&MARKER_DISABLED)==0) {
00387         float pos[2];
00388         rctf r;
00389 
00390         BLI_init_rctf(&r, track->pat_min[0], track->pat_max[0], track->pat_min[1], track->pat_max[1]);
00391         add_v2_v2v2(pos, marker->pos, track->offset);
00392 
00393         ED_clip_point_undistorted_pos(sc, pos, pos);
00394 
00395         if(BLI_in_rctf(&r, pos[0]-marker_pos[0], pos[1]-marker_pos[1])) {
00396             if(tiny) glPointSize(3.0f);
00397             else glPointSize(4.0f);
00398             glBegin(GL_POINTS);
00399                 glVertex2f(pos[0], pos[1]);
00400             glEnd();
00401             glPointSize(1.0f);
00402         } else {
00403             if(!tiny) glLineWidth(3.0f);
00404             glBegin(GL_LINES);
00405                 glVertex2f(pos[0] + px[0]*2, pos[1]);
00406                 glVertex2f(pos[0] + px[0]*8, pos[1]);
00407 
00408                 glVertex2f(pos[0] - px[0]*2, pos[1]);
00409                 glVertex2f(pos[0] - px[0]*8, pos[1]);
00410 
00411                 glVertex2f(pos[0], pos[1] - px[1]*2);
00412                 glVertex2f(pos[0], pos[1] - px[1]*8);
00413 
00414                 glVertex2f(pos[0], pos[1] + px[1]*2);
00415                 glVertex2f(pos[0], pos[1] + px[1]*8);
00416             glEnd();
00417             if(!tiny) glLineWidth(1.0f);
00418         }
00419     }
00420 
00421     /* pattern and search outline */
00422     glPushMatrix();
00423     glTranslatef(marker_pos[0], marker_pos[1], 0);
00424 
00425     if(!tiny) glLineWidth(3.0f);
00426 
00427     if(sc->flag&SC_SHOW_MARKER_PATTERN) {
00428         glBegin(GL_LINE_LOOP);
00429             glVertex2f(track->pat_min[0], track->pat_min[1]);
00430             glVertex2f(track->pat_max[0], track->pat_min[1]);
00431             glVertex2f(track->pat_max[0], track->pat_max[1]);
00432             glVertex2f(track->pat_min[0], track->pat_max[1]);
00433         glEnd();
00434     }
00435 
00436     show_search= TRACK_VIEW_SELECTED(sc, track) && ((marker->flag&MARKER_DISABLED)==0 || (sc->flag&SC_SHOW_MARKER_PATTERN)==0);
00437     if(sc->flag&SC_SHOW_MARKER_SEARCH && show_search) {
00438         glBegin(GL_LINE_LOOP);
00439             glVertex2f(track->search_min[0], track->search_min[1]);
00440             glVertex2f(track->search_max[0], track->search_min[1]);
00441             glVertex2f(track->search_max[0], track->search_max[1]);
00442             glVertex2f(track->search_min[0], track->search_max[1]);
00443         glEnd();
00444     }
00445     glPopMatrix();
00446 
00447     if(!tiny) glLineWidth(1.0f);
00448 }
00449 
00450 static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3])
00451 {
00452     if(track->flag&TRACK_CUSTOMCOLOR) {
00453         if(act) UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
00454         else copy_v3_v3(scol, track->color);
00455 
00456         mul_v3_v3fl(col, track->color, 0.5f);
00457     } else {
00458         UI_GetThemeColor3fv(TH_MARKER, col);
00459 
00460         if(act) UI_GetThemeColor3fv(TH_ACT_MARKER, scol);
00461         else UI_GetThemeColor3fv(TH_SEL_MARKER, scol);
00462     }
00463 }
00464 
00465 static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, float marker_pos[2], int width, int height, int act, int sel)
00466 {
00467     int tiny= sc->flag&SC_SHOW_TINY_MARKER;
00468     int show_search= 0;
00469     float col[3], scol[3], px[2];
00470 
00471     track_colors(track, act, col, scol);
00472 
00473     px[0]= 1.0f/width/sc->zoom;
00474     px[1]= 1.0f/height/sc->zoom;
00475 
00476     /* marker position and offset position */
00477     if((track->flag&SELECT)==sel && (marker->flag&MARKER_DISABLED)==0) {
00478         float pos[2];
00479         rctf r;
00480 
00481         if(track->flag&TRACK_LOCKED) {
00482             if(act) UI_ThemeColor(TH_ACT_MARKER);
00483             else if(track->flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
00484             else UI_ThemeColor(TH_LOCK_MARKER);
00485         } else {
00486             if(track->flag&SELECT) glColor3fv(scol);
00487             else glColor3fv(col);
00488         }
00489 
00490         BLI_init_rctf(&r, track->pat_min[0], track->pat_max[0], track->pat_min[1], track->pat_max[1]);
00491         add_v2_v2v2(pos, marker->pos, track->offset);
00492         ED_clip_point_undistorted_pos(sc, pos, pos);
00493 
00494         if(BLI_in_rctf(&r, pos[0]-marker_pos[0], pos[1]-marker_pos[1])) {
00495             if(!tiny) glPointSize(2.0f);
00496             glBegin(GL_POINTS);
00497                 glVertex2f(pos[0], pos[1]);
00498             glEnd();
00499             if(!tiny) glPointSize(1.0f);
00500         } else {
00501             glBegin(GL_LINES);
00502                 glVertex2f(pos[0] + px[0]*3, pos[1]);
00503                 glVertex2f(pos[0] + px[0]*7, pos[1]);
00504 
00505                 glVertex2f(pos[0] - px[0]*3, pos[1]);
00506                 glVertex2f(pos[0] - px[0]*7, pos[1]);
00507 
00508                 glVertex2f(pos[0], pos[1] - px[1]*3);
00509                 glVertex2f(pos[0], pos[1] - px[1]*7);
00510 
00511                 glVertex2f(pos[0], pos[1] + px[1]*3);
00512                 glVertex2f(pos[0], pos[1] + px[1]*7);
00513             glEnd();
00514 
00515             glColor3f(0.0f, 0.0f, 0.0f);
00516             glLineStipple(3, 0xaaaa);
00517             glEnable(GL_LINE_STIPPLE);
00518             glEnable(GL_COLOR_LOGIC_OP);
00519             glLogicOp(GL_NOR);
00520 
00521             glBegin(GL_LINES);
00522                 glVertex2fv(pos);
00523                 glVertex2fv(marker_pos);
00524             glEnd();
00525 
00526             glDisable(GL_COLOR_LOGIC_OP);
00527             glDisable(GL_LINE_STIPPLE);
00528         }
00529     }
00530 
00531     /* pattern */
00532     glPushMatrix();
00533     glTranslatef(marker_pos[0], marker_pos[1], 0);
00534 
00535     if(tiny) {
00536         glLineStipple(3, 0xaaaa);
00537         glEnable(GL_LINE_STIPPLE);
00538     }
00539 
00540     if((track->pat_flag&SELECT)==sel && (sc->flag&SC_SHOW_MARKER_PATTERN)) {
00541         if(track->flag&TRACK_LOCKED) {
00542             if(act) UI_ThemeColor(TH_ACT_MARKER);
00543             else if(track->pat_flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
00544             else UI_ThemeColor(TH_LOCK_MARKER);
00545         }
00546         else if(marker->flag&MARKER_DISABLED) {
00547             if(act) UI_ThemeColor(TH_ACT_MARKER);
00548             else if(track->pat_flag&SELECT) UI_ThemeColorShade(TH_DIS_MARKER, 128);
00549             else UI_ThemeColor(TH_DIS_MARKER);
00550         } else {
00551             if(track->pat_flag&SELECT) glColor3fv(scol);
00552             else glColor3fv(col);
00553         }
00554 
00555         glBegin(GL_LINE_LOOP);
00556             glVertex2f(track->pat_min[0], track->pat_min[1]);
00557             glVertex2f(track->pat_max[0], track->pat_min[1]);
00558             glVertex2f(track->pat_max[0], track->pat_max[1]);
00559             glVertex2f(track->pat_min[0], track->pat_max[1]);
00560         glEnd();
00561     }
00562 
00563     /* search */
00564     show_search= TRACK_VIEW_SELECTED(sc, track) && ((marker->flag&MARKER_DISABLED)==0 || (sc->flag&SC_SHOW_MARKER_PATTERN)==0);
00565     if((track->search_flag&SELECT)==sel && (sc->flag&SC_SHOW_MARKER_SEARCH) && show_search) {
00566         if(track->flag&TRACK_LOCKED) {
00567             if(act) UI_ThemeColor(TH_ACT_MARKER);
00568             else if(track->search_flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
00569             else UI_ThemeColor(TH_LOCK_MARKER);
00570         }
00571         else if(marker->flag&MARKER_DISABLED) {
00572             if(act) UI_ThemeColor(TH_ACT_MARKER);
00573             else if(track->search_flag&SELECT) UI_ThemeColorShade(TH_DIS_MARKER, 128);
00574             else UI_ThemeColor(TH_DIS_MARKER);
00575         } else {
00576             if(track->search_flag&SELECT) glColor3fv(scol);
00577             else glColor3fv(col);
00578         }
00579 
00580         glBegin(GL_LINE_LOOP);
00581             glVertex2f(track->search_min[0], track->search_min[1]);
00582             glVertex2f(track->search_max[0], track->search_min[1]);
00583             glVertex2f(track->search_max[0], track->search_max[1]);
00584             glVertex2f(track->search_min[0], track->search_max[1]);
00585         glEnd();
00586     }
00587 
00588     /* pyramid */
00589     if(sel && TRACK_SELECTED(track) && (sc->flag&SC_SHOW_PYRAMID_LEVELS) && (track->tracker==TRACKER_KLT) && (marker->flag&MARKER_DISABLED)==0) {
00590         if(track->flag&TRACK_LOCKED) {
00591             if(act) UI_ThemeColor(TH_ACT_MARKER);
00592             else if(track->pat_flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
00593             else UI_ThemeColor(TH_LOCK_MARKER);
00594         }
00595         else if(marker->flag&MARKER_DISABLED) {
00596             if(act) UI_ThemeColor(TH_ACT_MARKER);
00597             else if(track->pat_flag&SELECT) UI_ThemeColorShade(TH_DIS_MARKER, 128);
00598             else UI_ThemeColor(TH_DIS_MARKER);
00599         } else {
00600             if(track->pat_flag&SELECT) glColor3fv(scol);
00601             else glColor3fv(col);
00602         }
00603 
00604         {
00605             int i = 0;
00606             glPushMatrix();
00607             glEnable(GL_LINE_STIPPLE);
00608             for (i = 1; i < track->pyramid_levels; ++i) {
00609                 glScalef(2.0f, 2.0f, 1.0);
00610             }
00611             /* only draw a pattern for the coarsest level */
00612             glBegin(GL_LINE_LOOP);
00613                 glVertex2f(track->pat_min[0], track->pat_min[1]);
00614                 glVertex2f(track->pat_max[0], track->pat_min[1]);
00615                 glVertex2f(track->pat_max[0], track->pat_max[1]);
00616                 glVertex2f(track->pat_min[0], track->pat_max[1]);
00617             glEnd();
00618             glDisable(GL_LINE_STIPPLE);
00619             glPopMatrix();
00620         }
00621     }
00622 
00623     if(tiny)
00624         glDisable(GL_LINE_STIPPLE);
00625 
00626     glPopMatrix();
00627 }
00628 
00629 static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
00630             float marker_pos[2], int outline, int sel, int act, int width, int height)
00631 {
00632     float x, y, dx, dy, patdx, patdy, searchdx, searchdy, tdx, tdy;
00633     int tiny= sc->flag&SC_SHOW_TINY_MARKER;
00634     float col[3], scol[3], px[2];
00635 
00636     if((tiny && outline) || (marker->flag&MARKER_DISABLED))
00637         return;
00638 
00639     if(!TRACK_VIEW_SELECTED(sc, track) || track->flag&TRACK_LOCKED)
00640         return;
00641 
00642     track_colors(track, act, col, scol);
00643 
00644     if(outline) {
00645         glLineWidth(3.0f);
00646         UI_ThemeColor(TH_MARKER_OUTLINE);
00647     }
00648 
00649     glPushMatrix();
00650     glTranslatef(marker_pos[0], marker_pos[1], 0);
00651 
00652     dx= 6.0f/width/sc->zoom;
00653     dy= 6.0f/height/sc->zoom;
00654 
00655     patdx= MIN2(dx*2.0f/3.0f, (track->pat_max[0]-track->pat_min[0])/6.0f);
00656     patdy= MIN2(dy*2.0f/3.0f, (track->pat_max[1]-track->pat_min[1])/6.0f);
00657 
00658     searchdx= MIN2(dx, (track->search_max[0]-track->search_min[0])/6.0f);
00659     searchdy= MIN2(dy, (track->search_max[1]-track->search_min[1])/6.0f);
00660 
00661     px[0]= 1.0f/sc->zoom/width/sc->scale;
00662     px[1]= 1.0f/sc->zoom/height/sc->scale;
00663 
00664     if((sc->flag&SC_SHOW_MARKER_SEARCH) && ((track->search_flag&SELECT)==sel || outline)) {
00665         if(!outline) {
00666             if(track->search_flag&SELECT) glColor3fv(scol);
00667             else glColor3fv(col);
00668         }
00669 
00670         /* search offset square */
00671         x= track->search_min[0];
00672         y= track->search_max[1];
00673 
00674         tdx= searchdx;
00675         tdy= searchdy;
00676 
00677         if(outline) {
00678             tdx+= px[0];
00679             tdy+= px[1];
00680         }
00681 
00682         glBegin(GL_QUADS);
00683             glVertex3f(x-tdx, y+tdy, 0);
00684             glVertex3f(x+tdx, y+tdy, 0);
00685             glVertex3f(x+tdx, y-tdy, 0);
00686             glVertex3f(x-tdx, y-tdy, 0);
00687         glEnd();
00688 
00689         /* search resizing triangle */
00690         x= track->search_max[0];
00691         y= track->search_min[1];
00692 
00693         tdx= searchdx*2.0f;
00694         tdy= searchdy*2.0f;
00695 
00696         if(outline) {
00697             tdx+= px[0];
00698             tdy+= px[1];
00699         }
00700 
00701         glBegin(GL_TRIANGLES);
00702             glVertex3f(x, y, 0);
00703             glVertex3f(x-tdx, y, 0);
00704             glVertex3f(x, y+tdy, 0);
00705         glEnd();
00706     }
00707 
00708     if((sc->flag&SC_SHOW_MARKER_PATTERN) && ((track->pat_flag&SELECT)==sel || outline)) {
00709         if(!outline) {
00710             if(track->pat_flag&SELECT) glColor3fv(scol);
00711             else glColor3fv(col);
00712         }
00713 
00714         /* pattern offset square */
00715         x= track->pat_min[0];
00716         y= track->pat_max[1];
00717 
00718         tdx= patdx;
00719         tdy= patdy;
00720 
00721         if(outline) {
00722             tdx+= px[0];
00723             tdy+= px[1];
00724         }
00725 
00726         glBegin(GL_QUADS);
00727             glVertex3f(x-tdx, y+tdy, 0);
00728             glVertex3f(x+tdx, y+tdy, 0);
00729             glVertex3f(x+tdx, y-tdy, 0);
00730             glVertex3f(x-tdx, y-tdy, 0);
00731         glEnd();
00732 
00733         /* pattern resizing triangle */
00734         x= track->pat_max[0];
00735         y= track->pat_min[1];
00736 
00737         tdx= patdx*2.0f;
00738         tdy= patdy*2.0f;
00739 
00740         if(outline) {
00741             tdx+= px[0];
00742             tdy+= px[1];
00743         }
00744 
00745         glBegin(GL_TRIANGLES);
00746             glVertex3f(x, y, 0);
00747             glVertex3f(x-tdx, y, 0);
00748             glVertex3f(x, y+tdy, 0);
00749         glEnd();
00750     }
00751 
00752     glPopMatrix();
00753 
00754     if(outline)
00755         glLineWidth(1.0f);
00756 }
00757 
00758 static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, float marker_pos[2], int act,
00759             int width, int height, float zoomx, float zoomy)
00760 {
00761     char str[128]= {0}, state[64]= {0};
00762     float dx= 0.0f, dy= 0.0f, fontsize, pos[3];
00763     uiStyle *style= U.uistyles.first;
00764     int fontid= style->widget.uifont_id;
00765 
00766     if(!TRACK_VIEW_SELECTED(sc, track))
00767         return;
00768 
00769     BLF_size(fontid, 11.0f, U.dpi);
00770     fontsize= BLF_height_max(fontid);
00771 
00772     if(marker->flag&MARKER_DISABLED) {
00773         if(act) UI_ThemeColor(TH_ACT_MARKER);
00774         else UI_ThemeColorShade(TH_DIS_MARKER, 128);
00775     } else {
00776         if(act) UI_ThemeColor(TH_ACT_MARKER);
00777         else UI_ThemeColor(TH_SEL_MARKER);
00778     }
00779 
00780     if(sc->flag&SC_SHOW_MARKER_SEARCH) {
00781         dx= track->search_min[0];
00782         dy= track->search_min[1];
00783     } else if(sc->flag&SC_SHOW_MARKER_PATTERN) {
00784         dx= track->pat_min[0];
00785         dy= track->pat_min[1];
00786     }
00787 
00788     pos[0]= (marker_pos[0]+dx)*width;
00789     pos[1]= (marker_pos[1]+dy)*height;
00790     pos[2]= 0.0f;
00791 
00792     mul_m4_v3(sc->stabmat, pos);
00793 
00794     pos[0]= pos[0]*zoomx;
00795     pos[1]= pos[1]*zoomy - fontsize;
00796 
00797     if(marker->flag&MARKER_DISABLED) strcpy(state, "disabled");
00798     else if(marker->framenr!=sc->user.framenr) strcpy(state, "estimated");
00799     else if(marker->flag&MARKER_TRACKED) strcpy(state, "tracked");
00800     else strcpy(state, "keyframed");
00801 
00802     if(state[0])
00803         BLI_snprintf(str, sizeof(str), "%s: %s", track->name, state);
00804     else
00805         BLI_snprintf(str, sizeof(str), "%s", track->name);
00806 
00807     BLF_position(fontid, pos[0], pos[1], 0.0f);
00808     BLF_draw(fontid, str, sizeof(str));
00809     pos[1]-= fontsize;
00810 
00811     if(track->flag&TRACK_HAS_BUNDLE) {
00812         BLI_snprintf(str, sizeof(str), "Average error: %.3f", track->error);
00813         BLF_position(fontid, pos[0], pos[1], 0.0f);
00814         BLF_draw(fontid, str, sizeof(str));
00815         pos[1]-= fontsize;
00816     }
00817 
00818     if(track->flag&TRACK_LOCKED) {
00819         BLF_position(fontid, pos[0], pos[1], 0.0f);
00820         BLF_draw(fontid, "locked", 6);
00821     }
00822 }
00823 
00824 static void view2d_to_region_float(View2D *v2d, float x, float y, float *regionx, float *regiony)
00825 {
00826     /* express given coordinates as proportional values */
00827     x= -v2d->cur.xmin / (v2d->cur.xmax-v2d->cur.xmin);
00828     y= -v2d->cur.ymin / (v2d->cur.ymax-v2d->cur.ymin);
00829 
00830     /* convert proportional distances to screen coordinates */
00831     *regionx= v2d->mask.xmin + x*(v2d->mask.xmax-v2d->mask.xmin);
00832     *regiony= v2d->mask.ymin + y*(v2d->mask.ymax-v2d->mask.ymin);
00833 }
00834 
00835 static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
00836             int width, int height, float zoomx, float zoomy)
00837 {
00838     float x, y;
00839     MovieTracking* tracking= &clip->tracking;
00840     ListBase *tracksbase= BKE_tracking_get_tracks(tracking);
00841     MovieTrackingTrack *track, *act_track;
00842     MovieTrackingMarker *marker;
00843     int framenr= sc->user.framenr;
00844     int undistort= sc->user.render_flag&MCLIP_PROXY_RENDER_UNDISTORT;
00845     float *marker_pos= NULL, *fp, *active_pos= NULL, cur_pos[2];
00846 
00847     /* ** find window pixel coordinates of origin ** */
00848 
00849     /* UI_view2d_to_region_no_clip return integer values, this could
00850        lead to 1px flickering when view is locked to selection during playbeck.
00851        to avoid this flickering, calclate base point in the same way as it happens
00852        in UI_view2d_to_region_no_clip, but do it in floats here */
00853 
00854     view2d_to_region_float(&ar->v2d, 0.0f, 0.0f, &x, &y);
00855 
00856     glPushMatrix();
00857     glTranslatef(x, y, 0);
00858 
00859     glPushMatrix();
00860     glScalef(zoomx, zoomy, 0);
00861     glMultMatrixf(sc->stabmat);
00862     glScalef(width, height, 0);
00863 
00864     act_track= BKE_tracking_active_track(tracking);
00865 
00866     if(sc->user.render_flag&MCLIP_PROXY_RENDER_UNDISTORT) {
00867         int count= 0;
00868 
00869         /* count */
00870         track= tracksbase->first;
00871         while(track) {
00872             if((track->flag&TRACK_HIDDEN)==0) {
00873                 marker= BKE_tracking_get_marker(track, framenr);
00874 
00875                 if(MARKER_VISIBLE(sc, marker))
00876                     count++;
00877             }
00878 
00879             track= track->next;
00880         }
00881 
00882         /* undistort */
00883         if(count) {
00884             marker_pos= MEM_callocN(2*sizeof(float)*count, "draw_tracking_tracks marker_pos");
00885 
00886             track= tracksbase->first;
00887             fp= marker_pos;
00888             while(track) {
00889                 if((track->flag&TRACK_HIDDEN)==0) {
00890                     marker= BKE_tracking_get_marker(track, framenr);
00891 
00892                     if(MARKER_VISIBLE(sc, marker)) {
00893                         ED_clip_point_undistorted_pos(sc, marker->pos, fp);
00894 
00895                         if(track==act_track)
00896                             active_pos= fp;
00897 
00898                         fp+= 2;
00899                     }
00900                 }
00901 
00902                 track= track->next;
00903             }
00904         }
00905     }
00906 
00907     if(sc->flag&SC_SHOW_TRACK_PATH) {
00908         track= tracksbase->first;
00909         while(track) {
00910             if((track->flag&TRACK_HIDDEN)==0)
00911                 draw_track_path(sc, clip, track);
00912 
00913             track= track->next;
00914         }
00915     }
00916 
00917     /* markers outline and non-selected areas */
00918     track= tracksbase->first;
00919     fp= marker_pos;
00920     while(track) {
00921         if((track->flag&TRACK_HIDDEN)==0) {
00922             marker= BKE_tracking_get_marker(track, framenr);
00923 
00924             if(MARKER_VISIBLE(sc, marker)) {
00925                 copy_v2_v2(cur_pos, fp ? fp : marker->pos);
00926 
00927                 draw_marker_outline(sc, track, marker, cur_pos, width, height);
00928                 draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 0);
00929                 draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height);
00930                 draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height);
00931 
00932                 if(fp)
00933                     fp+= 2;
00934             }
00935         }
00936 
00937         track= track->next;
00938     }
00939 
00940     /* selected areas only, so selection wouldn't be overlapped by
00941        non-selected areas */
00942     track= tracksbase->first;
00943     fp= marker_pos;
00944     while(track) {
00945         if((track->flag&TRACK_HIDDEN)==0) {
00946             int act= track==act_track;
00947             marker= BKE_tracking_get_marker(track, framenr);
00948 
00949             if(MARKER_VISIBLE(sc, marker)) {
00950                 if(!act) {
00951                     copy_v2_v2(cur_pos, fp ? fp : marker->pos);
00952 
00953                     draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1);
00954                     draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height);
00955                 }
00956 
00957                 if(fp)
00958                     fp+= 2;
00959             }
00960         }
00961 
00962         track= track->next;
00963     }
00964 
00965     /* active marker would be displayed on top of everything else */
00966     if(act_track) {
00967         if((act_track->flag&TRACK_HIDDEN)==0) {
00968             marker= BKE_tracking_get_marker(act_track, framenr);
00969 
00970             if(MARKER_VISIBLE(sc, marker)) {
00971                 copy_v2_v2(cur_pos, active_pos ? active_pos : marker->pos);
00972 
00973                 draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1);
00974                 draw_marker_slide_zones(sc, act_track, marker, cur_pos, 0, 1, 1, width, height);
00975             }
00976         }
00977     }
00978 
00979     if(sc->flag&SC_SHOW_BUNDLES) {
00980         MovieTrackingObject *object= BKE_tracking_active_object(tracking);
00981         float pos[4], vec[4], mat[4][4], aspy;
00982 
00983         glEnable(GL_POINT_SMOOTH);
00984         glPointSize(3.0f);
00985 
00986         aspy= 1.0f/clip->tracking.camera.pixel_aspect;
00987         BKE_tracking_projection_matrix(tracking, object, framenr, width, height, mat);
00988 
00989         track= tracksbase->first;
00990         while(track) {
00991             if((track->flag&TRACK_HIDDEN)==0 && track->flag&TRACK_HAS_BUNDLE) {
00992                 marker= BKE_tracking_get_marker(track, framenr);
00993 
00994                 if(MARKER_VISIBLE(sc, marker)) {
00995                     float npos[2];
00996                     copy_v4_v4(vec, track->bundle_pos);
00997                     vec[3]=1;
00998 
00999                     mul_v4_m4v4(pos, mat, vec);
01000 
01001                     pos[0]= (pos[0]/(pos[3]*2.0f)+0.5f)*width;
01002                     pos[1]= (pos[1]/(pos[3]*2.0f)+0.5f)*height*aspy;
01003 
01004                     BKE_tracking_apply_intrinsics(tracking, pos, npos);
01005 
01006                     if(npos[0]>=0.0f && npos[1]>=0.0f && npos[0]<=width && npos[1]<=height*aspy) {
01007                         vec[0]= (marker->pos[0]+track->offset[0])*width;
01008                         vec[1]= (marker->pos[1]+track->offset[1])*height*aspy;
01009 
01010                         sub_v2_v2(vec, npos);
01011 
01012                         if(len_v2(vec)<3) glColor3f(0.0f, 1.0f, 0.0f);
01013                         else glColor3f(1.0f, 0.0f, 0.0f);
01014 
01015                         glBegin(GL_POINTS);
01016                             if(undistort) glVertex3f(pos[0]/width, pos[1]/(height*aspy), 0);
01017                             else glVertex3f(npos[0]/width, npos[1]/(height*aspy), 0);
01018                         glEnd();
01019                     }
01020                 }
01021             }
01022 
01023             track= track->next;
01024         }
01025 
01026         glPointSize(1.0f);
01027         glDisable(GL_POINT_SMOOTH);
01028     }
01029 
01030     glPopMatrix();
01031 
01032     if(sc->flag&SC_SHOW_NAMES) {
01033         /* scaling should be cleared before drawing texts, otherwise font would also be scaled */
01034         track= tracksbase->first;
01035         fp= marker_pos;
01036         while(track) {
01037             if((track->flag&TRACK_HIDDEN)==0) {
01038                 marker= BKE_tracking_get_marker(track, framenr);
01039 
01040                 if(MARKER_VISIBLE(sc, marker)) {
01041                     int act= track==act_track;
01042 
01043                     copy_v2_v2(cur_pos, fp ? fp : marker->pos);
01044 
01045                     draw_marker_texts(sc, track, marker, cur_pos, act, width, height, zoomx, zoomy);
01046 
01047                     if(fp) fp+= 2;
01048                 }
01049             }
01050 
01051             track= track->next;
01052         }
01053     }
01054 
01055     glPopMatrix();
01056 
01057     if(marker_pos)
01058         MEM_freeN(marker_pos);
01059 }
01060 
01061 static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int width, int height, float zoomx, float zoomy)
01062 {
01063     float x, y;
01064     const int n= 10;
01065     int i, j, a;
01066     float pos[2], tpos[2], grid[11][11][2];
01067     MovieTracking *tracking= &clip->tracking;
01068     float aspy= 1.0f/tracking->camera.pixel_aspect;
01069     float dx= (float)width/n, dy= (float)height/n*aspy;
01070 
01071     if(sc->mode!=SC_MODE_DISTORTION)
01072         return;
01073 
01074     if(!tracking->camera.focal)
01075         return;
01076 
01077     if((sc->flag&SC_SHOW_GRID)==0 && (sc->flag&SC_MANUAL_CALIBRATION)==0)
01078         return;
01079 
01080     view2d_to_region_float(&ar->v2d, 0.0f, 0.0f, &x, &y);
01081 
01082     glPushMatrix();
01083     glTranslatef(x, y, 0);
01084     glScalef(zoomx, zoomy, 0);
01085     glMultMatrixf(sc->stabmat);
01086     glScalef(width, height, 0);
01087 
01088     /* grid */
01089     if(sc->flag&SC_SHOW_GRID) {
01090         float val[4][2], idx[4][2];
01091         float min[2], max[2];
01092 
01093         for(a=0; a<4; a++) {
01094             if(a<2) val[a][a%2]= FLT_MAX;
01095             else val[a][a%2]= -FLT_MAX;
01096         }
01097 
01098         zero_v2(pos);
01099         for(i= 0; i<=n; i++) {
01100             for(j= 0; j<=n; j++) {
01101                 if(i==0 || j==0 || i==n || j==n) {
01102                     BKE_tracking_apply_intrinsics(tracking, pos, tpos);
01103 
01104                     for(a=0; a<4; a++) {
01105                         int ok;
01106 
01107                         if(a<2) ok= tpos[a%2] < val[a][a%2];
01108                         else ok= tpos[a%2] > val[a][a%2];
01109 
01110                         if(ok) {
01111                             copy_v2_v2(val[a], tpos);
01112                             idx[a][0]= j;
01113                             idx[a][1]= i;
01114                         }
01115                     }
01116                 }
01117 
01118                 pos[0]+= dx;
01119             }
01120 
01121             pos[0]= 0.0f;
01122             pos[1]+= dy;
01123         }
01124 
01125         INIT_MINMAX2(min, max);
01126 
01127         for(a= 0; a<4; a++) {
01128             pos[0]= idx[a][0]*dx;
01129             pos[1]= idx[a][1]*dy;
01130 
01131             BKE_tracking_invert_intrinsics(tracking, pos, tpos);
01132 
01133             DO_MINMAX2(tpos, min, max);
01134         }
01135 
01136         copy_v2_v2(pos, min);
01137         dx= (max[0]-min[0])/n;
01138         dy= (max[1]-min[1])/n;
01139 
01140         for(i= 0; i<=n; i++) {
01141             for(j= 0; j<=n; j++) {
01142                 BKE_tracking_apply_intrinsics(tracking, pos, grid[i][j]);
01143 
01144                 grid[i][j][0]/= width;
01145                 grid[i][j][1]/= height*aspy;
01146 
01147                 pos[0]+= dx;
01148             }
01149 
01150             pos[0]= min[0];
01151             pos[1]+= dy;
01152         }
01153 
01154         glColor3f(1.0f, 0.0f, 0.0f);
01155 
01156         for(i= 0; i<=n; i++) {
01157             glBegin(GL_LINE_STRIP);
01158                 for(j= 0; j<=n; j++) {
01159                     glVertex2fv(grid[i][j]);
01160                 }
01161             glEnd();
01162         }
01163 
01164         for(j= 0; j<=n; j++) {
01165             glBegin(GL_LINE_STRIP);
01166                 for(i= 0; i<=n; i++) {
01167                     glVertex2fv(grid[i][j]);
01168                 }
01169             glEnd();
01170         }
01171     }
01172 
01173     if(sc->flag&SC_MANUAL_CALIBRATION && clip->gpd) {
01174         bGPDlayer *layer= clip->gpd->layers.first;
01175 
01176         while(layer) {
01177             bGPDframe *frame= layer->frames.first;
01178 
01179             glColor4fv(layer->color);
01180             glLineWidth(layer->thickness);
01181             glPointSize((float)(layer->thickness + 2));
01182 
01183             while(frame) {
01184                 bGPDstroke *stroke= frame->strokes.first;
01185 
01186                 while(stroke) {
01187                     if(stroke->flag&GP_STROKE_2DSPACE) {
01188                         if(stroke->totpoints>1) {
01189                             glBegin(GL_LINE_STRIP);
01190                                 for(i= 0; i<stroke->totpoints-1; i++) {
01191                                     float npos[2], dpos[2], len;
01192                                     int steps;
01193 
01194                                     pos[0]= stroke->points[i].x*width;
01195                                     pos[1]= stroke->points[i].y*height*aspy;
01196 
01197                                     npos[0]= stroke->points[i+1].x*width;
01198                                     npos[1]= stroke->points[i+1].y*height*aspy;
01199 
01200                                     len= len_v2v2(pos, npos);
01201                                     steps= ceil(len/5.0f);
01202 
01203                                     /* we want to distort only long straight lines */
01204                                     if(stroke->totpoints==2) {
01205                                         BKE_tracking_invert_intrinsics(tracking, pos, pos);
01206                                         BKE_tracking_invert_intrinsics(tracking, npos, npos);
01207                                     }
01208 
01209                                     sub_v2_v2v2(dpos, npos, pos);
01210                                     mul_v2_fl(dpos, 1.0f/steps);
01211 
01212                                     for(j= 0; j<=steps; j++) {
01213                                         BKE_tracking_apply_intrinsics(tracking, pos, tpos);
01214                                         glVertex2f(tpos[0]/width, tpos[1]/(height*aspy));
01215 
01216                                         add_v2_v2(pos, dpos);
01217                                     }
01218                                 }
01219                             glEnd();
01220                         }
01221                         else if(stroke->totpoints==1) {
01222                             glBegin(GL_POINTS);
01223                                 glVertex2f(stroke->points[0].x, stroke->points[0].y);
01224                             glEnd();
01225                         }
01226                     }
01227 
01228                     stroke= stroke->next;
01229                 }
01230 
01231                 frame= frame->next;
01232             }
01233 
01234             layer= layer->next;
01235         }
01236 
01237         glLineWidth(1.0f);
01238         glPointSize(1.0f);
01239     }
01240 
01241     glPopMatrix();
01242 }
01243 
01244 void clip_draw_main(SpaceClip *sc, ARegion *ar, Scene *scene)
01245 {
01246     MovieClip *clip= ED_space_clip(sc);
01247     ImBuf *ibuf;
01248     int width, height;
01249     float zoomx, zoomy;
01250 
01251     /* if no clip, nothing to do */
01252     if(!clip)
01253         return;
01254 
01255     ED_space_clip_size(sc, &width, &height);
01256     ED_space_clip_zoom(sc, ar, &zoomx, &zoomy);
01257 
01258     if(sc->flag&SC_SHOW_STABLE) {
01259         float smat[4][4], ismat[4][4];
01260 
01261         ibuf= ED_space_clip_get_stable_buffer(sc, sc->loc, &sc->scale, &sc->angle);
01262 
01263         if(ibuf) {
01264             float loc[2];
01265 
01266             if(width != ibuf->x)
01267                 mul_v2_v2fl(loc, sc->loc, (float)width / ibuf->x);
01268             else
01269                 copy_v2_v2(loc, sc->loc);
01270 
01271             BKE_tracking_stabdata_to_mat4(width, height, loc, sc->scale, sc->angle, sc->stabmat);
01272 
01273             unit_m4(smat);
01274             smat[0][0]= 1.0f/width;
01275             smat[1][1]= 1.0f/height;
01276             invert_m4_m4(ismat, smat);
01277 
01278             mul_serie_m4(sc->unistabmat, smat, sc->stabmat, ismat, NULL, NULL, NULL, NULL, NULL);
01279         }
01280     } else {
01281         ibuf= ED_space_clip_get_buffer(sc);
01282 
01283         zero_v2(sc->loc);
01284         sc->scale= 1.0f;
01285         unit_m4(sc->stabmat);
01286         unit_m4(sc->unistabmat);
01287     }
01288 
01289     if(ibuf) {
01290         draw_movieclip_buffer(sc, ar, ibuf, width, height, zoomx, zoomy);
01291         IMB_freeImBuf(ibuf);
01292 
01293         draw_tracking_tracks(sc, ar, clip, width, height, zoomx, zoomy);
01294         draw_distortion(sc, ar, clip, width, height, zoomx, zoomy);
01295     }
01296 
01297     draw_movieclip_cache(sc, ar, clip, scene);
01298     draw_movieclip_notes(sc, ar);
01299 }
01300 
01301 /* draw grease pencil */
01302 void clip_draw_grease_pencil(bContext *C, int onlyv2d)
01303 {
01304     SpaceClip *sc= CTX_wm_space_clip(C);
01305     MovieClip *clip= ED_space_clip(sc);
01306     ImBuf *ibuf;
01307 
01308     if((sc->flag&SC_SHOW_GPENCIL)==0 || !clip)
01309         return;
01310 
01311     if(onlyv2d) {
01312         /* if manual calibration is used then grase pencil data is already
01313             drawed in draw_distortion */
01314         if((sc->flag&SC_MANUAL_CALIBRATION)==0 || sc->mode!=SC_MODE_DISTORTION) {
01315             ibuf= ED_space_clip_get_buffer(sc);
01316 
01317             if(ibuf) {
01318                 glPushMatrix();
01319                 glMultMatrixf(sc->unistabmat);
01320                 draw_gpencil_2dimage(C, ibuf);
01321 
01322                 IMB_freeImBuf(ibuf);
01323                 glPopMatrix();
01324             }
01325         }
01326     } else {
01327         draw_gpencil_view2d(C, 0);
01328     }
01329 }