pub mod ply;
pub mod obj;
#[cfg(feature = "las_laz")]
pub mod pasture;
pub mod pcd;
pub mod xyz_csv;
#[cfg(feature = "e57")]
pub mod e57;
pub mod error;
pub mod registry;
pub mod mesh_attributes;
pub mod serialization;
#[cfg(feature = "io-mmap")]
pub mod mmap;
#[cfg(test)]
pub mod tests;
pub use error::*;
pub use ply::{RobustPlyReader, RobustPlyWriter, PlyWriteOptions, PlyFormat, PlyValue};
pub use obj::{RobustObjReader, RobustObjWriter, ObjData, ObjWriteOptions, Material, FaceVertex, Face, Group};
pub use pcd::{RobustPcdReader, RobustPcdWriter, PcdWriteOptions, PcdDataFormat, PcdFieldType, PcdHeader, PcdValue};
pub use xyz_csv::{XyzCsvReader, XyzCsvWriter, XyzCsvStreamingReader, XyzCsvWriteOptions, XyzCsvSchema, XyzCsvPoint, Delimiter, ColumnType};
#[cfg(feature = "e57")]
pub use e57::{RobustE57Reader, RobustE57Writer, E57WriteOptions};
pub use registry::{IoRegistry, FormatHandler};
pub use mesh_attributes::{ExtendedTriangleMesh, MeshAttributeOptions, MeshMetadata, Tangent, UV};
pub use serialization::{SerializationOptions, AttributePreservingReader, AttributePreservingWriter};
use threecrate_core::{PointCloud, TriangleMesh, Result, Point3f};
use std::path::Path;
pub trait PointCloudReader {
fn read_point_cloud<P: AsRef<std::path::Path>>(path: P) -> Result<PointCloud<Point3f>>;
}
pub trait PointCloudWriter {
fn write_point_cloud<P: AsRef<std::path::Path>>(cloud: &PointCloud<Point3f>, path: P) -> Result<()>;
}
pub trait MeshReader {
fn read_mesh<P: AsRef<std::path::Path>>(path: P) -> Result<TriangleMesh>;
}
pub trait MeshWriter {
fn write_mesh<P: AsRef<std::path::Path>>(mesh: &TriangleMesh, path: P) -> Result<()>;
}
lazy_static::lazy_static! {
static ref IO_REGISTRY: IoRegistry = {
let mut registry = IoRegistry::new();
registry.register_point_cloud_handler("ply", Box::new(ply::PlyReader));
registry.register_mesh_handler("ply", Box::new(ply::PlyReader));
registry.register_point_cloud_writer("ply", Box::new(ply::PlyWriter));
registry.register_mesh_writer("ply", Box::new(ply::PlyWriter));
registry.register_mesh_handler("obj", Box::new(obj::ObjReader));
registry.register_mesh_writer("obj", Box::new(obj::ObjWriter));
#[cfg(feature = "las_laz")]
{
registry.register_point_cloud_handler("las", Box::new(pasture::PastureReader));
registry.register_point_cloud_handler("laz", Box::new(pasture::PastureReader));
registry.register_point_cloud_writer("las", Box::new(pasture::PastureWriter));
registry.register_point_cloud_writer("laz", Box::new(pasture::PastureWriter));
}
registry.register_point_cloud_handler("pcd", Box::new(pcd::PcdReader));
registry.register_point_cloud_writer("pcd", Box::new(pcd::PcdWriter));
registry.register_point_cloud_handler("xyz", Box::new(xyz_csv::XyzCsvReader));
registry.register_point_cloud_handler("csv", Box::new(xyz_csv::XyzCsvReader));
registry.register_point_cloud_handler("txt", Box::new(xyz_csv::XyzCsvReader));
registry.register_point_cloud_writer("xyz", Box::new(xyz_csv::XyzCsvWriter));
registry.register_point_cloud_writer("csv", Box::new(xyz_csv::XyzCsvWriter));
registry.register_point_cloud_writer("txt", Box::new(xyz_csv::XyzCsvWriter));
#[cfg(feature = "e57")]
{
registry.register_point_cloud_handler("e57", Box::new(e57::E57Reader));
registry.register_mesh_handler("e57", Box::new(e57::E57Reader));
registry.register_point_cloud_writer("e57", Box::new(e57::E57Writer));
registry.register_mesh_writer("e57", Box::new(e57::E57Writer));
}
registry
};
}
pub fn read_point_cloud<P: AsRef<Path>>(path: P) -> Result<PointCloud<Point3f>> {
let path = path.as_ref();
let extension = path.extension()
.and_then(|s| s.to_str())
.ok_or_else(|| threecrate_core::Error::UnsupportedFormat(
"No file extension found".to_string()
))?;
IO_REGISTRY.read_point_cloud(path, extension)
}
pub fn read_mesh<P: AsRef<Path>>(path: P) -> Result<TriangleMesh> {
let path = path.as_ref();
let extension = path.extension()
.and_then(|s| s.to_str())
.ok_or_else(|| threecrate_core::Error::UnsupportedFormat(
"No file extension found".to_string()
))?;
IO_REGISTRY.read_mesh(path, extension)
}
pub fn write_point_cloud<P: AsRef<Path>>(cloud: &PointCloud<Point3f>, path: P) -> Result<()> {
let path = path.as_ref();
let extension = path.extension()
.and_then(|s| s.to_str())
.ok_or_else(|| threecrate_core::Error::UnsupportedFormat(
"No file extension found".to_string()
))?;
IO_REGISTRY.write_point_cloud(cloud, path, extension)
}
pub fn write_mesh<P: AsRef<Path>>(mesh: &TriangleMesh, path: P) -> Result<()> {
let path = path.as_ref();
let extension = path.extension()
.and_then(|s| s.to_str())
.ok_or_else(|| threecrate_core::Error::UnsupportedFormat(
"No file extension found".to_string()
))?;
IO_REGISTRY.write_mesh(mesh, path, extension)
}
pub fn get_io_registry() -> &'static IoRegistry {
&IO_REGISTRY
}
pub fn read_point_cloud_iter<P: AsRef<Path>>(
path: P,
chunk_size: Option<usize>
) -> Result<Box<dyn Iterator<Item = Result<Point3f>> + Send + Sync>> {
let path = path.as_ref();
let extension = path.extension()
.and_then(|s| s.to_str())
.ok_or_else(|| threecrate_core::Error::UnsupportedFormat(
"No file extension found".to_string()
))?;
match extension {
"ply" => {
let iter = ply::PlyStreamingReader::new(path, chunk_size.unwrap_or(1000))?;
Ok(Box::new(iter))
}
"obj" => {
let iter = obj::ObjStreamingReader::new(path, chunk_size.unwrap_or(1000))?;
Ok(Box::new(iter))
}
"xyz" | "csv" | "txt" => {
let iter = xyz_csv::XyzCsvStreamingReader::new(path, chunk_size.unwrap_or(1000))?;
Ok(Box::new(iter))
}
_ => Err(threecrate_core::Error::UnsupportedFormat(
format!("Streaming not supported for format: {}", extension)
))
}
}
pub fn read_mesh_iter<P: AsRef<Path>>(
path: P,
chunk_size: Option<usize>
) -> Result<Box<dyn Iterator<Item = Result<[usize; 3]>> + Send + Sync>> {
let path = path.as_ref();
let extension = path.extension()
.and_then(|s| s.to_str())
.ok_or_else(|| threecrate_core::Error::UnsupportedFormat(
"No file extension found".to_string()
))?;
match extension {
"ply" => {
let iter = ply::PlyMeshStreamingReader::new(path, chunk_size.unwrap_or(1000))?;
Ok(Box::new(iter))
}
"obj" => {
let iter = obj::ObjMeshStreamingReader::new(path, chunk_size.unwrap_or(1000))?;
Ok(Box::new(iter))
}
_ => Err(threecrate_core::Error::UnsupportedFormat(
format!("Streaming not supported for format: {}", extension)
))
}
}