Reading and writing general point cloud files
If you just want to read the contents of a point cloud files without any special handling, use read_all
, like in the following example:
use anyhow::{bail, Context, Result}; use pasture_core::{ containers::{BorrowedBuffer, VectorBuffer}, layout::attributes::POSITION_3D, nalgebra::Vector3, }; use pasture_io::base::{read_all}; fn main() -> Result<()> { // Reading a point cloud file is as simple as calling `read_all` let points = read_all::<VectorBuffer, _>("pointcloud.las").context("Failed to read points")?; Ok(()) }
The opposite works for writing the contents of a pasture
buffer into a file. The type of file is deduced from the file extension, with three formats currently supported out of the box: LAS for files ending in .las
, compressed LAZ for files ending in .laz
, and 3D Tiles for files ending in .pnts
:
/// This point type uses the #[derive(PointType)] macro to auto-generate an appropriate PointLayout #[repr(C, packed)] #[derive(Copy, Clone, PointType, Debug, bytemuck::NoUninit, bytemuck::AnyBitPattern)] struct SimplePoint { #[pasture(BUILTIN_POSITION_3D)] pub position: Vector3<f64>, #[pasture(BUILTIN_INTENSITY)] pub intensity: u16, } fn main() -> Result<()> { // Create some points let points = vec![ SimplePoint { position: Vector3::new(1.0, 2.0, 3.0), intensity: 42, }, SimplePoint { position: Vector3::new(-1.0, -2.0, -3.0), intensity: 84, }, ]; let buffer = points.iter().copied().collect::<VectorBuffer>(); // Write all points in `buffer` into a LAS file: write_all(&buffer, "file.las")?; Ok(()) }