Code cleanup: use r_ prefix for return args
[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 MovieTrackingContext;
45 struct MovieTrackingObject;
46 struct MovieClipUser;
47 struct MovieDistortion;
48 struct Camera;
49 struct Object;
50 struct Scene;
51 struct rcti;
52
53 /* **** Common functions **** */
54
55 void BKE_tracking_free(struct MovieTracking *tracking);
56
57 void BKE_tracking_settings_init(struct MovieTracking *tracking);
58
59 struct ListBase *BKE_tracking_get_active_tracks(struct MovieTracking *tracking);
60 struct ListBase *BKE_tracking_get_active_plane_tracks(struct MovieTracking *tracking);
61 struct MovieTrackingReconstruction *BKE_tracking_get_active_reconstruction(struct MovieTracking *tracking);
62
63 /* matrices for constraints and drawing */
64 void BKE_tracking_get_camera_object_matrix(struct Scene *scene, struct Object *ob, float mat[4][4]);
65 void BKE_tracking_get_projection_matrix(struct MovieTracking *tracking, struct MovieTrackingObject *object,
66                                         int framenr, int winx, int winy, float mat[4][4]);
67
68 /* **** Clipboard **** */
69 void BKE_tracking_clipboard_free(void);
70 void BKE_tracking_clipboard_copy_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
71 bool BKE_tracking_clipboard_has_tracks(void);
72 void BKE_tracking_clipboard_paste_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
73
74 /* **** Track **** */
75 struct MovieTrackingTrack *BKE_tracking_track_add(struct MovieTracking *tracking, struct ListBase *tracksbase,
76                                                   float x, float y, int framenr, int width, int height);
77 struct MovieTrackingTrack *BKE_tracking_track_duplicate(struct MovieTrackingTrack *track);
78 void BKE_tracking_track_unique_name(struct ListBase *tracksbase, struct MovieTrackingTrack *track);
79 void BKE_tracking_track_free(struct MovieTrackingTrack *track);
80
81 void BKE_tracking_track_flag_set(struct MovieTrackingTrack *track, int area, int flag);
82 void BKE_tracking_track_flag_clear(struct MovieTrackingTrack *track, int area, int flag);
83
84 bool BKE_tracking_track_has_marker_at_frame(struct MovieTrackingTrack *track, int framenr);
85 bool BKE_tracking_track_has_enabled_marker_at_frame(struct MovieTrackingTrack *track, int framenr);
86
87 void BKE_tracking_track_path_clear(struct MovieTrackingTrack *track, int ref_frame, int action);
88 void BKE_tracking_tracks_join(struct MovieTracking *tracking, struct MovieTrackingTrack *dst_track, struct MovieTrackingTrack *src_track);
89
90 struct MovieTrackingTrack *BKE_tracking_track_get_named(struct MovieTracking *tracking,
91                                                         struct MovieTrackingObject *object,
92                                                         const char *name);
93 struct MovieTrackingTrack *BKE_tracking_track_get_indexed(struct MovieTracking *tracking, int tracknr,
94                                                           struct ListBase **tracksbase_r);
95
96 struct MovieTrackingTrack *BKE_tracking_track_get_active(struct MovieTracking *tracking);
97
98 float *BKE_tracking_track_get_mask(int frame_width, int frame_height, struct MovieTrackingTrack *track,
99                                    struct MovieTrackingMarker *marker);
100
101 float BKE_tracking_track_get_weight_for_marker(struct MovieClip *clip, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker);
102
103 /* selection */
104 void BKE_tracking_track_select(struct ListBase *tracksbase, struct MovieTrackingTrack *track, int area, bool extend);
105 void BKE_tracking_track_deselect(struct MovieTrackingTrack *track, int area);
106 void BKE_tracking_tracks_deselect_all(struct ListBase *tracksbase);
107
108 /* **** Marker **** */
109 struct MovieTrackingMarker *BKE_tracking_marker_insert(struct MovieTrackingTrack *track,
110                                                        struct MovieTrackingMarker *marker);
111 void BKE_tracking_marker_delete(struct MovieTrackingTrack *track, int framenr);
112
113 void BKE_tracking_marker_clamp(struct MovieTrackingMarker *marker, int event);
114
115 struct MovieTrackingMarker *BKE_tracking_marker_get(struct MovieTrackingTrack *track, int framenr);
116 struct MovieTrackingMarker *BKE_tracking_marker_get_exact(struct MovieTrackingTrack *track, int framenr);
117 struct MovieTrackingMarker *BKE_tracking_marker_ensure(struct MovieTrackingTrack *track, int framenr);
118
119 void BKE_tracking_marker_pattern_minmax(const struct MovieTrackingMarker *marker, float min[2], float max[2]);
120
121 void BKE_tracking_marker_get_subframe_position(struct MovieTrackingTrack *track, float framenr, float pos[2]);
122
123 /* **** Plane Track **** */
124 struct MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(struct MovieTracking *tracking, struct ListBase *plane_tracks_base,
125                                                              struct ListBase *tracks, int framenr);
126 void BKE_tracking_plane_track_unique_name(struct ListBase *plane_tracks_base, struct MovieTrackingPlaneTrack *plane_track);
127 void BKE_tracking_plane_track_free(struct MovieTrackingPlaneTrack *plane_track);
128
129 bool BKE_tracking_plane_track_has_marker_at_frame(struct MovieTrackingPlaneTrack *plane_track, int framenr);
130 bool BKE_tracking_plane_track_has_enabled_marker_at_frame(struct MovieTrackingPlaneTrack *plane_track, int framenr);
131
132 struct MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_named(struct MovieTracking *tracking,
133                                                                    struct MovieTrackingObject *object,
134                                                                    const char *name);
135
136 struct MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_active(struct MovieTracking *tracking);
137
138 void BKE_tracking_plane_tracks_deselect_all(struct ListBase *plane_tracks_base);
139
140 /* **** Plane Marker **** */
141 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_insert(struct MovieTrackingPlaneTrack *plane_track,
142                                                                   struct MovieTrackingPlaneMarker *plane_marker);
143 void BKE_tracking_plane_marker_delete(struct MovieTrackingPlaneTrack *plane_track, int framenr);
144
145 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_get(struct MovieTrackingPlaneTrack *plane_track, int framenr);
146 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_get_exact(struct MovieTrackingPlaneTrack *plane_track, int framenr);
147 struct MovieTrackingPlaneMarker *BKE_tracking_plane_marker_ensure(struct MovieTrackingPlaneTrack *plane_track, int framenr);
148
149 /* **** Object **** */
150 struct MovieTrackingObject *BKE_tracking_object_add(struct MovieTracking *tracking, const char *name);
151 bool BKE_tracking_object_delete(struct MovieTracking *tracking, struct MovieTrackingObject *object);
152
153 void BKE_tracking_object_unique_name(struct MovieTracking *tracking, struct MovieTrackingObject *object);
154
155 struct MovieTrackingObject *BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name);
156
157 struct MovieTrackingObject *BKE_tracking_object_get_active(struct MovieTracking *tracking);
158 struct MovieTrackingObject *BKE_tracking_object_get_camera(struct MovieTracking *tracking);
159
160 struct ListBase *BKE_tracking_object_get_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
161 struct ListBase *BKE_tracking_object_get_plane_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
162 struct MovieTrackingReconstruction *BKE_tracking_object_get_reconstruction(struct MovieTracking *tracking,
163                                                                            struct MovieTrackingObject *object);
164
165 /* **** Camera **** */
166 void BKE_tracking_camera_shift_get(struct MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty);
167 void BKE_tracking_camera_to_blender(struct MovieTracking *tracking, struct Scene *scene,
168                                     struct Camera *camera, int width, int height);
169
170 struct MovieReconstructedCamera *BKE_tracking_camera_get_reconstructed(struct MovieTracking *tracking,
171                                                                        struct MovieTrackingObject *object,
172                                                                        int framenr);
173 void BKE_tracking_camera_get_reconstructed_interpolate(struct MovieTracking *tracking,
174                                                        struct MovieTrackingObject *object,
175                                                        int framenr, float mat[4][4]);
176
177 /* **** Distortion/Undistortion **** */
178 struct MovieDistortion *BKE_tracking_distortion_new(void);
179 void BKE_tracking_distortion_update(struct MovieDistortion *distortion, struct MovieTracking *tracking,
180                                     int calibration_width, int calibration_height);
181 void BKE_tracking_distortion_set_threads(struct MovieDistortion *distortion, int threads);
182 struct MovieDistortion *BKE_tracking_distortion_copy(struct MovieDistortion *distortion);
183 struct ImBuf *BKE_tracking_distortion_exec(struct MovieDistortion *distortion, struct MovieTracking *tracking,
184                                            struct ImBuf *ibuf, int width, int height, float overscan, bool undistort);
185 void BKE_tracking_distortion_free(struct MovieDistortion *distortion);
186
187 void BKE_tracking_distort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]);
188 void BKE_tracking_undistort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]);
189
190 struct ImBuf *BKE_tracking_undistort_frame(struct MovieTracking *tracking, struct ImBuf *ibuf,
191                                            int calibration_width, int calibration_height, float overscan);
192 struct ImBuf *BKE_tracking_distort_frame(struct MovieTracking *tracking, struct ImBuf *ibuf,
193                                          int calibration_width, int calibration_height, float overscan);
194
195 void BKE_tracking_max_undistortion_delta_across_bound(struct MovieTracking *tracking, struct rcti *rect, float delta[2]);
196
197 /* **** Image sampling **** */
198 struct ImBuf *BKE_tracking_sample_pattern(int frame_width, int frame_height,
199                                           struct ImBuf *struct_ibuf, struct MovieTrackingTrack *track,
200                                           struct MovieTrackingMarker *marker, bool from_anchor, bool use_mask,
201                                           int num_samples_x, int num_samples_y, float pos[2]);
202 struct ImBuf *BKE_tracking_get_pattern_imbuf(struct ImBuf *ibuf, struct MovieTrackingTrack *track,
203                                              struct MovieTrackingMarker *marker, bool anchored, bool disable_channels);
204 struct ImBuf *BKE_tracking_get_search_imbuf(struct ImBuf *ibuf, struct MovieTrackingTrack *track,
205                                             struct MovieTrackingMarker *marker, bool anchored, bool disable_channels);
206
207 void BKE_tracking_disable_channels(struct ImBuf *ibuf, bool disable_red, bool disable_green,
208                                    bool disable_blue, bool grayscale);
209
210 /* **** 2D tracking **** */
211 struct MovieTrackingContext *BKE_tracking_context_new(struct MovieClip *clip, struct MovieClipUser *user,
212                                                       const bool backwards, const bool sequence);
213 void BKE_tracking_context_free(struct MovieTrackingContext *context);
214 void BKE_tracking_context_sync(struct MovieTrackingContext *context);
215 void BKE_tracking_context_sync_user(const struct MovieTrackingContext *context, struct MovieClipUser *user);
216 bool BKE_tracking_context_step(struct MovieTrackingContext *context);
217 void BKE_tracking_context_finish(struct MovieTrackingContext *context);
218
219 void BKE_tracking_refine_marker(struct MovieClip *clip, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker, bool backwards);
220
221 /* **** Plane tracking **** */
222
223 void BKE_tracking_track_plane_from_existing_motion(struct MovieTrackingPlaneTrack *plane_track, int start_frame);
224 void BKE_tracking_retrack_plane_from_existing_motion_at_segment(struct MovieTrackingPlaneTrack *plane_track, int start_frame);
225 void BKE_tracking_homography_between_two_quads(/*const*/ float reference_corners[4][2], /*const*/ float corners[4][2], float H[3][3]);
226
227 /* **** Camera solving **** */
228 bool BKE_tracking_reconstruction_check(struct MovieTracking *tracking, struct MovieTrackingObject *object,
229                                        char *error_msg, int error_size);
230
231 struct MovieReconstructContext *BKE_tracking_reconstruction_context_new(struct MovieClip *clip,
232                                                                         struct MovieTrackingObject *object,
233                                                                         int keyframe1, int keyframe2,
234                                                                         int width, int height);
235 void BKE_tracking_reconstruction_context_free(struct MovieReconstructContext *context);
236 void BKE_tracking_reconstruction_solve(struct MovieReconstructContext *context, short *stop, short *do_update,
237                                        float *progress, char *stats_message, int message_size);
238 bool BKE_tracking_reconstruction_finish(struct MovieReconstructContext *context, struct MovieTracking *tracking);
239
240 void BKE_tracking_reconstruction_scale(struct MovieTracking *tracking, float scale[3]);
241
242 /* **** Feature detection **** */
243 void BKE_tracking_detect_fast(struct MovieTracking *tracking, struct ListBase *tracksbase, struct ImBuf *imbuf,
244                               int framenr, int margin, int min_trackness, int min_distance, struct bGPDlayer *layer,
245                               bool place_outside_layer);
246
247 void BKE_tracking_detect_harris(struct MovieTracking *tracking, struct ListBase *tracksbase, struct ImBuf *ibuf,
248                                 int framenr, int margin, float threshold, int min_distance, struct bGPDlayer *layer,
249                                 bool place_outside_layer);
250
251 /* **** 2D stabilization **** */
252 void BKE_tracking_stabilization_data_get(struct MovieTracking *tracking, int framenr, int width, int height,
253                                          float translation[2], float *scale, float *angle);
254 struct ImBuf *BKE_tracking_stabilize_frame(struct MovieTracking *tracking, int framenr, struct ImBuf *ibuf,
255                                            float translation[2], float *scale, float *angle);
256 void BKE_tracking_stabilization_data_to_mat4(int width, int height, float aspect, float translation[2],
257                                              float scale, float angle, float mat[4][4]);
258
259 /* Dopesheet */
260 void BKE_tracking_dopesheet_tag_update(struct MovieTracking *tracking);
261 void BKE_tracking_dopesheet_update(struct MovieTracking *tracking);
262
263 #define TRACK_SELECTED(track)               ((track)->flag & SELECT || (track)->pat_flag & SELECT || (track)->search_flag & SELECT)
264
265 #define TRACK_AREA_SELECTED(track, area)    ((area) == TRACK_AREA_POINT ? (track)->flag & SELECT : \
266                                              ((area) == TRACK_AREA_PAT ? (track)->pat_flag & SELECT : \
267                                               (track)->search_flag & SELECT))
268
269 #define TRACK_VIEW_SELECTED(sc, track)      ((((track)->flag & TRACK_HIDDEN) == 0) && \
270                                              (TRACK_AREA_SELECTED(track, TRACK_AREA_POINT) || \
271                                               (((sc)->flag & SC_SHOW_MARKER_PATTERN) && TRACK_AREA_SELECTED(track, TRACK_AREA_PAT)) || \
272                                               (((sc)->flag & SC_SHOW_MARKER_SEARCH) && TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH))))
273
274 #define PLANE_TRACK_VIEW_SELECTED(plane_track) ((((plane_track)->flag & PLANE_TRACK_HIDDEN) == 0) && \
275                                                  ((plane_track)->flag & SELECT))
276
277 #define MARKER_VISIBLE(sc, track, marker)       (((marker)->flag & MARKER_DISABLED) == 0 || ((sc)->flag & SC_HIDE_DISABLED) == 0 || (sc->clip->tracking.act_track == track))
278
279 #define TRACK_CLEAR_UPTO        0
280 #define TRACK_CLEAR_REMAINED    1
281 #define TRACK_CLEAR_ALL         2
282
283 #define CLAMP_PAT_DIM       1
284 #define CLAMP_PAT_POS       2
285 #define CLAMP_SEARCH_DIM    3
286 #define CLAMP_SEARCH_POS    4
287
288 #define TRACK_AREA_NONE     -1
289 #define TRACK_AREA_POINT    1
290 #define TRACK_AREA_PAT      2
291 #define TRACK_AREA_SEARCH   4
292
293 #define TRACK_AREA_ALL      (TRACK_AREA_POINT | TRACK_AREA_PAT | TRACK_AREA_SEARCH)
294
295 #endif