@@ -87,6 +87,8 @@ void GlobalPositioner::SetupProblem(
8787 ceres::Problem::Options problem_options;
8888 problem_options.loss_function_ownership = ceres::DO_NOT_TAKE_OWNERSHIP;
8989 problem_ = std::make_unique<ceres::Problem>(problem_options);
90+ loss_function_ = options_.CreateLossFunction ();
91+
9092 // Allocate enough memory for the scales. One for each residual.
9193 // Due to possibly invalid image pairs or tracks, the actual number of
9294 // residuals may be smaller.
@@ -169,7 +171,7 @@ void GlobalPositioner::AddCameraToCameraConstraints(
169171 BATAPairwiseDirectionError::Create (translation);
170172 problem_->AddResidualBlock (
171173 cost_function,
172- options_. loss_function .get (),
174+ loss_function_ .get (),
173175 images[image_id1].cam_from_world .translation .data (),
174176 images[image_id2].cam_from_world .translation .data (),
175177 &scale);
@@ -212,19 +214,17 @@ void GlobalPositioner::AddPointToCameraConstraints(
212214
213215 if (loss_function_ptcam_uncalibrated_ == nullptr ) {
214216 loss_function_ptcam_uncalibrated_ =
215- std::make_shared<ceres::ScaledLoss>(options_. loss_function .get (),
217+ std::make_shared<ceres::ScaledLoss>(loss_function_ .get (),
216218 0.5 * weight_scale_pt,
217219 ceres::DO_NOT_TAKE_OWNERSHIP);
218220 }
219221
220222 if (options_.constraint_type ==
221223 GlobalPositionerOptions::POINTS_AND_CAMERAS_BALANCED) {
222- loss_function_ptcam_calibrated_ =
223- std::make_shared<ceres::ScaledLoss>(options_.loss_function .get (),
224- weight_scale_pt,
225- ceres::DO_NOT_TAKE_OWNERSHIP);
224+ loss_function_ptcam_calibrated_ = std::make_shared<ceres::ScaledLoss>(
225+ loss_function_.get (), weight_scale_pt, ceres::DO_NOT_TAKE_OWNERSHIP);
226226 } else {
227- loss_function_ptcam_calibrated_ = options_. loss_function ;
227+ loss_function_ptcam_calibrated_ = loss_function_ ;
228228 }
229229
230230 for (auto & [track_id, track] : tracks) {
0 commit comments