88 lines
2.3 KiB
Rust
88 lines
2.3 KiB
Rust
//! # RTX Segmentation
|
|
//!
|
|
//! Image segmentation and spatial mapping utilities for medical imaging.
|
|
//!
|
|
//! This crate provides tools for:
|
|
//! - K-D Tree spatial queries (nearest neighbor, k-nearest, radius search)
|
|
//! - K-means clustering for tissue segmentation
|
|
//! - Spatial mapping between point clouds and meshes
|
|
//!
|
|
//! ## Example
|
|
//!
|
|
//! ```rust,no_run
|
|
//! use rtx_segmentation::prelude::*;
|
|
//! use nalgebra::Point3;
|
|
//!
|
|
//! // Build a K-D tree from points
|
|
//! let points = vec![
|
|
//! Point3::new(0.0, 0.0, 0.0),
|
|
//! Point3::new(1.0, 0.0, 0.0),
|
|
//! Point3::new(0.0, 1.0, 0.0),
|
|
//! ];
|
|
//! let tree = KdTree3D::build(&points);
|
|
//!
|
|
//! // Find nearest neighbor
|
|
//! let query = Point3::new(0.5, 0.5, 0.0);
|
|
//! let (index, distance) = tree.nearest(&query).unwrap();
|
|
//! ```
|
|
|
|
pub mod error;
|
|
pub mod kdtree;
|
|
pub mod kmeans;
|
|
|
|
pub use error::{Result, SegmentationError};
|
|
|
|
/// Prelude module with commonly used types.
|
|
pub mod prelude {
|
|
pub use crate::error::{Result, SegmentationError};
|
|
pub use crate::kdtree::{KdTree3D, bounding_box, center_of_mass};
|
|
pub use crate::kmeans::{KMeans, KMeansConfig, KMeansResult, segment_volume_kmeans};
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use nalgebra::Point3;
|
|
|
|
#[test]
|
|
fn test_prelude_imports() {
|
|
use prelude::*;
|
|
|
|
let points = vec![
|
|
Point3::new(0.0, 0.0, 0.0),
|
|
Point3::new(1.0, 0.0, 0.0),
|
|
Point3::new(0.0, 1.0, 0.0),
|
|
];
|
|
|
|
let tree = KdTree3D::build(&points);
|
|
assert_eq!(tree.len(), 3);
|
|
}
|
|
|
|
#[test]
|
|
fn test_integration() {
|
|
use prelude::*;
|
|
|
|
// Build tree
|
|
let points = vec![
|
|
Point3::new(0.0, 0.0, 0.0),
|
|
Point3::new(1.0, 1.0, 1.0),
|
|
Point3::new(2.0, 2.0, 2.0),
|
|
];
|
|
let tree = KdTree3D::build(&points);
|
|
|
|
// Test nearest
|
|
let (idx, dist) = tree.nearest(&Point3::new(0.1, 0.1, 0.1)).unwrap();
|
|
assert_eq!(idx, 0);
|
|
assert!(dist < 0.2);
|
|
|
|
// Test center of mass
|
|
let com = center_of_mass(&points).unwrap();
|
|
assert!((com - Point3::new(1.0, 1.0, 1.0)).norm() < 1e-10);
|
|
|
|
// Test bounding box
|
|
let (min, max) = bounding_box(&points).unwrap();
|
|
assert!((min - Point3::new(0.0, 0.0, 0.0)).norm() < 1e-10);
|
|
assert!((max - Point3::new(2.0, 2.0, 2.0)).norm() < 1e-10);
|
|
}
|
|
}
|