[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42067] branches/soc-2011-tomato: Camera tracking: expose progress and status from camera solver into interface

Sergey Sharybin sergey.vfx at gmail.com
Tue Nov 22 15:45:22 CET 2011


Revision: 42067
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42067
Author:   nazgul
Date:     2011-11-22 14:45:22 +0000 (Tue, 22 Nov 2011)
Log Message:
-----------
Camera tracking: expose progress and status from camera solver into interface

Reporting progress isn't really accurate, but trying to make it more linear
can lead to spending more effort on it than having benefit. Also, changing
status in the information line helps to understand that blender isn't hang
up and solving is till working nicely.

Main changes in code:
- libmv_solveReconstruction now accepts additional parameters:

  * progress_update_callback - a function which is getting called
    from solver algorithm to report progress back to Blender.
  * callback_customdata - a user-defined context which is passing
    to progress_update_callback so progress can be updated in needed
    blender-side data structures.

  This parameters are optional.

- Added structure MovieTrackingStats which is placed in MovieTracking
  structure. It's supposed to be used for displaying information about
  different operations (currently it's only camera solver, but can be
  easily used for something else in the future) in clip editor.
  This statistics structure is getting allocated for time operator is
  working and not saving into .blend file.

- Clip Editor now displays statistics stored in MovieTrackingStats structure
  like it's done for rendering.

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/pipeline.cc
    branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/pipeline.h
    branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
    branches/soc-2011-tomato/extern/libmv/libmv-capi.h
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
    branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h

Modified: branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/pipeline.cc
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/pipeline.cc	2011-11-22 14:45:11 UTC (rev 42066)
+++ branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/pipeline.cc	2011-11-22 14:45:22 UTC (rev 42067)
@@ -21,6 +21,7 @@
 #include <cstdio>
 
 #include "libmv/logging/logging.h"
+#include "libmv/simple_pipeline/pipeline.h"
 #include "libmv/simple_pipeline/bundle.h"
 #include "libmv/simple_pipeline/intersect.h"
 #include "libmv/simple_pipeline/resect.h"
@@ -120,11 +121,14 @@
 template<typename PipelineRoutines>
 void InternalCompleteReconstruction(
     const Tracks &tracks,
-    typename PipelineRoutines::Reconstruction *reconstruction) {
+    typename PipelineRoutines::Reconstruction *reconstruction,
+    progress_update_callback update_callback,
+    void *update_customdata) {
   int max_track = tracks.MaxTrack();
   int max_image = tracks.MaxImage();
   int num_resects = -1;
   int num_intersects = -1;
+  int tot_resects = 0;
   LG << "Max track: " << max_track;
   LG << "Max image: " << max_image;
   LG << "Number of markers: " << tracks.NumMarkers();
@@ -180,6 +184,9 @@
       if (reconstructed_markers.size() >= 5) {
         if (PipelineRoutines::Resect(reconstructed_markers, reconstruction, false)) {
           num_resects++;
+          tot_resects++;
+          if(update_callback)
+            update_callback(update_customdata, (float)tot_resects/(max_image), "Completing solution");
           LG << "Ran Resect() for image " << image;
         } else {
           LG << "Failed Resect() for image " << image;
@@ -211,6 +218,8 @@
       if (PipelineRoutines::Resect(reconstructed_markers, reconstruction, true)) {
         num_resects++;
         LG << "Ran Resect() for image " << image;
+        if(update_callback)
+          update_callback(update_customdata, (float)tot_resects/(max_image), "Completing solution");
       } else {
         LG << "Failed Resect() for image " << image;
       }
@@ -289,15 +298,20 @@
 }
 
 void EuclideanCompleteReconstruction(const Tracks &tracks,
-                                     EuclideanReconstruction *reconstruction) {
+                                     EuclideanReconstruction *reconstruction,
+                                     progress_update_callback update_callback,
+                                     void *update_customdata) {
   InternalCompleteReconstruction<EuclideanPipelineRoutines>(tracks,
-                                                            reconstruction);
+                                                            reconstruction,
+                                                            update_callback,
+                                                            update_customdata);
 }
 
 void ProjectiveCompleteReconstruction(const Tracks &tracks,
                                       ProjectiveReconstruction *reconstruction) {
   InternalCompleteReconstruction<ProjectivePipelineRoutines>(tracks,
-                                                             reconstruction);
+                                                             reconstruction,
+                                                             NULL, NULL);
 }
 
 void InvertIntrinsicsForTracks(const Tracks &raw_tracks,

Modified: branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/pipeline.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/pipeline.h	2011-11-22 14:45:11 UTC (rev 42066)
+++ branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/pipeline.h	2011-11-22 14:45:22 UTC (rev 42067)
@@ -26,6 +26,8 @@
 
 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.
 
@@ -46,7 +48,9 @@
     \sa EuclideanResect, EuclideanIntersect, EuclideanBundle
 */
 void EuclideanCompleteReconstruction(const Tracks &tracks,
-                                     EuclideanReconstruction *reconstruction);
+                                     EuclideanReconstruction *reconstruction,
+                                     progress_update_callback update_callback,
+                                     void *update_customdata);
 
 /*!
     Estimate camera matrices and homogeneous 3D coordinates for all frames and

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2011-11-22 14:45:11 UTC (rev 42066)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2011-11-22 14:45:22 UTC (rev 42067)
@@ -31,6 +31,8 @@
 #include "libmv-capi.h"
 
 #include "glog/logging.h"
+#include "libmv/logging/logging.h"
+
 #include "Math/v3d_optimization.h"
 
 #include "libmv/tracking/esm_region_tracker.h"
@@ -356,7 +358,8 @@
 
 
 libmv_Reconstruction *libmv_solveReconstruction(libmv_Tracks *tracks, int keyframe1, int keyframe2,
-		int refine_intrinsics, double focal_length, double principal_x, double principal_y, double k1, double k2, double k3)
+			int refine_intrinsics, double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+			reconstruct_progress_update_cb progress_update_callback, void *callback_customdata)
 {
 	/* Invert the camera intrinsics. */
 	libmv::vector<libmv::Marker> markers = ((libmv::Tracks*)tracks)->AllMarkers();
