EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge upstream/main into camtrack-validate-input
vangel761ec9947efb8f
diff --cc crates/track/src/camtrack/bundle.rsindex 4149bc52e,7f8dc5bcc..e03341d14--- a/crates/track/src/camtrack/bundle.rs+++ b/crates/track/src/camtrack/bundle.rs@@@ -10,9 -10,9 +10,9 @@@use rayon::prelude::*;-use super::Distortion;use super::geometry::Pose;- use super::linalg::*;+ use super::linalg::{M3, V3, add, cholesky_solve, dot, inv3, mm, mtv, mv, rodrigues, scale, skew, sub};+use super::{Distortion, SolveError};/// A camera in the adjustment.#[derive(Clone, Copy, Debug, PartialEq)]@@@ -243,12 -174,32 +243,35 @@@ fn cam_jac(l: &Layout, ci: usize, c: &B}}+ /// Smooth per-camera log focal lengths in the normal equations.+ fn add_focal_prior(cams: &[BaCam], o: &BaOpts, l: &Layout, s_mat: &mut [f64], bc: &mut [f64]) {+ let n = l.n;+ // Focal prior.+ if let FocalMode::PerCamera(k) = o.focal {+ for i in 0..cams.len().saturating_sub(1) {+ let r = k * (cams[i].f.ln() - cams[i + 1].f.ln());+ let (a, b) = (l.fidx[i], l.fidx[i + 1]);+ let ia = (a != usize::MAX).then_some(a);+ let ib = (b != usize::MAX).then_some(b);+ for (idx, g) in [(ia, k), (ib, -k)] {+ let Some(x) = idx else { continue };+ bc[x] -= g * r;+ for (idy, h) in [(ia, k), (ib, -k)] {+ if let Some(y) = idy {+ s_mat[x * n + y] += g * h;+ }+ }+ }+ }+ }+ }+/// Run Levenberg–Marquardt. `cams` and `pts` are updated in place.-pub fn adjust(cams: &mut [BaCam], pts: &mut [V3], obs: &[BaObs], o: &BaOpts) -> BaReport {+/// Invalid inputs or workspaces exceeding 256 MiB return an error before mutation.+pub fn adjust(cams: &mut [BaCam], pts: &mut [V3], obs: &[BaObs], o: &BaOpts) -> Result<BaReport, SolveError> {+ validate(cams, pts, obs, o)?;let l = layout(cams.len(), o);+ let matrix_len = matrix_len(l.n, pts.len(), obs.len())?;let npts = pts.len();// Observations by point.let mut by_pt: Vec<Vec<u32>> = vec![vec![]; npts];