18 releases (9 breaking)

0.10.0 Aug 2, 2022
0.9.1 Feb 21, 2022
0.8.0 May 8, 2021
0.7.0 Jun 29, 2020
0.1.2 Jun 11, 2019

#2231 in Parser implementations

Download history 55/week @ 2023-11-20 92/week @ 2023-11-27 92/week @ 2023-12-04 80/week @ 2023-12-11 67/week @ 2023-12-18 30/week @ 2023-12-25 39/week @ 2024-01-01 96/week @ 2024-01-08 84/week @ 2024-01-15 58/week @ 2024-01-22 53/week @ 2024-01-29 61/week @ 2024-02-05 113/week @ 2024-02-12 81/week @ 2024-02-19 161/week @ 2024-02-26 60/week @ 2024-03-04

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

Custom license

210KB
1.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

Add pcd-rs to your Cargo.toml.

pcd_rs = "0.8.0"

Please visit docs.rs to see detailed 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)),
}
.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.8–4.5MB
~81K SLoC