#writer #pcd

pcd-rs

Working with PCD file format in Rust

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

#1788 in Parser implementations

Download history 44/week @ 2023-06-05 48/week @ 2023-06-12 76/week @ 2023-06-19 55/week @ 2023-06-26 129/week @ 2023-07-03 47/week @ 2023-07-10 43/week @ 2023-07-17 112/week @ 2023-07-24 96/week @ 2023-07-31 164/week @ 2023-08-07 68/week @ 2023-08-14 51/week @ 2023-08-21 64/week @ 2023-08-28 94/week @ 2023-09-04 85/week @ 2023-09-11 71/week @ 2023-09-18

335 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.7–4.5MB
~81K SLoC