Cleanup and small improvements to libmv
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 13 May 2013 14:39:06 +0000 (14:39 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 13 May 2013 14:39:06 +0000 (14:39 +0000)
- Added const modifiers where it makes sense and
  helps keep code safe.
- Reshuffled argument to match <inputs>,<outputs>
  convention on parameters.
- Pass values to ApplyRadialDistortionCameraIntrinsics
  by a constant reference.
  This will save lots of CPU ticks passing relatively
  heavy jet objects to this function when running
  bundle adjustment.

extern/libmv/ChangeLog
extern/libmv/libmv-capi.cc
extern/libmv/libmv-capi.h
extern/libmv/libmv/simple_pipeline/camera_intrinsics.h
extern/libmv/libmv/simple_pipeline/detect.cc
extern/libmv/libmv/simple_pipeline/detect.h
extern/libmv/libmv/simple_pipeline/reconstruction_scale.cc
source/blender/blenkernel/intern/tracking.c

index 60d8b1f6d6de5fd147fee967f156c6e29d51303e..34f63011ea8502f6455a3451a394bf67413bce25 100644 (file)
@@ -1,3 +1,19 @@
+commit 61ac890908a397860cabc60207500039876532cc
+Author: Sergey Sharybin <sergey.vfx@gmail.com>
+Date:   Mon May 13 04:44:14 2013 +0600
+
+    Pass ApplyRadialDistortionCameraIntrinsics input arguments by reference
+    
+    This shall save some CPU time on calling copy constructor and give
+    some boost of bundle adjuster (where jet could take some time to
+    be passed by value).
+
+commit 4d005ff0771e0e28159be25f8da69d983641384f
+Author: Sergey Sharybin <sergey.vfx@gmail.com>
+Date:   Mon May 13 04:22:05 2013 +0600
+
+    Minor code style cleanup.
+
 commit f003b9e3031db4592c2d91b1ea2538c73b7e767d
 Author: Sergey Sharybin <sergey.vfx@gmail.com>
 Date:   Sun May 12 22:34:54 2013 +0600
@@ -618,26 +634,3 @@ Date:   Fri Mar 1 17:37:35 2013 +0600
     This information is useful, but in cases when you, say,
     working on a bundler it's annoying to scroll all the
     information up.
-
-commit ac252bb1250b3028b9c94736b644e7ab4e7b14b8
-Author: Sergey Sharybin <sergey.vfx@gmail.com>
-Date:   Fri Mar 1 17:36:19 2013 +0600
-
-    Move radial distortion code to own templated function
-    
-    This shall not lead to any functional changes, just
-    avoids radial distortion code duplicated in camera
-    intrinsics and bundling code.
-    
-    For fancier bundle adjustment support of  different
-    distortion models this is not actually enough and
-    would need to make some bigger changes, but this
-    changes makes code a bit easier to maintain already.
-
-commit c253b794612dd529e1d3a9bd7a7c41c32c9a9abb
-Author: Sergey Sharybin <sergey.vfx@gmail.com>
-Date:   Fri Mar 1 17:33:27 2013 +0600
-
-    Use threaded cost function, jacobian and linear solver
-    computation, so bundling is as fast as it could be with
-    current parameter block structure.
index 1be7ac01b9fe91f798720ae9269dc279404975e0..0e25650db796b98787944714012f48cb4cbd02aa 100644 (file)
@@ -139,7 +139,8 @@ static void imageToFloatBuf(const libmv::FloatImage *image, int channels, float
 }
 
 #if defined(DUMP_FAILURE) || defined (DUMP_ALWAYS)
-static void savePNGImage(png_bytep *row_pointers, int width, int height, int depth, int color_type, char *file_name)
+static void savePNGImage(png_bytep *row_pointers, int width, int height, int depth, int color_type,
+                         const char *file_name)
 {
        png_infop info_ptr;
        png_structp png_ptr;
@@ -421,10 +422,13 @@ protected:
        void *callback_customdata_;
 };
 
-static void libmv_solveRefineIntrinsics(libmv::Tracks *tracks, libmv::CameraIntrinsics *intrinsics,
-                       libmv::EuclideanReconstruction *reconstruction, int refine_intrinsics,
-                       reconstruct_progress_update_cb progress_update_callback, void *callback_customdata,
-                       int bundle_constraints = libmv::BUNDLE_NO_CONSTRAINTS)
+static void libmv_solveRefineIntrinsics(const libmv::Tracks &tracks,
+                                        const int refine_intrinsics,
+                                        const int bundle_constraints,
+                                        reconstruct_progress_update_cb progress_update_callback,
+                                        void *callback_customdata,
+                                        libmv::EuclideanReconstruction *reconstruction,
+                                        libmv::CameraIntrinsics *intrinsics)
 {
        /* only a few combinations are supported but trust the caller */
        int bundle_intrinsics = 0;
@@ -444,15 +448,15 @@ static void libmv_solveRefineIntrinsics(libmv::Tracks *tracks, libmv::CameraIntr
 
        progress_update_callback(callback_customdata, 1.0, "Refining solution");
 
-       libmv::EuclideanBundleCommonIntrinsics(*(libmv::Tracks *)tracks,
+       libmv::EuclideanBundleCommonIntrinsics(tracks,
                                               bundle_intrinsics,
                                               bundle_constraints,
                                               reconstruction,
                                               intrinsics);
 }
 
-static void cameraIntrinsicsFromOptions(libmv::CameraIntrinsics *camera_intrinsics,
-                                        libmv_cameraIntrinsicsOptions *camera_intrinsics_options)
+static void cameraIntrinsicsFromOptions(const libmv_cameraIntrinsicsOptions *camera_intrinsics_options,
+                                        libmv::CameraIntrinsics *camera_intrinsics)
 {
        camera_intrinsics->SetFocalLength(camera_intrinsics_options->focal_length,
                                          camera_intrinsics_options->focal_length);
@@ -468,47 +472,47 @@ static void cameraIntrinsicsFromOptions(libmv::CameraIntrinsics *camera_intrinsi
                                        camera_intrinsics_options->image_height);
 }
 
-static libmv::Tracks getNormalizedTracks(libmv::Tracks *tracks, libmv::CameraIntrinsics *camera_intrinsics)
+static libmv::Tracks getNormalizedTracks(const libmv::Tracks &tracks, const libmv::CameraIntrinsics &camera_intrinsics)
 {
-       libmv::vector<libmv::Marker> markers = tracks->AllMarkers();
+       libmv::vector<libmv::Marker> markers = tracks.AllMarkers();
 
        for (int i = 0; i < markers.size(); ++i) {
-               camera_intrinsics->InvertIntrinsics(markers[i].x, markers[i].y,
+               camera_intrinsics.InvertIntrinsics(markers[i].x, markers[i].y,
                        &(markers[i].x), &(markers[i].y));
        }
 
        return libmv::Tracks(markers);
 }
 
-static void finishReconstruction(libmv::Tracks *tracks, libmv::CameraIntrinsics *camera_intrinsics,
+static void finishReconstruction(const libmv::Tracks &tracks, const libmv::CameraIntrinsics &camera_intrinsics,
                                  libmv_Reconstruction *libmv_reconstruction,
                                  reconstruct_progress_update_cb progress_update_callback,
                                  void *callback_customdata)
 {
-       libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
+       libmv::EuclideanReconstruction &reconstruction = libmv_reconstruction->reconstruction;
 
        /* reprojection error calculation */
        progress_update_callback(callback_customdata, 1.0, "Finishing solution");
-       libmv_reconstruction->tracks = *tracks;
-       libmv_reconstruction->error = libmv::EuclideanReprojectionError(*tracks, *reconstruction, *camera_intrinsics);
+       libmv_reconstruction->tracks = tracks;
+       libmv_reconstruction->error = libmv::EuclideanReprojectionError(tracks, reconstruction, camera_intrinsics);
 }
 
-libmv_Reconstruction *libmv_solveReconstruction(libmv_Tracks *libmv_tracks,
-                       libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
-                       libmv_reconstructionOptions *libmv_reconstruction_options,
+libmv_Reconstruction *libmv_solveReconstruction(const libmv_Tracks *libmv_tracks,
+                       const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+                       const libmv_reconstructionOptions *libmv_reconstruction_options,
                        reconstruct_progress_update_cb progress_update_callback,
                        void *callback_customdata)
 {
        libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction();
 
-       libmv::Tracks *tracks = ((libmv::Tracks *) libmv_tracks);
-       libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
-       libmv::CameraIntrinsics *camera_intrinsics = &libmv_reconstruction->intrinsics;
+       libmv::Tracks &tracks = *((libmv::Tracks *) libmv_tracks);
+       libmv::EuclideanReconstruction &reconstruction = libmv_reconstruction->reconstruction;
+       libmv::CameraIntrinsics &camera_intrinsics = libmv_reconstruction->intrinsics;
 
        ReconstructUpdateCallback update_callback =
                ReconstructUpdateCallback(progress_update_callback, callback_customdata);
 
-       cameraIntrinsicsFromOptions(camera_intrinsics, libmv_camera_intrinsics_options);
+       cameraIntrinsicsFromOptions(libmv_camera_intrinsics_options, &camera_intrinsics);
 
        /* Invert the camera intrinsics */
        libmv::Tracks normalized_tracks = getNormalizedTracks(tracks, camera_intrinsics);
@@ -530,20 +534,24 @@ libmv_Reconstruction *libmv_solveReconstruction(libmv_Tracks *libmv_tracks,
 
        update_callback.invoke(0, "Initial reconstruction");
 
-       libmv::EuclideanReconstructTwoFrames(keyframe_markers, reconstruction);
-       libmv::EuclideanBundle(normalized_tracks, reconstruction);
+       libmv::EuclideanReconstructTwoFrames(keyframe_markers, &reconstruction);
+       libmv::EuclideanBundle(normalized_tracks, &reconstruction);
        libmv::EuclideanCompleteReconstruction(reconstruction_options, normalized_tracks,
-                                              reconstruction, &update_callback);
+                                              &reconstruction, &update_callback);
 
        /* refinement */
        if (libmv_reconstruction_options->refine_intrinsics) {
-               libmv_solveRefineIntrinsics((libmv::Tracks *)tracks, camera_intrinsics, reconstruction,
-                       libmv_reconstruction_options->refine_intrinsics,
-                       progress_update_callback, callback_customdata);
+               libmv_solveRefineIntrinsics(tracks,
+                                           libmv_reconstruction_options->refine_intrinsics,
+                                           libmv::BUNDLE_NO_CONSTRAINTS,
+                                           progress_update_callback,
+                                           callback_customdata,
+                                           &reconstruction,
+                                           &camera_intrinsics);
        }
 
        /* set reconstruction scale to unity */
-       libmv::EuclideanScaleToUnity(reconstruction);
+       libmv::EuclideanScaleToUnity(&reconstruction);
 
        /* finish reconstruction */
        finishReconstruction(tracks, camera_intrinsics, libmv_reconstruction,
@@ -552,42 +560,44 @@ libmv_Reconstruction *libmv_solveReconstruction(libmv_Tracks *libmv_tracks,
        return (libmv_Reconstruction *)libmv_reconstruction;
 }
 
-struct libmv_Reconstruction *libmv_solveModal(struct libmv_Tracks *libmv_tracks,
-                       libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
-                       libmv_reconstructionOptions *libmv_reconstruction_options,
+struct libmv_Reconstruction *libmv_solveModal(const libmv_Tracks *libmv_tracks,
+                       const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+                       const libmv_reconstructionOptions *libmv_reconstruction_options,
                        reconstruct_progress_update_cb progress_update_callback,
                        void *callback_customdata)
 {
        libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction();
 
-       libmv::Tracks *tracks = ((libmv::Tracks *) libmv_tracks);
-       libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
-       libmv::CameraIntrinsics *camera_intrinsics = &libmv_reconstruction->intrinsics;
+       libmv::Tracks &tracks = *((libmv::Tracks *) libmv_tracks);
+       libmv::EuclideanReconstruction &reconstruction = libmv_reconstruction->reconstruction;
+       libmv::CameraIntrinsics &camera_intrinsics = libmv_reconstruction->intrinsics;
 
        ReconstructUpdateCallback update_callback =
                ReconstructUpdateCallback(progress_update_callback, callback_customdata);
 
-       cameraIntrinsicsFromOptions(camera_intrinsics, libmv_camera_intrinsics_options);
+       cameraIntrinsicsFromOptions(libmv_camera_intrinsics_options, &camera_intrinsics);
 
        /* Invert the camera intrinsics. */
        libmv::Tracks normalized_tracks = getNormalizedTracks(tracks, camera_intrinsics);
 
        /* Actual reconstruction. */
-       libmv::ModalSolver(normalized_tracks, reconstruction, &update_callback);
+       libmv::ModalSolver(normalized_tracks, &reconstruction, &update_callback);
 
        libmv::CameraIntrinsics empty_intrinsics;
        libmv::EuclideanBundleCommonIntrinsics(normalized_tracks,
                                               libmv::BUNDLE_NO_INTRINSICS,
                                               libmv::BUNDLE_NO_TRANSLATION,
-                                              reconstruction,
+                                              &reconstruction,
                                               &empty_intrinsics);
 
        /* Refinement. */
        if (libmv_reconstruction_options->refine_intrinsics) {
-               libmv_solveRefineIntrinsics((libmv::Tracks *)tracks, camera_intrinsics, reconstruction,
-                       libmv_reconstruction_options->refine_intrinsics,
-                       progress_update_callback, callback_customdata,
-                       libmv::BUNDLE_NO_TRANSLATION);
+               libmv_solveRefineIntrinsics(tracks,
+                                           libmv_reconstruction_options->refine_intrinsics,
+                                           libmv::BUNDLE_NO_TRANSLATION,
+                                           progress_update_callback, callback_customdata,
+                                           &reconstruction,
+                                           &camera_intrinsics);
        }
 
        /* Finish reconstruction. */
@@ -597,10 +607,10 @@ struct libmv_Reconstruction *libmv_solveModal(struct libmv_Tracks *libmv_tracks,
        return (libmv_Reconstruction *)libmv_reconstruction;
 }
 
-int libmv_reporojectionPointForTrack(libmv_Reconstruction *libmv_reconstruction, int track, double pos[3])
+int libmv_reporojectionPointForTrack(const libmv_Reconstruction *libmv_reconstruction, int track, double pos[3])
 {
-       libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
-       libmv::EuclideanPoint *point = reconstruction->PointForTrack(track);
+       const libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
+       const libmv::EuclideanPoint *point = reconstruction->PointForTrack(track);
 
        if(point) {
                pos[0] = point->X[0];
@@ -613,8 +623,10 @@ int libmv_reporojectionPointForTrack(libmv_Reconstruction *libmv_reconstruction,
        return 0;
 }
 
-static libmv::Marker ProjectMarker(const libmv::EuclideanPoint &point, const libmv::EuclideanCamera &camera,
-                       const libmv::CameraIntrinsics &intrinsics) {
+static libmv::Marker ProjectMarker(const libmv::EuclideanPoint &point,
+                                   const libmv::EuclideanCamera &camera,
+                                   const libmv::CameraIntrinsics &intrinsics)
+{
        libmv::Vec3 projected = camera.R * point.X + camera.t;
        projected /= projected(2);
 
@@ -627,10 +639,10 @@ static libmv::Marker ProjectMarker(const libmv::EuclideanPoint &point, const lib
        return reprojected_marker;
 }
 
-double libmv_reporojectionErrorForTrack(libmv_Reconstruction *libmv_reconstruction, int track)
+double libmv_reporojectionErrorForTrack(const libmv_Reconstruction *libmv_reconstruction, int track)
 {
-       libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
-       libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics;
+       const libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
+       const libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics;
        libmv::vector<libmv::Marker> markers = libmv_reconstruction->tracks.MarkersForTrack(track);
 
        int num_reprojected = 0;
@@ -656,10 +668,10 @@ double libmv_reporojectionErrorForTrack(libmv_Reconstruction *libmv_reconstructi
        return total_error / num_reprojected;
 }
 
-double libmv_reporojectionErrorForImage(libmv_Reconstruction *libmv_reconstruction, int image)
+double libmv_reporojectionErrorForImage(const libmv_Reconstruction *libmv_reconstruction, int image)
 {
-       libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
-       libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics;
+       const libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
+       const libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics;
        libmv::vector<libmv::Marker> markers = libmv_reconstruction->tracks.MarkersInImage(image);
        const libmv::EuclideanCamera *camera = reconstruction->CameraForImage(image);
        int num_reprojected = 0;
@@ -687,10 +699,11 @@ double libmv_reporojectionErrorForImage(libmv_Reconstruction *libmv_reconstructi
        return total_error / num_reprojected;
 }
 
-int libmv_reporojectionCameraForImage(libmv_Reconstruction *libmv_reconstruction, int image, double mat[4][4])
+int libmv_reporojectionCameraForImage(const libmv_Reconstruction *libmv_reconstruction,
+                                      int image, double mat[4][4])
 {
-       libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
-       libmv::EuclideanCamera *camera = reconstruction->CameraForImage(image);
+       const libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
+       const libmv::EuclideanCamera *camera = reconstruction->CameraForImage(image);
 
        if(camera) {
                for (int j = 0; j < 3; ++j) {
@@ -720,7 +733,7 @@ int libmv_reporojectionCameraForImage(libmv_Reconstruction *libmv_reconstruction
        return 0;
 }
 
-double libmv_reprojectionError(libmv_Reconstruction *libmv_reconstruction)
+double libmv_reprojectionError(const libmv_Reconstruction *libmv_reconstruction)
 {
        return libmv_reconstruction->error;
 }
@@ -732,8 +745,9 @@ void libmv_destroyReconstruction(libmv_Reconstruction *libmv_reconstruction)
 
 /* ************ feature detector ************ */
 
-struct libmv_Features *libmv_detectFeaturesFAST(unsigned char *data, int width, int height, int stride,
-                       int margin, int min_trackness, int min_distance)
+struct libmv_Features *libmv_detectFeaturesFAST(const unsigned char *data,
+                                                int width, int height, int stride,
+                                                int margin, int min_trackness, int min_distance)
 {
        libmv::Feature *features = NULL;
        std::vector<libmv::Feature> v;
@@ -765,8 +779,9 @@ struct libmv_Features *libmv_detectFeaturesFAST(unsigned char *data, int width,
        return (libmv_Features *)libmv_features;
 }
 
-struct libmv_Features *libmv_detectFeaturesMORAVEC(unsigned char *data, int width, int height, int stride,
-                       int margin, int count, int min_distance)
+struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data,
+                                                   int width, int height, int stride,
+                                                   int margin, int count, int min_distance)
 {
        libmv::Feature *features = NULL;
        libmv_Features *libmv_features = new libmv_Features;
@@ -789,12 +804,12 @@ struct libmv_Features *libmv_detectFeaturesMORAVEC(unsigned char *data, int widt
        return libmv_features;
 }
 
-int libmv_countFeatures(struct libmv_Features *libmv_features)
+int libmv_countFeatures(const libmv_Features *libmv_features)
 {
        return libmv_features->count;
 }
 
-void libmv_getFeature(struct libmv_Features *libmv_features, int number, double *x, double *y, double *score, double *size)
+void libmv_getFeature(const libmv_Features *libmv_features, int number, double *x, double *y, double *score, double *size)
 {
        libmv::Feature feature= libmv_features->features[number];
 
@@ -804,7 +819,7 @@ void libmv_getFeature(struct libmv_Features *libmv_features, int number, double
        *size = feature.size;
 }
 
-void libmv_destroyFeatures(struct libmv_Features *libmv_features)
+void libmv_destroyFeatures(libmv_Features *libmv_features)
 {
        if(libmv_features->features)
                delete [] libmv_features->features;
@@ -814,7 +829,8 @@ void libmv_destroyFeatures(struct libmv_Features *libmv_features)
 
 /* ************ camera intrinsics ************ */
 
-struct libmv_CameraIntrinsics *libmv_ReconstructionExtractIntrinsics(struct libmv_Reconstruction *libmv_Reconstruction) {
+struct libmv_CameraIntrinsics *libmv_ReconstructionExtractIntrinsics(libmv_Reconstruction *libmv_Reconstruction)
+{
        return (struct libmv_CameraIntrinsics *)&libmv_Reconstruction->intrinsics;
 }
 
@@ -825,16 +841,16 @@ struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNewEmpty(void)
        return (struct libmv_CameraIntrinsics *) camera_intrinsics;
 }
 
-struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNew(libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options)
+struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNew(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options)
 {
        libmv::CameraIntrinsics *camera_intrinsics = new libmv::CameraIntrinsics();
 
-       cameraIntrinsicsFromOptions(camera_intrinsics, libmv_camera_intrinsics_options);
+       cameraIntrinsicsFromOptions(libmv_camera_intrinsics_options, camera_intrinsics);
 
        return (struct libmv_CameraIntrinsics *) camera_intrinsics;
 }
 
-struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsCopy(struct libmv_CameraIntrinsics *libmvIntrinsics)
+struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsCopy(const libmv_CameraIntrinsics *libmvIntrinsics)
 {
        libmv::CameraIntrinsics *orig_intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
        libmv::CameraIntrinsics *new_intrinsics= new libmv::CameraIntrinsics(*orig_intrinsics);
@@ -849,8 +865,8 @@ void libmv_CameraIntrinsicsDestroy(struct libmv_CameraIntrinsics *libmvIntrinsic
        delete intrinsics;
 }
 
-void libmv_CameraIntrinsicsUpdate(struct libmv_CameraIntrinsics *libmv_intrinsics,
-                                  libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options)
+void libmv_CameraIntrinsicsUpdate(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+                                  libmv_CameraIntrinsics *libmv_intrinsics)
 {
        libmv::CameraIntrinsics *camera_intrinsics = (libmv::CameraIntrinsics *) libmv_intrinsics;
 
@@ -888,14 +904,14 @@ void libmv_CameraIntrinsicsUpdate(struct libmv_CameraIntrinsics *libmv_intrinsic
        }
 }
 
-void libmv_CameraIntrinsicsSetThreads(struct libmv_CameraIntrinsics *libmv_intrinsics, int threads)
+void libmv_CameraIntrinsicsSetThreads(libmv_CameraIntrinsics *libmv_intrinsics, int threads)
 {
        libmv::CameraIntrinsics *camera_intrinsics = (libmv::CameraIntrinsics *) libmv_intrinsics;
 
        camera_intrinsics->SetThreads(threads);
 }
 
-void libmv_CameraIntrinsicsExtract(struct libmv_CameraIntrinsics *libmv_intrinsics, double *focal_length,
+void libmv_CameraIntrinsicsExtract(const libmv_CameraIntrinsics *libmv_intrinsics, double *focal_length,
                        double *principal_x, double *principal_y, double *k1, double *k2, double *k3, int *width, int *height)
 {
        libmv::CameraIntrinsics *camera_intrinsics = (libmv::CameraIntrinsics *) libmv_intrinsics;
@@ -907,7 +923,7 @@ void libmv_CameraIntrinsicsExtract(struct libmv_CameraIntrinsics *libmv_intrinsi
        *k2 = camera_intrinsics->k2();
 }
 
-void libmv_CameraIntrinsicsUndistortByte(struct libmv_CameraIntrinsics *libmv_intrinsics,
+void libmv_CameraIntrinsicsUndistortByte(const libmv_CameraIntrinsics *libmv_intrinsics,
                        unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics *camera_intrinsics = (libmv::CameraIntrinsics *) libmv_intrinsics;
@@ -915,7 +931,7 @@ void libmv_CameraIntrinsicsUndistortByte(struct libmv_CameraIntrinsics *libmv_in
        camera_intrinsics->Undistort(src, dst, width, height, overscan, channels);
 }
 
-void libmv_CameraIntrinsicsUndistortFloat(struct libmv_CameraIntrinsics *libmvIntrinsics,
+void libmv_CameraIntrinsicsUndistortFloat(const libmv_CameraIntrinsics *libmvIntrinsics,
                        float *src, float *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
@@ -923,14 +939,14 @@ void libmv_CameraIntrinsicsUndistortFloat(struct libmv_CameraIntrinsics *libmvIn
        intrinsics->Undistort(src, dst, width, height, overscan, channels);
 }
 
-void libmv_CameraIntrinsicsDistortByte(struct libmv_CameraIntrinsics *libmvIntrinsics,
+void libmv_CameraIntrinsicsDistortByte(const libmv_CameraIntrinsics *libmvIntrinsics,
                        unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
        intrinsics->Distort(src, dst, width, height, overscan, channels);
 }
 
-void libmv_CameraIntrinsicsDistortFloat(struct libmv_CameraIntrinsics *libmvIntrinsics,
+void libmv_CameraIntrinsicsDistortFloat(const libmv_CameraIntrinsics *libmvIntrinsics,
                        float *src, float *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
@@ -940,12 +956,12 @@ void libmv_CameraIntrinsicsDistortFloat(struct libmv_CameraIntrinsics *libmvIntr
 
 /* ************ utils ************ */
 
-void libmv_ApplyCameraIntrinsics(libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+void libmv_ApplyCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
                                  double x, double y, double *x1, double *y1)
 {
        libmv::CameraIntrinsics camera_intrinsics;
 
-       cameraIntrinsicsFromOptions(&camera_intrinsics, libmv_camera_intrinsics_options);
+       cameraIntrinsicsFromOptions(libmv_camera_intrinsics_options, &camera_intrinsics);
 
        if (libmv_camera_intrinsics_options->focal_length) {
                /* do a lens undistortion if focal length is non-zero only */
@@ -954,12 +970,12 @@ void libmv_ApplyCameraIntrinsics(libmv_cameraIntrinsicsOptions *libmv_camera_int
        }
 }
 
-void libmv_InvertCameraIntrinsics(libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+void libmv_InvertCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
                                   double x, double y, double *x1, double *y1)
 {
        libmv::CameraIntrinsics camera_intrinsics;
 
-       cameraIntrinsicsFromOptions(&camera_intrinsics, libmv_camera_intrinsics_options);
+       cameraIntrinsicsFromOptions(libmv_camera_intrinsics_options, &camera_intrinsics);
 
        if (libmv_camera_intrinsics_options->focal_length) {
                /* do a lens distortion if focal length is non-zero only */
index bf09fbd50052da66e15f154e9a6ec83773ee8de7..5fab666e5a88b31561ab6b9bd3e8b0a1512c49d3 100644 (file)
@@ -101,30 +101,30 @@ typedef struct libmv_reconstructionOptions {
 
 typedef void (*reconstruct_progress_update_cb) (void *customdata, double progress, const char *message);
 
-struct libmv_Reconstruction *libmv_solveReconstruction(struct libmv_Tracks *libmv_tracks,
-                       libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
-                       libmv_reconstructionOptions *libmv_reconstruction_options,
+struct libmv_Reconstruction *libmv_solveReconstruction(const struct libmv_Tracks *libmv_tracks,
+                       const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+                       const libmv_reconstructionOptions *libmv_reconstruction_options,
                        reconstruct_progress_update_cb progress_update_callback,
                        void *callback_customdata);
-struct libmv_Reconstruction *libmv_solveModal(struct libmv_Tracks *libmv_tracks,
-                       libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
-                       libmv_reconstructionOptions *libmv_reconstruction_options,
+struct libmv_Reconstruction *libmv_solveModal(const struct libmv_Tracks *libmv_tracks,
+                       const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+                       const libmv_reconstructionOptions *libmv_reconstruction_options,
                        reconstruct_progress_update_cb progress_update_callback,
                        void *callback_customdata);
-int libmv_reporojectionPointForTrack(struct libmv_Reconstruction *libmv_reconstruction, int track, double pos[3]);
-double libmv_reporojectionErrorForTrack(struct libmv_Reconstruction *libmv_reconstruction, int track);
-double libmv_reporojectionErrorForImage(struct libmv_Reconstruction *libmv_reconstruction, int image);
-int libmv_reporojectionCameraForImage(struct libmv_Reconstruction *libmv_reconstruction, int image, double mat[4][4]);
-double libmv_reprojectionError(struct libmv_Reconstruction *libmv_reconstruction);
+int libmv_reporojectionPointForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track, double pos[3]);
+double libmv_reporojectionErrorForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track);
+double libmv_reporojectionErrorForImage(const struct libmv_Reconstruction *libmv_reconstruction, int image);
+int libmv_reporojectionCameraForImage(const struct libmv_Reconstruction *libmv_reconstruction, int image, double mat[4][4]);
+double libmv_reprojectionError(const struct libmv_Reconstruction *libmv_reconstruction);
 void libmv_destroyReconstruction(struct libmv_Reconstruction *libmv_reconstruction);
 
 /* feature detector */
-struct libmv_Features *libmv_detectFeaturesFAST(unsigned char *data, int width, int height, int stride,
+struct libmv_Features *libmv_detectFeaturesFAST(const unsigned char *data, int width, int height, int stride,
                        int margin, int min_trackness, int min_distance);
-struct libmv_Features *libmv_detectFeaturesMORAVEC(unsigned char *data, int width, int height, int stride,
+struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data, int width, int height, int stride,
                        int margin, int count, int min_distance);
-int libmv_countFeatures(struct libmv_Features *libmv_features);
-void libmv_getFeature(struct libmv_Features *libmv_features, int number, double *x, double *y, double *score, double *size);
+int libmv_countFeatures(const struct libmv_Features *libmv_features);
+void libmv_getFeature(const struct libmv_Features *libmv_features, int number, double *x, double *y, double *score, double *size);
 void libmv_destroyFeatures(struct libmv_Features *libmv_features);
 
 /* camera intrinsics */
@@ -132,36 +132,36 @@ struct libmv_CameraIntrinsics *libmv_ReconstructionExtractIntrinsics(struct libm
 
 struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNewEmpty(void);
 
-struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNew(libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options);
+struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNew(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options);
 
-struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsCopy(struct libmv_CameraIntrinsics *libmv_intrinsics);
+struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsCopy(const struct libmv_CameraIntrinsics *libmv_intrinsics);
 
 void libmv_CameraIntrinsicsDestroy(struct libmv_CameraIntrinsics *libmv_intrinsics);
 
-void libmv_CameraIntrinsicsUpdate(struct libmv_CameraIntrinsics *libmv_intrinsics,
-                                  libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options);
+void libmv_CameraIntrinsicsUpdate(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+                                  struct libmv_CameraIntrinsics *libmv_intrinsics);
 
 void libmv_CameraIntrinsicsSetThreads(struct libmv_CameraIntrinsics *libmv_intrinsics, int threads);
 
-void libmv_CameraIntrinsicsExtract(struct libmv_CameraIntrinsics *libmv_intrinsics, double *focal_length,
+void libmv_CameraIntrinsicsExtract(const struct libmv_CameraIntrinsics *libmv_intrinsics, double *focal_length,
                        double *principal_x, double *principal_y, double *k1, double *k2, double *k3, int *width, int *height);
 
-void libmv_CameraIntrinsicsUndistortByte(struct libmv_CameraIntrinsics *libmv_intrinsics,
+void libmv_CameraIntrinsicsUndistortByte(const struct libmv_CameraIntrinsics *libmv_intrinsics,
                        unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels);
 
-void libmv_CameraIntrinsicsUndistortFloat(struct libmv_CameraIntrinsics *libmv_intrinsics,
+void libmv_CameraIntrinsicsUndistortFloat(const struct libmv_CameraIntrinsics *libmv_intrinsics,
                        float *src, float *dst, int width, int height, float overscan, int channels);
 
-void libmv_CameraIntrinsicsDistortByte(struct libmv_CameraIntrinsics *libmv_intrinsics,
+void libmv_CameraIntrinsicsDistortByte(const struct libmv_CameraIntrinsics *libmv_intrinsics,
                        unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels);
 
-void libmv_CameraIntrinsicsDistortFloat(struct libmv_CameraIntrinsics *libmv_intrinsics,
+void libmv_CameraIntrinsicsDistortFloat(const struct libmv_CameraIntrinsics *libmv_intrinsics,
                        float *src, float *dst, int width, int height, float overscan, int channels);
 
 /* utils */
-void libmv_ApplyCameraIntrinsics(libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+void libmv_ApplyCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
                        double x, double y, double *x1, double *y1);
-void libmv_InvertCameraIntrinsics(libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
+void libmv_InvertCameraIntrinsics(const libmv_cameraIntrinsicsOptions *libmv_camera_intrinsics_options,
                        double x, double y, double *x1, double *y1);
 
 #ifdef __cplusplus
index 29d26c7f9ab902f341c9435c10090de06416fcef..5a348899a114af3ce42945bef445ff24c78a3764 100644 (file)
@@ -172,14 +172,17 @@ std::ostream& operator <<(std::ostream &os,
 // camera coordinates (i.e. the principal point is at (0, 0)) to get image
 // coordinates in pixels. Templated for use with autodifferentiation.
 template <typename T>
-inline void ApplyRadialDistortionCameraIntrinsics(T focal_length_x,
-                                                  T focal_length_y,
-                                                  T principal_point_x,
-                                                  T principal_point_y,
-                                                  T k1, T k2, T k3,
-                                                  T p1, T p2,
-                                                  T normalized_x,
-                                                  T normalized_y,
+inline void ApplyRadialDistortionCameraIntrinsics(const T &focal_length_x,
+                                                  const T &focal_length_y,
+                                                  const T &principal_point_x,
+                                                  const T &principal_point_y,
+                                                  const T &k1,
+                                                  const T &k2,
+                                                  const T &k3,
+                                                  const T &p1,
+                                                  const T &p2,
+                                                  const T &normalized_x,
+                                                  const T &normalized_y,
                                                   T *image_x,
                                                   T *image_y) {
   T x = normalized_x;
index 8451e47d3746c47ebfe8391944241f6db5d05543..627fa5419747f3b99a0db9c2b349f694e69c9d0e 100644 (file)
@@ -132,7 +132,7 @@ static uint SAD(const ubyte* imageA, const ubyte* imageB,
 }
 #endif
 
-void DetectMORAVEC(ubyte* image,
+void DetectMORAVEC(const ubyte* image,
                    int stride, int width, int height,
                    Feature* detected, int* count,
                    int distance,
@@ -144,7 +144,7 @@ void DetectMORAVEC(ubyte* image,
   const int r = 1;  // radius for self similarity comparison
   for (int y = distance; y < height-distance; y++) {
     for (int x = distance; x < width-distance; x++) {
-      ubyte* s = &image[y*stride+x];
+      const ubyte* s = &image[y*stride+x];
       int score =  // low self-similarity with overlapping patterns
                    // OPTI: load pattern once
           SAD(s, s-r*stride-r, stride, stride)+SAD(s, s-r*stride, stride, stride)+SAD(s, s-r*stride+r, stride, stride)+
index 6d0f55a082f349b4d83dd23439d2ee437d536370..f5bcd07afd749294a7b85dbf35dfb753e2827ecf 100644 (file)
@@ -88,7 +88,7 @@ std::vector<Feature> DetectFAST(const unsigned char* data, int width, int height
     \note \a You can crop the image (to avoid detecting markers near the borders) without copying:
              image += marginY*stride+marginX, width -= 2*marginX, height -= 2*marginY;
 */
-void DetectMORAVEC(ubyte* image, int stride, int width, int height,
+void DetectMORAVEC(const ubyte* image, int stride, int width, int height,
                    Feature* detected, int* count, int distance /*=32*/,
                    ubyte* pattern /*=0*/);
 
index c7295b9c9f3f79b788fce3d559c1e6c140896e12..40ac23be7a2e4e51ac626510321d27460d1749df 100644 (file)
@@ -38,8 +38,9 @@ void EuclideanScaleToUnity(EuclideanReconstruction *reconstruction) {
   double max_distance = 0.0;
   for (int i = 0; i < all_cameras.size(); ++i) {
     double distance = (all_cameras[i].t - cameras_mass_center).squaredNorm();
-    if (distance > max_distance)
+    if (distance > max_distance) {
       max_distance = distance;
+    }
   }
 
   if (max_distance == 0.0) {
index 74507b6d5431b2ea14562cd6063e4b3754d9ba9f..fd8ae34192a78223135be1cd2b5f2ca869f5faca 100644 (file)
@@ -1572,7 +1572,7 @@ void BKE_tracking_distortion_update(MovieDistortion *distortion, MovieTracking *
        cameraIntrinscisOptionsFromTracking(&camera_intrinsics_options, tracking,
                                            calibration_width, calibration_height);
 
-       libmv_CameraIntrinsicsUpdate(distortion->intrinsics, &camera_intrinsics_options);
+       libmv_CameraIntrinsicsUpdate(&camera_intrinsics_options, distortion->intrinsics);
 }
 
 void BKE_tracking_distortion_set_threads(MovieDistortion *distortion, int threads)