Camera tracking: progress report clean-up
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 27 Nov 2011 10:35:00 +0000 (10:35 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 27 Nov 2011 10:35:00 +0000 (10:35 +0000)
Send object which implements ProgressUpdateCallback to complete reconstruction
function rather than sending C-like procedure variable and context.

extern/libmv/CMakeLists.txt
extern/libmv/libmv-capi.cpp
extern/libmv/libmv/simple_pipeline/callbacks.cc [new file with mode: 0644]
extern/libmv/libmv/simple_pipeline/callbacks.h [new file with mode: 0644]
extern/libmv/libmv/simple_pipeline/pipeline.cc
extern/libmv/libmv/simple_pipeline/pipeline.h
source/blender/blenkernel/intern/tracking.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/makesdna/DNA_tracking_types.h

index cd1f572197ce988c33e3b86d9d1f9eb440e4cf50..6f0d5f3d126cd67b02922cc3beb39fc02a571918 100644 (file)
@@ -39,6 +39,7 @@ set(SRC
        libmv-capi.cpp
        libmv/numeric/numeric.cc
        libmv/numeric/poly.cc
+       libmv/simple_pipeline/callbacks.cc
        libmv/simple_pipeline/reconstruction.cc
        libmv/simple_pipeline/resect.cc
        libmv/simple_pipeline/intersect.cc
@@ -83,6 +84,7 @@ set(SRC
        libmv/numeric/poly.h
        libmv/numeric/function_derivative.h
        libmv/numeric/numeric.h
+       libmv/simple_pipeline/callbacks.h
        libmv/simple_pipeline/resect.h
        libmv/simple_pipeline/reconstruction.h
        libmv/simple_pipeline/camera_intrinsics.h
index 2472b08da190fae3870efbbab1460b5e4f939527..f08aea9fbd1359c651359def49a920584e925963 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "libmv/tracking/sad.h"
 
+#include "libmv/simple_pipeline/callbacks.h"
 #include "libmv/simple_pipeline/tracks.h"
 #include "libmv/simple_pipeline/initialize_reconstruction.h"
 #include "libmv/simple_pipeline/bundle.h"
@@ -341,6 +342,26 @@ void libmv_tracksDestroy(libmv_Tracks *libmv_tracks)
 
 /* ************ Reconstruction solver ************ */
 
+class ReconstructUpdateCallback : public libmv::ProgressUpdateCallback {
+public:
+       ReconstructUpdateCallback(reconstruct_progress_update_cb progress_update_callback,
+                       void *callback_customdata)
+       {
+               progress_update_callback_ = progress_update_callback;
+               callback_customdata_ = callback_customdata;
+       }
+
+       void invoke(double progress, const char *message)
+       {
+               if(progress_update_callback_) {
+                       progress_update_callback_(callback_customdata_, progress, message);
+               }
+       }
+protected:
+       reconstruct_progress_update_cb progress_update_callback_;
+       void *callback_customdata_;
+};
+
 int libmv_refineParametersAreValid(int parameters) {
        return (parameters == (LIBMV_REFINE_FOCAL_LENGTH))         ||
               (parameters == (LIBMV_REFINE_FOCAL_LENGTH           |
@@ -367,6 +388,9 @@ libmv_Reconstruction *libmv_solveReconstruction(libmv_Tracks *tracks, int keyfra
        libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
        libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics;
 
+       ReconstructUpdateCallback update_callback =
+               ReconstructUpdateCallback(progress_update_callback, callback_customdata);
+
        intrinsics->SetFocalLength(focal_length, focal_length);
        intrinsics->SetPrincipalPoint(principal_x, principal_y);
        intrinsics->SetRadialDistortion(k1, k2, k3);
@@ -385,13 +409,11 @@ libmv_Reconstruction *libmv_solveReconstruction(libmv_Tracks *tracks, int keyfra
                normalized_tracks.MarkersForTracksInBothImages(keyframe1, keyframe2);
        LG << "number of markers for init: " << keyframe_markers.size();
 
-       if(progress_update_callback)
-               progress_update_callback(callback_customdata, 0, "Initial reconstruction");
+       update_callback.invoke(0, "Initial reconstruction");
 
        libmv::EuclideanReconstructTwoFrames(keyframe_markers, reconstruction);
        libmv::EuclideanBundle(normalized_tracks, reconstruction);
-
-       libmv::EuclideanCompleteReconstruction(normalized_tracks, reconstruction, progress_update_callback, callback_customdata);
+       libmv::EuclideanCompleteReconstruction(normalized_tracks, reconstruction, &update_callback);
 
        if (refine_intrinsics) {
                /* only a few combinations are supported but trust the caller */
@@ -410,7 +432,8 @@ libmv_Reconstruction *libmv_solveReconstruction(libmv_Tracks *tracks, int keyfra
                }
 
                progress_update_callback(callback_customdata, 1.0, "Refining solution");
-               libmv::EuclideanBundleCommonIntrinsics(*(libmv::Tracks *)tracks, libmv_refine_flags, reconstruction, intrinsics);
+               libmv::EuclideanBundleCommonIntrinsics(*(libmv::Tracks *)tracks, libmv_refine_flags,
+                       reconstruction, intrinsics);
        }
 
        progress_update_callback(callback_customdata, 1.0, "Finishing solution");
diff --git a/extern/libmv/libmv/simple_pipeline/callbacks.cc b/extern/libmv/libmv/simple_pipeline/callbacks.cc
new file mode 100644 (file)
index 0000000..7e4bca6
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright (c) 2011 libmv authors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+
+#include "libmv/simple_pipeline/callbacks.h"
+
+namespace libmv {
+
+void ProgressUpdateCallback::invoke(double progress, const char* message)
+{
+}
+
+} // namespace libmv
diff --git a/extern/libmv/libmv/simple_pipeline/callbacks.h b/extern/libmv/libmv/simple_pipeline/callbacks.h
new file mode 100644 (file)
index 0000000..675f73c
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (c) 2011 libmv authors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+
+#ifndef LIBMV_SIMPLE_PIPELINE_CALLBACKS_H_
+#define LIBMV_SIMPLE_PIPELINE_CALLBACKS_H_
+
+namespace libmv {
+
+class ProgressUpdateCallback {
+ public:
+  virtual void invoke(double progress, const char *message);
+};
+
+}  // namespace libmv
+
+#endif  // LIBMV_SIMPLE_PIPELINE_MARKERS_H_
index 654127ac51d2ba96e7eae76ff2cf8bc37cdbe017..382365e579f379b9bb46bad646ae1ce63c38a5c8 100644 (file)
@@ -118,18 +118,19 @@ struct ProjectivePipelineRoutines {
 
 }  // namespace
 
-static void CompleteReconstructionLogProress(progress_update_callback update_callback,
-    void *update_customdata,
+static void CompleteReconstructionLogProress(ProgressUpdateCallback *update_callback,
     double progress,
-    const char *step)
+    const char *step = NULL)
 {
   if(update_callback) {
     char message[256];
+
     if(step)
       snprintf(message, sizeof(message), "Completing solution %d%% | %s", (int)(progress*100), step);
     else
       snprintf(message, sizeof(message), "Completing solution %d%%", (int)(progress*100));
-    update_callback(update_customdata, progress, message);
+
+    update_callback->invoke(progress, message);
   }
 }
 
@@ -137,8 +138,7 @@ template<typename PipelineRoutines>
 void InternalCompleteReconstruction(
     const Tracks &tracks,
     typename PipelineRoutines::Reconstruction *reconstruction,
-    progress_update_callback update_callback,
-    void *update_customdata) {
+    ProgressUpdateCallback *update_callback = NULL) {
   int max_track = tracks.MaxTrack();
   int max_image = tracks.MaxImage();
   int num_resects = -1;
@@ -167,16 +167,15 @@ void InternalCompleteReconstruction(
       LG << "Got " << reconstructed_markers.size()
          << " reconstructed markers for track " << track;
       if (reconstructed_markers.size() >= 2) {
-        CompleteReconstructionLogProress(update_callback, update_customdata,
-                                         (double)tot_resects/(max_image),
-                                         NULL);
+        CompleteReconstructionLogProress(update_callback,
+                                         (double)tot_resects/(max_image));
         PipelineRoutines::Intersect(reconstructed_markers, reconstruction);
         num_intersects++;
         LG << "Ran Intersect() for track " << track;
       }
     }
     if (num_intersects) {
-      CompleteReconstructionLogProress(update_callback, update_customdata,
+      CompleteReconstructionLogProress(update_callback,
                                        (double)tot_resects/(max_image),
                                        "Bundling...");
       PipelineRoutines::Bundle(tracks, reconstruction);
@@ -203,9 +202,8 @@ void InternalCompleteReconstruction(
       LG << "Got " << reconstructed_markers.size()
          << " reconstructed markers for image " << image;
       if (reconstructed_markers.size() >= 5) {
-        CompleteReconstructionLogProress(update_callback, update_customdata,
-                                         (double)tot_resects/(max_image),
-                                         NULL);
+        CompleteReconstructionLogProress(update_callback,
+                                         (double)tot_resects/(max_image));
         if (PipelineRoutines::Resect(reconstructed_markers, reconstruction, false)) {
           num_resects++;
           tot_resects++;
@@ -216,7 +214,7 @@ void InternalCompleteReconstruction(
       }
     }
     if (num_resects) {
-      CompleteReconstructionLogProress(update_callback, update_customdata,
+      CompleteReconstructionLogProress(update_callback,
                                        (double)tot_resects/(max_image),
                                        "Bundling...");
       PipelineRoutines::Bundle(tracks, reconstruction);
@@ -240,9 +238,8 @@ void InternalCompleteReconstruction(
       }
     }
     if (reconstructed_markers.size() >= 5) {
-      CompleteReconstructionLogProress(update_callback, update_customdata,
-                                       (double)tot_resects/(max_image),
-                                       NULL);
+      CompleteReconstructionLogProress(update_callback,
+                                       (double)tot_resects/(max_image));
       if (PipelineRoutines::Resect(reconstructed_markers, reconstruction, true)) {
         num_resects++;
         LG << "Ran Resect() for image " << image;
@@ -252,7 +249,7 @@ void InternalCompleteReconstruction(
     }
   }
   if (num_resects) {
-    CompleteReconstructionLogProress(update_callback, update_customdata,
+    CompleteReconstructionLogProress(update_callback,
                                      (double)tot_resects/(max_image),
                                      "Bundling...");
     PipelineRoutines::Bundle(tracks, reconstruction);
@@ -329,19 +326,16 @@ double ProjectiveReprojectionError(
 
 void EuclideanCompleteReconstruction(const Tracks &tracks,
                                      EuclideanReconstruction *reconstruction,
-                                     progress_update_callback update_callback,
-                                     void *update_customdata) {
+                                     ProgressUpdateCallback *update_callback) {
   InternalCompleteReconstruction<EuclideanPipelineRoutines>(tracks,
                                                             reconstruction,
-                                                            update_callback,
-                                                            update_customdata);
+                                                            update_callback);
 }
 
 void ProjectiveCompleteReconstruction(const Tracks &tracks,
                                       ProjectiveReconstruction *reconstruction) {
   InternalCompleteReconstruction<ProjectivePipelineRoutines>(tracks,
-                                                             reconstruction,
-                                                             NULL, NULL);
+                                                             reconstruction);
 }
 
 void InvertIntrinsicsForTracks(const Tracks &raw_tracks,
index dc1a79506f2f1369060b8a0afa423355d46d9cb9..e940b57bc0ddbaccc8edcd4075f759a72aa0beb2 100644 (file)
 #ifndef LIBMV_SIMPLE_PIPELINE_PIPELINE_H_
 #define LIBMV_SIMPLE_PIPELINE_PIPELINE_H_
 
+#include "libmv/simple_pipeline/callbacks.h"
 #include "libmv/simple_pipeline/tracks.h"
 #include "libmv/simple_pipeline/reconstruction.h"
 
 namespace libmv {
 
-typedef void (*progress_update_callback) (void *customdata, double progress, const char *message);
-
 /*!
     Estimate camera poses and scene 3D coordinates for all frames and tracks.
 
@@ -49,8 +48,7 @@ typedef void (*progress_update_callback) (void *customdata, double progress, con
 */
 void EuclideanCompleteReconstruction(const Tracks &tracks,
                                      EuclideanReconstruction *reconstruction,
-                                     progress_update_callback update_callback,
-                                     void *update_customdata);
+                                     ProgressUpdateCallback *update_callback = NULL);
 
 /*!
     Estimate camera matrices and homogeneous 3D coordinates for all frames and
index 449832fd4569b2295e3f4fdeba12d57848e905bb..4c54e9f22f51b0af55fc0a5ce2e573ec2d7eb9b5 100644 (file)
@@ -1356,7 +1356,6 @@ typedef struct ReconstructProgressData {
        short *stop;
        short *do_update;
        float *progress;
-       float stats_progress;
        char *stats_message;
        int message_size;
 } ReconstructProgressData;
@@ -1656,8 +1655,8 @@ static void solve_reconstruction_update_cb(void *customdata, double progress, co
                *progressdata->do_update= 1;
        }
 
-       BLI_snprintf(progressdata->stats_message, progressdata->message_size, "Solving camera | %s", message);
-       progressdata->stats_progress= progress;
+       BLI_snprintf(progressdata->stats_message, progressdata->message_size,
+                       "Solving camera | %s", message);
 }
 
 #if 0
index 43cce0ada673a974c52bbc14d9ece8797a7327b9..e91331e5252afd845bbdf42429674a6b565c622d 100644 (file)
@@ -1518,7 +1518,6 @@ typedef struct {
        ReportList *reports;
 
        char stats_message[256];
-       float *stats_progress;
 
        struct MovieReconstructContext *context;
 } SolveCameraJob;
@@ -1557,17 +1556,12 @@ static void solve_camera_updatejob(void *scv)
        MovieTracking *tracking= &scj->clip->tracking;
 
        BLI_strncpy(tracking->stats->message, scj->stats_message, sizeof(tracking->stats->message));
-
-       if(scj->stats_progress)
-               tracking->stats->progress= *scj->stats_progress;
 }
 
 static void solve_camera_startjob(void *scv, short *stop, short *do_update, float *progress)
 {
        SolveCameraJob *scj= (SolveCameraJob *)scv;
 
-       scj->stats_progress= progress;
-
        BKE_tracking_solve_reconstruction(scj->context, stop, do_update, progress,
                        scj->stats_message, sizeof(scj->stats_message));
 }
index 635be805d1b38975d551c0f0b55faf2858afd6e1..931ed6fb8c69caff0e5ec62e55d7641617fdbc3f 100644 (file)
@@ -174,7 +174,6 @@ typedef struct MovieTrackingReconstruction {
 } MovieTrackingReconstruction;
 
 typedef struct MovieTrackingStats {
-       float progress;
        char message[256];
 } MovieTrackingStats;