pub mod ascii;
pub mod las;
pub mod ply;
pub mod riegl;
pub mod shots;
use std::path::Path;
use crate::error::{Error, Result};
use crate::PointCloud;
fn ext(path: &Path) -> String {
path.extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase()
}
pub fn read(path: impl AsRef<Path>) -> Result<PointCloud> {
let path = path.as_ref();
match ext(path).as_str() {
"las" | "laz" => las::read_las(path),
"ply" => ply::read_ply(path),
"xyz" | "txt" | "csv" | "asc" | "pts" => ascii::read_ascii(path, None),
"rxp" => riegl::read_rxp(path, &riegl::RxpOptions::default()),
other => Err(Error::UnsupportedFormat(other.to_string())),
}
}
#[derive(Debug, Clone)]
pub struct WriteOptions {
pub point_format: u8,
pub scale: f64,
pub binary: bool,
pub crs_wkt: Option<String>,
}
impl Default for WriteOptions {
fn default() -> Self {
let las = las::LasWriteOptions::default();
WriteOptions { point_format: las.point_format, scale: las.scale, binary: true, crs_wkt: None }
}
}
pub fn write(cloud: &PointCloud, path: impl AsRef<Path>) -> Result<()> {
write_with(cloud, path, &WriteOptions::default())
}
pub fn write_with(cloud: &PointCloud, path: impl AsRef<Path>, opts: &WriteOptions) -> Result<()> {
let path = path.as_ref();
match ext(path).as_str() {
"las" | "laz" => las::write_las(cloud, path, &las::LasWriteOptions { point_format: opts.point_format, scale: opts.scale, crs_wkt: opts.crs_wkt.clone() }),
"ply" => ply::write_ply(cloud, path, opts.binary),
"xyz" | "txt" | "asc" | "pts" => ascii::write_ascii(cloud, path, " ", true, 4),
"csv" => ascii::write_ascii(cloud, path, ",", true, 4),
other => Err(Error::UnsupportedFormat(other.to_string())),
}
}