Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2020-04-20 13:44:07 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2020-04-20 17:26:39 +0300
commite9c9e1c2c7c1f740edbd771baf3f06b33d76c1b8 (patch)
tree177da4d1bac085d591aeb3ba0f563702f3c1af5a /intern/libmv
parentf0e896509024f036f9383ed121c6e170fd27a8b3 (diff)
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.
Diffstat (limited to 'intern/libmv')
-rw-r--r--intern/libmv/libmv/simple_pipeline/bundle.cc73
1 files changed, 51 insertions, 22 deletions
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) {