Blender V2.61 - r43446

clip_graph_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_movieclip_types.h"
00033 #include "DNA_scene_types.h"
00034 #include "DNA_object_types.h"   /* SELECT */
00035 
00036 #include "MEM_guardedalloc.h"
00037 
00038 #include "BKE_context.h"
00039 #include "BKE_movieclip.h"
00040 #include "BKE_tracking.h"
00041 
00042 #include "BLI_utildefines.h"
00043 #include "BLI_math.h"
00044 #include "BLI_string.h"
00045 
00046 #include "ED_screen.h"
00047 #include "ED_clip.h"
00048 
00049 #include "BIF_gl.h"
00050 
00051 #include "WM_types.h"
00052 
00053 #include "UI_interface.h"
00054 #include "UI_resources.h"
00055 #include "UI_view2d.h"
00056 
00057 #include "BLF_api.h"
00058 
00059 #include "clip_intern.h"    // own include
00060 
00061 static void draw_curve_knot(float x, float y, float xscale, float yscale, float hsize)
00062 {
00063     static GLuint displist=0;
00064 
00065     /* initialise round circle shape */
00066     if (displist == 0) {
00067         GLUquadricObj *qobj;
00068 
00069         displist= glGenLists(1);
00070         glNewList(displist, GL_COMPILE);
00071 
00072         qobj= gluNewQuadric();
00073         gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
00074         gluDisk(qobj, 0,  0.7, 8, 1);
00075         gluDeleteQuadric(qobj);
00076 
00077         glEndList();
00078     }
00079 
00080     glPushMatrix();
00081 
00082     glTranslatef(x, y, 0.0f);
00083     glScalef(1.0f/xscale*hsize, 1.0f/yscale*hsize, 1.0f);
00084     glCallList(displist);
00085 
00086     glPopMatrix();
00087 }
00088 
00089 static void draw_graph_cfra(SpaceClip *sc, ARegion *ar, Scene *scene)
00090 {
00091     View2D *v2d= &ar->v2d;
00092     float xscale, yscale;
00093     float vec[2];
00094 
00095     /* Draw a light green line to indicate current frame */
00096     vec[0]= (float)(sc->user.framenr * scene->r.framelen);
00097 
00098     UI_ThemeColor(TH_CFRAME);
00099     glLineWidth(2.0);
00100 
00101     glBegin(GL_LINE_STRIP);
00102         vec[1]= v2d->cur.ymin;
00103         glVertex2fv(vec);
00104 
00105         vec[1]= v2d->cur.ymax;
00106         glVertex2fv(vec);
00107     glEnd();
00108 
00109     glLineWidth(1.0);
00110 
00111     UI_view2d_view_orthoSpecial(ar, v2d, 1);
00112 
00113     /* because the frame number text is subject to the same scaling as the contents of the view */
00114     UI_view2d_getscale(v2d, &xscale, &yscale);
00115     glScalef(1.0f/xscale, 1.0f, 1.0f);
00116 
00117     clip_draw_curfra_label(sc, (float)sc->user.framenr * xscale, 18);
00118 
00119     /* restore view transform */
00120     glScalef(xscale, 1.0, 1.0);
00121 }
00122 
00123 static void tracking_segment_point_cb(void *UNUSED(userdata), MovieTrackingTrack *UNUSED(track),
00124             MovieTrackingMarker *marker, int UNUSED(coord), float val)
00125 {
00126     glVertex2f(marker->framenr, val);
00127 }
00128 
00129 void tracking_segment_start_cb(void *userdata, MovieTrackingTrack *track, int coord)
00130 {
00131     static float colors[2][3] = {{1.0f, 0.0f, 0.0f},
00132                                  {0.0f, 1.0f, 0.0f}};
00133     float col[4];
00134 
00135     copy_v3_v3(col, colors[coord]);
00136 
00137     if(track==userdata) {
00138         col[3]= 1.0f;
00139         glLineWidth(2.0f);
00140     } else {
00141         col[3]= 0.5f;
00142         glLineWidth(1.0f);
00143     }
00144 
00145     glColor4fv(col);
00146 
00147     glBegin(GL_LINE_STRIP);
00148 }
00149 
00150 void tracking_segment_end_cb(void *UNUSED(userdata))
00151 {
00152     glEnd();
00153 
00154     glLineWidth(1.0f);
00155 }
00156 
00157 static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track,
00158             MovieTrackingMarker *marker, int UNUSED(coord), float val)
00159 {
00160     struct { MovieTrackingTrack *act_track; int sel; float xscale, yscale, hsize; } *data = userdata;
00161     int sel= 0;
00162 
00163     if(track!=data->act_track)
00164         return;
00165 
00166     sel= (marker->flag&MARKER_GRAPH_SEL) ? 1 : 0;
00167 
00168     if(sel == data->sel) {
00169         if(sel) UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
00170         else UI_ThemeColor(TH_HANDLE_VERTEX);
00171 
00172         draw_curve_knot(marker->framenr, val, data->xscale, data->yscale, data->hsize);
00173     }
00174 }
00175 
00176 static void draw_tracks_curves(View2D *v2d, SpaceClip *sc)
00177 {
00178     MovieClip *clip= ED_space_clip(sc);
00179     MovieTracking *tracking= &clip->tracking;
00180     MovieTrackingTrack *act_track= BKE_tracking_active_track(tracking);
00181     int width, height;
00182     struct { MovieTrackingTrack *act_track; int sel; float xscale, yscale, hsize; } userdata;
00183 
00184     BKE_movieclip_get_size(clip, &sc->user, &width, &height);
00185 
00186     if(!width || !height)
00187         return;
00188 
00189     /* non-selected knot handles */
00190     userdata.hsize= UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE);
00191     userdata.sel= 0;
00192     userdata.act_track= act_track;
00193     UI_view2d_getscale(v2d, &userdata.xscale, &userdata.yscale);
00194     clip_graph_tracking_values_iterate(sc, &userdata, tracking_segment_knot_cb, NULL, NULL);
00195 
00196     /* draw graph lines */
00197     glEnable(GL_BLEND);
00198     clip_graph_tracking_values_iterate(sc, act_track, tracking_segment_point_cb, tracking_segment_start_cb, tracking_segment_end_cb);
00199     glDisable(GL_BLEND);
00200 
00201     /* selected knot handles on top of curves */
00202     userdata.sel= 1;
00203     clip_graph_tracking_values_iterate(sc, &userdata, tracking_segment_knot_cb, NULL, NULL);
00204 }
00205 
00206 static void draw_frame_curves(SpaceClip *sc)
00207 {
00208     MovieClip *clip= ED_space_clip(sc);
00209     MovieTracking *tracking= &clip->tracking;
00210     MovieTrackingReconstruction *reconstruction= BKE_tracking_get_reconstruction(tracking);
00211     int i, lines= 0, prevfra= 0;
00212 
00213     glColor3f(0.0f, 0.0f, 1.0f);
00214 
00215     for(i= 0; i<reconstruction->camnr; i++) {
00216         MovieReconstructedCamera *camera= &reconstruction->cameras[i];
00217 
00218         if(lines && camera->framenr!=prevfra+1) {
00219             glEnd();
00220             lines= 0;
00221         }
00222 
00223         if(!lines) {
00224             glBegin(GL_LINE_STRIP);
00225             lines= 1;
00226         }
00227 
00228         glVertex2f(camera->framenr, camera->error);
00229 
00230         prevfra= camera->framenr;
00231     }
00232 
00233     if(lines)
00234         glEnd();
00235 }
00236 
00237 void clip_draw_graph(SpaceClip *sc, ARegion *ar, Scene *scene)
00238 {
00239     MovieClip *clip= ED_space_clip(sc);
00240     View2D *v2d= &ar->v2d;
00241     View2DGrid *grid;
00242     short unitx= V2D_UNIT_FRAMESCALE, unity= V2D_UNIT_VALUES;
00243 
00244     /* grid */
00245     grid= UI_view2d_grid_calc(scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
00246     UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
00247     UI_view2d_grid_free(grid);
00248 
00249     if(clip) {
00250         if(sc->flag&SC_SHOW_GRAPH_TRACKS)
00251             draw_tracks_curves(v2d, sc);
00252 
00253         if(sc->flag&SC_SHOW_GRAPH_FRAMES)
00254             draw_frame_curves(sc);
00255     }
00256 
00257     /* current frame */
00258     draw_graph_cfra(sc, ar, scene);
00259 }