pub mod csv;
pub mod e57_format;
pub mod las_format;
pub mod pcd;
pub mod ply;
pub use csv::{read_csv, read_poses};
pub use e57_format::{read_e57, write_e57};
pub use las_format::{read_las, write_las};
pub use pcd::{read_pcd, write_pcd};
pub use ply::{read_ply, write_ply};
use std::path::Path;
use rigidity_core::PointCloud;
pub fn read(path: &Path) -> Result<PointCloud, IoError> {
match extension(path).as_str() {
"ply" => read_ply(path),
"las" | "laz" => read_las(path),
"e57" => read_e57(path),
"pcd" => read_pcd(path),
"csv" | "txt" => read_csv(path),
other => Err(IoError::UnknownFormat(other.to_owned())),
}
}
pub fn write(cloud: &PointCloud, path: &Path) -> Result<(), IoError> {
match extension(path).as_str() {
"ply" => write_ply(cloud, path),
"las" | "laz" => write_las(cloud, path),
"e57" => write_e57(cloud, path),
"pcd" => write_pcd(cloud, path),
other => Err(IoError::UnknownFormat(other.to_owned())),
}
}
pub const READABLE: &[&str] = &["ply", "las", "laz", "e57", "pcd", "csv", "txt"];
pub const WRITABLE: &[&str] = &["ply", "las", "laz", "e57", "pcd"];
fn extension(path: &Path) -> String {
path.extension()
.and_then(|extension| extension.to_str())
.unwrap_or_default()
.to_ascii_lowercase()
}
#[derive(Debug, thiserror::Error)]
pub enum IoError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("not a PLY file: the first line is not \"ply\"")]
NotPly,
#[error("PLY format \"{0}\" is not supported: need ascii or binary_little_endian")]
UnsupportedFormat(String),
#[error("malformed PLY header: {0}")]
BadHeader(String),
#[error("unknown PLY property type: \"{0}\"")]
UnknownPropertyType(String),
#[error("the vertex element is missing the x, y, z properties")]
MissingCoordinates,
#[error("list properties inside the vertex element are not supported")]
ListInVertex,
#[error("the first PLY element must be vertex, found \"{0}\"")]
VertexNotFirst(String),
#[error("truncated data: need {expected} bytes, {actual} available")]
Truncated {
expected: usize,
actual: usize,
},
#[error("could not parse the number \"{0}\"")]
BadNumber(String),
#[error("LAS error: {0}")]
Las(String),
#[error("E57 error: {0}")]
E57(String),
#[error("malformed PCD header: {0}")]
BadPcd(String),
#[error("unsupported PCD data: \"{0}\"")]
UnsupportedPcd(String),
#[error("unknown format: \"{0}\"")]
UnknownFormat(String),
#[error(transparent)]
Cloud(#[from] rigidity_core::CloudError),
}