use std::collections::{HashMap, BTreeMap};
use std::time::SystemTime;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ColorFormat {
Grayscale8,
Grayscale16,
RGB24,
RGBA32,
RGBA32F,
RGBA16F,
}
impl Default for ColorFormat {
fn default() -> Self {
Self::RGBA32
}
}
#[derive(Debug, Clone)]
pub struct CaptureConfig {
pub resolution: (u32, u32, u32),
pub depth_range: (f32, f32),
pub color_format: ColorFormat,
}
impl Default for CaptureConfig {
fn default() -> Self {
Self {
resolution: (256, 256, 256),
depth_range: (0.1, 10.0),
color_format: ColorFormat::RGBA32,
}
}
}
pub struct VolumeCapture {
config: CaptureConfig,
current_volume: Option<VolumeData>,
}
impl VolumeCapture {
pub fn new(config: CaptureConfig) -> Result<Self, CaptureError> {
Ok(Self {
config,
current_volume: None,
})
}
pub fn resolution(&self) -> (u32, u32, u32) {
self.config.resolution
}
pub fn capture(&mut self) -> Result<&VolumeData, CaptureError> {
let (x, y, z) = self.config.resolution;
let voxel_count: _ = (x * y * z) as usize;
let volume: _ = VolumeData {
resolution: self.config.resolution,
voxels: vec![Voxel::default(); voxel_count],
timestamp: std::time::SystemTime::now(),
};
self.current_volume = Some(volume);
Ok(self.current_volume.as_ref().unwrap())
}
pub fn current_volume(&self) -> Option<&VolumeData> {
self.current_volume.as_ref()
}
pub fn config(&self) -> &CaptureConfig {
&self.config
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct Voxel {
pub color: [f32; 4],
pub density: f32,
pub normal: [f32; 3],
}
#[derive(Debug, Clone)]
pub struct VolumeData {
pub resolution: (u32, u32, u32),
pub voxels: Vec<Voxel>,
pub timestamp: std::time::SystemTime,
}
#[derive(Debug, Clone)]
pub enum CaptureError {
InitializationFailed(String),
CaptureFailed(String),
DeviceNotFound,
}
impl std::fmt::Display for CaptureError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::InitializationFailed(msg) => write!(f, "初始化失败: {}", msg),
Self::CaptureFailed(msg) => write!(f, "捕捉失败: {}", msg),
Self::DeviceNotFound => write!(f, "设备未找到"),
}
}
}
impl std::error::Error for CaptureError {}