21 releases (11 breaking)

0.12.0 Oct 31, 2024
0.11.1 Jun 27, 2024
0.11.0 Apr 5, 2024
0.10.0 Aug 2, 2022
0.1.2 Jun 11, 2019

#513 in Parser implementations

Download history 148/week @ 2024-08-23 93/week @ 2024-08-30 176/week @ 2024-09-06 200/week @ 2024-09-13 186/week @ 2024-09-20 146/week @ 2024-09-27 95/week @ 2024-10-04 38/week @ 2024-10-11 56/week @ 2024-10-18 151/week @ 2024-10-25 116/week @ 2024-11-01 138/week @ 2024-11-08 167/week @ 2024-11-15 159/week @ 2024-11-22 89/week @ 2024-11-29 114/week @ 2024-12-06

543 downloads per month
Used in 4 crates (3 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

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)),
}
.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.9–4.5MB
~82K SLoC