projective_grid/lib.rs
1//! Generic 2D projective grid construction and homography tools.
2//!
3//! This crate provides reusable algorithms for turning a cloud of 2D
4//! points into a labelled grid: seed-and-grow BFS, boundary extension
5//! via fitted homography, and per-cell / global rectification.
6//!
7//! Pattern-agnostic at the bottom (KD-tree, circular stats, mean-shift,
8//! DLT homography); pattern-specific at the top via the
9//! [`square::grow::GrowValidator`] trait — chessboard parity, ChArUco
10//! marker rules, etc. plug in there.
11//!
12//! # Module layout
13//!
14//! | Module | Responsibility |
15//! |---|---|
16//! | [`square::grow`] | Seed-and-grow BFS over a square lattice |
17//! | [`square::extension`] | Boundary extension via globally-fit or local homography |
18//! | [`square::seed`] | 2×2 seed primitives (cell size, midpoint violation) |
19//! | [`square::validate`](mod@square::validate) | Post-grow line / local-H residual checks |
20//! | [`square::mesh`] / [`square::rectify`] | Per-cell mesh / global homography rectification |
21//! | [`square::smoothness`] | Midpoint prediction + step-aware outlier detection |
22//! | [`square::alignment`] | D4 transforms on integer grid coordinates |
23//! | [`hex`] | Hex grid: index, mesh, rectify, smoothness, alignment (no grow path yet) |
24//! | [`circular_stats`] | Undirected-angle helpers (smoothing, plateau peak picking, double-angle 2-means) |
25//! | [`global_step`] / [`local_step`] | Cell-size estimation primitives |
26//! | [`homography`] | 4-point + DLT homography with reprojection-quality diagnostics |
27
28mod float_helpers;
29
30pub mod affine;
31pub mod circular_stats;
32pub mod component_merge;
33pub mod global_step;
34pub mod hex;
35pub mod homography;
36pub mod local_step;
37pub mod square;
38pub mod topological;
39
40/// Trait alias for floating-point types supported by this crate.
41///
42/// Both `f32` and `f64` satisfy this bound. All public generic types default
43/// to `f32` for backward compatibility.
44pub trait Float: nalgebra::RealField + Copy {}
45impl<T: nalgebra::RealField + Copy> Float for T {}
46
47// --- Generic building blocks (no square / hex assumption) --------------------
48pub use affine::AffineTransform2D;
49pub use global_step::{estimate_global_cell_size, GlobalStepEstimate, GlobalStepParams};
50pub use homography::{
51 estimate_homography, estimate_homography_with_quality, homography_from_4pt,
52 homography_from_4pt_with_quality, Homography, HomographyQuality,
53};
54pub use local_step::{estimate_local_steps, LocalStep, LocalStepParams, LocalStepPointData};
55
56// --- Square-grid surface re-exported at the crate root --------
57pub use square::alignment::{GridAlignment, GridTransform, GRID_TRANSFORMS_D4};
58pub use square::index::GridCoords;
59pub use square::mesh::SquareGridHomographyMesh;
60pub use square::rectify::SquareGridHomography;
61pub use square::smoothness::{
62 square_find_inconsistent_corners, square_find_inconsistent_corners_step_aware,
63 square_predict_grid_position,
64};
65
66// --- Topological-grid surface --------------------------------
67pub use topological::{
68 build_grid_topological, AxisHint, TopologicalComponent, TopologicalError, TopologicalGrid,
69 TopologicalParams, TopologicalStats,
70};
71
72// --- Component merge (shared by both pipelines) --------------
73pub use component_merge::{
74 merge_components_local, ComponentInput, ComponentMergeResult, ComponentMergeStats,
75 LocalMergeParams,
76};