Skip to main content

PointCloudEncoder

Struct PointCloudEncoder 

Source
pub struct PointCloudEncoder { /* private fields */ }
Available on crate feature encoder only.
Expand description

Encoder for Draco point cloud bitstreams.

A PointCloudEncoder takes a PointCloud plus EncoderOptions and writes a .drc bitstream into an EncoderBuffer. Depending on the options it uses either KD-tree or sequential attribute encoding, matching C++ Draco’s PointCloudEncoder selection.

§Examples

use draco_core::{
    DataType, DecoderBuffer, EncoderBuffer, EncoderOptions, GeometryAttributeType,
    PointAttribute, PointCloud, PointCloudDecoder, PointCloudEncoder,
};

// Three points with float32 positions.
let mut pc = PointCloud::new();
let mut position = PointAttribute::new();
position.init(GeometryAttributeType::Position, 3, DataType::Float32, false, 3);
let coords: [f32; 9] = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0];
for (i, value) in coords.iter().enumerate() {
    position.buffer_mut().write(i * 4, &value.to_le_bytes());
}
pc.add_attribute(position);

// Encode, then decode it back.
let mut encoder = PointCloudEncoder::new();
encoder.set_point_cloud(pc);
let mut buffer = EncoderBuffer::new();
encoder.encode(&EncoderOptions::new(), &mut buffer)?;

let mut decoded = PointCloud::new();
PointCloudDecoder::new().decode(&mut DecoderBuffer::new(buffer.data()), &mut decoded)?;
assert_eq!(decoded.num_points(), 3);

Implementations§

Source§

impl PointCloudEncoder

Source

pub fn new() -> Self

Creates an encoder without an assigned point cloud.

Source

pub fn point_cloud(&self) -> Option<&PointCloud>

Returns the point cloud assigned to this encoder, if any.

Source

pub fn set_point_cloud(&mut self, pc: PointCloud)

Assigns the point cloud to encode.

Source

pub fn encode( &mut self, options: &EncoderOptions, out_buffer: &mut EncoderBuffer, ) -> Status

Encodes the assigned point cloud into an output buffer.

A point cloud must have been provided with set_point_cloud first.

§Errors

Returns an error if no point cloud was set, the options are unsupported, or attribute encoding fails.

Source

pub fn get_geometry_type(&self) -> EncodedGeometryType

Returns the geometry type produced by this encoder.

Trait Implementations§

Source§

impl Default for PointCloudEncoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl GeometryEncoder for PointCloudEncoder

Source§

fn point_cloud(&self) -> Option<&PointCloud>

Returns point-cloud geometry when available.
Source§

fn mesh(&self) -> Option<&Mesh>

Returns mesh geometry when available.
Source§

fn corner_table(&self) -> Option<&CornerTable>

Returns mesh corner-table topology when available.
Source§

fn options(&self) -> &EncoderOptions

Returns the active encoder options.
Source§

fn get_geometry_type(&self) -> EncodedGeometryType

Returns the encoded geometry type.
Source§

fn get_encoding_method(&self) -> Option<i32>

Returns the forced encoding method, if one is active.
Source§

fn get_data_to_corner_map(&self) -> Option<&[u32]>

Returns a data-to-corner map for mesh attribute prediction, if present.
Source§

fn get_vertex_to_data_map(&self) -> Option<&[i32]>

Returns a vertex-to-data map for mesh attribute prediction, if present.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.