@@ -377,15 +380,17 @@
 
 	libmv::Tracks normalized_tracks(markers);
 
-	// printf("frames to init from: %d, %d\n", keyframe1, keyframe2);
+	LG << "frames to init from: " << keyframe1 << " " << keyframe2;
 	libmv::vector<libmv::Marker> keyframe_markers =
 		normalized_tracks.MarkersForTracksInBothImages(keyframe1, keyframe2);
-	// printf("number of markers for init: %d\n", keyframe_markers.size());
+	LG << "number of markers for init: " << keyframe_markers.size();
 
+	progress_update_callback(callback_customdata, 0, "Initial reconstruction");
+
 	libmv::EuclideanReconstructTwoFrames(keyframe_markers, reconstruction);
 	libmv::EuclideanBundle(normalized_tracks, reconstruction);
 
-	libmv::EuclideanCompleteReconstruction(normalized_tracks, reconstruction);
+	libmv::EuclideanCompleteReconstruction(normalized_tracks, reconstruction, progress_update_callback, callback_customdata);
 
 	if (refine_intrinsics) {
 		/* only a few combinations are supported but trust the caller */
@@ -402,9 +407,12 @@
 		if (refine_intrinsics & LIBMV_REFINE_RADIAL_DISTORTION_K2) {
 			libmv_refine_flags |= libmv::BUNDLE_RADIAL_K2;
 		}
+
+		progress_update_callback(callback_customdata, 0, "Refining solution");
 		libmv::EuclideanBundleCommonIntrinsics(*(libmv::Tracks *)tracks, libmv_refine_flags, reconstruction, intrinsics);
 	}
 
+	progress_update_callback(callback_customdata, 0, "Finishing solution");
 	libmv_reconstruction->tracks = *(libmv::Tracks *)tracks;
 	libmv_reconstruction->error = libmv::EuclideanReprojectionError(*(libmv::Tracks *)tracks, *reconstruction, *intrinsics);
 

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2011-11-22 14:45:11 UTC (rev 42066)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2011-11-22 14:45:22 UTC (rev 42067)
@@ -64,10 +64,14 @@
 #define LIBMV_REFINE_PRINCIPAL_POINT	(1<<1)
 #define LIBMV_REFINE_RADIAL_DISTORTION_K1 (1<<2)
 #define LIBMV_REFINE_RADIAL_DISTORTION_K2 (1<<4)
+
+typedef void (*reconstruct_progress_update_cb) (void *customdata, double progress, const char *message);
+
 int libmv_refineParametersAreValid(int parameters);
 
 struct libmv_Reconstruction *libmv_solveReconstruction(struct libmv_Tracks *tracks, int keyframe1, int keyframe2,
-			int refine_intrinsics, double focal_length, double principal_x, double principal_y, double k1, double k2, double k3);
+			int refine_intrinsics, double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+			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);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-11-22 14:45:11 UTC (rev 42066)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-11-22 14:45:22 UTC (rev 42067)
@@ -97,7 +97,7 @@
 			int keyframe1, int keyframe2, int width, int height);
 void BKE_tracking_reconstruction_context_free(struct MovieReconstructContext *context);
 void BKE_tracking_solve_reconstruction(struct MovieReconstructContext *context,
-			short *stop, short *do_update, float *progress);
+			short *stop, short *do_update, float *progress, char *stats_message, int message_size);
 int BKE_tracking_finish_reconstruction(struct MovieReconstructContext *context, struct MovieTracking *tracking);
 
 struct MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(struct MovieTracking *tracking, int framenr);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-11-22 14:45:11 UTC (rev 42066)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-11-22 14:45:22 UTC (rev 42067)
@@ -1328,6 +1328,8 @@
 	short *stop;
 	short *do_update;
 	float *progress;
+	char *stats_message;
+	int message_size;
 } ReconstructProgressData;
 
 #if WITH_LIBMV
@@ -1616,20 +1618,7 @@
 	MEM_freeN(context);
 }
 
-#if 0
-
-/* TODO: this two callbacks are supposed to be used to make solving more
-         interactive with the interface, so approximated progress would be
-         displayed and it's also can be nice to have option to break solving

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list