Speedup track preview widget for byte images
[blender.git] / extern / libmv / libmv-capi_stub.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) 2013 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 WITH_LIBMV
28
29 #include "libmv-capi.h"
30
31 #include <cstdlib>
32 #include <cstring>
33
34 /* ************ Logging ************ */
35
36 void libmv_initLogging(const char * /*argv0*/)
37 {
38 }
39
40 void libmv_startDebugLogging(void)
41 {
42 }
43
44 void libmv_setLoggingVerbosity(int /*verbosity*/)
45 {
46 }
47
48 /* ************ Planar tracker ************ */
49
50 /* TrackRegion (new planar tracker) */
51 int libmv_trackRegion(const libmv_TrackRegionOptions * /*options*/,
52                       const float * /*image1*/, int /*image1_width*/, int /*image1_height*/,
53                       const float * /*image2*/, int /*image2_width*/, int /*image2_height*/,
54                       const double *x1, const double *y1,
55                       libmv_TrackRegionResult *result,
56                       double *x2, double *y2)
57 {
58         /* Convert to doubles for the libmv api. The four corners and the center. */
59         for (int i = 0; i < 5; ++i) {
60                 x2[i] = x1[i];
61                 y2[i] = y1[i];
62         }
63
64         result->termination = -1;
65         result->termination_reason = "Built without libmv support";
66         result->correlation = 0.0;
67
68         return false;
69 }
70
71 void libmv_samplePlanarPatch(const float * /*image*/,
72                              int /*width*/, int /*height*/, int /*channels*/,
73                              const double * /*xs*/, const double * /*ys*/,
74                              int /*num_samples_x*/, int /*num_samples_y*/,
75                              const float * /*mask*/,
76                              float * /*patch*/,
77                              double * /*warped_position_x*/, double * /*warped_position_y*/
78 {
79         /* TODO(sergey): implement */
80 }
81
82 void libmv_samplePlanarPatch(const unsigned char * /*image*/,
83                              int /*width*/, int /*height*/, int /*channels*/,
84                              const double * /*xs*/, const double * /*ys*/,
85                              int /*num_samples_x*/, int /*num_samples_y*/,
86                              const float * /*mask*/,
87                              unsigned char * /*patch*/,
88                              double * /*warped_position_x*/, double * /*warped_position_y*/
89 {
90         /* TODO(sergey): implement */
91 }
92
93 /* ************ Tracks ************ */
94
95 struct libmv_Tracks *libmv_tracksNew(void)
96 {
97         return NULL;
98 }
99
100 void libmv_tracksInsert(struct libmv_Tracks * /*libmv_tracks*/, int /*image*/,
101                         int /*track*/, double /*x*/, double /*y*/, double /*weight*/)
102 {
103 }
104
105 void libmv_tracksDestroy(struct libmv_Tracks * /*libmv_tracks*/)
106 {
107 }
108
109 /* ************ Reconstruction solver ************ */
110
111 struct libmv_Reconstruction *libmv_solveReconstruction(const struct libmv_Tracks * /*libmv_tracks*/,
112                 const libmv_CameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/,
113                 libmv_ReconstructionOptions * /*libmv_reconstruction_options*/,
114                 reconstruct_progress_update_cb /*progress_update_callback*/,
115                 void * /*callback_customdata*/)
116 {
117         return NULL;
118 }
119
120 struct libmv_Reconstruction *libmv_solveModal(const struct libmv_Tracks * /*libmv_tracks*/,
121                 const libmv_CameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/,
122                 const libmv_ReconstructionOptions * /*libmv_reconstruction_options*/,
123                 reconstruct_progress_update_cb /*progress_update_callback*/,
124                 void * /*callback_customdata*/)
125 {
126         return NULL;
127 }
128
129 int libmv_reprojectionPointForTrack(const struct libmv_Reconstruction * /*libmv_reconstruction*/,
130                                      int /*track*/, double /*pos*/[3])
131 {
132         return 0;
133 }
134
135 double libmv_reprojectionErrorForTrack(const struct libmv_Reconstruction * /*libmv_reconstruction*/, int /*track*/)
136 {
137         return 0.0;
138 }
139
140 double libmv_reprojectionErrorForImage(const struct libmv_Reconstruction * /*libmv_reconstruction*/, int /*image*/)
141 {
142         return 0.0;
143 }
144
145 int libmv_reprojectionCameraForImage(const struct libmv_Reconstruction * /*libmv_reconstruction*/, int /*image*/,
146                                       double /*mat*/[4][4])
147 {
148         return 0;
149 }
150
151 double libmv_reprojectionError(const struct libmv_Reconstruction * /*libmv_reconstruction*/)
152 {
153         return 0.0;
154 }
155
156 void libmv_reconstructionDestroy(struct libmv_Reconstruction * /*libmv_reconstruction*/)
157 {
158 }
159
160 /* ************ feature detector ************ */
161
162 struct libmv_Features *libmv_detectFeaturesByte(const unsigned char */*image_buffer*/,
163                                                 int /*width*/, int /*height*/, int /*channels*/,
164                                                 libmv_DetectOptions */*options*/)
165 {
166         return NULL;
167 }
168
169 struct libmv_Features *libmv_detectFeaturesFloat(const float */*image_buffer*/,
170                                                  int /*width*/, int /*height*/, int /*channels*/,
171                                                  libmv_DetectOptions */*options*/)
172 {
173         return NULL;
174 }
175
176 int libmv_countFeatures(const struct libmv_Features * /*libmv_features*/)
177 {
178         return 0;
179 }
180
181 void libmv_getFeature(const struct libmv_Features * /*libmv_features*/, int /*number*/,
182                       double *x, double *y, double *score, double *size)
183 {
184         *x = 0.0;
185         *y = 0.0;
186         *score = 0.0;
187         *size = 0.0;
188 }
189
190 void libmv_featuresDestroy(struct libmv_Features * /*libmv_features*/)
191 {
192 }
193
194 /* ************ camera intrinsics ************ */
195
196 struct libmv_CameraIntrinsics *libmv_reconstructionExtractIntrinsics(
197                 struct libmv_Reconstruction * /*libmv_reconstruction*/)
198 {
199         return NULL;
200 }
201
202 struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNewEmpty(void)
203 {
204         return NULL;
205 }
206
207 struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNew(
208                 const libmv_CameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/)
209 {
210         return NULL;
211 }
212
213 struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsCopy(const libmv_CameraIntrinsics * /*libmvIntrinsics*/)
214 {
215         return NULL;
216 }
217
218 void libmv_cameraIntrinsicsDestroy(struct libmv_CameraIntrinsics * /*libmvIntrinsics*/)
219 {
220 }
221
222 void libmv_cameraIntrinsicsUpdate(const libmv_CameraIntrinsicsOptions * /*libmv_camera_intrinsics_options*/,
223                                   struct libmv_CameraIntrinsics * /*libmv_intrinsics*/)
224 {
225 }
226
227 void libmv_cameraIntrinsicsSetThreads(struct libmv_CameraIntrinsics * /*libmv_intrinsics*/, int /*threads*/)
228 {
229 }
230
231 void libmv_cameraIntrinsicsExtract(const struct libmv_CameraIntrinsics * /*libmv_intrinsics*/, double * focal_length,
232                                    double * principal_x, double *principal_y, double *k1, double *k2, double *k3,
233                                    int *width, int *height)
234 {
235         *focal_length = 1.0;
236         *principal_x = 0.0;
237         *principal_y = 0.0;
238         *k1 = 0.0;
239         *k2 = 0.0;
240         *width = 0.0;
241         *height = 0.0;
242 }
243
244 void libmv_cameraIntrinsicsUndistortByte(const struct libmv_CameraIntrinsics * /*libmv_intrinsics*/,
245                                          unsigned char *src, unsigned char *dst, int width, int height,
246                                          float overscan, int channels)
247 {
248         memcpy(dst, src, channels * width * height * sizeof(unsigned char));
249 }
250
251 void libmv_cameraIntrinsicsUndistortFloat(const struct libmv_CameraIntrinsics * /*libmvIntrinsics*/,
252                                           float *src, float *dst, int width, int height, float overscan, int channels)
253 {
254         memcpy(dst, src, channels * width * height * sizeof(float));
255 }
256
257 void libmv_cameraIntrinsicsDistortByte(const struct libmv_CameraIntrinsics *libmvIntrinsics,
258                                        unsigned char *src, unsigned char *dst, int width, int height,
259                                        float overscan, int channels)
260 {
261         memcpy(dst, src, channels * width * height * sizeof(unsigned char));
262 }
263
264 void libmv_cameraIntrinsicsDistortFloat(const struct libmv_CameraIntrinsics *libmvIntrinsics,
265                                         float *src, float *dst, int width, int height, float overscan, int channels)
266 {
267         memcpy(dst, src, channels * width * height * sizeof(float));
268 }
269
270 /* ************ utils ************ */
271
272 void libmv_cameraIntrinsicsApply(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options,
273                                  double x, double y, double *x1, double *y1)
274 {
275         double focal_length = libmv_camera_intrinsics_options->focal_length;
276         double principal_x = libmv_camera_intrinsics_options->principal_point_x;
277         double principal_y = libmv_camera_intrinsics_options->principal_point_y;
278
279         *x1 = x * focal_length + principal_x;
280         *y1 = y * focal_length + principal_y;
281 }
282
283 void libmv_cameraIntrinsicsInvert(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options,
284                                   double x, double y, double *x1, double *y1)
285 {
286         double focal_length = libmv_camera_intrinsics_options->focal_length;
287         double principal_x = libmv_camera_intrinsics_options->principal_point_x;
288         double principal_y = libmv_camera_intrinsics_options->principal_point_y;
289
290         *x1 = (x - principal_x) / focal_length;
291         *y1 = (y - principal_y) / focal_length;
292 }
293
294 void libmv_homography2DFromCorrespondencesEuc(double (* /* x1 */)[2], double (* /* x2 */)[2], int /* num_points */,
295                                               double H[3][3])
296 {
297         memset(H, 0, sizeof(double[3][3]));
298         H[0][0] = 1.0f;
299         H[1][1] = 1.0f;
300         H[2][2] = 1.0f;
301 }
302
303 #endif  // ifndef WITH_LIBMV