Libmv: Add C-API function to set all markers within AutoTrack structure
[blender.git] / intern / libmv / intern / autotrack.cc
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) 2014 Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation,
22  *                 Sergey Sharybin
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 #include "intern/autotrack.h"
28 #include "intern/tracksN.h"
29 #include "intern/utildefines.h"
30 #include "libmv/autotrack/autotrack.h"
31
32 using mv::AutoTrack;
33 using mv::FrameAccessor;
34 using mv::Marker;
35 using libmv::TrackRegionOptions;
36 using libmv::TrackRegionResult;
37
38 libmv_AutoTrack* libmv_autoTrackNew(libmv_FrameAccessor *frame_accessor) {
39   return (libmv_AutoTrack*) LIBMV_OBJECT_NEW(AutoTrack,
40                                              (FrameAccessor*) frame_accessor);
41 }
42
43 void libmv_autoTrackDestroy(libmv_AutoTrack* libmv_autotrack) {
44   LIBMV_OBJECT_DELETE(libmv_autotrack, AutoTrack);
45 }
46
47 void libmv_autoTrackSetOptions(libmv_AutoTrack* libmv_autotrack,
48                                const libmv_AutoTrackOptions* options) {
49   AutoTrack *autotrack = ((AutoTrack*) libmv_autotrack);
50   libmv_configureTrackRegionOptions(options->track_region,
51                                     &autotrack->options.track_region);
52
53   autotrack->options.search_region.min(0) = options->search_region.min[0];
54   autotrack->options.search_region.min(1) = options->search_region.min[1];
55   autotrack->options.search_region.max(0) = options->search_region.max[0];
56   autotrack->options.search_region.max(1) = options->search_region.max[1];
57 }
58
59 int libmv_autoTrackMarker(libmv_AutoTrack* libmv_autotrack,
60                           const libmv_TrackRegionOptions* libmv_options,
61                           libmv_Marker *libmv_tracked_marker,
62                           libmv_TrackRegionResult* libmv_result) {
63
64   Marker tracked_marker;
65   TrackRegionOptions options;
66   TrackRegionResult result;
67   libmv_apiMarkerToMarker(*libmv_tracked_marker, &tracked_marker);
68   libmv_configureTrackRegionOptions(*libmv_options,
69                                     &options);
70   bool ok = (((AutoTrack*) libmv_autotrack)->TrackMarker(&tracked_marker,
71                                                          &result,
72                                                          &options));
73   libmv_markerToApiMarker(tracked_marker, libmv_tracked_marker);
74   libmv_regionTrackergetResult(result, libmv_result);
75   return ok && result.is_usable();
76 }
77
78 void libmv_autoTrackAddMarker(libmv_AutoTrack* libmv_autotrack,
79                               const libmv_Marker* libmv_marker) {
80   Marker marker;
81   libmv_apiMarkerToMarker(*libmv_marker, &marker);
82   ((AutoTrack*) libmv_autotrack)->AddMarker(marker);
83 }
84
85 void libmv_autoTrackSetMarkers(libmv_AutoTrack* libmv_autotrack,
86                                const libmv_Marker* libmv_marker,
87                                size_t num_markers) {
88   if (num_markers == 0) {
89     // Early output.
90     return;
91   }
92   libmv::vector<Marker> markers;
93   markers.resize(num_markers);
94   for (size_t i = 0; i < num_markers; ++i) {
95     libmv_apiMarkerToMarker(libmv_marker[i], &markers[i]);
96   }
97   ((AutoTrack*) libmv_autotrack)->SetMarkers(&markers);
98 }
99
100 int libmv_autoTrackGetMarker(libmv_AutoTrack* libmv_autotrack,
101                              int clip,
102                              int frame,
103                              int track,
104                              libmv_Marker *libmv_marker) {
105   Marker marker;
106   int ok = ((AutoTrack*) libmv_autotrack)->GetMarker(clip,
107                                                      frame,
108                                                      track,
109                                                      &marker);
110   if (ok) {
111     libmv_markerToApiMarker(marker, libmv_marker);
112   }
113   return ok;
114 }