From 26815f1e3ec5107c133007bbab05f2313e6f8b2d Mon Sep 17 00:00:00 2001 From: Andrew Straw Date: Mon, 13 Jan 2025 22:25:44 +0100 Subject: [PATCH] mcsc-structs: add validation --- geometry/mcsc-structs/src/lib.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/geometry/mcsc-structs/src/lib.rs b/geometry/mcsc-structs/src/lib.rs index 82b9e200e..c595c40c6 100644 --- a/geometry/mcsc-structs/src/lib.rs +++ b/geometry/mcsc-structs/src/lib.rs @@ -127,16 +127,47 @@ impl RadFile { /// All things saved to an MCSC directory pub struct McscConfigDir { + /// indicates whether point is visible from camera (shape: n_cams x n_points) pub id_mat: DatMat, + /// pixel size of each camera (shape n_cams x 2) pub res: DatMat, pub radfiles: Vec, pub camera_order: Vec, pub cfg: McscCfg, + /// image coordinates of point from camera (shape: n_cams*3 x n_points) pub points: DatMat, } impl McscConfigDir { + fn validate(&self) -> Result<()> { + let n_cams = self.id_mat.rows; + let n_points = self.id_mat.cols; + + if self.points.rows != n_cams * 3 { + eyre::bail!("inconsistent number of cameras"); + } + if self.points.cols != n_points { + eyre::bail!("inconsistent number of points"); + } + + if self.camera_order.len() != n_cams { + eyre::bail!("inconsistent number of cameras"); + } + + if self.res.rows != n_cams { + eyre::bail!("inconsistent number of cameras"); + } + + if self.res.cols != 2 { + eyre::bail!("inconsistent `res` data"); + } + + Ok(()) + } + pub fn save_to_path>(&self, p: P) -> Result<()> { + self.validate()?; + let base = PathBuf::from(p.as_ref()); std::fs::create_dir_all(&base)?;