Blender V2.61 - r43446
|
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_object_types.h" /* SELECT */ 00033 00034 #include "MEM_guardedalloc.h" 00035 00036 #include "BLI_utildefines.h" 00037 #include "BLI_math.h" 00038 #include "BLI_listbase.h" 00039 00040 #include "BKE_context.h" 00041 #include "BKE_movieclip.h" 00042 #include "BKE_tracking.h" 00043 #include "BKE_depsgraph.h" 00044 00045 #include "WM_api.h" 00046 #include "WM_types.h" 00047 00048 #include "ED_screen.h" 00049 #include "ED_clip.h" 00050 00051 #include "UI_interface.h" 00052 00053 #include "RNA_access.h" 00054 #include "RNA_define.h" 00055 00056 #include "UI_view2d.h" 00057 00058 #include "clip_intern.h" // own include 00059 00060 void clip_graph_tracking_values_iterate_track(SpaceClip *sc, MovieTrackingTrack *track, void *userdata, 00061 void (*func) (void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, int coord, float val), 00062 void (*segment_start) (void *userdata, MovieTrackingTrack *track, int coord), 00063 void (*segment_end) (void *userdata)) 00064 { 00065 MovieClip *clip= ED_space_clip(sc); 00066 int width, height, coord; 00067 00068 BKE_movieclip_get_size(clip, &sc->user, &width, &height); 00069 00070 for(coord= 0; coord<2; coord++) { 00071 int i, open= 0, prevfra= 0; 00072 float prevval= 0.0f; 00073 00074 for(i= 0; i<track->markersnr; i++) { 00075 MovieTrackingMarker *marker= &track->markers[i]; 00076 float val; 00077 00078 if(marker->flag&MARKER_DISABLED) { 00079 if(open) { 00080 if(segment_end) 00081 segment_end(userdata); 00082 00083 open= 0; 00084 } 00085 00086 continue; 00087 } 00088 00089 if(!open) { 00090 if(segment_start) 00091 segment_start(userdata, track, coord); 00092 00093 open= 1; 00094 prevval= marker->pos[coord]; 00095 } 00096 00097 /* value is a pixels per frame speed */ 00098 val= (marker->pos[coord] - prevval) * ((i==0) ? (width) : (height)); 00099 val/= marker->framenr-prevfra; 00100 00101 if(func) 00102 func(userdata, track, marker, coord, val); 00103 00104 prevval= marker->pos[coord]; 00105 prevfra= marker->framenr; 00106 } 00107 00108 if(open) { 00109 if(segment_end) 00110 segment_end(userdata); 00111 } 00112 } 00113 } 00114 00115 void clip_graph_tracking_values_iterate(SpaceClip *sc, void *userdata, 00116 void (*func) (void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, int coord, float val), 00117 void (*segment_start) (void *userdata, MovieTrackingTrack *track, int coord), 00118 void (*segment_end) (void *userdata)) 00119 { 00120 MovieClip *clip= ED_space_clip(sc); 00121 MovieTracking *tracking= &clip->tracking; 00122 ListBase *tracksbase= BKE_tracking_get_tracks(tracking); 00123 MovieTrackingTrack *track; 00124 00125 track= tracksbase->first; 00126 while(track) { 00127 if(TRACK_VIEW_SELECTED(sc, track)) { 00128 clip_graph_tracking_values_iterate_track(sc, track, userdata, func, segment_start, segment_end); 00129 } 00130 00131 track= track->next; 00132 } 00133 } 00134 00135 void clip_graph_tracking_iterate(SpaceClip *sc, void *userdata, 00136 void (*func) (void *userdata, MovieTrackingMarker *marker)) 00137 { 00138 MovieClip *clip= ED_space_clip(sc); 00139 MovieTracking *tracking= &clip->tracking; 00140 ListBase *tracksbase= BKE_tracking_get_tracks(tracking); 00141 MovieTrackingTrack *track; 00142 00143 track= tracksbase->first; 00144 while(track) { 00145 if(TRACK_VIEW_SELECTED(sc, track)) { 00146 int i; 00147 00148 for(i= 0; i<track->markersnr; i++) { 00149 MovieTrackingMarker *marker= &track->markers[i]; 00150 00151 if(marker->flag&MARKER_DISABLED) 00152 continue; 00153 00154 if(func) 00155 func(userdata, marker); 00156 } 00157 } 00158 00159 track= track->next; 00160 } 00161 } 00162 00163 void clip_delete_track(bContext *C, MovieClip *clip, ListBase *tracksbase, MovieTrackingTrack *track) 00164 { 00165 MovieTracking *tracking= &clip->tracking; 00166 MovieTrackingStabilization *stab= &tracking->stabilization; 00167 MovieTrackingTrack *act_track= BKE_tracking_active_track(tracking); 00168 00169 int has_bundle= 0, update_stab= 0; 00170 00171 if(track==act_track) 00172 tracking->act_track= NULL; 00173 00174 if(track==stab->rot_track) { 00175 stab->rot_track= NULL; 00176 00177 update_stab= 1; 00178 } 00179 00180 /* handle reconstruction display in 3d viewport */ 00181 if(track->flag&TRACK_HAS_BUNDLE) 00182 has_bundle= 1; 00183 00184 BKE_tracking_free_track(track); 00185 BLI_freelinkN(tracksbase, track); 00186 00187 WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip); 00188 00189 if(update_stab) { 00190 tracking->stabilization.ok= 0; 00191 00192 DAG_id_tag_update(&clip->id, 0); 00193 WM_event_add_notifier(C, NC_MOVIECLIP|ND_DISPLAY, clip); 00194 } 00195 00196 if(has_bundle) 00197 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL); 00198 } 00199 00200 void clip_delete_marker(bContext *C, MovieClip *clip, ListBase *tracksbase, MovieTrackingTrack *track, MovieTrackingMarker *marker) 00201 { 00202 if(track->markersnr==1) { 00203 clip_delete_track(C, clip, tracksbase, track); 00204 } 00205 else { 00206 BKE_tracking_delete_marker(track, marker->framenr); 00207 00208 WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip); 00209 } 00210 } 00211 00212 void clip_view_center_to_point(SpaceClip *sc, float x, float y) 00213 { 00214 int width, height; 00215 float aspx, aspy; 00216 00217 ED_space_clip_size(sc, &width, &height); 00218 ED_space_clip_aspect(sc, &aspx, &aspy); 00219 00220 sc->xof= (x-0.5f)*width*aspx; 00221 sc->yof= (y-0.5f)*height*aspy; 00222 }