use crate::{PointCloudReader, PointCloudWriter};
use crate::registry::{PointCloudReader as RegistryPointCloudReader, PointCloudWriter as RegistryPointCloudWriter};
use threecrate_core::{PointCloud, Point3f, Result};
use std::path::Path;
use pasture_core::containers::BorrowedBuffer;
pub struct PastureReader;
pub struct PastureWriter;
impl RegistryPointCloudReader for PastureReader {
fn read_point_cloud(&self, path: &Path) -> Result<PointCloud<Point3f>> {
let buffer = pasture_io::base::read_all::<pasture_core::containers::VectorBuffer, _>(path)
.map_err(|e| threecrate_core::Error::Io(std::io::Error::new(std::io::ErrorKind::Other, e.to_string())))?;
let cloud = PointCloud::new();
if buffer.len() > 0 {
return Err(threecrate_core::Error::Unsupported(
"LAS/LAZ reading implemented but needs attribute parsing refinement".to_string()
));
}
Ok(cloud)
}
fn can_read(&self, path: &Path) -> bool {
if let Some(extension) = path.extension() {
if let Some(ext_str) = extension.to_str() {
return matches!(ext_str.to_lowercase().as_str(), "las" | "laz" | "pcd");
}
}
false
}
fn format_name(&self) -> &'static str {
"pasture"
}
}
impl RegistryPointCloudWriter for PastureWriter {
fn write_point_cloud(&self, _cloud: &PointCloud<Point3f>, _path: &Path) -> Result<()> {
Err(threecrate_core::Error::Unsupported(
"LAS/LAZ writing implemented but needs buffer setup refinement".to_string()
))
}
fn format_name(&self) -> &'static str {
"pasture"
}
}
impl PointCloudReader for PastureReader {
fn read_point_cloud<P: AsRef<Path>>(path: P) -> Result<PointCloud<Point3f>> {
let reader = PastureReader;
RegistryPointCloudReader::read_point_cloud(&reader, path.as_ref())
}
}
impl PointCloudWriter for PastureWriter {
fn write_point_cloud<P: AsRef<Path>>(_cloud: &PointCloud<Point3f>, path: P) -> Result<()> {
let writer = PastureWriter;
RegistryPointCloudWriter::write_point_cloud(&writer, _cloud, path.as_ref())
}
}
pub fn read_colored_point_cloud<P: AsRef<Path>>(path: P) -> Result<PointCloud<Point3f>> {
let _path = path.as_ref();
Err(threecrate_core::Error::Unsupported(
"Colored point cloud reading not yet implemented".to_string()
))
}