diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-11-27 14:35:00 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-11-27 14:35:00 +0400 |
commit | 196d06a0bfd3f566b6c12c98006382f3a1a1d99c (patch) | |
tree | 6261d68c15c5871bb81d93b68c263c71c68be98f /extern/libmv | |
parent | f5f4348e10774fb1f90aaf718f144240137f4281 (diff) |
Camera tracking: progress report clean-up
Send object which implements ProgressUpdateCallback to complete reconstruction
function rather than sending C-like procedure variable and context.
Diffstat (limited to 'extern/libmv')
-rw-r--r-- | extern/libmv/CMakeLists.txt | 2 | ||||
-rw-r--r-- | extern/libmv/libmv-capi.cpp | 33 | ||||
-rw-r--r-- | extern/libmv/libmv/simple_pipeline/callbacks.cc | 29 | ||||
-rw-r--r-- | extern/libmv/libmv/simple_pipeline/callbacks.h | 33 | ||||
-rw-r--r-- | extern/libmv/libmv/simple_pipeline/pipeline.cc | 42 | ||||
-rw-r--r-- | extern/libmv/libmv/simple_pipeline/pipeline.h | 6 |
6 files changed, 112 insertions, 33 deletions
diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index cd1f572197c..6f0d5f3d126 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -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 diff --git a/extern/libmv/libmv-capi.cpp b/extern/libmv/libmv-capi.cpp index 2472b08da19..f08aea9fbd1 100644 --- a/extern/libmv/libmv-capi.cpp +++ b/extern/libmv/libmv-capi.cpp @@ -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 index 00000000000..7e4bca6efc7 --- /dev/null +++ b/extern/libmv/libmv/simple_pipeline/callbacks.cc @@ -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 index 00000000000..675f73c1cab --- /dev/null +++ b/extern/libmv/libmv/simple_pipeline/callbacks.h @@ -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_ diff --git a/extern/libmv/libmv/simple_pipeline/pipeline.cc b/extern/libmv/libmv/simple_pipeline/pipeline.cc index 654127ac51d..382365e579f 100644 --- a/extern/libmv/libmv/simple_pipeline/pipeline.cc +++ b/extern/libmv/libmv/simple_pipeline/pipeline.cc @@ -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, diff --git a/extern/libmv/libmv/simple_pipeline/pipeline.h b/extern/libmv/libmv/simple_pipeline/pipeline.h index dc1a79506f2..e940b57bc0d 100644 --- a/extern/libmv/libmv/simple_pipeline/pipeline.h +++ b/extern/libmv/libmv/simple_pipeline/pipeline.h @@ -21,13 +21,12 @@ #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 |