Pass EvaluationContext argument everywhere
[blender.git] / source / blender / blenkernel / BKE_tracking.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2011 Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation,
22  *                 Sergey Sharybin
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 #ifndef __BKE_TRACKING_H__
28 #define __BKE_TRACKING_H__
29
30 /** \file BKE_tracking.h
31  *  \ingroup bke
32  *  \author Sergey Sharybin
33  */
34
35 struct bGPDlayer;
36 struct ImBuf;
37 struct ListBase;
38 struct MovieReconstructContext;
39 struct MovieTrackingTrack;
40 struct MovieTrackingMarker;
41 struct MovieTrackingPlaneTrack;
42 struct MovieTrackingPlaneMarker;
43 struct MovieTracking;
44 struct MovieTrackingObject;
45 struct MovieClipUser;
46 struct MovieDistortion;
47 struct Camera;
48 struct Object;
49 struct Scene;
50 struct EvaluationContext;
51 struct rcti;
52
53 /* **** Common functions **** */
54
55 void BKE_tracking_free(struct MovieTracking *tracking);
56 void BKE_tracking_copy(struct MovieTracking *tracking_dst, const struct MovieTracking *tracking_src);
57
58 void BKE_tracking_settings_init(struct MovieTracking *tracking);
59
60 struct ListBase *BKE_tracking_get_active_tracks(struct MovieTracking *tracking);
61 struct ListBase *BKE_tracking_get_active_plane_tracks(struct MovieTracking *tracking);
62 struct MovieTrackingReconstruction *BKE_tracking_get_active_reconstruction(struct MovieTracking *tracking);
63
64 /* matrices for constraints and drawing */
65 void BKE_tracking_get_camera_object_matrix(struct Scene *scene, struct Object *ob, float mat[4][4]);
66 void BKE_tracking_get_projection_matrix(struct MovieTracking *tracking, struct MovieTrackingObject *object,
67                                         int framenr, int winx, int winy, float mat[4][4]);
68
69 /* **** Clipboard **** */
70 void BKE_tracking_clipboard_free(void);
71 void BKE_tracking_clipboard_copy_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
72 bool BKE_tracking_clipboard_has_tracks(void);
73 void BKE_tracking_clipboard_paste_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
74
75 /* **** Track **** */
76 struct MovieTrackingTrack *BKE_tracking_track_add(struct MovieTracking *tracking, struct ListBase *tracksbase,
77                                                   float x, float y, int framenr, int width, int height);
78 struct MovieTrackingTrack *BKE_tracking_track_duplicate(struct MovieTrackingTrack *track);
79 void BKE_tracking_track_unique_name(struct ListBase *tracksbase, struct MovieTrackingTrack *track);
80 void BKE_tracking_track_free(struct MovieTrackingTrack *track);
81
82 void BKE_tracking_track_flag_set(struct MovieTrackingTrack *track, int area, int flag);
83 void BKE_tracking_track_flag_clear(struct MovieTrackingTrack *track, int area, int flag);
84
85 bool BKE_tracking_track_has_marker_at_frame(struct MovieTrackingTrack *track, int framenr);
86 bool BKE_tracking_track_has_enabled_marker_at_frame(struct MovieTrackingTrack *track, int framenr);
87
88 void BKE_tracking_track_path_clear(struct MovieTrackingTrack *track, int ref_frame, int action);
89 void BKE_tracking_tracks_join(struct MovieTracking *tracking, struct MovieTrackingTrack *dst_track, struct MovieTrackingTrack *src_track);
90
91 struct MovieTrackingTrack *BKE_tracking_track_get_named(struct MovieTracking *tracking,
92                                                         struct MovieTrackingObject *object,
93                                                         const char *name);
94 struct MovieTrackingTrack *BKE_tracking_track_get_indexed(struct MovieTracking *tracking, int tracknr,
95                                                           struct ListBase **r_tracksbase);
96
97 struct MovieTrackingTrack *BKE_tracking_track_get_active(struct MovieTracking *tracking);
98
99 float *BKE_tracking_track_get_mask(int frame_width, int frame_height, struct MovieTrackingTrack *track,
100                                    struct MovieTrackingMarker *marker);
101
102 float BKE_tracking_track_get_weight_for_marker(struct MovieClip *clip, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker);
103
104 /* selection */
105 void BKE_tracking_track_select(struct ListBase *tracksbase, struct MovieTrackingTrack *track, int area, bool extend);
106 void BKE_tracking_track_deselect(struct MovieTrackingTrack *track, int area);
107 void BKE_tracking_tracks_deselect_all(struct ListBase *tracksbase);
108
109 /* **** Marker **** */
110 struct MovieTrackingMarker *BKE_tracking_marker_insert(struct MovieTrackingTrack *track,
111                                                        struct MovieTrackingMarker *marker);
112 void BKE_tracking_marker_delete(struct MovieTrackingTrack *track, int framenr);
113
114 void BKE_tracking_marker_clamp(struct MovieTrackingMarker *marker, int event);
115
116 struct MovieTrackingMarker *BKE_tracking_marker_get(struct MovieTrackingTrack *track, int framenr);
117 struct MovieTrackingMarker *BKE_tracking_marker_get_exact(struct MovieTrackingTrack *track, int framenr);
118 struct MovieTrackingMarker *BKE_tracking_marker_ensure(struct MovieTrackingTrack *track, int framenr);
119
120 void BKE_tracking_marker_pattern_minmax(const struct MovieTrackingMarker *marker, float min[2], float max[2]);
121
122 void BKE_tracking_marker_get_subframe_position(struct MovieTrackingTrack *track, float framenr, float pos[2]);
123
124 /* **** Plane Track **** */
125 struct MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(struct MovieTracking *tracking, struct ListBase *plane_tracks_base,
126                                                              struct ListBase *tracks, int framenr);
127 void BKE_tracking_plane_track_unique_name(struct ListBase *plane_tracks_base, struct MovieTrackingPlaneTrack *plane_track);
128 void BKE_tracking_plane_track_free(struct MovieTrackingPlaneTrack *plane_track);
129
130 bool BKE_tracking_plane_track_has_marker_at_frame(struct MovieTrackingPlaneTrack *plane_track, int framenr);
131 bool BKE_tracking_plane_track_has_enabled_marker_at_frame(struct MovieTrackingPlaneTrack *plane_track, int framenr);
132
133 struct MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_named(struct MovieTracking *tracking,
134                                                                    struct MovieTrackingObject *object,
135                                                                    const char *name);
136
137 struct MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_active(struct MovieTracking *tracking);
138
139 void BKE_tracking_plane_tracks_deselect_all(struct ListBase *plane_tracks_base);
140
141 bool BKE_tracking_plane_track_has_point_track(struct MovieTrackingPlaneTrack *plane_track,
142                                               struct MovieTrackingTrack *track);
143 bool BKE_tracking_plane_track_remove_point_track(struct MovieTrackingPlaneTrack *plane_track,
144                                                  struct MovieTrackingTrack *track);
145
146 void BKE_tracking_plane_tracks_remove_point_track(struct MovieTracking *tracking,
147                                                   struct MovieTrackingTrack *track);
148
149 void BKE_tracking_plane_track_replace_point_track(struct MovieTrackingPlaneTrack *plane_track,
150                                                   struct MovieTrackingTrack *old_track,
151                                                   struct MovieTrackingTrack *new_track);
152 void BKE_tracking_plane_tracks_replace_point_track(struct MovieTracking *tracking,
153                                                    struct MovieTrackingTrack *old_track,
154                                                    struct MovieTrackingTrack *new_track);
155
156 /* **** Plane Marker **** */
157 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_insert(struct MovieTrackingPlaneTrack *plane_track,
158                                                                   struct MovieTrackingPlaneMarker *plane_marker);
159 void BKE_tracking_plane_marker_delete(struct MovieTrackingPlaneTrack *plane_track, int framenr);
160
161 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_get(struct MovieTrackingPlaneTrack *plane_track, int framenr);
162 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_get_exact(struct MovieTrackingPlaneTrack *plane_track, int framenr);
163 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_ensure(struct MovieTrackingPlaneTrack *plane_track, int framenr);
164 void BKE_tracking_plane_marker_get_subframe_corners(struct MovieTrackingPlaneTrack *plane_track,
165                                                     float framenr,
166                                                     float corners[4][2]);
167
168 /* **** Object **** */
169 struct MovieTrackingObject *BKE_tracking_object_add(struct MovieTracking *tracking, const char *name);
170 bool BKE_tracking_object_delete(struct MovieTracking *tracking, struct MovieTrackingObject *object);
171
172 void BKE_tracking_object_unique_name(struct MovieTracking *tracking, struct MovieTrackingObject *object);
173
174 struct MovieTrackingObject *BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name);
175
176 struct MovieTrackingObject *BKE_tracking_object_get_active(struct MovieTracking *tracking);
177 struct MovieTrackingObject *BKE_tracking_object_get_camera(struct MovieTracking *tracking);
178
179 struct ListBase *BKE_tracking_object_get_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
180 struct ListBase *BKE_tracking_object_get_plane_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
181 struct MovieTrackingReconstruction *BKE_tracking_object_get_reconstruction(struct MovieTracking *tracking,
182                                                                            struct MovieTrackingObject *object);
183
184 /* **** Camera **** */
185 void BKE_tracking_camera_shift_get(struct MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty);
186 void BKE_tracking_camera_to_blender(struct MovieTracking *tracking, struct Scene *scene,
187                                     struct Camera *camera, int width, int height);
188
189 struct MovieReconstructedCamera *BKE_tracking_camera_get_reconstructed(struct MovieTracking *tracking,
190                                                                        struct MovieTrackingObject *object,
191                                                                        int framenr);
192 void BKE_tracking_camera_get_reconstructed_interpolate(struct MovieTracking *tracking,
193                                                        struct MovieTrackingObject *object,
194                                                        float framenr, float mat[4][4]);
195
196 /* **** Distortion/Undistortion **** */
197 struct MovieDistortion *BKE_tracking_distortion_new(struct MovieTracking *tracking,
198                                                     int calibration_width, int calibration_height);
199 void BKE_tracking_distortion_update(struct MovieDistortion *distortion, struct MovieTracking *tracking,
200                                     int calibration_width, int calibration_height);
201 void BKE_tracking_distortion_set_threads(struct MovieDistortion *distortion, int threads);
202 struct MovieDistortion *BKE_tracking_distortion_copy(struct MovieDistortion *distortion);
203 struct ImBuf *BKE_tracking_distortion_exec(struct MovieDistortion *distortion, struct MovieTracking *tracking,
204                                            struct ImBuf *ibuf, int width, int height, float overscan, bool undistort);
205 void BKE_tracking_distortion_distort_v2(struct MovieDistortion *distortion,
206                                         const float co[2],
207                                         float r_co[2]);
208 void BKE_tracking_distortion_undistort_v2(struct MovieDistortion *distortion,
209                                           const float co[2],
210                                           float r_co[2]);
211 void BKE_tracking_distortion_free(struct MovieDistortion *distortion);
212
213 void BKE_tracking_distort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]);
214 void BKE_tracking_undistort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]);
215
216 struct ImBuf *BKE_tracking_undistort_frame(struct MovieTracking *tracking, struct ImBuf *ibuf,
217                                            int calibration_width, int calibration_height, float overscan);
218 struct ImBuf *BKE_tracking_distort_frame(struct MovieTracking *tracking, struct ImBuf *ibuf,
219                                          int calibration_width, int calibration_height, float overscan);
220
221 void BKE_tracking_max_distortion_delta_across_bound(struct MovieTracking *tracking, struct rcti *rect,
222                                                     bool undistort, float delta[2]);
223
224 /* **** Image sampling **** */
225 struct ImBuf *BKE_tracking_sample_pattern(int frame_width, int frame_height,
226                                           struct ImBuf *struct_ibuf, struct MovieTrackingTrack *track,
227                                           struct MovieTrackingMarker *marker, bool from_anchor, bool use_mask,
228                                           int num_samples_x, int num_samples_y, float pos[2]);
229 struct ImBuf *BKE_tracking_get_pattern_imbuf(struct ImBuf *ibuf, struct MovieTrackingTrack *track,
230                                              struct MovieTrackingMarker *marker, bool anchored, bool disable_channels);
231 struct ImBuf *BKE_tracking_get_search_imbuf(struct ImBuf *ibuf, struct MovieTrackingTrack *track,
232                                             struct MovieTrackingMarker *marker, bool anchored, bool disable_channels);
233
234 void BKE_tracking_disable_channels(struct ImBuf *ibuf, bool disable_red, bool disable_green,
235                                    bool disable_blue, bool grayscale);
236
237 /* **** 2D tracking **** */
238 void BKE_tracking_refine_marker(struct MovieClip *clip, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker, bool backwards);
239
240 /* *** 2D auto track  *** */
241
242 struct AutoTrackContext *BKE_autotrack_context_new(struct MovieClip *clip, struct MovieClipUser *user,
243                                                    const bool backwards, const bool sequence);
244 bool BKE_autotrack_context_step(struct AutoTrackContext *context);
245 void BKE_autotrack_context_sync(struct AutoTrackContext *context);
246 void BKE_autotrack_context_sync_user(struct AutoTrackContext *context, struct MovieClipUser *user);
247 void BKE_autotrack_context_finish(struct AutoTrackContext *context);
248 void BKE_autotrack_context_free(struct AutoTrackContext *context);
249
250 /* **** Plane tracking **** */
251
252 void BKE_tracking_track_plane_from_existing_motion(struct MovieTrackingPlaneTrack *plane_track, int start_frame);
253 void BKE_tracking_retrack_plane_from_existing_motion_at_segment(struct MovieTrackingPlaneTrack *plane_track, int start_frame);
254 void BKE_tracking_homography_between_two_quads(/*const*/ float reference_corners[4][2], /*const*/ float corners[4][2], float H[3][3]);
255
256 /* **** Camera solving **** */
257 bool BKE_tracking_reconstruction_check(struct MovieTracking *tracking, struct MovieTrackingObject *object,
258                                        char *error_msg, int error_size);
259
260 struct MovieReconstructContext *BKE_tracking_reconstruction_context_new(struct MovieClip *clip,
261                                                                         struct MovieTrackingObject *object,
262                                                                         int keyframe1, int keyframe2,
263                                                                         int width, int height);
264 void BKE_tracking_reconstruction_context_free(struct MovieReconstructContext *context);
265 void BKE_tracking_reconstruction_solve(struct MovieReconstructContext *context, short *stop, short *do_update,
266                                        float *progress, char *stats_message, int message_size);
267 bool BKE_tracking_reconstruction_finish(struct MovieReconstructContext *context, struct MovieTracking *tracking);
268
269 void BKE_tracking_reconstruction_scale(struct MovieTracking *tracking, float scale[3]);
270
271 /* **** Feature detection **** */
272 void BKE_tracking_detect_fast(struct MovieTracking *tracking, struct ListBase *tracksbase, struct ImBuf *imbuf,
273                               int framenr, int margin, int min_trackness, int min_distance, struct bGPDlayer *layer,
274                               bool place_outside_layer);
275
276 void BKE_tracking_detect_harris(struct MovieTracking *tracking, struct ListBase *tracksbase, struct ImBuf *ibuf,
277                                 int framenr, int margin, float threshold, int min_distance, struct bGPDlayer *layer,
278                                 bool place_outside_layer);
279
280 /* **** 2D stabilization **** */
281 void BKE_tracking_stabilization_data_get(struct MovieClip *clip, int framenr, int width, int height,
282                                          float translation[2], float *scale, float *angle);
283 struct ImBuf *BKE_tracking_stabilize_frame(struct MovieClip *clip, int framenr, struct ImBuf *ibuf,
284                                            float translation[2], float *scale, float *angle);
285 void BKE_tracking_stabilization_data_to_mat4(int width, int height, float aspect, float translation[2],
286                                              float scale, float angle, float mat[4][4]);
287
288 /* Dopesheet */
289 void BKE_tracking_dopesheet_tag_update(struct MovieTracking *tracking);
290 void BKE_tracking_dopesheet_update(struct MovieTracking *tracking);
291
292 #define TRACK_SELECTED(track)               ((track)->flag & SELECT || (track)->pat_flag & SELECT || (track)->search_flag & SELECT)
293
294 #define TRACK_AREA_SELECTED(track, area)    ((area) == TRACK_AREA_POINT ? (track)->flag & SELECT : \
295                                              ((area) == TRACK_AREA_PAT ? (track)->pat_flag & SELECT : \
296                                               (track)->search_flag & SELECT))
297
298 #define TRACK_VIEW_SELECTED(sc, track)      ((((track)->flag & TRACK_HIDDEN) == 0) && \
299                                              (TRACK_AREA_SELECTED(track, TRACK_AREA_POINT) || \
300                                               (((sc)->flag & SC_SHOW_MARKER_PATTERN) && TRACK_AREA_SELECTED(track, TRACK_AREA_PAT)) || \
301                                               (((sc)->flag & SC_SHOW_MARKER_SEARCH) && TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH))))
302
303 #define PLANE_TRACK_VIEW_SELECTED(plane_track) ((((plane_track)->flag & PLANE_TRACK_HIDDEN) == 0) && \
304                                                  ((plane_track)->flag & SELECT))
305
306 #define MARKER_VISIBLE(sc, track, marker)       (((marker)->flag & MARKER_DISABLED) == 0 || ((sc)->flag & SC_HIDE_DISABLED) == 0 || (sc->clip->tracking.act_track == track))
307
308 #define TRACK_CLEAR_UPTO        0
309 #define TRACK_CLEAR_REMAINED    1
310 #define TRACK_CLEAR_ALL         2
311
312 #define CLAMP_PAT_DIM       1
313 #define CLAMP_PAT_POS       2
314 #define CLAMP_SEARCH_DIM    3
315 #define CLAMP_SEARCH_POS    4
316
317 #define TRACK_AREA_NONE     -1
318 #define TRACK_AREA_POINT    1
319 #define TRACK_AREA_PAT      2
320 #define TRACK_AREA_SEARCH   4
321
322 #define TRACK_AREA_ALL      (TRACK_AREA_POINT | TRACK_AREA_PAT | TRACK_AREA_SEARCH)
323
324 #endif