22 releases (12 breaking)

0.13.0 Mar 11, 2026
0.12.0 Oct 31, 2024
0.11.1 Jun 27, 2024
0.10.0 Aug 2, 2022
0.1.2 Jun 11, 2019

#2660 in Parser implementations

Download history 93/week @ 2026-01-05 77/week @ 2026-01-12 120/week @ 2026-01-19 109/week @ 2026-01-26 147/week @ 2026-02-02 79/week @ 2026-02-09 170/week @ 2026-02-16 108/week @ 2026-02-23 133/week @ 2026-03-02 199/week @ 2026-03-09 117/week @ 2026-03-16 124/week @ 2026-03-23 124/week @ 2026-03-30 147/week @ 2026-04-06 174/week @ 2026-04-13 85/week @ 2026-04-20

537 downloads per month
Used in 3 crates (2 directly)

Custom license

235KB
2.5K SLoC

pcd-rs: Read point cloud data from PCD file format

pcd-rs allows you to parse PCD point cloud data from a file or a binary buffer.

Usage

To add this crate to your project,

cargo add pcd-rs

Please visit docs.rs to learn more about the usage.

Examples

Example code can be found in examples directory. Run cargo run --example to list all available example binaries.

License

MIT license. See LICESE file.


lib.rs:

Read and write PCD file format.

This crate provides data serializer and deserializer for PCD (Point Cloud Data) file format. The [DynReader] and [DynWriter] can read and write PCD files with any valid schemas. It also supports deserializing to static types if the derive feature is enabled.

Supported Format Versions

  • 0.7
  • Older versions are not supported yet.

Any Schema Example

In the case of any schema, the points are represented by an array or a slice of [DynRecord]s, where is record wraps a sequence of data [Field]s.

Reader

The reader is created by [DynReader::open()], returning an iterator, which generates a sequence of Result<DynRecord>.

use pcd_rs::DynReader;

// Declare the reader
let reader = DynReader::open("test_files/binary.pcd")?;

// The reader itself is an iterator of records
let points: Result<Vec<_>, _> = reader.collect();
println!("There are {} points found.", points?.len());

Writer

The writer is first configured by [WriterInit], and then call [WriterInit::create()] to construct the [DynWriter]. The .push() is used to append the data to the writer. The writer must be finished by .finish() in the end.

use pcd_rs::{DataKind, DynRecord, DynWriter, Field, Schema, ValueKind, WriterInit};

// Declare point data
let points = [
    DynRecord(vec![
        Field::F32(vec![3.14159]),
        Field::U8(vec![2, 1, 7]),
        Field::I32(vec![-5]),
    ]),
    DynRecord(vec![
        Field::F32(vec![-0.0]),
        Field::U8(vec![254, 6, 98]),
        Field::I32(vec![7]),
    ]),
    DynRecord(vec![
        Field::F32(vec![5.6]),
        Field::U8(vec![4, 0, 111]),
        Field::I32(vec![-100000]),
    ]),
];

// Declare the schema
let schema = vec![
    ("x", ValueKind::F32, 1),
    ("y", ValueKind::U8, 3),
    ("z", ValueKind::I32, 1),
];

// Build a writer
let mut writer: DynWriter<_> = WriterInit {
    width: 300,
    height: 1,
    viewpoint: Default::default(),
    data_kind: DataKind::Ascii,
    schema: Some(Schema::from_iter(schema)),
    version: None,
}
.create("test_files/dump_ascii_untyped.pcd")?;

// Send the points to the writer
for point in points {
    writer.push(&point)?;
}

// Finalize the writer
writer.finish()?;

Dependencies

~2.6–4.5MB
~79K SLoC