ply_rs::writer

Struct Writer

Source
pub struct Writer<E: PropertyAccess> { /* private fields */ }
Expand description

Writes a Ply to a Write trait.

The simplest function to start with is write_ply(). It performs all necessary checks and writes a complete PLY file. Sometimes you might want to have better control over how much is written. All other write_ functions are for those cases. The trade-off is, that then you get responsible to write consistent data. See Ply::make_consistent().

For further information on the PLY file format, consult the official reference.

§Examples

Simplest case of writing an entire PLY file en bloc:

// Get a Ply from somewhere
// let mut ply = ...;

// Get a buffer with `Write` trait.
// For example a file: let buf = std::io::File(".../your.ply").unwrap();

// Create a writer
let w = Writer::new();

// Write your data:
let written = w.write_ply(&mut buf, &mut ply).unwrap();

Implementations§

Source§

impl<E: PropertyAccess> Writer<E>

Source

pub fn new() -> Self

Create a new Writer<E> where E is the element type. To get started quickly use DefaultElement.

Source

pub fn write_ply<T: Write>( &self, out: &mut T, ply: &mut Ply<E>, ) -> Result<usize>

Writes an entire PLY file modeled by ply to out, performs consistency chekc.

ply must be mutable since a consistency check is performed. If problems can be corrected automatically, ply will be modified accordingly.

Returns number of bytes written.

Source

pub fn write_ply_unchecked<T: Write>( &self, out: &mut T, ply: &Ply<E>, ) -> Result<usize>

Writes an entire PLY file modeled by ply to out, performes no consistency check.

Like write_ply but doesn’t check the input for inconsistency. The user is responsible to provide a consistent Ply, if not, behaviour is undefined and might result in a corrupted output.

Source§

impl<E: PropertyAccess> Writer<E>

Source

pub fn write_line_magic_number<T: Write>(&self, out: &mut T) -> Result<usize>

Writes the magic number “ply” and a new line.

Each PLY file must start with “ply\n”.

Source

pub fn write_line_format<T: Write>( &self, out: &mut T, encoding: &Encoding, version: &Version, ) -> Result<usize>

Writes “format ”.

Each PLY file must define its format.

Source

pub fn write_line_comment<T: Write>( &self, out: &mut T, comment: &Comment, ) -> Result<usize>

Writes a comment line.

A comment must not contain a line break and only consist of ascii characters.

Source

pub fn write_line_obj_info<T: Write>( &self, out: &mut T, obj_info: &ObjInfo, ) -> Result<usize>

Writes an object information line.

An object informatio line must not contain a line break an only consist of ascii characters.

Source

pub fn write_line_element_definition<T: Write>( &self, out: &mut T, element: &ElementDef, ) -> Result<usize>

Writes an element line from the header: “element

This line is part of the header. It defines the format of an element. It is directly followed by its property definitions.

Make sure the header is consistent with the payload.

Source

pub fn write_line_property_definition<T: Write>( &self, out: &mut T, property: &PropertyDef, ) -> Result<usize>

Writes a property line form the header: “property [list <index_type> <scalar_type> | <scalar_type> ]”

Make sure the property definition is consistent with the payload.

Source

pub fn write_element_definition<T: Write>( &self, out: &mut T, element: &ElementDef, ) -> Result<usize>

Writes the element line and all the property definitions

Convenience method to call write_line_element_definition and write_line_property_definition in the correct way.

Make sure the element definition is consistent with the payload.

Source

pub fn write_line_end_header<T: Write>(&self, out: &mut T) -> Result<usize>

Writes end_header\n. This terminates the header. Each following byte belongs to the payload.

Source

pub fn write_header<T: Write>( &self, out: &mut T, header: &Header, ) -> Result<usize>

Convenience method to write all header elements.

It starts with writing the magic number “ply\n” and ends with “end_header”.

Make sure the header is consistent with the payload.

Source§

impl<E: PropertyAccess> Writer<E>

§Payload

Source

pub fn write_payload<T: Write>( &self, out: &mut T, payload: &Payload<E>, header: &Header, ) -> Result<usize>

Writes the payload of a ply (ply.playload).

Make sure the Header is consistent with the payload.

Source

pub fn write_payload_of_element<T: Write>( &self, out: &mut T, element_list: &Vec<E>, element_def: &ElementDef, header: &Header, ) -> Result<usize>

Write all elments as stored in the element_list.

Make sure the header and the element definition is consistent with the payload.

Source§

impl<E: PropertyAccess> Writer<E>

§Ascii

Source

pub fn write_ascii_element<T: Write>( &self, out: &mut T, element: &E, element_def: &ElementDef, ) -> Result<usize>

Write a single ascii formatted element.

Source§

impl<E: PropertyAccess> Writer<E>

§Binary

Source

pub fn write_big_endian_element<T: Write>( &self, out: &mut T, element: &E, element_def: &ElementDef, ) -> Result<usize>

Write a single binary formatted element in big endian.

Source

pub fn write_little_endian_element<T: Write>( &self, out: &mut T, element: &E, element_def: &ElementDef, ) -> Result<usize>

Write a single binary formatted element in little endian.

Auto Trait Implementations§

§

impl<E> Freeze for Writer<E>

§

impl<E> RefUnwindSafe for Writer<E>
where E: RefUnwindSafe,

§

impl<E> Send for Writer<E>
where E: Send,

§

impl<E> Sync for Writer<E>
where E: Sync,

§

impl<E> Unpin for Writer<E>
where E: Unpin,

§

impl<E> UnwindSafe for Writer<E>
where E: UnwindSafe,

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.