tpt_sci_image/error.rs
1//! Errors for the `tpt-sci-image` crate.
2//!
3//! Every public reconstruction entry point validates its inputs and returns a
4//! [`Result`], matching the `Result`-returning convention of the other
5//! `tpt-science` crates. This replaces the previous silent zero-padding of
6//! malformed inputs, which could mask caller bugs.
7
8use thiserror::Error;
9
10/// Errors returned by the image reconstruction API.
11#[derive(Debug, Error, PartialEq, Eq)]
12pub enum ImageError {
13 /// The input image had zero rows or columns.
14 #[error("image must be non-empty, got {nrows}x{ncols}")]
15 EmptyImage {
16 /// Number of rows in the offending image.
17 nrows: usize,
18 /// Number of columns in the offending image.
19 ncols: usize,
20 },
21
22 /// The angle list supplied for a reconstruction was empty.
23 #[error("angle list must be non-empty")]
24 EmptyAngles,
25
26 /// The sinogram row count did not match the number of projection angles.
27 #[error("sinogram has {sino_rows} rows but {n_angles} angles were supplied")]
28 AngleCountMismatch {
29 /// Number of rows in the supplied sinogram.
30 sino_rows: usize,
31 /// Number of projection angles supplied.
32 n_angles: usize,
33 },
34
35 /// A sinogram dimension did not match the expected volume geometry
36 /// (`n_bins = max(nx, ny)`, or `n_z`).
37 #[error("expected dimension {expected} but got {got}")]
38 DimensionMismatch {
39 /// Expected extent (voxels or detector bins).
40 expected: usize,
41 /// Supplied extent.
42 got: usize,
43 },
44
45 /// A [`crate::cone_beam::ConeBeamGeometry`] parameter was invalid: a
46 /// non-positive source/detector distance or pixel spacing, or a zero
47 /// detector pixel count / angle count.
48 #[error("invalid cone-beam geometry: {reason}")]
49 InvalidGeometry {
50 /// Human-readable description of what was invalid.
51 reason: String,
52 },
53}