[Bf-blender-cvs] [e9c9e1c2c7c] master: Libmv: De-duplicate creation of residual block

Sergey Sharybin noreply at git.blender.org
Mon Apr 20 16:27:14 CEST 2020


Commit: e9c9e1c2c7c1f740edbd771baf3f06b33d76c1b8
Author: Sergey Sharybin
Date:   Mon Apr 20 12:44:07 2020 +0200
Branches: master
https://developer.blender.org/rBe9c9e1c2c7c1f740edbd771baf3f06b33d76c1b8

Libmv: De-duplicate creation of residual block

Allows to centralize logic which is needed to check which cost functor
to use for the specific intrinsics.

===================================================================

M	intern/libmv/libmv/simple_pipeline/bundle.cc

===================================================================

diff --git a/intern/libmv/libmv/simple_pipeline/bundle.cc b/intern/libmv/libmv/simple_pipeline/bundle.cc
index 7a0451213f7..bc2b5f65f53 100644
--- a/intern/libmv/libmv/simple_pipeline/bundle.cc
+++ b/intern/libmv/libmv/simple_pipeline/bundle.cc
@@ -389,6 +389,43 @@ void EuclideanBundlerPerformEvaluation(const Tracks &tracks,
   }
 }
 
+template<typename CostFunction>
+void AddResidualBlockToProblemImpl(const CameraIntrinsics *intrinsics,
+                                   double observed_x, double observed_y,
+                                   double weight,
+                                   double ceres_intrinsics[OFFSET_MAX],
+                                   double *camera_R_t,
+                                   EuclideanPoint *point,
+                                   ceres::Problem* problem) {
+  problem->AddResidualBlock(new ceres::AutoDiffCostFunction<
+      CostFunction, 2, OFFSET_MAX, 6, 3>(
+          new CostFunction(
+              intrinsics,
+              observed_x, observed_y,
+              weight)),
+      NULL,
+      ceres_intrinsics,
+      camera_R_t,
+      &point->X(0));
+}
+
+void AddResidualBlockToProblem(const CameraIntrinsics *invariant_intrinsics,
+                               const Marker &marker,
+                               double marker_weight,
+                               double ceres_intrinsics[OFFSET_MAX],
+                               double *camera_R_t,
+                               EuclideanPoint *point,
+                               ceres::Problem* problem) {
+    AddResidualBlockToProblemImpl<OpenCVReprojectionErrorApplyIntrinsics>(
+            invariant_intrinsics,
+            marker.x, marker.y,
+            marker_weight,
+            ceres_intrinsics,
+            camera_R_t,
+            point,
+            problem);
+}
+
 // This is an utility function to only bundle 3D position of
 // given markers list.
 //
@@ -418,17 +455,13 @@ void EuclideanBundlePointsOnly(const CameraIntrinsics *invariant_intrinsics,
     // camera translation.
     double *current_camera_R_t = &all_cameras_R_t[camera->image](0);
 
-    problem.AddResidualBlock(new ceres::AutoDiffCostFunction<
-        OpenCVReprojectionErrorApplyIntrinsics, 2, OFFSET_MAX, 6, 3>(
-            new OpenCVReprojectionErrorApplyIntrinsics(
-                invariant_intrinsics,
-                marker.x,
-                marker.y,
-                1.0)),
-        NULL,
-        ceres_intrinsics,
-        current_camera_R_t,
-        &point->X(0));
+    AddResidualBlockToProblem(invariant_intrinsics,
+                              marker,
+                              1.0,
+                              ceres_intrinsics,
+                              current_camera_R_t,
+                              point,
+                              &problem);
 
     problem.SetParameterBlockConstant(current_camera_R_t);
     num_residuals++;
@@ -538,17 +571,13 @@ void EuclideanBundleCommonIntrinsics(
     // no affect on the final solution.
     // This way ceres is not gonna to go crazy.
     if (marker.weight != 0.0) {
-      problem.AddResidualBlock(new ceres::AutoDiffCostFunction<
-          OpenCVReprojectionErrorApplyIntrinsics, 2, OFFSET_MAX, 6, 3>(
-              new OpenCVReprojectionErrorApplyIntrinsics(
-                  intrinsics,
-                  marker.x,
-                  marker.y,
-                  marker.weight)),
-          NULL,
-          ceres_intrinsics,
-          current_camera_R_t,
-          &point->X(0));
+      AddResidualBlockToProblem(intrinsics,
+                                marker,
+                                marker.weight,
+                                ceres_intrinsics,
+                                current_camera_R_t,
+                                point,
+                                &problem);
 
       // We lock the first camera to better deal with scene orientation ambiguity.
       if (!have_locked_camera) {



More information about the Bf-blender-cvs mailing list