105 lines
3.2 KiB
Rust
105 lines
3.2 KiB
Rust
//! # Simple Ablation Simulation Example
|
|
//!
|
|
//! A quick demonstration of the Medical Digital Twin Platform for
|
|
//! simulating thermal ablation of a tumor.
|
|
//!
|
|
//! ## Run
|
|
//! ```bash
|
|
//! cargo run --example simple_ablation
|
|
//! ```
|
|
|
|
use rtx_digital_twin::{
|
|
AblationProbe, DigitalTwin, InterventionType, OrganGeometry, TissueLabel, TissueType,
|
|
};
|
|
|
|
fn main() {
|
|
println!("\n=== Medical Digital Twin: Ablation Planning ===\n");
|
|
|
|
// Create a small 30x30x30 liver geometry (fast simulation)
|
|
println!("Step 1: Creating liver geometry with tumor...");
|
|
let mut geometry = OrganGeometry::new([30, 30, 30], [1.0, 1.0, 1.0]);
|
|
|
|
// Fill interior with liver tissue
|
|
for z in 5..25 {
|
|
for y in 5..25 {
|
|
for x in 5..25 {
|
|
geometry.set_label(x, y, z, TissueLabel::from(TissueType::Liver));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add spherical tumor at center
|
|
geometry.create_sphere(
|
|
[15.0, 15.0, 15.0],
|
|
4.0,
|
|
TissueLabel::from(TissueType::Tumor),
|
|
);
|
|
|
|
// Print statistics
|
|
let histogram = geometry.tissue_histogram();
|
|
let liver_voxels = histogram.get(&TissueType::Liver).copied().unwrap_or(0);
|
|
let tumor_voxels = histogram.get(&TissueType::Tumor).copied().unwrap_or(0);
|
|
|
|
println!(" Grid: 30x30x30 voxels @ 1mm resolution");
|
|
println!(
|
|
" Liver: {} voxels (~{:.1} cm³)",
|
|
liver_voxels,
|
|
liver_voxels as f32 / 1000.0
|
|
);
|
|
println!(
|
|
" Tumor: {} voxels (~{:.1} cm³)\n",
|
|
tumor_voxels,
|
|
tumor_voxels as f32 / 1000.0
|
|
);
|
|
|
|
// Create digital twin
|
|
println!("Step 2: Initializing digital twin...");
|
|
let mut twin = DigitalTwin::new(geometry);
|
|
println!(" Digital twin ready\n");
|
|
|
|
// Run baseline (no intervention)
|
|
println!("Step 3: Running baseline simulation...");
|
|
let baseline = twin.simulate_baseline().expect("Baseline failed");
|
|
println!(" Baseline max temp: {:.1}°C", baseline.max_temperature);
|
|
println!(" Converged in {} iterations\n", baseline.iterations);
|
|
|
|
// Plan RFA intervention
|
|
println!("Step 4: Planning RFA intervention...");
|
|
let probe = AblationProbe::new([15.0, 15.0, 15.0], 40.0)
|
|
.with_type(InterventionType::RadiofrequencyAblation)
|
|
.with_active_length(10.0)
|
|
.with_diameter(4.0);
|
|
|
|
println!(" Probe position: center of tumor");
|
|
println!(" Power: 40 W");
|
|
println!(" Active length: 10 mm\n");
|
|
|
|
// What-if analysis
|
|
println!("Step 5: Running what-if analysis (60 seconds)...");
|
|
twin.reset_temperature();
|
|
|
|
let result = twin.what_if(&probe, 60.0).expect("What-if failed");
|
|
|
|
println!(" Max temperature: {:.1}°C", result.max_temperature);
|
|
println!(
|
|
" Damaged volume: {:.1} mm³ ({:.2} cm³)",
|
|
result.total_damaged_volume,
|
|
result.total_damaged_volume / 1000.0
|
|
);
|
|
println!(
|
|
" Safety margin: {}",
|
|
if result.safety_margin_ok {
|
|
"OK"
|
|
} else {
|
|
"Review needed"
|
|
}
|
|
);
|
|
println!(" Iterations: {}\n", result.iterations);
|
|
|
|
// Display full report
|
|
println!("Step 6: Clinical Report\n");
|
|
println!("{}", result.report());
|
|
|
|
println!("=== Simulation Complete ===\n");
|
|
}
|