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