void BAHelpers::BundleToMap()

in opensfm/src/sfm/src/ba_helpers.cc [735:789]


void BAHelpers::BundleToMap(const bundle::BundleAdjuster& bundle_adjuster,
                            map::Map& output_map, bool update_cameras) {
  // update cameras
  if (update_cameras) {
    for (auto& cam : output_map.GetCameras()) {
      const auto& ba_cam = bundle_adjuster.GetCamera(cam.first);
      for (const auto& p : ba_cam.GetParametersMap()) {
        cam.second.SetParameterValue(p.first, p.second);
      }
    }
  }

  // Update bias
  for (auto& bias : output_map.GetBiases()) {
    const auto& new_bias = bundle_adjuster.GetBias(bias.first);
    if (!new_bias.IsValid()) {
      throw std::runtime_error("Bias " + bias.first +
                               " has either NaN or INF values.");
    }
    bias.second = new_bias;
  }

  // Update rig instances
  for (auto& instance : output_map.GetRigInstances()) {
    const auto new_instance =
        bundle_adjuster.GetRigInstance(instance.first).GetValue();
    if (!new_instance.IsValid()) {
      throw std::runtime_error("Rig Instance " + instance.first +
                               " has either NaN or INF values.");
    }
    instance.second.SetPose(new_instance);
  }

  // Update rig cameras
  for (auto& rig_camera : output_map.GetRigCameras()) {
    const auto new_rig_camera =
        bundle_adjuster.GetRigCamera(rig_camera.first).GetValue();
    if (!new_rig_camera.IsValid()) {
      throw std::runtime_error("Rig Camera " + rig_camera.first +
                               " has either NaN or INF values.");
    }
    rig_camera.second.pose = new_rig_camera;
  }

  // Update points
  for (auto& point : output_map.GetLandmarks()) {
    const auto& pt = bundle_adjuster.GetPoint(point.first);
    if (!pt.GetValue().allFinite()) {
      throw std::runtime_error("Point " + point.first +
                               " has either NaN or INF values.");
    }
    point.second.SetGlobalPos(pt.GetValue());
    point.second.SetReprojectionErrors(pt.reprojection_errors);
  }
}