Update Eigen to 3.3.7
[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
24  * \ingroup bke
25  */
26
27 struct Camera;
28 struct Depsgraph;
29 struct ImBuf;
30 struct ListBase;
31 struct MovieClipUser;
32 struct MovieDistortion;
33 struct MovieReconstructContext;
34 struct MovieTracking;
35 struct MovieTrackingMarker;
36 struct MovieTrackingObject;
37 struct MovieTrackingPlaneMarker;
38 struct MovieTrackingPlaneTrack;
39 struct MovieTrackingTrack;
40 struct Object;
41 struct Scene;
42 struct bGPDlayer;
43 struct rcti;
44
45 /* **** Common functions **** */
46
47 void BKE_tracking_free(struct MovieTracking *tracking);
48 void BKE_tracking_copy(struct MovieTracking *tracking_dst,
49                        const struct MovieTracking *tracking_src,
50                        const int flag);
51
52 void BKE_tracking_settings_init(struct MovieTracking *tracking);
53
54 struct ListBase *BKE_tracking_get_active_tracks(struct MovieTracking *tracking);
55 struct ListBase *BKE_tracking_get_active_plane_tracks(struct MovieTracking *tracking);
56 struct MovieTrackingReconstruction *BKE_tracking_get_active_reconstruction(
57     struct MovieTracking *tracking);
58
59 /* matrices for constraints and drawing */
60 void BKE_tracking_get_camera_object_matrix(struct Scene *scene,
61                                            struct Object *ob,
62                                            float mat[4][4]);
63 void BKE_tracking_get_projection_matrix(struct MovieTracking *tracking,
64                                         struct MovieTrackingObject *object,
65                                         int framenr,
66                                         int winx,
67                                         int winy,
68                                         float mat[4][4]);
69
70 /* **** Clipboard **** */
71 void BKE_tracking_clipboard_free(void);
72 void BKE_tracking_clipboard_copy_tracks(struct MovieTracking *tracking,
73                                         struct MovieTrackingObject *object);
74 bool BKE_tracking_clipboard_has_tracks(void);
75 void BKE_tracking_clipboard_paste_tracks(struct MovieTracking *tracking,
76                                          struct MovieTrackingObject *object);
77
78 /* **** Track **** */
79 struct MovieTrackingTrack *BKE_tracking_track_add(struct MovieTracking *tracking,
80                                                   struct ListBase *tracksbase,
81                                                   float x,
82                                                   float y,
83                                                   int framenr,
84                                                   int width,
85                                                   int height);
86 struct MovieTrackingTrack *BKE_tracking_track_duplicate(struct MovieTrackingTrack *track);
87 void BKE_tracking_track_unique_name(struct ListBase *tracksbase, struct MovieTrackingTrack *track);
88 void BKE_tracking_track_free(struct MovieTrackingTrack *track);
89
90 void BKE_tracking_track_flag_set(struct MovieTrackingTrack *track, int area, int flag);
91 void BKE_tracking_track_flag_clear(struct MovieTrackingTrack *track, int area, int flag);
92
93 bool BKE_tracking_track_has_marker_at_frame(struct MovieTrackingTrack *track, int framenr);
94 bool BKE_tracking_track_has_enabled_marker_at_frame(struct MovieTrackingTrack *track, int framenr);
95
96 void BKE_tracking_track_path_clear(struct MovieTrackingTrack *track, int ref_frame, int action);
97 void BKE_tracking_tracks_join(struct MovieTracking *tracking,
98                               struct MovieTrackingTrack *dst_track,
99                               struct MovieTrackingTrack *src_track);
100
101 struct MovieTrackingTrack *BKE_tracking_track_get_named(struct MovieTracking *tracking,
102                                                         struct MovieTrackingObject *object,
103                                                         const char *name);
104 struct MovieTrackingTrack *BKE_tracking_track_get_indexed(struct MovieTracking *tracking,
105                                                           int tracknr,
106                                                           struct ListBase **r_tracksbase);
107
108 struct MovieTrackingTrack *BKE_tracking_track_get_active(struct MovieTracking *tracking);
109
110 float *BKE_tracking_track_get_mask(int frame_width,
111                                    int frame_height,
112                                    struct MovieTrackingTrack *track,
113                                    struct MovieTrackingMarker *marker);
114
115 float BKE_tracking_track_get_weight_for_marker(struct MovieClip *clip,
116                                                struct MovieTrackingTrack *track,
117                                                struct MovieTrackingMarker *marker);
118
119 /* selection */
120 void BKE_tracking_track_select(struct ListBase *tracksbase,
121                                struct MovieTrackingTrack *track,
122                                int area,
123                                bool extend);
124 void BKE_tracking_track_deselect(struct MovieTrackingTrack *track, int area);
125 void BKE_tracking_tracks_deselect_all(struct ListBase *tracksbase);
126
127 /* **** Marker **** */
128 struct MovieTrackingMarker *BKE_tracking_marker_insert(struct MovieTrackingTrack *track,
129                                                        struct MovieTrackingMarker *marker);
130 void BKE_tracking_marker_delete(struct MovieTrackingTrack *track, int framenr);
131
132 void BKE_tracking_marker_clamp(struct MovieTrackingMarker *marker, int event);
133
134 struct MovieTrackingMarker *BKE_tracking_marker_get(struct MovieTrackingTrack *track, int framenr);
135 struct MovieTrackingMarker *BKE_tracking_marker_get_exact(struct MovieTrackingTrack *track,
136                                                           int framenr);
137 struct MovieTrackingMarker *BKE_tracking_marker_ensure(struct MovieTrackingTrack *track,
138                                                        int framenr);
139
140 void BKE_tracking_marker_pattern_minmax(const struct MovieTrackingMarker *marker,
141                                         float min[2],
142                                         float max[2]);
143
144 void BKE_tracking_marker_get_subframe_position(struct MovieTrackingTrack *track,
145                                                float framenr,
146                                                float pos[2]);
147
148 /* **** Plane Track **** */
149 struct MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(struct MovieTracking *tracking,
150                                                              struct ListBase *plane_tracks_base,
151                                                              struct ListBase *tracks,
152                                                              int framenr);
153 void BKE_tracking_plane_track_unique_name(struct ListBase *plane_tracks_base,
154                                           struct MovieTrackingPlaneTrack *plane_track);
155 void BKE_tracking_plane_track_free(struct MovieTrackingPlaneTrack *plane_track);
156
157 bool BKE_tracking_plane_track_has_marker_at_frame(struct MovieTrackingPlaneTrack *plane_track,
158                                                   int framenr);
159 bool BKE_tracking_plane_track_has_enabled_marker_at_frame(
160     struct MovieTrackingPlaneTrack *plane_track, int framenr);
161
162 struct MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_named(
163     struct MovieTracking *tracking, struct MovieTrackingObject *object, const char *name);
164
165 struct MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_active(
166     struct MovieTracking *tracking);
167
168 void BKE_tracking_plane_tracks_deselect_all(struct ListBase *plane_tracks_base);
169
170 bool BKE_tracking_plane_track_has_point_track(struct MovieTrackingPlaneTrack *plane_track,
171                                               struct MovieTrackingTrack *track);
172 bool BKE_tracking_plane_track_remove_point_track(struct MovieTrackingPlaneTrack *plane_track,
173                                                  struct MovieTrackingTrack *track);
174
175 void BKE_tracking_plane_tracks_remove_point_track(struct MovieTracking *tracking,
176                                                   struct MovieTrackingTrack *track);
177
178 void BKE_tracking_plane_track_replace_point_track(struct MovieTrackingPlaneTrack *plane_track,
179                                                   struct MovieTrackingTrack *old_track,
180                                                   struct MovieTrackingTrack *new_track);
181 void BKE_tracking_plane_tracks_replace_point_track(struct MovieTracking *tracking,
182                                                    struct MovieTrackingTrack *old_track,
183                                                    struct MovieTrackingTrack *new_track);
184
185 /* **** Plane Marker **** */
186 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_insert(
187     struct MovieTrackingPlaneTrack *plane_track, struct MovieTrackingPlaneMarker *plane_marker);
188 void BKE_tracking_plane_marker_delete(struct MovieTrackingPlaneTrack *plane_track, int framenr);
189
190 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_get(
191     struct MovieTrackingPlaneTrack *plane_track, int framenr);
192 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_get_exact(
193     struct MovieTrackingPlaneTrack *plane_track, int framenr);
194 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_ensure(
195     struct MovieTrackingPlaneTrack *plane_track, int framenr);
196 void BKE_tracking_plane_marker_get_subframe_corners(struct MovieTrackingPlaneTrack *plane_track,
197                                                     float framenr,
198                                                     float corners[4][2]);
199
200 /* **** Object **** */
201 struct MovieTrackingObject *BKE_tracking_object_add(struct MovieTracking *tracking,
202                                                     const char *name);
203 bool BKE_tracking_object_delete(struct MovieTracking *tracking,
204                                 struct MovieTrackingObject *object);
205
206 void BKE_tracking_object_unique_name(struct MovieTracking *tracking,
207                                      struct MovieTrackingObject *object);
208
209 struct MovieTrackingObject *BKE_tracking_object_get_named(struct MovieTracking *tracking,
210                                                           const char *name);
211
212 struct MovieTrackingObject *BKE_tracking_object_get_active(struct MovieTracking *tracking);
213 struct MovieTrackingObject *BKE_tracking_object_get_camera(struct MovieTracking *tracking);
214
215 struct ListBase *BKE_tracking_object_get_tracks(struct MovieTracking *tracking,
216                                                 struct MovieTrackingObject *object);
217 struct ListBase *BKE_tracking_object_get_plane_tracks(struct MovieTracking *tracking,
218                                                       struct MovieTrackingObject *object);
219 struct MovieTrackingReconstruction *BKE_tracking_object_get_reconstruction(
220     struct MovieTracking *tracking, struct MovieTrackingObject *object);
221
222 /* **** Camera **** */
223 void BKE_tracking_camera_shift_get(
224     struct MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty);
225 void BKE_tracking_camera_to_blender(struct MovieTracking *tracking,
226                                     struct Scene *scene,
227                                     struct Camera *camera,
228                                     int width,
229                                     int height);
230
231 struct MovieReconstructedCamera *BKE_tracking_camera_get_reconstructed(
232     struct MovieTracking *tracking, struct MovieTrackingObject *object, int framenr);
233 void BKE_tracking_camera_get_reconstructed_interpolate(struct MovieTracking *tracking,
234                                                        struct MovieTrackingObject *object,
235                                                        float framenr,
236                                                        float mat[4][4]);
237
238 /* **** Distortion/Undistortion **** */
239 struct MovieDistortion *BKE_tracking_distortion_new(struct MovieTracking *tracking,
240                                                     int calibration_width,
241                                                     int calibration_height);
242 void BKE_tracking_distortion_update(struct MovieDistortion *distortion,
243                                     struct MovieTracking *tracking,
244                                     int calibration_width,
245                                     int calibration_height);
246 void BKE_tracking_distortion_set_threads(struct MovieDistortion *distortion, int threads);
247 struct MovieDistortion *BKE_tracking_distortion_copy(struct MovieDistortion *distortion);
248 struct ImBuf *BKE_tracking_distortion_exec(struct MovieDistortion *distortion,
249                                            struct MovieTracking *tracking,
250                                            struct ImBuf *ibuf,
251                                            int width,
252                                            int height,
253                                            float overscan,
254                                            bool undistort);
255 void BKE_tracking_distortion_distort_v2(struct MovieDistortion *distortion,
256                                         const float co[2],
257                                         float r_co[2]);
258 void BKE_tracking_distortion_undistort_v2(struct MovieDistortion *distortion,
259                                           const float co[2],
260                                           float r_co[2]);
261 void BKE_tracking_distortion_free(struct MovieDistortion *distortion);
262
263 void BKE_tracking_distort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]);
264 void BKE_tracking_undistort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]);
265
266 struct ImBuf *BKE_tracking_undistort_frame(struct MovieTracking *tracking,
267                                            struct ImBuf *ibuf,
268                                            int calibration_width,
269                                            int calibration_height,
270                                            float overscan);
271 struct ImBuf *BKE_tracking_distort_frame(struct MovieTracking *tracking,
272                                          struct ImBuf *ibuf,
273                                          int calibration_width,
274                                          int calibration_height,
275                                          float overscan);
276
277 void BKE_tracking_max_distortion_delta_across_bound(struct MovieTracking *tracking,
278                                                     struct rcti *rect,
279                                                     bool undistort,
280                                                     float delta[2]);
281
282 /* **** Image sampling **** */
283 struct ImBuf *BKE_tracking_sample_pattern(int frame_width,
284                                           int frame_height,
285                                           struct ImBuf *struct_ibuf,
286                                           struct MovieTrackingTrack *track,
287                                           struct MovieTrackingMarker *marker,
288                                           bool from_anchor,
289                                           bool use_mask,
290                                           int num_samples_x,
291                                           int num_samples_y,
292                                           float pos[2]);
293 struct ImBuf *BKE_tracking_get_pattern_imbuf(struct ImBuf *ibuf,
294                                              struct MovieTrackingTrack *track,
295                                              struct MovieTrackingMarker *marker,
296                                              bool anchored,
297                                              bool disable_channels);
298 struct ImBuf *BKE_tracking_get_search_imbuf(struct ImBuf *ibuf,
299                                             struct MovieTrackingTrack *track,
300                                             struct MovieTrackingMarker *marker,
301                                             bool anchored,
302                                             bool disable_channels);
303
304 void BKE_tracking_disable_channels(
305     struct ImBuf *ibuf, bool disable_red, bool disable_green, bool disable_blue, bool grayscale);
306
307 /* **** 2D tracking **** */
308 void BKE_tracking_refine_marker(struct MovieClip *clip,
309                                 struct MovieTrackingTrack *track,
310                                 struct MovieTrackingMarker *marker,
311                                 bool backwards);
312
313 /* *** 2D auto track  *** */
314
315 struct AutoTrackContext *BKE_autotrack_context_new(struct MovieClip *clip,
316                                                    struct MovieClipUser *user,
317                                                    const bool backwards,
318                                                    const bool sequence);
319 bool BKE_autotrack_context_step(struct AutoTrackContext *context);
320 void BKE_autotrack_context_sync(struct AutoTrackContext *context);
321 void BKE_autotrack_context_sync_user(struct AutoTrackContext *context, struct MovieClipUser *user);
322 void BKE_autotrack_context_finish(struct AutoTrackContext *context);
323 void BKE_autotrack_context_free(struct AutoTrackContext *context);
324
325 /* **** Plane tracking **** */
326
327 void BKE_tracking_track_plane_from_existing_motion(struct MovieTrackingPlaneTrack *plane_track,
328                                                    int start_frame);
329 void BKE_tracking_retrack_plane_from_existing_motion_at_segment(
330     struct MovieTrackingPlaneTrack *plane_track, int start_frame);
331 void BKE_tracking_homography_between_two_quads(/*const*/ float reference_corners[4][2],
332                                                /*const*/ float corners[4][2],
333                                                float H[3][3]);
334
335 /* **** Camera solving **** */
336 bool BKE_tracking_reconstruction_check(struct MovieTracking *tracking,
337                                        struct MovieTrackingObject *object,
338                                        char *error_msg,
339                                        int error_size);
340
341 struct MovieReconstructContext *BKE_tracking_reconstruction_context_new(
342     struct MovieClip *clip,
343     struct MovieTrackingObject *object,
344     int keyframe1,
345     int keyframe2,
346     int width,
347     int height);
348 void BKE_tracking_reconstruction_context_free(struct MovieReconstructContext *context);
349 void BKE_tracking_reconstruction_solve(struct MovieReconstructContext *context,
350                                        short *stop,
351                                        short *do_update,
352                                        float *progress,
353                                        char *stats_message,
354                                        int message_size);
355 bool BKE_tracking_reconstruction_finish(struct MovieReconstructContext *context,
356                                         struct MovieTracking *tracking);
357
358 void BKE_tracking_reconstruction_report_error_message(struct MovieReconstructContext *context,
359                                                       const char *error_message);
360
361 const char *BKE_tracking_reconstruction_error_message_get(
362     const struct MovieReconstructContext *context);
363
364 void BKE_tracking_reconstruction_scale(struct MovieTracking *tracking, float scale[3]);
365
366 /* **** Feature detection **** */
367 void BKE_tracking_detect_fast(struct MovieTracking *tracking,
368                               struct ListBase *tracksbase,
369                               struct ImBuf *imbuf,
370                               int framenr,
371                               int margin,
372                               int min_trackness,
373                               int min_distance,
374                               struct bGPDlayer *layer,
375                               bool place_outside_layer);
376
377 void BKE_tracking_detect_harris(struct MovieTracking *tracking,
378                                 struct ListBase *tracksbase,
379                                 struct ImBuf *ibuf,
380                                 int framenr,
381                                 int margin,
382                                 float threshold,
383                                 int min_distance,
384                                 struct bGPDlayer *layer,
385                                 bool place_outside_layer);
386
387 /* **** 2D stabilization **** */
388 void BKE_tracking_stabilization_data_get(struct MovieClip *clip,
389                                          int framenr,
390                                          int width,
391                                          int height,
392                                          float translation[2],
393                                          float *scale,
394                                          float *angle);
395 struct ImBuf *BKE_tracking_stabilize_frame(struct MovieClip *clip,
396                                            int framenr,
397                                            struct ImBuf *ibuf,
398                                            float translation[2],
399                                            float *scale,
400                                            float *angle);
401 void BKE_tracking_stabilization_data_to_mat4(int width,
402                                              int height,
403                                              float aspect,
404                                              float translation[2],
405                                              float scale,
406                                              float angle,
407                                              float mat[4][4]);
408
409 /* Dopesheet */
410 void BKE_tracking_dopesheet_tag_update(struct MovieTracking *tracking);
411 void BKE_tracking_dopesheet_update(struct MovieTracking *tracking);
412
413 /* **** Query/search **** */
414
415 struct MovieTrackingObject *BKE_tracking_find_object_for_track(
416     const struct MovieTracking *tracking, const struct MovieTrackingTrack *track);
417 struct ListBase *BKE_tracking_find_tracks_list_for_track(struct MovieTracking *tracking,
418                                                          const struct MovieTrackingTrack *track);
419
420 struct MovieTrackingObject *BKE_tracking_find_object_for_plane_track(
421     const struct MovieTracking *tracking, const struct MovieTrackingPlaneTrack *plane_track);
422 struct ListBase *BKE_tracking_find_tracks_list_for_plane_track(
423     struct MovieTracking *tracking, const struct MovieTrackingPlaneTrack *plane_track);
424
425 void BKE_tracking_get_rna_path_for_track(const struct MovieTracking *tracking,
426                                          const struct MovieTrackingTrack *track,
427                                          char *rna_path,
428                                          size_t rna_path_len);
429 void BKE_tracking_get_rna_path_prefix_for_track(const struct MovieTracking *tracking,
430                                                 const struct MovieTrackingTrack *track,
431                                                 char *rna_path,
432                                                 size_t rna_path_len);
433 void BKE_tracking_get_rna_path_for_plane_track(const struct MovieTracking *tracking,
434                                                const struct MovieTrackingPlaneTrack *plane_track,
435                                                char *rna_path,
436                                                size_t rna_path_len);
437 void BKE_tracking_get_rna_path_prefix_for_plane_track(
438     const struct MovieTracking *tracking,
439     const struct MovieTrackingPlaneTrack *plane_track,
440     char *rna_path,
441     size_t rna_path_len);
442
443 /* **** Utility macros **** */
444
445 #define TRACK_SELECTED(track) \
446   ((track)->flag & SELECT || (track)->pat_flag & SELECT || (track)->search_flag & SELECT)
447
448 #define TRACK_AREA_SELECTED(track, area) \
449   ((area) == TRACK_AREA_POINT ? \
450        (track)->flag & SELECT : \
451        ((area) == TRACK_AREA_PAT ? (track)->pat_flag & SELECT : (track)->search_flag & SELECT))
452
453 #define TRACK_VIEW_SELECTED(sc, track) \
454   ((((track)->flag & TRACK_HIDDEN) == 0) && \
455    (TRACK_AREA_SELECTED(track, TRACK_AREA_POINT) || \
456     (((sc)->flag & SC_SHOW_MARKER_PATTERN) && TRACK_AREA_SELECTED(track, TRACK_AREA_PAT)) || \
457     (((sc)->flag & SC_SHOW_MARKER_SEARCH) && TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH))))
458
459 #define PLANE_TRACK_VIEW_SELECTED(plane_track) \
460   ((((plane_track)->flag & PLANE_TRACK_HIDDEN) == 0) && ((plane_track)->flag & SELECT))
461
462 #define MARKER_VISIBLE(sc, track, marker) \
463   (((marker)->flag & MARKER_DISABLED) == 0 || ((sc)->flag & SC_HIDE_DISABLED) == 0 || \
464    (sc->clip->tracking.act_track == track))
465
466 #define TRACK_CLEAR_UPTO 0
467 #define TRACK_CLEAR_REMAINED 1
468 #define TRACK_CLEAR_ALL 2
469
470 #define CLAMP_PAT_DIM 1
471 #define CLAMP_PAT_POS 2
472 #define CLAMP_SEARCH_DIM 3
473 #define CLAMP_SEARCH_POS 4
474
475 #define TRACK_AREA_NONE -1
476 #define TRACK_AREA_POINT 1
477 #define TRACK_AREA_PAT 2
478 #define TRACK_AREA_SEARCH 4
479
480 #define TRACK_AREA_ALL (TRACK_AREA_POINT | TRACK_AREA_PAT | TRACK_AREA_SEARCH)
481
482 #endif